public void resolve(BuildStrategy builder) { List<Artifact> initialArtifacts = new ArrayList<>(); initialArtifacts.addAll(mavenProject.getArtifacts()); if (pluginDependencies != null) { initialArtifacts.addAll(pluginDependencies); if (artifact.getClassifier() != null && artifact.getClassifier().equals("sources")) { artifacts.add(artifact); } else { artifacts.add(repositorySystem.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), "sources")); ArtifactResolutionRequest request = new ArtifactResolutionRequest() .setLocalRepository(localRepository) .setRemoteRepositories(new ArrayList<>(remoteRepositories)) .setArtifact(artifact); ArtifactResolutionResult result = repositorySystem.resolve(request); for (Artifact resolvedArtifact : result.getArtifacts()) { if (resolvedArtifact.getFile() != null) { File file = resolvedArtifact.getFile(); for (String sourceRoot : mavenProject.getCompileSourceRoots()) { builder.addSourcesDirectory(new File(sourceRoot).getAbsolutePath());
private String[] createDaemonClassPath() { Artifact toolArtifact = pluginArtifacts.stream() .filter(artifact -> artifact.getGroupId().equals("org.teavm") && artifact.getArtifactId().equals("teavm-tooling")) .findFirst() .orElse(null); if (toolArtifact == null) { return new String[0]; } ArtifactResolutionResult resolutionResult = repositorySystem.resolve(new ArtifactResolutionRequest() .setLocalRepository(localRepository) .setRemoteRepositories(new ArrayList<>(remoteRepositories)) .setResolveTransitively(true) .setResolveRoot(true) .setArtifact(toolArtifact)); if (!resolutionResult.isSuccess()) { return new String[0]; } return resolutionResult.getArtifacts().stream() .map(artifact -> artifact.getFile().getAbsolutePath()) .toArray(String[]::new); }
if ( result.hasMetadataResolutionExceptions() ) throw result.getMetadataResolutionException( 0 ); if ( result.hasCircularDependencyExceptions() ) throw result.getCircularDependencyException( 0 ); if ( result.hasVersionRangeViolations() ) throw result.getVersionRangeViolation( 0 ); if ( result.hasErrorArtifactExceptions() ) throw result.getErrorArtifactExceptions().get( 0 ); if ( result.hasMissingArtifacts() ) throw new MultipleArtifactsNotFoundException( request.getArtifact(), toList( result.getArtifacts() ), result.getMissingArtifacts(), request.getRemoteRepositories() ); if ( result.hasExceptions() ) + result.getExceptions(), request.getArtifact(), request.getRemoteRepositories() );
ArtifactResolutionResult result = new ArtifactResolutionResult(); result.addErrorArtifactException( e ); return result; result.addMissingArtifact( request.getArtifact() ); return result; new ArtifactResolutionException( "Unable to get dependency information for " + rootArtifact.getId() + ": " + e.getMessage(), rootArtifact, metadataRequest.getRemoteRepositories(), e ); result.addMetadataResolutionException( are ); return result; result.addArtifact( rootArtifact ); if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions() ) if ( result.getArtifactResolutionNodes() != null ) CountDownLatch latch = new CountDownLatch( result.getArtifactResolutionNodes().size() ); for ( ResolutionNode node : result.getArtifactResolutionNodes() ) result.addErrorArtifactException( new ArtifactResolutionException( "Resolution interrupted", rootArtifact, e ) ); allArtifacts.addAll( result.getArtifacts() ); result.setArtifacts( allArtifacts );
throws Exception final String rootDirectory = ResourceUtils.normalizePath(this.project.getBasedir().toString()); final File classpathFile = new File(rootDirectory, ".classpath"); final FileWriter fileWriter = new FileWriter(classpathFile); project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging()); projectArtifactIds.add(projectArtifact.getId()); if (!projectArtifactIds.contains(artifact.getId()) && !project.getGroupId().equals(artifact.getGroupId())) allArtifacts.addAll(result.getArtifacts());
ArtifactResolutionRequest request = new ArtifactResolutionRequest() .setArtifact(requiredArtifacts.iterator().next()) .setResolveRoot(true) .setResolveTransitively(true) .setArtifactDependencies(requiredArtifacts) .setLocalRepository(session.getLocalRepository()) .setRemoteRepositories(project.getRemoteArtifactRepositories()); ArtifactResolutionResult resolutionResult = repositorySystem.resolve(request); resolutionErrorHandler.throwErrors(request, resolutionResult); if (resolutionResult == null || resolutionResult.getArtifacts() == null) { throw new IllegalStateException("Annotation processing artifacts were not resolved."); List<String> apClasspath = new ArrayList<>(resolutionResult.getArtifacts().size()); String kaptCompilerPluginArtifact = null; for (Artifact artifact : resolutionResult.getArtifacts()) { if (artifact == null) { continue; if (artifact.getGroupId().equals(KAPT_DEPENDENCY.getGroupId()) && artifact.getArtifactId().equals(KAPT_DEPENDENCY.getArtifactId())) { kaptCompilerPluginArtifact = artifact.getFile().getAbsolutePath();
try { if (this.gemspec == null && project.getBasedir() != null && project.getBasedir().exists()) { final File pom = new File(this.project.getFile() .getAbsolutePath() + ".pom"); for (final Object element : jarDependencyArtifacts.getArtifacts()) { final Artifact dependency = (Artifact) element; getLog().info(" -- include -- " + dependency); path.append( File.separatorChar ).append( dependency.getGroupId().replace( ".", File.separator ) ); path.append( File.separatorChar ).append( dependency.getArtifactId() ); path.append( File.separatorChar ).append( dependency.getVersion() ); target = new File( path.toString(), dependency.getFile().getName() ); target.getParentFile().mkdirs();
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) { ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact); request.setResolveRoot(true).setResolveTransitively(false); request.setServers(mavenSession.getRequest().getServers()); request.setMirrors(mavenSession.getRequest().getMirrors()); 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();
if (detectProjectDependencies) for (Artifact artifact : project.getArtifacts()) { String dependencyKey = ArtifactUtils.versionlessKey(artifact.getGroupId(), artifact.getArtifactId()); this.projectBuilder.buildFromRepository( rootArtifact, this.remoteRepositories, this.localRepository ); List<Dependency> dependencies = rootProject.getDependencies(); Set<Artifact> dependencyArtifacts = MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null, null ); dependencyArtifacts.add( rootProject.getArtifact() ); result = resolver.resolveTransitively( dependencyArtifacts, rootArtifact, Collections.EMPTY_MAP, localRepository, Collection<Artifact> resolved = result.getArtifacts(); Collection<File> files = new ArrayList<File>(resolved.size() + 1 ); files.add( rootArtifact.getFile() ); for ( Artifact artifact : resolved )
Set<Artifact> depArtifacts = project.getDependencyArtifacts(); if ( depArtifacts == null ) depArtifacts = project.createArtifacts( artifactFactory, null, scopeFilter ); Artifact projectArtifact = project.getArtifact(); if ( projectArtifact == null ) metadataSource, scopeFilter ); if ( result.getArtifacts() != null && !result.getArtifacts().isEmpty() ) resolved.addAll( result.getArtifacts() ); if ( projectIds.contains( getProjectReferenceId( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ) ) )
artifact ); if (jarDependencyArtifacts != null ) { for (final Object element : jarDependencyArtifacts.getArtifacts()) { final Artifact dependency = (Artifact) element; getLog().info(" -- include -- " + dependency); gemSpecWriter.appendJarfile(dependency.getFile(), dependency.getFile().getName()); final File binDir = new File(project.getBasedir(), "bin"); final File libDir = new File(project.getBasedir(), "lib"); final File generatorsDir = new File(project.getBasedir(), "generators"); final File specDir = new File(project.getBasedir(), "spec"); final File testDir = new File(project.getBasedir(), "test"); .append("'\n"); if (jarDependencyArtifacts != null) { for (final Object element : jarDependencyArtifacts.getArtifacts()) { final Artifact dependency = (Artifact) element; writer.append(" require File.dirname(__FILE__) + '/") .append(dependency.getFile().getName()) .append("'\n");
@Override public File resolveArtifact(String groupId, String artifactId, String version, String type) { String canonicalString = groupId + ":" + artifactId + ":" + type + ":" + version; Artifact art = repositorySystem.createArtifact(groupId, artifactId, version, type); ArtifactResolutionRequest request = new ArtifactResolutionRequest() .setArtifact(art) .setResolveRoot(true) .setOffline(false) .setRemoteRepositories(project.getRemoteArtifactRepositories()) .setResolveTransitively(false); ArtifactResolutionResult res = repositorySystem.resolve(request); if (!res.isSuccess()) { throw new IllegalStateException("Cannot resolve artifact " + canonicalString); } for (Artifact artifact : res.getArtifacts()) { if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId) && artifact.getVersion().equals(version) && artifact.getType().equals(type)) { return artifact.getFile(); } } throw new IllegalStateException("Cannot find artifact " + canonicalString + " within the resolved resources"); }
public void execute() throws MojoExecutionException, MojoFailureException { Set<String> badDependencies = new LinkedHashSet<String>(); for (Artifact a: (Set<Artifact>)project.getDependencyArtifacts()) { try { if (StringUtils.isBlank(a.getType()) || StringUtils.equals("jar", a.getType()) && wrap(a).isPlugin()) { final String gav = String.format("%s:%s:%s", a.getGroupId(), a.getArtifactId(), a.getVersion()); getLog().error(String.format("Dependency on plugin %s does not include <type> tag", gav)); badDependencies.add(gav); Set<Artifact> artifacts = typeFilter.filter(project.getDependencyArtifacts()); artifacts = typeFilter.filter(artifacts); Set<Artifacts> nonOptionalArtifacts = new OptionalFilter(false).filter(artifacts); try { ArtifactResolutionResult r = resolver.resolveTransitively(artifacts, project.getArtifact(), remoteRepos, localRepository, artifactMetadataSource); ArtifactResolutionResult noR = resolver.resolveTransitively(nonOptionalArtifacts, project.getArtifact(), remoteRepos, localRepository, artifactMetadataSource); for (Artifact o : (Set<Artifact>)r.getArtifacts()) { MavenArtifact a = wrap(o); if (a.isPlugin()) { for (Artifact o: (Set<Artifact>)noR.getArtifacts()) { MavenArtifact a = wrap(o); if (a.isPlugin()) {
Artifact root = system.createArtifact( parts[ 0 ], parts[ 1 ], parts[ 2 ], "pom" ); ArtifactResolutionResult result; result = system.resolve( new ArtifactResolutionRequest() .setArtifact( root ) .setCollectionFilter( new ArtifactFilter() { for( Artifact a: result.getArtifacts() ){ if ( "jar".equals( a.getType() ) && a.getFile() != null ){ URL url = a.getFile().toURI().toURL();
protected List<File> getModulesJARs() throws MojoExecutionException { List<String> resolved = new ArrayList<String>(); List<File> result = new ArrayList<File>(); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setLocalRepository(session.getRequest().getLocalRepository()); // TODO: manage remote repositories request.setRemoteRepositories(session.getRequest().getRemoteRepositories()); //request.setRemoteRepositories(remoteRepositories); for (Object a : project.getDependencyArtifacts()) { // dependencyArtifacts contains modules from Maven reactor Artifact artifact = (Artifact) a; if (BW6Utils.isBW6(artifact)) { if (!"system".equals(artifact.getScope()) || artifact.getFile() == null || !artifact.getFile().exists()) { request.setArtifact(artifact); ArtifactResolutionResult r = resolver.resolve(request); if (r.isSuccess()) { getLog().debug("Successfully resolved artifact '" + artifact.getGroupId() + ":" + artifact.getArtifactId() + "'"); } if (artifact.getFile() == null || !artifact.getFile().exists()) { throw new MojoExecutionException(Messages.DEPENDENCY_RESOLUTION_FAILED, new FileNotFoundException()); } getLog().debug(artifact.getFile().getAbsolutePath()); } result.add(artifact.getFile()); resolved.add(artifact.getArtifactId()+"-"+artifact.getVersion().replace("-SNAPSHOT", ".qualifier")); } } return result; }
private Set<org.apache.maven.artifact.Artifact> getTransitiveDependency(org.apache.maven.artifact.Artifact artifact) throws MojoFailureException { try { org.apache.maven.artifact.Artifact pomArtifact = artifactFactory.createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact .getVersion(), artifact.getClassifier(), "pom"); MavenProject pomProject = mavenProjectBuilder.buildFromRepository(pomArtifact, this.remoteRepositories, this.localRepository); Set<org.apache.maven.artifact.Artifact> dependents = pomProject.createArtifacts(this.artifactFactory, null, null); ArtifactResolutionResult result = resolver.resolveTransitively(dependents, pomArtifact, this.localRepository, this.remoteRepositories, this.metadataSource, null); if (result != null) { getLog().debug("Found transitive dependency : " + result); return result.getArtifacts();
@Override public void executeJRuby() throws MojoExecutionException, IOException, ScriptException { if (this.project.getBasedir() == null || !this.project.getBasedir().exists()) { if (!this.buildDirectory.exists()) { this.buildDirectory = new File("target"); if (this.artifactId != null && this.groupId != null && this.version != null) { final Artifact artifact = this.repositorySystem.createArtifactWithClassifier(this.groupId, this.artifactId, this.version, "jar", null); ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(artifact) .setLocalRepository(this.localRepository) .setRemoteRepositories(this.project.getRemoteArtifactRepositories()); this.repositorySystem.resolve(request); try { final MavenProject project = projectFromArtifact(artifact); .setRemoteRepositories(this.project.getRemoteArtifactRepositories()) .setManagedVersionMap(project.getManagedVersionMap()); final ArtifactResolutionResult arr = this.repositorySystem.resolve(request); gemify(project, arr.getArtifacts());
private Classpath getArtifactClasspath( Artifact surefireArtifact ) { Classpath existing = ClasspathCache.getCachedClassPath( surefireArtifact.getArtifactId() ); if ( existing == null ) { List<String> items = new ArrayList<>(); for ( Artifact artifact : dependencyResolver.resolveArtifact( surefireArtifact ).getArtifacts() ) { getConsoleLogger().debug( "Adding to " + getPluginName() + " booter test classpath: " + artifact.getFile().getAbsolutePath() + " Scope: " + artifact.getScope() ); items.add( artifact.getFile().getAbsolutePath() ); } existing = new Classpath( items ); ClasspathCache.setCachedClasspath( surefireArtifact.getArtifactId(), existing ); } return existing; }
protected Artifact resolveJRubyStdlibArtifact(Artifact jruby) throws DependencyResolutionRequiredException, MojoExecutionException { final ArtifactResolutionRequest request = new ArtifactResolutionRequest(); for (final Dependency artifact : this.project.getDependencies()) { if (artifact.getArtifactId().equals(JRUBY_STDLIB) // TODO this condition is not needed ? && !artifact.getScope().equals(Artifact.SCOPE_PROVIDED) && !artifact.getScope().equals(Artifact.SCOPE_SYSTEM)) { request.setArtifact(this.repositorySystem .createArtifact(artifact.getGroupId(), artifact .getArtifactId(), artifact.getVersion(), artifact.getType())); break; } } if (request.getArtifact() == null){ request.setResolveTransitively(true); request.setArtifact(jruby); } request.setLocalRepository(this.localRepository); request.setRemoteRepositories(this.project.getRemoteArtifactRepositories()); Set<Artifact> set = this.repositorySystem.resolve(request).getArtifacts(); for (Artifact a: set){ if (JRUBY_STDLIB.equals(a.getArtifactId())) { return a; } } throw new MojoExecutionException("failed to resolve jruby stdlib artifact"); }
public List<String> getClasspathElements() throws MojoExecutionException { List<String> classpath = getClasspathComputer().computeClasspath(); if (extraClasspathElements != null) { ArtifactRepository localRepository = session.getLocalRepository(); List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories(); for (ArtifactRef a : extraClasspathElements) { Artifact artifact = repositorySystem.createArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion(), "jar"); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact( artifact ); request.setLocalRepository( localRepository ); request.setRemoteRepositories( remoteRepositories ); request.setResolveRoot( true ); request.setResolveTransitively( true ); ArtifactResolutionResult result = repositorySystem.resolve( request ); if (result.hasExceptions()) { throw new MojoExecutionException("Could not resolve extra classpath entry", result.getExceptions().get(0)); } for (Artifact b : result.getArtifacts()) { classpath.add(b.getFile().getAbsolutePath() + "[+**/*]"); } } } return classpath; }