Search in sources :

Example 1 with MavenArtifactVersionRange

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")));
}
Also used : MavenArtifactVersion(org.jboss.galleon.universe.maven.repo.MavenArtifactVersion) MavenArtifactVersionRange(org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange) Test(org.junit.Test)

Example 2 with MavenArtifactVersionRange

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")));
}
Also used : MavenArtifactVersion(org.jboss.galleon.universe.maven.repo.MavenArtifactVersion) MavenArtifactVersionRange(org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange) Test(org.junit.Test)

Example 3 with MavenArtifactVersionRange

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")));
}
Also used : MavenArtifactVersion(org.jboss.galleon.universe.maven.repo.MavenArtifactVersion) MavenArtifactVersionRange(org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange) Test(org.junit.Test)

Example 4 with MavenArtifactVersionRange

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")));
}
Also used : MavenArtifactVersion(org.jboss.galleon.universe.maven.repo.MavenArtifactVersion) MavenArtifactVersionRange(org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange) Test(org.junit.Test)

Example 5 with MavenArtifactVersionRange

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;
}
Also used : Path(java.nio.file.Path) MavenArtifactVersion(org.jboss.galleon.universe.maven.repo.MavenArtifactVersion) MavenArtifactVersionRange(org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) InstallationException(org.eclipse.aether.installation.InstallationException) MavenLatestVersionNotAvailableException(org.jboss.galleon.universe.maven.MavenLatestVersionNotAvailableException)

Aggregations

MavenArtifactVersion (org.jboss.galleon.universe.maven.repo.MavenArtifactVersion)10 MavenArtifactVersionRange (org.jboss.galleon.universe.maven.repo.MavenArtifactVersionRange)10 Test (org.junit.Test)9 Path (java.nio.file.Path)1 InstallationException (org.eclipse.aether.installation.InstallationException)1 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)1 MavenLatestVersionNotAvailableException (org.jboss.galleon.universe.maven.MavenLatestVersionNotAvailableException)1 MavenUniverseException (org.jboss.galleon.universe.maven.MavenUniverseException)1