Search in sources :

Example 76 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getVersionJar.

public Path getVersionJar(String version) throws ArtifactResolutionException {
    Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "jar", version.toString());
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(versionArtifact);
    request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
    ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
    return resolveArtifact.getArtifact().getFile().toPath();
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 77 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getPluginBundle.

public SPluginBundle getPluginBundle(String version) {
    try {
        Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version);
        ArtifactRequest request = new ArtifactRequest();
        request.setArtifact(versionArtifact);
        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
        File pomFile = resolveArtifact.getArtifact().getFile();
        MavenXpp3Reader mavenreader = new MavenXpp3Reader();
        Model model = null;
        try (FileReader fileReader = new FileReader(pomFile)) {
            model = mavenreader.read(fileReader);
        }
        SPluginBundle sPluginBundle = new SPluginBundle();
        sPluginBundle.setOrganization(model.getOrganization().getName());
        sPluginBundle.setName(model.getName());
        return sPluginBundle;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : SPluginBundle(org.bimserver.interfaces.objects.SPluginBundle) FileNotFoundException(java.io.FileNotFoundException) 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) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Model(org.apache.maven.model.Model) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 78 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult 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 79 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult 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 80 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project BIMserver by opensourceBIM.

the class MavenPluginLocation method getVersionPom.

public Path getVersionPom(String version) throws ArtifactResolutionException {
    Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(pomArtifact);
    request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
    ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
    return resolveArtifact.getArtifact().getFile().toPath();
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)83 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)53 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)51 Artifact (org.eclipse.aether.artifact.Artifact)41 File (java.io.File)37 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)37 IOException (java.io.IOException)16 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)16 ArrayList (java.util.ArrayList)15 Dependency (org.eclipse.aether.graph.Dependency)15 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)13 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)11 CollectRequest (org.eclipse.aether.collection.CollectRequest)11 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)10 FileNotFoundException (java.io.FileNotFoundException)9 RepositorySystem (org.eclipse.aether.RepositorySystem)8 Test (org.junit.Test)8 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)7