org.apache.maven.artifact.resolver.ArtifactResolutionResult Java Examples
The following examples show how to use
org.apache.maven.artifact.resolver.ArtifactResolutionResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Util.java From jax-maven-plugin with Apache License 2.0 | 6 votes |
static Stream<String> getPluginRuntimeDependencyEntries(AbstractMojo mojo, MavenProject project, Log log, RepositorySystem repositorySystem, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories) { PluginDescriptor pluginDescriptor = (PluginDescriptor) mojo.getPluginContext().get(PLUGIN_DESCRIPTOR); Plugin plugin = project.getBuild().getPluginsAsMap().get(pluginDescriptor.getPluginLookupKey()); List<ArtifactResolutionResult> artifactResolutionResults = plugin // .getDependencies() // .stream() // .map(repositorySystem::createDependencyArtifact) // .map(a -> Util.resolve(log, a, repositorySystem, localRepository, remoteRepositories)) // .collect(Collectors.toList()); Stream<Artifact> originalArtifacts = artifactResolutionResults.stream() .map(ArtifactResolutionResult::getOriginatingArtifact); Stream<Artifact> childArtifacts = artifactResolutionResults.stream() .flatMap(resolutionResult -> resolutionResult.getArtifactResolutionNodes().stream()) .map(ResolutionNode::getArtifact); return Stream.concat(originalArtifacts, childArtifacts).map(Artifact::getFile).map(File::getAbsolutePath); }
Example #2
Source File: MavenHelper.java From sarl with Apache License 2.0 | 6 votes |
/** Resolve the artifacts with the given key. * * @param groupId the group identifier. * @param artifactId the artifact identifier. * @return the discovered artifacts. * @throws MojoExecutionException if resolution cannot be done. * @since 0.8 */ public Set<Artifact> resolve(String groupId, String artifactId) throws MojoExecutionException { final ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setResolveRoot(true); request.setResolveTransitively(true); request.setLocalRepository(getSession().getLocalRepository()); request.setRemoteRepositories(getSession().getCurrentProject().getRemoteArtifactRepositories()); 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(createArtifact(groupId, artifactId)); final ArtifactResolutionResult result = resolve(request); return result.getArtifacts(); }
Example #3
Source File: JApiCmpMojoTest.java From japicmp with Apache License 2.0 | 6 votes |
@Test public void testSimple() throws MojoFailureException, MojoExecutionException { JApiCmpMojo mojo = new JApiCmpMojo(); Version oldVersion = createVersion("groupId", "artifactId", "0.1.0"); Version newVersion = createVersion("groupId", "artifactId", "0.1.1"); PluginParameters pluginParameters = new PluginParameters(false, newVersion, oldVersion, new Parameter(), null, Optional.of(Paths.get(System.getProperty("user.dir"), "target", "simple").toFile()), Optional.<String>absent(), true, null, null, null, null); ArtifactResolver artifactResolver = mock(ArtifactResolver.class); ArtifactResolutionResult artifactResolutionResult = mock(ArtifactResolutionResult.class); Set<Artifact> artifactSet = new HashSet<>(); Artifact resolvedArtifact = mock(Artifact.class); artifactSet.add(resolvedArtifact); when(resolvedArtifact.getFile()).thenReturn(Paths.get(System.getProperty("user.dir"), "target", "guava-18.0.jar").toFile()); when(artifactResolutionResult.getArtifacts()).thenReturn(artifactSet); when(artifactResolver.resolve(Matchers.<ArtifactResolutionRequest>anyObject())).thenReturn(artifactResolutionResult); ArtifactFactory artifactFactory = mock(ArtifactFactory.class); when(artifactFactory.createArtifactWithClassifier(eq("groupId"), eq("artifactId"), eq("0.1.1"), anyString(), anyString())).thenReturn(mock(Artifact.class)); MavenProject mavenProject = mock(MavenProject.class); when(mavenProject.getArtifact()).thenReturn(mock(Artifact.class)); MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mavenProject, mock(MojoExecution.class), "0.0.1", mock(ArtifactMetadataSource.class)); mojo.executeWithParameters(pluginParameters, mavenParameters); assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", "japicmp.diff")), is(true)); assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", "japicmp.xml")), is(true)); assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", "japicmp.html")), is(true)); }
Example #4
Source File: Util.java From yangtools with Eclipse Public License 1.0 | 6 votes |
/** * Read transitive dependencies of given plugin and store them in map. * * @param plugin * plugin to read * @param map * map, where founded transitive dependencies will be stored * @param repoSystem * repository system * @param localRepository * local repository * @param remoteRepos * list of remote repositories */ private static void getPluginTransitiveDependencies(final Plugin plugin, final Map<Artifact, Collection<Artifact>> map, final RepositorySystem repoSystem, final ArtifactRepository localRepository, final List<ArtifactRepository> remoteRepos) { List<Dependency> pluginDependencies = plugin.getDependencies(); for (Dependency dep : pluginDependencies) { Artifact artifact = repoSystem.createDependencyArtifact(dep); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setResolveTransitively(true); request.setLocalRepository(localRepository); request.setRemoteRepositories(remoteRepos); ArtifactResolutionResult result = repoSystem.resolve(request); Set<Artifact> pluginDependencyDependencies = result.getArtifacts(); map.put(artifact, pluginDependencyDependencies); } }
Example #5
Source File: AbstractCodegenMojo.java From cxf with Apache License 2.0 | 6 votes |
private Artifact resolveArbitraryWsdl(Artifact artifact) { ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setResolveRoot(true).setResolveTransitively(false); request.setServers(mavenSession.getRequest().getServers()); request.setMirrors(mavenSession.getRequest().getMirrors()); request.setProxies(mavenSession.getRequest().getProxies()); request.setLocalRepository(mavenSession.getLocalRepository()); request.setRemoteRepositories(mavenSession.getRequest().getRemoteRepositories()); ArtifactResolutionResult result = repositorySystem.resolve(request); Artifact resolvedArtifact = result.getOriginatingArtifact(); if (resolvedArtifact == null && !CollectionUtils.isEmpty(result.getArtifacts())) { resolvedArtifact = result.getArtifacts().iterator().next(); } return resolvedArtifact; }
Example #6
Source File: ArtifactResolver.java From pgpverify-maven-plugin with Apache License 2.0 | 5 votes |
private Artifact resolveSignature(Artifact artifact, SignatureRequirement requirement) throws MojoExecutionException { final Artifact aAsc = repositorySystem.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier()); aAsc.setArtifactHandler(new AscArtifactHandler(aAsc)); final ArtifactResolutionResult ascResult = request(aAsc, remoteRepositoriesIgnoreCheckSum); if (ascResult.isSuccess()) { LOG.debug("{} {}", aAsc, aAsc.getFile()); return aAsc; } switch (requirement) { case NONE: LOG.warn("No signature for {}", artifact.getId()); break; case STRICT: LOG.debug("No signature for {}", artifact.getId()); // no action needed here. If we need to show a warning message, // we will determine this when verifying signatures (or lack thereof) break; case REQUIRED: LOG.error("No signature for {}", artifact.getId()); throw new MojoExecutionException("No signature for " + artifact.getId()); default: throw new UnsupportedOperationException("Unsupported signature requirement."); } return null; }
Example #7
Source File: A_ModuleGenerator.java From deadcode4j with Apache License 2.0 | 5 votes |
private void enableArtifactResolving() { reset(this.repositorySystem); when(this.repositorySystem.resolve(any(ArtifactResolutionRequest.class))).thenAnswer(new Answer<ArtifactResolutionResult>() { @Override public ArtifactResolutionResult answer(InvocationOnMock invocationOnMock) throws Throwable { ArtifactResolutionRequest request = (ArtifactResolutionRequest) invocationOnMock.getArguments()[0]; request.getArtifact().setResolved(true); return new ArtifactResolutionResult(); } }); }
Example #8
Source File: A_ModuleGenerator.java From deadcode4j with Apache License 2.0 | 5 votes |
private void disableArtifactResolving() { when(this.repositorySystem.resolve(any(ArtifactResolutionRequest.class))).thenAnswer(new Answer<ArtifactResolutionResult>() { @Override public ArtifactResolutionResult answer(InvocationOnMock invocationOnMock) throws Throwable { ArtifactResolutionRequest request = (ArtifactResolutionRequest) invocationOnMock.getArguments()[0]; ArtifactResolutionResult artifactResolutionResult = new ArtifactResolutionResult(); artifactResolutionResult.addMissingArtifact(request.getArtifact()); return artifactResolutionResult; } }); }
Example #9
Source File: ModuleGenerator.java From deadcode4j with Apache License 2.0 | 5 votes |
/** * Creates a new <code>ModuleGenerator</code>. * * @param repositorySystem the given <code>RepositorySystem</code> is required to resolve the class path of the * examined maven projects * @since 2.0.0 */ public ModuleGenerator(@Nonnull final RepositorySystem repositorySystem) { packagingHandlers.put("pom", new PomPackagingHandler()); packagingHandlers.put("war", new WarPackagingHandler()); artifactResolverCache = new SequentialLoadingCache<Artifact, File>(NonNullFunctions.toFunction(new NonNullFunction<Artifact, Optional<File>>() { @Nonnull @Override public Optional<File> apply(@Nonnull Artifact input) { if (!input.isResolved()) { ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setResolveRoot(true); request.setResolveTransitively(false); request.setArtifact(input); ArtifactResolutionResult artifactResolutionResult = repositorySystem.resolve(request); if (!artifactResolutionResult.isSuccess()) { logger.warn(" Failed to resolve [{}]; some analyzers may not work properly.", getVersionedKeyFor(input)); return absent(); } } File classPathElement = input.getFile(); if (classPathElement == null) { logger.warn(" No valid path to [{}] found; some analyzers may not work properly.", getVersionedKeyFor(input)); return absent(); } return of(classPathElement); } })); }
Example #10
Source File: JApiCmpMojoTest.java From japicmp with Apache License 2.0 | 5 votes |
@Test public void testIgnoreMissingVersions() throws MojoFailureException, IOException, MojoExecutionException { JApiCmpMojo mojo = new JApiCmpMojo(); Version oldVersion = createVersion("groupId", "artifactId", "0.1.0"); Version newVersion = createVersion("groupId", "artifactId", "0.1.1"); Parameter parameterParam = new Parameter(); parameterParam.setIgnoreMissingNewVersion(true); parameterParam.setIgnoreMissingOldVersion(true); PluginParameters pluginParameters = new PluginParameters(false, newVersion, oldVersion, parameterParam, null, Optional.of(Paths.get(System.getProperty("user.dir"), "target", "simple").toFile()), Optional.<String>absent(), true, null, null, null, null); ArtifactResolver artifactResolver = mock(ArtifactResolver.class); ArtifactResolutionResult artifactResolutionResult = mock(ArtifactResolutionResult.class); Set<Artifact> artifactSet = new HashSet<>(); when(artifactResolutionResult.getArtifacts()).thenReturn(artifactSet); when(artifactResolver.resolve(Matchers.<ArtifactResolutionRequest>anyObject())).thenReturn(artifactResolutionResult); ArtifactFactory artifactFactory = mock(ArtifactFactory.class); when(artifactFactory.createArtifactWithClassifier(eq("groupId"), eq("artifactId"), eq("0.1.1"), anyString(), anyString())).thenReturn(mock(Artifact.class)); MojoExecution mojoExecution = mock(MojoExecution.class); String executionId = "ignoreMissingVersions"; when(mojoExecution.getExecutionId()).thenReturn(executionId); MavenProject mavenProject = mock(MavenProject.class); when(mavenProject.getArtifact()).thenReturn(mock(Artifact.class)); MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mavenProject, mojoExecution, "0.0.1", mock(ArtifactMetadataSource.class)); mojo.executeWithParameters(pluginParameters, mavenParameters); assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", executionId + ".diff")), is(false)); assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", executionId + ".xml")), is(false)); assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", "simple", "japicmp", executionId + ".html")), is(false)); }
Example #11
Source File: JApiCmpMojoTest.java From japicmp with Apache License 2.0 | 5 votes |
@Test public void testNoXmlAndNoHtmlNoDiffReport() throws MojoFailureException, MojoExecutionException { JApiCmpMojo mojo = new JApiCmpMojo(); Version oldVersion = createVersion("groupId", "artifactId", "0.1.0"); Version newVersion = createVersion("groupId", "artifactId", "0.1.1"); Parameter parameter = new Parameter(); parameter.setSkipHtmlReport(true); parameter.setSkipXmlReport(true); parameter.setSkipDiffReport(true); String reportDir = "noXmlAndNoHtmlNoDiffReport"; PluginParameters pluginParameters = new PluginParameters(false, newVersion, oldVersion, parameter, null, Optional.of(Paths.get(System.getProperty("user.dir"), "target", reportDir).toFile()), Optional.<String>absent(), true, null, null, null, null); ArtifactResolver artifactResolver = mock(ArtifactResolver.class); ArtifactResolutionResult artifactResolutionResult = mock(ArtifactResolutionResult.class); Set<Artifact> artifactSet = new HashSet<>(); Artifact resolvedArtifact = mock(Artifact.class); artifactSet.add(resolvedArtifact); when(resolvedArtifact.getFile()).thenReturn(Paths.get(System.getProperty("user.dir"), "target", "guava-18.0.jar").toFile()); when(artifactResolutionResult.getArtifacts()).thenReturn(artifactSet); when(artifactResolver.resolve(Matchers.<ArtifactResolutionRequest>anyObject())).thenReturn(artifactResolutionResult); ArtifactFactory artifactFactory = mock(ArtifactFactory.class); when(artifactFactory.createArtifactWithClassifier(eq("groupId"), eq("artifactId"), eq("0.1.1"), anyString(), anyString())).thenReturn(mock(Artifact.class)); MavenProject mavenProject = mock(MavenProject.class); when(mavenProject.getArtifact()).thenReturn(mock(Artifact.class)); MavenParameters mavenParameters = new MavenParameters(new ArrayList<ArtifactRepository>(), artifactFactory, mock(ArtifactRepository.class), artifactResolver, mavenProject, mock(MojoExecution.class), "0.0.1", mock(ArtifactMetadataSource.class)); mojo.executeWithParameters(pluginParameters, mavenParameters); assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", reportDir, "japicmp", "japicmp.diff")), is(false)); assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", reportDir, "japicmp", "japicmp.xml")), is(false)); assertThat(Files.exists(Paths.get(System.getProperty("user.dir"), "target", reportDir, "japicmp", "japicmp.html")), is(false)); }
Example #12
Source File: AbstractCodeGeneratorMojo.java From cxf with Apache License 2.0 | 5 votes |
private Artifact resolveRemoteWadlArtifact(Artifact artifact) throws MojoExecutionException { /** * First try to find the artifact in the reactor projects of the maven session. * So an artifact that is not yet built can be resolved */ List<MavenProject> rProjects = mavenSession.getProjects(); for (MavenProject rProject : rProjects) { if (artifact.getGroupId().equals(rProject.getGroupId()) && artifact.getArtifactId().equals(rProject.getArtifactId()) && artifact.getVersion().equals(rProject.getVersion())) { Set<Artifact> artifacts = rProject.getArtifacts(); for (Artifact pArtifact : artifacts) { if ("wadl".equals(pArtifact.getType())) { return pArtifact; } } } } ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setResolveRoot(true).setResolveTransitively(false); request.setServers(mavenSession.getRequest().getServers()); request.setMirrors(mavenSession.getRequest().getMirrors()); request.setProxies(mavenSession.getRequest().getProxies()); request.setLocalRepository(mavenSession.getLocalRepository()); request.setRemoteRepositories(mavenSession.getRequest().getRemoteRepositories()); ArtifactResolutionResult result = repositorySystem.resolve(request); Artifact resolvedArtifact = result.getOriginatingArtifact(); if (resolvedArtifact == null && !CollectionUtils.isEmpty(result.getArtifacts())) { resolvedArtifact = result.getArtifacts().iterator().next(); } return resolvedArtifact; }
Example #13
Source File: ArtifactResolver.java From pgpverify-maven-plugin with Apache License 2.0 | 5 votes |
private Artifact resolveArtifact(Artifact artifact) { final ArtifactResolutionResult result = request(artifact, remoteRepositories); if (!result.isSuccess()) { result.getExceptions().forEach(e -> LOG.warn("Failed to resolve {}: {}", artifact.getId(), e.getMessage())); } return artifact; }
Example #14
Source File: ArtifactResolver.java From pgpverify-maven-plugin with Apache License 2.0 | 5 votes |
private Artifact resolvePom(Artifact artifact) { final Artifact pomArtifact = repositorySystem.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); final ArtifactResolutionResult result = request(pomArtifact, remoteRepositories); if (!result.isSuccess()) { result.getExceptions().forEach( e -> LOG.debug("Failed to resolve pom {}: {}", pomArtifact.getId(), e.getMessage())); } return pomArtifact; }
Example #15
Source File: Util.java From jax-maven-plugin with Apache License 2.0 | 5 votes |
static ArtifactResolutionResult resolve(Log log, Artifact artifact, RepositorySystem repositorySystem, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories) { ArtifactResolutionRequest request = new ArtifactResolutionRequest() // .setArtifact(artifact) // .setLocalRepository(localRepository) // .setRemoteRepositories(remoteRepositories) // .setResolveTransitively(true) // .addListener(Util.createLoggingResolutionListener(log)); return repositorySystem.resolve(request); }
Example #16
Source File: UtilTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void checkClasspathTest() throws Exception { final MavenProject project = mock(MavenProject.class); final Plugin plugin = mock(Plugin.class); final RepositorySystem repoSystem = mock(RepositorySystem.class); final ArtifactRepository localRepo = mock(ArtifactRepository.class); final ArtifactResolutionResult artifactResolResult = mock(ArtifactResolutionResult.class); final Artifact artifact = mock(Artifact.class); final Dependency dep = mock(Dependency.class); final List<ArtifactRepository> remoteRepos = new ArrayList<>(); remoteRepos.add(localRepo); final Set<Artifact> artifacts = new HashSet<>(); artifacts.add(artifact); final List<Dependency> listDepcy = new ArrayList<>(); listDepcy.add(dep); when(project.getPlugin(anyString())).thenReturn(plugin); when(plugin.getDependencies()).thenReturn(listDepcy); when(artifact.getArtifactId()).thenReturn("artifactId"); when(artifact.getGroupId()).thenReturn("groupId"); when(artifact.getVersion()).thenReturn("SNAPSHOT"); when(repoSystem.createDependencyArtifact(dep)).thenReturn(artifact); when(repoSystem.resolve(any(ArtifactResolutionRequest.class))).thenReturn(artifactResolResult); when(artifactResolResult.getArtifacts()).thenReturn(artifacts); when(project.getDependencyArtifacts()).thenReturn(artifacts); Util.checkClasspath(project, repoSystem, localRepo, remoteRepos); assertEquals(1, artifacts.size()); assertEquals(1, remoteRepos.size()); assertEquals(1, listDepcy.size()); }
Example #17
Source File: PreCompileMojo.java From jprotobuf with Apache License 2.0 | 5 votes |
/** * Resolve the executable dependencies for the specified project * * @param executablePomArtifact the project's POM * @return a set of Artifacts * @throws MojoExecutionException if a failure happens */ private Set<Artifact> resolveExecutableDependencies( Artifact executablePomArtifact ) throws MojoExecutionException { Set<Artifact> executableDependencies; try { MavenProject executableProject = this.projectBuilder.buildFromRepository( executablePomArtifact, this.remoteRepositories, this.localRepository ); // get all of the dependencies for the executable project List<Dependency> dependencies = executableProject.getDependencies(); // make Artifacts of all the dependencies Set<Artifact> dependencyArtifacts = MavenMetadataSource.createArtifacts( this.artifactFactory, dependencies, null, null, null ); // not forgetting the Artifact of the project itself dependencyArtifacts.add( executableProject.getArtifact() ); // resolve all dependencies transitively to obtain a comprehensive list of assemblies ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencyArtifacts, executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, null, Collections.emptyList() ); executableDependencies = result.getArtifacts(); } catch ( Exception ex ) { throw new MojoExecutionException( "Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex ); } return executableDependencies; }
Example #18
Source File: ArtifactUtils.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 5 votes |
public static Collection<Artifact> resolveTransitively( final ArtifactFactory artifactFactory, final ArtifactResolver artifactResolver, final ArtifactRepository localRepository, final ArtifactMetadataSource artifactMetadataSource, final Dependency[] dependencies, final MavenProject project) throws InvalidDependencyVersionException, ArtifactResolutionException, ArtifactNotFoundException { if (dependencies == null) { return Collections.emptyList(); } @SuppressWarnings("unchecked") final Set<Artifact> artifacts = MavenMetadataSource.createArtifacts( artifactFactory, Arrays.asList(dependencies), "runtime", null, project); final ArtifactResolutionResult artifactResolutionResult = artifactResolver .resolveTransitively(artifacts, project.getArtifact(), project.getRemoteArtifactRepositories(), localRepository, artifactMetadataSource); @SuppressWarnings("unchecked") final Set<Artifact> resolvedArtifacts = artifactResolutionResult .getArtifacts(); return resolvedArtifacts; }
Example #19
Source File: ExtensionClassLoaderFactory.java From nifi-maven with Apache License 2.0 | 5 votes |
private Set<URL> toURLs(final Artifact artifact) throws MojoExecutionException { final Set<URL> urls = new HashSet<>(); final File artifactFile = artifact.getFile(); if (artifactFile == null) { getLog().debug("Attempting to resolve Artifact " + artifact + " because it has no File associated with it"); final ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setLocalRepository(localRepo); request.setArtifact(artifact); final ArtifactResolutionResult result = artifactResolver.resolve(request); if (!result.isSuccess()) { throw new MojoExecutionException("Could not resolve local dependency " + artifact); } getLog().debug("Resolved Artifact " + artifact + " to " + result.getArtifacts()); for (final Artifact resolved : result.getArtifacts()) { urls.addAll(toURLs(resolved)); } } else { try { final URL url = artifact.getFile().toURI().toURL(); getLog().debug("Adding URL " + url + " to ClassLoader"); urls.add(url); } catch (final MalformedURLException mue) { throw new MojoExecutionException("Failed to convert File " + artifact.getFile() + " into URL", mue); } } return urls; }
Example #20
Source File: GenerateBomMojo.java From sundrio with Apache License 2.0 | 5 votes |
private Set<Artifact> resolve(final Set<Artifact> dependencies) { ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(getProject().getArtifact()); request.setArtifactDependencies(dependencies); request.setLocalRepository(localRepository); request.setRemoteRepositories(remoteRepositories); request.setManagedVersionMap(getProject().getManagedVersionMap()); request.setResolveTransitively(true); ArtifactResolutionResult result = artifactResolver.resolve(request); return result.getArtifacts(); }
Example #21
Source File: MavenEmbedder.java From netbeans with Apache License 2.0 | 5 votes |
/** * * @param sources * @param remoteRepositories - these instances need to be properly mirrored and proxied. Either by creating via EmbedderFactory.createRemoteRepository() * or by using instances from MavenProject * @param localRepository * @throws ArtifactResolutionException * @throws ArtifactNotFoundException */ public void resolve(Artifact sources, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository) throws ArtifactResolutionException, ArtifactNotFoundException { setUpLegacySupport(); ArtifactResolutionRequest req = new ArtifactResolutionRequest(); req.setLocalRepository(localRepository); req.setRemoteRepositories(remoteRepositories); req.setArtifact(sources); req.setOffline(isOffline()); ArtifactResolutionResult result = repositorySystem.resolve(req); normalizePath(sources); // XXX check result for exceptions and throw them now? for (Exception ex : result.getExceptions()) { LOG.log(Level.FINE, null, ex); } }
Example #22
Source File: JpaSchemaGeneratorMojo.java From jpa-schema-maven-plugin with Apache License 2.0 | 4 votes |
private ClassLoader getProjectClassLoader() throws MojoExecutionException { try { // compiled classes List<String> classfiles = this.project.getCompileClasspathElements(); if (this.scanTestClasses) { classfiles.addAll(this.project.getTestClasspathElements()); } // classpath to url List<URL> classURLs = new ArrayList<>(classfiles.size()); for (String classfile : classfiles) { classURLs.add(new File(classfile).toURI().toURL()); } // dependency artifacts to url ArtifactResolutionRequest sharedreq = new ArtifactResolutionRequest().setResolveRoot(true) .setResolveTransitively(true) .setLocalRepository(this.session.getLocalRepository()) .setRemoteRepositories(this.project.getRemoteArtifactRepositories()); ArtifactRepository repository = this.session.getLocalRepository(); Set<Artifact> artifacts = this.project.getDependencyArtifacts(); for (Artifact artifact : artifacts) { if (!Artifact.SCOPE_TEST.equalsIgnoreCase(artifact.getScope())) { ArtifactResolutionRequest request = new ArtifactResolutionRequest(sharedreq).setArtifact(artifact); ArtifactResolutionResult result = this.repositorySystem.resolve(request); if (result.isSuccess()) { File file = repository.find(artifact).getFile(); if (file != null && file.isFile() && file.canRead()) { classURLs.add(file.toURI().toURL()); } } } } for (URL url : classURLs) { this.log.info(" * classpath: " + url); } return new URLClassLoader(classURLs.toArray(EMPTY_URLS), this.getClass().getClassLoader()); } catch (Exception e) { this.log.error(e); throw new MojoExecutionException("Error while creating classloader", e); } }
Example #23
Source File: MavenHelper.java From sarl with Apache License 2.0 | 2 votes |
/** Resolve an artifact. * * @param request the definition of the resolution request. * @return the result. * @throws MojoExecutionException if the resolution cannot be done. * @since 0.8 */ public ArtifactResolutionResult resolve(ArtifactResolutionRequest request) throws MojoExecutionException { return this.repositorySystem.resolve(request); }