1616import java .io .File ;
1717import java .io .FileWriter ;
1818import java .io .IOException ;
19+ import java .net .URISyntaxException ;
20+ import java .net .URL ;
1921import java .util .Objects ;
2022
2123/**
@@ -30,16 +32,25 @@ public NamingConventionsTask() {
3032 final Project project = getProject ();
3133
3234 SourceSetContainer sourceSets = getJavaSourceSets ();
33- final FileCollection classpath = project .files (
34- // This works because the class only depends on one class from junit that will be available from the
35- // tests compile classpath. It's the most straight forward way of telling Java where to find the main
36- // class.
37- NamingConventionsCheck .class .getProtectionDomain ().getCodeSource ().getLocation ().getPath (),
38- // the tests to be loaded
39- checkForTestsInMain ? sourceSets .getByName ("main" ).getRuntimeClasspath () : project .files (),
40- sourceSets .getByName ("test" ).getCompileClasspath (),
41- sourceSets .getByName ("test" ).getOutput ()
42- );
35+ final FileCollection classpath ;
36+ try {
37+ URL location = NamingConventionsCheck .class .getProtectionDomain ().getCodeSource ().getLocation ();
38+ if (location .getProtocol ().equals ("file" ) == false ) {
39+ throw new GradleException ("Unexpected location for NamingConventionCheck class: " + location );
40+ }
41+ classpath = project .files (
42+ // This works because the class only depends on one class from junit that will be available from the
43+ // tests compile classpath. It's the most straight forward way of telling Java where to find the main
44+ // class.
45+ location .toURI ().getPath (),
46+ // the tests to be loaded
47+ checkForTestsInMain ? sourceSets .getByName ("main" ).getRuntimeClasspath () : project .files (),
48+ sourceSets .getByName ("test" ).getCompileClasspath (),
49+ sourceSets .getByName ("test" ).getOutput ()
50+ );
51+ } catch (URISyntaxException e ) {
52+ throw new AssertionError (e );
53+ }
4354 dependsOn (project .getTasks ().matching (it -> "testCompileClasspath" .equals (it .getName ())));
4455 getInputs ().files (classpath );
4556
@@ -111,10 +122,6 @@ public void setSuccessMarker(File successMarker) {
111122 this .successMarker = successMarker ;
112123 }
113124
114- public boolean getSkipIntegTestInDisguise () {
115- return skipIntegTestInDisguise ;
116- }
117-
118125 public boolean isSkipIntegTestInDisguise () {
119126 return skipIntegTestInDisguise ;
120127 }
0 commit comments