Search in sources :

Example 1 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException in project liferay-ide by liferay.

the class LiferayMavenProjectProvider method getData.

@Override
public <T> List<T> getData(String key, Class<T> type, Object... params) {
    List<T> retval = null;
    if ("profileIds".equals(key)) {
        List<T> profileIds = new ArrayList<>();
        try {
            IMaven maven = MavenPlugin.getMaven();
            List<Profile> profiles = maven.getSettings().getProfiles();
            for (Profile profile : profiles) {
                if (profile.getActivation() != null) {
                    if (profile.getActivation().isActiveByDefault()) {
                        continue;
                    }
                }
                profileIds.add(type.cast(profile.getId()));
            }
            if ((params[0] != null) && params[0] instanceof File) {
                File locationDir = (File) params[0];
                File pomFile = new File(locationDir, IMavenConstants.POM_FILE_NAME);
                if (FileUtil.notExists(pomFile) && FileUtil.exists(locationDir.getParentFile())) {
                    // try one level up for when user is adding new module
                    pomFile = new File(locationDir.getParentFile(), IMavenConstants.POM_FILE_NAME);
                }
                if (FileUtil.exists(pomFile)) {
                    Model model = maven.readModel(pomFile);
                    File parentDir = pomFile.getParentFile();
                    while (model != null) {
                        for (org.apache.maven.model.Profile p : model.getProfiles()) {
                            profileIds.add(type.cast(p.getId()));
                        }
                        parentDir = parentDir.getParentFile();
                        if (FileUtil.exists(parentDir)) {
                            try {
                                model = maven.readModel(new File(parentDir, IMavenConstants.POM_FILE_NAME));
                            } catch (Exception e) {
                                model = null;
                            }
                        }
                    }
                }
            }
        } catch (CoreException ce) {
            LiferayMavenCore.logError(ce);
        }
        retval = profileIds;
    } else if ("liferayVersions".equals(key)) {
        List<T> possibleVersions = new ArrayList<>();
        RepositorySystem system = AetherUtil.newRepositorySystem();
        RepositorySystemSession session = AetherUtil.newRepositorySystemSession(system);
        String groupId = params[0].toString();
        String artifactId = params[1].toString();
        String coords = groupId + ":" + artifactId + ":[6,)";
        Artifact artifact = new DefaultArtifact(coords);
        VersionRangeRequest rangeRequest = new VersionRangeRequest();
        rangeRequest.setArtifact(artifact);
        rangeRequest.addRepository(AetherUtil.newCentralRepository());
        rangeRequest.addRepository(AetherUtil.newLiferayRepository());
        try {
            VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
            List<Version> versions = rangeResult.getVersions();
            for (Version version : versions) {
                String val = version.toString();
                if (!"6.2.0".equals(val) && !val.contains("7.0.0")) {
                    possibleVersions.add(type.cast(val));
                }
            }
            retval = possibleVersions;
        } catch (VersionRangeResolutionException vrre) {
        }
    } else if ("parentVersion".equals(key)) {
        List<T> version = new ArrayList<>();
        File locationDir = (File) params[0];
        File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME);
        if (FileUtil.exists(parentPom)) {
            try {
                IMaven maven = MavenPlugin.getMaven();
                Model model = maven.readModel(parentPom);
                version.add(type.cast(model.getVersion()));
                retval = version;
            } catch (CoreException ce) {
                LiferayMavenCore.logError("unable to get parent version", ce);
            }
        }
    } else if ("parentGroupId".equals(key)) {
        List<T> groupId = new ArrayList<>();
        File locationDir = (File) params[0];
        File parentPom = new File(locationDir, IMavenConstants.POM_FILE_NAME);
        if (FileUtil.exists(parentPom)) {
            try {
                IMaven maven = MavenPlugin.getMaven();
                Model model = maven.readModel(parentPom);
                groupId.add(type.cast(model.getGroupId()));
                retval = groupId;
            } catch (CoreException ce) {
                LiferayMavenCore.logError("unable to get parent groupId", ce);
            }
        }
    } else if ("archetypeGAV".equals(key)) {
        String frameworkType = (String) params[0];
        String value = LiferayMavenCore.getPreferenceString("archetype-gav-" + frameworkType, "");
        retval = Collections.singletonList(type.cast(value));
    }
    return retval;
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) ArrayList(java.util.ArrayList) NewLiferayProfile(com.liferay.ide.project.core.model.NewLiferayProfile) Profile(org.apache.maven.settings.Profile) CoreException(org.eclipse.core.runtime.CoreException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) RepositorySystem(org.eclipse.aether.RepositorySystem) CoreException(org.eclipse.core.runtime.CoreException) Version(org.eclipse.aether.version.Version) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Model(org.apache.maven.model.Model) ArrayList(java.util.ArrayList) List(java.util.List) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IMaven(org.eclipse.m2e.core.embedder.IMaven) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 2 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudApiMavenService method getBomVersions.

/**
 * Returns the available Google Cloud Java client library BOM versions from Maven Central.
 *
 * @return returns the {@link Version versions} of the BOMs
 */
List<Version> getBomVersions() {
    Artifact artifact = new DefaultArtifact(toBomCoordinates(GOOGLE_CLOUD_JAVA_BOM_ALL_VERSIONS_CONSTRAINT));
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.addRepository(MAVEN_CENTRAL_REPOSITORY);
    try {
        VersionRangeResult result = SYSTEM.resolveVersionRange(SESSION, rangeRequest);
        return result.getVersions();
    } catch (VersionRangeResolutionException e) {
        logger.warn("Error fetching available BOM versions from Maven Central", e);
        return ImmutableList.of();
    }
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) 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 3 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException in project revapi by revapi.

the class ReportAggregateMojo method getRunConfig.

private ProjectVersions getRunConfig(MavenProject project) {
    ProjectVersions ret = new ProjectVersions();
    Plugin revapiPlugin = findRevapi(project);
    if (revapiPlugin == null) {
        return ret;
    }
    Xpp3Dom pluginConfig = (Xpp3Dom) revapiPlugin.getConfiguration();
    String[] oldArtifacts = getArtifacts(pluginConfig, "oldArtifacts");
    String[] newArtifacts = getArtifacts(pluginConfig, "newArtifacts");
    String oldVersion = getValueOfChild(pluginConfig, "oldVersion");
    if (oldVersion == null) {
        oldVersion = System.getProperties().getProperty(Props.oldVersion.NAME, Props.oldVersion.DEFAULT_VALUE);
    }
    String newVersion = getValueOfChild(pluginConfig, "newVersion");
    if (newVersion == null) {
        newVersion = System.getProperties().getProperty(Props.newVersion.NAME, project.getVersion());
    }
    String defaultOldArtifact = Analyzer.getProjectArtifactCoordinates(project, oldVersion);
    String defaultNewArtifact = Analyzer.getProjectArtifactCoordinates(project, newVersion);
    if (oldArtifacts == null || oldArtifacts.length == 0) {
        if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
            return ret;
        }
        oldArtifacts = new String[] { defaultOldArtifact };
    }
    if (newArtifacts == null || newArtifacts.length == 0) {
        if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) {
            return ret;
        }
        newArtifacts = new String[] { defaultNewArtifact };
    }
    String versionRegexString = getValueOfChild(pluginConfig, "versionFormat");
    Pattern versionRegex = versionRegexString == null ? null : Pattern.compile(versionRegexString);
    DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
    session.setDependencySelector(new ScopeDependencySelector("compile", "provided"));
    session.setDependencyTraverser(new ScopeDependencyTraverser("compile", "provided"));
    if (alwaysCheckForReleaseVersion) {
        session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
    }
    ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, mavenSession.getCurrentProject().getRemoteProjectRepositories());
    Function<String, Artifact> resolve = gav -> {
        try {
            return Analyzer.resolveConstrained(project, gav, versionRegex, resolver);
        } catch (VersionRangeResolutionException | ArtifactResolutionException e) {
            getLog().warn("Could not resolve artifact '" + gav + "' with message: " + e.getMessage());
            return null;
        }
    };
    ret.oldGavs = Stream.of(oldArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);
    ret.newGavs = Stream.of(newArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new);
    return ret;
}
Also used : Component(org.apache.maven.plugins.annotations.Component) HashMap(java.util.HashMap) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Function(java.util.function.Function) Sink(org.apache.maven.doxia.sink.Sink) MessageFormat(java.text.MessageFormat) Execute(org.apache.maven.plugins.annotations.Execute) Mojo(org.apache.maven.plugins.annotations.Mojo) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ResourceBundle(java.util.ResourceBundle) MavenProject(org.apache.maven.project.MavenProject) Locale(java.util.Locale) Map(java.util.Map) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) SITE(org.apache.maven.plugins.annotations.LifecyclePhase.SITE) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) API(org.revapi.API) MavenSession(org.apache.maven.execution.MavenSession) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) MavenReportException(org.apache.maven.reporting.MavenReportException) Artifact(org.eclipse.aether.artifact.Artifact) AnalysisResult(org.revapi.AnalysisResult) Collectors(java.util.stream.Collectors) Revapi(org.revapi.Revapi) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) PACKAGE(org.apache.maven.plugins.annotations.LifecyclePhase.PACKAGE) List(java.util.List) Plugin(org.apache.maven.model.Plugin) Stream(java.util.stream.Stream) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector) Pattern(java.util.regex.Pattern) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) Artifact(org.eclipse.aether.artifact.Artifact) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) Plugin(org.apache.maven.model.Plugin) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector)

Example 4 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException in project pinpoint by naver.

the class DependencyResolver method resolveDependencySets.

public Map<String, List<Artifact>> resolveDependencySets(String... dependencies) {
    List<List<Artifact>> companions = resolve(dependencies);
    List<List<List<Artifact>>> xxx = new ArrayList<>();
    for (List<Artifact> companion : companions) {
        Artifact representative = companion.get(0);
        List<Version> versions;
        try {
            versions = getVersions(representative);
        } catch (VersionRangeResolutionException e) {
            throw new IllegalArgumentException("Fail to resolve version of: " + representative);
        }
        if (versions.isEmpty()) {
            throw new IllegalArgumentException("No version in the given range: " + representative);
        }
        List<List<Artifact>> companionVersions = new ArrayList<>(versions.size());
        for (Version version : versions) {
            List<Artifact> companionVersion = new ArrayList<>(companion.size());
            for (Artifact artifact : companion) {
                Artifact verArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version.toString());
                companionVersion.add(verArtifact);
            }
            companionVersions.add(companionVersion);
        }
        xxx.add(companionVersions);
    }
    Map<String, List<Artifact>> result = combination(xxx);
    return result;
}
Also used : ArrayList(java.util.ArrayList) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) Version(org.eclipse.aether.version.Version) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 5 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException 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.getRepositories());
    // 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.getRepositories());
                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.getRepositories());
                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)

Aggregations

VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)11 Artifact (org.eclipse.aether.artifact.Artifact)10 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)9 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)7 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)7 Version (org.eclipse.aether.version.Version)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)5 IOException (java.io.IOException)4 List (java.util.List)4 FileNotFoundException (java.io.FileNotFoundException)3 Model (org.apache.maven.model.Model)3 MavenProject (org.apache.maven.project.MavenProject)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)3 FileReader (java.io.FileReader)2 Collections (java.util.Collections)2 Locale (java.util.Locale)2 Map (java.util.Map)2