use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.
the class ConversionUtilsTest method testBsnMappingWithGroupIdNotPrefix.
public void testBsnMappingWithGroupIdNotPrefix() throws Exception {
Jar jar = new Jar(IO.getFile("testdata/3.jar"));
Artifact artifact = ConversionUtils.fromBundleJar(jar);
assertEquals("com.paremus", artifact.getGroupId());
assertEquals("org.bndtools.example.foo", artifact.getArtifactId());
}
use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.
the class ConversionUtilsTest method testBsnMappingWithGroupId.
public void testBsnMappingWithGroupId() throws Exception {
Jar jar = new Jar(IO.getFile("testdata/2.jar"));
Artifact artifact = ConversionUtils.fromBundleJar(jar);
assertEquals("org.bndtools", artifact.getGroupId());
assertEquals("example.foo", artifact.getArtifactId());
}
use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.
the class RemotePostProcessor method postProcessSnapshot.
private ArtifactResult postProcessSnapshot(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
for (RemoteRepository repository : request.getRepositories()) {
if (!repository.getPolicy(true).isEnabled()) {
// Skip the repo if it isn't enabled for snapshots
continue;
}
// Remove the workspace from the session so that we don't use it
DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
newSession.setWorkspaceReader(null);
// Find the snapshot metadata for the module
MetadataRequest mr = new MetadataRequest().setRepository(repository).setMetadata(new DefaultMetadata(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "maven-metadata.xml", SNAPSHOT));
for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
if (metadataResult.isResolved()) {
String version;
try {
Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
Versioning versioning = read.getVersioning();
if (versioning == null || versioning.getSnapshotVersions() == null || versioning.getSnapshotVersions().isEmpty()) {
continue;
} else {
version = versioning.getSnapshotVersions().get(0).getVersion();
}
} catch (Exception e) {
throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
}
Artifact fullVersionArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version);
try {
ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(fullVersionArtifact).addRepository(repository));
if (result.isResolved()) {
File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForRemoteArtifact(fullVersionArtifact, repository, artifact.toString()));
if (!toUse.exists()) {
logger.warn("The resolved artifact {} does not exist at {}", fullVersionArtifact, toUse);
continue;
} else {
logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
}
result.getArtifact().setFile(toUse);
return result;
}
} catch (ArtifactResolutionException e) {
logger.debug("Unable to locate the artifact {}", fullVersionArtifact, e);
}
}
}
}
logger.debug("Unable to resolve a remote repository containing {}", artifact);
return null;
}
use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.
the class RemotePostProcessor method postProcessResult.
@Override
public ArtifactResult postProcessResult(ArtifactResult resolvedArtifact) throws MojoExecutionException {
if (localURLs == LocalURLs.REQUIRED) {
// Skip the search as we will use the local file anyway
return resolvedArtifact;
}
String repoId = resolvedArtifact.getRepository().getId();
Artifact artifact = resolvedArtifact.getArtifact();
if ("workspace".equals(repoId) || "local".equals(repoId)) {
logger.debug("Post processing {} to determine a remote source", artifact);
ArtifactResult postProcessed;
if (artifact.isSnapshot()) {
postProcessed = postProcessSnapshot(resolvedArtifact.getRequest(), artifact);
} else {
postProcessed = postProcessRelease(resolvedArtifact.getRequest(), artifact);
}
if (postProcessed != null) {
return postProcessed;
}
}
return resolvedArtifact;
}
use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.
the class BaselineMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
logger.debug("skip project as configured");
return;
}
Artifact artifact = RepositoryUtils.toArtifact(project.getArtifact());
List<RemoteRepository> aetherRepos = getRepositories(artifact);
setupBase(artifact);
try {
if (base.getVersion() == null || base.getVersion().isEmpty()) {
searchForBaseVersion(artifact, aetherRepos);
}
if (base.getVersion() != null && !base.getVersion().isEmpty()) {
ArtifactResult artifactResult = locateBaseJar(aetherRepos);
Reporter reporter;
if (fullReport) {
reporter = new ReporterAdapter(System.out);
((ReporterAdapter) reporter).setTrace(true);
} else {
reporter = new ReporterAdapter();
}
Baseline baseline = new Baseline(reporter, new DiffPluginImpl());
if (checkFailures(artifact, artifactResult, baseline)) {
if (continueOnError) {
logger.warn("The baselining check failed when checking {} against {} but the bnd-baseline-maven-plugin is configured not to fail the build.", artifact, artifactResult.getArtifact());
} else {
throw new MojoExecutionException("The baselining plugin detected versioning errors");
}
} else {
logger.info("Baselining check succeeded checking {} against {}", artifact, artifactResult.getArtifact());
}
} else {
if (failOnMissing) {
throw new MojoExecutionException("Unable to locate a previous version of the artifact");
} else {
logger.warn("No previous version of {} could be found to baseline against", artifact);
}
}
} catch (RepositoryException re) {
throw new MojoExecutionException("Unable to locate a previous version of the artifact", re);
} catch (Exception e) {
throw new MojoExecutionException("An error occurred while calculating the baseline", e);
}
}
Aggregations