├── .github
├── CONTRIBUTING.md
├── FUNDING.yml
└── ISSUE_TEMPLATE.md
├── .gitignore
├── LICENSE
├── README.md
├── build.xml
├── manifest.mf
├── nbproject
├── build-impl.xml
├── genfiles.properties
├── platform.properties
├── project.properties
└── project.xml
├── pom.xml
└── src
└── org
└── netbeans
└── modules
└── php
└── phpcsfixer
├── Bundle.properties
├── Installer.java
├── commands
└── PhpCsFixer.java
├── onsave
└── PhpCsFixerOnSaveTask.java
├── options
├── Bundle.properties
├── PhpCsFixerOptions.java
├── PhpCsFixerOptionsPanel.form
├── PhpCsFixerOptionsPanel.java
├── PhpCsFixerOptionsPanelController.java
├── PhpCsFixerPanel.form
└── PhpCsFixerPanel.java
├── preferences
└── PhpCsFixerPreferences.java
└── ui
├── UiUtils.java
├── actions
├── Bundle.properties
├── FixAction.java
├── FixDryRunAction.java
├── PhpCsFixerActionsFactory.java
├── PhpCsFixerBaseAction.java
└── SelfUpdateAction.java
└── customizer
├── Bundle.properties
├── PhpCsFixerCustomizerPanel.form
├── PhpCsFixerCustomizerPanel.java
└── PhpCsFixerCustomizerProvider.java
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | ## Questions
4 |
5 | Please don't submit a question as an issue.
6 | If you have some questions, please post them to [my twitter account(@junichi_11)](https://twitter.com/junichi_11)
7 |
8 | ## Issues
9 |
10 | [Submit an Issue](https://github.com/junichi11/netbeans-php-cs-fixer-plugin/issues/new?title=&body=%23%23%23%23%20Overview%20description%0D%0A%0D%0A%23%23%23%23%20Steps%20to%20reproduce%0D%0A1.%20%0D%0A2.%20%0D%0A3.%20%0D%0A%0D%0A%23%23%23%23%20Actual%20results%0D%0A%0D%0A%23%23%23%23%20Expected%20results%0D%0A%0D%0A%23%23%23%23%20Version%20number%20of%20the%20plugin%0D%0A%0D%0A%23%23%23%23%20Version%20information%20of%20NetBeans%0D%0A%0D%0A)
11 |
12 | Please use the following template:
13 |
14 | ```markdown
15 | #### Overview description
16 |
17 | #### Steps to reproduce
18 | 1.
19 | 2.
20 | 3.
21 |
22 | #### Actual results
23 |
24 | #### Expected results
25 |
26 | #### Version number of the plugin
27 |
28 | #### Version information of NetBeans
29 |
30 | ```
31 |
32 | ## Pull Requests
33 |
34 | Please don't send your pull requests to the `master` branch.
35 | Please let me know if the repository has only the `master` branch.
36 |
37 | A branch for development will be named nb** (e.g. nb80).
38 | Please send your pull requests there.
39 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: junichi11
2 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | #### Issue type
2 |
3 | - [x] bug
4 | - [ ] enhancement
5 |
6 | #### Overview description
7 |
8 | #### Steps to reproduce
9 |
10 | 1.
11 | 2.
12 | 3.
13 |
14 | #### Actual results
15 |
16 | #### Expected results
17 |
18 | #### Your environment (NetBeans and plugin version, e.t.c.)
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | nbproject/private
3 | lib
4 | pom.xml.asc
5 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NetBeans PHP CS Fixer Plugin
2 |
3 | This plugin provides support for the PHP CS Fixer.
4 | You can run fix command with this plugin.
5 |
6 | ## PHP CS Fixer
7 |
8 | https://github.com/FriendsOfPHP/PHP-CS-Fixer
9 |
10 | ## Available versions of PHP CS Fixer
11 |
12 | - 1.x
13 | - 2.x (v0.6.0)
14 |
15 | ## Requirements
16 |
17 | - NetBeans 8.2+
18 |
19 | ## Available Commands
20 | - fix
21 | - fix --dry-run
22 | - self-update
23 |
24 | ## Features
25 |
26 | - Run commands
27 | - Run on Save
28 |
29 | ## Settings
30 |
31 | ### Global
32 |
33 | `Tools > Options > PHP > Framework & Tools > PHP CS Fixer`
34 | - set PHP CS Fixer path
35 | - select a version
36 | - set fix command options
37 |
38 | ### Project
39 |
40 | `project properties > PHP CS Fixer`
41 | - If you would like to use settings each projects, please, check `use project settings`
42 |
43 | ### Customizing Options
44 |
45 | If you would like to use some options, please check the custom checkbox, then please add them to it.
46 |
47 | e.g. `--cache-file=/path/to/.php_cs.cache`
48 |
49 | ### Show an output window
50 |
51 | If you would like to avoid showing the output window, please uncheck it. (Checked by default)
52 |
53 | ### Run self-update command on boot
54 |
55 | If you would like to run the self-update command on boot, please check it. (Unchecked by default)
56 |
57 | ## Usage
58 |
59 | 1. Right-click
60 | - Project
61 | - Directory
62 | - File
63 | - Editor
64 | 2. PHP CS Fixer
65 | - fix
66 | - fix --dry-run
67 | - self-update
68 |
69 | ## Download
70 |
71 | - https://plugins.netbeans.apache.org/catalogue/?id=36
72 | - https://github.com/junichi11/netbeans-php-cs-fixer-plugin/releases
73 |
74 | ## NOTE
75 |
76 | - Run on save feature may not work sometimes. Now after 1 second, the command is run. But I don't have another idea at the moment, sorry.
77 |
78 | ## Donation
79 |
80 | - https://github.com/sponsors/junichi11
81 |
82 | ## License
83 |
84 | The Apache License, Version 2.0
85 |
86 | ```
87 | Copyright 2022 junichi11.
88 |
89 | Licensed under the Apache License, Version 2.0 (the "License");
90 | you may not use this file except in compliance with the License.
91 | You may obtain a copy of the License at
92 |
93 | http://www.apache.org/licenses/LICENSE-2.0
94 |
95 | Unless required by applicable law or agreed to in writing, software
96 | distributed under the License is distributed on an "AS IS" BASIS,
97 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
98 | See the License for the specific language governing permissions and
99 | limitations under the License.
100 | ```
101 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Builds, tests, and runs the project org.netbeans.modules.php.phpcsfixer.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
32 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/manifest.mf:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | OpenIDE-Module: org.netbeans.modules.php.phpcsfixer
3 | OpenIDE-Module-Install: org/netbeans/modules/php/phpcsfixer/Installer.class
4 | OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/phpcsfixer/Bundle.properties
5 | OpenIDE-Module-Specification-Version: 0.12.0
6 |
--------------------------------------------------------------------------------
/nbproject/build-impl.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/nbproject/genfiles.properties:
--------------------------------------------------------------------------------
1 | build.xml.data.CRC32=25909fbc
2 | build.xml.script.CRC32=fd14ba45
3 | build.xml.stylesheet.CRC32=a56c6a5b@2.56.1
4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6 | nbproject/build-impl.xml.data.CRC32=25909fbc
7 | nbproject/build-impl.xml.script.CRC32=c04a25d5
8 | nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.56.1
9 |
--------------------------------------------------------------------------------
/nbproject/platform.properties:
--------------------------------------------------------------------------------
1 | cluster.path=\
2 | ${nbplatform.active.dir}/nb:\
3 | ${nbplatform.active.dir}/platform:\
4 | ${nbplatform.active.dir}/apisupport:\
5 | ${nbplatform.active.dir}/php:\
6 | ${nbplatform.active.dir}/ide:\
7 | ${nbplatform.active.dir}/websvccommon:\
8 | ${nbplatform.active.dir}/webcommon:\
9 | ${nbplatform.active.dir}/java:\
10 | ${nbplatform.active.dir}/harness
11 | nbplatform.active=default
12 |
--------------------------------------------------------------------------------
/nbproject/project.properties:
--------------------------------------------------------------------------------
1 | javac.source=1.8
2 | javac.compilerargs=-Xlint -Xlint:-serial
3 | license.file=LICENSE
4 | nbm.homepage=https://github.com/junichi11/netbeans-php-cs-fixer-plugin
5 | nbm.module.author=junichi11
6 | project.license=cddl-netbeans-sun
7 | keystore=nbproject/private/keystore
8 | nbm_alias=phpcsfixer
9 |
--------------------------------------------------------------------------------
/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.apisupport.project
4 |
5 |
6 | org.netbeans.modules.php.phpcsfixer
7 |
8 |
9 |
10 | org.netbeans.api.templates
11 |
12 |
13 |
14 | 1.7.1
15 |
16 |
17 |
18 | org.netbeans.modules.editor
19 |
20 |
21 |
22 | 3
23 | 1.70.2.5.21.40
24 |
25 |
26 |
27 | org.netbeans.modules.editor.document
28 |
29 |
30 |
31 | 1.9.1.3
32 |
33 |
34 |
35 | org.netbeans.modules.editor.lib
36 |
37 |
38 |
39 | 3
40 | 4.7.2.24.3.56
41 |
42 |
43 |
44 | org.netbeans.modules.editor.lib2
45 |
46 |
47 |
48 | 1
49 | 1.71.2.40
50 |
51 |
52 |
53 | org.netbeans.modules.editor.mimelookup
54 |
55 |
56 |
57 | 1
58 | 1.29.1
59 |
60 |
61 |
62 | org.netbeans.modules.extexecution
63 |
64 |
65 |
66 | 2
67 | 1.36.1
68 |
69 |
70 |
71 | org.netbeans.modules.extexecution.base
72 |
73 |
74 |
75 | 2
76 | 1.4.1
77 |
78 |
79 |
80 | org.netbeans.modules.options.api
81 |
82 |
83 |
84 | 1
85 | 1.31.1
86 |
87 |
88 |
89 | org.netbeans.modules.php.api.executable
90 |
91 |
92 |
93 | 0
94 | 0.19.1
95 |
96 |
97 |
98 | org.netbeans.modules.php.api.phpmodule
99 |
100 |
101 |
102 | 2.26.1
103 |
104 |
105 |
106 | org.netbeans.modules.projectapi
107 |
108 |
109 |
110 | 1
111 | 1.50.1
112 |
113 |
114 |
115 | org.netbeans.modules.projectuiapi
116 |
117 |
118 |
119 | 1
120 | 1.65.1.8
121 |
122 |
123 |
124 | org.netbeans.modules.projectuiapi.base
125 |
126 |
127 |
128 | 1
129 | 1.83.1.9
130 |
131 |
132 |
133 | org.openide.awt
134 |
135 |
136 |
137 | 7.55.1
138 |
139 |
140 |
141 | org.openide.dialogs
142 |
143 |
144 |
145 | 7.42.1
146 |
147 |
148 |
149 | org.openide.filesystems
150 |
151 |
152 |
153 | 8.5.1
154 |
155 |
156 |
157 | org.openide.filesystems.compat8
158 |
159 |
160 |
161 | 9.9.1
162 |
163 |
164 |
165 | org.openide.filesystems.nb
166 |
167 |
168 |
169 | 9.6.1
170 |
171 |
172 |
173 | org.openide.io
174 |
175 |
176 |
177 | 1.49.1
178 |
179 |
180 |
181 | org.openide.loaders
182 |
183 |
184 |
185 | 7.44.2
186 |
187 |
188 |
189 | org.openide.modules
190 |
191 |
192 |
193 | 7.48.1
194 |
195 |
196 |
197 | org.openide.nodes
198 |
199 |
200 |
201 | 7.33.1
202 |
203 |
204 |
205 | org.openide.text
206 |
207 |
208 |
209 | 6.54.2
210 |
211 |
212 |
213 | org.openide.util
214 |
215 |
216 |
217 | 8.29.2
218 |
219 |
220 |
221 | org.openide.util.lookup
222 |
223 |
224 |
225 | 8.19.1
226 |
227 |
228 |
229 | org.openide.util.ui
230 |
231 |
232 |
233 | 9.3.1
234 |
235 |
236 |
237 |
238 |
239 | unit
240 |
241 | org.netbeans.libs.junit4
242 |
243 |
244 |
245 | org.netbeans.modules.nbjunit
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.junichi11.netbeans.modules
5 | netbeans-php-cs-fixer
6 |
7 | 0.12.0
8 | nbm
9 | NetBeans PHP CS Fixer
10 | https://github.com/junichi11/netbeans-php-cs-fixer-plugin
11 | This plugin provides support for the PHP CS Fixer.
12 |
13 |
14 | junichi11
15 | Junichi Yamamoto
16 | https://github.com/junichi11
17 |
18 |
19 |
20 | scm:git:https://github.com/junichi11/netbeans-php-cs-fixer-plugin.git
21 | scm:git:https://github.com/junichi11/netbeans-php-cs-fixer-plugin.git
22 | https://github.com/junichi11/netbeans-php-cs-fixer-plugin
23 | HEAD
24 |
25 |
26 |
27 | Apache License, Version 2.0
28 | https://www.apache.org/licenses/LICENSE-2.0
29 |
30 |
31 |
32 |
33 | ossrh
34 | https://oss.sonatype.org/content/repositories/snapshots
35 |
36 |
37 | ossrh
38 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
39 |
40 |
41 |
42 |
43 |
44 | org.apache.maven.plugins
45 | maven-deploy-plugin
46 | 3.0.0-M1
47 |
48 |
49 | org.sonatype.plugins
50 | nexus-staging-maven-plugin
51 | 1.6.7
52 | true
53 |
54 | ossrh
55 | https://oss.sonatype.org/
56 | true
57 |
58 |
59 |
60 | org.apache.maven.plugins
61 | maven-compiler-plugin
62 | 3.8.1
63 |
64 | 1.8
65 | 1.8
66 |
67 |
68 |
69 | org.apache.maven.plugins
70 | maven-jar-plugin
71 | 3.1.2
72 |
73 |
74 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF
75 |
76 |
77 |
78 |
79 | org.apache.maven.plugins
80 | maven-gpg-plugin
81 | 1.6
82 |
83 |
84 | sign-artifacts
85 | verify
86 |
87 | sign
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/Bundle.properties:
--------------------------------------------------------------------------------
1 | OpenIDE-Module-Display-Category=PHP
2 | OpenIDE-Module-Long-Description=\
3 | Provides support for PHP CS Fixer.\n\
4 |
\n
fix
\n
fix --dry-run
\n
self-update
\n
5 | OpenIDE-Module-Name=PHP CS Fixer
6 | OpenIDE-Module-Short-Description=Support for PHP CS Fixer
7 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/Installer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer;
17 |
18 | import static java.util.logging.Level.INFO;
19 | import static java.util.logging.Level.WARNING;
20 | import java.util.logging.Logger;
21 | import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
22 | import org.netbeans.modules.php.api.util.StringUtils;
23 | import org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer;
24 | import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptions;
25 | import org.openide.modules.ModuleInstall;
26 |
27 | public class Installer extends ModuleInstall {
28 |
29 | private static final Logger LOGGER = Logger.getLogger(Installer.class.getName());
30 |
31 | @Override
32 | public void restored() {
33 | PhpCsFixerOptions options = PhpCsFixerOptions.getInstance();
34 | String phpCsFixerPath = options.getPhpCsFixerPath();
35 | if (!StringUtils.isEmpty(phpCsFixerPath) && options.runSelfUpdateOnBoot()) {
36 | try {
37 | PhpCsFixer.newInstance(phpCsFixerPath, true).selfUpdate(null);
38 | LOGGER.log(INFO, "PHP-CS-FIXER: Run self-update"); // NOI18N
39 | } catch (InvalidPhpExecutableException ex) {
40 | LOGGER.log(WARNING, ex.getMessage());
41 | }
42 | }
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/commands/PhpCsFixer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.commands;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.Collections;
21 | import java.util.List;
22 | import java.util.concurrent.ExecutionException;
23 | import java.util.concurrent.Future;
24 | import java.util.logging.Level;
25 | import java.util.logging.Logger;
26 | import org.netbeans.api.extexecution.ExecutionDescriptor;
27 | import org.netbeans.api.extexecution.base.input.InputProcessor;
28 | import org.netbeans.api.extexecution.base.input.InputProcessors;
29 | import org.netbeans.api.extexecution.base.input.LineProcessor;
30 | import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
31 | import org.netbeans.modules.php.api.executable.PhpExecutable;
32 | import org.netbeans.modules.php.api.executable.PhpExecutableValidator;
33 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
34 | import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptions;
35 | import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptionsPanelController;
36 | import org.openide.filesystems.FileObject;
37 | import org.openide.filesystems.FileUtil;
38 | import org.openide.util.Exceptions;
39 | import org.openide.util.NbBundle;
40 | import org.openide.windows.InputOutput;
41 |
42 | /**
43 | * @see https://github.com/FriendsOfPHP/PHP-CS-Fixer
44 | * @author junichi11
45 | */
46 | public final class PhpCsFixer {
47 |
48 | // PHP CS Fixer
49 | public static final String NAME = "php-cs-fixer"; // NOI18N
50 | public static final String NAME_LONG = NAME + ".phar"; // NOI18N
51 | public static final String DOWNLOAD_URL = "https://cs.symfony.com/download/php-cs-fixer-v3.phar"; // NOI18N
52 | private final String phpcsfixerPath;
53 | private boolean isDryRun;
54 | private boolean useSilentDescriptor;
55 | // commands
56 | private static final String FIX_COMMAND = "fix"; // NOI18N
57 | private static final String SELF_UPDATE_COMMAND = "self-update"; // NOI18N
58 | //parameters
59 | private static final String VERSION_PARAM = "--version"; // NOI18N
60 | public static final String DRY_RUN_PARAM = "--dry-run"; // NOI18N
61 | public static final String VERBOSE_PARAM = "--verbose"; // NOI18N
62 | public static final String DIFF_PARAM = "--diff"; // NOI18N
63 | // 1.x
64 | public static final String CONFIG_PARAM = "--config=%s"; // NOI18N
65 | public static final String LEVEL_PARAM = "--level=%s"; // NOI18N
66 | public static final String FIXERS_PARAM = "--fixers=%s"; // NOI18N
67 | // 2.x
68 | public static final String RULES_PARAM = "--rules=%s"; // NOI18N
69 | public static final String DIFF_FORMAT_UDIFF_PARAM = "--diff-format=udiff"; // NOI18N
70 | private static final List DEFAULT_PARAMS = Arrays.asList(
71 | "--ansi", // NOI18N
72 | "--no-interaction"); // NOI18N
73 |
74 | private static final ExecutionDescriptor DEFAULT_EXECUTION_DESCRIPTOR = new ExecutionDescriptor()
75 | .optionsPath(PhpCsFixerOptionsPanelController.getOptionsPath())
76 | .controllable(true)
77 | .frontWindow(true)
78 | .frontWindowOnError(true)
79 | .inputVisible(false)
80 | .showProgress(true);
81 |
82 | private static final ExecutionDescriptor NO_OUTPUT_EXECUTION_DESCRIPTOR = new ExecutionDescriptor()
83 | .inputOutput(InputOutput.NULL);
84 | private static final Logger LOGGER = Logger.getLogger(PhpCsFixer.class.getName());
85 |
86 | private PhpCsFixer(String phpcsfixerPath) {
87 | this(phpcsfixerPath, false);
88 | }
89 |
90 | private PhpCsFixer(String phpcsfixerPath, boolean useSilentDescriptor) {
91 | this.phpcsfixerPath = phpcsfixerPath;
92 | this.useSilentDescriptor = useSilentDescriptor;
93 | this.isDryRun = false;
94 | }
95 |
96 | public static PhpCsFixer getDefault() throws InvalidPhpExecutableException {
97 | String phpcsfixerPath = PhpCsFixerOptions.getInstance().getPhpCsFixerPath();
98 | return newInstance(phpcsfixerPath);
99 | }
100 |
101 | public static PhpCsFixer newInstance(String scriptPath) throws InvalidPhpExecutableException {
102 | return newInstance(scriptPath, false);
103 | }
104 |
105 | public static PhpCsFixer newInstance(String scriptPath, boolean useSilentDescriptor) throws InvalidPhpExecutableException {
106 | String warning = validate(scriptPath);
107 | if (warning != null) {
108 | LOGGER.log(Level.WARNING, "PHP CS Fixer path is not set."); // NOI18N
109 | throw new InvalidPhpExecutableException(warning);
110 | }
111 | return new PhpCsFixer(scriptPath, useSilentDescriptor);
112 | }
113 |
114 | @NbBundle.Messages("PhpCsFixer.script.label=PHP CS Fixer")
115 | private static String validate(String phpcsfixerPath) {
116 | return PhpExecutableValidator.validateCommand(phpcsfixerPath, Bundle.PhpCsFixer_script_label());
117 | }
118 |
119 | @NbBundle.Messages({
120 | "# {0} - command name",
121 | "PhpCsFixer.run=PHP CS Fixer ({0})"
122 | })
123 | public Future fix(PhpModule phpModule, String... params) {
124 | return runCommand(phpModule, FIX_COMMAND, Bundle.PhpCsFixer_run(FIX_COMMAND), Arrays.asList(params));
125 | }
126 |
127 | public Future fixDryRun(PhpModule phpModule, String... params) {
128 | isDryRun = true;
129 | List allParams = new ArrayList<>(params.length + 1);
130 | allParams.addAll(Arrays.asList(params));
131 | allParams.add(DRY_RUN_PARAM);
132 | return runCommand(phpModule, FIX_COMMAND, Bundle.PhpCsFixer_run(FIX_COMMAND + " " + DRY_RUN_PARAM), allParams);
133 | }
134 |
135 | public Future selfUpdate(PhpModule phpModule) {
136 | return runCommand(phpModule, SELF_UPDATE_COMMAND, Bundle.PhpCsFixer_run(SELF_UPDATE_COMMAND));
137 | }
138 |
139 | /**
140 | * Get version.
141 | *
142 | * @return version
143 | */
144 | public String getVersion() {
145 | DefaultLineProcessor lineProcessor = new DefaultLineProcessor();
146 | Future result = getPhpExecutable(null, "version")
147 | .additionalParameters(Arrays.asList(VERSION_PARAM))
148 | .run(NO_OUTPUT_EXECUTION_DESCRIPTOR, getOutputProcessorFactory(lineProcessor));
149 | try {
150 | if (result != null) {
151 | result.get();
152 | }
153 | } catch (InterruptedException ex) {
154 | Thread.currentThread().interrupt();
155 | } catch (ExecutionException ex) {
156 | Exceptions.printStackTrace(ex);
157 | }
158 | return lineProcessor.getResult();
159 | }
160 |
161 | private Future runCommand(PhpModule phpModule, String command, String title) {
162 | return runCommand(phpModule, command, title, Collections.emptyList());
163 | }
164 |
165 | private Future runCommand(PhpModule phpModule, String command, String title, List params) {
166 | PhpExecutable phpcsfixer = getPhpExecutable(phpModule, title);
167 | if (phpcsfixer == null) {
168 | return null;
169 | }
170 | return phpcsfixer
171 | .additionalParameters(mergeParameters(command, DEFAULT_PARAMS, params))
172 | .run(getDescriptor(phpModule));
173 | }
174 |
175 | private List mergeParameters(String command, List defaultParams, List params) {
176 | List allParams = new ArrayList<>(defaultParams.size() + params.size() + 1);
177 | allParams.add(command);
178 | allParams.addAll(params);
179 | allParams.addAll(defaultParams);
180 | return allParams;
181 | }
182 |
183 | private PhpExecutable getPhpExecutable(PhpModule phpModule, String title) {
184 | FileObject sourceDirectory = null;
185 | if (phpModule != null) {
186 | sourceDirectory = phpModule.getSourceDirectory();
187 | }
188 | PhpExecutable phpcsfixer = new PhpExecutable(phpcsfixerPath)
189 | .optionsSubcategory(PhpCsFixerOptionsPanelController.OPTIONS_SUBPATH)
190 | .displayName(title);
191 | if (sourceDirectory != null) {
192 | phpcsfixer.workDir(FileUtil.toFile(sourceDirectory));
193 | }
194 | return phpcsfixer;
195 | }
196 |
197 | private ExecutionDescriptor getDescriptor(PhpModule phpModule) {
198 | ExecutionDescriptor descriptor;
199 | if (useSilentDescriptor) {
200 | descriptor = NO_OUTPUT_EXECUTION_DESCRIPTOR;
201 | } else if (PhpCsFixerOptions.getInstance().showOutputWindow() || isDryRun) {
202 | descriptor = DEFAULT_EXECUTION_DESCRIPTOR;
203 | } else {
204 | descriptor = NO_OUTPUT_EXECUTION_DESCRIPTOR;
205 | }
206 | descriptor = descriptor.postExecution(() -> {});
207 | if (phpModule != null) {
208 | final FileObject sourceDirectory = phpModule.getSourceDirectory();
209 | if (sourceDirectory != null) {
210 | descriptor = descriptor.postExecution(() -> {
211 | // refresh sources after running command
212 | sourceDirectory.refresh();
213 | });
214 | }
215 | }
216 | return descriptor;
217 | }
218 |
219 | /**
220 | * Get InputProcessorFactory.
221 | *
222 | * @param lineProcessor
223 | * @return InputProcessorFactory
224 | */
225 | private ExecutionDescriptor.InputProcessorFactory2 getOutputProcessorFactory(final LineProcessor lineProcessor) {
226 | return (InputProcessor defaultProcessor) -> InputProcessors.ansiStripping(InputProcessors.bridge(lineProcessor));
227 | }
228 |
229 | private static class DefaultLineProcessor implements LineProcessor {
230 |
231 | private final StringBuilder result = new StringBuilder();
232 | private final List list = new ArrayList<>();
233 |
234 | @Override
235 | public void processLine(String line) {
236 | list.add(line);
237 | if (!list.isEmpty()) {
238 | result.append("\n"); // NOI18N
239 | }
240 | result.append(line);
241 | }
242 |
243 | @Override
244 | public void reset() {
245 | }
246 |
247 | @Override
248 | public void close() {
249 | }
250 |
251 | public String getResult() {
252 | return result.toString();
253 | }
254 |
255 | public List asLines() {
256 | return list;
257 | }
258 | }
259 | }
260 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/onsave/PhpCsFixerOnSaveTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.onsave;
17 |
18 | import java.util.concurrent.TimeUnit;
19 | import java.util.logging.Level;
20 | import java.util.logging.Logger;
21 | import javax.swing.text.Document;
22 | import org.netbeans.api.editor.mimelookup.MimeRegistration;
23 | import org.netbeans.modules.editor.NbEditorUtilities;
24 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
25 | import org.netbeans.modules.php.api.util.FileUtils;
26 | import org.netbeans.modules.php.api.util.StringUtils;
27 | import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptions;
28 | import org.netbeans.modules.php.phpcsfixer.preferences.PhpCsFixerPreferences;
29 | import org.netbeans.modules.php.phpcsfixer.ui.actions.FixAction;
30 | import org.netbeans.spi.editor.document.OnSaveTask;
31 | import org.openide.filesystems.FileObject;
32 | import org.openide.util.RequestProcessor;
33 |
34 | /**
35 | *
36 | * @author junichi11
37 | */
38 | public final class PhpCsFixerOnSaveTask implements OnSaveTask {
39 |
40 | private final Context context;
41 | private static final RequestProcessor RP = new RequestProcessor(PhpCsFixerOnSaveTask.class);
42 | private static final Logger LOGGER = Logger.getLogger(PhpCsFixerOnSaveTask.class.getName());
43 |
44 | private PhpCsFixerOnSaveTask(Context context) {
45 | this.context = context;
46 | }
47 |
48 | @Override
49 | public void performTask() {
50 | String path = PhpCsFixerOptions.getInstance().getPhpCsFixerPath();
51 | if (StringUtils.isEmpty(path)) {
52 | LOGGER.log(Level.WARNING, "Not found : PHP CS Fixer (Please, set PHP CS Fixer path to Options)"); // NOI18N
53 | return;
54 | }
55 | Document document = context.getDocument();
56 | final FileObject fileObject = NbEditorUtilities.getFileObject(document);
57 | if (fileObject != null) {
58 | // check run on save option
59 | boolean isRunOnSave;
60 | final PhpModule phpModule = PhpModule.Factory.forFileObject(fileObject);
61 | if (phpModule != null && PhpCsFixerPreferences.useProject(phpModule)) {
62 | isRunOnSave = PhpCsFixerPreferences.isRunOnSave(phpModule);
63 | } else {
64 | isRunOnSave = PhpCsFixerOptions.getInstance().isRunOnSave();
65 | }
66 | if (!isRunOnSave) {
67 | return;
68 | }
69 |
70 | // XXX Run command after 1 second
71 | // Somethimes it may not work
72 | RP.schedule(() -> {
73 | FixAction fixAction = new FixAction();
74 | fixAction.actionPerformed(null, fileObject);
75 | LOGGER.log(Level.FINE, "Run php-cs-fixer: {0}", fileObject.getNameExt()); // NOI18N
76 | }, 1000, TimeUnit.MILLISECONDS);
77 | }
78 | }
79 |
80 | @Override
81 | public void runLocked(Runnable r) {
82 | r.run();
83 | }
84 |
85 | @Override
86 | public boolean cancel() {
87 | return true;
88 | }
89 |
90 | @MimeRegistration(mimeType = FileUtils.PHP_MIME_TYPE, service = OnSaveTask.Factory.class, position = 5000)
91 | public static final class FactoryImpl implements Factory {
92 |
93 | @Override
94 | public OnSaveTask createTask(Context context) {
95 | return new PhpCsFixerOnSaveTask(context);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/options/Bundle.properties:
--------------------------------------------------------------------------------
1 | PhpCsFixerOptionsPanel.levelCheckBox.text=--level=
2 | PhpCsFixerOptionsPanel.runOnSaveCheckBox.text=run on save
3 | PhpCsFixerOptionsPanel.customTextField.text=
4 | PhpCsFixerOptionsPanel.customCheckBox.text=custom
5 | PhpCsFixerOptionsPanel.configCheckBox.text=--config=
6 | PhpCsFixerPanel.pathTextField.text=
7 | PhpCsFixerPanel.pathLabel.text=PHP CS Fixer
8 | PhpCsFixerPanel.browseButton.text=Browse...
9 | PhpCsFixerPanel.phpCsFixerNameLabel.text=path to php-cs-fixer (php-cs-fixer or php-cs-fixer.phar)
10 | PhpCsFixerOptionsPanel.fixersCheckBox.text=--fixers=
11 | PhpCsFixerOptionsPanel.fixersTextField.text=
12 | PhpCsFixerPanel.downloadButton.text=Download...
13 | PhpCsFixerOptionsPanel.verboseCheckBox.text=--verbose
14 | PhpCsFixerOptionsPanel.diffCheckBox.text=--diff
15 | PhpCsFixerOptionsPanel.dryRunLabel.text=--dry-run
16 | PhpCsFixerOptionsPanel.versionLabel.text=Version:
17 | PhpCsFixerOptionsPanel.rulesCheckBox.text=--rules=
18 | PhpCsFixerOptionsPanel.rulesTextField.text=
19 | PhpCsFixerPanel.showOutputWindowCheckBox.text=Show an output window
20 | PhpCsFixerOptionsPanel.diffFormatUdiffCheckBox.text=--diff-format=udiff
21 | PhpCsFixerPanel.selfUpdateButton.text=Self Update
22 | PhpCsFixerPanel.runSelfUpdateOnBootCheckBox.text=Run self-update command on boot
23 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.options;
17 |
18 | import java.io.File;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import java.util.prefs.Preferences;
22 | import org.netbeans.modules.php.api.util.FileUtils;
23 | import org.netbeans.modules.php.api.util.StringUtils;
24 | import org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer;
25 | import org.openide.util.NbPreferences;
26 |
27 | /**
28 | *
29 | * @author junichi11
30 | */
31 | public final class PhpCsFixerOptions {
32 |
33 | private static final PhpCsFixerOptions INSTANCE = new PhpCsFixerOptions();
34 | private static final String PREFERENCES_PATH = "php-cs-fixer"; // NOI18N
35 | private static final String PHP_CS_FIXER_PATH = "php-cs-fixer.path"; // NOI18N
36 | private static final String PHP_CS_FIXER_VERSION = "php-cs-fixer.version"; // NOI18N
37 | private static final String RUN_ON_SAVE = "run.on.save"; // NOI18N
38 | // php-cs-fixer options
39 | private static final String USE_LEVEL = "use.level"; // NOI18N
40 | private static final String LEVEL = "level"; // NOI18N
41 | private static final String USE_CONFIG = "use.config"; // NOI18N
42 | private static final String CONFIG = "config"; // NOI18N
43 | private static final String USE_FIXERS = "use.fixers"; // NOI18N
44 | private static final String FIXERS = "fixers"; // NOI18N
45 | // 2.x
46 | private static final String USE_RULES = "use.rules"; // NOI18N
47 | private static final String RULES = "rules"; // NOI18N
48 | private static final String DIFF_FORMAT_UDIFF = "diff.format.udiff"; // NOI18N
49 | // common
50 | private static final String USE_CUSTOM = "use.custom"; // NOI18N
51 | private static final String CUSTOM = "custom"; // NOI18N
52 | private static final String VERBOSE = "verbose"; // NOI18N
53 | private static final String DIFF = "diff"; // NOI18N
54 | private static final String SHOW_OUTPUT_WINDOW = "show.output.window"; // NOI18N
55 | private static final String RUN_SELF_UPDATE_ON_BOOT = "run.self.update.on.boot"; // NOI18N
56 | private volatile boolean phpcsfixerSearched = false;
57 |
58 | public static final int LATEST_VERSION = 3;
59 |
60 | private PhpCsFixerOptions() {
61 | }
62 |
63 | public static PhpCsFixerOptions getInstance() {
64 | return INSTANCE;
65 | }
66 |
67 | public String getPhpCsFixerPath() {
68 | String phpcsfixerPath = getPreferences().get(PHP_CS_FIXER_PATH, null);
69 | if (phpcsfixerPath == null && !phpcsfixerSearched) {
70 | phpcsfixerSearched = true;
71 | List paths = FileUtils.findFileOnUsersPath(PhpCsFixer.NAME, PhpCsFixer.NAME_LONG);
72 | if (!paths.isEmpty()) {
73 | phpcsfixerPath = paths.get(0);
74 | setPhpCsFixerPath(phpcsfixerPath);
75 | }
76 | }
77 |
78 | // check whether file exists
79 | if (!StringUtils.isEmpty(phpcsfixerPath)) {
80 | File file = new File(phpcsfixerPath);
81 | if (!file.exists()) {
82 | phpcsfixerPath = ""; // NOI18N
83 | setPhpCsFixerPath(phpcsfixerPath);
84 | }
85 | }
86 |
87 | return phpcsfixerPath;
88 | }
89 |
90 | public void setPhpCsFixerPath(String path) {
91 | getPreferences().put(PHP_CS_FIXER_PATH, path);
92 | }
93 |
94 | public int getVersion() {
95 | int version = getPreferences().getInt(PHP_CS_FIXER_VERSION, LATEST_VERSION);
96 | if (version <= 0 || LATEST_VERSION < version) {
97 | version = LATEST_VERSION;
98 | }
99 | return version;
100 | }
101 |
102 | public void setVersion(int version) {
103 | getPreferences().putInt(PHP_CS_FIXER_VERSION, version);
104 | }
105 |
106 | // version 1.x
107 | public boolean useLevel() {
108 | return getPreferences().getBoolean(USE_LEVEL, false);
109 | }
110 |
111 | public void setLevel(boolean use) {
112 | getPreferences().putBoolean(USE_LEVEL, use);
113 | }
114 |
115 | public String getLevel() {
116 | return getPreferences().get(LEVEL, ""); // NOI18N
117 | }
118 |
119 | public void setLevel(String level) {
120 | getPreferences().put(LEVEL, level);
121 | }
122 |
123 | public boolean useConfig() {
124 | return getPreferences().getBoolean(USE_CONFIG, false);
125 | }
126 |
127 | public void setConfig(boolean use) {
128 | getPreferences().putBoolean(USE_CONFIG, use);
129 | }
130 |
131 | public String getConfig() {
132 | return getPreferences().get(CONFIG, ""); // NOI18N
133 | }
134 |
135 | public void setConfig(String config) {
136 | getPreferences().put(CONFIG, config);
137 | }
138 |
139 | public boolean useFixers() {
140 | return getPreferences().getBoolean(USE_FIXERS, false);
141 | }
142 |
143 | public void setFixers(boolean use) {
144 | getPreferences().putBoolean(USE_FIXERS, use);
145 | }
146 |
147 | public String getFixers() {
148 | return getPreferences().get(FIXERS, ""); // NOI18N
149 | }
150 |
151 | public void setFixers(String fixers) {
152 | getPreferences().put(FIXERS, fixers);
153 | }
154 |
155 | // 2.x
156 | public boolean useRules() {
157 | return getPreferences().getBoolean(USE_RULES, false);
158 | }
159 |
160 | public void setRules(boolean use) {
161 | getPreferences().putBoolean(USE_RULES, use);
162 | }
163 |
164 | public String getRules() {
165 | return getPreferences().get(RULES, ""); // NOI18N
166 | }
167 |
168 | public void setRules(String rules) {
169 | getPreferences().put(RULES, rules);
170 | }
171 |
172 | // common
173 | public boolean useCustom() {
174 | return getPreferences().getBoolean(USE_CUSTOM, false);
175 | }
176 |
177 | public void setCustom(boolean use) {
178 | getPreferences().putBoolean(USE_CUSTOM, use);
179 | }
180 |
181 | public String getCustom() {
182 | return getPreferences().get(CUSTOM, ""); // NOI18N
183 | }
184 |
185 | public void setCustom(String custom) {
186 | getPreferences().put(CUSTOM, custom);
187 | }
188 |
189 | public boolean isRunOnSave() {
190 | return getPreferences().getBoolean(RUN_ON_SAVE, false);
191 | }
192 |
193 | public void setRunOnSave(boolean isRunOnSave) {
194 | getPreferences().putBoolean(RUN_ON_SAVE, isRunOnSave);
195 | }
196 |
197 | public boolean isVerbose() {
198 | return getPreferences().getBoolean(VERBOSE, false);
199 | }
200 |
201 | public void setVerbose(boolean isVerbose) {
202 | getPreferences().putBoolean(VERBOSE, isVerbose);
203 | }
204 |
205 | public boolean isDiff() {
206 | return getPreferences().getBoolean(DIFF, false);
207 | }
208 |
209 | public void setDiff(boolean isDiff) {
210 | getPreferences().putBoolean(DIFF, isDiff);
211 | }
212 |
213 | public boolean isDiffFormatUdiff() {
214 | return getPreferences().getBoolean(DIFF_FORMAT_UDIFF, false);
215 | }
216 |
217 | public void setDiffFormatUdiff(boolean isUdiff) {
218 | getPreferences().putBoolean(DIFF_FORMAT_UDIFF, isUdiff);
219 | }
220 |
221 | public boolean showOutputWindow() {
222 | return getPreferences().getBoolean(SHOW_OUTPUT_WINDOW, true);
223 | }
224 |
225 | public void setShowOutputWindow(boolean show) {
226 | getPreferences().putBoolean(SHOW_OUTPUT_WINDOW, show);
227 | }
228 |
229 | public boolean runSelfUpdateOnBoot() {
230 | return getPreferences().getBoolean(RUN_SELF_UPDATE_ON_BOOT, true);
231 | }
232 |
233 | public void setRunSelfUpdateOnBoot(boolean run) {
234 | getPreferences().putBoolean(RUN_SELF_UPDATE_ON_BOOT, run);
235 | }
236 |
237 | public List getAllOptions() {
238 | List all = new ArrayList<>();
239 | if (getVersion() == 2) {
240 | if (useRules() && !getRules().isEmpty()) {
241 | all.add(String.format(PhpCsFixer.RULES_PARAM, getRules()));
242 | }
243 | } else {
244 | if (useLevel() && !getLevel().isEmpty()) {
245 | all.add(String.format(PhpCsFixer.LEVEL_PARAM, getLevel()));
246 | }
247 | if (useConfig() && !getConfig().isEmpty()) {
248 | all.add(String.format(PhpCsFixer.CONFIG_PARAM, getConfig()));
249 | }
250 | if (useFixers() && !getFixers().isEmpty()) {
251 | all.add(String.format(PhpCsFixer.FIXERS_PARAM, getFixers()));
252 | }
253 | }
254 | if (useCustom() && !getCustom().isEmpty()) {
255 | all.addAll(StringUtils.explode(getCustom(), " ")); // NOI18N
256 | }
257 |
258 | return all;
259 | }
260 |
261 | private Preferences getPreferences() {
262 | return NbPreferences.forModule(PhpCsFixerOptions.class).node(PREFERENCES_PATH);
263 | }
264 | }
265 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerOptionsPanel.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
257 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerOptionsPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.options;
17 |
18 | import java.awt.event.ItemEvent;
19 | import java.awt.event.ItemListener;
20 | import java.util.Arrays;
21 | import java.util.List;
22 | import javax.swing.DefaultComboBoxModel;
23 | import javax.swing.GroupLayout;
24 | import javax.swing.JCheckBox;
25 | import javax.swing.JComboBox;
26 | import javax.swing.JLabel;
27 | import javax.swing.JSeparator;
28 | import javax.swing.JTextField;
29 | import javax.swing.LayoutStyle;
30 | import org.openide.awt.Mnemonics;
31 | import org.openide.util.NbBundle;
32 |
33 | /**
34 | *
35 | * @author junichi11
36 | */
37 | public class PhpCsFixerOptionsPanel extends javax.swing.JPanel {
38 |
39 | private static final long serialVersionUID = 388435168100294200L;
40 | private static final List VERSIONS = Arrays.asList(1, 2, 3);
41 |
42 | /**
43 | * Creates new form PhpCsFixerOptionsPanel
44 | */
45 | public PhpCsFixerOptionsPanel() {
46 | initComponents();
47 | init();
48 | }
49 |
50 | private void init() {
51 | VERSIONS.forEach((version) -> {
52 | versionComboBox.addItem(version);
53 | });
54 | }
55 |
56 | public int getVersion() {
57 | return (Integer) versionComboBox.getSelectedItem();
58 | }
59 |
60 | public void setVersion(int version) {
61 | versionComboBox.setSelectedItem(version);
62 | }
63 |
64 | public boolean useConfig() {
65 | return configCheckBox.isSelected();
66 | }
67 |
68 | public void setConfig(boolean use) {
69 | configCheckBox.setSelected(use);
70 | }
71 |
72 | public String getConfig() {
73 | return (String) configComboBox.getSelectedItem();
74 | }
75 |
76 | public void setConfig(String config) {
77 | configComboBox.setSelectedItem(config);
78 | }
79 |
80 | public JComboBox getConfigComboBox() {
81 | return configComboBox;
82 | }
83 |
84 | // 1.x
85 | public boolean useFixers() {
86 | return fixersCheckBox.isSelected();
87 | }
88 |
89 | public void setFixers(boolean use) {
90 | fixersCheckBox.setSelected(use);
91 | }
92 |
93 | public String getFixers() {
94 | return fixersTextField.getText();
95 | }
96 |
97 | public void setFixers(String fixersText) {
98 | fixersTextField.setText(fixersText);
99 | }
100 |
101 | public boolean useLevel() {
102 | return levelCheckBox.isSelected();
103 | }
104 |
105 | public void setLevel(boolean use) {
106 | levelCheckBox.setSelected(use);
107 | }
108 |
109 | public String getLevel() {
110 | return (String) levelComboBox.getSelectedItem();
111 | }
112 |
113 | public void setLevel(String levelItem) {
114 | levelComboBox.setSelectedItem(levelItem);
115 | }
116 |
117 | // 2.x
118 | public boolean useRules() {
119 | return rulesCheckBox.isSelected();
120 | }
121 |
122 | public void setRules(boolean use) {
123 | rulesCheckBox.setSelected(use);
124 | }
125 |
126 | public String getRules() {
127 | return rulesTextField.getText();
128 | }
129 |
130 | public void setRules(String rulesText) {
131 | rulesTextField.setText(rulesText);
132 | }
133 |
134 | // common
135 | public boolean useCustom() {
136 | return customCheckBox.isSelected();
137 | }
138 |
139 | public void setCustom(boolean use) {
140 | customCheckBox.setSelected(use);
141 | }
142 |
143 | public String getCustom() {
144 | return customTextField.getText();
145 | }
146 |
147 | public void setCustom(String options) {
148 | customTextField.setText(options);
149 | }
150 |
151 | public boolean isRunOnSave() {
152 | return runOnSaveCheckBox.isSelected();
153 | }
154 |
155 | public void setRunOnSave(boolean use) {
156 | runOnSaveCheckBox.setSelected(use);
157 | }
158 |
159 | public boolean isVerbose() {
160 | return verboseCheckBox.isSelected();
161 | }
162 |
163 | public void setVerbose(boolean isVerbose) {
164 | verboseCheckBox.setSelected(isVerbose);
165 | }
166 |
167 | public boolean isDiff() {
168 | return diffCheckBox.isSelected();
169 | }
170 |
171 | public void setDiff(boolean isDiff) {
172 | diffCheckBox.setSelected(isDiff);
173 | }
174 |
175 | public boolean isDiffFormatUdiff() {
176 | return diffFormatUdiffCheckBox.isSelected();
177 | }
178 |
179 | public void setDiffFormatUdiff(boolean isUdiff) {
180 | diffFormatUdiffCheckBox.setSelected(isUdiff);
181 | }
182 |
183 | private void setVersion1ComponentsVisible(boolean isVisible) {
184 | levelCheckBox.setVisible(isVisible);
185 | levelComboBox.setVisible(isVisible);
186 | configCheckBox.setVisible(isVisible);
187 | configComboBox.setVisible(isVisible);
188 | fixersCheckBox.setVisible(isVisible);
189 | fixersTextField.setVisible(isVisible);
190 | }
191 |
192 | private void setVersion2ComponentsVisible(boolean isVisible) {
193 | rulesCheckBox.setVisible(isVisible);
194 | rulesTextField.setVisible(isVisible);
195 | diffFormatUdiffCheckBox.setVisible(isVisible);
196 | }
197 |
198 | private void setVersion3ComponentsVisible(boolean isVisible) {
199 | rulesCheckBox.setVisible(isVisible);
200 | rulesTextField.setVisible(isVisible);
201 | }
202 |
203 | /**
204 | * This method is called from within the constructor to initialize the form.
205 | * WARNING: Do NOT modify this code. The content of this method is always
206 | * regenerated by the Form Editor.
207 | */
208 | @SuppressWarnings("unchecked")
209 | // //GEN-BEGIN:initComponents
210 | private void initComponents() {
211 |
212 | levelCheckBox = new JCheckBox();
213 | levelComboBox = new JComboBox<>();
214 | configCheckBox = new JCheckBox();
215 | configComboBox = new JComboBox<>();
216 | fixersCheckBox = new JCheckBox();
217 | fixersTextField = new JTextField();
218 | customCheckBox = new JCheckBox();
219 | customTextField = new JTextField();
220 | runOnSaveCheckBox = new JCheckBox();
221 | dryRunLabel = new JLabel();
222 | dryRunSeparator = new JSeparator();
223 | verboseCheckBox = new JCheckBox();
224 | diffCheckBox = new JCheckBox();
225 | versionLabel = new JLabel();
226 | versionComboBox = new JComboBox<>();
227 | rulesCheckBox = new JCheckBox();
228 | rulesTextField = new JTextField();
229 | diffFormatUdiffCheckBox = new JCheckBox();
230 |
231 | Mnemonics.setLocalizedText(levelCheckBox, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.levelCheckBox.text")); // NOI18N
232 |
233 | levelComboBox.setModel(new DefaultComboBoxModel(new String[] { "", "psr0", "psr1", "psr2", "symfony"}));
234 |
235 | Mnemonics.setLocalizedText(configCheckBox, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.configCheckBox.text")); // NOI18N
236 |
237 | configComboBox.setEditable(true);
238 | configComboBox.setModel(new DefaultComboBoxModel(new String[] { "", "default", "magento", "sf23"}));
239 |
240 | Mnemonics.setLocalizedText(fixersCheckBox, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.fixersCheckBox.text")); // NOI18N
241 |
242 | fixersTextField.setText(NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.fixersTextField.text")); // NOI18N
243 |
244 | Mnemonics.setLocalizedText(customCheckBox, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.customCheckBox.text")); // NOI18N
245 |
246 | customTextField.setText(NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.customTextField.text")); // NOI18N
247 |
248 | Mnemonics.setLocalizedText(runOnSaveCheckBox, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.runOnSaveCheckBox.text")); // NOI18N
249 |
250 | Mnemonics.setLocalizedText(dryRunLabel, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.dryRunLabel.text")); // NOI18N
251 |
252 | Mnemonics.setLocalizedText(verboseCheckBox, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.verboseCheckBox.text")); // NOI18N
253 |
254 | Mnemonics.setLocalizedText(diffCheckBox, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.diffCheckBox.text")); // NOI18N
255 |
256 | Mnemonics.setLocalizedText(versionLabel, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.versionLabel.text")); // NOI18N
257 |
258 | versionComboBox.addItemListener(new ItemListener() {
259 | public void itemStateChanged(ItemEvent evt) {
260 | versionComboBoxItemStateChanged(evt);
261 | }
262 | });
263 |
264 | Mnemonics.setLocalizedText(rulesCheckBox, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.rulesCheckBox.text")); // NOI18N
265 |
266 | rulesTextField.setText(NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.rulesTextField.text")); // NOI18N
267 |
268 | Mnemonics.setLocalizedText(diffFormatUdiffCheckBox, NbBundle.getMessage(PhpCsFixerOptionsPanel.class, "PhpCsFixerOptionsPanel.diffFormatUdiffCheckBox.text")); // NOI18N
269 |
270 | GroupLayout layout = new GroupLayout(this);
271 | this.setLayout(layout);
272 | layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
273 | .addGroup(layout.createSequentialGroup()
274 | .addContainerGap()
275 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
276 | .addGroup(layout.createSequentialGroup()
277 | .addComponent(dryRunLabel)
278 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
279 | .addComponent(dryRunSeparator))
280 | .addGroup(layout.createSequentialGroup()
281 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
282 | .addComponent(levelCheckBox)
283 | .addComponent(configCheckBox)
284 | .addComponent(fixersCheckBox)
285 | .addComponent(customCheckBox)
286 | .addComponent(versionLabel)
287 | .addComponent(rulesCheckBox))
288 | .addGap(18, 18, 18)
289 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
290 | .addComponent(fixersTextField)
291 | .addComponent(customTextField)
292 | .addGroup(layout.createSequentialGroup()
293 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
294 | .addComponent(levelComboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
295 | .addComponent(configComboBox, GroupLayout.PREFERRED_SIZE, 140, GroupLayout.PREFERRED_SIZE)
296 | .addComponent(versionComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
297 | .addGap(0, 228, Short.MAX_VALUE))
298 | .addComponent(rulesTextField)))
299 | .addGroup(layout.createSequentialGroup()
300 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
301 | .addComponent(runOnSaveCheckBox)
302 | .addGroup(layout.createSequentialGroup()
303 | .addComponent(verboseCheckBox)
304 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
305 | .addComponent(diffCheckBox)
306 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
307 | .addComponent(diffFormatUdiffCheckBox)))
308 | .addGap(0, 0, Short.MAX_VALUE)))
309 | .addContainerGap())
310 | );
311 | layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
312 | .addGroup(layout.createSequentialGroup()
313 | .addContainerGap()
314 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
315 | .addComponent(versionLabel)
316 | .addComponent(versionComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
317 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
318 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
319 | .addComponent(levelComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
320 | .addComponent(levelCheckBox))
321 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
322 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
323 | .addComponent(configCheckBox)
324 | .addComponent(configComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
325 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
326 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
327 | .addComponent(fixersCheckBox)
328 | .addComponent(fixersTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
329 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
330 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
331 | .addComponent(rulesCheckBox)
332 | .addComponent(rulesTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
333 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
334 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
335 | .addComponent(customCheckBox)
336 | .addComponent(customTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
337 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
338 | .addComponent(runOnSaveCheckBox)
339 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
340 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
341 | .addComponent(dryRunLabel)
342 | .addComponent(dryRunSeparator, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE))
343 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
344 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
345 | .addComponent(verboseCheckBox)
346 | .addComponent(diffCheckBox)
347 | .addComponent(diffFormatUdiffCheckBox))
348 | .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
349 | );
350 | }// //GEN-END:initComponents
351 |
352 | private void versionComboBoxItemStateChanged(ItemEvent evt) {//GEN-FIRST:event_versionComboBoxItemStateChanged
353 | Integer item = (Integer) evt.getItem();
354 | if (item == 2) {
355 | setVersion1ComponentsVisible(false);
356 | setVersion3ComponentsVisible(false);
357 | setVersion2ComponentsVisible(true);
358 | } else if (item == 3) {
359 | setVersion1ComponentsVisible(false);
360 | setVersion2ComponentsVisible(false);
361 | setVersion3ComponentsVisible(true);
362 | } else {
363 | setVersion1ComponentsVisible(true);
364 | setVersion2ComponentsVisible(false);
365 | setVersion3ComponentsVisible(false);
366 | }
367 | }//GEN-LAST:event_versionComboBoxItemStateChanged
368 |
369 | // Variables declaration - do not modify//GEN-BEGIN:variables
370 | private JCheckBox configCheckBox;
371 | private JComboBox configComboBox;
372 | private JCheckBox customCheckBox;
373 | private JTextField customTextField;
374 | private JCheckBox diffCheckBox;
375 | private JCheckBox diffFormatUdiffCheckBox;
376 | private JLabel dryRunLabel;
377 | private JSeparator dryRunSeparator;
378 | private JCheckBox fixersCheckBox;
379 | private JTextField fixersTextField;
380 | private JCheckBox levelCheckBox;
381 | private JComboBox levelComboBox;
382 | private JCheckBox rulesCheckBox;
383 | private JTextField rulesTextField;
384 | private JCheckBox runOnSaveCheckBox;
385 | private JCheckBox verboseCheckBox;
386 | private JComboBox versionComboBox;
387 | private JLabel versionLabel;
388 | // End of variables declaration//GEN-END:variables
389 | }
390 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerOptionsPanelController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.options;
17 |
18 | import java.beans.PropertyChangeListener;
19 | import java.beans.PropertyChangeSupport;
20 | import javax.swing.JComponent;
21 | import org.netbeans.modules.php.api.util.UiUtils;
22 | import org.netbeans.spi.options.OptionsPanelController;
23 | import org.openide.util.HelpCtx;
24 | import org.openide.util.Lookup;
25 | import org.openide.util.NbBundle;
26 |
27 | @UiUtils.PhpOptionsPanelRegistration(
28 | id = PhpCsFixerOptionsPanelController.ID,
29 | displayName = "#LBL_PhpCsFixerOptionsName",
30 | position = 2010
31 | )
32 | @NbBundle.Messages({
33 | "LBL_PhpCsFixerOptionsName=PHP CS Fixer",
34 | "PhpCsFixer.options.keywords.TabTitle=Frameworks & Tools"
35 | })
36 | @OptionsPanelController.Keywords(keywords = {"php", "php cs fixer", "php coding standards fixer"},
37 | location = UiUtils.OPTIONS_PATH, tabTitle = "#PhpCsFixer.options.keywords.TabTitle")
38 | public final class PhpCsFixerOptionsPanelController extends OptionsPanelController {
39 |
40 | public static final String ID = "PHP-CS-Fixer"; // NOI18N
41 | public static final String OPTIONS_SUBPATH = "PHPCSFixer"; // NOI18N
42 | private PhpCsFixerPanel panel;
43 | private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
44 | private boolean changed;
45 |
46 | public static String getOptionsPath() {
47 | return UiUtils.FRAMEWORKS_AND_TOOLS_OPTIONS_PATH;
48 | }
49 |
50 | @Override
51 | public void update() {
52 | getPanel().load();
53 | changed = false;
54 | }
55 |
56 | @Override
57 | public void applyChanges() {
58 | getPanel().store();
59 | changed = false;
60 | }
61 |
62 | @Override
63 | public void cancel() {
64 | // need not do anything special, if no changes have been persisted yet
65 | }
66 |
67 | @Override
68 | public boolean isValid() {
69 | return getPanel().valid();
70 | }
71 |
72 | @Override
73 | public boolean isChanged() {
74 | return changed;
75 | }
76 |
77 | @Override
78 | public HelpCtx getHelpCtx() {
79 | return null; // new HelpCtx("...ID") if you have a help set
80 | }
81 |
82 | @Override
83 | public JComponent getComponent(Lookup masterLookup) {
84 | return getPanel();
85 | }
86 |
87 | @Override
88 | public void addPropertyChangeListener(PropertyChangeListener l) {
89 | pcs.addPropertyChangeListener(l);
90 | }
91 |
92 | @Override
93 | public void removePropertyChangeListener(PropertyChangeListener l) {
94 | pcs.removePropertyChangeListener(l);
95 | }
96 |
97 | private PhpCsFixerPanel getPanel() {
98 | if (panel == null) {
99 | panel = new PhpCsFixerPanel(this);
100 | }
101 | return panel;
102 | }
103 |
104 | void changed() {
105 | if (!changed) {
106 | changed = true;
107 | pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);
108 | }
109 | pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerPanel.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
156 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.options;
17 |
18 | import java.awt.EventQueue;
19 | import java.awt.event.ActionEvent;
20 | import java.awt.event.ActionListener;
21 | import java.io.File;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.io.InputStream;
25 | import java.net.MalformedURLException;
26 | import java.net.URL;
27 | import java.util.concurrent.ExecutionException;
28 | import java.util.concurrent.Future;
29 | import static java.util.logging.Level.INFO;
30 | import static java.util.logging.Level.WARNING;
31 | import java.util.logging.Logger;
32 | import javax.swing.GroupLayout;
33 | import javax.swing.JButton;
34 | import javax.swing.JCheckBox;
35 | import javax.swing.JLabel;
36 | import javax.swing.JTextField;
37 | import javax.swing.LayoutStyle;
38 | import javax.swing.SwingUtilities;
39 | import javax.swing.filechooser.FileFilter;
40 | import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
41 | import org.netbeans.modules.php.api.util.FileUtils;
42 | import org.netbeans.modules.php.api.util.StringUtils;
43 | import org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer;
44 | import org.netbeans.modules.php.phpcsfixer.ui.UiUtils;
45 | import org.openide.awt.Mnemonics;
46 | import org.openide.filesystems.FileChooserBuilder;
47 | import org.openide.filesystems.FileObject;
48 | import org.openide.filesystems.FileUtil;
49 | import org.openide.util.NbBundle;
50 | import org.openide.util.RequestProcessor;
51 |
52 | final class PhpCsFixerPanel extends javax.swing.JPanel {
53 |
54 | private static final long serialVersionUID = 8727885479187122174L;
55 | private final PhpCsFixerOptionsPanelController controller;
56 | private static final String PHPCSFIXER_LAST_FOLDER_SUFFIX = ".phpcsfixer"; // NOI18N
57 | private static final RequestProcessor RP = new RequestProcessor(PhpCsFixerPanel.class);
58 | private static final Logger LOGGER = Logger.getLogger(PhpCsFixerPanel.class.getName());
59 |
60 | private int version;
61 | // 1.x
62 | private boolean useLevel;
63 | private boolean useConfig;
64 | private boolean useFixers;
65 | private String level;
66 | private String config;
67 | private String fixers;
68 | // 2.x
69 | private boolean useRules;
70 | private boolean isDiffFormatUdiff;
71 | private String rules;
72 | // common
73 | private boolean useCustom;
74 | private boolean showOutputWindow;
75 | private boolean runSelfUpdateOnBoot;
76 | private boolean isRunOnSave;
77 | private boolean isVerbose;
78 | private boolean isDiff;
79 | private String custom;
80 |
81 | PhpCsFixerPanel(PhpCsFixerOptionsPanelController controller) {
82 | this.controller = controller;
83 | initComponents();
84 | setVersion(""); // NOI18N
85 | }
86 |
87 | /**
88 | * This method is called from within the constructor to initialize the form.
89 | * WARNING: Do NOT modify this code. The content of this method is always
90 | * regenerated by the Form Editor.
91 | */
92 | // //GEN-BEGIN:initComponents
93 | private void initComponents() {
94 |
95 | pathLabel = new JLabel();
96 | pathTextField = new JTextField();
97 | browseButton = new JButton();
98 | phpCsFixerNameLabel = new JLabel();
99 | optionsPanel = new PhpCsFixerOptionsPanel();
100 | downloadButton = new JButton();
101 | showOutputWindowCheckBox = new JCheckBox();
102 | versionLabel = new JLabel();
103 | selfUpdateButton = new JButton();
104 | runSelfUpdateOnBootCheckBox = new JCheckBox();
105 |
106 | Mnemonics.setLocalizedText(pathLabel, NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.pathLabel.text")); // NOI18N
107 |
108 | pathTextField.setText(NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.pathTextField.text")); // NOI18N
109 |
110 | Mnemonics.setLocalizedText(browseButton, NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.browseButton.text")); // NOI18N
111 | browseButton.addActionListener(new ActionListener() {
112 | public void actionPerformed(ActionEvent evt) {
113 | browseButtonActionPerformed(evt);
114 | }
115 | });
116 |
117 | Mnemonics.setLocalizedText(phpCsFixerNameLabel, NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.phpCsFixerNameLabel.text")); // NOI18N
118 |
119 | Mnemonics.setLocalizedText(downloadButton, NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.downloadButton.text")); // NOI18N
120 | downloadButton.addActionListener(new ActionListener() {
121 | public void actionPerformed(ActionEvent evt) {
122 | downloadButtonActionPerformed(evt);
123 | }
124 | });
125 |
126 | Mnemonics.setLocalizedText(showOutputWindowCheckBox, NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.showOutputWindowCheckBox.text")); // NOI18N
127 |
128 | Mnemonics.setLocalizedText(versionLabel, "VERSION"); // NOI18N
129 |
130 | Mnemonics.setLocalizedText(selfUpdateButton, NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.selfUpdateButton.text")); // NOI18N
131 | selfUpdateButton.addActionListener(new ActionListener() {
132 | public void actionPerformed(ActionEvent evt) {
133 | selfUpdateButtonActionPerformed(evt);
134 | }
135 | });
136 |
137 | Mnemonics.setLocalizedText(runSelfUpdateOnBootCheckBox, NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.runSelfUpdateOnBootCheckBox.text")); // NOI18N
138 |
139 | GroupLayout layout = new GroupLayout(this);
140 | this.setLayout(layout);
141 | layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
142 | .addComponent(optionsPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
143 | .addGroup(layout.createSequentialGroup()
144 | .addContainerGap()
145 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
146 | .addGroup(layout.createSequentialGroup()
147 | .addComponent(pathLabel)
148 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
149 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
150 | .addGroup(layout.createSequentialGroup()
151 | .addComponent(phpCsFixerNameLabel)
152 | .addGap(0, 0, Short.MAX_VALUE))
153 | .addGroup(layout.createSequentialGroup()
154 | .addComponent(pathTextField)
155 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
156 | .addComponent(browseButton, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
157 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
158 | .addComponent(downloadButton)
159 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
160 | .addComponent(selfUpdateButton))))
161 | .addGroup(layout.createSequentialGroup()
162 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
163 | .addComponent(showOutputWindowCheckBox)
164 | .addComponent(versionLabel)
165 | .addComponent(runSelfUpdateOnBootCheckBox))
166 | .addGap(0, 0, Short.MAX_VALUE)))
167 | .addContainerGap())
168 | );
169 | layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
170 | .addGroup(layout.createSequentialGroup()
171 | .addContainerGap()
172 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
173 | .addComponent(pathLabel)
174 | .addComponent(pathTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
175 | .addComponent(browseButton)
176 | .addComponent(downloadButton)
177 | .addComponent(selfUpdateButton))
178 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
179 | .addComponent(phpCsFixerNameLabel)
180 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
181 | .addComponent(versionLabel)
182 | .addGap(10, 10, 10)
183 | .addComponent(showOutputWindowCheckBox)
184 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
185 | .addComponent(runSelfUpdateOnBootCheckBox)
186 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
187 | .addComponent(optionsPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
188 | .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
189 | );
190 | }// //GEN-END:initComponents
191 |
192 | @NbBundle.Messages("LBL_SelectPhpCsFixer=Select PHP CS Fixer")
193 | private void browseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
194 | File phpcsfixer = new FileChooserBuilder(PhpCsFixerPanel.class.getName() + PHPCSFIXER_LAST_FOLDER_SUFFIX)
195 | .setTitle(Bundle.LBL_SelectPhpCsFixer())
196 | .setFilesOnly(true)
197 | .setFileFilter(new FileFilterImpl())
198 | .showOpenDialog();
199 | if (phpcsfixer != null) {
200 | phpcsfixer = FileUtil.normalizeFile(phpcsfixer);
201 | if (phpcsfixer.getName().equals(PhpCsFixer.NAME_LONG)
202 | || phpcsfixer.getName().equals(PhpCsFixer.NAME)
203 | || phpcsfixer.getName().equals(PhpCsFixer.NAME + FileUtils.getScriptExtension(true))) {
204 | setPath(phpcsfixer.getAbsolutePath());
205 | } else {
206 | setPath(""); // NOI18N
207 | }
208 | }
209 | }//GEN-LAST:event_browseButtonActionPerformed
210 |
211 | @NbBundle.Messages("LBL_SelectDonwloadFolder=Select download folder")
212 | private void downloadButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_downloadButtonActionPerformed
213 | File downloadDirectory = new FileChooserBuilder(PhpCsFixerPanel.class.getName() + PHPCSFIXER_LAST_FOLDER_SUFFIX)
214 | .setTitle(Bundle.LBL_SelectDonwloadFolder())
215 | .setDirectoriesOnly(true)
216 | .showOpenDialog();
217 | if (downloadDirectory != null) {
218 | downloadDirectory = FileUtil.normalizeFile(downloadDirectory);
219 | // has phpcsfixer file?
220 | FileObject downloadFileObject = FileUtil.toFileObject(downloadDirectory);
221 | FileObject[] children = downloadFileObject.getChildren();
222 | for (FileObject child : children) {
223 | if (!child.isFolder() && child.getNameExt().equals(PhpCsFixer.NAME_LONG)) {
224 | LOGGER.log(INFO, PhpCsFixer.NAME_LONG + " already exists in {0} directory.", downloadFileObject.getName()); // NOI18N
225 | UiUtils.showErrorMessage(String.format(PhpCsFixer.NAME_LONG + " already exists in %s directory.", downloadFileObject.getName())); // NOI18N
226 | try {
227 | setPath(FileUtil.toFile(child).getCanonicalPath());
228 | } catch (IOException ex) {
229 | LOGGER.log(WARNING, ex.getMessage());
230 | }
231 | return;
232 | }
233 | }
234 |
235 | // create file
236 | File file = new File(downloadDirectory, PhpCsFixer.NAME_LONG);
237 | try (FileOutputStream outputStream = new FileOutputStream(file)) {
238 | URL downloadUrl = new URL(PhpCsFixer.DOWNLOAD_URL);
239 | InputStream inputStream = downloadUrl.openStream();
240 | int data;
241 | while ((data = inputStream.read()) != -1) {
242 | outputStream.write(data);
243 | }
244 | String filePath = file.getCanonicalPath();
245 | setPath(filePath);
246 | // run self-update because it might be an old version
247 | selfUpdate(filePath);
248 | } catch (MalformedURLException ex) {
249 | if (file.exists()) {
250 | file.delete();
251 | }
252 | LOGGER.log(WARNING, "Download URL may be changed.", ex); // NOI18N
253 | } catch (IOException ex) {
254 | if (file.exists()) {
255 | file.delete();
256 | }
257 | downloadButton.setEnabled(false);
258 | }
259 | }
260 | }//GEN-LAST:event_downloadButtonActionPerformed
261 |
262 | @NbBundle.Messages("PhpCsFixerPanel.selfupdate.warning.message=Please set a file path")
263 | private void selfUpdateButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_selfUpdateButtonActionPerformed
264 | if (StringUtils.isEmpty(getPath())) {
265 | UiUtils.showWarningMessage(Bundle.PhpCsFixerPanel_selfupdate_warning_message());
266 | } else {
267 | selfUpdate(getPath());
268 | }
269 | }//GEN-LAST:event_selfUpdateButtonActionPerformed
270 |
271 | void load() {
272 | PhpCsFixerOptions options = getOptions();
273 | setPath(options.getPhpCsFixerPath());
274 | setShowOutputWindow(options.showOutputWindow());
275 |
276 | // original options
277 | version = options.getVersion();
278 | showOutputWindow = options.showOutputWindow();
279 | runSelfUpdateOnBoot = options.runSelfUpdateOnBoot();
280 |
281 | // 1.x
282 | useLevel = options.useLevel();
283 | level = options.getLevel();
284 | useConfig = options.useConfig();
285 | config = options.getConfig();
286 | useFixers = options.useFixers();
287 | fixers = options.getFixers();
288 |
289 | // 2.x
290 | useRules = options.useRules();
291 | rules = options.getRules();
292 | isDiffFormatUdiff = options.isDiffFormatUdiff();
293 |
294 | // common
295 | useCustom = options.useCustom();
296 | custom = options.getCustom();
297 | isRunOnSave = options.isRunOnSave();
298 | isVerbose = options.isVerbose();
299 | isDiff = options.isDiff();
300 |
301 | optionsPanel.setVersion(version);
302 | // 1.x
303 | optionsPanel.setLevel(useLevel);
304 | optionsPanel.setLevel(level);
305 | optionsPanel.setConfig(useConfig);
306 | optionsPanel.setConfig(config);
307 | optionsPanel.setFixers(useFixers);
308 | optionsPanel.setFixers(fixers);
309 |
310 | // 2.x
311 | optionsPanel.setRules(useRules);
312 | optionsPanel.setRules(rules);
313 | optionsPanel.setDiffFormatUdiff(isDiffFormatUdiff);
314 |
315 | // common
316 | optionsPanel.setCustom(useCustom);
317 | optionsPanel.setCustom(custom);
318 | optionsPanel.setRunOnSave(isRunOnSave);
319 | optionsPanel.setVerbose(isVerbose);
320 | optionsPanel.setDiff(isDiff);
321 | downloadButton.setEnabled(true);
322 | }
323 |
324 | void store() {
325 | PhpCsFixerOptions options = getOptions();
326 | String path = getPath();
327 | if (path.endsWith(PhpCsFixer.NAME)
328 | || path.endsWith(PhpCsFixer.NAME_LONG)
329 | || path.endsWith(PhpCsFixer.NAME + FileUtils.getScriptExtension(true))) {
330 | options.setPhpCsFixerPath(getPath());
331 | } else {
332 | options.setPhpCsFixerPath(""); // NOI18N
333 | }
334 |
335 | if (showOutputWindow != showOutputWindow()) {
336 | options.setShowOutputWindow(showOutputWindow());
337 | }
338 |
339 | if (runSelfUpdateOnBoot != runSelfUpdateOnBoot()) {
340 | options.setRunSelfUpdateOnBoot(runSelfUpdateOnBoot());
341 | }
342 |
343 | if (version != optionsPanel.getVersion()) {
344 | options.setVersion(optionsPanel.getVersion());
345 | }
346 | // 1.x
347 | if (useLevel != optionsPanel.useLevel()) {
348 | options.setLevel(optionsPanel.useLevel());
349 | }
350 | if (!level.equals(optionsPanel.getLevel())) {
351 | options.setLevel(optionsPanel.getLevel());
352 | }
353 | if (useConfig != optionsPanel.useConfig()) {
354 | options.setConfig(optionsPanel.useConfig());
355 | }
356 | if (!config.equals(optionsPanel.getConfig())) {
357 | options.setConfig(optionsPanel.getConfig());
358 | }
359 | if (useFixers != optionsPanel.useFixers()) {
360 | options.setFixers(optionsPanel.useFixers());
361 | }
362 | if (!fixers.equals(optionsPanel.getFixers())) {
363 | options.setFixers(optionsPanel.getFixers());
364 | }
365 | // 2.x
366 | if (useRules != optionsPanel.useRules()) {
367 | options.setRules(optionsPanel.useRules());
368 | }
369 | if (!rules.equals(optionsPanel.getRules())) {
370 | options.setRules(optionsPanel.getRules());
371 | }
372 | if (useCustom != optionsPanel.useCustom()) {
373 | options.setCustom(optionsPanel.useCustom());
374 | }
375 | if (isDiffFormatUdiff != optionsPanel.isDiffFormatUdiff()) {
376 | options.setDiffFormatUdiff(optionsPanel.isDiffFormatUdiff());
377 | }
378 | // common
379 | if (!custom.equals(optionsPanel.getCustom())) {
380 | options.setCustom(optionsPanel.getCustom());
381 | }
382 | if (isRunOnSave != optionsPanel.isRunOnSave()) {
383 | options.setRunOnSave(optionsPanel.isRunOnSave());
384 | }
385 | if (isVerbose != optionsPanel.isVerbose()) {
386 | options.setVerbose(optionsPanel.isVerbose());
387 | }
388 | if (isDiff != optionsPanel.isDiff()) {
389 | options.setDiff(optionsPanel.isDiff());
390 | }
391 | }
392 |
393 | private PhpCsFixerOptions getOptions() {
394 | return PhpCsFixerOptions.getInstance();
395 | }
396 |
397 | public void setPath(String path) {
398 | pathTextField.setText(path);
399 | // set version
400 | if (!StringUtils.isEmpty(path)) {
401 | reloadVersion(path);
402 | } else {
403 | setVersion(""); // NOI18N
404 | }
405 | }
406 |
407 | public String getPath() {
408 | return pathTextField.getText().trim();
409 | }
410 |
411 | public void setVersion(String version) {
412 | versionLabel.setText(String.format("%s", version)); // NOI18N
413 | }
414 |
415 | public String getVersion() {
416 | return versionLabel.getText();
417 | }
418 |
419 | public void setShowOutputWindow(boolean show) {
420 | showOutputWindowCheckBox.setSelected(show);
421 | }
422 |
423 | public boolean showOutputWindow() {
424 | return showOutputWindowCheckBox.isSelected();
425 | }
426 |
427 | public void setRunSelfUpdateOnBoot(boolean run) {
428 | runSelfUpdateOnBootCheckBox.setSelected(run);
429 | }
430 |
431 | public boolean runSelfUpdateOnBoot() {
432 | return runSelfUpdateOnBootCheckBox.isSelected();
433 | }
434 |
435 | private void selfUpdate(String filePath) {
436 | RP.post(() -> {
437 | try {
438 | Future future = PhpCsFixer.newInstance(filePath).selfUpdate(null);
439 | Integer get = future.get();
440 | reloadVersion(filePath);
441 | } catch (InvalidPhpExecutableException ex) {
442 | UiUtils.showWarningMessage(ex.getMessage());
443 | } catch (InterruptedException ex) {
444 | Thread.currentThread().interrupt();
445 | } catch (ExecutionException ex) {
446 | LOGGER.log(WARNING, null, ex);
447 | }
448 | });
449 | }
450 |
451 | @NbBundle.Messages("PhpCsFixerPanel.loading.version=Loading...")
452 | private void reloadVersion(String path) {
453 | if (!EventQueue.isDispatchThread()) {
454 | SwingUtilities.invokeLater(() -> setVersion(Bundle.PhpCsFixerPanel_loading_version()));
455 | }
456 | RP.post(() -> {
457 | try {
458 | String ver = PhpCsFixer.newInstance(path).getVersion();
459 | SwingUtilities.invokeLater(() -> setVersion(ver));
460 | } catch (InvalidPhpExecutableException ex) {
461 | SwingUtilities.invokeLater(() -> setVersion("")); // NOI18N
462 | LOGGER.log(WARNING, ex.getMessage());
463 | }
464 | });
465 | }
466 |
467 | boolean valid() {
468 | // TODO check whether form is consistent and complete
469 | String path = pathTextField.getText();
470 | return !StringUtils.isEmpty(path);
471 | }
472 |
473 | // Variables declaration - do not modify//GEN-BEGIN:variables
474 | private JButton browseButton;
475 | private JButton downloadButton;
476 | private PhpCsFixerOptionsPanel optionsPanel;
477 | private JLabel pathLabel;
478 | private JTextField pathTextField;
479 | private JLabel phpCsFixerNameLabel;
480 | private JCheckBox runSelfUpdateOnBootCheckBox;
481 | private JButton selfUpdateButton;
482 | private JCheckBox showOutputWindowCheckBox;
483 | private JLabel versionLabel;
484 | // End of variables declaration//GEN-END:variables
485 |
486 | private static class FileFilterImpl extends FileFilter {
487 |
488 | public FileFilterImpl() {
489 | }
490 |
491 | @Override
492 | public boolean accept(File f) {
493 | if (f.isDirectory()) {
494 | return true;
495 | }
496 | String name = f.getName();
497 | return f.isFile() && name.startsWith(PhpCsFixer.NAME);
498 | }
499 |
500 | @Override
501 | public String getDescription() {
502 | return PhpCsFixer.NAME + " or " + PhpCsFixer.NAME_LONG; // NOI18N
503 | }
504 | }
505 | }
506 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/preferences/PhpCsFixerPreferences.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.preferences;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.prefs.Preferences;
21 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
22 | import org.netbeans.modules.php.api.util.StringUtils;
23 | import org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer;
24 | import static org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptions.LATEST_VERSION;
25 |
26 | /**
27 | *
28 | * @author junichi11
29 | */
30 | public final class PhpCsFixerPreferences {
31 |
32 | private static final String USE_GLOBAL = "use-global"; // NOI18N
33 | private static final String USE_PROJECT = "use-project"; // NOI18N
34 | private static final String RUN_ON_SAVE = "run-on-save"; // NOI18N
35 | // php-cs-fixer options
36 | private static final String VERSION = "version"; // NOI18N
37 | // 1.x
38 | private static final String USE_LEVEL = "use-level"; // NOI18N
39 | private static final String LEVEL = "level"; // NOI18N
40 | private static final String USE_CONFIG = "use-config"; // NOI18N
41 | private static final String CONFIG = "config"; // NOI18N
42 | private static final String USE_FIXERS = "use-fixers"; // NOI18N
43 | private static final String FIXERS = "fixers"; // NOI18N
44 | private static final String USE_CUSTOM = "use-custom"; // NOI18N
45 | // 2.x
46 | private static final String USE_RULES = "use-rules"; // NOI18N
47 | private static final String RULES = "rules"; // NOI18N
48 | private static final String DIFF_FORMAT_UDIFF = "diff-format-udiff"; // NOI18N
49 | // common
50 | private static final String CUSTOM = "custom"; // NOI18N
51 | private static final String VERBOSE = "verbose"; // NOI18N
52 | private static final String DIFF = "diff"; // NOI18N
53 |
54 | private PhpCsFixerPreferences() {
55 | }
56 |
57 | public static boolean useGlobal(PhpModule phpModule) {
58 | return getPreferences(phpModule).getBoolean(USE_GLOBAL, true);
59 | }
60 |
61 | public static void setGlobal(PhpModule phpModule, boolean use) {
62 | getPreferences(phpModule).putBoolean(USE_GLOBAL, use);
63 | }
64 |
65 | public static boolean useProject(PhpModule phpModule) {
66 | return getPreferences(phpModule).getBoolean(USE_PROJECT, false);
67 | }
68 |
69 | public static void setProject(PhpModule phpModule, boolean use) {
70 | getPreferences(phpModule).putBoolean(USE_PROJECT, use);
71 | }
72 |
73 | public static int getVersion(PhpModule phpModule) {
74 | int version = getPreferences(phpModule).getInt(VERSION, LATEST_VERSION);
75 | if (version <= 0 || LATEST_VERSION < version) {
76 | version = LATEST_VERSION;
77 | }
78 | return version;
79 | }
80 |
81 | public static void setVersion(PhpModule phpModule, int version) {
82 | getPreferences(phpModule).putInt(VERSION, version);
83 | }
84 |
85 | // 1.x
86 | public static boolean useLevel(PhpModule phpModule) {
87 | return getPreferences(phpModule).getBoolean(USE_LEVEL, false);
88 | }
89 |
90 | public static void setLevel(PhpModule phpModule, boolean use) {
91 | getPreferences(phpModule).putBoolean(USE_LEVEL, use);
92 | }
93 |
94 | public static String getLevel(PhpModule phpModule) {
95 | return getPreferences(phpModule).get(LEVEL, ""); // NOI18N
96 | }
97 |
98 | public static void setLevel(PhpModule phpModule, String level) {
99 | getPreferences(phpModule).put(LEVEL, level);
100 | }
101 |
102 | public static boolean useConfig(PhpModule phpModule) {
103 | return getPreferences(phpModule).getBoolean(USE_CONFIG, false);
104 | }
105 |
106 | public static void setConfig(PhpModule phpModule, boolean use) {
107 | getPreferences(phpModule).putBoolean(USE_CONFIG, use);
108 | }
109 |
110 | public static String getConfig(PhpModule phpModule) {
111 | return getPreferences(phpModule).get(CONFIG, ""); // NOI18N
112 | }
113 |
114 | public static void setConfig(PhpModule phpModule, String config) {
115 | getPreferences(phpModule).put(CONFIG, config);
116 | }
117 |
118 | public static boolean useFixers(PhpModule phpModule) {
119 | return getPreferences(phpModule).getBoolean(USE_FIXERS, false);
120 | }
121 |
122 | public static void setFixers(PhpModule phpModule, boolean use) {
123 | getPreferences(phpModule).putBoolean(USE_FIXERS, use);
124 | }
125 |
126 | public static String getFixers(PhpModule phpModule) {
127 | return getPreferences(phpModule).get(FIXERS, ""); // NOI18N
128 | }
129 |
130 | public static void setFixers(PhpModule phpModule, String fixers) {
131 | getPreferences(phpModule).put(FIXERS, fixers);
132 | }
133 |
134 | // 2.x
135 | public static boolean useRules(PhpModule phpModule) {
136 | return getPreferences(phpModule).getBoolean(USE_RULES, false);
137 | }
138 |
139 | public static void setRules(PhpModule phpModule, boolean use) {
140 | getPreferences(phpModule).putBoolean(USE_RULES, use);
141 | }
142 |
143 | public static String getRules(PhpModule phpModule) {
144 | return getPreferences(phpModule).get(RULES, ""); // NOI18N
145 | }
146 |
147 | public static void setRules(PhpModule phpModule, String rules) {
148 | getPreferences(phpModule).put(RULES, rules);
149 | }
150 |
151 | public static boolean useCustom(PhpModule phpModule) {
152 | return getPreferences(phpModule).getBoolean(USE_CUSTOM, false);
153 | }
154 |
155 | public static void setCustom(PhpModule phpModule, boolean use) {
156 | getPreferences(phpModule).putBoolean(USE_CUSTOM, use);
157 | }
158 |
159 | public static String getCustom(PhpModule phpModule) {
160 | return getPreferences(phpModule).get(CUSTOM, ""); // NOI18N
161 | }
162 |
163 | public static void setCustom(PhpModule phpModule, String custom) {
164 | getPreferences(phpModule).put(CUSTOM, custom);
165 | }
166 |
167 | public static boolean isRunOnSave(PhpModule phpModule) {
168 | return getPreferences(phpModule).getBoolean(RUN_ON_SAVE, false);
169 | }
170 |
171 | public static void setRunOnSave(PhpModule phpModule, boolean isRunOnSave) {
172 | getPreferences(phpModule).putBoolean(RUN_ON_SAVE, isRunOnSave);
173 | }
174 |
175 | public static boolean isVerbose(PhpModule phpModule) {
176 | return getPreferences(phpModule).getBoolean(VERBOSE, false);
177 | }
178 |
179 | public static void setVerbose(PhpModule phpModule, boolean isVerbose) {
180 | getPreferences(phpModule).putBoolean(VERBOSE, isVerbose);
181 | }
182 |
183 | public static boolean isDiff(PhpModule phpModule) {
184 | return getPreferences(phpModule).getBoolean(DIFF, false);
185 | }
186 |
187 | public static void setDiff(PhpModule phpModule, boolean isDiff) {
188 | getPreferences(phpModule).putBoolean(DIFF, isDiff);
189 | }
190 |
191 | public static boolean isDiffFormatUdiff(PhpModule phpModule) {
192 | return getPreferences(phpModule).getBoolean(DIFF_FORMAT_UDIFF, false);
193 | }
194 |
195 | public static void setDiffFormatUdiff(PhpModule phpModule, boolean isDiff) {
196 | getPreferences(phpModule).putBoolean(DIFF_FORMAT_UDIFF, isDiff);
197 | }
198 |
199 | public static List getAllOptions(PhpModule phpModule) {
200 | List all = new ArrayList<>();
201 | if (getVersion(phpModule) == 2) {
202 | if (useRules(phpModule) && !getRules(phpModule).isEmpty()) {
203 | all.add(String.format(PhpCsFixer.RULES_PARAM, getRules(phpModule)));
204 | }
205 | } else {
206 | if (useLevel(phpModule) && !getLevel(phpModule).isEmpty()) {
207 | all.add(String.format(PhpCsFixer.LEVEL_PARAM, getLevel(phpModule)));
208 | }
209 | if (useConfig(phpModule) && !getConfig(phpModule).isEmpty()) {
210 | all.add(String.format(PhpCsFixer.CONFIG_PARAM, getConfig(phpModule)));
211 | }
212 | if (useFixers(phpModule) && !getFixers(phpModule).isEmpty()) {
213 | all.add(String.format(PhpCsFixer.FIXERS_PARAM, getFixers(phpModule)));
214 | }
215 | }
216 | if (useCustom(phpModule) && !getCustom(phpModule).isEmpty()) {
217 | all.addAll(StringUtils.explode(getCustom(phpModule), " ")); // NOI18N
218 | }
219 | return all;
220 | }
221 |
222 | private static Preferences getPreferences(PhpModule phpModule) {
223 | return phpModule.getPreferences(PhpCsFixerPreferences.class, true);
224 | }
225 | }
226 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/UiUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.ui;
17 |
18 | import org.openide.DialogDisplayer;
19 | import org.openide.NotifyDescriptor;
20 |
21 | /**
22 | *
23 | * @author junichi11
24 | */
25 | public final class UiUtils {
26 |
27 | private UiUtils() {
28 | }
29 |
30 | public static void showWarningMessage(String message) {
31 | showMessage(message, NotifyDescriptor.WARNING_MESSAGE);
32 | }
33 |
34 | public static void showErrorMessage(String message) {
35 | showMessage(message, NotifyDescriptor.ERROR_MESSAGE);
36 | }
37 |
38 | public static void showInfoMessage(String message) {
39 | showMessage(message, NotifyDescriptor.INFORMATION_MESSAGE);
40 | }
41 |
42 | public static void showMessage(String message, int messageType) {
43 | NotifyDescriptor.Message m = new NotifyDescriptor.Message(message, messageType);
44 | DialogDisplayer.getDefault().notify(m);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/actions/Bundle.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junichi11/netbeans-php-cs-fixer-plugin/1ac23bce6e9ee6bd30f916a8ef06dcce391236cf/src/org/netbeans/modules/php/phpcsfixer/ui/actions/Bundle.properties
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/actions/FixAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.ui.actions;
17 |
18 | import java.io.IOException;
19 | import java.util.ArrayList;
20 | import java.util.Collection;
21 | import java.util.Collections;
22 | import java.util.Enumeration;
23 | import java.util.List;
24 | import java.util.concurrent.ExecutionException;
25 | import java.util.concurrent.Future;
26 | import java.util.logging.Level;
27 | import java.util.logging.Logger;
28 | import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
29 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
30 | import org.netbeans.modules.php.api.util.StringUtils;
31 | import org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer;
32 | import org.openide.*;
33 | import org.openide.awt.ActionID;
34 | import org.openide.awt.ActionRegistration;
35 | import org.openide.filesystems.FileObject;
36 | import org.openide.filesystems.FileUtil;
37 | import org.openide.loaders.DataObject;
38 | import org.openide.loaders.DataObjectNotFoundException;
39 | import org.openide.util.Exceptions;
40 | import org.openide.util.Lookup;
41 | import org.openide.util.NbBundle;
42 | import org.openide.util.Utilities;
43 |
44 | /**
45 | *
46 | * @author junichi11
47 | */
48 | @ActionID(
49 | category = "PHP",
50 | id = "org.netbeans.modules.php.phpcsfixer.ui.actions.FixAction"
51 | )
52 | @ActionRegistration(
53 | displayName = "#CTL_FixAction"
54 | )
55 | @NbBundle.Messages("CTL_FixAction=PHP CS Fixer: Fix")
56 | public class FixAction extends PhpCsFixerBaseAction {
57 |
58 | private static final long serialVersionUID = -3347012049948024185L;
59 | private static final Logger LOGGER = Logger.getLogger(FixAction.class.getName());
60 |
61 | @NbBundle.Messages("FixAction.name=Fix")
62 | @Override
63 | protected String getName() {
64 | return Bundle.FixAction_name();
65 | }
66 |
67 | @Override
68 | protected void runCommand(PhpModule phpModule, List options) throws InvalidPhpExecutableException {
69 | Collection extends FileObject> targetFiles = getTargetFiles();
70 | for (FileObject target : targetFiles) {
71 | if (target.isFolder()) {
72 | Enumeration extends FileObject> children = target.getChildren(true);
73 | while (children.hasMoreElements()) {
74 | if (isModifiedFile(children.nextElement())) {
75 | return;
76 | }
77 | }
78 | } else {
79 | if (isModifiedFile(target)) {
80 | return;
81 | }
82 | }
83 | runCommand(phpModule, options, target);
84 | }
85 | }
86 |
87 | @NbBundle.Messages({
88 | "# {0} - file name",
89 | "FixAction.message.modified.file=There is a modified file({0})."
90 | })
91 | private boolean isModifiedFile(FileObject target) {
92 | try {
93 | DataObject dataObject = DataObject.find(target);
94 | if (!target.isFolder() && dataObject.isModified()) {
95 | // show message
96 | NotifyDescriptor descriptor = new NotifyDescriptor.Message(
97 | Bundle.FixAction_message_modified_file(target.getNameExt()),
98 | NotifyDescriptor.ERROR_MESSAGE
99 | );
100 | DialogDisplayer.getDefault().notifyLater(descriptor);
101 | return true;
102 | }
103 | }catch (DataObjectNotFoundException ex) {
104 | LOGGER.log(Level.WARNING, null, ex);
105 | }
106 | return false;
107 | }
108 |
109 | @Override
110 | public void runCommand(PhpModule phpModule, List options, FileObject targetFile) throws InvalidPhpExecutableException {
111 | List params = getAllParams(targetFile, options);
112 | if (!params.isEmpty()) {
113 | Future result = PhpCsFixer.getDefault().fix(phpModule, params.toArray(new String[0]));
114 | if (result != null) {
115 | try {
116 | result.get();
117 | } catch (InterruptedException | ExecutionException ex) {
118 | Exceptions.printStackTrace(ex);
119 | }
120 | }
121 | }
122 | }
123 |
124 | protected Collection extends FileObject> getTargetFiles() {
125 | Lookup context = Utilities.actionsGlobalContext();
126 | return context.lookupAll(FileObject.class);
127 | }
128 |
129 | protected List getAllParams(FileObject target, List options) {
130 | if (target == null) {
131 | return Collections.emptyList();
132 | }
133 | String targetPath = null;
134 | try {
135 | targetPath = FileUtil.toFile(target).getCanonicalPath();
136 | } catch (IOException ex) {
137 | Exceptions.printStackTrace(ex);
138 | }
139 | if (StringUtils.isEmpty(targetPath)) {
140 | return Collections.emptyList();
141 | }
142 |
143 | List params = new ArrayList<>(Collections.singletonList(targetPath));
144 | params.addAll(options);
145 | return params;
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/actions/FixDryRunAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.ui.actions;
17 |
18 | import java.util.List;
19 | import java.util.concurrent.ExecutionException;
20 | import java.util.concurrent.Future;
21 | import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
22 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
23 | import org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer;
24 | import org.openide.awt.ActionID;
25 | import org.openide.awt.ActionRegistration;
26 | import org.openide.filesystems.FileObject;
27 | import org.openide.util.Exceptions;
28 | import org.openide.util.NbBundle;
29 |
30 | /**
31 | *
32 | * @author junichi11
33 | */
34 | @ActionID(
35 | category = "PHP",
36 | id = "org.netbeans.modules.php.phpcsfixer.ui.actions.FixDryRunAction"
37 | )
38 | @ActionRegistration(
39 | displayName = "#CTL_FixDryRunAction"
40 | )
41 | @NbBundle.Messages("CTL_FixDryRunAction=PHP CS Fixer: Fix --dry-run")
42 | public class FixDryRunAction extends FixAction {
43 |
44 | private static final long serialVersionUID = 7751096230753168096L;
45 |
46 | @NbBundle.Messages("FixDryRunAction.name=Fix --dry-run")
47 | @Override
48 | protected String getName() {
49 | return Bundle.FixDryRunAction_name();
50 | }
51 |
52 | @Override
53 | protected void runCommand(PhpModule phpModule, List options) throws InvalidPhpExecutableException {
54 | for (FileObject target : getTargetFiles()) {
55 | List params = getAllParams(target, options);
56 | if (!params.isEmpty()) {
57 | Future result = PhpCsFixer.getDefault().fixDryRun(phpModule, params.toArray(new String[0]));
58 | if (result != null) {
59 | try {
60 | result.get();
61 | } catch (InterruptedException | ExecutionException ex) {
62 | Exceptions.printStackTrace(ex);
63 | }
64 | }
65 | }
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/actions/PhpCsFixerActionsFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.ui.actions;
17 |
18 | import java.awt.event.ActionEvent;
19 | import javax.swing.AbstractAction;
20 | import javax.swing.JMenu;
21 | import javax.swing.JMenuItem;
22 | import org.netbeans.api.project.FileOwnerQuery;
23 | import org.netbeans.api.project.Project;
24 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
25 | import org.netbeans.modules.php.api.util.StringUtils;
26 | import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptions;
27 | import org.netbeans.spi.project.ui.support.ProjectConvertors;
28 | import org.openide.awt.ActionID;
29 | import org.openide.awt.ActionReference;
30 | import org.openide.awt.ActionReferences;
31 | import org.openide.awt.ActionRegistration;
32 | import org.openide.filesystems.FileObject;
33 | import org.openide.util.Lookup;
34 | import org.openide.util.NbBundle;
35 | import org.openide.util.Utilities;
36 | import org.openide.util.actions.Presenter;
37 |
38 | /**
39 | *
40 | * @author junichi11
41 | */
42 | @ActionID(
43 | category = "PHP",
44 | id = "org.netbeans.modules.php.phpcsfixer.ui.actions.PhpCsFixerActionsFactory")
45 | @ActionRegistration(
46 | displayName = "#PhpCsFixerActionsFactory.name", lazy = false)
47 | @ActionReferences({
48 | @ActionReference(path = "Loaders/folder/any/Actions", position = 1690),
49 | @ActionReference(path = "Loaders/text/x-php5/Actions", position = 1690),
50 | @ActionReference(path = "Editors/text/x-php5/Popup", position = 590),
51 | @ActionReference(path = "Projects/org-netbeans-modules-php-project/Actions", position = 1090)
52 | })
53 | @NbBundle.Messages("PhpCsFixerActionsFactory.name=PHP CS Fixer")
54 | public class PhpCsFixerActionsFactory extends AbstractAction implements Presenter.Popup {
55 |
56 | private static final long serialVersionUID = -3056069945397188766L;
57 | private JMenu actions = null;
58 |
59 | @Override
60 | public void actionPerformed(ActionEvent e) {
61 | assert false;
62 | }
63 |
64 | @Override
65 | public JMenuItem getPopupPresenter() {
66 | if (!isInPhpModule()) {
67 | return new JMenuItem();
68 | }
69 | String phpCsFixerPath = PhpCsFixerOptions.getInstance().getPhpCsFixerPath();
70 | if (StringUtils.isEmpty(phpCsFixerPath)) {
71 | JMenuItem item = new JMenuItem();
72 | item.setVisible(false);
73 | return item;
74 | }
75 | if (actions == null) {
76 | actions = new PhpCsFixerActions();
77 | }
78 | return actions;
79 | }
80 |
81 | private boolean isInPhpModule() {
82 | Lookup context = Utilities.actionsGlobalContext();
83 | FileObject target = context.lookup(FileObject.class);
84 | if (target == null) {
85 | return false;
86 | }
87 | if (!target.isFolder()) {
88 | return true;
89 | }
90 | Project nonConvertorOwner = ProjectConvertors.getNonConvertorOwner(target);
91 | if (nonConvertorOwner == null) {
92 | nonConvertorOwner = FileOwnerQuery.getOwner(target);
93 | if (nonConvertorOwner == null) {
94 | return false;
95 | }
96 | }
97 | PhpModule phpModule = PhpModule.Factory.lookupPhpModule(nonConvertorOwner);
98 | if (phpModule != null) {
99 | return true;
100 | }
101 | phpModule = PhpModule.Factory.forFileObject(target);
102 | return phpModule != null;
103 | }
104 |
105 | //~ inner class
106 | private static class PhpCsFixerActions extends JMenu {
107 |
108 | private static final long serialVersionUID = 4460699854597307907L;
109 |
110 | public PhpCsFixerActions() {
111 | super(Bundle.PhpCsFixerActionsFactory_name());
112 | // add actions
113 | add(new FixAction());
114 | add(new FixDryRunAction());
115 | add(new SelfUpdateAction());
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/actions/PhpCsFixerBaseAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.ui.actions;
17 |
18 | import java.awt.event.ActionEvent;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import java.util.logging.Level;
22 | import java.util.logging.Logger;
23 | import javax.swing.AbstractAction;
24 | import static javax.swing.Action.NAME;
25 | import static javax.swing.Action.SHORT_DESCRIPTION;
26 | import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
27 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
28 | import org.netbeans.modules.php.api.util.StringUtils;
29 | import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptions;
30 | import org.netbeans.modules.php.phpcsfixer.preferences.PhpCsFixerPreferences;
31 | import org.openide.filesystems.FileObject;
32 | import static org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer.DIFF_FORMAT_UDIFF_PARAM;
33 | import static org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer.DIFF_PARAM;
34 | import static org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer.VERBOSE_PARAM;
35 |
36 | /**
37 | *
38 | * @author junichi11
39 | */
40 | public abstract class PhpCsFixerBaseAction extends AbstractAction {
41 |
42 | private static final long serialVersionUID = -8856272088582157210L;
43 | private static final Logger LOGGER = Logger.getLogger(PhpCsFixerBaseAction.class.getName());
44 |
45 | public PhpCsFixerBaseAction() {
46 | putValue("noIconInMenu", true); // NOI18N
47 | String name = getName();
48 | putValue(NAME, name);
49 | putValue(SHORT_DESCRIPTION, name);
50 | putValue("menuText", name); // NOI18N
51 | }
52 |
53 | protected abstract String getName();
54 |
55 | protected abstract void runCommand(PhpModule phpModule, List options) throws InvalidPhpExecutableException;
56 |
57 | protected abstract void runCommand(PhpModule phpModule, List options, FileObject targetFile) throws InvalidPhpExecutableException;
58 |
59 | @Override
60 | public void actionPerformed(ActionEvent e) {
61 | PhpModule phpModule = PhpModule.Factory.inferPhpModule();
62 | if (phpModule == null) {
63 | return;
64 | }
65 | try {
66 | runCommand(phpModule, getOptions());
67 | } catch (InvalidPhpExecutableException ex) {
68 | LOGGER.log(Level.WARNING, null, ex);
69 | }
70 | }
71 |
72 | public void actionPerformed(ActionEvent e, FileObject targetFile) {
73 | PhpModule phpModule = PhpModule.Factory.forFileObject(targetFile);
74 | if (phpModule == null) {
75 | return;
76 | }
77 | try {
78 | runCommand(phpModule, getOptions(), targetFile);
79 | } catch (InvalidPhpExecutableException ex) {
80 | LOGGER.log(Level.WARNING, null, ex);
81 | }
82 | }
83 |
84 | private List getOptions() {
85 | PhpModule phpModule = PhpModule.Factory.inferPhpModule();
86 | List options = new ArrayList<>();
87 | boolean isDryRun = isDryRun();
88 | boolean isVerbose;
89 | boolean isDiff;
90 | boolean isDiffFormatUdiff;
91 |
92 | if (phpModule == null || PhpCsFixerPreferences.useGlobal(phpModule)) {
93 | // use global
94 | PhpCsFixerOptions instance = PhpCsFixerOptions.getInstance();
95 | options.addAll(instance.getAllOptions());
96 | isVerbose = instance.isVerbose();
97 | isDiff = instance.isDiff();
98 | isDiffFormatUdiff = instance.isDiffFormatUdiff();
99 | } else {
100 | // use project
101 | options.addAll(PhpCsFixerPreferences.getAllOptions(phpModule));
102 | isVerbose = PhpCsFixerPreferences.isVerbose(phpModule);
103 | isDiff = PhpCsFixerPreferences.isDiff(phpModule);
104 | isDiffFormatUdiff = PhpCsFixerPreferences.isDiffFormatUdiff(phpModule);
105 | }
106 |
107 | if (isDryRun) {
108 | if (isVerbose) {
109 | options.add(VERBOSE_PARAM);
110 | if (isDiff) {
111 | options.add(DIFF_PARAM);
112 | if (isDiffFormatUdiff) {
113 | options.add(DIFF_FORMAT_UDIFF_PARAM);
114 | }
115 | }
116 | }
117 | }
118 |
119 | return options;
120 | }
121 |
122 | private boolean isDryRun() {
123 | String name = getName();
124 | if (StringUtils.isEmpty(name)) {
125 | return false;
126 | }
127 | return name.contains("--dry-run"); // NOI18N
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/actions/SelfUpdateAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.ui.actions;
17 |
18 | import java.util.List;
19 | import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
20 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
21 | import org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer;
22 | import org.openide.filesystems.FileObject;
23 | import org.openide.util.NbBundle;
24 |
25 | /**
26 | *
27 | * @author junichi11
28 | */
29 | public class SelfUpdateAction extends PhpCsFixerBaseAction {
30 |
31 | private static final long serialVersionUID = -6042811476506701499L;
32 |
33 | @NbBundle.Messages("SelfUpdateAction.name=self-update")
34 | @Override
35 | protected String getName() {
36 | return Bundle.SelfUpdateAction_name();
37 | }
38 |
39 | @Override
40 | protected void runCommand(PhpModule phpModule, List options) throws InvalidPhpExecutableException {
41 | PhpCsFixer.getDefault().selfUpdate(phpModule);
42 | }
43 |
44 | @Override
45 | protected void runCommand(PhpModule phpModule, List options, FileObject targetFile) throws InvalidPhpExecutableException {
46 | PhpCsFixer.getDefault().selfUpdate(phpModule);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/customizer/Bundle.properties:
--------------------------------------------------------------------------------
1 | PhpCsFixerCustomizerPanel.useGlobalRadioButton.text=use global settings
2 | PhpCsFixerCustomizerPanel.useProjectRadioButton.text=use project settings
3 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/customizer/PhpCsFixerCustomizerPanel.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
79 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/customizer/PhpCsFixerCustomizerPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.ui.customizer;
17 |
18 | import java.awt.Component;
19 | import java.awt.event.ActionEvent;
20 | import java.awt.event.ActionListener;
21 | import javax.swing.ButtonGroup;
22 | import javax.swing.GroupLayout;
23 | import javax.swing.JComboBox;
24 | import javax.swing.JRadioButton;
25 | import javax.swing.LayoutStyle;
26 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
27 | import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptionsPanel;
28 | import org.netbeans.modules.php.phpcsfixer.preferences.PhpCsFixerPreferences;
29 | import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
30 | import org.openide.awt.Mnemonics;
31 | import org.openide.util.NbBundle;
32 |
33 | /**
34 | *
35 | * @author junichi11
36 | */
37 | public final class PhpCsFixerCustomizerPanel extends javax.swing.JPanel {
38 |
39 | private static final long serialVersionUID = -6326119172349277539L;
40 | private final Category catetgory;
41 | private final PhpModule phpModule;
42 | private boolean isGlobal;
43 | private boolean isProject;
44 | private int version;
45 | // 1.x
46 | private boolean useLevel;
47 | private String level;
48 | private boolean useConfig;
49 | private String config;
50 | private boolean useFixers;
51 | private String fixers;
52 | // 2.x
53 | private boolean useRules;
54 | private boolean isDiffFormatUdiff;
55 | private String rules;
56 | // common
57 | private boolean useCustom;
58 | private String custom;
59 | private boolean isRunOnSave;
60 | private boolean isVerbose;
61 | private boolean isDiff;
62 |
63 | /**
64 | * Creates new form PhpCsFixerCustomizerPanel
65 | */
66 | public PhpCsFixerCustomizerPanel(Category catetgory, PhpModule phpModule) {
67 | catetgory.setOkButtonListener((ActionEvent e) -> {
68 | save();
69 | });
70 | this.catetgory = catetgory;
71 | this.phpModule = phpModule;
72 | initComponents();
73 | // load
74 | load();
75 | // set enabled components
76 | setEnabledProject(isProject());
77 | }
78 |
79 | private void save() {
80 | if (isGlobal()) {
81 | if (isGlobal != isGlobal()) {
82 | PhpCsFixerPreferences.setGlobal(phpModule, isGlobal());
83 | PhpCsFixerPreferences.setProject(phpModule, isProject());
84 | }
85 | } else if (isProject()) {
86 | if (isProject != isProject()) {
87 | PhpCsFixerPreferences.setGlobal(phpModule, isGlobal());
88 | PhpCsFixerPreferences.setProject(phpModule, isProject());
89 | }
90 | if (version != optionsPanel.getVersion()) {
91 | PhpCsFixerPreferences.setVersion(phpModule, optionsPanel.getVersion());
92 | }
93 |
94 | // 1.x
95 | if (useLevel != optionsPanel.useLevel()) {
96 | PhpCsFixerPreferences.setLevel(phpModule, optionsPanel.useLevel());
97 | }
98 | if (!level.equals(optionsPanel.getLevel())) {
99 | PhpCsFixerPreferences.setLevel(phpModule, optionsPanel.getLevel());
100 | }
101 | if (useConfig != optionsPanel.useConfig()) {
102 | PhpCsFixerPreferences.setConfig(phpModule, optionsPanel.useConfig());
103 | }
104 | if (!config.equals(optionsPanel.getConfig())) {
105 | PhpCsFixerPreferences.setConfig(phpModule, optionsPanel.getConfig());
106 | }
107 | if (useFixers != optionsPanel.useFixers()) {
108 | PhpCsFixerPreferences.setFixers(phpModule, optionsPanel.useFixers());
109 | }
110 | if (!fixers.equals(optionsPanel.getFixers())) {
111 | PhpCsFixerPreferences.setFixers(phpModule, optionsPanel.getFixers());
112 | }
113 |
114 | // 2.x
115 | if (useRules != optionsPanel.useRules()) {
116 | PhpCsFixerPreferences.setRules(phpModule, optionsPanel.useRules());
117 | }
118 | if (!rules.equals(optionsPanel.getRules())) {
119 | PhpCsFixerPreferences.setRules(phpModule, optionsPanel.getRules());
120 | }
121 | if (isDiffFormatUdiff != optionsPanel.isDiffFormatUdiff()) {
122 | PhpCsFixerPreferences.setDiffFormatUdiff(phpModule, optionsPanel.isDiffFormatUdiff());
123 | }
124 |
125 | // common
126 | if (useCustom != optionsPanel.useCustom()) {
127 | PhpCsFixerPreferences.setCustom(phpModule, optionsPanel.useCustom());
128 | }
129 | if (!custom.equals(optionsPanel.getCustom())) {
130 | PhpCsFixerPreferences.setCustom(phpModule, optionsPanel.getCustom());
131 | }
132 | if (isRunOnSave != optionsPanel.isRunOnSave()) {
133 | PhpCsFixerPreferences.setRunOnSave(phpModule, optionsPanel.isRunOnSave());
134 | }
135 | if (isVerbose != optionsPanel.isVerbose()) {
136 | PhpCsFixerPreferences.setVerbose(phpModule, optionsPanel.isVerbose());
137 | }
138 | if (isDiff != optionsPanel.isDiff()) {
139 | PhpCsFixerPreferences.setDiff(phpModule, optionsPanel.isDiff());
140 | }
141 | } else {
142 | // do nothing
143 | }
144 | }
145 |
146 | public boolean isGlobal() {
147 | return useGlobalRadioButton.isSelected();
148 | }
149 |
150 | public boolean isProject() {
151 | return useProjectRadioButton.isSelected();
152 | }
153 |
154 | private void load() {
155 | isGlobal = PhpCsFixerPreferences.useGlobal(phpModule);
156 | isProject = PhpCsFixerPreferences.useProject(phpModule);
157 |
158 | version = PhpCsFixerPreferences.getVersion(phpModule);
159 | useLevel = PhpCsFixerPreferences.useLevel(phpModule);
160 | level = PhpCsFixerPreferences.getLevel(phpModule);
161 | useConfig = PhpCsFixerPreferences.useConfig(phpModule);
162 | config = PhpCsFixerPreferences.getConfig(phpModule);
163 | useFixers = PhpCsFixerPreferences.useFixers(phpModule);
164 | fixers = PhpCsFixerPreferences.getFixers(phpModule);
165 | // 2.x
166 | useRules = PhpCsFixerPreferences.useRules(phpModule);
167 | rules = PhpCsFixerPreferences.getRules(phpModule);
168 | isDiffFormatUdiff = PhpCsFixerPreferences.isDiffFormatUdiff(phpModule);
169 | // common
170 | useCustom = PhpCsFixerPreferences.useCustom(phpModule);
171 | custom = PhpCsFixerPreferences.getCustom(phpModule);
172 | isRunOnSave = PhpCsFixerPreferences.isRunOnSave(phpModule);
173 | isVerbose = PhpCsFixerPreferences.isVerbose(phpModule);
174 | isDiff = PhpCsFixerPreferences.isDiff(phpModule);
175 | // global, project
176 | useGlobalRadioButton.setSelected(isGlobal);
177 | useProjectRadioButton.setSelected(isProject);
178 |
179 | // options
180 | optionsPanel.setVersion(version);
181 | // 1.x
182 | optionsPanel.setLevel(useLevel);
183 | optionsPanel.setLevel(level);
184 | optionsPanel.setConfig(useConfig);
185 | optionsPanel.setConfig(config);
186 | optionsPanel.setFixers(useFixers);
187 | optionsPanel.setFixers(fixers);
188 | // 2.x
189 | optionsPanel.setRules(useRules);
190 | optionsPanel.setRules(rules);
191 | optionsPanel.setDiffFormatUdiff(isDiffFormatUdiff);
192 | // common
193 | optionsPanel.setCustom(useCustom);
194 | optionsPanel.setCustom(custom);
195 | optionsPanel.setRunOnSave(isRunOnSave);
196 | optionsPanel.setVerbose(isVerbose);
197 | optionsPanel.setDiff(isDiff);
198 | }
199 |
200 | /**
201 | * This method is called from within the constructor to initialize the form.
202 | * WARNING: Do NOT modify this code. The content of this method is always
203 | * regenerated by the Form Editor.
204 | */
205 | @SuppressWarnings("unchecked")
206 | // //GEN-BEGIN:initComponents
207 | private void initComponents() {
208 |
209 | buttonGroup = new ButtonGroup();
210 | useGlobalRadioButton = new JRadioButton();
211 | useProjectRadioButton = new JRadioButton();
212 | optionsPanel = new PhpCsFixerOptionsPanel();
213 |
214 | buttonGroup.add(useGlobalRadioButton);
215 | useGlobalRadioButton.setSelected(true);
216 | Mnemonics.setLocalizedText(useGlobalRadioButton, NbBundle.getMessage(PhpCsFixerCustomizerPanel.class, "PhpCsFixerCustomizerPanel.useGlobalRadioButton.text")); // NOI18N
217 | useGlobalRadioButton.addActionListener(new ActionListener() {
218 | public void actionPerformed(ActionEvent evt) {
219 | useGlobalRadioButtonActionPerformed(evt);
220 | }
221 | });
222 |
223 | buttonGroup.add(useProjectRadioButton);
224 | Mnemonics.setLocalizedText(useProjectRadioButton, NbBundle.getMessage(PhpCsFixerCustomizerPanel.class, "PhpCsFixerCustomizerPanel.useProjectRadioButton.text")); // NOI18N
225 | useProjectRadioButton.addActionListener(new ActionListener() {
226 | public void actionPerformed(ActionEvent evt) {
227 | useProjectRadioButtonActionPerformed(evt);
228 | }
229 | });
230 |
231 | GroupLayout layout = new GroupLayout(this);
232 | this.setLayout(layout);
233 | layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
234 | .addGroup(layout.createSequentialGroup()
235 | .addContainerGap()
236 | .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
237 | .addComponent(useGlobalRadioButton)
238 | .addComponent(useProjectRadioButton))
239 | .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
240 | .addComponent(optionsPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
241 | );
242 | layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
243 | .addGroup(layout.createSequentialGroup()
244 | .addContainerGap()
245 | .addComponent(useGlobalRadioButton)
246 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
247 | .addComponent(useProjectRadioButton)
248 | .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
249 | .addComponent(optionsPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
250 | );
251 | }// //GEN-END:initComponents
252 |
253 | private void useGlobalRadioButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_useGlobalRadioButtonActionPerformed
254 | setEnabledProject(false);
255 | }//GEN-LAST:event_useGlobalRadioButtonActionPerformed
256 |
257 | private void useProjectRadioButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_useProjectRadioButtonActionPerformed
258 | setEnabledProject(true);
259 | }//GEN-LAST:event_useProjectRadioButtonActionPerformed
260 | // Variables declaration - do not modify//GEN-BEGIN:variables
261 | private ButtonGroup buttonGroup;
262 | private PhpCsFixerOptionsPanel optionsPanel;
263 | private JRadioButton useGlobalRadioButton;
264 | private JRadioButton useProjectRadioButton;
265 | // End of variables declaration//GEN-END:variables
266 |
267 | private void setEnabledProject(boolean enabled) {
268 | for (Component component : optionsPanel.getComponents()) {
269 | component.setEnabled(enabled);
270 | }
271 | JComboBox configComboBox = optionsPanel.getConfigComboBox();
272 | configComboBox.setEditable(enabled);
273 | }
274 | }
275 |
--------------------------------------------------------------------------------
/src/org/netbeans/modules/php/phpcsfixer/ui/customizer/PhpCsFixerCustomizerProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.netbeans.modules.php.phpcsfixer.ui.customizer;
17 |
18 | import javax.swing.JComponent;
19 | import org.netbeans.modules.php.api.phpmodule.PhpModule;
20 | import org.netbeans.spi.project.ui.support.ProjectCustomizer;
21 | import org.openide.util.Lookup;
22 | import org.openide.util.NbBundle;
23 |
24 | /**
25 | *
26 | * @author junichi11
27 | */
28 | public final class PhpCsFixerCustomizerProvider implements ProjectCustomizer.CompositeCategoryProvider {
29 |
30 | @NbBundle.Messages("LBL.PhpCsFixerCustomizerProvider.name=PHP CS Fixer")
31 | @Override
32 | public ProjectCustomizer.Category createCategory(Lookup context) {
33 | return ProjectCustomizer.Category.create("PHP", Bundle.LBL_PhpCsFixerCustomizerProvider_name(), null);
34 | }
35 |
36 | @ProjectCustomizer.CompositeCategoryProvider.Registration(projectType = "org-netbeans-modules-php-project", position = 4500)
37 | public static PhpCsFixerCustomizerProvider create() {
38 | return new PhpCsFixerCustomizerProvider();
39 | }
40 |
41 | private PhpCsFixerCustomizerProvider() {
42 | }
43 |
44 | @Override
45 | public JComponent createComponent(ProjectCustomizer.Category category, Lookup context) {
46 | PhpModule phpModule = PhpModule.Factory.lookupPhpModule(context);
47 | return new PhpCsFixerCustomizerPanel(category, phpModule);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------