Search in sources :

Example 16 with MavenArtifact

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

the class MavenUniverseFeaturePackCreatorTestCase method doInit.

@Override
protected void doInit() throws Exception {
    final MavenProducerInstaller producer1 = new MavenProducerInstaller("producer1", repo, new MavenArtifact().setGroupId("universe.producer.maven.test").setArtifactId("maven-producer1").setVersion("1.0.0.Final"), "universe.feature-pack.maven.test", "feature-pack1").addFrequencies("alpha", "beta").addChannel("1.0", "[1.0.0,2.0.0)").install();
    new MavenUniverseInstaller(repo, new MavenArtifact().setGroupId("universe.maven.test").setArtifactId("maven-universe1").setVersion("1.0.0.Final")).addProducer(producer1.getName(), producer1.getArtifact().setPath(null).setVersionRange("[1.0,2.0-alpha)")).install();
    FeaturePackCreator.getInstance().addArtifactResolver(repo).newFeaturePack().setFPID(FeaturePackLocation.fromString("producer1@" + MavenUniverseFactory.ID + "(universe.maven.test:maven-universe1:[1.0,2.0-alpha)):1.0#1.0.0.Final").getFPID()).newPackage("p1", true).writeContent("p1.txt", "p1 text").getFeaturePack().getCreator().install();
}
Also used : MavenProducerInstaller(org.jboss.galleon.universe.maven.MavenProducerInstaller) MavenUniverseInstaller(org.jboss.galleon.universe.maven.MavenUniverseInstaller) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact)

Example 17 with MavenArtifact

use of org.jboss.galleon.universe.maven.MavenArtifact in project wildfly-maven-plugin by wildfly.

the class LocalCLIExecutor method retrieveCoreVersion.

private static String retrieveCoreVersion(MavenRepoManager artifactResolver) throws Exception {
    InputStream is = LocalCLIExecutor.class.getResourceAsStream("/META-INF/maven/plugin.xml");
    if (is == null) {
        throw new MojoExecutionException("Can't retrieve plugin descriptor");
    }
    PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
    PluginDescriptor pluginDescriptor = builder.build(new InputStreamReader(is, StandardCharsets.UTF_8));
    MavenArtifact mavenArtifact = new MavenArtifact();
    mavenArtifact.setGroupId(pluginDescriptor.getGroupId());
    mavenArtifact.setArtifactId(pluginDescriptor.getArtifactId());
    mavenArtifact.setVersion(pluginDescriptor.getVersion());
    mavenArtifact.setExtension("pom");
    artifactResolver.resolve(mavenArtifact);
    Model model = readModel(mavenArtifact.getPath());
    Parent artifactParent = model.getParent();
    MavenArtifact parentArtifact = new MavenArtifact();
    parentArtifact.setGroupId(artifactParent.getGroupId());
    parentArtifact.setArtifactId(artifactParent.getArtifactId());
    parentArtifact.setVersion(artifactParent.getVersion());
    parentArtifact.setExtension("pom");
    artifactResolver.resolve(parentArtifact);
    Model parentModel = readModel(parentArtifact.getPath());
    return parentModel.getProperties().getProperty(WILDLY_CORE_VERSION_PROPERTY);
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InputStreamReader(java.io.InputStreamReader) PluginDescriptorBuilder(org.apache.maven.plugin.descriptor.PluginDescriptorBuilder) Parent(org.apache.maven.model.Parent) InputStream(java.io.InputStream) Model(org.apache.maven.model.Model) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact)

Example 18 with MavenArtifact

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

the class ProvisionStateMojo method resolveMaven.

private Path resolveMaven(ArtifactCoordinate coordinate, MavenRepoManager resolver) throws MavenUniverseException, MojoExecutionException {
    final MavenArtifact artifact = new MavenArtifact();
    artifact.setGroupId(coordinate.getGroupId());
    artifact.setArtifactId(coordinate.getArtifactId());
    String version = coordinate.getVersion();
    if (isEmptyOrNull(version)) {
        // direct dependencies may override the managed versions
        for (Artifact a : project.getArtifacts()) {
            if (coordinate.getArtifactId().equals(a.getArtifactId()) && coordinate.getGroupId().equals(a.getGroupId()) && coordinate.getExtension().equals(a.getType()) && (coordinate.getClassifier() == null ? "" : coordinate.getClassifier()).equals(a.getClassifier() == null ? "" : a.getClassifier())) {
                version = a.getVersion();
                break;
            }
        }
        if (isEmptyOrNull(version)) {
            // Now we are going to look for for among the managed dependencies
            for (Dependency d : project.getDependencyManagement().getDependencies()) {
                if (coordinate.getArtifactId().equals(d.getArtifactId()) && coordinate.getGroupId().equals(d.getGroupId()) && coordinate.getExtension().equals(d.getType()) && (coordinate.getClassifier() == null ? "" : coordinate.getClassifier()).equals(d.getClassifier() == null ? "" : d.getClassifier())) {
                    version = d.getVersion();
                    break;
                }
            }
            if (isEmptyOrNull(version)) {
                throw new MojoExecutionException(coordinate.getGroupId() + ":" + coordinate.getArtifactId() + ":" + (coordinate.getClassifier() == null ? "" : coordinate.getClassifier()) + ":" + coordinate.getExtension() + " was found among neither the project's dependencies nor the managed dependencies." + " To proceed, please, add the desired version of the feature-pack to the provisioning configuration" + " or the project dependencies, or the dependency management section of the Maven project");
            }
        }
    }
    artifact.setVersion(version);
    artifact.setExtension(coordinate.getExtension());
    artifact.setClassifier(coordinate.getClassifier());
    resolver.resolve(artifact);
    return artifact.getPath();
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Dependency(org.apache.maven.model.Dependency) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact) Artifact(org.apache.maven.artifact.Artifact)

Example 19 with MavenArtifact

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

the class AbstractMavenArtifactRepositoryManager method getAllVersions.

@Override
public List<String> getAllVersions(MavenArtifact mavenArtifact, Pattern includeVersion, Pattern excludeVersion) throws MavenUniverseException {
    Artifact artifact = new DefaultArtifact(mavenArtifact.getGroupId(), mavenArtifact.getArtifactId(), mavenArtifact.getExtension(), mavenArtifact.getVersionRange());
    VersionRangeResult rangeResult = getVersionRange(artifact);
    List<String> versions = new ArrayList<>();
    for (Version v : rangeResult.getVersions()) {
        String vString = v.toString();
        if ((includeVersion == null || includeVersion.matcher(vString).matches()) && (excludeVersion == null || !excludeVersion.matcher(vString).matches())) {
            versions.add(vString);
        }
    }
    return versions;
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) Version(org.eclipse.aether.version.Version) MavenArtifactVersion(org.jboss.galleon.universe.maven.repo.MavenArtifactVersion) ArrayList(java.util.ArrayList) MavenArtifact(org.jboss.galleon.universe.maven.MavenArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 20 with MavenArtifact

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

MavenArtifact (org.jboss.galleon.universe.maven.MavenArtifact)34 MavenProducerInstaller (org.jboss.galleon.universe.maven.MavenProducerInstaller)11 MavenUniverseInstaller (org.jboss.galleon.universe.maven.MavenUniverseInstaller)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 MavenUniverseException (org.jboss.galleon.universe.maven.MavenUniverseException)6 Path (java.nio.file.Path)5 Test (org.junit.Test)5 MavenArtifactRepositoryManager (org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager)3 HashSet (java.util.HashSet)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 ProvisioningException (org.jboss.galleon.ProvisioningException)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Artifact (org.apache.maven.artifact.Artifact)1 Dependency (org.apache.maven.model.Dependency)1 Model (org.apache.maven.model.Model)1 Parent (org.apache.maven.model.Parent)1 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)1