├── .gitignore ├── .idea ├── misc.xml ├── modules.xml ├── runConfigurations │ └── GradleConfirmation.xml └── vcs.xml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── GradleConfirmation.iml ├── GradleConfirmation.jar ├── LICENSE ├── META-INF └── plugin.xml ├── README.md └── src └── com └── github └── shiraji └── gradleconfirmation ├── action ├── GradleConfirmationListDisableTaskNamesAction.java └── GradleConfirmationToggleAction.java ├── config └── GradleConfirmationConfig.java ├── task └── GradleConfirmationTaskManager.java └── view ├── GradleConfirmationDisableTaskListForm.form └── GradleConfirmationDisableTaskListForm.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Intellij ### 4 | 5 | ## Directory-based project format: 6 | .idea/* 7 | # if you remove the above rule, at least ignore the following: 8 | 9 | # User-specific stuff: 10 | # .idea/workspace.xml 11 | # .idea/tasks.xml 12 | # .idea/dictionaries 13 | 14 | # Sensitive or high-churn files: 15 | # .idea/dataSources.ids 16 | # .idea/dataSources.xml 17 | # .idea/sqlDataSources.xml 18 | # .idea/dynamic.xml 19 | # .idea/uiDesigner.xml 20 | !.idea/vcs.xml 21 | !.idea/modules.xml 22 | !.idea/misc.xml 23 | !.idea/runConfigurations/ 24 | 25 | # Gradle: 26 | # .idea/gradle.xml 27 | # .idea/libraries 28 | 29 | # Mongo Explorer plugin: 30 | # .idea/mongoSettings.xml 31 | 32 | ## File-based project format: 33 | *.ipr 34 | *.iws 35 | 36 | ## Plugin-specific files: 37 | 38 | # IntelliJ 39 | /out/ 40 | 41 | # mpeltonen/sbt-idea plugin 42 | .idea_modules/ 43 | 44 | # JIRA plugin 45 | atlassian-ide-plugin.xml 46 | 47 | # Crashlytics plugin (for Android Studio and IntelliJ) 48 | com_crashlytics_export_strings.xml 49 | crashlytics.properties 50 | crashlytics-build.properties 51 | 52 | 53 | ### Java ### 54 | *.class 55 | 56 | # Mobile Tools for Java (J2ME) 57 | .mtj.tmp/ 58 | 59 | # Package Files # 60 | *.war 61 | *.ear 62 | 63 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 64 | hs_err_pid* 65 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/runConfigurations/GradleConfirmation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### [ver 1.0.0](https://github.com/shiraji/GradleConfirmation/releases/tag/v1.0.0) 2 | 3 | * [#9](https://github.com/shiraji/GradleConfirmation/issues/9) Added CHANGELOG.md 4 | * [#10](https://github.com/shiraji/GradleConfirmation/issues/10) Added a function that disables to show the confirmation based on gradle task names 5 | 6 | ### [ver 0.0.3](https://github.com/shiraji/GradleConfirmation/releases/tag/v0.0.3) 7 | 8 | * [#3](https://github.com/shiraji/GradleConfirmation/issues/3) Replaced showing the notification with printing the message to the console 9 | * [#2](https://github.com/shiraji/GradleConfirmation/issues/2) Added Github/Plugin Home Page information to plugin.xml 10 | 11 | ### [ver 0.0.2](https://github.com/shiraji/GradleConfirmation/releases/tag/v0.0.2) 12 | 13 | * Changed how to store settings (PersistentStateComponent to PropertiesComponent) 14 | * [#1](https://github.com/shiraji/GradleConfirmation/issues/1) Added README.md 15 | 16 | ### [ver 0.0.1](https://github.com/shiraji/GradleConfirmation/releases/tag/v0.0.1) 17 | 18 | * Initial release 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | Contribution is welcome! Please give me pull request to fix documentation. Raise issue is also welcome. Here is how you can contribute this library. 4 | 5 | 1. [Fork](https://github.com/shiraji/GradleConfirmation/fork) 6 | 1. Clone your forked repository: `git clone your-repositity-url` 7 | 1. Create your feature branch: `git checkout -b 3_new-feature` where 3 is issue number. (if there is no issue, don't worry about this) 8 | 1. Empty commit with what you will archive: `git commit --allow-empty -m 'Fix #3'` 9 | 1. Push to the branch: `git push origin 3_new-feature` 10 | 1. Submit a pull request with [WIP] in pull request title 11 | 1. Hack, Hack, Hack 12 | 1. Commit your changes: `git commit -am 'Add some feature'` 13 | 1. Push commits: `git push origin 3_new-featureu` 14 | 1. After your code is good to go, replace [WIP] from pull request title 15 | -------------------------------------------------------------------------------- /GradleConfirmation.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /GradleConfirmation.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/GradleConfirmation/f79b554980f2abb49d1884e336fc39f0a165ce15/GradleConfirmation.jar -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | -------------------------------------------------------------------------------- /META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.github.shiraji.gradleconfirmation 3 | Gradle Confirmation 4 | 1.0.0 5 | Shiraji 6 | 7 |
9 | GitHub | 10 | Issues 11 | ]]>
12 | 13 | 1.0.0

15 | 18 | 19 |

0.0.3

20 | 23 | 24 |

0.0.2

25 | 28 | 29 |

0.0.1

30 | 33 | ]]> 34 |
35 | 36 | 37 | 38 | 39 | 41 | 44 | 45 | 46 | 47 | 48 | org.jetbrains.plugins.gradle 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 66 | 70 | 71 | 75 | 76 | 77 | 78 | 79 | 80 |
81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gradle Confirmation 2 | 3 | [![Join the chat at https://gitter.im/shiraji/GradleConfirmation](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/shiraji/GradleConfirmation?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-GradleConfirmation-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/2350) [![Software License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](https://github.com/shiraji/GradleConfirmation/blob/master/LICENSE) 4 | 5 | This plugin shows a confirmation dialog before executing gradle tasks. 6 | 7 | ## Installation 8 | 9 | Use the IDE's plugin manager to install the latest version of the plugin. 10 | 11 | or 12 | 13 | [Download](https://github.com/shiraji/GradleConfirmation/blob/master/GradleConfirmation.jar?raw=true) jar file and then go to Preferences > Plugins > Install plugin from disk... > Select the jar file you downloaded 14 | 15 | ## Usage 16 | 17 | Run Gradle task[s] from Gradle projects window, this plugin popup confirmation dialog asking the developer really want to run the task. If the developer click NO, the plugin stop executing the gradle task[s]. 18 | 19 | To disable this plugin, go to `Tools > uncheck Show Gradle Confirmation` 20 | 21 | ## History 22 | 23 | See [CHANGELOG](https://github.com/shiraji/GradleConfirmation/blob/master/CHANGELOG.md) 24 | 25 | ## License 26 | 27 | ``` 28 | Copyright 2016 Yoshinori Isogai 29 | 30 | Licensed under the Apache License, Version 2.0 (the "License"); 31 | you may not use this file except in compliance with the License. 32 | You may obtain a copy of the License at 33 | 34 | http://www.apache.org/licenses/LICENSE-2.0 35 | 36 | Unless required by applicable law or agreed to in writing, software 37 | distributed under the License is distributed on an "AS IS" BASIS, 38 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 39 | See the License for the specific language governing permissions and 40 | limitations under the License. 41 | ``` 42 | -------------------------------------------------------------------------------- /src/com/github/shiraji/gradleconfirmation/action/GradleConfirmationListDisableTaskNamesAction.java: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.gradleconfirmation.action; 2 | 3 | import com.github.shiraji.gradleconfirmation.config.GradleConfirmationConfig; 4 | import com.github.shiraji.gradleconfirmation.view.GradleConfirmationDisableTaskListForm; 5 | import com.intellij.openapi.actionSystem.AnAction; 6 | import com.intellij.openapi.actionSystem.AnActionEvent; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.openapi.ui.DialogWrapper; 9 | import com.intellij.openapi.ui.StripeTable; 10 | import com.intellij.ui.AnActionButton; 11 | import com.intellij.ui.AnActionButtonRunnable; 12 | import com.intellij.ui.ToolbarDecorator; 13 | 14 | import org.jetbrains.annotations.NotNull; 15 | import org.jetbrains.annotations.Nullable; 16 | 17 | import java.awt.BorderLayout; 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.logging.Logger; 22 | 23 | import javax.swing.Action; 24 | import javax.swing.JComponent; 25 | import javax.swing.table.DefaultTableColumnModel; 26 | import javax.swing.table.DefaultTableModel; 27 | 28 | public class GradleConfirmationListDisableTaskNamesAction extends AnAction { 29 | 30 | final DefaultTableModel model = new DefaultTableModel(new String[]{"Task Names"}, 0); 31 | Logger mLogger = Logger.getLogger 32 | (GradleConfirmationListDisableTaskNamesAction.class.getName()); 33 | GradleConfirmationDisableTaskListForm mGradleConfirmationDisableTaskListForm = new 34 | GradleConfirmationDisableTaskListForm(); 35 | 36 | @Override 37 | public void actionPerformed(AnActionEvent anActionEvent) { 38 | Project project = anActionEvent.getProject(); 39 | initModel(project); 40 | if (new GradleConfirmationDisableTaskListDialog(project).showAndGet()) { 41 | saveToConfig(project); 42 | } 43 | } 44 | 45 | private void initModel(Project project) { 46 | clearModel(); 47 | addRows(project); 48 | } 49 | 50 | private void addRows(Project project) { 51 | String[] disableTaskList = GradleConfirmationConfig.getDisableTaskList(project); 52 | if (disableTaskList == null) { 53 | return; 54 | } 55 | 56 | for (String distableTask : disableTaskList) { 57 | model.addRow(new String[]{distableTask}); 58 | } 59 | } 60 | 61 | private void clearModel() { 62 | int rowCount = model.getRowCount(); 63 | for (int i = 0; i < rowCount; i++) { 64 | model.removeRow(0); 65 | } 66 | } 67 | 68 | private void saveToConfig(Project project) { 69 | List taskList = new ArrayList(); 70 | int rowCount = model.getRowCount(); 71 | for (int i = 0; i < rowCount; i++) { 72 | String taskName = (String) model.getValueAt(i, 0); 73 | if (taskName != null && taskName.length() > 0) { 74 | taskList.add(taskName); 75 | } 76 | } 77 | 78 | GradleConfirmationConfig.setDisableTaskList(project, taskList); 79 | } 80 | 81 | class GradleConfirmationDisableTaskListDialog extends DialogWrapper { 82 | final StripeTable table = new StripeTable(model); 83 | 84 | protected GradleConfirmationDisableTaskListDialog(@Nullable Project project) { 85 | super(project); 86 | init(); 87 | setTitle("Disable Task List - Gradle Confirmation"); 88 | setSize(300, 500); 89 | } 90 | 91 | @Nullable 92 | @Override 93 | protected JComponent createCenterPanel() { 94 | ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table).disableUpDownActions(); 95 | initDecorator(decorator); 96 | initColumnWidth(table); 97 | mGradleConfirmationDisableTaskListForm.mDisableTaskListPanel.add(decorator.createPanel(), BorderLayout.CENTER); 98 | return mGradleConfirmationDisableTaskListForm.mRootPanel; 99 | } 100 | 101 | private void initDecorator(ToolbarDecorator decorator) { 102 | decorator.setAddAction(new AnActionButtonRunnable() { 103 | @Override 104 | public void run(AnActionButton anActionButton) { 105 | model.addRow(new String[]{""}); 106 | table.setModel(model); 107 | table.editCellAt(model.getRowCount() - 1, 0); 108 | } 109 | }).setRemoveAction(new AnActionButtonRunnable() { 110 | @Override 111 | public void run(AnActionButton anActionButton) { 112 | int[] selectedColumns = table.getSelectedRows(); 113 | Arrays.sort(selectedColumns); 114 | for (int i = selectedColumns.length - 1; i >= 0; i--) { 115 | model.removeRow(selectedColumns[i]); 116 | table.setModel(model); 117 | } 118 | } 119 | }); 120 | } 121 | 122 | private void initColumnWidth(StripeTable table) { 123 | DefaultTableColumnModel columnModel = (DefaultTableColumnModel) table.getColumnModel(); 124 | columnModel.getColumn(0).setPreferredWidth(300); 125 | } 126 | 127 | @NotNull 128 | protected Action[] createActions() { 129 | return new Action[]{this.getOKAction(), this.getCancelAction()}; 130 | } 131 | 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/com/github/shiraji/gradleconfirmation/action/GradleConfirmationToggleAction.java: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.gradleconfirmation.action; 2 | 3 | import com.github.shiraji.gradleconfirmation.config.GradleConfirmationConfig; 4 | import com.intellij.openapi.actionSystem.AnActionEvent; 5 | import com.intellij.openapi.actionSystem.ToggleAction; 6 | 7 | public class GradleConfirmationToggleAction extends ToggleAction { 8 | 9 | @Override 10 | public boolean isSelected(AnActionEvent anActionEvent) { 11 | return GradleConfirmationConfig.isSelected(anActionEvent.getProject()); 12 | } 13 | 14 | @Override 15 | public void setSelected(AnActionEvent anActionEvent, boolean b) { 16 | GradleConfirmationConfig.setSelected(anActionEvent.getProject(), b); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/github/shiraji/gradleconfirmation/config/GradleConfirmationConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.gradleconfirmation.config; 2 | 3 | import com.intellij.ide.util.PropertiesComponent; 4 | import com.intellij.openapi.project.Project; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | public class GradleConfirmationConfig { 11 | 12 | public static final String IS_ENABLE_CONF_KEY = "com.github.shiraji.gradleconfirmation.isenable"; 13 | public static final String DISABLE_TASKS_LIST_KEY = "com.github.shiraji.gradleconfirmation.config.GradleConfirmationConfig.DISABLE_TASKS_LIST_KEY"; 14 | 15 | public static boolean isSelected(Project project) { 16 | return PropertiesComponent.getInstance(project).getBoolean(IS_ENABLE_CONF_KEY, true); 17 | } 18 | 19 | public static void setSelected(Project project, boolean isEnable) { 20 | PropertiesComponent.getInstance(project).setValue(IS_ENABLE_CONF_KEY, String.valueOf(isEnable)); 21 | } 22 | 23 | public static String[] getDisableTaskList(Project project) { 24 | return PropertiesComponent.getInstance(project).getValues(DISABLE_TASKS_LIST_KEY); 25 | } 26 | 27 | public static void setDisableTaskList(Project project, List 28 | disableTaskList) { 29 | if (disableTaskList.size() > 0) { 30 | setDisableTaskList(project, disableTaskList.toArray(new String[0])); 31 | } else { 32 | clearDisableTaskList(project); 33 | } 34 | } 35 | 36 | public static void setDisableTaskList(Project project, String[] 37 | disableTaskList) { 38 | PropertiesComponent.getInstance(project).setValues(DISABLE_TASKS_LIST_KEY, disableTaskList); 39 | } 40 | 41 | public static void clearDisableTaskList(Project project) { 42 | PropertiesComponent.getInstance(project).setValues(DISABLE_TASKS_LIST_KEY, null); 43 | } 44 | 45 | public static void addDisableTaskList(Project project, String 46 | disableTaskName) { 47 | String[] taskArray = getDisableTaskList(project); 48 | List taskList; 49 | if (taskArray == null || taskArray.length <= 0) { 50 | taskList = new ArrayList(); 51 | } else { 52 | taskList = new ArrayList(Arrays.asList(taskArray)); 53 | } 54 | taskList.add(disableTaskName); 55 | setDisableTaskList(project, taskList.toArray(new String[0])); 56 | } 57 | 58 | public static boolean isDistableTaskList(Project project, List taskList) { 59 | String[] disableTaskArray = getDisableTaskList(project); 60 | if (disableTaskArray == null || disableTaskArray.length < taskList 61 | .size()) { 62 | return false; 63 | } 64 | List disableTaskList = new ArrayList(Arrays.asList 65 | (disableTaskArray)); 66 | return disableTaskList.containsAll(taskList); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/github/shiraji/gradleconfirmation/task/GradleConfirmationTaskManager.java: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.gradleconfirmation.task; 2 | 3 | import com.github.shiraji.gradleconfirmation.config.GradleConfirmationConfig; 4 | import com.intellij.openapi.diagnostic.Logger; 5 | import com.intellij.openapi.externalSystem.model.ExternalSystemException; 6 | import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId; 7 | import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener; 8 | import com.intellij.openapi.project.Project; 9 | 10 | import org.jetbrains.plugins.gradle.service.task.GradleTaskManagerExtension; 11 | import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | import javax.swing.Box; 17 | import javax.swing.JCheckBox; 18 | import javax.swing.JComponent; 19 | import javax.swing.JLabel; 20 | import javax.swing.JOptionPane; 21 | 22 | public class GradleConfirmationTaskManager implements GradleTaskManagerExtension { 23 | private static final Logger LOG = Logger.getInstance(GradleConfirmationTaskManager.class.getName()); 24 | 25 | private static final boolean STOP_EXECUTE = true; 26 | private static final boolean START_EXECUTE = false; 27 | 28 | @Override 29 | public boolean executeTasks(ExternalSystemTaskId externalSystemTaskId, List taskNames, String s, 30 | GradleExecutionSettings gradleExecutionSettings, List list1, 31 | List list2, String s1, 32 | ExternalSystemTaskNotificationListener externalSystemTaskNotificationListener) 33 | throws ExternalSystemException { 34 | LOG.debug("executeTasks"); 35 | 36 | Project project = externalSystemTaskId.findProject(); 37 | 38 | if (project == null || !isEnablePlugin(project)) { 39 | return START_EXECUTE; 40 | } 41 | 42 | if (isDisableTasks(project, taskNames)) { 43 | showDisableMessage(externalSystemTaskId, 44 | externalSystemTaskNotificationListener); 45 | return START_EXECUTE; 46 | } 47 | 48 | String taskListNames = createTaskListNames(taskNames); 49 | JCheckBox jCheckBox = new JCheckBox(String.format("Do not show dialog for '%s'", taskNames.get(0))); 50 | 51 | int optionDialog = showConfirmationDialog(taskNames, taskListNames, jCheckBox); 52 | 53 | if (optionDialog == JOptionPane.YES_OPTION) { 54 | addToDisableList(taskNames, project, jCheckBox); 55 | return START_EXECUTE; 56 | } else { 57 | showCancelMessage(externalSystemTaskId, externalSystemTaskNotificationListener, taskListNames); 58 | return STOP_EXECUTE; 59 | } 60 | } 61 | 62 | private int showConfirmationDialog(List taskNames, String taskListNames, JCheckBox jCheckBox) { 63 | String questionMessage = String.format("Are you sure you want to run %s?", taskListNames); 64 | List componentList = new ArrayList(); 65 | componentList.add(new JLabel(questionMessage)); 66 | if (taskNames.size() == 1) { 67 | componentList.add((JComponent) Box.createVerticalStrut(20)); 68 | componentList.add(jCheckBox); 69 | } 70 | 71 | return JOptionPane.showOptionDialog(null, componentList.toArray(new JComponent[0]), "Gradle Confirmation", 72 | JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, 73 | null, new String[]{"Run", "Cancel"}, null); 74 | } 75 | 76 | private void addToDisableList(List taskNames, Project project, JCheckBox jCheckBox) { 77 | if (jCheckBox.isSelected()) { 78 | GradleConfirmationConfig.addDisableTaskList(project, taskNames.get(0)); 79 | } 80 | } 81 | 82 | private boolean isEnablePlugin(Project project) { 83 | return GradleConfirmationConfig.isSelected(project); 84 | } 85 | 86 | private boolean isDisableTasks(Project project, List taskList) { 87 | return GradleConfirmationConfig.isDistableTaskList(project, taskList); 88 | } 89 | 90 | private void showDisableMessage(ExternalSystemTaskId externalSystemTaskId, 91 | ExternalSystemTaskNotificationListener externalSystemTaskNotificationListener) { 92 | externalSystemTaskNotificationListener.onTaskOutput(externalSystemTaskId, 93 | "To enable Gradle Confirmation dialog, go to Tools > Gradle Confirmation > Edit Disable Tasks...\n", true); 94 | } 95 | 96 | private void showCancelMessage(ExternalSystemTaskId externalSystemTaskId, 97 | ExternalSystemTaskNotificationListener externalSystemTaskNotificationListener, 98 | String taskListNames) { 99 | externalSystemTaskNotificationListener.onTaskOutput(externalSystemTaskId, 100 | String.format("Stop running %s\n", taskListNames), true); 101 | } 102 | 103 | private String createTaskListNames(List taskNames) { 104 | StringBuilder sb = new StringBuilder(); 105 | int size = taskNames.size(); 106 | for (int i = 0; i < size; i++) { 107 | appendSingleQuote(sb); 108 | sb.append(taskNames.get(i)); 109 | appendSingleQuote(sb); 110 | appendCommaWithCondition(sb, i + 1 < size); 111 | } 112 | return sb.toString(); 113 | } 114 | 115 | private void appendSingleQuote(StringBuilder sb) { 116 | sb.append("'"); 117 | } 118 | 119 | private void appendCommaWithCondition(StringBuilder sb, boolean flag) { 120 | if (flag) { 121 | sb.append(", "); 122 | } 123 | } 124 | 125 | @Override 126 | public boolean cancelTask(ExternalSystemTaskId externalSystemTaskId, 127 | ExternalSystemTaskNotificationListener externalSystemTaskNotificationListener) 128 | throws ExternalSystemException { 129 | LOG.debug("cancelTasks"); 130 | 131 | return false; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/com/github/shiraji/gradleconfirmation/view/GradleConfirmationDisableTaskListForm.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | -------------------------------------------------------------------------------- /src/com/github/shiraji/gradleconfirmation/view/GradleConfirmationDisableTaskListForm.java: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.gradleconfirmation.view; 2 | 3 | import javax.swing.JPanel; 4 | 5 | public class GradleConfirmationDisableTaskListForm { 6 | public JPanel mDisableTaskListPanel; 7 | public JPanel mRootPanel; 8 | } 9 | --------------------------------------------------------------------------------