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);
}
}
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());
}
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());
}
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;
}
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());
}
Aggregations