Skip to content

Commit f3fcf6a

Browse files
author
skiera
committed
Fixed 50: load standards from custom lib
1 parent 1934be0 commit f3fcf6a

File tree

3 files changed

+48
-16
lines changed

3 files changed

+48
-16
lines changed

META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: PHP Tool Codesniffer
44
Bundle-SymbolicName: org.phpsrc.eclipse.pti.tools.codesniffer;singleton:=true
5-
Bundle-Version: 1.2.3.R20100314000000
5+
Bundle-Version: 1.2.4.R20100413000000
66
Bundle-Activator: org.phpsrc.eclipse.pti.tools.codesniffer.PHPCodeSnifferPlugin
77
Bundle-Vendor: Sven Kiera
88
Require-Bundle: org.eclipse.ui,

src/org/phpsrc/eclipse/pti/tools/codesniffer/PHPCodeSnifferPlugin.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.osgi.framework.BundleContext;
3535
import org.phpsrc.eclipse.pti.core.AbstractPHPToolPlugin;
3636
import org.phpsrc.eclipse.pti.library.pear.PHPLibraryPEARPlugin;
37+
import org.phpsrc.eclipse.pti.library.pear.core.preferences.PEARPreferences;
38+
import org.phpsrc.eclipse.pti.library.pear.core.preferences.PEARPreferencesFactory;
3739
import org.phpsrc.eclipse.pti.tools.codesniffer.core.preferences.PHPCodeSnifferPreferences;
3840
import org.phpsrc.eclipse.pti.tools.codesniffer.core.preferences.PHPCodeSnifferPreferencesFactory;
3941

@@ -44,6 +46,7 @@ public class PHPCodeSnifferPlugin extends AbstractPHPToolPlugin {
4446

4547
// The plug-in ID
4648
public static final String PLUGIN_ID = "org.phpsrc.eclipse.pti.tools.codesniffer";
49+
private static final String DEFAULT_PEAR_LIB_PATH = "/php/library/PEAR/PHP/CodeSniffer/Standards";
4750

4851
// The shared instance
4952
private static PHPCodeSnifferPlugin plugin;
@@ -61,7 +64,7 @@ public PHPCodeSnifferPlugin() {
6164
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
6265
* )
6366
*/
64-
67+
6568
public void start(BundleContext context) throws Exception {
6669
super.start(context);
6770
plugin = this;
@@ -74,7 +77,7 @@ public void start(BundleContext context) throws Exception {
7477
* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
7578
* )
7679
*/
77-
80+
7881
public void stop(BundleContext context) throws Exception {
7982
plugin = null;
8083
super.stop(context);
@@ -89,16 +92,36 @@ public static PHPCodeSnifferPlugin getDefault() {
8992
return plugin;
9093
}
9194

92-
public String[] getCodeSnifferStandards() {
93-
IPath sp = PHPLibraryPEARPlugin.getDefault().resolvePluginResource(
94-
"/php/library/PEAR/PHP/CodeSniffer/Standards");
95+
public String[] getCodeSnifferStandards(String lib) {
96+
String libPath = null;
97+
if (lib != null && !"".equals(lib) && !lib.startsWith("<")) {
98+
PEARPreferences prefs = PEARPreferencesFactory.factoryByName(lib);
99+
if (prefs != null)
100+
libPath = prefs.getLibraryPath();
101+
}
95102

96-
File[] dirs = new File(sp.toString()).listFiles(new FileFilter() {
103+
File standardPath = null;
104+
if (libPath != null) {
105+
standardPath = new File(libPath + "/PHP/CodeSniffer/Standards");
106+
if (!standardPath.exists())
107+
standardPath = new File(libPath + "/PEAR/PHP/CodeSniffer/Standards");
108+
} else {
109+
standardPath = new File(PHPLibraryPEARPlugin.getDefault().resolvePluginResource(DEFAULT_PEAR_LIB_PATH)
110+
.toPortableString());
111+
}
112+
113+
if (standardPath == null || !standardPath.exists())
114+
return new String[0];
115+
116+
File[] dirs = standardPath.listFiles(new FileFilter() {
97117
public boolean accept(File f) {
98118
return f.isDirectory() && !f.getName().startsWith(".");
99119
}
100120
});
101121

122+
if (dirs == null)
123+
return new String[0];
124+
102125
String[] standards = new String[dirs.length];
103126
for (int i = 0; i < dirs.length; i++) {
104127
standards[i] = dirs[i].getName();
@@ -107,7 +130,6 @@ public boolean accept(File f) {
107130
return standards;
108131
}
109132

110-
111133
public IPath[] getPluginIncludePaths(IProject project) {
112134
PHPCodeSnifferPreferences prefs = PHPCodeSnifferPreferencesFactory.factory(project);
113135
IPath[] pearPaths = PHPLibraryPEARPlugin.getDefault().getPluginIncludePaths(prefs.getPearLibraryName());

src/org/phpsrc/eclipse/pti/tools/codesniffer/ui/preferences/PHPCodeSnifferConfigurationBlock.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@
4848
import org.eclipse.php.internal.ui.wizards.fields.ListDialogField;
4949
import org.eclipse.php.internal.ui.wizards.fields.StringDialogField;
5050
import org.eclipse.swt.SWT;
51+
import org.eclipse.swt.events.SelectionEvent;
52+
import org.eclipse.swt.events.SelectionListener;
5153
import org.eclipse.swt.graphics.Font;
5254
import org.eclipse.swt.graphics.Image;
5355
import org.eclipse.swt.layout.GridData;
5456
import org.eclipse.swt.layout.GridLayout;
57+
import org.eclipse.swt.widgets.Combo;
5558
import org.eclipse.swt.widgets.Composite;
5659
import org.eclipse.swt.widgets.Control;
5760
import org.eclipse.swt.widgets.Group;
@@ -221,8 +224,6 @@ public PHPCodeSnifferConfigurationBlock(IStatusChangeListener context, IProject
221224
fStandardsList.setTableColumns(new ListDialogField.ColumnsDescription(data, columnsHeaders, true));
222225
fStandardsList.setViewerSorter(new ViewerSorter());
223226

224-
unpackStandards();
225-
226227
if (fStandardsList.getSize() > 0) {
227228
fStandardsList.selectFirstElement();
228229
} else {
@@ -252,9 +253,8 @@ public PHPCodeSnifferConfigurationBlock(IStatusChangeListener context, IProject
252253

253254
private static Key[] getKeys() {
254255
return new Key[] { PREF_PHP_EXECUTABLE, PREF_PEAR_LIBRARY, PREF_DEBUG_PRINT_OUTPUT, PREF_CUSTOM_STANDARD_NAMES,
255-
PREF_CUSTOM_STANDARD_PATHS, PREF_DEFAULT_STANDARD_NAME, PREF_DEFAULT_STANDARD_PATH,
256-
PREF_ACTIVE_STANDARDS, PREF_DEFAULT_TAB_WITH, PREF_FILE_EXTENSIONS, PREF_IGNORE_PATTERN,
257-
PREF_IGNORE_SNIFFS };
256+
PREF_CUSTOM_STANDARD_PATHS, PREF_ACTIVE_STANDARDS, PREF_DEFAULT_TAB_WITH, PREF_FILE_EXTENSIONS,
257+
PREF_IGNORE_PATTERN, PREF_IGNORE_SNIFFS };
258258
}
259259

260260
protected Composite createToolContents(Composite parent) {
@@ -316,6 +316,16 @@ private Composite createStandardsTabContent(Composite folder) {
316316
createDialogFieldsWithInfoText(folder, new DialogField[] { fIgnoreSniffs }, "Ignore Sniffs",
317317
new String[] { "Sniffs are separated by a comma" });
318318

319+
unpackStandards(pearLibraryCombo.getText());
320+
pearLibraryCombo.addSelectionListener(new SelectionListener() {
321+
public void widgetSelected(SelectionEvent e) {
322+
unpackStandards(((Combo) e.widget).getText());
323+
}
324+
325+
public void widgetDefaultSelected(SelectionEvent e) {
326+
}
327+
});
328+
319329
return markersGroup;
320330
}
321331

@@ -437,7 +447,7 @@ protected Key getPEARLibraryKey() {
437447
*/
438448

439449
protected void updateControls() {
440-
unpackStandards();
450+
unpackStandards(pearLibraryCombo.getText());
441451
unpackTabWidth();
442452
unpackFileExtensions();
443453
unpackIgnorePattern();
@@ -468,7 +478,7 @@ private void unpackIgnoreSniffs() {
468478
fIgnoreSniffs.setText(ignoreSniffs);
469479
}
470480

471-
private void unpackStandards() {
481+
private void unpackStandards(String libName) {
472482
String activeStandards = getValue(PREF_ACTIVE_STANDARDS);
473483
ArrayList<String> activeList = new ArrayList<String>();
474484

@@ -483,7 +493,7 @@ private void unpackStandards() {
483493

484494
String customStandardPrefs = getValue(PREF_CUSTOM_STANDARD_NAMES);
485495

486-
String[] standards = PHPCodeSnifferPlugin.getDefault().getCodeSnifferStandards();
496+
String[] standards = PHPCodeSnifferPlugin.getDefault().getCodeSnifferStandards(libName);
487497
String[] customStandards = {};
488498
String[] customPaths = {};
489499

0 commit comments

Comments
 (0)