Search in sources :

Example 11 with Version

use of org.eclipse.aether.version.Version in project drools by kiegroup.

the class MavenRepository method resolveArtifact.

public Artifact resolveArtifact(ReleaseId releaseId) {
    String artifactName = releaseId.toString();
    if (DependencyDescriptor.isRangedVersion(releaseId.getVersion())) {
        Version v = resolveVersion(artifactName);
        if (v == null) {
            return null;
        }
        artifactName = releaseId.getGroupId() + ":" + releaseId.getArtifactId() + ":" + v;
    }
    return resolveArtifact(artifactName);
}
Also used : Version(org.eclipse.aether.version.Version)

Example 12 with Version

use of org.eclipse.aether.version.Version in project BIMserver by opensourceBIM.

the class MavenPluginLocation method iterateAllVersions.

public Iterator<MavenPluginVersion> iterateAllVersions() {
    Artifact artifact = new DefaultArtifact(groupId, artifactId, null, "[0,)");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
    try {
        VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
        List<Version> versions = rangeResult.getVersions();
        if (!versions.isEmpty()) {
            Iterator<Version> versionIterator = Lists.reverse(versions).iterator();
            return Iterators.transform(versionIterator, new Function<Version, MavenPluginVersion>() {

                @Override
                public MavenPluginVersion apply(Version version) {
                    try {
                        MavenPluginVersion mavenPluginVersion = createMavenVersion(version);
                        return mavenPluginVersion;
                    } catch (ArtifactDescriptorException | ArtifactResolutionException | IOException | XmlPullParserException e) {
                        LOGGER.error("", e);
                    }
                    return null;
                }
            });
        }
    } catch (VersionRangeResolutionException e) {
        LOGGER.error("", e);
    }
    return Collections.emptyIterator();
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.eclipse.aether.version.Version) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 13 with Version

use of org.eclipse.aether.version.Version in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getAllVersions.

@Override
public List<MavenPluginVersion> getAllVersions() {
    List<MavenPluginVersion> pluginVersions = new ArrayList<>();
    Artifact artifact = new DefaultArtifact(groupId, artifactId, null, "[0,)");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
    // RemoteRepository centralRepo = newCentralRepository();
    try {
        VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
        List<Version> versions = rangeResult.getVersions();
        if (!versions.isEmpty()) {
            for (int i = versions.size() - 1; i >= Math.max(0, versions.size() - 3); i--) {
                Version version = versions.get(i);
                ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
                Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
                descriptorRequest.setArtifact(versionArtifact);
                descriptorRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
                MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
                ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
                ArtifactRequest request = new ArtifactRequest();
                request.setArtifact(descriptorResult.getArtifact());
                request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
                ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
                File pomFile = resolveArtifact.getArtifact().getFile();
                MavenXpp3Reader mavenreader = new MavenXpp3Reader();
                try (FileReader fileReader = new FileReader(pomFile)) {
                    Model model = mavenreader.read(fileReader);
                    mavenPluginVersion.setModel(model);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                }
                for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
                    DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
                    mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
                }
                pluginVersions.add(0, mavenPluginVersion);
            }
        }
    } catch (VersionRangeResolutionException e) {
        e.printStackTrace();
    } catch (ArtifactDescriptorException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return pluginVersions;
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.eclipse.aether.version.Version) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Model(org.apache.maven.model.Model) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) File(java.io.File) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 14 with Version

use of org.eclipse.aether.version.Version in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getLatestVersion.

public MavenPluginVersion getLatestVersion() {
    Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":LATEST");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    try {
        VersionRangeResult rangeResult = mavenPluginRepository.getSystem().resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
        List<Version> versions = rangeResult.getVersions();
        if (!versions.isEmpty()) {
            Version version = versions.get(0);
            ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
            Artifact versionArtifact = new DefaultArtifact(groupId + ":" + artifactId + ":pom:" + version.toString());
            descriptorRequest.setArtifact(versionArtifact);
            MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
            ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
            ArtifactRequest request = new ArtifactRequest();
            request.setArtifact(descriptorResult.getArtifact());
            ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
            File pomFile = resolveArtifact.getArtifact().getFile();
            MavenXpp3Reader mavenreader = new MavenXpp3Reader();
            try (FileReader fileReader = new FileReader(pomFile)) {
                try {
                    Model model = mavenreader.read(fileReader);
                    mavenPluginVersion.setModel(model);
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                }
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
                DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
                mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
            }
            return mavenPluginVersion;
        }
    } catch (VersionRangeResolutionException e) {
        e.printStackTrace();
    } catch (ArtifactDescriptorException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Version(org.eclipse.aether.version.Version) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) IOException(java.io.IOException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Model(org.apache.maven.model.Model) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) File(java.io.File) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 15 with Version

use of org.eclipse.aether.version.Version in project acceptance-test-harness by jenkinsci.

the class LocalOverrideUpdateCenterMetadataDecoratorImpl method decorate.

@Override
public void decorate(UpdateCenterMetadata ucm) {
    if ("true".equals(System.getenv("LOCAL_SNAPSHOTS"))) {
        File userHome = new File(System.getProperty("user.home"));
        File localRepo = MavenLocalRepository.getMavenLocalRepository();
        VersionScheme versionScheme = new GenericVersionScheme();
        for (Iterator<Map.Entry<String, PluginMetadata>> it = ucm.plugins.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<String, PluginMetadata> entry = it.next();
            DefaultArtifact artifact = entry.getValue().getDefaultArtifact();
            File artifactDir = new File(new File(localRepo, artifact.getGroupId().replace('.', File.separatorChar)), artifact.getArtifactId());
            File metadata = new File(artifactDir, "maven-metadata-local.xml");
            if (metadata.isFile()) {
                try {
                    Version ucVersion = versionScheme.parseVersion(artifact.getVersion());
                    NodeList versions = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(metadata).getElementsByTagName("version");
                    for (int i = 0; i < versions.getLength(); i++) {
                        String version = versions.item(i).getTextContent();
                        if (version.endsWith("-SNAPSHOT") && versionScheme.parseVersion(version).compareTo(ucVersion) > 0) {
                            File hpi = new File(new File(artifactDir, version), artifact.getArtifactId() + "-" + version + ".hpi");
                            if (hpi.isFile()) {
                                String name = entry.getKey();
                                System.err.println("Overriding " + name + " " + ucVersion + " with local build of " + version);
                                PluginMetadata m = PluginMetadata.LocalOverride.create(hpi);
                                String parsedName = m.getName();
                                if (!name.equals(parsedName)) {
                                    throw new AssertionError("wrong name: " + parsedName + " vs. " + name);
                                }
                                entry.setValue(m);
                            }
                        }
                    }
                } catch (Exception x) {
                    x.printStackTrace();
                }
            }
        }
    }
    // deprecated mechanism, as of 1.57
    for (Map.Entry<String, String> e : System.getenv().entrySet()) {
        String key = e.getKey();
        if (!isPluginEnvironmentVariable(key))
            continue;
        try {
            override(ucm, e.getValue());
            System.err.println("Using XXX.jpi/XXX_JPI env vars is deprecated. Use LOCAL_JARS instead.");
        } catch (Exception x) {
            throw new IllegalArgumentException("Unable to honor environment variable " + key, x);
        }
    }
    // past 1.57, preferred way
    String localJars = System.getenv("LOCAL_JARS");
    if (localJars != null) {
        for (String jar : localJars.split(File.pathSeparator)) {
            try {
                override(ucm, jar);
            } catch (Exception x) {
                throw new IllegalArgumentException("Unable to honor LOCAL_JARS environment variable", x);
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) VersionScheme(org.eclipse.aether.version.VersionScheme) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) Version(org.eclipse.aether.version.Version) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) File(java.io.File) Map(java.util.Map) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

Version (org.eclipse.aether.version.Version)17 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)9 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)9 Artifact (org.eclipse.aether.artifact.Artifact)8 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)8 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)8 File (java.io.File)7 ArrayList (java.util.ArrayList)6 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)4 Path (java.nio.file.Path)3 Map (java.util.Map)3 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)3 Model (org.apache.maven.model.Model)3 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)3 RepositorySystem (org.eclipse.aether.RepositorySystem)3 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 FileNotFoundException (java.io.FileNotFoundException)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2