@@ -19,31 +19,12 @@ settingsEvaluated { Settings settings ->
19
19
}
20
20
21
21
if (remoteBuildCacheType) {
22
- if (! [' develocity' , ' gradle-enterprise' , ' http' ]. contains(remoteBuildCacheType)) {
23
- // The scripts already fail if the value of --remote-build-cache-type isn't valid.
24
- // This is for the sake of completeness since this init script assumes it's valid.
25
- def errorFile = new File (expDir, ' errors.txt' )
26
- def message = " Invalid value '${ remoteBuildCacheType} ' for remote build cache type. Values are 'develocity', 'gradle-enterprise', or 'http'."
27
- errorFile. text = message
28
- throw new IllegalStateException (message)
22
+ if (isInvalidRemoteBuildCacheType(remoteBuildCacheType)) {
23
+ failInvalidRemoteBuildCacheType(remoteBuildCacheType, expDir)
29
24
}
30
25
31
26
if (isTopLevelBuild && missingRequiredPlugin(settings, remoteBuildCacheType)) {
32
- // Included builds may not have the necessary plugin applied.
33
- // Only fail if the top-level build is missing the required extension.
34
- def errorFile = new File (expDir, ' errors.txt' )
35
- errorFile. text = " Remote build cache type '${ remoteBuildCacheType} ' requested, but the required plugin is not applied."
36
- if (remoteBuildCacheType == ' develocity' ) {
37
- throw new IllegalStateException (" Remote build cache type 'develocity' requested,\n " +
38
- " but the Develocity Gradle plugin is not applied.\n " +
39
- " Either apply it directly (see $docsRoot /current/#applying_the_plugin),\n " +
40
- " use --enable-develocity to enable the plugin,\n " +
41
- " or use --remote-build-cache-type to choose a different remote build cache type\n " +
42
- " when running the build validation script." )
43
- } else {
44
- throw new IllegalStateException (" Remote build cache type 'gradle-enterprise' requested,\n " +
45
- " but the Gradle Enterprise Gradle plugin is not applied (see $docsRoot /legacy/#applying_the_plugin)." )
46
- }
27
+ failMissingRequiredPlugin(remoteBuildCacheType, expDir, docsRoot)
47
28
}
48
29
49
30
def remoteBuildCacheImplementation = getRemoteBuildCacheImplementation(settings, remoteBuildCacheType)
@@ -64,30 +45,24 @@ settingsEvaluated { Settings settings ->
64
45
if (remoteBuildCacheUrl) {
65
46
remote. url = remoteBuildCacheUri
66
47
} else if (! remote. url) {
67
- // Gradle already fails in this case, but handling it here means we can fail the experiment more
68
- // gracefully and provide guidance the user.
69
- def errorFile = new File (expDir, ' errors.txt' )
70
- errorFile. text = ' A remote build cache URL has not been configured in the project or on the command line.'
71
- throw new IllegalStateException (" A remote build cache URL is not configured.\n "
72
- + " Either configure it directly (see $docsRoot /current/#using_gradles_built_in_http_connector) in the project,\n "
73
- + " or use --remote-build-cache-url when running the build validation script." )
48
+ failMissingUrlForHttpBuildCache(expDir, docsRoot)
74
49
}
75
- } else if (remote . class . name . startsWith( ' com.gradle.develocity' ) || remote . class . name . startsWith( ' com.gradle.enterprise' )) {
50
+ } else if (isBuildCacheImplementationFor(remote, ' com.gradle.develocity' ) || isBuildCacheImplementationFor(remote, ' com.gradle.enterprise' )) {
76
51
if (remoteBuildCacheUri) {
77
52
remote. server = toServerPart(remoteBuildCacheUri)
78
53
remote. path = remoteBuildCacheUri. path
79
54
}
80
55
}
81
56
} else if (isTopLevelBuild) {
82
- def errorFile = new File (expDir, ' errors.txt' )
83
- errorFile. text = " Remote build cache is not configured for the project."
84
- throw new IllegalStateException (" Remote build cache is not configured for the project.\n " +
85
- " Either configure it directly (see $docsRoot /current/#using_the_develocity_connector),\n " +
86
- " or use --remote-build-cache-type when running the build validation script." )
57
+ failMissingRemoteBuildCacheConfiguration(expDir, docsRoot)
87
58
}
88
59
}
89
60
}
90
61
62
+ static boolean isInvalidRemoteBuildCacheType (String remoteBuildCacheType ) {
63
+ return ! [' develocity' , ' gradle-enterprise' , ' http' ]. contains(remoteBuildCacheType)
64
+ }
65
+
91
66
static boolean missingRequiredPlugin (Settings settings , String type ) {
92
67
return type == " develocity" && ! settings. pluginManager. hasPlugin(' com.gradle.develocity' )
93
68
|| type == " gradle-enterprise" && ! settings. pluginManager. hasPlugin(' com.gradle.enterprise' )
@@ -104,10 +79,59 @@ static Class<? extends BuildCache> getRemoteBuildCacheImplementation(Settings se
104
79
return null
105
80
}
106
81
82
+ static boolean isBuildCacheImplementationFor (BuildCache buildCache , String implementation ) {
83
+ return buildCache. class. name. startsWith(implementation)
84
+ }
85
+
107
86
static URI withPathTrailingSlash (URI uri ) {
108
87
return uri. path. endsWith(" /" ) ? uri : new URI (uri. scheme, uri. userInfo, uri. host, uri. port, uri. path + " /" , uri. query, uri. fragment)
109
88
}
110
89
111
90
static String toServerPart (URI uri ) {
112
91
return new URI (uri. scheme, uri. userInfo, uri. host, uri. port, null , uri. query, uri. fragment)
113
92
}
93
+
94
+ // The scripts already fail if the value of --remote-build-cache-type isn't valid.
95
+ // This is for the sake of completeness since this init script assumes it's valid.
96
+ static void failInvalidRemoteBuildCacheType (String remoteBuildCacheType , String expDir ) {
97
+ def errorFile = new File (expDir, ' errors.txt' )
98
+ def message = " Invalid value '${ remoteBuildCacheType} ' for remote build cache type. Values are 'develocity', 'gradle-enterprise', or 'http'."
99
+ errorFile. text = message
100
+ throw new IllegalStateException (message)
101
+ }
102
+
103
+ // Included builds may not have the necessary plugin applied.
104
+ // Only fail if the top-level build is missing the required extension.
105
+ static void failMissingRequiredPlugin (String remoteBuildCacheType , String expDir , String docsRoot ) {
106
+ def errorFile = new File (expDir, ' errors.txt' )
107
+ errorFile. text = " Remote build cache type '${ remoteBuildCacheType} ' requested, but the required plugin is not applied."
108
+ if (remoteBuildCacheType == ' develocity' ) {
109
+ throw new IllegalStateException (" Remote build cache type 'develocity' requested,\n " +
110
+ " but the Develocity Gradle plugin is not applied.\n " +
111
+ " Either apply it directly (see $docsRoot /current/#applying_the_plugin),\n " +
112
+ " use --enable-develocity to enable the plugin,\n " +
113
+ " or use --remote-build-cache-type to choose a different remote build cache type\n " +
114
+ " when running the build validation script." )
115
+ } else {
116
+ throw new IllegalStateException (" Remote build cache type 'gradle-enterprise' requested,\n " +
117
+ " but the Gradle Enterprise Gradle plugin is not applied (see $docsRoot /legacy/#applying_the_plugin)." )
118
+ }
119
+ }
120
+
121
+ // Gradle already fails in this case, but handling it here means we can fail the experiment more
122
+ // gracefully and provide guidance the user.
123
+ static void failMissingUrlForHttpBuildCache (String expDir , String docsRoot ) {
124
+ def errorFile = new File (expDir, ' errors.txt' )
125
+ errorFile. text = ' A remote build cache URL has not been configured in the project or on the command line.'
126
+ throw new IllegalStateException (" A remote build cache URL is not configured.\n "
127
+ + " Either configure it directly (see $docsRoot /current/#using_gradles_built_in_http_connector) in the project,\n "
128
+ + " or use --remote-build-cache-url when running the build validation script." )
129
+ }
130
+
131
+ static void failMissingRemoteBuildCacheConfiguration (String expDir , String docsRoot ) {
132
+ def errorFile = new File (expDir, ' errors.txt' )
133
+ errorFile. text = " Remote build cache is not configured for the project."
134
+ throw new IllegalStateException (" Remote build cache is not configured for the project.\n " +
135
+ " Either configure it directly (see $docsRoot /current/#using_the_develocity_connector),\n " +
136
+ " or use --remote-build-cache-type when running the build validation script." )
137
+ }
0 commit comments