use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.
the class DefaultRepositoryAssembler method assembleRepositoryArtifacts.
private void assembleRepositoryArtifacts(ProjectBuildingRequest buildingRequest, Iterable<ArtifactResult> result, ArtifactFilter filter, Map<String, GroupVersionAlignment> groupVersionAlignments) throws RepositoryAssemblyException {
try {
for (ArtifactResult ar : result) {
Artifact a = ar.getArtifact();
if (filter.include(a)) {
getLogger().debug("Re-resolving: " + a + " for repository assembly.");
setAlignment(a, groupVersionAlignments);
artifactResolver.resolveArtifact(buildingRequest, TransferUtils.toArtifactCoordinate(a));
a.setVersion(a.getBaseVersion());
File targetFile = new File(repositoryManager.getLocalRepositoryBasedir(buildingRequest), repositoryManager.getPathForLocalArtifact(buildingRequest, a));
FileUtils.copyFile(a.getFile(), targetFile);
// writeChecksums( targetFile );
}
}
} catch (ArtifactResolverException e) {
throw new RepositoryAssemblyException("Error resolving artifacts: " + e.getMessage(), e);
} catch (IOException e) {
throw new RepositoryAssemblyException("Error writing artifact metdata.", e);
}
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.
the class GetMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkip()) {
getLog().info("Skipping plugin execution");
return;
}
if (coordinate.getArtifactId() == null && artifact == null) {
throw new MojoFailureException("You must specify an artifact, " + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
}
if (artifact != null) {
String[] tokens = StringUtils.split(artifact, ":");
if (tokens.length < 3 || tokens.length > 5) {
throw new MojoFailureException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
}
coordinate.setGroupId(tokens[0]);
coordinate.setArtifactId(tokens[1]);
coordinate.setVersion(tokens[2]);
if (tokens.length >= 4) {
coordinate.setType(tokens[3]);
}
if (tokens.length == 5) {
coordinate.setClassifier(tokens[4]);
}
}
ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
List<ArtifactRepository> repoList = new ArrayList<ArtifactRepository>();
if (pomRemoteRepositories != null) {
repoList.addAll(pomRemoteRepositories);
}
if (remoteRepositories != null) {
// Use the same format as in the deploy plugin id::layout::url
List<String> repos = Arrays.asList(StringUtils.split(remoteRepositories, ","));
for (String repo : repos) {
repoList.add(parseRepository(repo, always));
}
}
try {
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(repoList);
if (transitive) {
getLog().info("Resolving " + coordinate + " with transitive dependencies");
dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
} else {
getLog().info("Resolving " + coordinate);
artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
}
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
} catch (DependencyResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.
the class PurgeLocalRepositoryMojo method reResolveArtifacts.
private void reResolveArtifacts(MavenProject project, Set<Artifact> artifacts, ArtifactFilter filter) throws ArtifactResolutionException, ArtifactNotFoundException {
// because Maven 2 will not automatically re-resolve them when resolving the artifact
for (Artifact artifact : artifacts) {
try {
// CHECKSTYLE_OFF: LineLength
artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), org.apache.maven.shared.artifact.TransferUtils.toArtifactCoordinate(artifact));
// CHECKSTYLE_ON: LineLength
} catch (ArtifactResolverException e) {
verbose(e.getMessage());
}
}
List<Artifact> missingArtifacts = new ArrayList<Artifact>();
for (Artifact artifact : artifacts) {
verbose("Resolving artifact: " + artifact.getId());
try {
artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), artifact);
} catch (ArtifactResolverException e) {
verbose(e.getMessage());
missingArtifacts.add(artifact);
}
}
if (missingArtifacts.size() > 0) {
StringBuffer message = new StringBuffer("required artifacts missing:\n");
for (Artifact missingArtifact : missingArtifacts) {
message.append(" ").append(missingArtifact.getId()).append('\n');
}
message.append("\nfor the artifact:");
throw new ArtifactResolutionException(message.toString(), project.getArtifact(), project.getRemoteArtifactRepositories());
}
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-archetype by apache.
the class IntegrationTestMojo method setupParentProjects.
private File setupParentProjects(File configFolder, File buildFolder) throws IOException, MojoExecutionException, IntegrationTestFailure {
// look for 'archetype.pom.properties'
File archetypePomPropertiesFile = new File(configFolder, "archetype.pom.properties");
if (!archetypePomPropertiesFile.exists()) {
getLog().debug("No 'archetype.pom.properties' file found in " + configFolder);
return buildFolder;
}
// go up to the parent configuration folder
buildFolder = setupParentProjects(configFolder.getParentFile(), buildFolder);
Properties archetypePomProperties = loadProperties(archetypePomPropertiesFile);
String groupId = archetypePomProperties.getProperty(Constants.GROUP_ID);
if (StringUtils.isEmpty(groupId)) {
throw new MojoExecutionException("Property " + Constants.GROUP_ID + " not set in " + archetypePomPropertiesFile);
}
String artifactId = archetypePomProperties.getProperty(Constants.ARTIFACT_ID);
if (StringUtils.isEmpty(artifactId)) {
throw new MojoExecutionException("Property " + Constants.ARTIFACT_ID + " not set in " + archetypePomPropertiesFile);
}
String version = archetypePomProperties.getProperty(Constants.VERSION);
if (StringUtils.isEmpty(version)) {
throw new MojoExecutionException("Property " + Constants.VERSION + " not set in " + archetypePomPropertiesFile);
}
File archetypeFile;
try {
archetypeFile = getArchetypeFile(groupId, artifactId, version);
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Could not resolve archetype artifact ", e);
}
Properties archetypeProperties = getProperties(archetypePomPropertiesFile);
getLog().info("Setting up parent project in " + buildFolder);
ArchetypeGenerationRequest request = generate(groupId, artifactId, version, archetypeFile, archetypeProperties, buildFolder.toString());
return new File(buildFolder, request.getArtifactId());
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-archetype by apache.
the class DefaultDownloader method download.
public File download(String groupId, String artifactId, String version, ArtifactRepository archetypeRepository, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, ProjectBuildingRequest buildingRequest) throws DownloadException, DownloadNotFoundException {
DefaultArtifactCoordinate jarCoordinate = new DefaultArtifactCoordinate();
jarCoordinate.setGroupId(groupId);
jarCoordinate.setArtifactId(artifactId);
jarCoordinate.setVersion(version);
DefaultArtifactCoordinate pomCoordinate = new DefaultArtifactCoordinate();
pomCoordinate.setGroupId(groupId);
pomCoordinate.setArtifactId(artifactId);
pomCoordinate.setVersion(version);
pomCoordinate.setExtension("pom");
List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>(remoteRepositories);
if (repositories.isEmpty() && archetypeRepository != null) {
repositories.add(archetypeRepository);
} else if (repositories.isEmpty() && localRepository != null) {
repositories.add(localRepository);
}
ArtifactRepository localRepo = localRepository;
buildingRequest.setLocalRepository(localRepo);
buildingRequest.setRemoteRepositories(repositories);
Artifact artifact;
try {
artifact = artifactResolver.resolveArtifact(buildingRequest, jarCoordinate).getArtifact();
} catch (ArtifactResolverException e) {
throw new DownloadException("Error downloading " + jarCoordinate + ".", e);
}
// still required???
try {
artifactResolver.resolveArtifact(buildingRequest, pomCoordinate);
} catch (ArtifactResolverException e) {
throw new DownloadException("Error downloading POM for " + artifact.getId() + ".", e);
}
return artifact.getFile();
}
Aggregations