use of org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange in project galleon by wildfly.
the class MavenArtifactVersionRangeTestCase method testFromVersionExclusive.
@Test
public void testFromVersionExclusive() throws Exception {
MavenArtifactVersionRange range = parser.parseRange("(1.0,)");
Assert.assertFalse(range.includesVersion(new MavenArtifactVersion("0.5")));
Assert.assertFalse(range.includesVersion(new MavenArtifactVersion("1.0.0")));
Assert.assertTrue(range.includesVersion(new MavenArtifactVersion("1.0.1")));
}
use of org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange in project galleon by wildfly.
the class MavenArtifactVersionRangeTestCase method testUpToVersionInclusive.
@Test
public void testUpToVersionInclusive() throws Exception {
MavenArtifactVersionRange range = parser.parseRange("(,1.0]");
Assert.assertTrue(range.includesVersion(new MavenArtifactVersion("0.5")));
Assert.assertTrue(range.includesVersion(new MavenArtifactVersion("1.0.0")));
Assert.assertFalse(range.includesVersion(new MavenArtifactVersion("1.0.1")));
}
use of org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange in project galleon by wildfly.
the class MavenArtifactVersionRangeTestCase method testFromVersionInclusive.
@Test
public void testFromVersionInclusive() throws Exception {
MavenArtifactVersionRange range = parser.parseRange("[1.0,)");
Assert.assertFalse(range.includesVersion(new MavenArtifactVersion("0.5")));
Assert.assertTrue(range.includesVersion(new MavenArtifactVersion("1.0.0")));
Assert.assertTrue(range.includesVersion(new MavenArtifactVersion("1.0.1")));
}
use of org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange in project galleon by wildfly.
the class MavenArtifactVersionRangeTestCase method testExclusiveRange.
@Test
public void testExclusiveRange() throws Exception {
MavenArtifactVersionRange range = parser.parseRange("(1.2,1.3)");
Assert.assertFalse(range.includesVersion(new MavenArtifactVersion("1.2.0.Final")));
Assert.assertFalse(range.includesVersion(new MavenArtifactVersion("1.2.0.Alpha")));
Assert.assertTrue(range.includesVersion(new MavenArtifactVersion("1.2.5.Alpha")));
Assert.assertTrue(range.includesVersion(new MavenArtifactVersion("1.3.0.Alpha")));
Assert.assertFalse(range.includesVersion(new MavenArtifactVersion("1.3.0.Final")));
}
use of org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange in project galleon by wildfly.
the class AbstractMavenArtifactRepositoryManager method resolveLatestVersionDir.
private Path resolveLatestVersionDir(MavenArtifact artifact, String lowestQualifier) throws MavenUniverseException {
if (artifact.getGroupId() == null) {
MavenErrors.missingGroupId();
}
if (artifact.getArtifactId() == null) {
MavenErrors.missingArtifactId();
}
if (artifact.getVersionRange() == null) {
throw new MavenUniverseException("Version range is missing for " + artifact.getCoordsAsString());
}
Path repoHome = getSession().getLocalRepository().getBasedir().toPath();
Path artifactDir = repoHome;
final String[] groupParts = artifact.getGroupId().split("\\.");
for (String part : groupParts) {
artifactDir = artifactDir.resolve(part);
}
artifactDir = artifactDir.resolve(artifact.getArtifactId());
if (!Files.exists(artifactDir)) {
throw MavenErrors.artifactNotFound(artifact, repoHome);
}
final MavenArtifactVersionRange range = versionRangeParser.parseRange(artifact.getVersionRange());
if (lowestQualifier == null) {
lowestQualifier = "";
}
Path latestDir = null;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(artifactDir)) {
MavenArtifactVersion latest = null;
for (Path versionDir : stream) {
if (!Files.isDirectory(versionDir)) {
continue;
}
final MavenArtifactVersion next = new MavenArtifactVersion(versionDir.getFileName().toString());
if (!range.includesVersion(next) || !next.isQualifierHigher(lowestQualifier, true)) {
continue;
}
if (latest == null || latest.compareTo(next) <= 0) {
latest = next;
latestDir = versionDir;
}
}
} catch (Exception e) {
throw new MavenUniverseException("Failed to determine the latest version of " + artifact.getCoordsAsString(), e);
}
if (latestDir == null) {
throw new MavenUniverseException("Failed to determine the latest version of " + artifact.getCoordsAsString());
}
return latestDir;
}
Aggregations