use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project felix by apache.
the class BundleAllPlugin method resolveArtifact.
private Artifact resolveArtifact(Artifact artifact) throws MojoExecutionException, ArtifactNotFoundException {
VersionRange versionRange;
if (artifact.getVersion() != null) {
versionRange = VersionRange.createFromVersion(artifact.getVersion());
} else {
versionRange = artifact.getVersionRange();
}
/*
* there's a bug with ArtifactFactory#createDependencyArtifact(String, String, VersionRange,
* String, String, String) that ignores the scope parameter, that's why we use the one with
* the extra null parameter
*/
Artifact resolvedArtifact = m_factory.createDependencyArtifact(artifact.getGroupId(), artifact.getArtifactId(), versionRange, artifact.getType(), artifact.getClassifier(), artifact.getScope(), null);
try {
m_artifactResolver.resolve(resolvedArtifact, remoteRepositories, localRepository);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Error resolving artifact " + resolvedArtifact, e);
}
return resolvedArtifact;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project midpoint by Evolveum.
the class SchemaDistMojo method getArtifact.
protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException, InvalidVersionSpecificationException {
Artifact artifact;
VersionRange vr = VersionRange.createFromVersionSpec(artifactItem.getVersion());
if (StringUtils.isEmpty(artifactItem.getClassifier())) {
artifact = factory.createDependencyArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), vr, artifactItem.getType(), null, Artifact.SCOPE_COMPILE);
} else {
artifact = factory.createDependencyArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), vr, artifactItem.getType(), artifactItem.getClassifier(), Artifact.SCOPE_COMPILE);
}
try {
resolver.resolve(artifact, remoteRepos, local);
} catch (ArtifactResolutionException | ArtifactNotFoundException e) {
throw new MojoExecutionException("Error resolving artifact " + artifact, e);
}
return artifact;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.
the class ProcessRemoteResourcesMojo method downloadBundles.
private List<File> downloadBundles(List<String> bundles) throws MojoExecutionException {
List<File> bundleArtifacts = new ArrayList<File>();
try {
for (String artifactDescriptor : bundles) {
// groupId:artifactId:version[:type[:classifier]]
String[] s = artifactDescriptor.split(":");
File artifactFile = null;
// check if the artifact is part of the reactor
if (mavenSession != null) {
List<MavenProject> list = mavenSession.getSortedProjects();
for (MavenProject p : list) {
if (s[0].equals(p.getGroupId()) && s[1].equals(p.getArtifactId()) && s[2].equals(p.getVersion())) {
if (s.length >= 4 && "test-jar".equals(s[3])) {
artifactFile = new File(p.getBuild().getTestOutputDirectory());
} else {
artifactFile = new File(p.getBuild().getOutputDirectory());
}
}
}
}
if (artifactFile == null || !artifactFile.exists()) {
String type = (s.length >= 4 ? s[3] : "jar");
String classifier = (s.length == 5 ? s[4] : null);
Artifact artifact = artifactFactory.createDependencyArtifact(s[0], s[1], VersionRange.createFromVersion(s[2]), type, classifier, Artifact.SCOPE_RUNTIME);
artifactResolver.resolve(artifact, remoteArtifactRepositories, localRepository);
artifactFile = artifact.getFile();
}
bundleArtifacts.add(artifactFile);
}
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Error downloading resources archive.", e);
} catch (ArtifactNotFoundException e) {
throw new MojoExecutionException("Resources archive cannot be found.", e);
}
return bundleArtifacts;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.
the class BundlePackMojo method execute.
@SuppressWarnings("unchecked")
public void execute() throws MojoExecutionException {
readArtifactDataFromUser();
Artifact artifact = artifactFactory.createProjectArtifact(groupId, artifactId, version);
try {
artifactResolver.resolve(artifact, Collections.EMPTY_LIST, localRepository);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Unable to resolve artifact " + artifact.getId(), e);
} catch (ArtifactNotFoundException e) {
throw new MojoExecutionException("Artifact " + artifact.getId() + " not found in local repository", e);
}
File pom = artifact.getFile();
File dir = pom.getParentFile();
Model model = readPom(pom);
boolean rewrite = false;
try {
if (model.getPackaging() == null) {
model.setPackaging("jar");
rewrite = true;
}
if (model.getName() == null) {
getLog().info("Project name is missing, please type the project name [" + artifactId + "]:");
model.setName(inputHandler.readLine());
if (model.getName() == null) {
model.setName(artifactId);
}
rewrite = true;
}
if (model.getDescription() == null) {
getLog().info("Project description is missing, please type the project description:");
model.setDescription(inputHandler.readLine());
rewrite = true;
}
if (model.getUrl() == null) {
getLog().info("Project URL is missing, please type the project URL:");
model.setUrl(inputHandler.readLine());
rewrite = true;
}
List<License> licenses = model.getLicenses();
if (licenses.isEmpty()) {
License license = new License();
getLog().info("License name is missing, please type the license name:");
license.setName(inputHandler.readLine());
getLog().info("License URL is missing, please type the license URL:");
license.setUrl(inputHandler.readLine());
licenses.add(license);
rewrite = true;
}
if (disableMaterialization) {
getLog().warn("Validations to confirm support for project materialization have been DISABLED." + "\n\nYour project may not provide the POM elements necessary to allow " + "users to retrieve sources on-demand," + "\nor to easily checkout your project in an IDE. " + "THIS CAN SERIOUSLY INCONVENIENCE YOUR USERS.\n\nContinue? [y/N]");
try {
if ('y' != inputHandler.readLine().toLowerCase().charAt(0)) {
disableMaterialization = false;
}
} catch (IOException e) {
getLog().debug("Error reading confirmation: " + e.getMessage(), e);
}
}
if (!disableMaterialization) {
Scm scm = model.getScm();
if (scm == null) {
scm = new Scm();
model.setScm(scm);
}
if (scm.getUrl() == null) {
if (scmUrl != null) {
scm.setUrl(scmUrl);
} else {
getLog().info("SCM view URL is missing, please type the URL for the viewable SCM interface:");
scm.setUrl(inputHandler.readLine());
rewrite = true;
}
}
if (scm.getConnection() == null) {
if (scmConnection != null) {
scm.setConnection(scmConnection);
} else {
getLog().info("SCM read-only connection URL is missing, please type the read-only SCM URL:");
scm.setConnection(inputHandler.readLine());
rewrite = true;
}
}
}
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
try {
if (rewrite) {
new MavenXpp3Writer().write(WriterFactory.newXmlWriter(pom), model);
}
String finalName = null;
if (model.getBuild() != null) {
finalName = model.getBuild().getFinalName();
}
if (finalName == null) {
finalName = model.getArtifactId() + "-" + model.getVersion();
}
boolean batchMode = settings == null ? false : !settings.isInteractiveMode();
List<File> files = BundleUtils.selectProjectFiles(dir, inputHandler, finalName, pom, getLog(), batchMode);
File bundle = new File(basedir, finalName + "-bundle.jar");
jarArchiver.addFile(pom, POM);
boolean artifactChecks = !"pom".equals(model.getPackaging());
boolean sourcesFound = false;
boolean javadocsFound = false;
for (File f : files) {
if (artifactChecks && f.getName().endsWith(finalName + "-sources.jar")) {
sourcesFound = true;
} else if (artifactChecks && f.getName().equals(finalName + "-javadoc.jar")) {
javadocsFound = true;
}
jarArchiver.addFile(f, f.getName());
}
if (artifactChecks && !sourcesFound) {
getLog().warn("Sources not included in upload bundle.");
}
if (artifactChecks && !javadocsFound) {
getLog().warn("Javadoc not included in upload bundle.");
}
jarArchiver.setDestFile(bundle);
jarArchiver.createArchive();
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (ArchiverException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionException in project maven-plugins by apache.
the class RepositoryUtils method getDependencyUrlFromRepository.
/**
* @param artifact not null
* @param repo not null
* @return the artifact url in the given repo for the given artifact. If it is a snapshot artifact, the version
* will be the timestamp and the build number from the metadata. Could return null if the repo is blacklisted.
*/
public String getDependencyUrlFromRepository(Artifact artifact, ArtifactRepository repo) {
if (repo.isBlacklisted()) {
return null;
}
Artifact copyArtifact = ArtifactUtils.copyArtifact(artifact);
// Try to get the last artifact repo name depending the snapshot version
if ((artifact.isSnapshot() && repo.getSnapshots().isEnabled())) {
if (artifact.getBaseVersion().equals(artifact.getVersion())) {
// Try to resolve it if not already done
if (artifact.getMetadataList() == null || artifact.getMetadataList().isEmpty()) {
try {
resolve(artifact);
} catch (ArtifactResolutionException e) {
log.error("Artifact: " + artifact.getId() + " could not be resolved.");
} catch (ArtifactNotFoundException e) {
log.error("Artifact: " + artifact.getId() + " was not found.");
}
}
for (ArtifactMetadata m : artifact.getMetadataList()) {
if (m instanceof SnapshotArtifactRepositoryMetadata) {
SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata) m;
Metadata metadata = snapshotMetadata.getMetadata();
Versioning versioning = metadata.getVersioning();
if (versioning == null || versioning.getSnapshot() == null || versioning.getSnapshot().isLocalCopy() || versioning.getSnapshot().getTimestamp() == null) {
continue;
}
// create the version according SnapshotTransformation
String version = StringUtils.replace(copyArtifact.getVersion(), Artifact.SNAPSHOT_VERSION, versioning.getSnapshot().getTimestamp()) + "-" + versioning.getSnapshot().getBuildNumber();
copyArtifact.setVersion(version);
}
}
}
}
return repo.getUrl() + "/" + repo.pathOf(copyArtifact);
}
Aggregations