Skip to content

Commit e7b3c49

Browse files
author
skiera
committed
0 parents  commit e7b3c49

29 files changed

+2760
-0
lines changed

.classpath

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

.project

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Plugin_org.phpsrc.eclipse.pti.tools.codesniffer</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>

META-INF/MANIFEST.MF

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: PHP Tool Codesniffer
4+
Bundle-SymbolicName: org.phpsrc.eclipse.pti.tools.codesniffer;singleton:=true
5+
Bundle-Version: 1.2.3.R20100314000000
6+
Bundle-Activator: org.phpsrc.eclipse.pti.tools.codesniffer.PHPCodeSnifferPlugin
7+
Bundle-Vendor: Sven Kiera
8+
Require-Bundle: org.eclipse.ui,
9+
org.eclipse.core.runtime,
10+
org.phpsrc.eclipse.pti.core;bundle-version="1.3.0",
11+
org.phpsrc.eclipse.pti.library.pear;bundle-version="1.2.0",
12+
org.eclipse.php.ui;bundle-version="2.1.0",
13+
org.eclipse.php.debug.core;bundle-version="2.1.0",
14+
org.eclipse.php.debug.ui;bundle-version="2.1.0",
15+
org.eclipse.core.resources;bundle-version="3.4.1",
16+
org.eclipse.dltk.core,
17+
org.eclipse.wst.validation,
18+
org.eclipse.debug.ui;bundle-version="3.4.1",
19+
org.eclipse.wst.html.core;bundle-version="1.1.203",
20+
org.eclipse.wst.xml.core;bundle-version="1.1.306",
21+
org.eclipse.wst.sse.core;bundle-version="1.1.302",
22+
org.eclipse.ui.ide;bundle-version="3.4.1",
23+
org.eclipse.wst.sse.ui;bundle-version="1.1.100"
24+
Bundle-RequiredExecutionEnvironment: J2SE-1.5
25+
Bundle-ActivationPolicy: lazy
26+
Export-Package: org.phpsrc.eclipse.pti.tools.codesniffer,
27+
org.phpsrc.eclipse.pti.tools.codesniffer.core.preferences

build.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.,\
5+
plugin.xml,\
6+
bin/,\
7+
php/,\
8+
icons/
9+
src.includes = src/,\
10+
php/,\
11+
META-INF/

icons/obj16/phpsrc.gif

632 Bytes
Loading

icons/obj16/validate_resource.gif

616 Bytes
Loading

php/tools/phpcs.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* PHP_CodeSniffer tokenises PHP code and detects violations of a
4+
* defined set of coding standards.
5+
*
6+
* PHP version 5
7+
*
8+
* @category PHP
9+
* @package PHP_CodeSniffer
10+
* @author Greg Sherwood <[email protected]>
11+
* @author Marc McIntyre <[email protected]>
12+
* @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
13+
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
14+
* @version CVS: $Id: phpcs,v 1.40 2008/03/10 02:39:04 squiz Exp $
15+
* @link http://pear.php.net/package/PHP_CodeSniffer
16+
*/
17+
18+
error_reporting(E_ALL | E_STRICT);
19+
ob_start();
20+
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
21+
include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
22+
} else {
23+
include_once 'PHP/CodeSniffer/CLI.php';
24+
}
25+
26+
$phpcs = new PHP_CodeSniffer_CLI();
27+
$phpcs->checkRequirements();
28+
29+
$numErrors = $phpcs->process();
30+
$sOutput = ob_get_flush();
31+
32+
if ($numErrors === 0) {
33+
exit(0);
34+
} else {
35+
exit(1);
36+
}
37+
38+
?>

plugin.xml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?eclipse version="3.4"?>
3+
<plugin>
4+
<extension
5+
id="org.phpsrc.eclipse.pti.tools.codesniffer.validator.phpToolCodeSnifferMarker"
6+
name="PHP CodeSniffer"
7+
point="org.eclipse.core.resources.markers">
8+
<persistent value="true"/>
9+
<attribute name="lineNumber"/>
10+
<attribute name="charStart"/>
11+
<attribute name="charEnd"/>
12+
<attribute name="message"/>
13+
<attribute name="priority"/>
14+
<attribute name="severity"/>
15+
<super type="org.eclipse.core.resources.problemmarker"/>
16+
</extension>
17+
<extension
18+
id="CodeSnifferValidatorForPHP"
19+
name="PHP CodeSniffer Validator (for PHP Files)"
20+
point="org.eclipse.wst.validation.validatorV2">
21+
<validator
22+
class="org.phpsrc.eclipse.pti.tools.codesniffer.validator.PHPCodeSnifferValidator"
23+
build="true"
24+
manual="true"
25+
markerId="org.phpsrc.eclipse.pti.tools.codesniffer.validator.phpToolCodeSnifferMarker"
26+
sourceid="org.eclipse.php.core.phpsource"
27+
version="1">
28+
<include>
29+
<rules>
30+
<contentType exactMatch="true" id="org.eclipse.php.core.phpsource"></contentType>
31+
</rules>
32+
</include>
33+
<group id="org.eclipse.wst.sse.core.structuredModelGroup" />
34+
</validator>
35+
</extension>
36+
<extension
37+
point="org.eclipse.ui.preferencePages">
38+
<page
39+
category="org.phpsrc.eclipse.pti.ui.preferences.PHPToolsPreferencePage"
40+
class="org.phpsrc.eclipse.pti.tools.codesniffer.ui.preferences.PHPCodeSnifferPreferencePage"
41+
id="org.phpsrc.eclipse.pti.tools.codesniffer.ui.preferences.PHPCodeSnifferPreferencePage"
42+
name="PHP CodeSniffer">
43+
</page>
44+
</extension>
45+
<extension point="org.eclipse.ui.propertyPages">
46+
<page
47+
category="org.phpsrc.eclipse.pti.ui.propertyPages.PHPToolsPreferencePage"
48+
class="org.phpsrc.eclipse.pti.tools.codesniffer.ui.preferences.PHPCodeSnifferPreferencePage"
49+
id="org.phpsrc.eclipse.pti.tools.codesniffer.ui.propertyPages.PHPCodeSnifferPreferencePage"
50+
name="PHP CodeSniffer">
51+
<enabledWhen>
52+
<adapt type="org.eclipse.core.resources.IProject">
53+
</adapt>
54+
</enabledWhen>
55+
<filter name="nature" value="org.eclipse.php.core.PHPNature" />
56+
</page>
57+
</extension>
58+
<extension
59+
point="org.eclipse.ui.ide.markerResolution">
60+
<markerResolutionGenerator
61+
markerType="org.phpsrc.eclipse.pti.tools.codesniffer.validator.phpToolCodeSnifferMarker"
62+
class="org.phpsrc.eclipse.pti.tools.codesniffer.ui.correction.CorrectionMarkerResolutionGenerator">
63+
</markerResolutionGenerator>
64+
</extension>
65+
66+
<extension
67+
point="org.eclipse.ui.commands">
68+
<category
69+
id="org.phpsrc.eclipse.pti.tools.codesniffer.ui.commands"
70+
name="PHP CodeSniffer">
71+
</category>
72+
<command
73+
id="org.phpsrc.eclipse.pti.tools.codesniffer.ui.commands.validateresources"
74+
categoryId="org.phpsrc.eclipse.pti.tools.codesniffer.ui.commands"
75+
name="PHP CodeSniffer">
76+
</command>
77+
</extension>
78+
79+
<extension
80+
point="org.eclipse.ui.menus">
81+
<menuContribution
82+
locationURI="popup:org.phpsrc.eclipse.pti.ui.menus.phptools?after=additions">
83+
<command
84+
commandId="org.phpsrc.eclipse.pti.tools.codesniffer.ui.commands.validateresources"
85+
tooltip="Validate selected files or folders with PHP CodeSniffer"
86+
icon="icons/obj16/validate_resource.gif">
87+
<visibleWhen>
88+
<with variable="activeMenuSelection">
89+
<iterate>
90+
<adapt type="org.eclipse.core.resources.IResource" />
91+
</iterate>
92+
</with>
93+
</visibleWhen>
94+
</command>
95+
</menuContribution>
96+
</extension>
97+
98+
<extension
99+
name="PHP CodeSniffer"
100+
point="org.eclipse.ui.actionSets">
101+
<actionSet
102+
id="org.phpsrc.eclipse.pti.tools.codesniffer.ui.actionSet"
103+
label="PHP CodeSniffer"
104+
visible="false">
105+
<action
106+
id="org.phpsrc.eclipse.pti.tools.codesniffer.ui.action.ValidateResourcesAction"
107+
definitionId="org.phpsrc.eclipse.pti.tools.codesniffer.ui.commands.validateresources"
108+
label="PHP CodeSniffer"
109+
icon="icons/obj16/validate_resource.gif"
110+
toolbarPath="org.phpsrc.eclipse.pti.tools.codesniffer.ui.actionSet"
111+
tooltip="Validate with PHP CodeSniffer"
112+
class="org.phpsrc.eclipse.pti.tools.codesniffer.ui.actions.ValidateResourcesAction"
113+
enablesFor="*">
114+
</action>
115+
</actionSet>
116+
</extension>
117+
<extension point="org.eclipse.ui.perspectiveExtensions">
118+
<perspectiveExtension targetID="org.eclipse.php.perspective">
119+
<actionSet id="org.phpsrc.eclipse.pti.tools.codesniffer.ui.actionSet" />
120+
</perspectiveExtension>
121+
</extension>
122+
</plugin>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2010, Sven Kiera
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* - Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimer in the documentation
11+
* and/or other materials provided with the distribution.
12+
* - Neither the name of the Organisation nor the names of its contributors may
13+
* be used to endorse or promote products derived from this software without
14+
* specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*******************************************************************************/
27+
package org.phpsrc.eclipse.pti.tools.codesniffer;
28+
29+
public interface ICodeSnifferConstants {
30+
public static final String PLUGIN_ID = PHPCodeSnifferPlugin.PLUGIN_ID;
31+
32+
public static final String PREFERENCE_PAGE_ID = PLUGIN_ID + ".preferences.CodeSnifferPreferencePage"; //$NON-NLS-1$
33+
public static final String PROJECT_PAGE_ID = PLUGIN_ID + ".properties.CodeSnifferPreferencePage"; //$NON-NLS-1$
34+
35+
public static final String VALIDATOR_CODESNIFFER_MARKER = "org.phpsrc.eclipse.pti.tools.codesniffer.validator.phpToolCodeSnifferMarker"; //$NON-NLS-1$
36+
37+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2010, Sven Kiera
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* - Redistributions of source code must retain the above copyright notice, this
8+
* list of conditions and the following disclaimer.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimer in the documentation
11+
* and/or other materials provided with the distribution.
12+
* - Neither the name of the Organisation nor the names of its contributors may
13+
* be used to endorse or promote products derived from this software without
14+
* specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*******************************************************************************/
27+
package org.phpsrc.eclipse.pti.tools.codesniffer;
28+
29+
import java.io.File;
30+
import java.io.FileFilter;
31+
32+
import org.eclipse.core.resources.IProject;
33+
import org.eclipse.core.runtime.IPath;
34+
import org.osgi.framework.BundleContext;
35+
import org.phpsrc.eclipse.pti.core.AbstractPHPToolPlugin;
36+
import org.phpsrc.eclipse.pti.library.pear.PHPLibraryPEARPlugin;
37+
import org.phpsrc.eclipse.pti.tools.codesniffer.core.preferences.PHPCodeSnifferPreferences;
38+
import org.phpsrc.eclipse.pti.tools.codesniffer.core.preferences.PHPCodeSnifferPreferencesFactory;
39+
40+
/**
41+
* The activator class controls the plug-in life cycle
42+
*/
43+
public class PHPCodeSnifferPlugin extends AbstractPHPToolPlugin {
44+
45+
// The plug-in ID
46+
public static final String PLUGIN_ID = "org.phpsrc.eclipse.pti.tools.codesniffer";
47+
48+
// The shared instance
49+
private static PHPCodeSnifferPlugin plugin;
50+
51+
/**
52+
* The constructor
53+
*/
54+
public PHPCodeSnifferPlugin() {
55+
}
56+
57+
/*
58+
* (non-Javadoc)
59+
*
60+
* @see
61+
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
62+
* )
63+
*/
64+
65+
public void start(BundleContext context) throws Exception {
66+
super.start(context);
67+
plugin = this;
68+
}
69+
70+
/*
71+
* (non-Javadoc)
72+
*
73+
* @see
74+
* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
75+
* )
76+
*/
77+
78+
public void stop(BundleContext context) throws Exception {
79+
plugin = null;
80+
super.stop(context);
81+
}
82+
83+
/**
84+
* Returns the shared instance
85+
*
86+
* @return the shared instance
87+
*/
88+
public static PHPCodeSnifferPlugin getDefault() {
89+
return plugin;
90+
}
91+
92+
public String[] getCodeSnifferStandards() {
93+
IPath sp = PHPLibraryPEARPlugin.getDefault().resolvePluginResource(
94+
"/php/library/PEAR/PHP/CodeSniffer/Standards");
95+
96+
File[] dirs = new File(sp.toString()).listFiles(new FileFilter() {
97+
public boolean accept(File f) {
98+
return f.isDirectory() && !f.getName().startsWith(".");
99+
}
100+
});
101+
102+
String[] standards = new String[dirs.length];
103+
for (int i = 0; i < dirs.length; i++) {
104+
standards[i] = dirs[i].getName();
105+
}
106+
107+
return standards;
108+
}
109+
110+
111+
public IPath[] getPluginIncludePaths(IProject project) {
112+
PHPCodeSnifferPreferences prefs = PHPCodeSnifferPreferencesFactory.factory(project);
113+
IPath[] pearPaths = PHPLibraryPEARPlugin.getDefault().getPluginIncludePaths(prefs.getPearLibraryName());
114+
115+
IPath[] includePaths = new IPath[pearPaths.length + 1];
116+
includePaths[0] = resolvePluginResource("/php/tools");
117+
System.arraycopy(pearPaths, 0, includePaths, 1, pearPaths.length);
118+
119+
return includePaths;
120+
}
121+
}

0 commit comments

Comments
 (0)