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