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