use of org.eclipse.aether.artifact.Artifact 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);
rangeRequest.setRepositories(mavenPluginRepository.getRepositories());
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);
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)) {
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.artifact.Artifact 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.getRepositories());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
return resolveArtifact.getArtifact().getFile().toPath();
}
use of org.eclipse.aether.artifact.Artifact in project BIMserver by opensourceBIM.
the class MavenPluginLocation method getLatestVersionString.
public String getLatestVersionString() {
Artifact lastArt = new DefaultArtifact(groupId, artifactId, "jar", "LATEST");
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(lastArt);
request.setRepositories(mavenPluginRepository.getRepositories());
try {
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
return resolveArtifact.getArtifact().getVersion();
} catch (ArtifactResolutionException e1) {
e1.printStackTrace();
}
return null;
}
use of org.eclipse.aether.artifact.Artifact 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.getRepositories());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
return resolveArtifact.getArtifact().getFile().toPath();
}
use of org.eclipse.aether.artifact.Artifact 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);
request.setRepositories(mavenPluginRepository.getRepositories());
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;
}
Aggregations