List of usage examples for org.apache.maven.artifact.resolver MultipleArtifactsNotFoundException getMissingArtifacts
public List<Artifact> getMissingArtifacts()
From source file:com.ning.maven.plugins.dependencyversionscheck.AbstractDependencyVersionsMojo.java
License:Apache License
/** * Reports an exception thrown by the resolution process. *//* w w w . ja v a2 s .c om*/ private void logArtifactResolutionException(AbstractArtifactResolutionException ex) { if (ex instanceof MultipleArtifactsNotFoundException) { MultipleArtifactsNotFoundException multiEx = (MultipleArtifactsNotFoundException) ex; StringBuilder builder = new StringBuilder(); for (Iterator iter = multiEx.getMissingArtifacts().iterator(); iter.hasNext();) { Artifact artifact = (Artifact) iter.next(); builder.append(getQualifiedName(artifact)); if (iter.hasNext()) { builder.append(", "); } } LOG.warn("Could not find artifacts '{}'", builder); } else { LOG.warn("Could not find artifact '{}'", getQualifiedName(ex.getArtifact())); } LOG.debug("Error:", ex); }
From source file:io.sarl.maven.compiler.MavenHelper.java
License:Apache License
/** Replies the dependencies for the given artifact. * * @param artifactId - the artifact identifier. * @param plugins indicates if the map of the plugin artifacts must be explore (if true) or the dependency * artifacts (if false)./*from www . j a v a2 s . c om*/ * @return the dependencies. * @throws MojoExecutionException if the resolution cannot be done. */ public Set<Artifact> resolveDependencies(String artifactId, boolean plugins) throws MojoExecutionException { final Artifact pluginArtifact; if (plugins) { pluginArtifact = getSession().getCurrentProject().getPluginArtifactMap().get(artifactId); } else { pluginArtifact = getSession().getCurrentProject().getArtifactMap().get(artifactId); } final ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setResolveRoot(false); request.setResolveTransitively(true); request.setLocalRepository(getSession().getLocalRepository()); request.setOffline(getSession().isOffline()); request.setForceUpdate(getSession().getRequest().isUpdateSnapshots()); request.setServers(getSession().getRequest().getServers()); request.setMirrors(getSession().getRequest().getMirrors()); request.setProxies(getSession().getRequest().getProxies()); request.setArtifact(pluginArtifact); final ArtifactResolutionResult result = this.repositorySystem.resolve(request); try { this.resolutionErrorHandler.throwErrors(request, result); } catch (MultipleArtifactsNotFoundException e) { final Collection<Artifact> missing = new HashSet<>(e.getMissingArtifacts()); if (!missing.isEmpty()) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } } catch (ArtifactResolutionException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } return result.getArtifacts(); }
From source file:org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver.java
License:Open Source License
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<String, MavenProject>( 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);//from ww w .j a v a2s. c o m } // 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<String>(); scopes.add(Artifact.SCOPE_COMPILE); Collection<Artifact> artifacts; try { artifacts = projectDependenciesResolver.resolve(project, scopes, session); } catch (MultipleArtifactsNotFoundException e) { Collection<Artifact> missing = new HashSet<Artifact>(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); } } } } } }
From source file:org.eclipse.tycho.core.osgitools.targetplatform.LocalTargetPlatformResolver.java
License:Open Source License
private void addDependencies(MavenSession session, MavenProject project, DefaultTargetPlatform 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<String, MavenProject>( 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);/*from w ww .ja va2 s . c o m*/ } // 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<String>(); scopes.add(Artifact.SCOPE_COMPILE); Collection<Artifact> artifacts; try { artifacts = projectDependenciesResolver.resolve(project, scopes, session); } catch (MultipleArtifactsNotFoundException e) { Collection<Artifact> missing = new HashSet<Artifact>(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); } } } } } }
From source file:org.eclipse.tycho.p2.facade.P2TargetPlatformResolver.java
License:Open Source License
protected TargetPlatform doResolvePlatform(final MavenSession session, final MavenProject project, List<ReactorProject> reactorProjects, List<Dependency> dependencies, P2Resolver resolver) { TargetPlatformConfiguration configuration = (TargetPlatformConfiguration) project .getContextValue(TychoConstants.CTX_TARGET_PLATFORM_CONFIGURATION); resolver.setRepositoryCache(repositoryCache); resolver.setOffline(session.isOffline()); resolver.setLogger(new P2Logger() { public void debug(String message) { if (message != null && message.length() > 0) { getLogger().info(message); // TODO }/* w w w. j ava 2 s . c om*/ } public void info(String message) { if (message != null && message.length() > 0) { getLogger().info(message); } } public boolean isDebugEnabled() { return getLogger().isDebugEnabled() && DebugUtils.isDebugEnabled(session, project); } }); Map<File, ReactorProject> projects = new HashMap<File, ReactorProject>(); resolver.setLocalRepositoryLocation(new File(session.getLocalRepository().getBasedir())); resolver.setEnvironments(getEnvironments(configuration)); for (ReactorProject otherProject : reactorProjects) { if (getLogger().isDebugEnabled()) { getLogger().debug("P2resolver.addMavenProject " + otherProject.getId()); } projects.put(otherProject.getBasedir(), otherProject); resolver.addReactorArtifact(new ReactorArtifactFacade(otherProject, null)); Map<String, Set<Object>> dependencyMetadata = otherProject.getDependencyMetadata(); if (dependencyMetadata != null) { for (String classifier : dependencyMetadata.keySet()) { resolver.addReactorArtifact(new ReactorArtifactFacade(otherProject, classifier)); } } } if (dependencies != null) { for (Dependency dependency : dependencies) { resolver.addDependency(dependency.getType(), dependency.getArtifactId(), dependency.getVersion()); } } if (TargetPlatformConfiguration.POM_DEPENDENCIES_CONSIDER.equals(configuration.getPomDependencies())) { Set<String> projectIds = new HashSet<String>(); for (ReactorProject p : reactorProjects) { String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion()); projectIds.add(key); } ArrayList<String> scopes = new ArrayList<String>(); scopes.add(Artifact.SCOPE_COMPILE); Collection<Artifact> artifacts; try { artifacts = projectDependenciesResolver.resolve(project, scopes, session); } catch (MultipleArtifactsNotFoundException e) { Collection<Artifact> missing = new HashSet<Artifact>(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<Artifact>(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); } addToP2ViewOfLocalRepository(session, externalArtifacts, project); for (Artifact artifact : externalArtifacts) { /* * TODO This call generates p2 metadata for the POM dependencies. If the artifact * has an attached p2metadata.xml, we should reuse that metadata. */ /* * TODO The generated metadata is "depencency only" metadata. (Just by coincidence * this is currently full metadata.) Since this POM depencency metadata may be * copied into an eclipse-repository or p2-enabled RCP installation, it shall be * documented that the generated metadata must be full metadata. */ if (getLogger().isDebugEnabled()) { getLogger().debug("P2resolver.addMavenArtifact " + artifact.toString()); } resolver.addMavenArtifact(new ArtifactFacade(artifact)); } } for (ArtifactRepository repository : project.getRemoteArtifactRepositories()) { try { URI uri = new URL(repository.getUrl()).toURI(); if (repository.getLayout() instanceof P2ArtifactRepositoryLayout) { if (session.isOffline()) { getLogger().debug("Offline mode, using local cache only for repository " + repository.getId() + " (" + repository.getUrl() + ")"); } try { Authentication auth = repository.getAuthentication(); if (auth != null) { resolver.setCredentials(uri, auth.getUsername(), auth.getPassword()); } resolver.addP2Repository(uri); getLogger().debug( "Added p2 repository " + repository.getId() + " (" + repository.getUrl() + ")"); } catch (Exception e) { String msg = "Failed to access p2 repository " + repository.getId() + " (" + repository.getUrl() + "), will try to use local cache. Reason: " + e.getMessage(); if (getLogger().isDebugEnabled()) { getLogger().warn(msg, e); } else { getLogger().warn(msg); } } } else { if (!configuration.isIgnoreTychoRepositories() && !session.isOffline()) { try { MavenRepositoryReader reader = plexus.lookup(MavenRepositoryReader.class); reader.setArtifactRepository(repository); reader.setLocalRepository(session.getLocalRepository()); String repositoryKey = getRepositoryKey(repository); TychoRepositoryIndex index = repositoryCache.getRepositoryIndex(repositoryKey); if (index == null) { index = new DefaultTychoRepositoryIndex(reader); repositoryCache.putRepositoryIndex(repositoryKey, index); } resolver.addMavenRepository(uri, index, reader); getLogger().debug("Added Maven repository " + repository.getId() + " (" + repository.getUrl() + ")"); } catch (FileNotFoundException e) { // it happens } catch (Exception e) { getLogger().debug("Unable to initialize remote Tycho repository", e); } } else { String msg = "Ignoring Maven repository " + repository.getId() + " (" + repository.getUrl() + ")"; if (session.isOffline()) { msg += " while in offline mode"; } getLogger().debug(msg); } } } catch (MalformedURLException e) { getLogger().warn("Could not parse repository URL", e); } catch (URISyntaxException e) { getLogger().warn("Could not parse repository URL", e); } } Target target = configuration.getTarget(); if (target != null) { Set<URI> uris = new HashSet<URI>(); for (Target.Location location : target.getLocations()) { String type = location.getType(); if (!"InstallableUnit".equalsIgnoreCase(type)) { getLogger().warn("Target location type: " + type + " is not supported"); continue; } for (Target.Repository repository : location.getRepositories()) { try { URI uri = new URI(getMirror(repository, session.getRequest().getMirrors())); if (uris.add(uri)) { if (session.isOffline()) { getLogger().debug("Ignored repository " + uri + " while in offline mode"); } else { String id = repository.getId(); if (id != null) { Server server = session.getSettings().getServer(id); if (server != null) { resolver.setCredentials(uri, server.getUsername(), server.getPassword()); } else { getLogger().info("Unknown server id=" + id + " for repository location=" + repository.getLocation()); } } try { resolver.addP2Repository(uri); } catch (Exception e) { String msg = "Failed to access p2 repository " + uri + ", will try to use local cache. Reason: " + e.getMessage(); if (getLogger().isDebugEnabled()) { getLogger().warn(msg, e); } else { getLogger().warn(msg); } } } } } catch (URISyntaxException e) { getLogger().debug("Could not parse repository URL", e); } } for (Target.Unit unit : location.getUnits()) { String versionRange; if ("0.0.0".equals(unit.getVersion())) { versionRange = unit.getVersion(); } else { // perfect version match versionRange = "[" + unit.getVersion() + "," + unit.getVersion() + "]"; } resolver.addDependency(P2Resolver.TYPE_INSTALLABLE_UNIT, unit.getId(), versionRange); } } } if (!isAllowConflictingDependencies(project, configuration)) { List<P2ResolutionResult> results = resolver.resolveProject(project.getBasedir()); MultiEnvironmentTargetPlatform multiPlatform = new MultiEnvironmentTargetPlatform(); // FIXME this is just wrong for (int i = 0; i < configuration.getEnvironments().size(); i++) { TargetEnvironment environment = configuration.getEnvironments().get(i); P2ResolutionResult result = results.get(i); DefaultTargetPlatform platform = newDefaultTargetPlatform(session, projects, result); // addProjects( session, platform ); multiPlatform.addPlatform(environment, platform); } return multiPlatform; } else { P2ResolutionResult result = resolver.collectProjectDependencies(project.getBasedir()); return newDefaultTargetPlatform(session, projects, result); } }
From source file:org.eclipse.tycho.p2.resolver.P2DependencyResolver.java
License:Open Source License
private PomDependencyCollector collectPomDependencies(MavenProject project, List<ReactorProject> reactorProjects, MavenSession session) { Set<String> projectIds = new HashSet<String>(); for (ReactorProject p : reactorProjects) { String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion()); projectIds.add(key);// w ww . j a v a2s. c o m } ArrayList<String> scopes = new ArrayList<String>(); scopes.add(Artifact.SCOPE_COMPILE); Collection<Artifact> artifacts; try { artifacts = projectDependenciesResolver.resolve(project, scopes, session); } catch (MultipleArtifactsNotFoundException e) { Collection<Artifact> missing = new HashSet<Artifact>(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<Artifact>(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); }
From source file:org.eclipse.tycho.p2.resolver.P2TargetPlatformResolver.java
License:Open Source License
private void addPomDependenciesToTargetPlatform(MavenProject project, TargetPlatformBuilder resolutionContext, List<ReactorProject> reactorProjects, MavenSession session) { Set<String> projectIds = new HashSet<String>(); for (ReactorProject p : reactorProjects) { String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion()); projectIds.add(key);/*from w w w .j a v a 2 s.c om*/ } ArrayList<String> scopes = new ArrayList<String>(); scopes.add(Artifact.SCOPE_COMPILE); Collection<Artifact> artifacts; try { artifacts = projectDependenciesResolver.resolve(project, scopes, session); } catch (MultipleArtifactsNotFoundException e) { Collection<Artifact> missing = new HashSet<Artifact>(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<Artifact>(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); } List<Artifact> explicitArtifacts = MavenDependencyInjector.filterInjectedDependencies(externalArtifacts); // needed when the resolution is done again for the test runtime PomDependencyProcessor pomDependencyProcessor = new PomDependencyProcessor(session, repositorySystem, equinox.getService(LocalRepositoryP2Indices.class), getLogger()); pomDependencyProcessor.addPomDependenciesToResolutionContext(project, explicitArtifacts, resolutionContext); }