Skip to content

Commit 5cd20b7

Browse files
committed
Merge branch 'nb82'
2 parents 47b50f8 + 3894f17 commit 5cd20b7

17 files changed

+567
-63
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ https://github.com/FriendsOfPHP/PHP-CS-Fixer
3939
`project properties > PHP CS Fixer`
4040
- If you would like to use settings each projects, please, check `use project settings`
4141

42+
### Customizing Options
43+
44+
If you would like to use some options, please check the custom checkbox, then please add them to it.
45+
46+
e.g. `--cache-file=/path/to/.php_cs.cache`
47+
48+
### Show an output window
49+
50+
If you would like to avoid showing the output window, please uncheck it. (Checked by default)
51+
52+
### Run self-update command on boot
53+
54+
If you would like to run the self-update command on boot, please check it. (Unchecked by default)
55+
4256
## Usage
4357

4458
1. Right-click
@@ -58,7 +72,7 @@ https://github.com/FriendsOfPHP/PHP-CS-Fixer
5872

5973
## NOTE
6074

61-
- Run on save feature may not work somethimes. Now after 1 second, the command is run. But I don't have another idea at the moment, sorry.
75+
- 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.
6276

6377
## License
6478

manifest.mf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Manifest-Version: 1.0
22
OpenIDE-Module: org.netbeans.modules.php.phpcsfixer
3+
OpenIDE-Module-Install: org/netbeans/modules/php/phpcsfixer/Installer.class
34
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/phpcsfixer/Bundle.properties
45
OpenIDE-Module-Specification-Version: 0.8.1

nbproject/platform.properties

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ cluster.path=\
55
${nbplatform.active.dir}/php:\
66
${nbplatform.active.dir}/ide:\
77
${nbplatform.active.dir}/websvccommon:\
8-
${nbplatform.active.dir}/ergonomics:\
9-
${nbplatform.active.dir}/mobility:\
108
${nbplatform.active.dir}/webcommon:\
119
${nbplatform.active.dir}/java:\
12-
${nbplatform.active.dir}/enterprise:\
13-
${nbplatform.active.dir}/profiler:\
14-
${nbplatform.active.dir}/javafx:\
1510
${nbplatform.active.dir}/harness
1611
nbplatform.active=default

nbproject/project.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
<code-name-base>org.netbeans.modules.php.phpcsfixer</code-name-base>
77
<standalone/>
88
<module-dependencies>
9+
<dependency>
10+
<code-name-base>org.netbeans.api.templates</code-name-base>
11+
<build-prerequisite/>
12+
<compile-dependency/>
13+
<run-dependency>
14+
<specification-version>1.7.1</specification-version>
15+
</run-dependency>
16+
</dependency>
917
<dependency>
1018
<code-name-base>org.netbeans.modules.editor</code-name-base>
1119
<build-prerequisite/>
@@ -15,6 +23,14 @@
1523
<specification-version>1.70.2.5.21.40</specification-version>
1624
</run-dependency>
1725
</dependency>
26+
<dependency>
27+
<code-name-base>org.netbeans.modules.editor.document</code-name-base>
28+
<build-prerequisite/>
29+
<compile-dependency/>
30+
<run-dependency>
31+
<specification-version>1.9.1.3</specification-version>
32+
</run-dependency>
33+
</dependency>
1834
<dependency>
1935
<code-name-base>org.netbeans.modules.editor.lib</code-name-base>
2036
<build-prerequisite/>
@@ -51,6 +67,15 @@
5167
<specification-version>1.36.1</specification-version>
5268
</run-dependency>
5369
</dependency>
70+
<dependency>
71+
<code-name-base>org.netbeans.modules.extexecution.base</code-name-base>
72+
<build-prerequisite/>
73+
<compile-dependency/>
74+
<run-dependency>
75+
<release-version>2</release-version>
76+
<specification-version>1.4.1</specification-version>
77+
</run-dependency>
78+
</dependency>
5479
<dependency>
5580
<code-name-base>org.netbeans.modules.options.api</code-name-base>
5681
<build-prerequisite/>
@@ -128,6 +153,14 @@
128153
<specification-version>8.5.1</specification-version>
129154
</run-dependency>
130155
</dependency>
156+
<dependency>
157+
<code-name-base>org.openide.filesystems.compat8</code-name-base>
158+
<build-prerequisite/>
159+
<compile-dependency/>
160+
<run-dependency>
161+
<specification-version>9.9.1</specification-version>
162+
</run-dependency>
163+
</dependency>
131164
<dependency>
132165
<code-name-base>org.openide.filesystems.nb</code-name-base>
133166
<build-prerequisite/>
@@ -152,6 +185,14 @@
152185
<specification-version>7.44.2</specification-version>
153186
</run-dependency>
154187
</dependency>
188+
<dependency>
189+
<code-name-base>org.openide.modules</code-name-base>
190+
<build-prerequisite/>
191+
<compile-dependency/>
192+
<run-dependency>
193+
<specification-version>7.48.1</specification-version>
194+
</run-dependency>
195+
</dependency>
155196
<dependency>
156197
<code-name-base>org.openide.nodes</code-name-base>
157198
<build-prerequisite/>
@@ -193,6 +234,20 @@
193234
</run-dependency>
194235
</dependency>
195236
</module-dependencies>
237+
<test-dependencies>
238+
<test-type>
239+
<name>unit</name>
240+
<test-dependency>
241+
<code-name-base>org.netbeans.libs.junit4</code-name-base>
242+
<compile-dependency/>
243+
</test-dependency>
244+
<test-dependency>
245+
<code-name-base>org.netbeans.modules.nbjunit</code-name-base>
246+
<recursive/>
247+
<compile-dependency/>
248+
</test-dependency>
249+
</test-type>
250+
</test-dependencies>
196251
<public-packages/>
197252
</data>
198253
</configuration>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*/
40+
package org.netbeans.modules.php.phpcsfixer;
41+
42+
import static java.util.logging.Level.INFO;
43+
import static java.util.logging.Level.WARNING;
44+
import java.util.logging.Logger;
45+
import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
46+
import org.netbeans.modules.php.api.util.StringUtils;
47+
import org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer;
48+
import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptions;
49+
import org.openide.modules.ModuleInstall;
50+
51+
public class Installer extends ModuleInstall {
52+
53+
private static final Logger LOGGER = Logger.getLogger(Installer.class.getName());
54+
55+
@Override
56+
public void restored() {
57+
PhpCsFixerOptions options = PhpCsFixerOptions.getInstance();
58+
String phpCsFixerPath = options.getPhpCsFixerPath();
59+
if (!StringUtils.isEmpty(phpCsFixerPath) && options.runSelfUpdateOnBoot()) {
60+
try {
61+
PhpCsFixer.newInstance(phpCsFixerPath, true).selfUpdate(null);
62+
LOGGER.log(INFO, "Run self-update"); // NOI18N
63+
} catch (InvalidPhpExecutableException ex) {
64+
LOGGER.log(WARNING, ex.getMessage());
65+
}
66+
}
67+
}
68+
69+
}

src/org/netbeans/modules/php/phpcsfixer/commands/PhpCsFixer.java

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@
4545
import java.util.Arrays;
4646
import java.util.Collections;
4747
import java.util.List;
48+
import java.util.concurrent.ExecutionException;
4849
import java.util.concurrent.Future;
4950
import java.util.logging.Level;
5051
import java.util.logging.Logger;
5152
import org.netbeans.api.extexecution.ExecutionDescriptor;
53+
import org.netbeans.api.extexecution.base.input.InputProcessor;
54+
import org.netbeans.api.extexecution.base.input.InputProcessors;
55+
import org.netbeans.api.extexecution.base.input.LineProcessor;
5256
import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
5357
import org.netbeans.modules.php.api.executable.PhpExecutable;
5458
import org.netbeans.modules.php.api.executable.PhpExecutableValidator;
@@ -57,6 +61,7 @@
5761
import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptionsPanelController;
5862
import org.openide.filesystems.FileObject;
5963
import org.openide.filesystems.FileUtil;
64+
import org.openide.util.Exceptions;
6065
import org.openide.util.NbBundle;
6166
import org.openide.windows.InputOutput;
6267

@@ -72,17 +77,22 @@ public final class PhpCsFixer {
7277
public static final String DOWNLOAD_URL = "http://get.sensiolabs.org/php-cs-fixer.phar"; // NOI18N
7378
private final String phpcsfixerPath;
7479
private boolean isDryRun;
80+
private boolean useSilentDescriptor;
7581
// commands
7682
private static final String FIX_COMMAND = "fix"; // NOI18N
7783
private static final String SELF_UPDATE_COMMAND = "self-update"; // NOI18N
7884
//parameters
85+
private static final String VERSION_PARAM = "--version"; // NOI18N
7986
public static final String DRY_RUN_PARAM = "--dry-run"; // NOI18N
87+
public static final String VERBOSE_PARAM = "--verbose"; // NOI18N
88+
public static final String DIFF_PARAM = "--diff"; // NOI18N
8089
// 1.x
8190
public static final String CONFIG_PARAM = "--config=%s"; // NOI18N
8291
public static final String LEVEL_PARAM = "--level=%s"; // NOI18N
8392
public static final String FIXERS_PARAM = "--fixers=%s"; // NOI18N
8493
// 2.x
8594
public static final String RULES_PARAM = "--rules=%s"; // NOI18N
95+
public static final String DIFF_FORMAT_UDIFF_PARAM = "--diff-format=udiff"; // NOI18N
8696
private static final List<String> DEFAULT_PARAMS = Arrays.asList(
8797
"--ansi", // NOI18N
8898
"--no-interaction"); // NOI18N
@@ -99,19 +109,32 @@ public final class PhpCsFixer {
99109
.inputOutput(InputOutput.NULL);
100110
private static final Logger LOGGER = Logger.getLogger(PhpCsFixer.class.getName());
101111

102-
public PhpCsFixer(String phpcsfixerPath) {
112+
private PhpCsFixer(String phpcsfixerPath) {
113+
this(phpcsfixerPath, false);
114+
}
115+
116+
private PhpCsFixer(String phpcsfixerPath, boolean useSilentDescriptor) {
103117
this.phpcsfixerPath = phpcsfixerPath;
104-
isDryRun = false;
118+
this.useSilentDescriptor = useSilentDescriptor;
119+
this.isDryRun = false;
105120
}
106121

107122
public static PhpCsFixer getDefault() throws InvalidPhpExecutableException {
108123
String phpcsfixerPath = PhpCsFixerOptions.getInstance().getPhpCsFixerPath();
109-
String warning = validate(phpcsfixerPath);
124+
return newInstance(phpcsfixerPath);
125+
}
126+
127+
public static PhpCsFixer newInstance(String scriptPath) throws InvalidPhpExecutableException {
128+
return newInstance(scriptPath, false);
129+
}
130+
131+
public static PhpCsFixer newInstance(String scriptPath, boolean useSilentDescriptor) throws InvalidPhpExecutableException {
132+
String warning = validate(scriptPath);
110133
if (warning != null) {
111134
LOGGER.log(Level.WARNING, "PHP CS Fixer path is not set."); // NOI18N
112135
throw new InvalidPhpExecutableException(warning);
113136
}
114-
return new PhpCsFixer(phpcsfixerPath);
137+
return new PhpCsFixer(scriptPath, useSilentDescriptor);
115138
}
116139

117140
@NbBundle.Messages("PhpCsFixer.script.label=PHP CS Fixer")
@@ -139,6 +162,28 @@ public Future<Integer> selfUpdate(PhpModule phpModule) {
139162
return runCommand(phpModule, SELF_UPDATE_COMMAND, Bundle.PhpCsFixer_run(SELF_UPDATE_COMMAND));
140163
}
141164

165+
/**
166+
* Get version.
167+
*
168+
* @return version
169+
*/
170+
public String getVersion() {
171+
DefaultLineProcessor lineProcessor = new DefaultLineProcessor();
172+
Future<Integer> result = getPhpExecutable(null, "version")
173+
.additionalParameters(Arrays.asList(VERSION_PARAM))
174+
.run(NO_OUTPUT_EXECUTION_DESCRIPTOR, getOutputProcessorFactory(lineProcessor));
175+
try {
176+
if (result != null) {
177+
result.get();
178+
}
179+
} catch (InterruptedException ex) {
180+
Thread.currentThread().interrupt();
181+
} catch (ExecutionException ex) {
182+
Exceptions.printStackTrace(ex);
183+
}
184+
return lineProcessor.getResult();
185+
}
186+
142187
private Future<Integer> runCommand(PhpModule phpModule, String command, String title) {
143188
return runCommand(phpModule, command, title, Collections.<String>emptyList());
144189
}
@@ -177,7 +222,9 @@ private PhpExecutable getPhpExecutable(PhpModule phpModule, String title) {
177222

178223
private ExecutionDescriptor getDescriptor(PhpModule phpModule) {
179224
ExecutionDescriptor descriptor;
180-
if (PhpCsFixerOptions.getInstance().showOutputWindow() || isDryRun) {
225+
if (useSilentDescriptor) {
226+
descriptor = NO_OUTPUT_EXECUTION_DESCRIPTOR;
227+
} else if (PhpCsFixerOptions.getInstance().showOutputWindow() || isDryRun) {
181228
descriptor = DEFAULT_EXECUTION_DESCRIPTOR;
182229
} else {
183230
descriptor = NO_OUTPUT_EXECUTION_DESCRIPTOR;
@@ -194,4 +241,45 @@ private ExecutionDescriptor getDescriptor(PhpModule phpModule) {
194241
}
195242
return descriptor;
196243
}
244+
245+
/**
246+
* Get InputProcessorFactory.
247+
*
248+
* @param lineProcessor
249+
* @return InputProcessorFactory
250+
*/
251+
private ExecutionDescriptor.InputProcessorFactory2 getOutputProcessorFactory(final LineProcessor lineProcessor) {
252+
return (InputProcessor defaultProcessor) -> InputProcessors.ansiStripping(InputProcessors.bridge(lineProcessor));
253+
}
254+
255+
private static class DefaultLineProcessor implements LineProcessor {
256+
257+
private final StringBuilder result = new StringBuilder();
258+
private final List<String> list = new ArrayList<>();
259+
260+
@Override
261+
public void processLine(String line) {
262+
list.add(line);
263+
if (!list.isEmpty()) {
264+
result.append("\n"); // NOI18N
265+
}
266+
result.append(line);
267+
}
268+
269+
@Override
270+
public void reset() {
271+
}
272+
273+
@Override
274+
public void close() {
275+
}
276+
277+
public String getResult() {
278+
return result.toString();
279+
}
280+
281+
public List<String> asLines() {
282+
return list;
283+
}
284+
}
197285
}

src/org/netbeans/modules/php/phpcsfixer/options/Bundle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ PhpCsFixerOptionsPanel.versionLabel.text=Version:
1717
PhpCsFixerOptionsPanel.rulesCheckBox.text=--rules=
1818
PhpCsFixerOptionsPanel.rulesTextField.text=
1919
PhpCsFixerPanel.showOutputWindowCheckBox.text=Show an output window
20+
PhpCsFixerOptionsPanel.diffFormatUdiffCheckBox.text=--diff-format=udiff
21+
PhpCsFixerPanel.versionLabel.text=VERSION
22+
PhpCsFixerPanel.selfUpdateButton.text=Self Update...
23+
PhpCsFixerPanel.runSelfUpdateOnBootCheckBox.text=Run self-update command on boot

0 commit comments

Comments
 (0)