aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-04-11 16:55:40 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-04-11 16:55:40 +0200
commit07625d01d50a80c360156869b375f8672b3a280d (patch)
treeb7b12e66699089c743b7ef7c4b02a5af39257d34 /plugins
parent821193dfc6504ab799d60ea6e5cbd66a65e2f095 (diff)
downloadsonarqube-07625d01d50a80c360156869b375f8672b3a280d.tar.gz
sonarqube-07625d01d50a80c360156869b375f8672b3a280d.zip
SONAR-791 compare package declaration with physical directory
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/CheckstyleSquidBridge.java20
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/JavaAstScanner.java67
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/JavaAstVisitor.java26
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java62
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java9
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java39
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/SquidTestUtils.java16
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/BreakCheckTest.java13
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/ContinueCheckTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AccessorVisitorTest.java20
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AnonymousInnerClassVisitorTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BlankLinesVisitorTest.java16
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BrancheVisitorTest.java8
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ClassVisitorTest.java24
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java26
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ComplexityVisitorTest.java10
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/EndAtLineVisitorTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java10
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/HeaderCommentVisitorTest.java14
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesOfCodeVisitorTest.java12
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesVisitorTest.java10
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/MethodVisitorTest.java14
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java66
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PublicApiVisitorTest.java36
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/StatementVisitorTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/BytecodeVisitorsTest.java10
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/ClassworldsClassLoaderTest.java8
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/VirtualMethodsLinkerTest.java7
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassProviderImplTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassVisitorTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldVisitorTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodVisitorTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/ArchitectureCheckTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/CallToDeprecatedMethodCheckTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedPrivateMethodCheckTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedProtectedMethodCheckTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/AccessorVisitorTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/LCOM4VisitorTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/ClassComplexityCheckTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/DITCheckTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/MethodComplexityCheckTest.java4
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java3
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java8
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidTest.java10
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidUserGuideTest.java6
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/JavaBeanWithApiDoc.java1
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/PureJavaBean.java1
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/branches/NoBranches.java4
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/branches/SimpleBranches.java4
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/classes/AbstractClass.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/commentedCode/org/foo/CommentedOutFile.java5
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithComments.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithCommentsOnLineOfCode.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeader.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeaderAndBlankLines.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithVars.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithoutHeaderAndWithCComment.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/Constants.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/EmptyConstructor.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/InterfaceWithComments.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/foo/ClassWithPackageAndJavadocHeader.java (renamed from plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithPackageAndJavadocHeader.java)0
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/loc/Test001.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/ncloc/TestNclocWithHeader.java2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/metrics/packages/org/foo/SimpleBean.java31
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/AnnotationDefinition.java1
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/InterfaceWithAnnotation.java1
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/foo/ClassWithPackageImportsComment.java (renamed from plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/ClassWithPackageImportsComment.java)2
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/special_cases/packageInfo/org/apache/cxf/jaxrs/ext/logging/package-info.java (renamed from plugins/sonar-squid-java-plugin/test-resources/special_cases/package-info.java)62
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/CommentedOutFile.java7
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/GoodPackage.java7
-rw-r--r--plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/WrongPackage.java7
75 files changed, 522 insertions, 305 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/CheckstyleSquidBridge.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/CheckstyleSquidBridge.java
index 3607ab3fe82..9de6058b3b6 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/CheckstyleSquidBridge.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/CheckstyleSquidBridge.java
@@ -19,12 +19,13 @@
*/
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) {
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/JavaAstScanner.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/JavaAstScanner.java
index ae908db4c67..350d160f2e2 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/JavaAstScanner.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/JavaAstScanner.java
@@ -19,11 +19,14 @@
*/
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);
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/JavaAstVisitor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/JavaAstVisitor.java
index c0c4c635c50..64d21c9a3d4 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/JavaAstVisitor.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/JavaAstVisitor.java
@@ -19,18 +19,18 @@
*/
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;
}
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java
index a0ba7e71430..fe512777008 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/java/ast/visitor/PackageVisitor.java
@@ -19,17 +19,21 @@
*/
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
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
index 01494e6ea56..4be634b0546 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidExecutor.java
@@ -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);
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java
index 1e4da4853f3..318bded0ea8 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java
@@ -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) {
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java
index 7506dbb50bd..afddc3cf2cd 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java
@@ -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));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/SquidTestUtils.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/SquidTestUtils.java
index 766929440cf..c8e428c1f31 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/SquidTestUtils.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/SquidTestUtils.java
@@ -19,10 +19,26 @@
*/
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);
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/BreakCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/BreakCheckTest.java
index 2b61b9ea455..9ee98d5530e 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/BreakCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/BreakCheckTest.java
@@ -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
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/ContinueCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/ContinueCheckTest.java
index a5787df6df2..09bd0b5afac 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/ContinueCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/ContinueCheckTest.java
@@ -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
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java
index 2888fdcb22d..e83b3ce77c3 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/check/UndocumentedApiCheckTest.java
@@ -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();
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AccessorVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AccessorVisitorTest.java
index 7e43874b24f..9f1aed35175 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AccessorVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AccessorVisitorTest.java
@@ -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));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AnonymousInnerClassVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AnonymousInnerClassVisitorTest.java
index d2827ccabe5..77da25cac70 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AnonymousInnerClassVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/AnonymousInnerClassVisitorTest.java
@@ -20,11 +20,11 @@
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"));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BlankLinesVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BlankLinesVisitorTest.java
index 711872a2831..d5b5fe342c8 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BlankLinesVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BlankLinesVisitorTest.java
@@ -20,11 +20,11 @@
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));
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BrancheVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BrancheVisitorTest.java
index e385db329ff..52085be3a33 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BrancheVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/BrancheVisitorTest.java
@@ -20,11 +20,11 @@
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));
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ClassVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ClassVisitorTest.java
index ee9a68dec15..dcbe39d8807 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ClassVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ClassVisitorTest.java
@@ -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));
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java
index af8ba251112..f67fa24820b 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/CommentVisitorTest.java
@@ -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;
@@ -75,6 +77,18 @@ public class CommentVisitorTest {
}
@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");
SourceFile file = (SourceFile) squid.search("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();
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ComplexityVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ComplexityVisitorTest.java
index 07e7209ab09..fafdd011af4 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ComplexityVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/ComplexityVisitorTest.java
@@ -20,11 +20,11 @@
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));
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/EndAtLineVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/EndAtLineVisitorTest.java
index dc72f66caea..53d9970b6d8 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/EndAtLineVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/EndAtLineVisitorTest.java
@@ -20,10 +20,10 @@
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());
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java
index 7fe8036b70f..22eeaa8d4f4 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java
@@ -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));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/HeaderCommentVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/HeaderCommentVisitorTest.java
index 662f871cdc9..9be05e7465d 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/HeaderCommentVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/HeaderCommentVisitorTest.java
@@ -20,11 +20,11 @@
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));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesOfCodeVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesOfCodeVisitorTest.java
index 107945ea0fe..c1403a22457 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesOfCodeVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesOfCodeVisitorTest.java
@@ -20,11 +20,11 @@
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));
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesVisitorTest.java
index 0d0eaec4984..bdc9987f179 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/LinesVisitorTest.java
@@ -20,11 +20,11 @@
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));
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/MethodVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/MethodVisitorTest.java
index a8e7d740ec4..4d79a5ca33a 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/MethodVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/MethodVisitorTest.java
@@ -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
index 00000000000..5363c12ad81
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java
@@ -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));
+ }
+}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PublicApiVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PublicApiVisitorTest.java
index 925d196deda..2ad9296ddb4 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PublicApiVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PublicApiVisitorTest.java
@@ -20,11 +20,11 @@
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));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/StatementVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/StatementVisitorTest.java
index ea7f9c57671..a452f21dfe7 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/StatementVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/StatementVisitorTest.java
@@ -20,11 +20,11 @@
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");
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/BytecodeVisitorsTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/BytecodeVisitorsTest.java
index 24cf3c4c5a6..6ac724dc307 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/BytecodeVisitorsTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/BytecodeVisitorsTest.java
@@ -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));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/ClassworldsClassLoaderTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/ClassworldsClassLoaderTest.java
index 93f0a2b4345..ea93533cffc 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/ClassworldsClassLoaderTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/ClassworldsClassLoaderTest.java
@@ -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());
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/VirtualMethodsLinkerTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/VirtualMethodsLinkerTest.java
index a301b26039a..4281314d5f0 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/VirtualMethodsLinkerTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/VirtualMethodsLinkerTest.java
@@ -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");
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassProviderImplTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassProviderImplTest.java
index 2858a76ff3c..11cc7981700 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassProviderImplTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassProviderImplTest.java
@@ -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());
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassVisitorTest.java
index d3b8a507a14..7e1b7a3f188 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmClassVisitorTest.java
@@ -20,17 +20,17 @@
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() {
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldVisitorTest.java
index c1165191e9c..40a73f6e0b7 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmFieldVisitorTest.java
@@ -20,17 +20,17 @@
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");
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodVisitorTest.java
index 27abac563cc..a1d8324c440 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/asm/AsmMethodVisitorTest.java
@@ -20,14 +20,14 @@
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() {
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/ArchitectureCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/ArchitectureCheckTest.java
index 0c0d4db2ae9..4233312cb48 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/ArchitectureCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/ArchitectureCheckTest.java
@@ -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"));
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/CallToDeprecatedMethodCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/CallToDeprecatedMethodCheckTest.java
index 209c7c6d1d6..e6ed3f42bb9 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/CallToDeprecatedMethodCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/CallToDeprecatedMethodCheckTest.java
@@ -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
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedPrivateMethodCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedPrivateMethodCheckTest.java
index e09496804e1..e1da2df5c0d 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedPrivateMethodCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedPrivateMethodCheckTest.java
@@ -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
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedProtectedMethodCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedProtectedMethodCheckTest.java
index fd89ccdb3d2..b4573367a2f 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedProtectedMethodCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/check/UnusedProtectedMethodCheckTest.java
@@ -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
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/AccessorVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/AccessorVisitorTest.java
index 5cb36686f5a..3b81a45c2c0 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/AccessorVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/AccessorVisitorTest.java
@@ -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()) {
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/LCOM4VisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/LCOM4VisitorTest.java
index 4e1bc2bda6d..4a9d2af770f 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/LCOM4VisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/bytecode/visitor/LCOM4VisitorTest.java
@@ -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());
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/ClassComplexityCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/ClassComplexityCheckTest.java
index 66b3ab29ac0..65cbb288f8d 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/ClassComplexityCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/ClassComplexityCheckTest.java
@@ -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();
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/DITCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/DITCheckTest.java
index 0aecce29ae2..b74ffd8f49a 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/DITCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/DITCheckTest.java
@@ -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();
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/MethodComplexityCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/MethodComplexityCheckTest.java
index 985fd9b205e..f44ec36ef5f 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/MethodComplexityCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/MethodComplexityCheckTest.java
@@ -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();
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java
index 23d196c8b4a..0b36b69ba55 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/squid/check/NoSonarCheckTest.java
@@ -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();
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java
index dc0b363b0b5..25b7ac00313 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java
@@ -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));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java
index ec308e66a16..d22cfece08a 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java
@@ -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);
}
/**
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidTest.java
index 3f01a71bd26..92defe7ad3f 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidTest.java
@@ -20,11 +20,11 @@
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"));
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidUserGuideTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidUserGuideTest.java
index 9dd2a97b957..56e0ae64bdb 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidUserGuideTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/squid/SquidUserGuideTest.java
@@ -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();
}
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/JavaBeanWithApiDoc.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/JavaBeanWithApiDoc.java
index 4a322994300..0a5d146ed06 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/JavaBeanWithApiDoc.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/JavaBeanWithApiDoc.java
@@ -1,4 +1,3 @@
-package java.bean.test;
public class JavaBeanWithAPIDoc {
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/PureJavaBean.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/PureJavaBean.java
index 1af27e2a425..226accd5cb5 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/PureJavaBean.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/accessors/PureJavaBean.java
@@ -1,4 +1,3 @@
-package java.bean.test;
public class PureJavaBean {
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/branches/NoBranches.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/branches/NoBranches.java
index 0a897e478c5..952306c7d2b 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/branches/NoBranches.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/branches/NoBranches.java
@@ -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;
}
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/branches/SimpleBranches.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/branches/SimpleBranches.java
index e2bd9a5a875..50092f8641e 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/branches/SimpleBranches.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/branches/SimpleBranches.java
@@ -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;
}
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/classes/AbstractClass.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/classes/AbstractClass.java
index 4e1b6cad790..fb3135d8d13 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/classes/AbstractClass.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/classes/AbstractClass.java
@@ -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
index 00000000000..810c32b70be
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/commentedCode/org/foo/CommentedOutFile.java
@@ -0,0 +1,5 @@
+//package org.foo;
+//
+//public class CommentedOutFile {
+//
+//} \ No newline at end of file
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithComments.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithComments.java
index 6a3f508081f..272d55bb5d9 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithComments.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithComments.java
@@ -1,7 +1,7 @@
/*
* Header
*/
-package test;
+
import nothing;
//single comment 1
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithCommentsOnLineOfCode.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithCommentsOnLineOfCode.java
index 8f27316339d..e39c272870b 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithCommentsOnLineOfCode.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithCommentsOnLineOfCode.java
@@ -1,4 +1,4 @@
-package test;
+
public class ClassWithCommentsOnLineOfCode {
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeader.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeader.java
index a58d6932246..b402a30a944 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeader.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeader.java
@@ -3,7 +3,7 @@
*
* multi lines
*/
-package test;
+
import nothing;
//single comment 1
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeaderAndBlankLines.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeaderAndBlankLines.java
index 768cb56c232..c06dbc0de38 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeaderAndBlankLines.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithHeaderAndBlankLines.java
@@ -8,7 +8,7 @@ blank lines in comments block
should no be counted
*/
-package test;
+
public interface ClassWithHeaderAndBlankLines {
void reset();
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithVars.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithVars.java
index 4135eb29d30..542b66c7d17 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithVars.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithVars.java
@@ -1,7 +1,7 @@
/*
* Header
*/
-package test;
+
import nothing;
//single comment 1
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithoutHeaderAndWithCComment.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithoutHeaderAndWithCComment.java
index b83822f5b7e..7f17fe29cef 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithoutHeaderAndWithCComment.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithoutHeaderAndWithCComment.java
@@ -1,4 +1,4 @@
-package test;
+
import nothing;
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/Constants.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/Constants.java
index f52c100b9cb..da20288279a 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/Constants.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/Constants.java
@@ -18,7 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts.chain;
+
/**
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/EmptyConstructor.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/EmptyConstructor.java
index 9f008bbfd8c..26a1c1e821b 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/EmptyConstructor.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/EmptyConstructor.java
@@ -1,7 +1,7 @@
/*
* Header
*/
-package test;
+
public class EmptyConstructor {
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/InterfaceWithComments.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/InterfaceWithComments.java
index 74db2b709bb..87d6bc220fc 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/InterfaceWithComments.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/InterfaceWithComments.java
@@ -1,7 +1,7 @@
/*
* Header
*/
-package test;
+
public interface Something {
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java
index a0dba5ed7bd..0835f5fea9a 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/MethodsWithOverrideAnnotation.java
@@ -1,7 +1,7 @@
/*
* Header
*/
-package test;
+
public class MethodsWithOverrideAnnotation {
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithPackageAndJavadocHeader.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/foo/ClassWithPackageAndJavadocHeader.java
index a3523c52627..a3523c52627 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/ClassWithPackageAndJavadocHeader.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/javadoc/foo/ClassWithPackageAndJavadocHeader.java
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/loc/Test001.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/loc/Test001.java
index 1b301fce998..76a4f9e9392 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/loc/Test001.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/loc/Test001.java
@@ -1,7 +1,7 @@
/*
* Header
*/
-package test;
+
import nothing;
//single comment 1
diff --git a/plugins/sonar-squid-java-plugin/test-resources/metrics/ncloc/TestNclocWithHeader.java b/plugins/sonar-squid-java-plugin/test-resources/metrics/ncloc/TestNclocWithHeader.java
index 3e63467b369..7df94e49655 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/metrics/ncloc/TestNclocWithHeader.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/ncloc/TestNclocWithHeader.java
@@ -7,7 +7,7 @@
* lines
*/
-package test;
+
/**
* This is a nice comments header
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
index 00000000000..9cd3eb7de1b
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/test-resources/metrics/packages/org/foo/SimpleBean.java
@@ -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/annotations/AnnotationDefinition.java b/plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/AnnotationDefinition.java
index c8b1986529b..5984ae8b838 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/AnnotationDefinition.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/AnnotationDefinition.java
@@ -1,4 +1,3 @@
-package org.sonar.plugins.api;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
diff --git a/plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/InterfaceWithAnnotation.java b/plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/InterfaceWithAnnotation.java
index 6219c240fcc..740518a3692 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/InterfaceWithAnnotation.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/special_cases/annotations/InterfaceWithAnnotation.java
@@ -1,4 +1,3 @@
-package com.toto;
public interface InterfaceWithAnnotation {
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/foo/ClassWithPackageImportsComment.java
index 6d231bf4ca3..98fac7dfd5f 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/ClassWithPackageImportsComment.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/special_cases/emptyFiles/foo/ClassWithPackageImportsComment.java
@@ -1,5 +1,5 @@
// some comment
-package test;
+package foo;
import java.lang.Runtime;
import org.apache.commons.*;
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/packageInfo/org/apache/cxf/jaxrs/ext/logging/package-info.java
index 7076688ebd5..f569bf6138b 100644
--- a/plugins/sonar-squid-java-plugin/test-resources/special_cases/package-info.java
+++ b/plugins/sonar-squid-java-plugin/test-resources/special_cases/packageInfo/org/apache/cxf/jaxrs/ext/logging/package-info.java
@@ -1,31 +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;
-
+/**
+ * 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
index 00000000000..88f9cf0144b
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/CommentedOutFile.java
@@ -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
index 00000000000..08e93ee0c7a
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/GoodPackage.java
@@ -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
index 00000000000..00b7237ac1c
--- /dev/null
+++ b/plugins/sonar-squid-java-plugin/test-resources/special_cases/wrongPackages/org/foo/WrongPackage.java
@@ -0,0 +1,7 @@
+package com.somewhere;
+
+public class WrongPackage {
+
+ private int i;
+
+} \ No newline at end of file