diff options
author | Godin <mandrikov@gmail.com> | 2010-11-03 14:42:22 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-11-03 14:42:22 +0000 |
commit | 3cd3e807f4b55c51362290885398cba067812699 (patch) | |
tree | 194e191d47c118c6c383814e5535a2f04089702c /plugins/sonar-squid-java-plugin | |
parent | ce0caddad67119edc47fd5509720e78fcd5e3da7 (diff) | |
download | sonarqube-3cd3e807f4b55c51362290885398cba067812699.tar.gz sonarqube-3cd3e807f4b55c51362290885398cba067812699.zip |
Use ProjectClasspath instead of custom filtering in sonar-squid-java-plugin
Diffstat (limited to 'plugins/sonar-squid-java-plugin')
-rw-r--r-- | plugins/sonar-squid-java-plugin/pom.xml | 49 | ||||
-rw-r--r-- | plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidSensor.java | 53 |
2 files changed, 16 insertions, 86 deletions
diff --git a/plugins/sonar-squid-java-plugin/pom.xml b/plugins/sonar-squid-java-plugin/pom.xml index 7ec6145e76a..4fc97d4fef7 100644 --- a/plugins/sonar-squid-java-plugin/pom.xml +++ b/plugins/sonar-squid-java-plugin/pom.xml @@ -16,16 +16,18 @@ <dependencies> <dependency> <groupId>org.codehaus.sonar</groupId> - <artifactId>sonar-deprecated</artifactId> + <artifactId>sonar-plugin-api</artifactId> + <scope>provided</scope> </dependency> - <dependency> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-squid</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-graph</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>asm</groupId> @@ -33,10 +35,6 @@ <version>3.2</version> </dependency> <dependency> - <groupId>org.codehaus.sonar</groupId> - <artifactId>sonar-plugin-api</artifactId> - </dependency> - <dependency> <groupId>checkstyle</groupId> <artifactId>checkstyle</artifactId> <version>5.1</version> @@ -63,51 +61,16 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-common-artifact-filters</artifactId> - <exclusions> - <!-- optimizations to reduce the size of the plugin JAR --> - <exclusion> - <groupId>org.apache.maven</groupId> - <artifactId>maven-core</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.maven</groupId> - <artifactId>maven-artifact</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.maven</groupId> - <artifactId>maven-model</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-plugin-testing-harness</artifactId> - </exclusion> - <exclusion> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-container-default</artifactId> - </exclusion> - <exclusion> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-utils</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> + <scope>provided</scope> </dependency> <dependency> <groupId>classworlds</groupId> <artifactId>classworlds</artifactId> <scope>provided</scope> </dependency> - - + <!-- unit tests --> <dependency> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-testing-harness</artifactId> 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 e2f58dca855..5abb4f50b67 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 @@ -20,29 +20,18 @@ package org.sonar.plugins.squid; import org.apache.commons.io.FileUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.project.MavenProject; -import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts; -import org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter; -import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; import org.sonar.api.CoreProperties; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.Phase; -import org.sonar.api.batch.Sensor; -import org.sonar.api.batch.SensorContext; +import org.sonar.api.batch.*; import org.sonar.api.checks.AnnotationCheckFactory; import org.sonar.api.checks.NoSonarFilter; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.Java; import org.sonar.api.resources.Project; -import org.sonar.api.utils.SonarException; import java.io.File; import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Set; @Phase(name = Phase.Name.PRE) /* TODO is the flag still used ? */ @@ -52,11 +41,13 @@ public class SquidSensor implements Sensor { private SquidSearchProxy proxy; private NoSonarFilter noSonarFilter; private RulesProfile profile; + private ProjectClasspath projectClasspath; - public SquidSensor(RulesProfile profile, SquidSearchProxy proxy, NoSonarFilter noSonarFilter) { + public SquidSensor(RulesProfile profile, SquidSearchProxy proxy, NoSonarFilter noSonarFilter, ProjectClasspath projectClasspath) { this.proxy = proxy; this.noSonarFilter = noSonarFilter; this.profile = profile; + this.projectClasspath = projectClasspath; } public boolean shouldExecuteOnProject(Project project) { @@ -84,38 +75,15 @@ public class SquidSensor implements Sensor { return project.getFileSystem().getJavaSourceFiles(); } - /** - * TODO replace this code by org.sonar.api.batch.ProjectClasspath - * - * @return Collection of java.util.File - */ private Collection<File> getBytecodeFiles(Project project) { - try { - Collection<File> bytecodeFiles = new ArrayList<File>(); - if (hasProjectBytecodeFiles(project)) { - File classesDir = project.getFileSystem().getBuildOutputDir(); - if (classesDir != null && classesDir.exists()) { - bytecodeFiles.add(classesDir); - } - - MavenProject mavenProject = project.getPom(); - FilterArtifacts filters = new FilterArtifacts(); - filters.addFilter(new ProjectTransitivityFilter(mavenProject.getDependencyArtifacts(), false)); - - // IMPORTANT : the following annotation must be aded to BatchMojo : @requiresDependencyResolution test - // => Include scopes compile and provided, exclude scopes test, system and runtime - filters.addFilter(new ScopeFilter("compile", "")); - Set<Artifact> artifacts = mavenProject.getArtifacts(); - artifacts = filters.filter(artifacts); - for (Artifact a : artifacts) { - bytecodeFiles.add(a.getFile()); - } + Collection<File> bytecodeFiles = projectClasspath.getElements(); + if ( !hasProjectBytecodeFiles(project)) { + File classesDir = project.getFileSystem().getBuildOutputDir(); + if (classesDir != null && classesDir.exists()) { + bytecodeFiles.remove(classesDir); } - return bytecodeFiles; - - } catch (Exception e) { - throw new SonarException(e); } + return bytecodeFiles; } private boolean hasProjectBytecodeFiles(Project project) { @@ -127,7 +95,6 @@ public class SquidSensor implements Sensor { } } return false; - } @Override |