Skip to content

Commit d1c12aa

Browse files
Daniel Muehlbachlerromani
authored andcommitted
Issues #246: update to CS 8.26
1 parent 1edf967 commit d1c12aa

File tree

6 files changed

+10
-51
lines changed

6 files changed

+10
-51
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Compatibility matrix from checkstyle team:
2121

2222
Checkstyle Plugin|Sonar min|Sonar max|Checkstyle|Jdk
2323
-----------------|---------|---------|----------|---
24+
4.26|6.7 |7.7+|8.26|1.8
2425
4.25|6.7 |7.7+|8.25|1.8
2526
4.24|6.7 |7.7+|8.24|1.8
2627
4.23|6.7 |7.7+|8.23|1.8

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
</ciManagement>
9191

9292
<properties>
93-
<checkstyle.version>8.25</checkstyle.version>
93+
<checkstyle.version>8.26</checkstyle.version>
9494
<sonar.version>6.7</sonar.version>
9595
<sonar-java.version>5.12.0.17701</sonar-java.version>
9696
<maven.checkstyle.plugin.version>2.17</maven.checkstyle.plugin.version>

src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
import java.net.MalformedURLException;
2727
import java.net.URI;
2828
import java.net.URL;
29-
import java.net.URLClassLoader;
30-
import java.util.ArrayList;
31-
import java.util.Collection;
32-
import java.util.List;
3329
import java.util.Locale;
3430
import java.util.Objects;
3531
import java.util.stream.Collectors;
@@ -42,7 +38,6 @@
4238
import org.sonar.api.batch.ScannerSide;
4339
import org.sonar.api.batch.fs.InputFile;
4440
import org.sonar.api.batch.sensor.SensorContext;
45-
import org.sonar.plugins.java.api.JavaResourceLocator;
4641

4742
import com.google.common.annotations.VisibleForTesting;
4843
import com.puppycrawl.tools.checkstyle.Checker;
@@ -59,13 +54,11 @@ public class CheckstyleExecutor {
5954

6055
private final CheckstyleConfiguration configuration;
6156
private final CheckstyleAuditListener listener;
62-
private final JavaResourceLocator javaResourceLocator;
6357

6458
public CheckstyleExecutor(CheckstyleConfiguration configuration,
65-
CheckstyleAuditListener listener, JavaResourceLocator javaResourceLocator) {
59+
CheckstyleAuditListener listener) {
6660
this.configuration = configuration;
6761
this.listener = listener;
68-
this.javaResourceLocator = javaResourceLocator;
6962
}
7063

7164
/**
@@ -81,22 +74,19 @@ public void execute(SensorContext context) {
8174
Locale.setDefault(Locale.ENGLISH);
8275
final ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
8376
Thread.currentThread().setContextClassLoader(PackageNamesLoader.class.getClassLoader());
84-
final URLClassLoader projectClassloader = createClassloader();
8577
try {
86-
executeWithClassLoader(projectClassloader);
78+
executeWithClassLoader();
8779
}
8880
finally {
8981
Thread.currentThread().setContextClassLoader(initialClassLoader);
9082
Locale.setDefault(initialLocale);
91-
close(projectClassloader);
9283
}
9384
}
9485

95-
private void executeWithClassLoader(URLClassLoader projectClassloader) {
86+
private void executeWithClassLoader() {
9687
final Checker checker = new Checker();
9788
OutputStream xmlOutput = null;
9889
try {
99-
checker.setClassLoader(projectClassloader);
10090
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
10191
checker.addListener(listener);
10292

@@ -146,14 +136,4 @@ URL getUrl(URI uri) {
146136
+ "Classpath element is invalid: " + uri, ex);
147137
}
148138
}
149-
150-
private URLClassLoader createClassloader() {
151-
final Collection<File> classpathElements = javaResourceLocator.classpath();
152-
final List<URL> urls = new ArrayList<>(classpathElements.size());
153-
for (File file : classpathElements) {
154-
urls.add(getUrl(file.toURI()));
155-
}
156-
return new URLClassLoader(urls.toArray(new URL[0]), null);
157-
}
158-
159139
}

src/main/resources/org/sonar/l10n/checkstyle.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodChec
9494
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.param.scope=visibility scope where Javadoc comments are checked
9595
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.param.excludeScope=visibility scope where Javadoc comments are not checked
9696
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.param.allowUndeclaredRTE=whether to allow documented exceptions that are not declared if they are a subclass of java.lang.RuntimeException. Default is false.
97-
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.param.suppressLoadErrors=When set to false all problems with loading classes would be reported as violations. Default is true.
9897
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.param.allowedAnnotations=List of annotations that could allow missed documentation
9998
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.param.validateThrows=Allows validating throws tags
100-
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck.param.logLoadErrors=If set to false a classpath configuration problem is assumed and the TreeWalker stops operating on the class completely. If set to true (the default) , checkstyle assumes a typo or refactoring problem in the javadoc and logs the problem in the normal checkstyle report
10199
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocBlockTagLocationCheck.name=Javadoc Block Tag Location
102100
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocBlockTagLocationCheck.param.tags=Specify the javadoc tags to process.
103101
rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck.name=Javadoc Method

src/main/resources/org/sonar/plugins/checkstyle/rules.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -856,16 +856,9 @@
856856
<param key="allowMissingReturnTag" type="BOOLEAN">
857857
<defaultValue>false</defaultValue>
858858
</param>
859-
<param key="logLoadErrors" type="BOOLEAN">
860-
<defaultValue>true</defaultValue>
861-
</param>
862859
<param key="tokens" type="s[METHOD_DEF,CTOR_DEF,ANNOTATION_FIELD_DEF]">
863860
<defaultValue>METHOD_DEF,CTOR_DEF,ANNOTATION_FIELD_DEF</defaultValue>
864861
</param>
865-
<param key="suppressLoadErrors" type="BOOLEAN">
866-
<!-- Note that default value in Checkstyle 5.5 is false -->
867-
<defaultValue>true</defaultValue>
868-
</param>
869862
<status>READY</status>
870863
</rule>
871864

src/test/java/org/sonar/plugins/checkstyle/CheckstyleExecutorTest.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
import org.sonar.api.batch.fs.internal.DefaultIndexedFile;
4848
import org.sonar.api.batch.fs.internal.DefaultInputFile;
4949
import org.sonar.api.batch.sensor.SensorContext;
50-
import org.sonar.plugins.java.api.JavaResourceLocator;
5150

52-
import com.google.common.collect.ImmutableList;
5351
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
5452
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
5553

@@ -64,8 +62,7 @@ public class CheckstyleExecutorTest {
6462
public void execute() throws CheckstyleException {
6563
final CheckstyleConfiguration conf = mockConf();
6664
final CheckstyleAuditListener listener = mockListener();
67-
final CheckstyleExecutor executor = new CheckstyleExecutor(conf, listener,
68-
createJavaResourceLocator());
65+
final CheckstyleExecutor executor = new CheckstyleExecutor(conf, listener);
6966
executor.execute(context);
7067

7168
verify(listener, times(1)).auditStarted(any(AuditEvent.class));
@@ -93,8 +90,7 @@ public void executeException() throws CheckstyleException {
9390
thrown.expect(IllegalStateException.class);
9491
thrown.expectMessage("Can not execute Checkstyle");
9592
final CheckstyleConfiguration conf = mockConf();
96-
final CheckstyleExecutor executor = new CheckstyleExecutor(conf, null,
97-
createJavaResourceLocator());
93+
final CheckstyleExecutor executor = new CheckstyleExecutor(conf, null);
9894
executor.execute(context);
9995
}
10096

@@ -103,17 +99,10 @@ public void getUrlException() throws URISyntaxException {
10399
thrown.expect(IllegalStateException.class);
104100
thrown.expectMessage("Fail to create the project classloader. "
105101
+ "Classpath element is invalid: htp://aa");
106-
final CheckstyleExecutor executor = new CheckstyleExecutor(null, mockListener(),
107-
createJavaResourceLocator());
102+
final CheckstyleExecutor executor = new CheckstyleExecutor(null, mockListener());
108103
executor.getUrl(new URI("htp://aa"));
109104
}
110105

111-
private static JavaResourceLocator createJavaResourceLocator() {
112-
final JavaResourceLocator javaResourceLocator = mock(JavaResourceLocator.class);
113-
when(javaResourceLocator.classpath()).thenReturn(ImmutableList.of(new File(".")));
114-
return javaResourceLocator;
115-
}
116-
117106
/**
118107
* We do suppression as we need to cache value initialLocale
119108
* @noinspection TooBroadScope
@@ -130,8 +119,7 @@ public void generateXmlReportInEnglish() throws Exception {
130119
report.delete();
131120
when(conf.getTargetXmlReport()).thenReturn(report);
132121
final CheckstyleAuditListener listener = mockListener();
133-
final CheckstyleExecutor executor = new CheckstyleExecutor(conf, listener,
134-
createJavaResourceLocator());
122+
final CheckstyleExecutor executor = new CheckstyleExecutor(conf, listener);
135123
executor.execute(context);
136124

137125
Assert.assertTrue("Report should exists", report.exists());
@@ -154,8 +142,7 @@ public void generateXmlReportNull() throws CheckstyleException {
154142
report.delete();
155143
when(conf.getTargetXmlReport()).thenReturn(null);
156144
final CheckstyleAuditListener listener = mockListener();
157-
final CheckstyleExecutor executor = new CheckstyleExecutor(conf, listener,
158-
createJavaResourceLocator());
145+
final CheckstyleExecutor executor = new CheckstyleExecutor(conf, listener);
159146
executor.execute(context);
160147

161148
Assert.assertFalse("Report should NOT exists", report.exists());

0 commit comments

Comments
 (0)