Skip to content

Commit a0d1dfe

Browse files
author
KINAXIS\agharat
committed
Modified caching configuration, unit tests
1 parent e2f1c6d commit a0d1dfe

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

src/main/java/org/jenkinsci/plugins/workflow/libs/LibraryCachingConfiguration.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -158,37 +158,4 @@ public FormValidation doClearCache(@QueryParameter String name, @QueryParameter
158158
return FormValidation.ok("The cache dir was deleted successfully.");
159159
}
160160
}
161-
162-
/**
163-
* Method can be called from an external source to delete cache of a particular version of the shared library
164-
* Example: delete cache from through pipeline script once the build is successful
165-
* @param jenkinsLibrary Name of the shared library
166-
* @param version Name of the version to delete the cache
167-
* @throws IOException
168-
* @throws InterruptedException
169-
*/
170-
public static void deleteLibraryCacheForBranch(String jenkinsLibrary, String version) throws IOException, InterruptedException {
171-
if (LibraryCachingConfiguration.getGlobalLibrariesCacheDir().exists()) {
172-
for (FilePath libraryNamePath : LibraryCachingConfiguration.getGlobalLibrariesCacheDir().list("*-name.txt")) {
173-
String cacheName;
174-
try (InputStream stream = libraryNamePath.read()) {
175-
cacheName = IOUtils.toString(stream, StandardCharsets.UTF_8);
176-
177-
if (cacheName.equals(jenkinsLibrary)) {
178-
FilePath libraryCachePath = LibraryCachingConfiguration.getGlobalLibrariesCacheDir()
179-
.child(libraryNamePath.getName().replace("-name.txt", ""));
180-
ReentrantReadWriteLock retrieveLock = LibraryAdder.getReadWriteLockFor(libraryCachePath.getName());
181-
if (retrieveLock.writeLock().tryLock(10, TimeUnit.SECONDS)) {
182-
try {
183-
libraryCachePath.deleteRecursive();
184-
libraryNamePath.delete();
185-
} finally {
186-
retrieveLock.writeLock().unlock();
187-
}
188-
}
189-
}
190-
}
191-
}
192-
}
193-
}
194161
}

src/test/java/org/jenkinsci/plugins/workflow/libs/LibraryCachingConfigurationTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public void isExcluded() {
190190
assertFalse(substringVersionConfig.isExcluded(null));
191191
}
192192

193+
@Issue("JENKINS-69135") //"Versions to include" feature for caching
193194
@Test
194195
@WithoutJenkins
195196
public void isIncluded() {
@@ -205,6 +206,16 @@ public void isIncluded() {
205206
assertTrue(substringVersionConfig.isIncluded(SUBSTRING_INCLUDED_VERSIONS_1));
206207
assertTrue(substringVersionConfig.isIncluded(SUBSTRING_INCLUDED_VERSIONS_2));
207208

209+
assertFalse(nullVersionConfig.isIncluded(""));
210+
assertFalse(oneVersionConfig.isIncluded(""));
211+
assertFalse(multiVersionConfig.isIncluded(""));
212+
assertFalse(substringVersionConfig.isIncluded(""));
213+
214+
assertFalse(nullVersionConfig.isIncluded(null));
215+
assertFalse(oneVersionConfig.isIncluded(null));
216+
assertFalse(multiVersionConfig.isIncluded(null));
217+
assertFalse(substringVersionConfig.isIncluded(null));
218+
208219
}
209220

210221
@Test
@@ -234,6 +245,9 @@ public void clearCache() throws Exception {
234245
assertThat(new File(cache.withSuffix("-name.txt").getRemote()), not(anExistingFile()));
235246
}
236247

248+
//Test similar substrings in "Versions to include" & "Versions to exclude"
249+
//Exclusion takes precedence
250+
@Issue("JENKINS-69135") //"Versions to include" feature for caching
237251
@Test
238252
public void clearCacheConflict() throws Exception {
239253
sampleRepo.init();
@@ -255,6 +269,7 @@ public void clearCacheConflict() throws Exception {
255269
LibrariesAction action = b.getAction(LibrariesAction.class);
256270
LibraryRecord record = action.getLibraries().get(0);
257271
FilePath cache = LibraryCachingConfiguration.getGlobalLibrariesCacheDir().child(record.getDirectoryName());
272+
// Cache should not get created since the version is included in "Versions to exclude"
258273
assertThat(new File(cache.getRemote()), not(anExistingDirectory()));
259274
assertThat(new File(cache.withSuffix("-name.txt").getRemote()), not(anExistingFile()));
260275
}

0 commit comments

Comments
 (0)