Search in sources :

Example 6 with MavenUniverseException

use of org.jboss.galleon.universe.maven.MavenUniverseException in project galleon by wildfly.

the class SimplisticMavenRepoManager method resolve.

@Override
public void resolve(MavenArtifact artifact) throws MavenUniverseException {
    if (artifact.isResolved()) {
        throw new MavenUniverseException("Artifact is already resolved");
    }
    Path path = null;
    try {
        path = getArtifactPath(artifact);
        if (!Files.exists(path)) {
            throw new MavenUniverseException(pathDoesNotExist(artifact, path));
        }
        artifact.setPath(path);
        return;
    } catch (MavenUniverseException e) {
        if (fallback == null) {
            throw e;
        }
    }
    try {
        fallback.resolve(artifact);
    } catch (MavenUniverseException e) {
        throw new MavenUniverseException(pathDoesNotExist(artifact, path), e);
    }
}
Also used : Path(java.nio.file.Path) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException)

Example 7 with MavenUniverseException

use of org.jboss.galleon.universe.maven.MavenUniverseException in project galleon by wildfly.

the class MavenProducerInstallTestCase method testMain.

@Test
public void testMain() throws Exception {
    final String fpGroupId = "fp-group1";
    final String fpArtifactId = "fp-artifact1";
    final MavenProducerInstaller producerInstaller = new MavenProducerInstaller("producer1", repo, producerArtifact, fpGroupId, fpArtifactId);
    producerInstaller.addFrequencies("alpha", "beta");
    producerInstaller.addChannel("1.0", "[1.0.0,2.0.0)");
    producerInstaller.addChannel("2.0", "[2.0.0,3.0.0)", false, ".*-ext-[0-9][0-9]", ".*-ext-11");
    producerInstaller.install();
    producerArtifact.setPath(null);
    MavenProducer producer = new MavenProducer("producer1", repo, producerArtifact);
    Assert.assertEquals(fpGroupId, producer.getFeaturePackGroupId());
    Assert.assertEquals(fpArtifactId, producer.getFeaturePackArtifactId());
    Collection<String> frequencies = producer.getFrequencies();
    Assert.assertEquals(3, frequencies.size());
    Assert.assertTrue(frequencies.contains("alpha"));
    Assert.assertTrue(frequencies.contains("beta"));
    Assert.assertTrue(frequencies.contains("final"));
    Assert.assertTrue(producer.hasChannel("1.0"));
    MavenChannel channel = producer.getChannel("1.0");
    Assert.assertEquals(fpGroupId, channel.getFeaturePackGroupId());
    Assert.assertEquals(fpArtifactId, channel.getFeaturePackArtifactId());
    Assert.assertEquals("[1.0.0,2.0.0)", channel.getVersionRange());
    frequencies = channel.getFrequencies();
    Assert.assertEquals(3, frequencies.size());
    Assert.assertTrue(frequencies.contains("alpha"));
    Assert.assertTrue(frequencies.contains("beta"));
    Assert.assertTrue(frequencies.contains("final"));
    channel = producer.getChannel("2.0");
    Assert.assertEquals(fpGroupId, channel.getFeaturePackGroupId());
    Assert.assertEquals(fpArtifactId, channel.getFeaturePackArtifactId());
    Assert.assertEquals("[2.0.0,3.0.0)", channel.getVersionRange());
    Assert.assertEquals(".*-ext-[0-9][0-9]", channel.getVersionIncludeRegex());
    Assert.assertEquals(".*-ext-11", channel.getVersionExcludeRegex());
    frequencies = channel.getFrequencies();
    Assert.assertEquals(3, frequencies.size());
    Assert.assertTrue(frequencies.contains("alpha"));
    Assert.assertTrue(frequencies.contains("beta"));
    Assert.assertTrue(frequencies.contains("final"));
    Assert.assertTrue(producer.hasChannel("2.0"));
    Assert.assertFalse(producer.hasChannel("3.0"));
    try {
        producer.getChannel("3.0");
    } catch (MavenUniverseException e) {
        Assert.assertEquals(MavenErrors.channelNotFound(producer.getName(), "3.0").getLocalizedMessage(), e.getLocalizedMessage());
    }
    Assert.assertEquals(2, producer.getChannels().size());
}
Also used : MavenProducerInstaller(org.jboss.galleon.universe.maven.MavenProducerInstaller) MavenProducer(org.jboss.galleon.universe.maven.MavenProducer) MavenChannel(org.jboss.galleon.universe.maven.MavenChannel) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) Test(org.junit.Test)

Example 8 with MavenUniverseException

use of org.jboss.galleon.universe.maven.MavenUniverseException in project galleon by wildfly.

the class MavenUniverseInstallTestCase method testMain.

@Test
public void testMain() throws Exception {
    final MavenUniverseInstaller universeInstaller = new MavenUniverseInstaller(repo, universeArtifact);
    universeInstaller.addProducer("producer1", GROUP_ID, "producer1", "[1.0.0,2.0.0)");
    universeInstaller.addProducer("producer2", GROUP_ID, "producer2", "[3.0.0,4.0.0)");
    universeInstaller.install();
    universeArtifact.setPath(null);
    final MavenUniverse universe = new MavenUniverse(repo, universeArtifact);
    Assert.assertTrue(universe.hasProducer("producer1"));
    MavenProducer producer = universe.getProducer("producer1");
    Assert.assertEquals(GROUP_ID, producer.getArtifact().getGroupId());
    Assert.assertEquals("producer1", producer.getArtifact().getArtifactId());
    Assert.assertEquals("[1.0.0,2.0.0)", producer.getArtifact().getVersionRange());
    producer = universe.getProducer("producer2");
    Assert.assertEquals(GROUP_ID, producer.getArtifact().getGroupId());
    Assert.assertEquals("producer2", producer.getArtifact().getArtifactId());
    Assert.assertEquals("[3.0.0,4.0.0)", producer.getArtifact().getVersionRange());
    Assert.assertTrue(universe.hasProducer("producer2"));
    Assert.assertFalse(universe.hasProducer("producerN"));
    try {
        universe.getProducer("producerN");
    } catch (MavenUniverseException e) {
        Assert.assertEquals(MavenErrors.producerNotFound("producerN").getLocalizedMessage(), e.getLocalizedMessage());
    }
    Assert.assertEquals(2, universe.getProducers().size());
}
Also used : MavenUniverse(org.jboss.galleon.universe.maven.MavenUniverse) MavenUniverseInstaller(org.jboss.galleon.universe.maven.MavenUniverseInstaller) MavenProducer(org.jboss.galleon.universe.maven.MavenProducer) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) Test(org.junit.Test)

Example 9 with MavenUniverseException

use of org.jboss.galleon.universe.maven.MavenUniverseException 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)

Example 10 with MavenUniverseException

use of org.jboss.galleon.universe.maven.MavenUniverseException in project galleon by wildfly.

the class CreateProducerMojo method createProducer.

private void createProducer() throws MavenUniverseException, MojoExecutionException {
    final MavenArtifact producerArtifact = new MavenArtifact().setGroupId(groupId).setArtifactId(artifactId).setVersion(version);
    final MavenProducerInstaller installer = new MavenProducerInstaller(name, SimplisticMavenRepoManager.getInstance(Paths.get(project.getBuild().getDirectory()).resolve("local-repo"), new MavenArtifactRepositoryManager(repoSystem, repoSession, repositories)), producerArtifact, featurePackGroupId, featurePackArtifactId);
    for (String frequency : frequencies) {
        installer.addFrequency(frequency);
    }
    final Set<String> names = new HashSet<>(channels.size());
    for (ChannelDescription channel : channels) {
        if (!names.add(channel.name)) {
            throw new MojoExecutionException("Duplicate channel " + channel.name);
        }
        try {
            installer.addChannel(channel.name, channel.versionRange);
        } catch (MavenUniverseException e) {
            throw new MojoExecutionException("Failed to add channel " + channel.name, e);
        }
    }
    try {
        installer.install();
    } catch (MavenUniverseException e) {
        throw new MojoExecutionException("Failed to create producer", e);
    }
    projectHelper.attachArtifact(project, "jar", producerArtifact.getPath().toFile());
}
Also used : MavenProducerInstaller(org.jboss.galleon.universe.maven.MavenProducerInstaller) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenArtifactRepositoryManager(org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) HashSet(java.util.HashSet)

Aggregations

MavenUniverseException (org.jboss.galleon.universe.maven.MavenUniverseException)16 Path (java.nio.file.Path)6 MavenArtifact (org.jboss.galleon.universe.maven.MavenArtifact)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 InstallationException (org.eclipse.aether.installation.InstallationException)3 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)3 MavenArtifactRepositoryManager (org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager)3 MavenLatestVersionNotAvailableException (org.jboss.galleon.universe.maven.MavenLatestVersionNotAvailableException)3 MavenProducer (org.jboss.galleon.universe.maven.MavenProducer)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)2 MavenProducerInstaller (org.jboss.galleon.universe.maven.MavenProducerInstaller)2 MavenUniverseInstaller (org.jboss.galleon.universe.maven.MavenUniverseInstaller)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 InstallRequest (org.eclipse.aether.installation.InstallRequest)1 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)1