]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-791 compare package declaration with physical directory
authorsimonbrandhof <simon.brandhof@gmail.com>
Mon, 11 Apr 2011 14:55:40 +0000 (16:55 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Mon, 11 Apr 2011 14:55:40 +0000 (16:55 +0200)
78 files changed:
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/CheckstyleSquidBridge.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/JavaAstScanner.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/JavaAstVisitor.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/SquidTestUtils.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/BreakCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/ContinueCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AccessorVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AnonymousInnerClassVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BlankLinesVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BrancheVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ClassVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ComplexityVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/EndAtLineVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/HeaderCommentVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesOfCodeVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/MethodVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java [new file with mode: 0644]
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PublicApiVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/StatementVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/BytecodeVisitorsTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/ClassworldsClassLoaderTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/VirtualMethodsLinkerTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassProviderImplTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/ArchitectureCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/CallToDeprecatedMethodCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedPrivateMethodCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedProtectedMethodCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/AccessorVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/LCOM4VisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/ClassComplexityCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/DITCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/MethodComplexityCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidUserGuideTest.java
plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/JavaBeanWithApiDoc.java
plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/PureJavaBean.java
plugins/sonar-squid-java-plugin/test-resources/metrics/branches/NoBranches.java
plugins/sonar-squid-java-plugin/test-resources/metrics/branches/SimpleBranches.java
plugins/sonar-squid-java-plugin/test-resources/metrics/classes/AbstractClass.java
plugins/sonar-squid-java-plugin/test-resources/metrics/commentedCode/org/foo/CommentedOutFile.java [new file with mode: 0644]
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithComments.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithCommentsOnLineOfCode.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeader.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeaderAndBlankLines.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithPackageAndJavadocHeader.java [deleted file]
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithVars.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithoutHeaderAndWithCComment.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/Constants.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/EmptyConstructor.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/InterfaceWithComments.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java
plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/foo/ClassWithPackageAndJavadocHeader.java [new file with mode: 0644]
plugins/sonar-squid-java-plugin/test-resources/metrics/loc/Test001.java
plugins/sonar-squid-java-plugin/test-resources/metrics/ncloc/TestNclocWithHeader.java
plugins/sonar-squid-java-plugin/test-resources/metrics/packages/org/foo/SimpleBean.java [new file with mode: 0644]
plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/AnnotationDefinition.java
plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/InterfaceWithAnnotation.java
plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/ClassWithPackageImportsComment.java [deleted file]
plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/foo/ClassWithPackageImportsComment.java [new file with mode: 0644]
plugins/sonar-squid-java-plugin/test-resources/special_cases/package-info.java [deleted file]
plugins/sonar-squid-java-plugin/test-resources/special_cases/packageInfo/org/apache/cxf/jaxrs/ext/logging/package-info.java [new file with mode: 0644]
plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/CommentedOutFile.java [new file with mode: 0644]
plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/GoodPackage.java [new file with mode: 0644]
plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/WrongPackage.java [new file with mode: 0644]

index 3607ab3fe82fb3bfac938d57885665b5576e454e..9de6058b3b6653d36fc6ac826f5bd710d550321f 100644 (file)
  */
 package org.sonar.java.ast;
 
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.io.File;
+import java.util.*;
 
+import com.google.common.collect.Maps;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.sonar.api.resources.InputFile;
 import org.sonar.java.ast.visitor.JavaAstVisitor;
 import org.sonar.java.recognizer.JavaFootprint;
 import org.sonar.java.squid.JavaSquidConfiguration;
@@ -40,6 +41,7 @@ public class CheckstyleSquidBridge extends Check {
   private static JavaAstVisitor[] visitors;
   private static int[] allTokens;
   private static CodeRecognizer codeRecognizer;
+  private static Map<java.io.File,InputFile> inputFilesByPath = Maps.newHashMap();
 
   static void setASTVisitors(List<JavaAstVisitor> visitors) {
     CheckstyleSquidBridge.visitors = visitors.toArray(new JavaAstVisitor[visitors.size()]);
@@ -63,6 +65,17 @@ public class CheckstyleSquidBridge extends Check {
     return allTokens; //NOSONAR returning directly the array is not a security flaw here
   }
 
+  public static InputFile getInputFile(File path) {
+    return inputFilesByPath.get(path);
+  }
+
+  public static void setInputFiles(Collection<InputFile> inputFiles) {
+    inputFilesByPath.clear();
+    for (InputFile inputFile : inputFiles) {
+      inputFilesByPath.put(inputFile.getFile(), inputFile);
+    }
+  }
+
   @Override
   public void beginTree(DetailAST ast) {
     try {
@@ -70,6 +83,7 @@ public class CheckstyleSquidBridge extends Check {
       for (JavaAstVisitor visitor : visitors) {
         visitor.setFileContents(getFileContents());
         visitor.setSource(source);
+        visitor.setInputFile(getInputFile(new java.io.File(getFileContents().getFilename())));
         visitor.visitFile(ast);
       }
     } catch (RuntimeException e) {
index ae908db4c67d7955e9df94ae9338b8c0835a7458..350d160f2e2ba7b431b2dfea1712f948c18d144e 100644 (file)
  */
 package org.sonar.java.ast;
 
+import com.google.common.collect.Lists;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.sonar.api.resources.InputFile;
+import org.sonar.api.resources.InputFileUtils;
 import org.sonar.java.ast.visitor.*;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.api.AnalysisException;
@@ -57,33 +60,6 @@ public class JavaAstScanner extends CodeScanner<JavaAstVisitor> {
     this.project = project;
   }
 
-  /**
-   * Create and execute the Checkstyle engine.
-   * 
-   * @param files
-   *          collection of files to analyse. This list shouldn't contain and directory.
-   * @param charset
-   *          the default charset to use to read files
-   */
-  private void launchCheckstyleEngine(Collection<File> files, Charset charset) {
-    Checker c = createChecker(charset);
-    ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
-    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-    try {
-      c.setClassloader(getClass().getClassLoader());
-      c.setModuleClassLoader(getClass().getClassLoader());
-      c.process(new ArrayList<File>(files));
-      c.destroy();
-    } finally {
-      Thread.currentThread().setContextClassLoader(initialClassLoader);
-    }
-  }
-
-  /**
-   * Creates the Checkstyle Checker object.
-   * 
-   * @return a nice new fresh Checkstyle Checker
-   */
   private Checker createChecker(Charset charset) {
     InputStream checkstyleConfig = null;
     try {
@@ -110,20 +86,23 @@ public class JavaAstScanner extends CodeScanner<JavaAstVisitor> {
   }
 
   public JavaAstScanner scanDirectory(File javaSourceDirectory) {
-    List<File> files = new ArrayList<File>(FileUtils.listFiles(javaSourceDirectory, FileFilterUtils.fileFileFilter(), FileFilterUtils
-        .directoryFileFilter()));
-    return scanFiles(files);
+    List<InputFile> inputFiles = Lists.newArrayList();
+    Collection<File> files = FileUtils.listFiles(javaSourceDirectory, FileFilterUtils.fileFileFilter(), FileFilterUtils.directoryFileFilter());
+    for (File file : files) {
+      inputFiles.add(InputFileUtils.create(javaSourceDirectory, file));
+    }
+    return scanFiles(inputFiles);
   }
 
-  public JavaAstScanner scanFile(File javaFile) {
+  public JavaAstScanner scanFile(InputFile javaFile) {
     return scanFiles(Arrays.asList(javaFile));
   }
 
-  public JavaAstScanner scanFiles(Collection<File> javaFiles) {
+  public JavaAstScanner scanFiles(Collection<InputFile> inputFiles) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("----- Java sources analyzed by Squid:");
-      for (File javaFile : javaFiles) {
-        LOG.debug(javaFile.getAbsolutePath());
+      for (InputFile inputFile : inputFiles) {
+        LOG.debug(inputFile.toString());
       }
       LOG.debug("-----");
     }
@@ -135,13 +114,29 @@ public class JavaAstScanner extends CodeScanner<JavaAstVisitor> {
     }
     CheckstyleSquidBridge.setASTVisitors(getVisitors());
     CheckstyleSquidBridge.setSquidConfiguration(conf);
-    launchCheckstyleEngine(javaFiles, conf.getCharset());
+    CheckstyleSquidBridge.setInputFiles(inputFiles);
+    launchCheckstyle(InputFileUtils.toFiles(inputFiles), conf.getCharset());
     return this;
   }
 
+  private void launchCheckstyle(Collection<File> files, Charset charset) {
+    Checker c = createChecker(charset);
+    ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
+    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+    try {
+      c.setClassloader(getClass().getClassLoader());
+      c.setModuleClassLoader(getClass().getClassLoader());
+      c.process(Lists.<File>newArrayList(files));
+      c.destroy();
+    } finally {
+      Thread.currentThread().setContextClassLoader(initialClassLoader);
+    }
+  }
+
+
   @Override
   public Collection<Class<? extends JavaAstVisitor>> getVisitorClasses() {
-    List<Class<? extends JavaAstVisitor>> visitorClasses = new ArrayList<Class<? extends JavaAstVisitor>>();
+    List<Class<? extends JavaAstVisitor>> visitorClasses = Lists.newArrayList();
     visitorClasses.add(PackageVisitor.class);
     visitorClasses.add(FileVisitor.class);
     visitorClasses.add(ClassVisitor.class);
index c0c4c635c5043dcc213271efe7bbe34ad93ebbe7..64d21c9a3d4875e6532baa54ba798ba78613ae62 100644 (file)
  */
 package org.sonar.java.ast.visitor;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Stack;
-
-import org.sonar.squid.text.Source;
+import com.google.common.collect.Lists;
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.api.FileContents;
+import org.sonar.api.resources.InputFile;
 import org.sonar.squid.api.CodeVisitor;
 import org.sonar.squid.api.SourceClass;
 import org.sonar.squid.api.SourceCode;
 import org.sonar.squid.api.SourcePackage;
+import org.sonar.squid.text.Source;
 
-import com.puppycrawl.tools.checkstyle.api.DetailAST;
-import com.puppycrawl.tools.checkstyle.api.FileContents;
+import java.util.List;
+import java.util.Stack;
 
 public abstract class JavaAstVisitor implements CodeVisitor {
 
@@ -38,9 +38,11 @@ public abstract class JavaAstVisitor implements CodeVisitor {
 
   private FileContents fileContents;
 
+  private InputFile inputFile;
+
   private Source source;
 
-  private static final List<Integer> emptyWantedTokens = new ArrayList<Integer>();
+  private static final List<Integer> emptyWantedTokens = Lists.newArrayList();
 
   public final void setFileContents(FileContents fileContents) {
     this.fileContents = fileContents;
@@ -54,6 +56,14 @@ public abstract class JavaAstVisitor implements CodeVisitor {
     this.source = source;
   }
 
+  public final InputFile getInputFile() {
+    return inputFile;
+  }
+
+  public final void setInputFile(InputFile inputFile) {
+    this.inputFile = inputFile;
+  }
+
   final Source getSource() {
     return source;
   }
index a0ba7e71430d2a8d262ffd3c68239a205109a8b0..fe512777008ceb4d0d7ad684bb108a69a8803083 100644 (file)
  */
 package org.sonar.java.ast.visitor;
 
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.api.FullIdent;
+import com.puppycrawl.tools.checkstyle.api.TokenTypes;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.resources.InputFileUtils;
+import org.sonar.squid.api.AnalysisException;
 import org.sonar.squid.api.SourceCode;
 import org.sonar.squid.api.SourcePackage;
 import org.sonar.squid.indexer.SquidIndex;
 import org.sonar.squid.measures.Metric;
 
-import com.puppycrawl.tools.checkstyle.api.DetailAST;
-import com.puppycrawl.tools.checkstyle.api.FullIdent;
-import com.puppycrawl.tools.checkstyle.api.TokenTypes;
-
 public class PackageVisitor extends JavaAstVisitor {
 
+  private static final String ROOT_PACKAGE = "";
+  
   private SquidIndex indexer;
 
   public PackageVisitor(SquidIndex indexer) {
@@ -38,11 +42,14 @@ public class PackageVisitor extends JavaAstVisitor {
 
   @Override
   public void visitFile(DetailAST ast) {
+    SourceCode packageRes = null;
+
     if (ast == null) {
-      // ast can be null for empty classes
-      return;
+      // ast can be null for empty files (all the file is commented-out)
+      packageRes = guessPackage();
+    } else {
+      packageRes = createSourcePackage(ast);
     }
-    SourceCode packageRes = createSourcePackage(ast);
     if (peekSourceCode().hasChild(packageRes)) {
       packageRes = indexer.search(packageRes.getKey());
     }
@@ -50,23 +57,44 @@ public class PackageVisitor extends JavaAstVisitor {
     addSourceCode(packageRes);
   }
 
+  private SourcePackage guessPackage() {
+    String directory = InputFileUtils.getRelativeDirectory(getInputFile());
+    return new SourcePackage(directory);
+  }
+
   @Override
   public void leaveFile(DetailAST ast) {
-    if (ast == null) {
-      // ast can be null for empty classes
-      return;
-    }
     popSourceCode();
   }
 
   private SourcePackage createSourcePackage(DetailAST ast) {
-    SourcePackage packageRes;
-    if (ast.getType() != TokenTypes.PACKAGE_DEF) {
-      packageRes = new SourcePackage("");
-    } else {
+    String key = ROOT_PACKAGE;
+    if (ast.getType() == TokenTypes.PACKAGE_DEF) {
       String packageName = FullIdent.createFullIdent(ast.getLastChild().getPreviousSibling()).getText();
-      packageRes = new SourcePackage(packageName.replace('.', '/'));
+      key = packageName.replace('.', '/');
+    }
+    checkPhysicalDirectory(key);
+    return new SourcePackage(key);
+  }
+
+  /**
+   * Check that package declaration is consistent with the physical location of Java file.
+   * It aims to detect two cases :
+   * - wrong package declaration : "package org.foo" stored in the directory "org/bar"
+   * - source directory badly configured : src/ instead of src/main/java/
+   *
+   * @since 2.8
+   */
+  private void checkPhysicalDirectory(String key) {
+    String relativeDirectory = InputFileUtils.getRelativeDirectory(getInputFile());
+    // both relativeDirectory and key use slash '/' as separator
+    if (!StringUtils.equals(relativeDirectory, key)) {
+      String packageName = StringUtils.replace(key, "/", ".");
+      if (StringUtils.contains(relativeDirectory, key) || StringUtils.contains(key, relativeDirectory)) {
+        throw new AnalysisException(String.format("The source directory does not correspond to the package declaration %s", packageName));
+      }
+      throw new AnalysisException(String.format("The package declaration %s does not correspond to the file path %s",
+          packageName, getInputFile().getRelativePath()));
     }
-    return packageRes;
   }
 }
\ No newline at end of file
index 01494e6ea56700e57250ea3337d22c69a120242a..4be634b0546a662d9e36b1eb5f7ccbbe336d2c26 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils;
 import org.sonar.api.batch.SensorContext;
 import org.sonar.api.checks.CheckFactory;
 import org.sonar.api.checks.NoSonarFilter;
+import org.sonar.api.resources.InputFile;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
 import org.sonar.api.utils.TimeProfiler;
@@ -76,11 +77,7 @@ public final class SquidExecutor {
     return conf;
   }
 
-  protected SquidExecutor(Squid squid) {
-    this.squid = squid;
-  }
-
-  public void scan(Collection<File> sourceFiles, Collection<File> bytecodeFilesOrDirectories) {
+  public void scan(Collection<InputFile> sourceFiles, Collection<File> bytecodeFilesOrDirectories) {
     for (Object checker : checkFactory.getChecks()) {
       squid.registerVisitor((CodeVisitor) checker);
     }
@@ -159,7 +156,7 @@ public final class SquidExecutor {
   }
 
 
-  void scanSources(Collection<File> sourceFiles) {
+  void scanSources(Collection<InputFile> sourceFiles) {
     if (sourceFiles != null && !sourceFiles.isEmpty()) {
       TimeProfiler profiler = new TimeProfiler(getClass()).start("Java AST scan");
       JavaAstScanner sourceScanner = squid.register(JavaAstScanner.class);
index 1e4da4853f377b72e87d8845a06231d67c6b2dd4..318bded0ea87f54776d8e13d5369df13ae8bc54a 100644 (file)
@@ -86,8 +86,8 @@ public class SquidSensor implements Sensor {
     }
   }
 
-  private List<File> getMainSourceFiles(Project project) {
-    return project.getFileSystem().getJavaSourceFiles();
+  private List<InputFile> getMainSourceFiles(Project project) {
+    return project.getFileSystem().mainFiles(Java.KEY);
   }
 
   private Collection<File> getMainBytecodeFiles(Project project) {
index 7506dbb50bdddeef0e3d1fe301273cc105ffbde0..afddc3cf2cd8bd8993f5a33f13d536960a8f222c 100644 (file)
@@ -20,7 +20,8 @@
 package org.sonar.java.ast;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
@@ -46,7 +47,7 @@ public class JavaAstScannerTest {
   @Test
   public void testMacRomanEncoding() {
     squid = new Squid(new JavaSquidConfiguration(false, Charset.forName("MacRoman")));
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/encoding/MacRomanEncoding.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/encoding/MacRomanEncoding.java"));
     SourceProject prj = squid.aggregate();
     assertEquals(4, prj.getInt(Metric.METHODS));
   }
@@ -54,37 +55,41 @@ public class JavaAstScannerTest {
   @Test(expected = AnalysisException.class)
   public void testCP1252EncodingWithWrongDefined() {
     squid = new Squid(new JavaSquidConfiguration(true, Charset.forName("MacRoman")));
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/encoding/CP1252Encoding.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/encoding/CP1252Encoding.java"));
   }
 
   @Test
   public void testCheckstyleParsingBug() {
     // see
     // http://sourceforge.net/tracker/?func=detail&atid=397078&aid=1667137&group_id=29721
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/parsingErrors/CheckstyleBug.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/parsingErrors/CheckstyleBug.java"));
     SourceProject prj = squid.aggregate();
     assertEquals(0, prj.getInt(Metric.CLASSES));
   }
 
   @Test
   public void testEmptyClassWithComment() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/emptyFiles/ClassWithOnlyComment.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/emptyFiles/ClassWithOnlyComment.java"));
     SourceProject prj = squid.aggregate();
     assertEquals(0, prj.getInt(Metric.CLASSES));
-    assertEquals(0, prj.getInt(Metric.PACKAGES));
+    assertEquals(1, prj.getInt(Metric.PACKAGES));
+    assertEquals(1, prj.getInt(Metric.FILES));
     assertEquals(1, prj.getInt(Metric.COMMENT_LINES));
+
+    assertNotNull(squid.search("ClassWithOnlyComment.java"));//file
+    assertNull(squid.search("ClassWithOnlyComment"));//class
   }
 
   @Test
   public void testEmptyFileWithBlankLines() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/emptyFiles/EmptyFileWithBlankLines.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/emptyFiles/EmptyFileWithBlankLines.java"));
     SourceProject prj = squid.aggregate();
     assertEquals(0, prj.getDouble(Metric.COMMENT_LINES_DENSITY), 0.01);
   }
 
   @Test
   public void testClassWithPackageImportsComment() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/emptyFiles/ClassWithPackageImportsComment.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/emptyFiles", "foo/ClassWithPackageImportsComment.java"));
     SourceProject prj = squid.aggregate();
     assertEquals(0, prj.getInt(Metric.CLASSES));
     assertEquals(1, prj.getInt(Metric.PACKAGES));
@@ -105,11 +110,11 @@ public class JavaAstScannerTest {
       }
       System.setProperty("file.encoding", "MacRoman");
       squid = new Squid(new JavaSquidConfiguration(false));
-      squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/encoding/MacRomanEncoding.java"));
+      squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/encoding/MacRomanEncoding.java"));
       macRoman = squid.aggregate();
       System.setProperty("file.encoding", "CP1252");
       squid = new Squid(new JavaSquidConfiguration(false));
-      squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/encoding/CP1252Encoding.java"));
+      squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/encoding/CP1252Encoding.java"));
       cp1252 = squid.aggregate();
     } finally {
       System.setProperty("file.encoding", currentEncoding);
@@ -121,7 +126,7 @@ public class JavaAstScannerTest {
   @Test
   public void testCP1252Encoding() {
     squid = new Squid(new JavaSquidConfiguration(false, Charset.forName("CP1252")));
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/encoding/CP1252Encoding.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/encoding/CP1252Encoding.java"));
     SourceProject prj = squid.aggregate();
     assertEquals(4, prj.getInt(Metric.METHODS));
   }
@@ -129,17 +134,17 @@ public class JavaAstScannerTest {
   @Test
   public void testUTF8Encoding() {
     squid = new Squid(new JavaSquidConfiguration(false, Charset.forName(CharEncoding.UTF_8)));
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/encoding/Utf8Encoding.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/encoding/Utf8Encoding.java"));
     SourceProject prj = squid.aggregate();
     assertEquals(4, prj.getInt(Metric.METHODS));
   }
 
   @Test
   public void testInterfaceWithAnnotations() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/annotations/InterfaceWithAnnotation.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/annotations/InterfaceWithAnnotation.java"));
     SourceProject prj = squid.aggregate();
-    assertEquals(12, prj.getInt(Metric.LINES));
-    assertEquals(7, prj.getInt(Metric.LINES_OF_CODE));
+    assertEquals(11, prj.getInt(Metric.LINES));
+    assertEquals(6, prj.getInt(Metric.LINES_OF_CODE));
     assertEquals(0, prj.getInt(Metric.STATEMENTS));
     assertEquals(2, prj.getInt(Metric.METHODS));
     assertEquals(2, prj.getInt(Metric.COMPLEXITY));
@@ -147,7 +152,7 @@ public class JavaAstScannerTest {
 
   @Test
   public void testClassesWithGenerics() {
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/special_cases/generics"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/special_cases/generics"));
     SourceProject prj = squid.aggregate();
     assertEquals(2, prj.getInt(Metric.FILES));
     assertEquals(3, prj.getInt(Metric.METHODS));
@@ -155,7 +160,7 @@ public class JavaAstScannerTest {
 
   @Test
   public void testPackageInfo() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/package-info.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/packageInfo", "org/apache/cxf/jaxrs/ext/logging/package-info.java"));
     SourceProject prj = squid.aggregate();
     assertEquals(1, prj.getInt(Metric.FILES));
     assertEquals(4, prj.getInt(Metric.LINES_OF_CODE));
index 766929440cff64eeff6990df2acfb1816b531e86..c8e428c1f310684e34a9778d9f9d2a6ada1244ce 100644 (file)
  */
 package org.sonar.java.ast;
 
+import org.sonar.api.resources.InputFile;
+import org.sonar.api.resources.InputFileUtils;
+
 import java.io.File;
 
 public final class SquidTestUtils {
 
+  /**
+   * Assumes that the Java file has no package. It's declared in the root directory.
+   */
+  public static InputFile getInputFile(String relativePath) {
+    File file = getFile(relativePath);
+    return InputFileUtils.create(file.getParentFile(), file);
+  }
+
+  public static InputFile getInputFile(String basedir, String relativePath) {
+    File file = getFile(basedir + "/" + relativePath);
+    return InputFileUtils.create(getFile(basedir), file);
+  }
+
   public static File getFile(String relativePath) {
     return new File("test-resources" + relativePath);
   }
index 2b61b9ea45539e5284c377bad0cc3be751cd2792..9ee98d5530e4acba8e2868cdff6acfa1bdafbc4f 100644 (file)
@@ -22,16 +22,21 @@ package org.sonar.java.ast.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
+import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.Test;
+import org.sonar.api.resources.InputFileUtils;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.CheckMessage;
 import org.sonar.squid.api.SourceFile;
 
+import java.io.File;
+import java.util.Collection;
+
 public class BreakCheckTest {
 
   private Squid squid;
@@ -40,7 +45,11 @@ public class BreakCheckTest {
   public void setUp() {
     squid = new Squid(new JavaSquidConfiguration());
     squid.registerVisitor(BreakCheck.class);
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/commons-collections-3.2.1/src/org/apache/commons/collections/map"));
+
+    File basedir = SquidTestUtils.getFile("/commons-collections-3.2.1/src");
+    Collection<File> files = FileUtils.listFiles(new File(basedir, "org/apache/commons/collections/map"), new String[]{"java"}, true);
+
+    squid.register(JavaAstScanner.class).scanFiles(InputFileUtils.create(basedir, files));
   }
 
   @Test
index a5787df6df25cc3cb34530d414077cb93265646d..09bd0b5afac83be105c7f2385f0f05e23201bce5 100644 (file)
@@ -22,11 +22,11 @@ package org.sonar.java.ast.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.CheckMessage;
@@ -41,7 +41,7 @@ public class ContinueCheckTest {
     squid = new Squid(new JavaSquidConfiguration());
     squid.registerVisitor(ContinueCheck.class);
     squid.register(JavaAstScanner.class).scanFile(
-        getFile("/commons-collections-3.2.1/src/org/apache/commons/collections/ExtendedProperties.java"));
+        SquidTestUtils.getInputFile("/commons-collections-3.2.1/src", "org/apache/commons/collections/ExtendedProperties.java"));
   }
 
   @Test
index 2888fdcb22d4f302dd5dd35073e519f917146e21..e83b3ce77c36ab0cddf169d83f06f4a1a3611996 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.java.ast.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import java.util.Collections;
 import java.util.Comparator;
@@ -31,6 +30,7 @@ import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.java.squid.SquidScanner;
 import org.sonar.squid.Squid;
@@ -48,7 +48,7 @@ public class UndocumentedApiCheckTest {
   public void setUp() {
     squid = new Squid(new JavaSquidConfiguration());
     squid.registerVisitor(UndocumentedApiCheck.class);
-    squid.register(JavaAstScanner.class).scanFile(getFile("/rules/UndocumentedApi.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/rules/UndocumentedApi.java"));
     squid.decorateSourceCodeTreeWith(Metric.values());
     squid.register(SquidScanner.class).scan();
   }
index 7e43874b24fe380e1f90b3704b9c33172fe56c9a..9f1aed35175643cfb268fb782ff0804577339330 100644 (file)
@@ -21,13 +21,13 @@ package org.sonar.java.ast.visitor;
 
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
 import org.sonar.squid.measures.Metric;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 public class AccessorVisitorTest {
 
@@ -36,10 +36,10 @@ public class AccessorVisitorTest {
   @Test
   public void analyzePureJavaBean() {
     squid = new Squid(new JavaSquidConfiguration(true));
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/accessors/PureJavaBean.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/accessors/PureJavaBean.java"));
     SourceCode res = squid.aggregate();
-    assertEquals(55, res.getInt(Metric.LINES_OF_CODE));
-    assertEquals(95, res.getInt(Metric.LINES));
+    assertEquals(54, res.getInt(Metric.LINES_OF_CODE));
+    assertEquals(94, res.getInt(Metric.LINES));
     assertEquals(6, res.getInt(Metric.ACCESSORS));
     assertEquals(10, res.getInt(Metric.METHODS));
   }
@@ -47,10 +47,10 @@ public class AccessorVisitorTest {
   @Test
   public void considerAccessorAsMethod() {
     squid = new Squid(new JavaSquidConfiguration(false));
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/accessors/JavaBeanWithApiDoc.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/accessors/JavaBeanWithApiDoc.java"));
     SourceCode res = squid.aggregate();
-    assertEquals(11, res.getInt(Metric.LINES_OF_CODE));
-    assertEquals(31, res.getInt(Metric.LINES));
+    assertEquals(10, res.getInt(Metric.LINES_OF_CODE));
+    assertEquals(30, res.getInt(Metric.LINES));
     assertEquals(2, res.getInt(Metric.METHODS));
     assertEquals(0, res.getInt(Metric.ACCESSORS));
     assertEquals(4, res.getInt(Metric.PUBLIC_API));
@@ -60,10 +60,10 @@ public class AccessorVisitorTest {
   @Test
   public void analyseVarAccessorsImpactOnOtherMeasures() {
     squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/accessors/JavaBeanWithApiDoc.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/accessors/JavaBeanWithApiDoc.java"));
     SourceCode res = squid.aggregate();
-    assertEquals(11, res.getInt(Metric.LINES_OF_CODE));
-    assertEquals(31, res.getInt(Metric.LINES));
+    assertEquals(10, res.getInt(Metric.LINES_OF_CODE));
+    assertEquals(30, res.getInt(Metric.LINES));
     assertEquals(1, res.getInt(Metric.METHODS));
     assertEquals(1, res.getInt(Metric.ACCESSORS));
     assertEquals(3, res.getInt(Metric.PUBLIC_API));
index d2827ccabe5a4aff1c0920fdc1cdb89ab148c159..77da25cac705816969e91d8145da3cab258e0222 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertNotNull;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 
@@ -39,7 +39,7 @@ public class AnonymousInnerClassVisitorTest {
 
   @Test
   public void testCreateInnerSquidClass() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/classes/AnonymousInnerClass.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/classes/AnonymousInnerClass.java"));
     squid.aggregate();
     assertNotNull(squid.search("AnonymousInnerClass$1"));
     assertNotNull(squid.search("AnonymousInnerClass$2"));
index 711872a2831440d3c50eb28a99c5e4a0cad25ac4..d5b5fe342c8708bf563bdddef32f53da08bc71e5 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -41,25 +41,25 @@ public class BlankLinesVisitorTest {
 
   @Test
   public void analyseTest002() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/loc/Test002.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/loc/Test002.java"));
     assertEquals(5, squid.aggregate().getInt(Metric.BLANK_LINES));
   }
 
   @Test
   public void analyseTest001() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/loc/Test001.java"));
-    assertEquals(3, squid.aggregate().getInt(Metric.BLANK_LINES));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/loc/Test001.java"));
+    assertEquals(4, squid.aggregate().getInt(Metric.BLANK_LINES));
 
-    SourceCode classSource = squid.search("test/Something");
+    SourceCode classSource = squid.search("Something");
     assertEquals(2, classSource.getInt(Metric.BLANK_LINES));
   }
 
   @Test
   public void analyseClassWithHeaderAndBlankLines() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/ClassWithHeaderAndBlankLines.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/ClassWithHeaderAndBlankLines.java"));
     SourceCode sources = squid.aggregate();
-    assertEquals(4, sources.getInt(Metric.LINES_OF_CODE));
-    assertEquals(3, sources.getInt(Metric.BLANK_LINES));
+    assertEquals(3, sources.getInt(Metric.LINES_OF_CODE));
+    assertEquals(4, sources.getInt(Metric.BLANK_LINES));
     assertEquals(6, sources.getInt(Metric.COMMENT_BLANK_LINES));
   }
 }
index e385db329ffb95f5a218f9d0b664e0d3075e4d48..52085be3a33838df2327dc6f58cc99599153ba6b 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -41,21 +41,21 @@ public class BrancheVisitorTest {
 
   @Test
   public void testNoBranches() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/branches/NoBranches.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/branches/NoBranches.java"));
     SourceCode res = squid.aggregate();
     assertEquals(0, res.getInt(Metric.BRANCHES));
   }
 
   @Test
   public void testSimpleBranches() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/branches/SimpleBranches.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/branches/SimpleBranches.java"));
     SourceCode res = squid.aggregate();
     assertEquals(8, res.getInt(Metric.BRANCHES));
   }
 
   @Test
   public void testComplexBranches() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/branches/ComplexBranches.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/branches/ComplexBranches.java"));
     SourceCode res = squid.aggregate();
     assertEquals(6, res.getInt(Metric.BRANCHES));
   }
index ee9a68dec150319d74daefb8834892b48cf52fe3..dcbe39d88074da30a03678d0e8f73e60f9d40c10 100644 (file)
@@ -24,13 +24,13 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import java.util.Iterator;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceClass;
@@ -49,7 +49,7 @@ public class ClassVisitorTest {
 
   @Test
   public void analyseTest003() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/classes/Test003.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/classes/Test003.java"));
     SourceCode project = squid.aggregate();
     SourceCode defaultPackage = project.getFirstChild();
     SourceCode file = defaultPackage.getFirstChild();
@@ -68,7 +68,7 @@ public class ClassVisitorTest {
 
   @Test
   public void analyseClassCounterEnum() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/classes/ClassCounterEnum.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/classes/ClassCounterEnum.java"));
     SourceCode project = squid.aggregate();
     SourceCode defaultPackage = project.getFirstChild();
     assertEquals(1, defaultPackage.getInt(Metric.CLASSES));
@@ -76,37 +76,37 @@ public class ClassVisitorTest {
 
   @Test
   public void analyseAnnotationDefinition() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/annotations/AnnotationDefinition.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/annotations/AnnotationDefinition.java"));
     SourceCode project = squid.aggregate();
     SourceCode annotation = project.getFirstChild();
     assertEquals(1, annotation.getInt(Metric.CLASSES));
-    assertNotNull(squid.search("org/sonar/plugins/api/AnnotationDefinition"));
+    assertNotNull(squid.search("AnnotationDefinition"));
   }
 
   @Test
   public void analyseInterface() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/classes/Interface.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/classes/Interface.java"));
     SourceCode project = squid.aggregate();
     assertEquals(1, project.getInt(Metric.INTERFACES));
   }
 
   @Test
   public void analyseAbstractClass() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/classes/AbstractClass.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/classes/AbstractClass.java"));
     SourceCode project = squid.aggregate();
     assertEquals(1, project.getInt(Metric.ABSTRACT_CLASSES));
   }
 
   @Test
   public void testStartAtLine() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/classes/AbstractClass.java"));
-    SourceCode classTest = squid.search("org/sonar/AbstractClass");
-    assertEquals(4, classTest.getStartAtLine());
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/classes/AbstractClass.java"));
+    SourceCode classTest = squid.search("AbstractClass");
+    assertEquals(2, classTest.getStartAtLine());
   }
 
   @Test
   public void analysePrivateInnerClass() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/classes/InnerClassTests.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/classes/InnerClassTests.java"));
     SourceCode project = squid.aggregate();
     SourceCode defaultPackage = project.getFirstChild();
     SourceCode defaultClassFile = defaultPackage.getFirstChild();
@@ -124,7 +124,7 @@ public class ClassVisitorTest {
 
   @Test
   public void detectSuppressWarningsAnnotation() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/rules/ClassWithSuppressWarningsAnnotation.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/rules/ClassWithSuppressWarningsAnnotation.java"));
     SourceClass sourceClass = (SourceClass) squid.search("ClassWithSuppressWarningsAnnotation");
     assertThat(sourceClass.isSuppressWarnings(), is(true));
   }
index af8ba25111218bfee9e69910d4471e7a27e3cdce..f67fa24820b6cffe0918c5fd337786f913b7b2d7 100644 (file)
@@ -22,11 +22,13 @@ package org.sonar.java.ast.visitor;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
+import org.sonar.api.resources.InputFile;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -74,6 +76,18 @@ public class CommentVisitorTest {
     assertEquals(2, method.getInt(Metric.COMMENT_BLANK_LINES));
   }
 
+  @Test
+  @Ignore("TODO")
+  public void testCommentedOutFile() {
+    SourceProject res = scan("/metrics/commentedCode", "org/foo/CommentedOutFile.java");
+  }
+
+  @Test
+  @Ignore("TODO")
+  public void shouldGuessPackageOfcommentedOutFile() {
+    SourceProject res = scan("/metrics/commentedCode", "org/foo/CommentedOutFile.java");
+  }
+
   @Test
   public void testNoSonarTagDetection() {
     scan("/rules/FileWithNOSONARTags.java");
@@ -101,8 +115,14 @@ public class CommentVisitorTest {
     assertEquals(0, project.getInt(Metric.COMMENTED_OUT_CODE_LINES));
   }
 
-  private SourceProject scan(String path) {
-    squid.register(JavaAstScanner.class).scanFile(getFile(path));
+  private SourceProject scan(String filePath) {
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile(filePath));
+    return squid.aggregate();
+  }
+
+  private SourceProject scan(String basedir, String filePath) {
+    InputFile inputFile = SquidTestUtils.getInputFile(basedir, filePath);
+    squid.register(JavaAstScanner.class).scanFile(inputFile);
     return squid.aggregate();
   }
 }
index 07e7209ab09fec41c60d455ba4ae05664277b054..fafdd011af41113c87da2263a4c606e3d68dfd32 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -41,23 +41,23 @@ public class ComplexityVisitorTest {
 
   @Test
   public void testNoBranches() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/branches/NoBranches.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/branches/NoBranches.java"));
     SourceCode res = squid.aggregate();
     assertEquals(3, res.getInt(Metric.COMPLEXITY));
   }
 
   @Test
   public void testSimpleBranches() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/branches/SimpleBranches.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/branches/SimpleBranches.java"));
     SourceCode res = squid.aggregate();
     assertEquals(15, res.getInt(Metric.COMPLEXITY));
-    SourceCode simpleSwitch = squid.search("Car#simpleSwitch()V");
+    SourceCode simpleSwitch = squid.search("SimpleBranches#simpleSwitch()V");
     assertEquals(3, simpleSwitch.getInt(Metric.COMPLEXITY));
   }
 
   @Test
   public void testInstanceAndStaticInitBlocks() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/complexity/InstanceAndStaticInitBlocks.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/complexity/InstanceAndStaticInitBlocks.java"));
     SourceCode res = squid.aggregate();
     assertEquals(2, res.getInt(Metric.COMPLEXITY));
   }
index dc72f66caea805356e9decf802336410b09f73fc..53d9970b6d82af9ecd7ad66c37aa841239b962e9 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 
@@ -32,14 +32,14 @@ public class EndAtLineVisitorTest {
   @Test
   public void testEndAtLineForMethod() {
     Squid squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/methods/ClassWithStaticMethods.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/methods/ClassWithStaticMethods.java"));
     assertEquals(17, squid.search("ClassWithStaticMethods#doJob2()V").getEndAtLine());
   }
 
   @Test
   public void testEndAtLineForClass() {
     Squid squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/methods/ClassWithStaticMethods.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/methods/ClassWithStaticMethods.java"));
     assertEquals(30, squid.search("ClassWithStaticMethods").getEndAtLine());
   }
 }
index 7fe8036b70fad9be0110da740bcbdf7a17e5ef5d..22eeaa8d4f44ea23b519918d2f298a957c38617c 100644 (file)
@@ -21,15 +21,17 @@ package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.google.common.collect.Lists;
 import org.junit.Before;
 import org.junit.Test;
+import org.sonar.api.resources.InputFile;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -54,9 +56,9 @@ public class FileVisitorTest {
 
   @Test
   public void analyseTest003() {
-    List<File> files = new ArrayList<File>();
-    files.add(getFile("/metrics/loc/Test002.java"));
-    files.add(getFile("/metrics/classes/Test003.java"));
+    List<InputFile> files = Lists.newArrayList();
+    files.add(SquidTestUtils.getInputFile("/metrics/loc/Test002.java"));
+    files.add(SquidTestUtils.getInputFile("/metrics/classes/Test003.java"));
     squid.register(JavaAstScanner.class).scanFiles(files);
     SourceCode project = squid.aggregate();
     assertEquals(2, project.getInt(Metric.FILES));
index 662f871cdc920298d39b2913c0366733badbec6a..9be05e7465d53b86c1ec28764ad1d259d33b7ccd 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -41,17 +41,17 @@ public class HeaderCommentVisitorTest {
 
   @Test
   public void analyseHeaderCommentsStandard() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/ClassWithHeader.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/ClassWithHeader.java"));
     SourceCode res = squid.aggregate();
     assertEquals(7, res.getInt(Metric.COMMENT_LINES_WITHOUT_HEADER));
     assertEquals(32, res.getInt(Metric.LINES));
-    assertEquals(11, res.getInt(Metric.LINES_OF_CODE));
+    assertEquals(10, res.getInt(Metric.LINES_OF_CODE));
     assertEquals(2, res.getInt(Metric.HEADER_COMMENT_LINES));
   }
 
   @Test
   public void analyseHeaderCommentsAndNoPackage() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/ClassWithHeaderAndNoPackage.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/ClassWithHeaderAndNoPackage.java"));
     SourceCode res = squid.aggregate();
     assertEquals(7, res.getInt(Metric.COMMENT_LINES_WITHOUT_HEADER));
     assertEquals(30, res.getInt(Metric.LINES));
@@ -61,7 +61,7 @@ public class HeaderCommentVisitorTest {
 
   @Test
   public void analyseHeaderCommentsAndNoPackageNoImports() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/ClassWithHeaderAndNoPackageNoImports.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/ClassWithHeaderAndNoPackageNoImports.java"));
     SourceCode res = squid.aggregate();
     assertEquals(3, res.getInt(Metric.COMMENT_LINES_WITHOUT_HEADER));
     assertEquals(23, res.getInt(Metric.LINES));
@@ -71,7 +71,7 @@ public class HeaderCommentVisitorTest {
 
   @Test
   public void analyseJavadocHeaderAndPackage() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/ClassWithPackageAndJavadocHeader.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/", "foo/ClassWithPackageAndJavadocHeader.java"));
     SourceCode res = squid.aggregate();
     assertEquals(2, res.getInt(Metric.HEADER_COMMENT_LINES));
     assertEquals(3, res.getInt(Metric.COMMENT_LINES_WITHOUT_HEADER));
@@ -81,7 +81,7 @@ public class HeaderCommentVisitorTest {
 
   @Test
   public void analyseCCommentWithoutHeader() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/ClassWithoutHeaderAndWithCComment.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/ClassWithoutHeaderAndWithCComment.java"));
     SourceCode res = squid.aggregate();
     assertEquals(3, res.getInt(Metric.COMMENT_LINES_WITHOUT_HEADER));
     assertEquals(0, res.getInt(Metric.HEADER_COMMENT_LINES));
index 107945ea0fe6cb4e1d1ce0c7aa8957dd70925e9d..c1403a224572804966b786571924cdc6cf62811d 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -41,7 +41,7 @@ public class LinesOfCodeVisitorTest {
 
   @Test
   public void analyseTestNcloc() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/ncloc/TestNcloc.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/ncloc/TestNcloc.java"));
     SourceCode res = squid.aggregate();
     assertEquals(39, res.getInt(Metric.LINES));
     assertEquals(9, res.getInt(Metric.BLANK_LINES));
@@ -56,7 +56,7 @@ public class LinesOfCodeVisitorTest {
 
   @Test
   public void analyseTestNclocWithClassComment() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/ncloc/TestNclocWithClassComment.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/ncloc/TestNclocWithClassComment.java"));
     SourceCode res = squid.aggregate();
     assertEquals(46, res.getInt(Metric.LINES));
     assertEquals(9, res.getInt(Metric.BLANK_LINES));
@@ -67,12 +67,12 @@ public class LinesOfCodeVisitorTest {
 
   @Test
   public void analyseTestNclocWithHeader() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/ncloc/TestNclocWithHeader.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/ncloc/TestNclocWithHeader.java"));
     SourceCode res = squid.aggregate();
     assertEquals(59, res.getInt(Metric.LINES));
-    assertEquals(11, res.getInt(Metric.BLANK_LINES));
+    assertEquals(12, res.getInt(Metric.BLANK_LINES));
     assertEquals(4, res.getInt(Metric.HEADER_COMMENT_LINES));
     assertEquals(12, res.getInt(Metric.COMMENT_BLANK_LINES));
-    assertEquals(27, res.getInt(Metric.LINES_OF_CODE));
+    assertEquals(26, res.getInt(Metric.LINES_OF_CODE));
   }
 }
index 0d0eaec498458ffb09f35822c87be1233b3e9dae..bdc9987f1797596797826f381e85a11ba627c212 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -41,20 +41,20 @@ public class LinesVisitorTest {
 
   @Test
   public void analyseTest001() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/loc/Test001.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/loc/Test001.java"));
     SourceCode res = squid.aggregate();
     assertEquals(25, res.getInt(Metric.LINES));
 
-    SourceCode classSource = squid.search("test/Something");
+    SourceCode classSource = squid.search("Something");
     assertEquals(14, classSource.getInt(Metric.LINES));
 
-    SourceCode methodSource = squid.search("test/Something#run()V");
+    SourceCode methodSource = squid.search("Something#run()V");
     assertEquals(3, methodSource.getInt(Metric.LINES));
   }
 
   @Test
   public void analyseTest002() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/loc/Test002.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/loc/Test002.java"));
     SourceCode res = squid.aggregate();
     assertEquals(19, res.getInt(Metric.LINES));
   }
index a8e7d740ec49b95d8b277f09cefdefe461d8fda1..4d79a5ca33a0fcfd22ff37b00b34c9027af5c248 100644 (file)
@@ -23,11 +23,11 @@ import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -46,7 +46,7 @@ public class MethodVisitorTest {
 
   @Test
   public void analyseClassWithStaticMethods() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/methods/ClassWithStaticMethods.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/methods/ClassWithStaticMethods.java"));
     SourceCode prj = squid.decorateSourceCodeTreeWith(Metric.values());
     assertEquals(3, prj.getInt(Metric.METHODS));
     assertEquals(8, prj.getInt(Metric.COMPLEXITY));
@@ -54,7 +54,7 @@ public class MethodVisitorTest {
 
   @Test
   public void methodWithAnonymousInnerClass() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/methods/MethodWithAnonymousInnerClass.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/methods/MethodWithAnonymousInnerClass.java"));
     SourceCode prj = squid.decorateSourceCodeTreeWith(Metric.values());
     assertEquals(4, prj.getInt(Metric.METHODS));
     assertEquals(4, squid.search(new QueryByType(SourceMethod.class)).size());
@@ -63,14 +63,14 @@ public class MethodVisitorTest {
 
   @Test
   public void testStartAtLine() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/methods/ClassWithStaticMethods.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/methods/ClassWithStaticMethods.java"));
     SourceCode doJob2Method = squid.search("ClassWithStaticMethods#doJob1()V");
     assertEquals(3, doJob2Method.getStartAtLine());
   }
 
   @Test
   public void testMethodSignature() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/methods/ClassWithDifferentMethodSignatures.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/methods/ClassWithDifferentMethodSignatures.java"));
     assertNotNull(squid.search("ClassWithDifferentMethodSignatures#<init>()V"));
     assertNotNull(squid.search("ClassWithDifferentMethodSignatures#<init>(LList;)V"));
     assertNotNull(squid.search("ClassWithDifferentMethodSignatures#method()V"));
@@ -87,14 +87,14 @@ public class MethodVisitorTest {
 
   @Test
   public void testConstructorsMetric() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/methods/ClassWithDifferentMethodSignatures.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/methods/ClassWithDifferentMethodSignatures.java"));
     SourceCode source = squid.decorateSourceCodeTreeWith(Metric.values());
     assertEquals(2, source.getInt(Metric.CONSTRUCTORS));
   }
 
   @Test
   public void detectSuppressWarningsAnnotation() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/rules/ClassWithSuppressWarningsAnnotation.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/rules/ClassWithSuppressWarningsAnnotation.java"));
 
     assertThat(getMethod("ClassWithSuppressWarningsAnnotation#fullyQualifiedName()V").isSuppressWarnings(), is(true));
     assertThat(getMethod("ClassWithSuppressWarningsAnnotation#singleValue()V").isSuppressWarnings(), is(true));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java
new file mode 100644 (file)
index 0000000..5363c12
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.java.ast.visitor;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
+import org.sonar.java.squid.JavaSquidConfiguration;
+import org.sonar.squid.Squid;
+import org.sonar.squid.api.AnalysisException;
+import org.sonar.squid.api.SourceProject;
+import org.sonar.squid.measures.Metric;
+
+import static org.junit.Assert.*;
+
+public class PackageVisitorTest {
+
+  private Squid squid;
+
+  @Before
+  public void setup() {
+    squid = new Squid(new JavaSquidConfiguration());
+  }
+
+  @Test(expected = AnalysisException.class)
+  public void shouldFailIfPackageDifferentThanPhysicalDirectory() {
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/wrongPackages/", "org/foo/WrongPackage.java"));
+    squid.aggregate();
+  }
+
+  @Test(expected = AnalysisException.class)
+  public void shouldFailIfBadSourceDirectory() {
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/wrongPackages/org", "foo/GoodPackage.java"));
+    squid.aggregate();
+  }
+
+  @Test
+  public void shouldGuessPackageWhenCommentedOutFile() {
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/wrongPackages", "org/foo/CommentedOutFile.java"));
+    SourceProject project = squid.aggregate();
+
+    assertNull(squid.search("CommentedOutFile.java"));
+    assertNotNull(squid.search("org/foo/CommentedOutFile.java"));
+    assertNotNull(squid.search("org/foo"));
+    assertEquals(1, project.getInt(Metric.PACKAGES));
+  }
+}
index 925d196deda5c182a71203c807c65b66de118391..2ad9296ddb44a9c8bd6a32953bd7ed36101a9400 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -41,20 +41,20 @@ public class PublicApiVisitorTest {
 
   @Test
   public void analyseClassWithCommentsOnLineOfCode() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/ClassWithCommentsOnLineOfCode.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/ClassWithCommentsOnLineOfCode.java"));
     SourceCode res = squid.aggregate();
-    assertEquals(8, res.getInt(Metric.LINES_OF_CODE));
+    assertEquals(7, res.getInt(Metric.LINES_OF_CODE));
     assertEquals(4, res.getInt(Metric.COMMENT_LINES));
     assertEquals(2, res.getInt(Metric.PUBLIC_API));
   }
 
   @Test
   public void analyseVars() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/ClassWithVars.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/ClassWithVars.java"));
     SourceCode res = squid.aggregate();
-    assertEquals(16, res.getInt(Metric.LINES_OF_CODE));
+    assertEquals(15, res.getInt(Metric.LINES_OF_CODE));
     assertEquals(59, res.getInt(Metric.LINES));
-    assertEquals(9, res.getInt(Metric.BLANK_LINES));
+    assertEquals(10, res.getInt(Metric.BLANK_LINES));
     assertEquals(21, res.getInt(Metric.COMMENT_BLANK_LINES));
     assertEquals(5, res.getInt(Metric.PUBLIC_API));
     assertEquals(1, res.getInt(Metric.HEADER_COMMENT_LINES));
@@ -65,11 +65,11 @@ public class PublicApiVisitorTest {
 
   @Test
   public void analyseConstants() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/Constants.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/Constants.java"));
     SourceCode res = squid.aggregate();
-    assertEquals(10, res.getInt(Metric.LINES_OF_CODE));
+    assertEquals(9, res.getInt(Metric.LINES_OF_CODE));
     assertEquals(76, res.getInt(Metric.LINES));
-    assertEquals(10, res.getInt(Metric.BLANK_LINES));
+    assertEquals(11, res.getInt(Metric.BLANK_LINES));
     assertEquals(21, res.getInt(Metric.COMMENT_BLANK_LINES));
     assertEquals(1, res.getInt(Metric.PUBLIC_API));
     assertEquals(15, res.getInt(Metric.HEADER_COMMENT_LINES));
@@ -79,28 +79,28 @@ public class PublicApiVisitorTest {
 
   @Test
   public void analyseApiDocCounter() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/ClassWithComments.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/ClassWithComments.java"));
     SourceCode res = squid.aggregate();
     assertEquals(7, res.getInt(Metric.PUBLIC_API));
     assertEquals(4, res.getInt(Metric.PUBLIC_DOC_API));
     assertEquals(66, res.getInt(Metric.LINES));
-    assertEquals(19, res.getInt(Metric.LINES_OF_CODE));
-    assertEquals(0.45, res.getDouble(Metric.COMMENT_LINES_DENSITY), 0.01);
+    assertEquals(18, res.getInt(Metric.LINES_OF_CODE));
+    assertEquals(0.47, res.getDouble(Metric.COMMENT_LINES_DENSITY), 0.01);
   }
 
   @Test
   public void analyseJavaDocCounterOnAnnotation() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/special_cases/annotations/AnnotationDefinition.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/annotations/AnnotationDefinition.java"));
     SourceCode res = squid.aggregate();
     assertEquals(3, res.getInt(Metric.PUBLIC_API));
     assertEquals(2, res.getInt(Metric.PUBLIC_DOC_API));
-    assertEquals(19, res.getInt(Metric.LINES));
-    assertEquals(0.33, res.getDouble(Metric.COMMENT_LINES_DENSITY), 0.01);
+    assertEquals(18, res.getInt(Metric.LINES));
+    assertEquals(0.36, res.getDouble(Metric.COMMENT_LINES_DENSITY), 0.01);
   }
 
   @Test
   public void analyseInterfaceComments() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/InterfaceWithComments.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/InterfaceWithComments.java"));
     SourceCode res = squid.aggregate();
     assertEquals(6, res.getInt(Metric.PUBLIC_API));
     assertEquals(2, res.getInt(Metric.PUBLIC_DOC_API));
@@ -110,7 +110,7 @@ public class PublicApiVisitorTest {
 
   @Test
   public void excludeMethodWithOverrideAnnotation() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/MethodsWithOverrideAnnotation.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/MethodsWithOverrideAnnotation.java"));
     SourceCode res = squid.aggregate();
     assertEquals(2, res.getInt(Metric.PUBLIC_API));
     assertEquals(0, res.getInt(Metric.PUBLIC_DOC_API));
@@ -118,7 +118,7 @@ public class PublicApiVisitorTest {
 
   @Test
   public void excludeEmptyConstructor() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/javadoc/EmptyConstructor.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/javadoc/EmptyConstructor.java"));
     SourceCode res = squid.aggregate();
     assertEquals(3, res.getInt(Metric.PUBLIC_API));
     assertEquals(0, res.getInt(Metric.PUBLIC_DOC_API));
index ea7f9c57671f16b93257c92c8442f39c803bfbe3..a452f21dfe731cc5291d270dd8ceb8f6037e882c 100644 (file)
 package org.sonar.java.ast.visitor;
 
 import static org.junit.Assert.assertEquals;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
 import org.sonar.squid.api.SourceCode;
@@ -41,7 +41,7 @@ public class StatementVisitorTest {
 
   @Test
   public void testNoStatements() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/statements/NoStatements.java"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/statements/NoStatements.java"));
     SourceCode res = squid.aggregate();
     assertEquals(12, res.getInt(Metric.STATEMENTS));
     SourceCode simpleIf = squid.search("Car#simpleIf(LString;)V");
index 24cf3c4c5a66f9dccbc1717613473c076e04eeb5..6ac724dc307abe5e443e8df585616a95dabda4d4 100644 (file)
@@ -24,7 +24,6 @@ import static org.hamcrest.Matchers.notNullValue;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -39,6 +38,7 @@ import org.junit.Test;
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.util.TraceClassVisitor;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.asm.AsmResource;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
@@ -67,8 +67,8 @@ public class BytecodeVisitorsTest {
   @BeforeClass
   public static void setup() {
     squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/src"));
-    squid.register(BytecodeScanner.class).scanDirectory(getFile("/bytecode/bin"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/src"));
+    squid.register(BytecodeScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/bin"));
     squid.decorateSourceCodeTreeWith(Metric.values());
     tag = squid.search("tags/Tag");
     tagFile = squid.search("tags/Tag.java");
@@ -240,11 +240,11 @@ public class BytecodeVisitorsTest {
 
   @Test
   @Ignore
-  public void testClassWithEnum() throws FileNotFoundException, IOException {
+  public void testClassWithEnum() throws IOException {
     SourceFile classWithEnum = (SourceFile) squid.search("specialCases/ClassWithEnum.java");
     SourceClass myEnum = (SourceClass) squid.search("specialCases/ClassWithEnum$MyEnum");
 
-    ClassReader asmReader = new ClassReader(new FileInputStream(getFile("/bytecode/bin/specialCases/ClassWithEnum$MyEnum.class")));
+    ClassReader asmReader = new ClassReader(new FileInputStream(SquidTestUtils.getFile("/bytecode/bin/specialCases/ClassWithEnum$MyEnum.class")));
     TraceClassVisitor classVisitor = new TraceClassVisitor(new PrintWriter(System.out));
     asmReader.accept(classVisitor, 0);
     classVisitor.print(new PrintWriter(System.out));
index 93f0a2b4345780d28b7cbb8c88eb7428fb713ce3..ea93533cffca297f481dbab74f1fc507a42ee29d 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.java.bytecode;
 
 import org.junit.Test;
+import org.sonar.java.ast.SquidTestUtils;
 
 import java.io.File;
 import java.util.Collections;
@@ -28,7 +29,6 @@ import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.core.IsNot.not;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 public class ClassworldsClassLoaderTest {
 
@@ -41,7 +41,7 @@ public class ClassworldsClassLoaderTest {
 
   @Test
   public void createFromDirectory() throws ClassNotFoundException {
-    File dir = getFile("/bytecode/bin/");
+    File dir = SquidTestUtils.getFile("/bytecode/bin/");
     ClassLoader classloader = ClassworldsClassLoader.create(dir);
     assertThat(classloader.loadClass("tags.TagName"), not(nullValue()));
 
@@ -55,7 +55,7 @@ public class ClassworldsClassLoaderTest {
 
   @Test
   public void createFromJar() throws ClassNotFoundException {
-    File jar = getFile("/bytecode/lib/hello.jar");
+    File jar = SquidTestUtils.getFile("/bytecode/lib/hello.jar");
     ClassLoader classloader = ClassworldsClassLoader.create(jar);
     assertThat(classloader.loadClass("org.sonar.tests.Hello"), not(nullValue()));
     assertThat(classloader.getResource("org/sonar/tests/Hello.class"), not(nullValue()));
@@ -70,7 +70,7 @@ public class ClassworldsClassLoaderTest {
 
   @Test
   public void unknownJarIsIgnored() throws ClassNotFoundException {
-    File jar = getFile("/bytecode/lib/unknown.jar");
+    File jar = SquidTestUtils.getFile("/bytecode/lib/unknown.jar");
     ClassLoader classloader = ClassworldsClassLoader.create(jar);
     assertThat(classloader.getResource("org/sonar/tests/Hello.class"), nullValue());
   }
index a301b26039a375683d1a6c3a6811946db82bd3b7..4281314d5f0ce20e8943e2ba88f3b9c5a1579dac 100644 (file)
@@ -21,11 +21,10 @@ package org.sonar.java.bytecode;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
-import org.sonar.java.bytecode.BytecodeScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.check.UnusedProtectedMethodCheck;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
@@ -37,9 +36,9 @@ public class VirtualMethodsLinkerTest {
   @Test
   public void testLinkingRunMethodVirtualMethodToItsImplementation() {
     Squid squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/virtualMethodsLinker/src"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/virtualMethodsLinker/src"));
     squid.registerVisitor(UnusedProtectedMethodCheck.class);
-    squid.register(BytecodeScanner.class).scanDirectory(getFile("/bytecode/virtualMethodsLinker/bin"));
+    squid.register(BytecodeScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/virtualMethodsLinker/bin"));
     squid.decorateSourceCodeTreeWith(Metric.values());
 
     SourceFile file = (SourceFile) squid.search("Animal.java");
index 2858a76ff3c388ba908ac0ac57cc7488ffa47d15..11cc79817006e42ddd641f830a99379ea54235bc 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.java.bytecode.asm;
 
 import org.junit.Test;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.ClassworldsClassLoader;
 import org.sonar.java.bytecode.asm.AsmClassProvider.DETAIL_LEVEL;
 
@@ -27,7 +28,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 public class AsmClassProviderImplTest {
 
@@ -85,7 +85,7 @@ public class AsmClassProviderImplTest {
 
   @Test
   public void testPersonalClassLoader() {
-    asmClassProviderImpl = new AsmClassProviderImpl(ClassworldsClassLoader.create(getFile("/bytecode/bin/")));
+    asmClassProviderImpl = new AsmClassProviderImpl(ClassworldsClassLoader.create(SquidTestUtils.getFile("/bytecode/bin/")));
     assertEquals(DETAIL_LEVEL.STRUCTURE_AND_CALLS, asmClassProviderImpl.getClass("tags/Line", DETAIL_LEVEL.STRUCTURE_AND_CALLS).getDetailLevel());
   }
 }
index d3b8a507a14a944e069ceb58f21fd64db24645da..7e1b7a3f1883fb1a94a6e2f2ef75746c3d895faa 100644 (file)
 package org.sonar.java.bytecode.asm;
 
 import org.junit.Test;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.ClassworldsClassLoader;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 public class AsmClassVisitorTest {
 
-  private static AsmClassProvider asmClassProvider = new AsmClassProviderImpl(ClassworldsClassLoader.create(getFile("/bytecode/bin/")));
+  private static AsmClassProvider asmClassProvider = new AsmClassProviderImpl(ClassworldsClassLoader.create(SquidTestUtils.getFile("/bytecode/bin/")));
 
   @Test
   public void testVisit() {
index c1165191e9c12a20b653dbafecb42c340a541f8f..40a73f6e0b7d793c8ed2a42017b0740418d68222 100644 (file)
 package org.sonar.java.bytecode.asm;
 
 import org.junit.Test;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.ClassworldsClassLoader;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 public class AsmFieldVisitorTest {
 
   @Test
   public void testVisitStringField() {
-    AsmClassProviderImpl classProvider = new AsmClassProviderImpl(ClassworldsClassLoader.create(getFile("/bytecode/bin/")));
+    AsmClassProviderImpl classProvider = new AsmClassProviderImpl(ClassworldsClassLoader.create(SquidTestUtils.getFile("/bytecode/bin/")));
     AsmClass fileClass = classProvider.getClass("tags/SourceFile");
     assertEquals(5, fileClass.getFields().size());
     AsmField field = fileClass.getField("path");
index 27abac563cc830b0fcc4117cfb0691e49dd2c94f..a1d8324c440603686535979c053ad711bba60b99 100644 (file)
 package org.sonar.java.bytecode.asm;
 
 import org.junit.Test;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.ClassworldsClassLoader;
 
 import static org.junit.Assert.*;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 public class AsmMethodVisitorTest {
 
-  private AsmClassProvider asmClassProvider = new AsmClassProviderImpl(ClassworldsClassLoader.create(getFile("/bytecode/bin/")));
+  private AsmClassProvider asmClassProvider = new AsmClassProviderImpl(ClassworldsClassLoader.create(SquidTestUtils.getFile("/bytecode/bin/")));
 
   @Test
   public void testVisitFieldInsn() {
index 0c0d4db2ae97cd4e8bb7bc45467e84beb11c42f9..4233312cb4882126d45c95641e978a21d3fd9ee1 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.java.bytecode.check;
 
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.BytecodeScanner;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
@@ -29,7 +30,6 @@ import org.sonar.squid.api.SourceFile;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 public class ArchitectureCheckTest {
 
@@ -78,8 +78,8 @@ public class ArchitectureCheckTest {
     check.setToClasses(toClasses);
 
     squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/architecture/src"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/architecture/src"));
     squid.registerVisitor(check);
-    squid.register(BytecodeScanner.class).scanDirectory(getFile("/bytecode/architecture/bin"));
+    squid.register(BytecodeScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/architecture/bin"));
   }
 }
index 209c7c6d1d60992265ceab5d2fc1b48a510ac4e9..e6ed3f42bb9f299597423313e217c3061faf9498 100644 (file)
@@ -21,11 +21,11 @@ package org.sonar.java.bytecode.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.BytecodeScanner;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
@@ -39,9 +39,9 @@ public class CallToDeprecatedMethodCheckTest {
   @BeforeClass
   public static void setup() {
     squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/callToDeprecatedMethod/src"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/callToDeprecatedMethod/src"));
     squid.registerVisitor(CallToDeprecatedMethodCheck.class);
-    squid.register(BytecodeScanner.class).scanDirectory(getFile("/bytecode/callToDeprecatedMethod/bin"));
+    squid.register(BytecodeScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/callToDeprecatedMethod/bin"));
   }
 
   @Test
index e09496804e1f7cf170f087d3e73c26510d9d606d..e1da2df5c0d4d71b2c8f8c2c6a0914b502e03839 100644 (file)
@@ -21,11 +21,11 @@ package org.sonar.java.bytecode.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.BytecodeScanner;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
@@ -39,9 +39,9 @@ public class UnusedPrivateMethodCheckTest {
   @BeforeClass
   public static void setup() {
     squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/unusedPrivateMethod/src"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/unusedPrivateMethod/src"));
     squid.registerVisitor(UnusedPrivateMethodCheck.class);
-    squid.register(BytecodeScanner.class).scanDirectory(getFile("/bytecode/unusedPrivateMethod/bin"));
+    squid.register(BytecodeScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/unusedPrivateMethod/bin"));
   }
 
   @Test
index fd89ccdb3d250c2dd89bfccd705e196c4de3b8a8..b4573367a2fbe826193cbae9fbfc58e255475304 100644 (file)
@@ -21,11 +21,11 @@ package org.sonar.java.bytecode.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.BytecodeScanner;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
@@ -39,9 +39,9 @@ public class UnusedProtectedMethodCheckTest {
   @BeforeClass
   public static void setup() {
     squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/unusedProtectedMethod/src"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/unusedProtectedMethod/src"));
     squid.registerVisitor(UnusedProtectedMethodCheck.class);
-    squid.register(BytecodeScanner.class).scanDirectory(getFile("/bytecode/unusedProtectedMethod/bin"));
+    squid.register(BytecodeScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/unusedProtectedMethod/bin"));
   }
 
   @Test
index 5cb36686f5ab8e7be33103041aa36f831aa7d609..3b81a45c2c04c2a6d04ee768f11a52d5d8e3fef3 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.java.bytecode.visitor;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.ClassworldsClassLoader;
 import org.sonar.java.bytecode.asm.AsmClass;
 import org.sonar.java.bytecode.asm.AsmClassProvider;
@@ -28,7 +29,6 @@ import org.sonar.java.bytecode.asm.AsmClassProviderImpl;
 import org.sonar.java.bytecode.asm.AsmMethod;
 
 import static org.junit.Assert.*;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 public class AccessorVisitorTest {
 
@@ -38,7 +38,7 @@ public class AccessorVisitorTest {
 
   @BeforeClass
   public static void init() {
-    asmClassProvider = new AsmClassProviderImpl(ClassworldsClassLoader.create(getFile("/bytecode/bin/")));
+    asmClassProvider = new AsmClassProviderImpl(ClassworldsClassLoader.create(SquidTestUtils.getFile("/bytecode/bin/")));
     javaBean = asmClassProvider.getClass("properties/JavaBean");
     accessorVisitor.visitClass(javaBean);
     for (AsmMethod method : javaBean.getMethods()) {
index 4e1bc2bda6ddf87df98ab76bce89c3eae13ea4aa..4a9d2af770fed7f334cf4b29d175976d97bf56c1 100644 (file)
@@ -21,11 +21,11 @@ package org.sonar.java.bytecode.visitor;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.BytecodeScanner;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.Squid;
@@ -40,8 +40,8 @@ public class LCOM4VisitorTest {
     JavaSquidConfiguration conf = new JavaSquidConfiguration();
     conf.addFieldToExcludeFromLcom4Calculation("LOG");
     squid = new Squid(conf);
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/lcom4/src"));
-    squid.register(BytecodeScanner.class).scanDirectory(getFile("/bytecode/lcom4/bin"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/lcom4/src"));
+    squid.register(BytecodeScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/lcom4/bin"));
     squid.decorateSourceCodeTreeWith(Metric.values());
   }
 
index 66b3ab29ac04c01639619b232afa0d8a4a228454..65cbb288f8d0fb173909acef7f6c2b44ea68c433 100644 (file)
@@ -22,11 +22,11 @@ package org.sonar.java.squid.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.java.squid.SquidScanner;
 import org.sonar.squid.Squid;
@@ -45,8 +45,8 @@ public class ClassComplexityCheckTest {
     check.setMax(5);
     squid.registerVisitor(check);
     JavaAstScanner scanner = squid.register(JavaAstScanner.class);
-    scanner.scanFile(getFile("/metrics/branches/NoBranches.java"));
-    scanner.scanFile(getFile("/metrics/branches/ComplexBranches.java"));
+    scanner.scanFile(SquidTestUtils.getInputFile("/metrics/branches/NoBranches.java"));
+    scanner.scanFile(SquidTestUtils.getInputFile("/metrics/branches/ComplexBranches.java"));
     squid.decorateSourceCodeTreeWith(Metric.values());
     squid.register(SquidScanner.class).scan();
   }
index 0aecce29ae2643fd910aa4bf1bcff2369fbdcc53..b74ffd8f49a9385d16bba56f3fe26eeab1129b36 100644 (file)
@@ -22,11 +22,11 @@ package org.sonar.java.squid.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.BytecodeScanner;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.java.squid.SquidScanner;
@@ -44,8 +44,8 @@ public class DITCheckTest {
     DITCheck check = new DITCheck();
     check.setMax(1);
     squid.registerVisitor(check);
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/bytecode/unusedProtectedMethod/src"));
-    squid.register(BytecodeScanner.class).scanDirectory(getFile("/bytecode/unusedProtectedMethod/bin"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/unusedProtectedMethod/src"));
+    squid.register(BytecodeScanner.class).scanDirectory(SquidTestUtils.getFile("/bytecode/unusedProtectedMethod/bin"));
     squid.register(SquidScanner.class).scan();
   }
 
index 985fd9b205e74bb6456ce1d7f2e9825bec70f7b4..f44ec36ef5f4a517fb18b71be3e0100a779fde6f 100644 (file)
@@ -22,11 +22,11 @@ package org.sonar.java.squid.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.java.squid.SquidScanner;
 import org.sonar.squid.Squid;
@@ -44,7 +44,7 @@ public class MethodComplexityCheckTest {
     check.setMax(5);
     squid.registerVisitor(check);
     JavaAstScanner scanner = squid.register(JavaAstScanner.class);
-    scanner.scanFile(getFile("/metrics/branches/ComplexBranches.java"));
+    scanner.scanFile(SquidTestUtils.getInputFile("/metrics/branches/ComplexBranches.java"));
     squid.decorateSourceCodeTreeWith(Metric.values());
     squid.register(SquidScanner.class).scan();
   }
index 23d196c8b4a65574ed9a6fe403f67c33f7df11ce..0b36b69ba550fea682a46923a397edd18fae7825 100644 (file)
@@ -21,11 +21,11 @@ package org.sonar.java.squid.check;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.java.squid.SquidScanner;
 import org.sonar.squid.Squid;
@@ -42,8 +42,8 @@ public class NoSonarCheckTest {
     NoSonarCheck check = new NoSonarCheck();
     squid.registerVisitor(check);
     JavaAstScanner scanner = squid.register(JavaAstScanner.class);
-    scanner.scanFile(getFile("/rules/FileWithNOSONARTags.java"));
-    scanner.scanFile(getFile("/rules/FileWithoutNOSONARTags.java"));
+    scanner.scanFile(SquidTestUtils.getInputFile("/rules/FileWithNOSONARTags.java"));
+    scanner.scanFile(SquidTestUtils.getInputFile("/rules/FileWithoutNOSONARTags.java"));
     squid.decorateSourceCodeTreeWith(Metric.values());
     squid.register(SquidScanner.class).scan();
   }
index dc0b363b0b529dc212c37b1a48e5944f12340103..25b7ac003132eebe2586acb31cee44ef9cfdb759 100644 (file)
@@ -36,6 +36,7 @@ import org.sonar.api.batch.SensorContext;
 import org.sonar.api.checks.AnnotationCheckFactory;
 import org.sonar.api.checks.CheckFactory;
 import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.resources.InputFile;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
 import org.sonar.squid.Squid;
@@ -62,7 +63,7 @@ public class SquidExecutorTest {
   @Test
   public void doNotScanBytecodeIfNoSources() throws IOException, URISyntaxException {
     SquidExecutor executor = new SquidExecutor(true, "LOG, logger", createCheckFactory(), Charset.defaultCharset());
-    executor.scan(Collections.<File> emptyList(), Arrays.asList(SquidTestUtils.getStrutsCoreJar()));
+    executor.scan(Collections.<InputFile> emptyList(), Arrays.asList(SquidTestUtils.getStrutsCoreJar()));
 
     assertThat(executor.isSourceScanned(), is(false));
     assertThat(executor.isBytecodeScanned(), is(false));
index ec308e66a16df0fe9ad228a033c073ff03457e19..d22cfece08a3e74d60f01425035bcc86ad5c31df 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonar.plugins.squid;
 
 import org.apache.commons.io.FileUtils;
+import org.sonar.api.resources.InputFile;
+import org.sonar.api.resources.InputFileUtils;
 import org.sonar.api.utils.ZipUtils;
 
 import java.io.File;
@@ -35,13 +37,15 @@ public final class SquidTestUtils {
   /**
    * See http://svn.apache.org/repos/asf/struts/struts1/tags/STRUTS_1_3_9/core
    */
-  public static Collection<File> getStrutsCoreSources() throws IOException, URISyntaxException {
+  public static Collection<InputFile> getStrutsCoreSources() throws IOException, URISyntaxException {
     File sourceDir = new File("target/struts-core-1.3.9-sources");
     if (!sourceDir.exists() || sourceDir.list().length==0) {
       FileUtils.forceMkdir(sourceDir);
       ZipUtils.unzip(new File(SquidTestUtils.class.getResource("/struts-core-1.3.9-sources.jar").toURI()), sourceDir);
     }
-    return FileUtils.listFiles(sourceDir, new String[]{"java"}, true);
+    Collection<File> javaFiles = FileUtils.listFiles(sourceDir, new String[]{"java"}, true);
+
+    return InputFileUtils.create(sourceDir, javaFiles);
   }
 
   /**
index 3f01a71bd26c73a52ffc7627657a16e21a3ced88..92defe7ad3fdb5e867878afe6f96e6a96f15fc10 100644 (file)
 package org.sonar.squid;
 
 import static org.junit.Assert.assertNotNull;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.squid.JavaSquidConfiguration;
 
 public class SquidTest {
@@ -38,9 +38,9 @@ public class SquidTest {
 
   @Test
   public void searchSingleResult() {
-    squid.register(JavaAstScanner.class).scanFile(getFile("/metrics/accessors/JavaBeanWithApiDoc.java"));
-    assertNotNull(squid.search("java/bean/test"));
-    assertNotNull(squid.search("java/bean/test/JavaBeanWithApiDoc.java"));
-    assertNotNull(squid.search("java/bean/test/JavaBeanWithAPIDoc"));
+    squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/packages/", "org/foo/SimpleBean.java"));
+    assertNotNull(squid.search("org/foo"));
+    assertNotNull(squid.search("org/foo/SimpleBean.java"));
+    assertNotNull(squid.search("org/foo/SimpleBean"));
   }
 }
index 9dd2a97b957c109b32bdd1b01e854c1309f35480..56e0ae64bdbd8ab5c1a339294374e51758ab6494 100644 (file)
@@ -24,7 +24,6 @@ import static org.hamcrest.number.OrderingComparisons.lessThan;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.sonar.java.ast.SquidTestUtils.getFile;
 
 import java.util.Collection;
 import java.util.Map;
@@ -33,6 +32,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.sonar.graph.IncrementalCyclesAndFESSolver;
 import org.sonar.java.ast.JavaAstScanner;
+import org.sonar.java.ast.SquidTestUtils;
 import org.sonar.java.bytecode.BytecodeScanner;
 import org.sonar.java.squid.JavaSquidConfiguration;
 import org.sonar.squid.api.SourceCode;
@@ -55,8 +55,8 @@ public class SquidUserGuideTest {
   @BeforeClass
   public static void setup() {
     squid = new Squid(new JavaSquidConfiguration());
-    squid.register(JavaAstScanner.class).scanDirectory(getFile("/commons-collections-3.2.1/src"));
-    squid.register(BytecodeScanner.class).scanDirectory(getFile("/commons-collections-3.2.1/bin"));
+    squid.register(JavaAstScanner.class).scanDirectory(SquidTestUtils.getFile("/commons-collections-3.2.1/src"));
+    squid.register(BytecodeScanner.class).scanDirectory(SquidTestUtils.getFile("/commons-collections-3.2.1/bin"));
     project = squid.aggregate();
   }
 
index 0a897e478c5b4957aa5b11c99786219acc2bc85f..952306c7d2bec308753fcc3e541fdbec78f51a57 100644 (file)
@@ -1,8 +1,8 @@
-public class Car {
+public class NoBranches {
        private int n;
        private String s;
 
-       public AClass(int n, String s) {
+       public NoBranches(int n, String s) {
                this.n = n;
                this.s = s;
        }
index e2bd9a5a8756e2218a4fa2b0b0834f44b71bd5b2..50092f8641e2d1bb748eb3cc16ca35855b22f821 100644 (file)
@@ -1,10 +1,10 @@
 import java.util.ArrayList;
 
-public class Car {
+public class SimpleBranches {
        private int n;
        private String s;
 
-       public AClass(int n, String s) {
+       public SimpleBranches(int n, String s) {
                this.n = n;
                this.s = s;
        }
index 4e1b6cad790f414a3964baa615d7ada8ac19abf0..fb3135d8d13f53136880e1296a070a6922992587 100644 (file)
@@ -1,6 +1,4 @@
 
-package org.sonar;
-
 public abstract class AbstractClass {
   
   //comment
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/commentedCode/org/foo/CommentedOutFile.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/commentedCode/org/foo/CommentedOutFile.java
new file mode 100644 (file)
index 0000000..810c32b
--- /dev/null
@@ -0,0 +1,5 @@
+//package org.foo;
+//
+//public class CommentedOutFile {
+//
+//}
\ No newline at end of file
index a58d6932246c643afc598c3b0ec594dd08c470e8..b402a30a9440290c2e1afaa43bcad7bf86ab8db2 100644 (file)
@@ -3,7 +3,7 @@
  * 
  * multi lines
  */
-package test;
+
 
 import nothing;
 //single comment 1
index 768cb56c232dabfe14be3456a8a55dee46d24cba..c06dbc0de38b6ac403432146aba5b1364aa6ec3a 100644 (file)
@@ -8,7 +8,7 @@ blank lines in comments block
 should no be counted\r
 \r
 */\r
-package test;\r
+\r
 \r
 public interface ClassWithHeaderAndBlankLines {\r
     void reset();\r
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithPackageAndJavadocHeader.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithPackageAndJavadocHeader.java
deleted file mode 100644 (file)
index a3523c5..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * File header as javadoc
- * should be detected as a header
- * 
- */
-package foo;
-
-/**
- * This is a class comment
- */
-public class ClassWithPackageAndJavadocHeader {
-
-       public static void doJob1() {
-               int i = 3;
-               if (i == 4) {
-                       i++;
-               }
-       }
-       
-       /**
-        * 
-        * qsdfqsdf
-        */
-       public static void doJob2() {
-               int i = 3;
-               if (i == 4) {
-                       if (i == 3) {
-                               i--;
-                               //mlkqjdsf
-                       }
-               }
-       }
-       public class Toto{
-               public static void doJob2() {
-                       int i = 3;
-                       if (i == 4) {
-                               if (i == 3) {
-                                       i--;
-                               }
-                       }
-               }
-               
-       }
-       
-       
-       
-       
-       
-
-}
index 4135eb29d30391e1d6ad6901ede3ac4df9a5fcf5..542b66c7d175882d7dfa6e0dae0b3e0e11e91918 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Header
  */
-package test;
+
 
 import nothing;
 //single comment 1
index f52c100b9cbb1288d082f02858e12407b9627f1f..da20288279ac2319350eddb5b868281988c83bd6 100644 (file)
@@ -18,7 +18,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.struts.chain;
+
 
 
 /**
index 9f008bbfd8c056d5dc3b4c8411ba113d715ab550..26a1c1e821bfc1bef1e2ef00f831212672859de1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Header
  */
-package test;
+
 
 public class EmptyConstructor {
     
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/foo/ClassWithPackageAndJavadocHeader.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/foo/ClassWithPackageAndJavadocHeader.java
new file mode 100644 (file)
index 0000000..a3523c5
--- /dev/null
@@ -0,0 +1,50 @@
+/**
+ * File header as javadoc
+ * should be detected as a header
+ * 
+ */
+package foo;
+
+/**
+ * This is a class comment
+ */
+public class ClassWithPackageAndJavadocHeader {
+
+       public static void doJob1() {
+               int i = 3;
+               if (i == 4) {
+                       i++;
+               }
+       }
+       
+       /**
+        * 
+        * qsdfqsdf
+        */
+       public static void doJob2() {
+               int i = 3;
+               if (i == 4) {
+                       if (i == 3) {
+                               i--;
+                               //mlkqjdsf
+                       }
+               }
+       }
+       public class Toto{
+               public static void doJob2() {
+                       int i = 3;
+                       if (i == 4) {
+                               if (i == 3) {
+                                       i--;
+                               }
+                       }
+               }
+               
+       }
+       
+       
+       
+       
+       
+
+}
index 1b301fce9988bf8ec9aa4db09d5035ffe69b9051..76a4f9e9392b24c5929ff1e7ead995b38ce85c70 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Header
  */
-package test;
+
 
 import nothing;
 //single comment 1
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/packages/org/foo/SimpleBean.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/packages/org/foo/SimpleBean.java
new file mode 100644 (file)
index 0000000..9cd3eb7
--- /dev/null
@@ -0,0 +1,31 @@
+package org.foo;
+
+public class SimpleBean {
+  
+  /**
+   * Not to count
+   */
+  private String testVar;
+  
+  /**
+   * To count
+   */
+  public String testVar2;
+  
+  /**
+   * This api doc should not be counted not its complexity
+   * @return
+   */
+  public String getTest() {
+    return testVar;
+  }
+  
+  /**
+   * This api doc should be counted
+   * @return
+   */
+  public String getTest2() {
+    return "test";
+  }
+  
+}
\ No newline at end of file
diff --git a/plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/ClassWithPackageImportsComment.java b/plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/ClassWithPackageImportsComment.java
deleted file mode 100644 (file)
index 6d231bf..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// some comment
-package test;
-
-import java.lang.Runtime;
-import org.apache.commons.*;
-
-// another comment
\ No newline at end of file
diff --git a/plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/foo/ClassWithPackageImportsComment.java b/plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/foo/ClassWithPackageImportsComment.java
new file mode 100644 (file)
index 0000000..98fac7d
--- /dev/null
@@ -0,0 +1,7 @@
+// some comment
+package foo;
+
+import java.lang.Runtime;
+import org.apache.commons.*;
+
+// another comment
\ No newline at end of file
diff --git a/plugins/sonar-squid-java-plugin/test-resources/special_cases/package-info.java b/plugins/sonar-squid-java-plugin/test-resources/special_cases/package-info.java
deleted file mode 100644 (file)
index 7076688..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/**\r
- * Licensed to the Apache Software Foundation (ASF) under one\r
- * or more contributor license agreements. See the NOTICE file\r
- * distributed with this work for additional information\r
- * regarding copyright ownership. The ASF licenses this file\r
- * to you under the Apache License, Version 2.0 (the\r
- * "License"); you may not use this file except in compliance\r
- * with the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing,\r
- * software distributed under the License is distributed on an\r
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r
- * KIND, either express or implied. See the License for the\r
- * specific language governing permissions and limitations\r
- * under the License.\r
- */\r
-\r
-/**\r
- * JAX-RS specific logging support. Based on <tt>java.util.logging</tt> (JUL)\r
- * with use of different logging frameworks factored out; assumes that client \r
- * with source code logging to other systems, like Log4J, can bridge \r
- * to this implementation applying <a href="www.slf4j.org">SLF4J</a> \r
- * that JAXRS already depends on.\r
- */\r
-@javax.xml.bind.annotation.XmlSchema(xmlns = {\r
-        @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://cxf.apache.org/jaxrs/log", prefix = "log")\r
-            })\r
-package org.apache.cxf.jaxrs.ext.logging;\r
-\r
diff --git a/plugins/sonar-squid-java-plugin/test-resources/special_cases/packageInfo/org/apache/cxf/jaxrs/ext/logging/package-info.java b/plugins/sonar-squid-java-plugin/test-resources/special_cases/packageInfo/org/apache/cxf/jaxrs/ext/logging/package-info.java
new file mode 100644 (file)
index 0000000..f569bf6
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * JAX-RS specific logging support. Based on <tt>java.util.logging</tt> (JUL)
+ * with use of different logging frameworks factored out; assumes that client 
+ * with source code logging to other systems, like Log4J, can bridge 
+ * to this implementation applying <a href="www.slf4j.org">SLF4J</a> 
+ * that JAXRS already depends on.
+ */
+@javax.xml.bind.annotation.XmlSchema(xmlns = {
+        @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://cxf.apache.org/jaxrs/log", prefix = "log")
+            })
+package org.apache.cxf.jaxrs.ext.logging;
+
diff --git a/plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/CommentedOutFile.java b/plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/CommentedOutFile.java
new file mode 100644 (file)
index 0000000..88f9cf0
--- /dev/null
@@ -0,0 +1,7 @@
+//package org.foo;
+//
+//public class GoodPackage {
+//
+//  private int i;
+//
+//}
\ No newline at end of file
diff --git a/plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/GoodPackage.java b/plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/GoodPackage.java
new file mode 100644 (file)
index 0000000..08e93ee
--- /dev/null
@@ -0,0 +1,7 @@
+package org.foo;
+
+public class GoodPackage {
+
+  private int i;
+
+}
\ No newline at end of file
diff --git a/plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/WrongPackage.java b/plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/WrongPackage.java
new file mode 100644 (file)
index 0000000..00b7237
--- /dev/null
@@ -0,0 +1,7 @@
+package com.somewhere;
+
+public class WrongPackage {
+
+  private int i;
+
+}
\ No newline at end of file