89
89
if (action != null ) {
90
90
// Resuming a build, so just look up what we loaded before.
91
91
for (LibraryRecord record : action .getLibraries ()) {
92
- FilePath libDir = new FilePath (execution .getOwner ().getRootDir ()).child ("libs/" + record .name );
92
+ FilePath libDir = new FilePath (execution .getOwner ().getRootDir ()).child ("libs/" + record .getDirectoryName () );
93
93
for (String root : new String [] {"src" , "vars" }) {
94
94
FilePath dir = libDir .child (root );
95
95
if (dir .isDirectory ()) {
120
120
}
121
121
String version = cfg .defaultedVersion (libraryVersions .remove (name ));
122
122
Boolean changelog = cfg .defaultedChangelogs (libraryChangelogs .remove (name ));
123
- librariesAdded .put (name , new LibraryRecord (name , version , kindTrusted , changelog , cfg .getCachingConfiguration ()));
123
+ String source = kind .getClass ().getName ();
124
+ if (cfg instanceof LibraryResolver .ResolvedLibraryConfiguration ) {
125
+ source = ((LibraryResolver .ResolvedLibraryConfiguration ) cfg ).getSource ();
126
+ }
127
+ librariesAdded .put (name , new LibraryRecord (name , version , kindTrusted , changelog , cfg .getCachingConfiguration (), source ));
124
128
retrievers .put (name , cfg .getRetriever ());
125
129
}
126
130
}
135
139
// Now actually try to retrieve the libraries.
136
140
for (LibraryRecord record : librariesAdded .values ()) {
137
141
listener .getLogger ().println ("Loading library " + record .name + "@" + record .version );
138
- for (URL u : retrieve (record . name , record . version , retrievers .get (record .name ), record . trusted , record . changelog , record . cachingConfiguration , listener , build , execution , record . variables )) {
142
+ for (URL u : retrieve (record , retrievers .get (record .name ), listener , build , execution )) {
139
143
additions .add (new Addition (u , record .trusted ));
140
144
}
141
145
}
152
156
}
153
157
154
158
/** Retrieve library files. */
155
- static List <URL > retrieve (@ NonNull String name , @ NonNull String version , @ NonNull LibraryRetriever retriever , boolean trusted , Boolean changelog , LibraryCachingConfiguration cachingConfiguration , @ NonNull TaskListener listener , @ NonNull Run <?,?> run , @ NonNull CpsFlowExecution execution , @ NonNull Set <String > variables ) throws Exception {
156
- FilePath libDir = new FilePath (execution .getOwner ().getRootDir ()).child ("libs/" + name );
159
+ static List <URL > retrieve (@ NonNull LibraryRecord record , @ NonNull LibraryRetriever retriever , @ NonNull TaskListener listener , @ NonNull Run <?,?> run , @ NonNull CpsFlowExecution execution ) throws Exception {
160
+ String name = record .name ;
161
+ String version = record .version ;
162
+ boolean changelog = record .changelog ;
163
+ LibraryCachingConfiguration cachingConfiguration = record .cachingConfiguration ;
164
+ FilePath libDir = new FilePath (execution .getOwner ().getRootDir ()).child ("libs/" + record .getDirectoryName ());
157
165
Boolean shouldCache = cachingConfiguration != null ;
158
- final FilePath libraryCacheDir = new FilePath (LibraryCachingConfiguration .getGlobalLibrariesCacheDir (), name );
159
- final FilePath versionCacheDir = new FilePath (libraryCacheDir , version );
166
+ final FilePath versionCacheDir = new FilePath (LibraryCachingConfiguration .getGlobalLibrariesCacheDir (), record .getDirectoryName ());
160
167
final FilePath retrieveLockFile = new FilePath (versionCacheDir , LibraryCachingConfiguration .RETRIEVE_LOCK_FILE );
161
168
final FilePath lastReadFile = new FilePath (versionCacheDir , LibraryCachingConfiguration .LAST_READ_FILE );
162
169
@@ -195,9 +202,11 @@ static List<URL> retrieve(@NonNull String name, @NonNull String version, @NonNul
195
202
} else {
196
203
retriever .retrieve (name , version , changelog , libDir , run , listener );
197
204
}
205
+ // Write the user-provided name to a file as a debugging aid.
206
+ libDir .withSuffix ("-name.txt" ).write (name , "UTF-8" );
198
207
199
208
// Replace any classes requested for replay:
200
- if (!trusted ) {
209
+ if (!record . trusted ) {
201
210
for (String clazz : ReplayAction .replacementsIn (execution )) {
202
211
for (String root : new String [] {"src" , "vars" }) {
203
212
String rel = root + "/" + clazz .replace ('.' , '/' ) + ".groovy" ;
@@ -221,7 +230,7 @@ static List<URL> retrieve(@NonNull String name, @NonNull String version, @NonNul
221
230
if (varsDir .isDirectory ()) {
222
231
urls .add (varsDir .toURI ().toURL ());
223
232
for (FilePath var : varsDir .list ("*.groovy" )) {
224
- variables .add (var .getBaseName ());
233
+ record . variables .add (var .getBaseName ());
225
234
}
226
235
}
227
236
if (urls .isEmpty ()) {
@@ -245,8 +254,11 @@ static List<URL> retrieve(@NonNull String name, @NonNull String version, @NonNul
245
254
if (action != null ) {
246
255
FilePath libs = new FilePath (run .getRootDir ()).child ("libs" );
247
256
for (LibraryRecord library : action .getLibraries ()) {
248
- FilePath f = libs .child (library .name + "/resources/" + name );
249
- if (f .exists ()) {
257
+ FilePath libResources = libs .child (library .getDirectoryName () + "/resources/" );
258
+ FilePath f = libResources .child (name );
259
+ if (!new File (f .getRemote ()).getCanonicalFile ().toPath ().startsWith (libResources .absolutize ().getRemote ())) {
260
+ throw new AbortException (name + " references a file that is not contained within the library: " + library .name );
261
+ } else if (f .exists ()) {
250
262
resources .put (library .name , readResource (f , encoding ));
251
263
}
252
264
}
@@ -278,7 +290,7 @@ private static String readResource(FilePath file, @CheckForNull String encoding)
278
290
List <GlobalVariable > vars = new ArrayList <>();
279
291
for (LibraryRecord library : action .getLibraries ()) {
280
292
for (String variable : library .variables ) {
281
- vars .add (new UserDefinedGlobalVariable (variable , new File (run .getRootDir (), "libs/" + library .name + "/vars/" + variable + ".txt" )));
293
+ vars .add (new UserDefinedGlobalVariable (variable , new File (run .getRootDir (), "libs/" + library .getDirectoryName () + "/vars/" + variable + ".txt" )));
282
294
}
283
295
}
284
296
return vars ;
@@ -304,7 +316,7 @@ private static String readResource(FilePath file, @CheckForNull String encoding)
304
316
continue ; // TODO JENKINS-41157 allow replay of trusted libraries if you have ADMINISTER
305
317
}
306
318
for (String rootName : new String [] {"src" , "vars" }) {
307
- FilePath root = libs .child (library .name + "/" + rootName );
319
+ FilePath root = libs .child (library .getDirectoryName () + "/" + rootName );
308
320
if (!root .isDirectory ()) {
309
321
continue ;
310
322
}
0 commit comments