use of org.eclipse.aether.version.Version in project buck by facebook.
the class Resolver method getNewerVersionFile.
/**
* @return {@link Path} to the file in {@code project} with filename consistent with the given
* {@link Artifact}, but with a newer version. If no such file exists, {@link Optional#empty} is
* returned. If multiple such files are present one with the newest version will be returned.
*/
@VisibleForTesting
Optional<Path> getNewerVersionFile(final Artifact artifactToDownload, Path project) throws IOException {
final Version artifactToDownloadVersion;
try {
artifactToDownloadVersion = versionScheme.parseVersion(artifactToDownload.getVersion());
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
final Pattern versionExtractor = Pattern.compile(String.format(ARTIFACT_FILE_NAME_REGEX_FORMAT, artifactToDownload.getArtifactId(), VERSION_REGEX_GROUP, artifactToDownload.getExtension()));
Iterable<Version> versionsPresent = FluentIterable.from(Files.newDirectoryStream(project)).transform(new Function<Path, Version>() {
@Nullable
@Override
public Version apply(Path input) {
Matcher matcher = versionExtractor.matcher(input.getFileName().toString());
if (matcher.matches()) {
try {
return versionScheme.parseVersion(matcher.group(1));
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
} else {
return null;
}
}
}).filter(Objects::nonNull);
List<Version> newestPresent = Ordering.natural().greatestOf(versionsPresent, 1);
if (newestPresent.isEmpty() || newestPresent.get(0).compareTo(artifactToDownloadVersion) <= 0) {
return Optional.empty();
} else {
return Optional.of(project.resolve(String.format(ARTIFACT_FILE_NAME_FORMAT, artifactToDownload.getArtifactId(), newestPresent.get(0).toString(), artifactToDownload.getExtension())));
}
}
use of org.eclipse.aether.version.Version in project fabric8 by jboss-fuse.
the class ReplaceConflictingVersionResolver method selectVersion.
private void selectVersion(DependencyNode node, DependencyNode parent, int depth, Map<DependencyNode, Integer> depths, ConflictGroup group, Map<?, ?> conflictIds) throws RepositoryException {
Integer smallestDepth = depths.get(node);
if (smallestDepth == null || smallestDepth > depth) {
depths.put(node, depth);
} else {
return;
}
Object key = conflictIds.get(node);
if (group.key.equals(key)) {
Position pos = new Position(parent, depth);
if (parent != null) {
group.positions.add(pos);
}
if (!group.isAcceptable(node.getVersion())) {
return;
}
group.candidates.put(node, pos);
VersionConstraint versionConstraint = node.getVersionConstraint();
if (versionConstraint != null && versionConstraint.getRange() != null && isNotEmpty(versionConstraint.getRange())) {
group.constraints.add(versionConstraint);
}
if (group.version == null || isNearer(pos, node.getVersion(), group.position, group.version)) {
group.version = node.getVersion();
group.versionDependency = node;
group.position = pos;
}
if (!group.isAcceptable(group.version)) {
group.version = null;
group.versionDependency = null;
for (Iterator<Map.Entry<DependencyNode, Position>> it = group.candidates.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<DependencyNode, Position> entry = it.next();
Version version = entry.getKey().getVersion();
pos = entry.getValue();
if (!group.isAcceptable(version)) {
it.remove();
} else if (group.version == null || isNearer(pos, version, group.position, group.version)) {
group.version = version;
group.versionDependency = entry.getKey();
group.position = pos;
}
}
if (group.version == null) {
Collection<String> versions = new LinkedHashSet<String>();
for (VersionConstraint constraint : group.constraints) {
versions.add(constraint.toString());
}
// TODO, FIXME
throw new UnsolvableVersionConflictException(Collections.<List<DependencyNode>>emptyList());
}
}
}
for (DependencyNode child : node.getChildren()) {
selectVersion(child, node, depth + 1, depths, group, conflictIds);
}
}
use of org.eclipse.aether.version.Version in project spf4j by zolyfarkas.
the class JDiffRunner method runDiffBetweenReleases.
public void runDiffBetweenReleases(final String groupId, final String artifactId, final String versionRange, final File destinationFolder, final int maxNrOFDiffs) throws DependencyResolutionException, VersionRangeResolutionException, IOException, ArtifactResolutionException, JavadocExecutionException {
JDiffRunner jdiff = new JDiffRunner();
List<Version> rangeVersions = MavenRepositoryUtils.getVersions(groupId, artifactId, versionRange, remoteRepos, repositorySystem, reposSession);
int size = rangeVersions.size();
if (size < 2) {
return;
}
LinkedList<Version> versions = new LinkedList<>();
versions.add(rangeVersions.get(size - 1));
for (int i = size - 2, j = 1; i >= 0 && j < maxNrOFDiffs; i--) {
Version ver = rangeVersions.get(i);
if (ver.toString().contains("SNAPSHOT")) {
continue;
}
versions.addFirst(ver);
j++;
}
Version v = versions.get(0);
File prevSourcesArtifact = MavenRepositoryUtils.resolveArtifact(groupId, artifactId, "sources", "jar", v.toString(), remoteRepos, repositorySystem, reposSession);
File prevJavaDocArtifact = MavenRepositoryUtils.resolveArtifact(groupId, artifactId, "javadoc", "jar", v.toString(), remoteRepos, repositorySystem, reposSession);
Path tempDir = Files.createTempDirectory("jdiff");
try {
Path sourceDestination = tempDir.resolve(artifactId).resolve(v.toString()).resolve("sources");
Compress.unzip(prevSourcesArtifact.toPath(), sourceDestination);
Set<File> deps = MavenRepositoryUtils.resolveArtifactAndDependencies("compile", groupId, artifactId, null, "jar", v.toString(), remoteRepos, repositorySystem, reposSession);
String prevApiName = artifactId + '-' + v;
Set<String> prevPackages = jdiff.generateJDiffXML(Arrays.asList(sourceDestination.toFile()), deps, destinationFolder, prevApiName, null);
for (int i = 1, l = versions.size(); i < l; i++) {
v = versions.get(i);
File sourceArtifact = MavenRepositoryUtils.resolveArtifact(groupId, artifactId, "sources", "jar", v.toString(), remoteRepos, repositorySystem, reposSession);
File javadocArtifact = MavenRepositoryUtils.resolveArtifact(groupId, artifactId, "javadoc", "jar", v.toString(), remoteRepos, repositorySystem, reposSession);
sourceDestination = tempDir.resolve(artifactId).resolve(v.toString()).resolve("sources");
Compress.unzip(sourceArtifact.toPath(), sourceDestination);
deps = MavenRepositoryUtils.resolveArtifactAndDependencies("compile", groupId, artifactId, null, "jar", v.toString(), remoteRepos, repositorySystem, reposSession);
String apiName = artifactId + '-' + v;
Set<String> packages = jdiff.generateJDiffXML(Arrays.asList(sourceDestination.toFile()), deps, destinationFolder, apiName, null);
prevPackages.addAll(packages);
Path reportsDestination = destinationFolder.toPath().resolve(prevApiName + '_' + apiName);
Compress.unzip(prevJavaDocArtifact.toPath(), reportsDestination.resolve(prevApiName));
Compress.unzip(javadocArtifact.toPath(), reportsDestination.resolve(apiName));
jdiff.generateReport(destinationFolder, prevApiName, apiName, "../" + prevApiName + '/', "../" + apiName + '/', prevPackages, reportsDestination.toFile());
prevApiName = apiName;
prevPackages = packages;
prevJavaDocArtifact = javadocArtifact;
}
} finally {
FileUtils.deleteDirectory(tempDir.toFile());
}
}
use of org.eclipse.aether.version.Version 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.version.Version 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;
}
Aggregations