List of usage examples for org.apache.maven.artifact.resolver.filter AndArtifactFilter AndArtifactFilter
public AndArtifactFilter(List<ArtifactFilter> filters)
From source file:com.github.ferstl.jarscan.AbstractJarScanMojo.java
private ArtifactFilter createArtifactFilter() { List<ArtifactFilter> filters = new ArrayList<>(3); if (this.scope != null) { filters.add(new ScopeArtifactFilter(this.scope)); }/*from w ww.j a v a2 s .co m*/ if (!this.includes.isEmpty()) { filters.add(new StrictPatternIncludesArtifactFilter(this.includes)); } if (!this.excludes.isEmpty()) { filters.add(new StrictPatternExcludesArtifactFilter(this.excludes)); } return new AndArtifactFilter(filters); }
From source file:org.echocat.jomon.maven.boot.ArtifactFactory.java
License:Mozilla Public License
@Nonnull protected ArtifactFilter toArtifactFilter(@Nonnull ArtifactFactoryRequest request) { final ArtifactFilter includeScopesFilter = toIncludeScopesFilter(request.getIncludeScopes()); final ArtifactFilter excludeScopesFilter = toExcludeScopesFilter(request.getExcludeScopes()); final ArtifactFilter optionalFilter = toOptionalFilter(request.getOptionalHandling()); return new AndArtifactFilter(Arrays.asList(includeScopesFilter, excludeScopesFilter, optionalFilter)); }
From source file:org.fusesource.mop.MOPRepository.java
License:Open Source License
public Set<Artifact> resolveArtifacts(ArtifactFilter filter, final ArtifactId id) throws Exception, InvalidRepositoryException { debug("Resolving artifact " + id); RepositorySystem repositorySystem = (RepositorySystem) getContainer().lookup(RepositorySystem.class); List<ArtifactRepository> remoteRepositories = createRemoteRepositories(repositorySystem); ArtifactRepository localRepository = createLocalRepository(repositorySystem, "mop.local", getLocalRepo().getAbsolutePath(), false); // If group id is not set.. we can still look it up in the db // of installed artifacs. if (id.getGroupId() == null) { database(true, new DBCallback() { public void execute(Database database) throws Exception { // Makes groupId includeOptional.. we look it up in the database. if (id.getGroupId() == null) { Map<String, Set<String>> rc = Database .groupByGroupId(database.findByArtifactId(id.getArtifactId())); if (rc.isEmpty()) { throw new Exception( "Please qualify a group id: No local artifacts match: " + id.getArtifactId()); }//from ww w . j a v a2s. c o m if (rc.size() > 1) { System.out.println("Local artifacts that match:"); for (String s : rc.keySet()) { System.out.println(" " + s + ":" + id.getArtifactId()); } throw new Exception("Please qualify a group id: Multiple local artifacts match: " + id); } id.setGroupId(rc.keySet().iterator().next()); debug("Resolving artifact " + id); } } }); } if (online) { // Keep track that we are trying an install.. // If an install dies midway.. the repo will have partlly installed dependencies... // we may want to continue the install?? // database.beginInstall(id.toString()); } Artifact artifact = repositorySystem.createArtifactWithClassifier(id.getGroupId(), id.getArtifactId(), id.getVersion(), id.getType(), id.getClassifier()); // Setup the filters which will constrain the resulting dependencies.. List<ArtifactFilter> constraints = new ArrayList<ArtifactFilter>(); constraints.add(new ScopeArtifactFilter(scope)); if (!includeOptional) { constraints.add(new ArtifactFilter() { public boolean include(Artifact artifact) { return !artifact.isOptional(); } }); } if (filter != null) { constraints.add(filter); } ArtifactFilter filters = new AndArtifactFilter(constraints); ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(artifact) .setResolveRoot(true).setResolveTransitively(isTransitive()).setLocalRepository(localRepository) .setRemoteRepositories(remoteRepositories).setOffline(!online).setCollectionFilter(filters); ArtifactResolutionResult result = repositorySystem.resolve(request); List<Artifact> list = result.getMissingArtifacts(); if (!list.isEmpty()) { throw new Exception("The following artifacts could not be downloaded: " + list); } if (/* result.getArtifacts().isEmpty() && */!result.getExceptions().isEmpty()) { throw new Exception("Error resolving artifact " + artifact, result.getExceptions().get(0)); } Set<Artifact> rc = result.getArtifacts(); if (online) { // Have the DB index the installed the artifacts. final LinkedHashSet<String> installed = new LinkedHashSet<String>(); for (Artifact a : rc) { installed.add(a.getId()); } database(false, new DBCallback() { public void execute(Database database) throws Exception { database.install(installed); } }); } debug(" Resolved: " + id); for (Artifact a : rc) { debug(" depends on: " + a.getId() + ", scope: " + a.getScope() + ", optional: " + a.isOptional() + ", file: " + a.getFile()); } return rc; }
From source file:org.phenotips.tool.packager.PackageMojo.java
License:Open Source License
private Set<Artifact> resolveTransitively(Set<Artifact> artifacts) throws MojoExecutionException { AndArtifactFilter filter = new AndArtifactFilter(Arrays.asList(new ScopeArtifactFilter("runtime"), // - Exclude JCL and LOG4J since we want all logging to go through SLF4J. Note that we're excluding // log4j-<version>.jar but keeping log4j-over-slf4j-<version>.jar // - Exclude batik-js to prevent conflict with the patched version of Rhino used by yuicompressor used // for JSX. See http://jira.xwiki.org/jira/browse/XWIKI-6151 for more details. new ExcludesArtifactFilter(Arrays.asList("org.apache.xmlgraphic:batik-js", "org.slf4j:slf4j-log4j12", "commons-logging:commons-logging", "commons-logging:commons-logging-api", "log4j:log4j", "com.bea.xml:jsr173-ri")))); ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(this.project.getArtifact()) .setArtifactDependencies(artifacts).setCollectionFilter(filter) .setRemoteRepositories(this.remoteRepositories).setLocalRepository(this.localRepository) .setManagedVersionMap(getManagedVersionMap()).setResolveRoot(false).setResolveTransitively(true); ArtifactResolutionResult resolutionResult = this.repositorySystem.resolve(request); if (resolutionResult.hasExceptions()) { throw new MojoExecutionException(String.format("Failed to resolve artifacts [%s]", artifacts, resolutionResult.getExceptions().get(0))); }/* ww w . j av a2 s . c o m*/ return resolutionResult.getArtifacts(); }
From source file:org.sourcepit.osgifier.maven.context.LegacyOsgifierModelBuilder.java
License:Apache License
private ArtifactFilter newResolutionFilter(String scope) { final List<ArtifactFilter> artifactFilters = new ArrayList<ArtifactFilter>(2); artifactFilters.add(new ScopeArtifactFilter(scope)); artifactFilters.add(new TypeArtifactFilter("jar")); return new AndArtifactFilter(artifactFilters); }
From source file:org.xwiki.tool.packager.PackageMojo.java
License:Open Source License
private Set<Artifact> resolveTransitively(Set<Artifact> artifacts) throws MojoExecutionException { AndArtifactFilter filter = new AndArtifactFilter(Arrays.asList(new ScopeArtifactFilter("runtime"), // - Exclude JCL and LOG4J since we want all logging to go through SLF4J. Note that we're excluding // log4j-<version>.jar but keeping log4j-over-slf4j-<version>.jar // - Exclude batik-js to prevent conflict with the patched version of Rhino used by yuicompressor used // for JSX. See http://jira.xwiki.org/jira/browse/XWIKI-6151 for more details. new ExcludesArtifactFilter(Arrays.asList("org.apache.xmlgraphic:batik-js", "commons-logging:commons-logging", "commons-logging:commons-logging-api", "log4j:log4j")))); ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(this.project.getArtifact()) .setArtifactDependencies(artifacts).setCollectionFilter(filter) .setRemoteRepositories(this.remoteRepositories).setLocalRepository(this.localRepository) .setManagedVersionMap(getManagedVersionMap()).setResolveRoot(false); ArtifactResolutionResult resolutionResult = this.repositorySystem.resolve(request); if (resolutionResult.hasExceptions()) { throw new MojoExecutionException(String.format("Failed to resolve artifacts [%s]", artifacts, resolutionResult.getExceptions().get(0))); }/*from w w w. java2 s . c om*/ return resolutionResult.getArtifacts(); }