16
16
import java .io .File ;
17
17
import java .io .FileWriter ;
18
18
import java .io .IOException ;
19
+ import java .net .URISyntaxException ;
20
+ import java .net .URL ;
19
21
import java .util .Objects ;
20
22
21
23
/**
@@ -30,16 +32,25 @@ public NamingConventionsTask() {
30
32
final Project project = getProject ();
31
33
32
34
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
+ }
43
54
dependsOn (project .getTasks ().matching (it -> "testCompileClasspath" .equals (it .getName ())));
44
55
getInputs ().files (classpath );
45
56
@@ -111,10 +122,6 @@ public void setSuccessMarker(File successMarker) {
111
122
this .successMarker = successMarker ;
112
123
}
113
124
114
- public boolean getSkipIntegTestInDisguise () {
115
- return skipIntegTestInDisguise ;
116
- }
117
-
118
125
public boolean isSkipIntegTestInDisguise () {
119
126
return skipIntegTestInDisguise ;
120
127
}
0 commit comments