Skip to content

Commit

Permalink
Reduce dependency to java-squid
Browse files Browse the repository at this point in the history
As a first step towards fixing checkstyle#40 reduce the dependency from
sonar-java-plugin to java-squid.
  • Loading branch information
marschall committed Feb 7, 2017
1 parent 8a1d8c9 commit 3441795
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
10 changes: 1 addition & 9 deletions checkstyle-sonar-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,9 @@
<!-- till https://github.com/checkstyle/sonar-checkstyle/issues/40 -->
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-java-plugin</artifactId>
<type>sonar-plugin</type>
<artifactId>java-squid</artifactId>
<version>${sonar-java.version}</version>
<scope>provided</scope>
<!-- to avoid 4.5.1 api pickup -->
<exclusions>
<exclusion>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- required to load external descriptiona, see CheckstyleRulesDefinition -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.plugins.java.api.JavaResourceLocator;
import org.sonar.java.JavaClasspath;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
Expand All @@ -48,13 +48,13 @@ public class CheckstyleExecutor implements BatchExtension {

private final CheckstyleConfiguration configuration;
private final CheckstyleAuditListener listener;
private final JavaResourceLocator javaResourceLocator;
private final JavaClasspath javaClasspath;

public CheckstyleExecutor(CheckstyleConfiguration configuration, CheckstyleAuditListener listener,
JavaResourceLocator javaResourceLocator) {
JavaClasspath javaClasspath) {
this.configuration = configuration;
this.listener = listener;
this.javaResourceLocator = javaResourceLocator;
this.javaClasspath = javaClasspath;
}

/**
Expand Down Expand Up @@ -111,7 +111,7 @@ URL getUrl(URI uri) {
}

private URLClassLoader createClassloader() {
Collection<File> classpathElements = javaResourceLocator.classpath();
Collection<File> classpathElements = javaClasspath.getElements();
List<URL> urls = Lists.newArrayList();
for (File file : classpathElements) {
urls.add(getUrl(file.toURI()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void execute() throws CheckstyleException {
CheckstyleConfiguration conf = mockConf();
CheckstyleAuditListener listener = mockListener();
CheckstyleExecutor executor =
new CheckstyleExecutor(conf, listener, createJavaResourceLocator());
new CheckstyleExecutor(conf, listener, createJavaClasspath());
executor.execute();

verify(listener, times(1)).auditStarted(any(AuditEvent.class));
Expand Down Expand Up @@ -91,7 +91,7 @@ public void executeException() throws CheckstyleException {
thrown.expectMessage("Can not execute Checkstyle");
CheckstyleConfiguration conf = mockConf();
CheckstyleExecutor executor =
new CheckstyleExecutor(conf, null, createJavaResourceLocator());
new CheckstyleExecutor(conf, null, createJavaClasspath());
executor.execute();
}

Expand All @@ -101,14 +101,14 @@ public void getUrlException() throws URISyntaxException {
thrown.expectMessage("Fail to create the project classloader. "
+ "Classpath element is invalid: htp://aa");
CheckstyleExecutor executor =
new CheckstyleExecutor(null, null, createJavaResourceLocator());
new CheckstyleExecutor(null, null, createJavaClasspath());
executor.getUrl(new URI("htp://aa"));
}

private static JavaResourceLocator createJavaResourceLocator() {
private static JavaClasspath createJavaClasspath() {
JavaClasspath javaClasspath = mock(JavaClasspath.class);
when(javaClasspath.getElements()).thenReturn(ImmutableList.of(new File(".")));
return new DefaultJavaResourceLocator(null, javaClasspath, null);
return javaClasspath;
}

@Test
Expand All @@ -122,7 +122,7 @@ public void canGenerateXmlReportInEnglish() throws CheckstyleException, IOExcept
when(conf.getTargetXmlReport()).thenReturn(report);
CheckstyleAuditListener listener = mockListener();
CheckstyleExecutor executor =
new CheckstyleExecutor(conf, listener, createJavaResourceLocator());
new CheckstyleExecutor(conf, listener, createJavaClasspath());
executor.execute();

assertThat(report.exists(), is(true));
Expand Down

0 comments on commit 3441795

Please sign in to comment.