use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project jangaroo-tools by CoreMedia.
the class ExmlToMxmlMojo method resolveExtAsArtifact.
private Artifact resolveExtAsArtifact(String version, String packaging) throws MojoExecutionException {
Artifact toDownload = artifactFactory.createBuildArtifact("net.jangaroo", "ext-as", version, packaging);
try {
getLog().info("Resolving " + toDownload + "...");
artifactResolver.resolve(toDownload, remoteRepositories, localRepository);
return toDownload;
} catch (AbstractArtifactResolutionException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
}
use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project tycho by eclipse.
the class LocalDependencyResolver method addDependencies.
private void addDependencies(MavenSession session, MavenProject project, DefaultDependencyArtifacts platform) {
TargetPlatformConfiguration configuration = (TargetPlatformConfiguration) project.getContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION);
if (configuration != null && TargetPlatformConfiguration.POM_DEPENDENCIES_CONSIDER.equals(configuration.getPomDependencies())) {
Map<String, MavenProject> projectIds = new HashMap<>(session.getProjects().size() * 2);
// make a list of reactor projects
for (MavenProject p : session.getProjects()) {
String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion());
projectIds.put(key, p);
}
// handle dependencies that are in reactor
for (Dependency dependency : project.getDependencies()) {
if (Artifact.SCOPE_COMPILE.equals(dependency.getScope())) {
String key = ArtifactUtils.key(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
if (projectIds.containsKey(key)) {
MavenProject dependent = projectIds.get(key);
ArtifactKey artifactKey = getArtifactKey(session, dependent);
if (artifactKey != null) {
platform.removeAll(artifactKey.getType(), artifactKey.getId());
ReactorProject projectProxy = DefaultReactorProject.adapt(dependent);
platform.addReactorArtifact(artifactKey, projectProxy, null, null);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Add Maven project " + artifactKey);
}
}
}
}
}
// handle rest of dependencies
ArrayList<String> scopes = new ArrayList<>();
scopes.add(Artifact.SCOPE_COMPILE);
Collection<Artifact> artifacts;
try {
artifacts = projectDependenciesResolver.resolve(project, scopes, session);
} catch (MultipleArtifactsNotFoundException e) {
Collection<Artifact> missing = new HashSet<>(e.getMissingArtifacts());
for (Iterator<Artifact> it = missing.iterator(); it.hasNext(); ) {
Artifact a = it.next();
String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
if (projectIds.containsKey(key)) {
it.remove();
}
}
if (!missing.isEmpty()) {
throw new RuntimeException("Could not resolve project dependencies", e);
}
artifacts = e.getResolvedArtifacts();
artifacts.removeAll(e.getMissingArtifacts());
} catch (AbstractArtifactResolutionException e) {
throw new RuntimeException("Could not resolve project dependencies", e);
}
for (Artifact artifact : artifacts) {
String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
if (!projectIds.containsKey(key)) {
File plugin = artifact.getFile();
ArtifactKey artifactKey = getArtifactKey(session, plugin);
if (artifactKey != null) {
platform.addArtifactFile(artifactKey, plugin, null);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Add Maven artifact " + artifactKey);
}
}
}
}
}
}
use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project hudson-2.x by hudson.
the class HudsonTestCase method recipeLoadCurrentPlugin.
/**
* If this test harness is launched for a Hudson plugin, locate the <tt>target/test-classes/the.hpl</tt>
* and add a recipe to install that to the new Hudson.
*
* <p>
* This file is created by <tt>maven-hpi-plugin</tt> at the testCompile phase when the current
* packaging is <tt>hpi</tt>.
*/
protected void recipeLoadCurrentPlugin() throws Exception {
final Enumeration<URL> e = getClass().getClassLoader().getResources("the.hpl");
// nope
if (!e.hasMoreElements())
return;
final URL hpl = e.nextElement();
recipes.add(new Runner() {
@Override
public void decorateHome(HudsonTestCase testCase, File home) throws Exception {
while (e.hasMoreElements()) {
final URL hpl = e.nextElement();
// make the plugin itself available
Manifest m = new Manifest(hpl.openStream());
String shortName = m.getMainAttributes().getValue("Short-Name");
if (shortName == null)
throw new Error(hpl + " doesn't have the Short-Name attribute");
FileUtils.copyURLToFile(hpl, new File(home, "plugins/" + shortName + ".hpl"));
// make dependency plugins available
// TODO: probably better to read POM, but where to read from?
// TODO: this doesn't handle transitive dependencies
// Tom: plugins are now searched on the classpath first. They should be available on
// the compile or test classpath. As a backup, we do a best-effort lookup in the Maven repository
// For transitive dependencies, we could evaluate Plugin-Dependencies transitively.
String dependencies = m.getMainAttributes().getValue("Plugin-Dependencies");
if (dependencies != null) {
MavenEmbedder embedder = new MavenEmbedder(getClass().getClassLoader(), null);
for (String dep : dependencies.split(",")) {
String[] tokens = dep.split(":");
String artifactId = tokens[0];
String version = tokens[1];
File dependencyJar = null;
// need to search multiple group IDs
// TODO: extend manifest to include groupID:artifactID:version
Exception resolutionError = null;
for (String groupId : new String[] { "org.jvnet.hudson.plugins", "org.jvnet.hudson.main" }) {
// first try to find it on the classpath.
// this takes advantage of Maven POM located in POM
URL dependencyPomResource = getClass().getResource("/META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml");
if (dependencyPomResource != null) {
// found it
dependencyJar = Which.jarFile(dependencyPomResource);
break;
} else {
Artifact a;
a = embedder.createArtifact(groupId, artifactId, version, "compile", /*doesn't matter*/
"hpi");
try {
embedder.resolve(a, Arrays.asList(embedder.createRepository("http://maven.glassfish.org/content/groups/public/", "repo")), embedder.getLocalRepository());
dependencyJar = a.getFile();
} catch (AbstractArtifactResolutionException x) {
// could be a wrong groupId
resolutionError = x;
}
}
}
if (dependencyJar == null)
throw new Exception("Failed to resolve plugin: " + dep, resolutionError);
File dst = new File(home, "plugins/" + artifactId + ".hpi");
if (!dst.exists() || dst.lastModified() != dependencyJar.lastModified()) {
FileUtils.copyFile(dependencyJar, dst);
}
}
}
}
}
});
}
use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project sling by apache.
the class BundleInstallFileMojo method resolveBundleFileFromArtifact.
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
private String resolveBundleFileFromArtifact() throws MojoExecutionException {
if (artifactId == null && artifact == null) {
return null;
}
if (artifactId == null) {
String[] tokens = StringUtils.split(artifact, ":");
if (tokens.length != 3 && tokens.length != 4 && tokens.length != 5) {
throw new MojoExecutionException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
}
groupId = tokens[0];
artifactId = tokens[1];
version = tokens[2];
if (tokens.length >= 4)
packaging = tokens[3];
if (tokens.length == 5)
classifier = tokens[4];
}
Artifact packageArtifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
if (pomRemoteRepositories == null) {
pomRemoteRepositories = new ArrayList();
}
List repoList = new ArrayList(pomRemoteRepositories);
if (repositoryUrl != null) {
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
ArtifactRepository remoteRepo = artifactRepositoryFactory.createArtifactRepository(repositoryId, repositoryUrl, repositoryLayout, policy, policy);
repoList.add(remoteRepo);
}
try {
artifactResolver.resolve(packageArtifact, repoList, localRepository);
getLog().info("Resolved artifact to " + packageArtifact.getFile().getAbsolutePath());
} catch (AbstractArtifactResolutionException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
return packageArtifact.getFile().getAbsolutePath();
}
use of org.apache.maven.artifact.resolver.AbstractArtifactResolutionException in project tycho by eclipse.
the class P2DependencyResolver method collectPomDependencies.
private PomDependencyCollector collectPomDependencies(MavenProject project, List<ReactorProject> reactorProjects, MavenSession session) {
Set<String> projectIds = new HashSet<>();
for (ReactorProject p : reactorProjects) {
String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion());
projectIds.add(key);
}
ArrayList<String> scopes = new ArrayList<>();
scopes.add(Artifact.SCOPE_COMPILE);
Collection<Artifact> artifacts;
try {
artifacts = projectDependenciesResolver.resolve(project, scopes, session);
} catch (MultipleArtifactsNotFoundException e) {
Collection<Artifact> missing = new HashSet<>(e.getMissingArtifacts());
for (Iterator<Artifact> it = missing.iterator(); it.hasNext(); ) {
Artifact a = it.next();
String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
if (projectIds.contains(key)) {
it.remove();
}
}
if (!missing.isEmpty()) {
throw new RuntimeException("Could not resolve project dependencies", e);
}
artifacts = e.getResolvedArtifacts();
artifacts.removeAll(e.getMissingArtifacts());
} catch (AbstractArtifactResolutionException e) {
throw new RuntimeException("Could not resolve project dependencies", e);
}
List<Artifact> externalArtifacts = new ArrayList<>(artifacts.size());
for (Artifact artifact : artifacts) {
String key = ArtifactUtils.key(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
if (projectIds.contains(key)) {
// resolved to an older snapshot from the repo, we only want the current project in the reactor
continue;
}
externalArtifacts.add(artifact);
}
PomDependencyProcessor pomDependencyProcessor = new PomDependencyProcessor(session, repositorySystem, resolverFactory, equinox.getService(LocalRepositoryP2Indices.class), getLogger());
return pomDependencyProcessor.collectPomDependencies(project, externalArtifacts);
}
Aggregations