Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #19 from willybarro/master

Bugfixes and additions :)
  • Loading branch information...
commit ded6cd89e606c2d56556c701a8426423ea05cae9 2 parents 86a4e41 + 33e3c8d
@beberlei authored
Showing with 736 additions and 350 deletions.
  1. +1 −0  .gitignore
  2. +0 −59 README
  3. +62 −0 README.md
  4. +8 −8 build.xml
  5. +5 −5 manifest.mf
  6. +42 −42 nbproject/build-impl.xml
  7. +8 −8 nbproject/genfiles.properties
  8. +3 −2 nbproject/private/platform-private.properties
  9. +4 −4 nbproject/private/private.xml
  10. +1 −1  nbproject/project.properties
  11. +148 −140 nbproject/project.xml
  12. +2 −5 src/de/whitewashing/php/cs/CodeSnifferAction.java
  13. +145 −19 src/de/whitewashing/php/cs/command/CodeSniffer.java
  14. +0 −2  src/de/whitewashing/php/cs/command/CodeSnifferBuilder.java
  15. +13 −0 src/de/whitewashing/php/cs/command/CodeSnifferPhpException.java
  16. +2 −1  src/de/whitewashing/php/cs/command/CodeSnifferXmlLogParser.java
  17. +21 −1 src/de/whitewashing/php/cs/layer.xml
  18. +2 −0  src/de/whitewashing/php/cs/resources/cs-error-annotation.xml
  19. +2 −0  src/de/whitewashing/php/cs/resources/cs-warn-annotation.xml
  20. +7 −1 src/de/whitewashing/php/cs/ui/options/Bundle.properties
  21. +0 −2  src/de/whitewashing/php/cs/ui/options/CodeSnifferOptions.java
  22. +81 −12 src/de/whitewashing/php/cs/ui/options/CodeSnifferOptionsPanel.form
  23. +178 −33 src/de/whitewashing/php/cs/ui/options/CodeSnifferOptionsPanel.java
  24. +1 −5 src/de/whitewashing/php/cs/ui/options/CodeSnifferOptionsPanelController.java
View
1  .gitignore
@@ -1 +1,2 @@
build
+nbproject/
View
59 README
@@ -1,59 +0,0 @@
-Netbeans PHP Editor Extensions:
-==============================
-
-No Warranty whatsoever for this, it might break your Netbeans ;-)
-Only tested with netbeans 6.7, uses APIs that are not in 6.5.
-The module automatically scans for the "phpcs" executable inside the enviroment path.
-
-Currently this module has two little features:
-
-1. PHP Coding Standards Support for the Tasks Window
-2. Additionall "Show Coding Standards Violations" for Inline Highlighting of Violations
-
-TASK WINDOW
-==============
-
-Open up the Tasks Window from "Window - Tasks" or CTRL+6.
-
-To enable the Todo List CS Scanning you have to right click on the Filter Icon
-and Select "Edit". Add a New Filter "Coding Standards" and activate only "PHP Coding Standards"
-as task group and confirm. Then you have to click the uppermost icon on the left
-of the tasks window that enables "Current File Scope".
-
-For performance reasons the PHPCS plugin will only work in this mode, which
-means only the coding standard violations of the current file are shown
-in the task window.
-
-SHOW CODING VIOLATIONS
-======================
-
-Per right click on the Editor window you can select "Show Coding Standard" which
-highlights lines with warnings and errors. This highlights disappear when the file
-is changed and saved.
-
-CONFIGURE CODING-STANDARD
-=========================
-
-In the Advanced/Miscellaneous Tab of the Options Dialog you can chose which
-coding standard you want to use and where the PHPCS binary (script) is located.
-
-TODOS
-=====
-
-* Add project level Coding Standard Configuration
-
-EXTENDING THIS PLUGIN
-=====================
-
-If you git clone this project you have to modify the nbproject/private/platform-private.properties
-file and fill it with the following two properties:
-
- user.properties.file=/home/benny/.netbeans/6.8/build.properties
- nbplatform.default.harness.dir=/home/benny/programs/netbeans-6.8/harness
-
-THANK YOU NOTES
-===============
-
-We thank the following individuals for contributing code and knowledge to this project:
-
-Petr Pisl, tprochazka, Alexandre Haguiar
View
62 README.md
@@ -0,0 +1,62 @@
+
+Netbeans PHP Editor Extensions:
+==============================
+
+No Warranty whatsoever for this, it might break your Netbeans ;-)
+Tested only on Netbeans 7, but, should work with 6.7+.
+The module automatically scans for the "phpcs" executable inside the enviroment path.
+
+##Features:
+
+1. PHP Coding Standards Support for the Tasks Window.
+1. Highlighting of Violations (in editor):
+ * Right click on editor > __"Show Coding Standards Violations"__ or;
+ * Shift + F12 hotkey.
+1. Error stripe violations highlight: Every error appears as a little horizontal line at the right side of editor scrollbar.
+
+TASK WINDOW
+==============
+
+Open up the Tasks Window from "Window - Tasks" or CTRL+6.
+
+To enable the Todo List CS Scanning you have to right click on the Filter Icon and Select "Edit". Add a New Filter "Coding Standards" and activate only "PHP Coding Standards" as task group and confirm. Then you have to click the uppermost icon on the left of the tasks window that enables "Current File Scope".
+
+For performance reasons the PHPCS plugin will only work in this mode, which means only the coding standard violations of the current file are shown in the task window.
+
+CONFIGURE CODING-STANDARD
+=========================
+
+In the Advanced/Miscellaneous Tab of the Options Dialog you can choose which coding standard you want to use and where the PHPCS binary (script) is located.
+
+TODO'S
+=====
+
+* Add project level Coding Standard Configuration
+
+EXTENDING THIS PLUGIN
+=====================
+
+If you git clone this project you have to modify the nbproject/private/platform-private.properties file and fill it with the following two properties:
+
+ user.properties.file=/home/benny/.netbeans/6.8/build.properties
+ nbplatform.default.harness.dir=/home/benny/programs/netbeans-6.8/harness
+
+THANK YOU NOTES
+===============
+
+We thank the following individuals for contributing code and knowledge to this project:
+
+Petr Pisl, tprochazka, Alexandre Haguiar
+
+CHANGELOG
+===============
+###Version __1.2.0__:
+* __Added__: Shortcut, press Shift+F12 to analyse current file;
+* __Added__: Validation to the form/panel. Validates if PHPCS is working and if there are any valid Code Standards;
+* __Added__: Validation on preferences storage, avoids invalid settings to be saved;
+* __Added__: Refresh button on configuration panel. This button revalidates PHPCS binary and refresh code standards list at user will;
+* __Added__: Warnings/Errors are also added to the error stripe (column right to the editor scrollbar). Now one won't need to scroll all the file to find CS warnings/errors;
+* __Added__: Context menu for JS and CSS files (both also supported by PHPCS tokenizer);
+* __Added__: Show information dialog if no error/warnings were found;
+* __Added__: If PHPCS fails with a fatal error, show an information dialog;
+* __Fixed__: Exception handling if no CodeStandard is selected (NullPointerException).
View
16 build.xml
@@ -1,8 +1,8 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
-<!-- for some information on what you could do (e.g. targets to override). -->
-<!-- If you delete this file and reopen the project it will be recreated. -->
-<project name="de.whitewashing.php.cs" default="netbeans" basedir=".">
- <description>Builds, tests, and runs the project de.whitewashing.php.cs.</description>
- <import file="nbproject/build-impl.xml"/>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
+<!-- for some information on what you could do (e.g. targets to override). -->
+<!-- If you delete this file and reopen the project it will be recreated. -->
+<project name="de.whitewashing.php.cs" default="netbeans" basedir=".">
+ <description>Builds, tests, and runs the project de.whitewashing.php.cs.</description>
+ <import file="nbproject/build-impl.xml"/>
+</project>
View
10 manifest.mf
@@ -1,5 +1,5 @@
-Manifest-Version: 1.0
-OpenIDE-Module: de.whitewashing.php.cs/0
-OpenIDE-Module-Implementation-Version: 1
-OpenIDE-Module-Layer: de/whitewashing/php/cs/layer.xml
-OpenIDE-Module-Localizing-Bundle: de/whitewashing/php/cs/Bundle.properties
+Manifest-Version: 1.0
+OpenIDE-Module: de.whitewashing.php.cs/0
+OpenIDE-Module-Implementation-Version: 1
+OpenIDE-Module-Layer: de/whitewashing/php/cs/layer.xml
+OpenIDE-Module-Localizing-Bundle: de/whitewashing/php/cs/Bundle.properties
View
84 nbproject/build-impl.xml
@@ -1,42 +1,42 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-*** GENERATED FROM project.xml - DO NOT EDIT ***
-*** EDIT ../build.xml INSTEAD ***
--->
-<project name="de.whitewashing.php.cs-impl" basedir="..">
- <fail message="Please build using Ant 1.7.1 or higher.">
- <condition>
- <not>
- <antversion atleast="1.7.1"/>
- </not>
- </condition>
- </fail>
- <property file="nbproject/private/platform-private.properties"/>
- <property file="nbproject/platform.properties"/>
- <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
- <attribute name="name"/>
- <attribute name="value"/>
- <sequential>
- <property name="@{name}" value="${@{value}}"/>
- </sequential>
- </macrodef>
- <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
- <attribute name="property"/>
- <attribute name="value"/>
- <sequential>
- <property name="@{property}" value="@{value}"/>
- </sequential>
- </macrodef>
- <property file="${user.properties.file}"/>
- <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
- <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
- <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
- <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
- <condition>
- <not>
- <contains string="${cluster.path.evaluated}" substring="platform"/>
- </not>
- </condition>
- </fail>
- <import file="${harness.dir}/build.xml"/>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+*** GENERATED FROM project.xml - DO NOT EDIT ***
+*** EDIT ../build.xml INSTEAD ***
+-->
+<project name="de.whitewashing.php.cs-impl" basedir="..">
+ <fail message="Please build using Ant 1.7.1 or higher.">
+ <condition>
+ <not>
+ <antversion atleast="1.7.1"/>
+ </not>
+ </condition>
+ </fail>
+ <property file="nbproject/private/platform-private.properties"/>
+ <property file="nbproject/platform.properties"/>
+ <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2">
+ <attribute name="name"/>
+ <attribute name="value"/>
+ <sequential>
+ <property name="@{name}" value="${@{value}}"/>
+ </sequential>
+ </macrodef>
+ <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2">
+ <attribute name="property"/>
+ <attribute name="value"/>
+ <sequential>
+ <property name="@{property}" value="@{value}"/>
+ </sequential>
+ </macrodef>
+ <property file="${user.properties.file}"/>
+ <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
+ <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
+ <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/>
+ <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness).">
+ <condition>
+ <not>
+ <contains string="${cluster.path.evaluated}" substring="platform"/>
+ </not>
+ </condition>
+ </fail>
+ <import file="${harness.dir}/build.xml"/>
+</project>
View
16 nbproject/genfiles.properties
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=cf839f5c
-build.xml.script.CRC32=4128fe19
-build.xml.stylesheet.CRC32=79c3b980@1.31.1.7
-# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
-# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=cf839f5c
-nbproject/build-impl.xml.script.CRC32=8aa25b8f
-nbproject/build-impl.xml.stylesheet.CRC32=261c4bef@1.31.1.7
+build.xml.data.CRC32=11b337b4
+build.xml.script.CRC32=4128fe19
+build.xml.stylesheet.CRC32=a56c6a5b@1.46.1
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=11b337b4
+nbproject/build-impl.xml.script.CRC32=8aa25b8f
+nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.46.1
View
5 nbproject/private/platform-private.properties
@@ -1,2 +1,3 @@
-user.properties.file=/home/benny/.netbeans/6.8/build.properties
-nbplatform.default.harness.dir=/home/benny/programs/netbeans-6.8/harness
+user.properties.file=/home/willy/.netbeans/7.0/build.properties
+nbplatform.default.harness.dir=/home/willy/netbeans-7.0.1/harness
+#nbplatform.default.harness.dir=C:\\Program Files\\NetBeans 7.0.1\\harness
View
8 nbproject/private/private.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
- <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
-</project-private>
+<?xml version="1.0" encoding="UTF-8"?>
+<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
+ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
+</project-private>
View
2  nbproject/project.properties
@@ -3,4 +3,4 @@ javac.compilerargs=-Xlint -Xlint:-serial
license.file=LICENSE
nbm.homepage=http://github.com/beberlei/netbeans-php-enhancements
nbm.module.author=Manuel Piechler, Benjamin Eberlei
-spec.version.base=1.1
+spec.version.base=1.2
View
288 nbproject/project.xml
@@ -1,140 +1,148 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://www.netbeans.org/ns/project/1">
- <type>org.netbeans.modules.apisupport.project</type>
- <configuration>
- <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
- <code-name-base>de.whitewashing.php.cs</code-name-base>
- <standalone/>
- <module-dependencies>
- <dependency>
- <code-name-base>org.jdesktop.layout</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <release-version>1</release-version>
- <specification-version>1.7.1.103</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.netbeans.modules.extexecution</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <release-version>2</release-version>
- <specification-version>1.14.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.netbeans.modules.options.api</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <release-version>1</release-version>
- <specification-version>1.12.2</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <release-version>1</release-version>
- <specification-version>1.39.1.6</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.netbeans.modules.settings</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <release-version>1</release-version>
- <specification-version>1.18.1.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.netbeans.spi.tasklist</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <release-version>1</release-version>
- <specification-version>1.4.1.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.openide.actions</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <specification-version>6.11.1.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.openide.awt</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <specification-version>7.8.1.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.openide.filesystems</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <specification-version>7.21.1.1.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.openide.loaders</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <specification-version>7.5.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.openide.nodes</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <specification-version>7.9.1.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.openide.text</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <specification-version>6.22.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.openide.util</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <specification-version>7.22.1.1</specification-version>
- </run-dependency>
- </dependency>
- <dependency>
- <code-name-base>org.openide.windows</code-name-base>
- <build-prerequisite/>
- <compile-dependency/>
- <run-dependency>
- <specification-version>6.26.1</specification-version>
- </run-dependency>
- </dependency>
- </module-dependencies>
- <test-dependencies>
- <test-type>
- <name>unit</name>
- <test-dependency>
- <code-name-base>org.netbeans.libs.junit4</code-name-base>
- <compile-dependency/>
- </test-dependency>
- </test-type>
- </test-dependencies>
- <public-packages/>
- </data>
- </configuration>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.apisupport.project</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
+ <code-name-base>de.whitewashing.php.cs</code-name-base>
+ <standalone/>
+ <module-dependencies>
+ <dependency>
+ <code-name-base>org.jdesktop.layout</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.7.1.103</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.extexecution</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>2</release-version>
+ <specification-version>1.14.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.options.api</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.12.2</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.projectuiapi</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.39.1.6</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.settings</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.18.1.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.spi.tasklist</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.4.1.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.actions</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>6.11.1.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.awt</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.8.1.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.dialogs</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.20.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.filesystems</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.21.1.1.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.loaders</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.5.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.nodes</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.9.1.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.text</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>6.22.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.util</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.22.1.1</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.windows</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>6.26.1</specification-version>
+ </run-dependency>
+ </dependency>
+ </module-dependencies>
+ <test-dependencies>
+ <test-type>
+ <name>unit</name>
+ <test-dependency>
+ <code-name-base>org.netbeans.libs.junit4</code-name-base>
+ <compile-dependency/>
+ </test-dependency>
+ </test-type>
+ </test-dependencies>
+ <public-packages/>
+ </data>
+ </configuration>
+</project>
View
7 src/de/whitewashing/php/cs/CodeSnifferAction.java
@@ -5,7 +5,6 @@
package de.whitewashing.php.cs;
import de.whitewashing.php.cs.command.CodeSnifferBuilder;
-import de.whitewashing.php.cs.command.CodeSniffer;
import javax.swing.JMenuItem;
import org.openide.cookies.EditorCookie;
import org.openide.nodes.Node;
@@ -17,15 +16,13 @@
public final class CodeSnifferAction extends CookieAction {
- private CodeSniffer codeSniffer = CodeSnifferBuilder.createOrReturn();
-
protected void performAction(Node[] activatedNodes) {
if(activatedNodes.length != 1) {
return;
}
FileObject fo = getFileObject(activatedNodes[0]);
- this.codeSniffer.execute(fo, true);
+ CodeSnifferBuilder.createOrReturn().execute(fo, true);
}
/**
@@ -95,7 +92,7 @@ protected boolean asynchronous() {
protected JMenuItem setEnabledForExistingBinary(JMenuItem item)
{
- item.setEnabled(this.codeSniffer.isEnabled());
+ item.setEnabled(CodeSnifferBuilder.createOrReturn().isEnabled());
return item;
}
}
View
164 src/de/whitewashing/php/cs/command/CodeSniffer.java
@@ -4,6 +4,7 @@
*/
package de.whitewashing.php.cs.command;
+import java.io.BufferedReader;
import java.util.concurrent.ExecutionException;
import java.io.File;
import java.io.IOException;
@@ -11,9 +12,14 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.netbeans.api.extexecution.ExecutionDescriptor;
import org.netbeans.api.extexecution.ExecutionService;
import org.netbeans.api.extexecution.ExternalProcessBuilder;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+import org.openide.cookies.EditorCookie;
import org.openide.cookies.LineCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
@@ -35,6 +41,11 @@
private String codingStandard;
private boolean showWarnings;
+ public void setShellScript(String shellScript) {
+ this.shellScript = shellScript;
+ }
+
+
public CodeSniffer(String shellScript, String codingStandard, boolean showWarnings) {
this.shellScript = shellScript;
this.codingStandard = codingStandard;
@@ -42,7 +53,43 @@ public CodeSniffer(String shellScript, String codingStandard, boolean showWarnin
}
public boolean isEnabled() {
- return this.shellScript !=null && new File(this.shellScript).exists();
+ if(this.shellScript == null || this.shellScript.equals("")) {
+ return false;
+ } else {
+ File shellFile = new File(this.shellScript);
+ return shellFile.isFile() && shellFile.canExecute();
+ }
+ }
+
+ public String getVersion() {
+ if(!isEnabled()) {
+ return "?";
+ }
+
+ ExternalProcessBuilder procBuilder = new ExternalProcessBuilder(this.shellScript)
+ .addArgument("--version");
+
+ try {
+ ProcessExecutor executor = new ProcessExecutor();
+ Reader executedProcess = executor.execute(procBuilder);
+
+ // Handle PHP Exceptions
+ handlePhpExceptions(executedProcess);
+
+ String versionLine = this.getStringFromReader(executedProcess);
+ Pattern pattern = Pattern.compile("(?:CodeSniffer.*?)(?:v\\.?(?:ersion)?\\s+)([0-9]+\\.[0-9]+(?:\\.[0-9]+)?)", Pattern.CASE_INSENSITIVE);
+ Matcher m = pattern.matcher(versionLine);
+ if(!m.find()) {
+ return "?";
+ }
+
+ return m.group(1);
+ } catch(CodeSnifferPhpException e) {
+ DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE));
+ return "?";
+ } catch(java.io.IOException e) {
+ return "?";
+ }
}
public List<String> getAvailableStandards() {
@@ -50,12 +97,24 @@ public boolean isEnabled() {
return new ArrayList<String>();
}
- ExternalProcessBuilder procBuilder = new ExternalProcessBuilder(this.shellScript)
- .addArgument("-i");
+ try {
+ ExternalProcessBuilder procBuilder = new ExternalProcessBuilder(this.shellScript)
+ .addArgument("-i");
- ProcessExecutor executor = new ProcessExecutor();
- StupidStandardsOutputParser parser = new StupidStandardsOutputParser();
- return parser.parse(executor.execute(procBuilder));
+ ProcessExecutor executor = new ProcessExecutor();
+ StupidStandardsOutputParser parser = new StupidStandardsOutputParser();
+
+ Reader executedProcess = executor.execute(procBuilder);
+
+ // Handle PHP Exceptions
+ handlePhpExceptions(executedProcess);
+
+ return parser.parse(executedProcess);
+ } catch(java.io.IOException e) {
+ DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE));
+ }
+
+ return new ArrayList<String>();
}
public CodeSnifferXmlLogResult execute(FileObject fo) {
@@ -68,9 +127,9 @@ public CodeSnifferXmlLogResult execute(FileObject fo, boolean annotateLines) {
if(parent == null || this.isEnabled() == false) {
return CodeSnifferXmlLogResult.empty();
}
-
+
+ // Executes PHPCS
ExternalProcessBuilder externalProcessBuilder;
-
if (this.showWarnings) {
externalProcessBuilder = new ExternalProcessBuilder(this.shellScript)
.workingDirectory(parent)
@@ -87,11 +146,27 @@ public CodeSnifferXmlLogResult execute(FileObject fo, boolean annotateLines) {
}
CodeSnifferXmlLogParser parser = new CodeSnifferXmlLogParser();
- CodeSnifferXmlLogResult rs = parser.parse(new ProcessExecutor().execute(externalProcessBuilder));
+ Reader executedProcess = new ProcessExecutor().execute(externalProcessBuilder);
- if(annotateLines) {
- annotateWithCodingStandardHints(fo, rs);
+ CodeSnifferXmlLogResult rs = CodeSnifferXmlLogResult.empty();
+ try {
+ // Handle PHP Exceptions
+ handlePhpExceptions(executedProcess);
+
+ // Parse response
+ rs = parser.parse(executedProcess);
+ if(annotateLines) {
+ annotateWithCodingStandardHints(fo, rs);
+ }
+
+ // Check if we have no errors at all
+ if(rs.getCsErrors().isEmpty() && rs.getCsWarnings().isEmpty())
+ DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Great!\nNo errors or warnings found.", NotifyDescriptor.INFORMATION_MESSAGE));
+ } catch(java.io.IOException e) {
+ DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(e.getMessage(), NotifyDescriptor.ERROR_MESSAGE));
}
+
+ // Progress bar finish
return rs;
}
@@ -99,11 +174,11 @@ private void annotateWithCodingStandardHints(FileObject fo, CodeSnifferXmlLogRes
CodeSnifferFileListener l = new CodeSnifferFileListener();
l.setLogResult(rs);
fo.addFileChangeListener(l);
-
+
try {
DataObject d = DataObject.find(fo);
LineCookie cookie = d.getCookie(LineCookie.class);
-
+
Line.Set lineSet = null;
Line line = null;
for (int i = 0; i < rs.getCsErrors().size(); i++) {
@@ -121,6 +196,20 @@ private void annotateWithCodingStandardHints(FileObject fo, CodeSnifferXmlLogRes
Exceptions.printStackTrace(ex);
}
}
+
+ /**
+ * Creates a simple string from the given input reader.
+ * This method will not handle exceptions.
+ *
+ * @param reader The raw input stream.
+ *
+ * @return String
+ */
+ private String getStringFromReader(Reader reader)
+ throws IOException
+ {
+ return new BufferedReader(reader).readLine();
+ }
/**
* Small utility class that is used to execute an external CodeSniffer process.
@@ -136,6 +225,7 @@ private void annotateWithCodingStandardHints(FileObject fo, CodeSnifferXmlLogRes
* @return Reader
*/
public Reader execute(ExternalProcessBuilder builder) {
+ builder = builder.redirectErrorStream(true);
CodeSnifferOutput output = new CodeSnifferOutput();
ExecutionDescriptor descriptor = new ExecutionDescriptor()
@@ -156,6 +246,47 @@ public Reader execute(ExternalProcessBuilder builder) {
return output.getReader();
}
}
+
+ /**
+ * Reads the stream searching for fatal errors when executing PHPCS
+ */
+ public void handlePhpExceptions(Reader reader)
+ throws CodeSnifferPhpException, IOException
+ {
+ BufferedReader output = new BufferedReader(reader);
+ String ln;
+ while((ln = output.readLine()) != null) {
+ String message = "";
+
+ // Treats fatal errors and parse errors that PHP may throw
+ if(ln.indexOf("Fatal error:") >= 0 || ln.indexOf("Parse error:") >= 0) {
+ if(ln.indexOf("Fatal error:") >= 0) {
+ Matcher m = Pattern.compile(
+ "Fatal error:\\s+(.*(?:line\\s+|:)[0-9]+)",
+ Pattern.CASE_INSENSITIVE
+ ).matcher(ln);
+ if(m.find())
+ message = m.group(1);
+ } else if(ln.indexOf("Parse error:") >= 0) {
+ Matcher m = Pattern.compile(
+ "Parse error:\\s+(.*(?:line\\s+|:)[0-9]+)",
+ Pattern.CASE_INSENSITIVE
+ ).matcher(ln);
+ if(m.find())
+ message = m.group(1);
+ }
+
+ String finalMessage = "A fatal error occured, check your PHPCS installation.";
+ if(!message.equals(""))
+ finalMessage += "\nError:\n" + message;
+
+ reader.reset();
+ throw new CodeSnifferPhpException(finalMessage);
+ }
+ }
+
+ reader.reset();
+ }
/**
* Utility class that parses the textual output of the CodeSniffer -i option
@@ -195,12 +326,7 @@ public Reader execute(ExternalProcessBuilder builder) {
*/
private String getStringFromReader(Reader reader) {
try {
- char[] chars = new char[1024];
- reader.read(chars);
- StringBuilder sb = new StringBuilder();
- sb.append(chars);
-
- return sb.toString();
+ return CodeSniffer.this.getStringFromReader(reader);
} catch (IOException e) {
return this.DEFAULT_STANDARDS;
}
View
2  src/de/whitewashing/php/cs/command/CodeSnifferBuilder.java
@@ -6,7 +6,6 @@
package de.whitewashing.php.cs.command;
import de.whitewashing.php.cs.ui.options.CodeSnifferOptions;
-import java.util.ArrayList;
/**
* Simple factory/singleton that creates a unique CodeSniffer instance based
@@ -27,7 +26,6 @@ public static CodeSniffer createOrReturn() {
public static CodeSniffer create() {
CodeSnifferOptions options = new CodeSnifferOptions();
-
return (codeSniffer = new CodeSniffer(options.getShellScript(), options.getCodingStandard(), options.hasShowWarnings()));
}
}
View
13 src/de/whitewashing/php/cs/command/CodeSnifferPhpException.java
@@ -0,0 +1,13 @@
+package de.whitewashing.php.cs.command;
+
+/**
+ * Default exception when
+ * @author Willy Barro
+ */
+public class CodeSnifferPhpException extends java.io.IOException {
+
+ CodeSnifferPhpException(String finalMessage) {
+ super(finalMessage);
+ }
+
+}
View
3  src/de/whitewashing/php/cs/command/CodeSnifferXmlLogParser.java
@@ -46,6 +46,7 @@ CodeSnifferXmlLogResult parse(Reader reader)
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
+ String exception = "";
try {
builder = factory.newDocumentBuilder();
Document document;
@@ -70,7 +71,7 @@ CodeSnifferXmlLogResult parse(Reader reader)
} catch (ParserConfigurationException ex) {
} catch(SAXParseException ex) {
-
+ exception = ex.getMessage();
} catch (SAXException ex) {
}
View
22 src/de/whitewashing/php/cs/layer.xml
@@ -16,13 +16,33 @@
</file>
</folder>
</folder>
+ <folder name="javascript">
+ <folder name="Popup">
+ <file name="de-whitewashing-php-cs-CodeSnifferAction.shadow">
+ <attr name="originalFile" stringvalue="Actions/PHP/de-whitewashing-php-cs-CodeSnifferAction.instance"/>
+ <attr name="position" intvalue="875"/>
+ </file>
+ </folder>
+ </folder>
+ <folder name="x-css">
+ <folder name="Popup">
+ <file name="de-whitewashing-php-cs-CodeSnifferAction.shadow">
+ <attr name="originalFile" stringvalue="Actions/PHP/de-whitewashing-php-cs-CodeSnifferAction.instance"/>
+ <attr name="position" intvalue="875"/>
+ </file>
+ </folder>
+ </folder>
</folder>
-
<folder name="AnnotationTypes">
<file name="de-whitewashing-php-cs-annotation-warning.xml" url="nbresloc:/de/whitewashing/php/cs/resources/cs-warn-annotation.xml"/>
<file name="de-whitewashing-php-cs-annotation-error.xml" url="nbresloc:/de/whitewashing/php/cs/resources/cs-error-annotation.xml"/>
</folder>
</folder>
+ <folder name="Shortcuts">
+ <file name="S-F12.shadow">
+ <attr name="originalFile" stringvalue="Actions/PHP/de-whitewashing-php-cs-CodeSnifferAction.instance"/>
+ </file>
+ </folder>
<folder name="Loaders">
<folder name="text">
<folder name="x-php5">
View
2  src/de/whitewashing/php/cs/resources/cs-error-annotation.xml
@@ -6,5 +6,7 @@
visible="true"
glyph="nbresloc:/de/whitewashing/php/cs/resources/cserror.png"
highlight="#FFCFCF"
+ custom_sidebar_color="#FF0000"
type="line"
+ severity="warning"
/>
View
2  src/de/whitewashing/php/cs/resources/cs-warn-annotation.xml
@@ -6,5 +6,7 @@
visible="true"
glyph="nbresloc:/de/whitewashing/php/cs/resources/cswarn.png"
highlight="#FFFBCF"
+ custom_sidebar_color="#FFBE00"
type="line"
+ severity="warning"
/>
View
8 src/de/whitewashing/php/cs/ui/options/Bundle.properties
@@ -7,4 +7,10 @@ LBL_CodeSnifferSelect=Select CodeSniffer script
CodeSnifferPanel.AccessibleContext.accessibleDescription=Panel for CodeSniffer options.
CodeSnifferOptionsPanel.browseButton.text=Browse...
CodeSnifferOptionsPanel.codeSnifferLabel.text=CodeSniffer script:
-CodeSnifferOptionsPanel.codeSnifferTextField.text=
+CodeSnifferOptionsPanel.codeSnifferTextField.text=
+CodeSnifferOptionsPanel.refreshButton.toolTipText=Refresh CodeSniffer scripts and available standards.
+CodeSnifferOptionsPanel.refreshButton.text=Refresh
+CodeSnifferOptionsPanel.statusLabel.text=Status:
+CodeSnifferOptionsPanel.versionLabel.text=Version:
+CodeSnifferOptionsPanel.versionTextLabel.text=?
+CodeSnifferOptionsPanel.statusTextLabel.text=?
View
2  src/de/whitewashing/php/cs/ui/options/CodeSnifferOptions.java
@@ -6,8 +6,6 @@
package de.whitewashing.php.cs.ui.options;
import de.whitewashing.php.cs.command.CodeSniffer;
-import de.whitewashing.php.cs.command.CodeSniffer;
-import de.whitewashing.php.cs.command.CodeSnifferBinary;
import de.whitewashing.php.cs.command.CodeSnifferBinary;
import java.util.ArrayList;
import java.util.List;
View
93 src/de/whitewashing/php/cs/ui/options/CodeSnifferOptionsPanel.form
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8" ?>
+<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties>
@@ -29,25 +29,40 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
- <Group type="102" alignment="0" attributes="0">
- <EmptySpace max="-2" attributes="0"/>
+ <Group type="102" attributes="0">
+ <EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
+ <Component id="labelStandard" min="-2" max="-2" attributes="0"/>
<Component id="codeSnifferLabel" alignment="1" min="-2" max="-2" attributes="0"/>
- <Component id="labelStandard" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
- <Component id="checkBoxShowWarnings" alignment="0" pref="469" max="32767" attributes="1"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" max="-2" attributes="0">
- <Component id="inputBoxStandard" alignment="0" max="32767" attributes="1"/>
- <Component id="codeSnifferTextField" alignment="0" min="-2" pref="365" max="-2" attributes="1"/>
+ <Component id="statusLabel" alignment="1" max="32767" attributes="1"/>
+ <Component id="versionLabel" alignment="1" max="32767" attributes="1"/>
+ </Group>
+ <EmptySpace max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="0" max="-2" attributes="0">
+ <Component id="versionTextLabel" max="32767" attributes="1"/>
+ <Component id="statusTextLabel" alignment="0" pref="261" max="32767" attributes="1"/>
+ </Group>
+ </Group>
+ <Group type="102" alignment="0" attributes="0">
+ <Group type="103" groupAlignment="1" attributes="0">
+ <Component id="codeSnifferTextField" min="-2" pref="350" max="-2" attributes="1"/>
+ <Group type="103" alignment="1" groupAlignment="0" attributes="0">
+ <Component id="checkBoxShowWarnings" alignment="0" min="-2" pref="230" max="-2" attributes="1"/>
+ <Component id="inputBoxStandard" alignment="0" min="-2" pref="350" max="-2" attributes="1"/>
+ </Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="browseButton" min="-2" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Component id="refreshButton" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
- <EmptySpace max="-2" attributes="0"/>
+ <EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -56,18 +71,29 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
- <Component id="codeSnifferLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="codeSnifferTextField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="browseButton" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="refreshButton" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="codeSnifferLabel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
- <EmptySpace type="unrelated" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="3" attributes="0">
+ <Component id="statusLabel" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="statusTextLabel" alignment="3" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="3" attributes="0">
+ <Component id="versionLabel" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="versionTextLabel" alignment="3" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="inputBoxStandard" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="labelStandard" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
- <EmptySpace type="separate" max="-2" attributes="0"/>
+ <EmptySpace max="-2" attributes="0"/>
<Component id="checkBoxShowWarnings" min="-2" max="-2" attributes="0"/>
- <EmptySpace pref="208" max="32767" attributes="0"/>
+ <EmptySpace pref="185" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -124,5 +150,48 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="browseButtonActionPerformed"/>
</Events>
</Component>
+ <Component class="javax.swing.JButton" name="refreshButton">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="de/whitewashing/php/cs/ui/options/Bundle.properties" key="CodeSnifferOptionsPanel.refreshButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="de/whitewashing/php/cs/ui/options/Bundle.properties" key="CodeSnifferOptionsPanel.refreshButton.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="refreshButtonActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JLabel" name="statusTextLabel">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="de/whitewashing/php/cs/ui/options/Bundle.properties" key="CodeSnifferOptionsPanel.statusTextLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JLabel" name="statusLabel">
+ <Properties>
+ <Property name="horizontalAlignment" type="int" value="4"/>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="de/whitewashing/php/cs/ui/options/Bundle.properties" key="CodeSnifferOptionsPanel.statusLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JLabel" name="versionLabel">
+ <Properties>
+ <Property name="horizontalAlignment" type="int" value="4"/>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="de/whitewashing/php/cs/ui/options/Bundle.properties" key="CodeSnifferOptionsPanel.versionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JLabel" name="versionTextLabel">
+ <Properties>
+ <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+ <ResourceString bundle="de/whitewashing/php/cs/ui/options/Bundle.properties" key="CodeSnifferOptionsPanel.versionTextLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+ </Property>
+ </Properties>
+ </Component>
</SubComponents>
</Form>
View
211 src/de/whitewashing/php/cs/ui/options/CodeSnifferOptionsPanel.java
@@ -10,7 +10,11 @@
*/
package de.whitewashing.php.cs.ui.options;
+import de.whitewashing.php.cs.command.CodeSniffer;
+import de.whitewashing.php.cs.command.CodeSnifferBuilder;
+import java.awt.Color;
import java.io.File;
+import java.util.List;
import org.openide.filesystems.FileChooserBuilder;
import org.openide.filesystems.FileUtil;
import org.openide.util.NbBundle;
@@ -26,11 +30,10 @@
*/
private static final String CODE_SNIFFER_LAST_FOLDER_SUFFIX = ".codeSniffer";
+ private CodeSniffer command = null;
private CodeSnifferOptions options = null;
- public CodeSnifferOptionsPanel(CodeSnifferOptions options) {
- this.options = options;
-
+ public CodeSnifferOptionsPanel() {
initComponents();
}
@@ -49,6 +52,11 @@ private void initComponents() {
codeSnifferLabel = new javax.swing.JLabel();
codeSnifferTextField = new javax.swing.JTextField();
browseButton = new javax.swing.JButton();
+ refreshButton = new javax.swing.JButton();
+ statusTextLabel = new javax.swing.JLabel();
+ statusLabel = new javax.swing.JLabel();
+ versionLabel = new javax.swing.JLabel();
+ versionTextLabel = new javax.swing.JLabel();
setNextFocusableComponent(this);
setPreferredSize(new java.awt.Dimension(612, 322));
@@ -70,41 +78,79 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
+ refreshButton.setText(org.openide.util.NbBundle.getMessage(CodeSnifferOptionsPanel.class, "CodeSnifferOptionsPanel.refreshButton.text")); // NOI18N
+ refreshButton.setToolTipText(org.openide.util.NbBundle.getMessage(CodeSnifferOptionsPanel.class, "CodeSnifferOptionsPanel.refreshButton.toolTipText")); // NOI18N
+ refreshButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ refreshButtonActionPerformed(evt);
+ }
+ });
+
+ statusTextLabel.setText(org.openide.util.NbBundle.getMessage(CodeSnifferOptionsPanel.class, "CodeSnifferOptionsPanel.statusTextLabel.text")); // NOI18N
+
+ statusLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+ statusLabel.setText(org.openide.util.NbBundle.getMessage(CodeSnifferOptionsPanel.class, "CodeSnifferOptionsPanel.statusLabel.text")); // NOI18N
+
+ versionLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+ versionLabel.setText(org.openide.util.NbBundle.getMessage(CodeSnifferOptionsPanel.class, "CodeSnifferOptionsPanel.versionLabel.text")); // NOI18N
+
+ versionTextLabel.setText(org.openide.util.NbBundle.getMessage(CodeSnifferOptionsPanel.class, "CodeSnifferOptionsPanel.versionTextLabel.text")); // NOI18N
+
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
- .addContainerGap()
+ .add(18, 18, 18)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
- .add(codeSnifferLabel)
- .add(labelStandard))
+ .add(labelStandard)
+ .add(codeSnifferLabel))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
- .add(checkBoxShowWarnings, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
- .add(org.jdesktop.layout.GroupLayout.LEADING, inputBoxStandard, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .add(org.jdesktop.layout.GroupLayout.LEADING, codeSnifferTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 365, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
+ .add(statusLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .add(versionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
+ .add(versionTextLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .add(statusTextLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)))
+ .add(layout.createSequentialGroup()
+ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
+ .add(codeSnifferTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 350, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
+ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
+ .add(checkBoxShowWarnings, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 230, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
+ .add(inputBoxStandard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 350, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
- .add(browseButton)))
- .addContainerGap())
+ .add(browseButton)
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+ .add(refreshButton)))
+ .add(18, 18, 18))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
- .add(codeSnifferLabel)
.add(codeSnifferTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
- .add(browseButton))
- .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
+ .add(browseButton)
+ .add(refreshButton)
+ .add(codeSnifferLabel))
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
+ .add(statusLabel)
+ .add(statusTextLabel))
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
+ .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
+ .add(versionLabel)
+ .add(versionTextLabel))
+ .add(18, 18, 18)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(inputBoxStandard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(labelStandard))
- .add(18, 18, 18)
+ .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(checkBoxShowWarnings)
- .addContainerGap(208, Short.MAX_VALUE))
+ .addContainerGap(185, Short.MAX_VALUE))
);
getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CodeSnifferOptionsPanel.class, "CodeSnifferPanel.AccessibleContext.accessibleDescription")); // NOI18N
@@ -118,35 +164,129 @@ private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
if (codeSnifferScript != null) {
codeSnifferScript = FileUtil.normalizeFile(codeSnifferScript);
codeSnifferTextField.setText(codeSnifferScript.getAbsolutePath());
+ refresh();
}
}//GEN-LAST:event_browseButtonActionPerformed
+private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
+ refresh();
+}//GEN-LAST:event_refreshButtonActionPerformed
+
+ /**
+ * Loads everything that were previously set (if any) and refresh
+ */
void load() {
- inputBoxStandard.removeAllItems();
- for (String standard : this.options.getCodingStandards()) {
- inputBoxStandard.addItem(standard);
+ command = CodeSnifferBuilder.createOrReturn();
+
+ // Gets available standards
+ options = new CodeSnifferOptions(command.getAvailableStandards());
+
+ // Fill inputs with previously saved preferences
+ fillForm();
+
+ //
+ refresh();
+ }
+
+ /**
+ * Refresh current form
+ * Validates if PHPCS is installed and loads latest code standards
+ */
+ void refresh() {
+ String csPath = codeSnifferTextField.getText();
+ command.setShellScript(csPath);
+
+ if(valid()) {
+ store(true);
+
+ statusTextLabel.setText("Activated");
+ statusTextLabel.setForeground(new Color(16, 110, 0));
+
+ inputBoxStandard.setEnabled(true);
+ checkBoxShowWarnings.setEnabled(true);
+
+ // Updates inputs with new provided data (if any)
+ fillForm();
+ } else {
+ inputBoxStandard.setEnabled(false);
+ checkBoxShowWarnings.setEnabled(false);
+ checkBoxShowWarnings.setSelected(false);
+ statusTextLabel.setForeground(Color.RED);
}
+
+ versionTextLabel.setText(command.getVersion());
+ }
+
+ /**
+ * Validates form, PHPCS script and standards
+ * @return boolean
+ */
+ boolean valid() {
+ boolean isValid;
+
+ // Gets PHPCS version, if "?" then, valid PHPCS were not found
+ if(command.getVersion().equals("?")) {
+ isValid = false;
+ statusTextLabel.setText("Invalid CodeSniffer script");
+ } else {
+ // Gets available standards
+ List<String> availableStandards = command.getAvailableStandards();
+ options = new CodeSnifferOptions(availableStandards);
- inputBoxStandard.setSelectedItem(options.getCodingStandard());
- checkBoxShowWarnings.setSelected(options.hasShowWarnings());
- codeSnifferTextField.setText(options.getShellScript());
+ if(availableStandards.isEmpty()) {
+ isValid = false;
+ statusTextLabel.setText("No code standards found");
+ } else {
+ isValid = true;
+ }
+ }
+
+ return isValid;
}
+ /**
+ * Store method as NB need it (without arguments)
+ */
void store() {
- // Only add when a standard exists
- options.setCodingStandard((String) inputBoxStandard.getSelectedItem());
- options.setShowWarnings(checkBoxShowWarnings.isSelected());
- options.setShellScript(codeSnifferTextField.getText());
-
- // or:
- // SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText());
-
+ store(false);
}
+
+ /**
+ * Store method, will persist set NBPreferences
+ * @param assumeValid If validation should be run again. If true, avoids unnecessary validations.
+ */
+ void store(boolean assumeValid) {
+ if(assumeValid || valid()) {
+ // Only add when a standard exists
+ String selectedItem = (String) inputBoxStandard.getSelectedItem();
+ if(selectedItem != null) {
+ options.setCodingStandard((String) inputBoxStandard.getSelectedItem());
+ }
- boolean valid() {
- // TODO check whether form is consistent and complete
- return true;
+ options.setShowWarnings(checkBoxShowWarnings.isSelected());
+ options.setShellScript(codeSnifferTextField.getText());
+
+ // or:
+ // SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText());
+ }
}
+
+ /**
+ * Fill form input's and checkboxes with nbpreferences data
+ */
+ void fillForm() {
+ // Remove all standards
+ inputBoxStandard.removeAllItems();
+
+ for(String standard : options.getCodingStandards()) {
+ inputBoxStandard.addItem(standard);
+ }
+
+ inputBoxStandard.setSelectedItem(options.getCodingStandard());
+ checkBoxShowWarnings.setSelected(options.hasShowWarnings());
+ codeSnifferTextField.setText(options.getShellScript());
+ }
+
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton browseButton;
private javax.swing.JCheckBox checkBoxShowWarnings;
@@ -154,5 +294,10 @@ boolean valid() {
private javax.swing.JTextField codeSnifferTextField;
private javax.swing.JComboBox inputBoxStandard;
private javax.swing.JLabel labelStandard;
+ private javax.swing.JButton refreshButton;
+ private javax.swing.JLabel statusLabel;
+ private javax.swing.JLabel statusTextLabel;
+ private javax.swing.JLabel versionLabel;
+ private javax.swing.JLabel versionTextLabel;
// End of variables declaration//GEN-END:variables
}
View
6 src/de/whitewashing/php/cs/ui/options/CodeSnifferOptionsPanelController.java
@@ -4,7 +4,6 @@
*/
package de.whitewashing.php.cs.ui.options;
-import de.whitewashing.php.cs.command.CodeSniffer;
import de.whitewashing.php.cs.command.CodeSnifferBuilder;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
@@ -62,10 +61,7 @@ public void removePropertyChangeListener(PropertyChangeListener l) {
private CodeSnifferOptionsPanel getPanel() {
if (panel == null) {
- CodeSniffer command = CodeSnifferBuilder.createOrReturn();
- CodeSnifferOptions options = new CodeSnifferOptions(command.getAvailableStandards());
-
- panel = new CodeSnifferOptionsPanel(options);
+ panel = new CodeSnifferOptionsPanel();
}
return panel;
}
Please sign in to comment.
Something went wrong with that request. Please try again.