Compare commits

..

No commits in common. "341fcb9eeebcc03bf01073f91b19c005f048a8a9" and "6a03aa110a6b1d75d58b9561a7923d8dbe583074" have entirely different histories.

3 changed files with 2 additions and 88 deletions

2
core

@ -1 +1 @@
Subproject commit 1e916abfd19354a433c7686672273af2e1b1c11d
Subproject commit 44f26d9090b7093b769441256f0667640a15cc26

View file

@ -664,42 +664,7 @@ public class BaseProject extends BuildExecutor {
if (rife2Agent_ == null) {
return null;
}
var directory = libRuntimeDirectory();
var logical = rife2Agent_.toFileName();
// for a released version the on-disk name matches the dependency exactly
if (!rife2Agent_.version().isSnapshot()) {
return new File(directory, logical);
}
// snapshot artifacts keep their resolved, timestamped names on disk, so
// the logical name with the SNAPSHOT qualifier won't exist; locate the
// resolved file by matching that qualifier against the timestamp part,
// e.g. rife2-1.10.0-SNAPSHOT-agent.jar resolves to a file like
// rife2-1.10.0-20240101.120000-1-agent.jar
var marker = logical.toUpperCase().indexOf(SNAPSHOT_QUALIFIER);
if (marker >= 0) {
var prefix = logical.substring(0, marker);
var suffix = logical.substring(marker + SNAPSHOT_QUALIFIER.length());
var matches = directory.listFiles((dir, name) ->
name.length() > prefix.length() + suffix.length() &&
name.startsWith(prefix) && name.endsWith(suffix));
if (matches != null && matches.length > 0) {
// when several resolved snapshots are present, pick the most
// recent one; timestamped names sort chronologically
var latest = matches[0];
for (var candidate : matches) {
if (candidate.getName().compareTo(latest.getName()) > 0) {
latest = candidate;
}
}
return latest;
}
}
// fall back to the logical name if no resolved file could be found
return new File(directory, logical);
return new File(libRuntimeDirectory(), rife2Agent_.toFileName());
}
/**

View file

@ -324,55 +324,4 @@ class TestBaseProject {
);
}
}
@Nested
@DisplayName("getRife2AgentFile()")
class Rife2AgentFileTest {
@Test
@DisplayName("null when the agent isn't used")
void nullWhenUnused() {
assertNull(project.getRife2AgentFile());
}
@Test
@DisplayName("released version uses the exact logical name")
void releasedVersion() throws Exception {
project.useRife2Agent(project.version(1, 9, 1));
var expected = new File(project.libRuntimeDirectory(), "rife2-1.9.1-agent.jar");
Files.createFile(expected.toPath());
assertEquals(expected, project.getRife2AgentFile());
}
@Test
@DisplayName("snapshot version resolves the timestamped file, ignoring look-alikes")
void snapshotResolvesTimestamped() throws Exception {
project.useRife2Agent(project.version(1, 10, 0, "SNAPSHOT"));
var dir = project.libRuntimeDirectory();
var agent = new File(dir, "rife2-1.10.0-20240101.120000-1-agent.jar");
Files.createFile(agent.toPath());
// neither the main jar nor the agent sources jar may be picked
Files.createFile(new File(dir, "rife2-1.10.0-20240101.120000-1.jar").toPath());
Files.createFile(new File(dir, "rife2-1.10.0-20240101.120000-1-agent-sources.jar").toPath());
assertEquals(agent, project.getRife2AgentFile());
}
@Test
@DisplayName("snapshot version picks the most recent resolved file")
void snapshotPicksMostRecent() throws Exception {
project.useRife2Agent(project.version(1, 10, 0, "SNAPSHOT"));
var dir = project.libRuntimeDirectory();
Files.createFile(new File(dir, "rife2-1.10.0-20240101.120000-1-agent.jar").toPath());
var newest = new File(dir, "rife2-1.10.0-20240202.130000-1-agent.jar");
Files.createFile(newest.toPath());
assertEquals(newest, project.getRife2AgentFile());
}
@Test
@DisplayName("snapshot version falls back to the logical name when nothing is resolved")
void snapshotFallsBack() {
project.useRife2Agent(project.version(1, 10, 0, "SNAPSHOT"));
var logical = new File(project.libRuntimeDirectory(), "rife2-1.10.0-SNAPSHOT-agent.jar");
assertEquals(logical, project.getRife2AgentFile());
}
}
}