Index: src/org/infernus/idea/checkstyle/CheckStyleInspection.java
===================================================================
--- src/org/infernus/idea/checkstyle/CheckStyleInspection.java (revision 83)
+++ src/org/infernus/idea/checkstyle/CheckStyleInspection.java Thu May 21 11:33:48 CEST 2009
@@ -33,6 +33,7 @@
import java.io.File;
import java.io.FileWriter;
import java.util.List;
+import java.util.ArrayList;
/**
* Inspection for CheckStyle integration for IntelliJ IDEA.
@@ -204,8 +205,12 @@
final CheckStyleAuditListener listener
= new CheckStyleAuditListener(psiFile, manager);
checker.addListener(listener);
- checker.process(new File[]{tempFile});
+
+// checker.process(new File[]{tempFile});
+ ArrayList list = new ArrayList();
+ list.add(tempFile);
+ checker.process(list);
- checker.destroy();
+ checker.destroy();
final List problems = listener.getProblems();
return problems.toArray(new ProblemDescriptor[problems.size()]);
Index: src/org/infernus/idea/checkstyle/checker/FileScanner.java
===================================================================
--- src/org/infernus/idea/checkstyle/checker/FileScanner.java (revision 80)
+++ src/org/infernus/idea/checkstyle/checker/FileScanner.java Thu May 21 11:33:48 CEST 2009
@@ -12,166 +12,190 @@
import com.puppycrawl.tools.checkstyle.Checker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.infernus.idea.checkstyle.util.CheckStyleUtilities;
import org.infernus.idea.checkstyle.CheckStylePlugin;
+import org.infernus.idea.checkstyle.util.CheckStyleUtilities;
import org.jetbrains.annotations.NonNls;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
/**
* Runnable for scanning an individual file.
*/
-final class FileScanner implements Runnable {
+final class FileScanner implements Runnable
+{
- private CheckStylePlugin plugin;
- private List results;
- private PsiFile fileToScan;
- private ClassLoader moduleClassLoader;
- private Throwable error;
+ private CheckStylePlugin plugin;
+ private List results;
+ private PsiFile fileToScan;
+ private ClassLoader moduleClassLoader;
+ private Throwable error;
- /**
- * Logger for this class.
- */
- @NonNls
- private static final Log LOG = LogFactory.getLog(FileScanner.class);
+ /**
+ * Logger for this class.
+ */
+ @NonNls
+ private static final Log LOG = LogFactory.getLog(FileScanner.class);
- /**
- * Create a new file scanner.
- *
- * @param checkStylePlugin CheckStylePlugin.
- * @param fileToScan the file to scan.
- * @param moduleClassLoader the class loader for the file's module
- */
- public FileScanner(CheckStylePlugin checkStylePlugin, final PsiFile fileToScan,
+ /**
+ * Create a new file scanner.
+ *
+ * @param checkStylePlugin CheckStylePlugin.
+ * @param fileToScan the file to scan.
+ * @param moduleClassLoader the class loader for the file's module
+ */
+ public FileScanner(CheckStylePlugin checkStylePlugin, final PsiFile fileToScan,
- final ClassLoader moduleClassLoader) {
+ final ClassLoader moduleClassLoader)
+ {
- this.plugin = checkStylePlugin;
- this.fileToScan = fileToScan;
- this.moduleClassLoader = moduleClassLoader;
- }
+ this.plugin = checkStylePlugin;
+ this.fileToScan = fileToScan;
+ this.moduleClassLoader = moduleClassLoader;
+ }
- /**
- * {@inheritDoc}
- */
+ /**
+ * {@inheritDoc}
+ */
- public void run() {
- try {
+ public void run()
+ {
+ try
+ {
- results = checkPsiFile(fileToScan, moduleClassLoader);
+ results = checkPsiFile(fileToScan, moduleClassLoader);
- this.plugin.getToolWindowPanel().incrementProgressBar();
+ this.plugin.getToolWindowPanel().incrementProgressBar();
- } catch (Throwable e) {
+ } catch (Throwable e)
+ {
- error = e;
- }
- }
+ error = e;
+ }
+ }
- /**
- * Get the results of the scan.
- *
- * @return the results of the scan.
- */
+ /**
+ * Get the results of the scan.
+ *
+ * @return the results of the scan.
+ */
- public List getResults() {
+ public List getResults()
+ {
- return results;
- }
+ return results;
+ }
- /**
- * Get any error that may have occurred during the scan.
- *
- * @return any error that may have occurred during the scan
- */
+ /**
+ * Get any error that may have occurred during the scan.
+ *
+ * @return any error that may have occurred during the scan
+ */
- public Throwable getError() {
+ public Throwable getError()
+ {
- return error;
- }
+ return error;
+ }
- /**
- * Scan a PSI file with CheckStyle.
- *
- * @param element the PSI element to scan. This will be
- * ignored if not a java file.
- * @param moduleClassLoader the class loader for the current module.
- * @return a list of tree nodes representing the result tree for this
- * file, an empty list or null if this file is invalid or
- * has no errors.
- * @throws Throwable if the
- */
- private List checkPsiFile(final PsiElement element,
- final ClassLoader moduleClassLoader)
+ /**
+ * Scan a PSI file with CheckStyle.
+ *
+ * @param element the PSI element to scan. This will be
+ * ignored if not a java file.
+ * @param moduleClassLoader the class loader for the current module.
+ * @return a list of tree nodes representing the result tree for this
+ * file, an empty list or null if this file is invalid or
+ * has no errors.
+ * @throws Throwable if the
+ */
+ private List checkPsiFile(final PsiElement element,
+ final ClassLoader moduleClassLoader)
- throws Throwable {
+ throws Throwable
+ {
- if (element == null || !element.isValid() || !element.isPhysical()
+ if (element == null || !element.isValid() || !element.isPhysical()
- || !PsiFile.class.isAssignableFrom(element.getClass())) {
+ || !PsiFile.class.isAssignableFrom(element.getClass()))
+ {
- final String elementString = (element != null
- ? element.toString() : null);
- LOG.debug("Skipping as invalid type: " + elementString);
+ final String elementString = (element != null
+ ? element.toString() : null);
+ LOG.debug("Skipping as invalid type: " + elementString);
- return null;
- }
+ return null;
+ }
- final PsiFile psiFile = (PsiFile) element;
- LOG.debug("Scanning " + psiFile.getName());
+ final PsiFile psiFile = (PsiFile) element;
+ LOG.debug("Scanning " + psiFile.getName());
- final boolean checkTestClasses = this.plugin.getConfiguration().isScanningTestClasses();
+ final boolean checkTestClasses = this.plugin.getConfiguration().isScanningTestClasses();
- if (!checkTestClasses && isTestClass(element)) {
+ if (!checkTestClasses && isTestClass(element))
+ {
- LOG.debug("Skipping test class " + psiFile.getName());
- return null;
- }
+ LOG.debug("Skipping test class " + psiFile.getName());
+ return null;
+ }
- final InspectionManager manager
- = InspectionManager.getInstance(psiFile.getProject());
+ final InspectionManager manager
+ = InspectionManager.getInstance(psiFile.getProject());
- if (!CheckStyleUtilities.isValidFileType(psiFile.getFileType())) {
+ if (!CheckStyleUtilities.isValidFileType(psiFile.getFileType()))
+ {
- return null;
- }
+ return null;
+ }
- File tempFile = null;
+ File tempFile = null;
- try {
+ try
+ {
- final Checker checker = this.plugin.getChecker(moduleClassLoader);
+ final Checker checker = this.plugin.getChecker(moduleClassLoader);
- // we need to copy to a file as IntelliJ may not have
- // saved the file recently...
- final CreateTempFileThread fileThread
- = new CreateTempFileThread(psiFile);
- ApplicationManager.getApplication().runReadAction(fileThread);
+ // we need to copy to a file as IntelliJ may not have
+ // saved the file recently...
+ final CreateTempFileThread fileThread
+ = new CreateTempFileThread(psiFile);
+ ApplicationManager.getApplication().runReadAction(fileThread);
- // rethrow any error from the thread.
+ // rethrow any error from the thread.
- if (fileThread.getFailure() != null) {
+ if (fileThread.getFailure() != null)
+ {
- throw fileThread.getFailure();
- }
+ throw fileThread.getFailure();
+ }
- tempFile = fileThread.getFile();
+ tempFile = fileThread.getFile();
- if (tempFile == null) {
+ if (tempFile == null)
+ {
- throw new IllegalStateException("Failed to create temporary file.");
- }
+ throw new IllegalStateException("Failed to create temporary file.");
+ }
- final CheckStyleAuditListener listener
- = new CheckStyleAuditListener(psiFile, manager, true);
- checker.addListener(listener);
+ final CheckStyleAuditListener listener
+ = new CheckStyleAuditListener(psiFile, manager, true);
+ checker.addListener(listener);
- checker.process(new File[]{tempFile});
+// checker.process(new File[]{tempFile}.);
+ ArrayList list = new ArrayList();
+ list.add(tempFile);
+ checker.process(list);
- checker.destroy();
+ checker.destroy();
- return listener.getProblems();
+ return listener.getProblems();
- } catch (IOException e) {
+ } catch (IOException e)
+ {
- LOG.error("Failure when creating temp file", e);
- throw new IllegalStateException("Couldn't create temp file", e);
+ LOG.error("Failure when creating temp file", e);
+ throw new IllegalStateException("Couldn't create temp file", e);
- } finally {
- if (tempFile != null && tempFile.exists()) {
+ } finally
+ {
+ if (tempFile != null && tempFile.exists())
+ {
- tempFile.delete();
- }
- }
- }
+ tempFile.delete();
+ }
+ }
+ }
- private boolean isTestClass(final PsiElement element) {
+ private boolean isTestClass(final PsiElement element)
+ {
- final VirtualFile elementFile = element.getContainingFile().getVirtualFile();
+ final VirtualFile elementFile = element.getContainingFile().getVirtualFile();
- if (elementFile == null) {
+ if (elementFile == null)
+ {
- return false;
- }
+ return false;
+ }
- final Module module = ModuleUtil.findModuleForFile(elementFile, plugin.getProject());
+ final Module module = ModuleUtil.findModuleForFile(elementFile, plugin.getProject());
- if (module == null) {
+ if (module == null)
+ {
- return false;
- }
+ return false;
+ }
- final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
- return moduleRootManager != null && moduleRootManager.getFileIndex().isInTestSourceContent(elementFile);
- }
+ final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
+ return moduleRootManager != null && moduleRootManager.getFileIndex().isInTestSourceContent(elementFile);
+ }
}
Index: src/org/infernus/idea/checkstyle/checker/CheckerFactory.java
===================================================================
--- src/org/infernus/idea/checkstyle/checker/CheckerFactory.java (revision 83)
+++ src/org/infernus/idea/checkstyle/checker/CheckerFactory.java Thu May 21 13:34:20 CEST 2009
@@ -166,6 +166,7 @@
replaceSupressionFilterPath(config, baseDir);
+ ((Checker) threadReturn[0]).setModuleClassLoader(Thread.currentThread().getContextClassLoader());
((Checker) threadReturn[0]).configure(config);
} finally {
Index: META-INF/plugin.xml
===================================================================
--- META-INF/plugin.xml (revision 85)
+++ META-INF/plugin.xml Thu May 21 15:50:41 CEST 2009
@@ -11,13 +11,14 @@
]]>
- 2.5
+ 2.6
James Shiell
+ 2.6: Checkstyle 5.0 integration.
2.5: New: Result list may be filtered on severity.
2.5: New: Backend re-written to support mutliple CheckStyle files. You will need to set your configuration once again I'm afraid.
2.4: New: Default CheckStyle file now has generics patch applied.