protected File getFile(String artifactName) { // artifactMap is a bit too simplistic for (Artifact artifact : project.getArtifacts()) if (artifact.toString().startsWith(artifactName)) return artifact.getFile(); throw new IllegalArgumentException( "could not find " + artifactName + " in " + project.getArtifacts()); }
/** * Log Projects and their resolved dependencies via MavenProject.getArtifacts(). * * @param reactorProjects MavenProjects in the current reactor */ private void checkReactor(final List<MavenProject> reactorProjects) { for (final MavenProject reactorProject : reactorProjects) { final String msg = "Check resolved Artifacts for: " + "\ngroudId: " + reactorProject.getGroupId() + "\nartifactId: " + reactorProject.getArtifactId() + "\nversion: " + reactorProject.getVersion(); if (getLog().isDebugEnabled()) getLog().debug(msg); if (reactorProject.getArtifacts() == null || reactorProject.getArtifacts().isEmpty()) { if (getLog().isDebugEnabled()) getLog().debug("+ Dependencies not resolved or Reactor-Project has no dependencies!"); } else { for (final Artifact artifact : reactorProject.getArtifacts()) { if (getLog().isDebugEnabled()) getLog() .debug( " + " + artifact.getGroupId() + " : " + artifact.getArtifactId() + " : " + artifact.getVersion() + " : " + artifact.getType() + " : " + artifact.getFile()); } } } }
/** * Merge WsdlOptions that point to the same file by adding the extraargs to the first option and * deleting the second from the options list * * @param options */ @SuppressWarnings("unchecked") private Artifact resolveRemoteWsdlArtifact(List<?> remoteRepos, 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.getSortedProjects(); 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; } } } } /** If this did not work resolve the artifact using the artifactResolver */ try { artifactResolver.resolve(artifact, remoteRepos, localRepository); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Error downloading wsdl artifact.", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Resource can not be found.", e); } return artifact; }
/** * Set up the execution classpath for Jasper. * * <p>Put everything in the classesDirectory and all of the dependencies on the classpath. * * @returns a list of the urls of the dependencies * @throws Exception */ private List<URL> setUpWebAppClassPath() throws Exception { // add any classes from the webapp List<URL> urls = new ArrayList<URL>(); String classesDir = classesDirectory.getCanonicalPath(); classesDir = classesDir + (classesDir.endsWith(File.pathSeparator) ? "" : File.separator); urls.add(Resource.toURL(new File(classesDir))); if (getLog().isDebugEnabled()) getLog().debug("Adding to classpath classes dir: " + classesDir); // add the dependencies of the webapp (which will form WEB-INF/lib) for (Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); ) { Artifact artifact = (Artifact) iter.next(); // Include runtime and compile time libraries if (!Artifact.SCOPE_TEST.equals(artifact.getScope()) && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) { String filePath = artifact.getFile().getCanonicalPath(); if (getLog().isDebugEnabled()) getLog().debug("Adding to classpath dependency file: " + filePath); urls.add(Resource.toURL(artifact.getFile())); } } return urls; }
private void addDependencies(final MavenProject project, final JettyWebAppContext webAppConfig) throws Exception { List<File> dependencyFiles = new ArrayList<File>(); List<Resource> overlays = new ArrayList<Resource>(); for (Artifact artifact : project.getArtifacts()) { if (artifact.getType().equals("war")) { overlays.add(Resource.newResource("jar:" + artifact.getFile().toURL().toString() + "!/")); } else if ((!Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) && (!Artifact.SCOPE_TEST.equals(artifact.getScope()))) { File dependencyFile = artifact.getFile(); if (dependencyFile == null || !dependencyFile.exists()) { String coordinates = String.format( "%s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); LOG.log( Level.WARNING, "Dependency '" + coordinates + "' does not exist in repository. Skipping!"); continue; } dependencyFiles.add(artifact.getFile()); } } webAppConfig.setOverlays(overlays); webAppConfig.setWebInfLib(dependencyFiles); }
// used by "initialize", "dist" and "war" mojos protected Artifact findFrameworkArtifact(boolean minVersionWins) { Artifact result = null; Set<?> artifacts = project.getArtifacts(); for (Iterator<?> iter = artifacts.iterator(); iter.hasNext(); ) { Artifact artifact = (Artifact) iter.next(); if ("zip".equals(artifact.getType())) { if ("framework".equals(artifact.getClassifier())) { result = artifact; if (!minVersionWins) { break; } // System.out.println( "added framework: " + artifact.getGroupId() + ":" + // artifact.getArtifactId() // ); // don't break, maybe there is "framework-min" artifact too } // "module-min" overrides "module" (if present) else if ("framework-min".equals(artifact.getClassifier())) { result = artifact; // System.out.println( "added framework-min: " + artifact.getGroupId() + ":" // + artifact.getArtifactId() ); if (minVersionWins) { break; } } } } return result; }
public List<Artifact> getIncludedArtifacts() throws MojoExecutionException { if (inlcudedArtifacts == null) { inlcudedArtifacts = new ArrayList<Artifact>(); Set<Artifact> artifacts = project.getArtifacts(); if (includes != null) { if (exclusions != null) { throw new MojoExecutionException("Both inlcudes and exclusions are specified"); } Set<String> inclusionKeys = getArtifactKeys(includes); for (Artifact a : artifacts) { if (inclusionKeys.contains( getArtifactKey(a.getGroupId(), a.getArtifactId(), a.getClassifier()))) { inlcudedArtifacts.add(a); } } } else { Set<String> exclusionKeys = new HashSet<String>(getArtifactKeys(exclusions)); exclusionKeys.addAll(getImportedArtifactKeys()); for (Artifact a : artifacts) { if (!exclusionKeys.contains( getArtifactKey(a.getGroupId(), a.getArtifactId(), a.getClassifier()))) { inlcudedArtifacts.add(a); } } } } return inlcudedArtifacts; }
@Override protected List<File> getDependencies() { ArrayList<File> dependencies = new ArrayList<File>(); @SuppressWarnings("unchecked") final Iterator<Artifact> it = project.getArtifacts().iterator(); while (it.hasNext()) { final Artifact declared = it.next(); this.log.debug("Checking artifact " + declared); if (this.isJavaArtifact(declared)) { if (Artifact.SCOPE_COMPILE.equals(declared.getScope()) || Artifact.SCOPE_RUNTIME.equals(declared.getScope()) || Artifact.SCOPE_PROVIDED.equals(declared.getScope()) || Artifact.SCOPE_SYSTEM.equals(declared.getScope())) { this.log.debug("Resolving artifact " + declared); if (declared.getFile() != null) { dependencies.add(declared.getFile()); } else { this.log.debug("Unable to resolve artifact " + declared); } } else { this.log.debug( "Artifact " + declared + " has not scope compile or runtime, but " + declared.getScope()); } } else { this.log.debug( "Artifact " + declared + " is not a java artifact, type is " + declared.getType()); } } return dependencies; }
private void generateMetadata(Archiver archiver) throws ArchiverException, MojoExecutionException { Log log = getLog(); File tmpServicesDir = new File(new File(tmpDirectory, "META-INF"), "services"); File buildServicesDir = new File(new File(buildOutputDirectory, "META-INF"), "services"); if (!tmpServicesDir.mkdirs()) { throw new MojoExecutionException( "Error while creating the directory: " + tmpServicesDir.getPath()); } log.debug("Initializing class scanner ..."); ClassScanner scanner = new ClassScanner(buildOutputDirectory); for (Artifact artifact : filterArtifacts( (Set<Artifact>) project.getArtifacts(), new ScopeArtifactFilter(Artifact.SCOPE_COMPILE))) { scanner.addToClasspath(artifact.getFile()); } List<ServiceLocator> serviceLocators = new ArrayList<ServiceLocator>(serviceClassNames.length); for (String serviceClassName : serviceClassNames) { // If the user provided its own service file, skip generation File file = new File(buildServicesDir, serviceClassName); if (file.exists()) { log.debug(file + " exists; don't scan for " + serviceClassName + " implementation"); } else { ServiceLocator sl = new ServiceLocator(serviceClassName); serviceLocators.add(sl); scanner.addVisitor(sl); } } try { scanner.scan(); } catch (ClassScannerException e) { throw new MojoExecutionException("Failed to scan classes for services", e); } for (ServiceLocator sl : serviceLocators) { File file = new File(tmpServicesDir, sl.getServiceClassName()); if (!sl.getImplementations().isEmpty()) { String destFileName = "META-INF/services/" + sl.getServiceClassName(); log.info("Generating " + destFileName); try { Writer out = new OutputStreamWriter(new FileOutputStream(file)); try { for (String impl : sl.getImplementations()) { log.debug(" " + impl); out.write(impl); out.write("\n"); } } finally { out.close(); } } catch (IOException e) { throw new MojoExecutionException("Unable to create temporary file " + file, e); } archiver.addFile(file, destFileName); } } }
/** * @return * @throws MalformedURLException * @throws IOException */ private List<Artifact> getWarArtifacts() throws MalformedURLException, IOException { List<Artifact> warArtifacts = new ArrayList<Artifact>(); for (Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); ) { Artifact artifact = (Artifact) iter.next(); if (artifact.getType().equals("war")) warArtifacts.add(artifact); } return warArtifacts; }
@SuppressWarnings("unchecked") public Set<Artifact> getProjectRuntimeArtifacts() { Set<Artifact> artifacts = new HashSet<Artifact>(); for (Artifact projectArtifact : (Collection<Artifact>) project.getArtifacts()) { String scope = projectArtifact.getScope(); if (SCOPE_RUNTIME.equals(scope) || SCOPE_COMPILE.equals(scope)) { artifacts.add(projectArtifact); } } return artifacts; }
public void test017_moduleRefresh() throws Exception { IProject p2 = createExisting("t017-p2"); IProject p3 = createExisting("t017-p3"); IProject p4 = createExisting("t017-p4"); waitForJobsToComplete(); IFile pom = p3.getFile("pom.xml"); MavenProject mavenProject = manager.create(pom, false, null).getMavenProject(monitor); Artifact a = mavenProject.getArtifacts().iterator().next(); assertTrue(a.isResolved()); assertEquals( p4.getFile(IMavenConstants.POM_FILE_NAME).getLocation().toFile().getAbsoluteFile(), a.getFile().getAbsoluteFile()); copyContent(p2, "pom_changed.xml", "pom.xml"); mavenProject = manager.create(pom, false, null).getMavenProject(monitor); a = mavenProject.getArtifacts().iterator().next(); assertFalse(a.isResolved()); }
@SuppressWarnings("unchecked") private Set<Artifact> getFilteredArtifacts( String groupId, String artifactId, String type, String classifier) throws MojoExecutionException { Set<Artifact> projectArtifacts = new LinkedHashSet<Artifact>(); projectArtifacts.addAll(project.getAttachedArtifacts()); projectArtifacts.addAll(project.getArtifacts()); FilterArtifacts filter = getFilters(groupId, artifactId, type, classifier); return filtterArtifacts(projectArtifacts, filter); }
/** * Gets all dependency jars of the project specified by 'project' parameter from the local mirror * and copies them under targetFolder * * @param targetFolder The folder which the dependency jars will be copied to */ public static void copyArtifactsTo(MavenProject project, String targetFolder) throws MojoExecutionException { File targetFolderFile = new File(targetFolder); for (Iterator it = project.getArtifacts().iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); File f = artifact.getFile(); LOG.info("Artifact {} found.", f.getAbsolutePath()); if (f == null) { throw new MojoExecutionException( "Cannot locate artifact file of " + artifact.getArtifactId()); } // Check already existing artifacts and replace them if they are of a lower version try { List<String> existing = FileUtils.getFileNames( targetFolderFile, artifact.getArtifactId() + "-*.jar", null, false); if (existing.size() != 0) { String version = existing.get(0).split("(" + artifact.getArtifactId() + "-)")[1].split("(.jar)")[0]; DefaultArtifactVersion existingVersion = new DefaultArtifactVersion(version); DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(artifact.getVersion()); if (existingVersion.compareTo(artifactVersion) < 0) { // Remove existing version FileUtils.forceDelete(targetFolder + existing.get(0)); } else { LOG.info( "Artifact " + artifact.getArtifactId() + " with the same or higher " + "version already exists in lib folder, skipping copy"); continue; } } LOG.info("Copying {} to {}", f.getName(), targetFolder); FileUtils.copyFileToDirectory(f.getAbsolutePath(), targetFolder); } catch (IOException e) { throw new MojoExecutionException( "Error while copying artifact file of " + artifact.getArtifactId(), e); } } }
public void testWorkspaceDependencyVersionRange() throws Exception { IProject[] projects = importProjects( "projects/versionrange", new String[] {"p001/pom.xml", "p002/pom.xml"}, new ResolverConfiguration()); waitForJobsToComplete(); IMavenProjectFacade f1 = manager.create(projects[0], monitor); MavenProject p1 = f1.getMavenProject(monitor); ArrayList<Artifact> a1 = new ArrayList<Artifact>(p1.getArtifacts()); assertEquals(1, a1.size()); assertEquals(projects[1].getLocation().append("target/classes").toFile(), a1.get(0).getFile()); }
@SuppressWarnings("unchecked") private ArrayList<String> getClasspath() throws MojoExecutionException { ArrayList<String> artifacts = new ArrayList<String>(); try { artifacts.add(classesDirectory.getCanonicalPath()); for (Artifact artifact : (Set<Artifact>) project.getArtifacts()) { File file = artifact.getFile(); getLog().debug("Including: " + file); artifacts.add(file.getCanonicalPath()); } } catch (IOException e) { throw new MojoExecutionException("Could not determine project classath.", e); } return artifacts; }
/** @return */ private List<File> getDependencyFiles() { List<File> dependencyFiles = new ArrayList<File>(); for (Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); ) { Artifact artifact = (Artifact) iter.next(); if (((!Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) && (!Artifact.SCOPE_TEST.equals(artifact.getScope()))) || (useTestScope && Artifact.SCOPE_TEST.equals(artifact.getScope()))) { dependencyFiles.add(artifact.getFile()); getLog().debug("Adding artifact " + artifact.getFile().getName() + " for WEB-INF/lib "); } } return dependencyFiles; }
public void execute() throws MojoExecutionException, MojoFailureException { File testDir = new File(project.getBuild().getTestOutputDirectory(), "test-dependencies"); testDir.mkdirs(); try { Writer w = new OutputStreamWriter(new FileOutputStream(new File(testDir, "index")), "UTF-8"); for (Artifact a : (Set<Artifact>) project.getArtifacts()) { if (!HpiUtil.isPlugin(a)) continue; getLog().debug("Copying " + a.getId() + " as a test dependency"); File dst = new File(testDir, a.getArtifactId() + ".hpi"); FileUtils.copyFile(a.getFile(), dst); w.write(a.getArtifactId() + "\n"); } w.close(); } catch (IOException e) { throw new MojoExecutionException("Failed to copy dependency plugins", e); } }
public void testEnvironmentVariablesConsidered() throws Exception { String tmpDir = System.getenv("TEMP"); assertTrue("This test requires the environment variable TEMP to be set", tmpDir != null); File systemJar = new File("projects/MNGECLIPSE-581/mngeclipse-581.jar"); File tempJar = new File(tmpDir, "mngeclipse-581.jar"); FileUtils.copyFile(systemJar, tempJar); tempJar.deleteOnExit(); IProject[] projects = importProjects( "projects/MNGECLIPSE-581", new String[] {"pom.xml"}, new ResolverConfiguration()); assertEquals(1, projects.length); assertNotNull(projects[0]); IMavenProjectFacade facade = manager.getProject(projects[0]); assertNotNull(facade); MavenProject project = facade.getMavenProject(); assertNotNull(project); File file = project.getArtifacts().iterator().next().getFile(); assertTrue(file.toString(), file.isFile()); }
protected ClassLoader getProjectClassloader() throws MojoExecutionException { try { if (projectClassloader == null) { Set<Artifact> artifacts = project.getArtifacts(); List<URL> urls = new ArrayList<URL>(); for (Artifact artifact : artifacts) { urls.add(artifact.getFile().toURI().toURL()); } if (getLog().isDebugEnabled()) { for (URL url : urls) { getLog().debug("Project dependency URL: " + url.toString()); } } projectClassloader = new URLClassLoader(urls.toArray(new URL[0]), this.getClass().getClassLoader()); } return projectClassloader; } catch (MalformedURLException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } }
/** * @return * @throws MojoExecutionException */ public List<String> getProvidedJars() throws MojoExecutionException { // if we are configured to include the provided dependencies on the plugin's classpath // (which mimics being on jetty's classpath vs being on the webapp's classpath), we first // try and filter out ones that will clash with jars that are plugin dependencies, then // create a new classloader that we setup in the parent chain. if (useProvidedScope) { List<String> provided = new ArrayList<String>(); for (Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); ) { Artifact artifact = iter.next(); if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) && !isPluginArtifact(artifact)) { provided.add(artifact.getFile().getAbsolutePath()); if (getLog().isDebugEnabled()) { getLog().debug("Adding provided artifact: " + artifact); } } } return provided; } else return null; }
private void addMissingArtifactProblemInfos( MavenProject mavenProject, SourceLocation location, List<MavenProblemInfo> knownProblems) { Set<Artifact> artifacts = mavenProject.getArtifacts(); all_artifacts_loop: for (Artifact mavenArtifact : artifacts) { if (!mavenArtifact.isResolved()) { org.eclipse.aether.artifact.Artifact artifact = RepositoryUtils.toArtifact(mavenArtifact); for (MavenProblemInfo problem : knownProblems) { if (problem instanceof ArtifactNotFoundProblemInfo) { ArtifactNotFoundProblemInfo artifactNotFoundProblemInfo = (ArtifactNotFoundProblemInfo) problem; if (equals(artifactNotFoundProblemInfo.getArtifact(), artifact)) { continue all_artifacts_loop; } } } knownProblems.add( new ArtifactNotFoundProblemInfo(artifact, mavenConfiguration.isOffline(), location)); } } }
protected List<IMavenProjectFacade> getWorkspaceDependencies( IProject project, MavenProject mavenProject) { Set<IProject> projects = new HashSet<IProject>(); List<IMavenProjectFacade> dependencies = new ArrayList<IMavenProjectFacade>(); Set<Artifact> artifacts = mavenProject.getArtifacts(); for (Artifact artifact : artifacts) { IMavenProjectFacade dependency = projectManager.getMavenProject( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()); if ((Artifact.SCOPE_COMPILE.equals(artifact.getScope()) || Artifact.SCOPE_RUNTIME.equals( artifact.getScope())) // MNGECLIPSE-1578 Runtime dependencies should be deployed && dependency != null && !dependency.getProject().equals(project) && dependency.getFullPath(artifact.getFile()) != null && projects.add(dependency.getProject())) { dependencies.add(dependency); } } return dependencies; }
@NotNull private MavenServerExecutionResult createExecutionResult( File file, MavenExecutionResult result, DependencyNode rootNode) throws RemoteException { Collection<MavenProjectProblem> problems = MavenProjectProblem.createProblemsList(); THashSet<MavenId> unresolvedArtifacts = new THashSet<MavenId>(); validate(file, result.getExceptions(), problems, unresolvedArtifacts); MavenProject mavenProject = result.getMavenProject(); if (mavenProject == null) return new MavenServerExecutionResult(null, problems, unresolvedArtifacts); MavenModel model = MavenModelConverter.convertModel( mavenProject.getModel(), mavenProject.getCompileSourceRoots(), mavenProject.getTestCompileSourceRoots(), mavenProject.getArtifacts(), (rootNode == null ? Collections.emptyList() : rootNode.getChildren()), mavenProject.getExtensionArtifacts(), getLocalRepositoryFile()); RemoteNativeMavenProjectHolder holder = new RemoteNativeMavenProjectHolder(mavenProject); try { UnicastRemoteObject.exportObject(holder, 0); } catch (RemoteException e) { throw new RuntimeException(e); } Collection<String> activatedProfiles = collectActivatedProfiles(mavenProject); MavenServerExecutionResult.ProjectData data = new MavenServerExecutionResult.ProjectData( model, MavenModelConverter.convertToMap(mavenProject.getModel()), holder, activatedProfiles); return new MavenServerExecutionResult(data, problems, unresolvedArtifacts); }
protected Map<String, Artifact> findAllModuleArtifacts(boolean minVersionWins) { Map<String, Artifact> result = new HashMap<String, Artifact>(); Set<?> artifacts = project.getArtifacts(); for (Iterator<?> iter = artifacts.iterator(); iter.hasNext(); ) { Artifact artifact = (Artifact) iter.next(); if ("zip".equals(artifact.getType())) { if ("module".equals(artifact.getClassifier()) || "module-min".equals(artifact.getClassifier())) { String moduleName = artifact.getArtifactId(); if (moduleName.startsWith("play-")) { moduleName = moduleName.substring("play-".length()); } if ("module".equals(artifact.getClassifier())) { if (!minVersionWins || result.get(moduleName) == null) { result.put(moduleName, artifact); // System.out.println("added module: " + artifact.getGroupId() + ":" + // artifact.getArtifactId()); } } else // "module-min" { if (minVersionWins || result.get(moduleName) == null) { result.put(moduleName, artifact); // System.out.println("added module-min: " + artifact.getGroupId() + ":" + // artifact.getArtifactId()); } } } } else if ("play".equals(artifact.getType())) { String moduleName = artifact.getArtifactId(); result.put(moduleName, artifact); } } return result; }
/** * Add any relevant project dependencies to the classpath. Takes includeProjectDependencies into * consideration. * * @param path classpath of {@link java.net.URL} objects * @throws MojoExecutionException */ private void addRelevantProjectDependenciesToClasspath(Set<URL> path) throws MojoExecutionException { if (this.includeProjectDependencies) { try { getLog().debug("Project Dependencies will be included."); URL mainClasses = new File(project.getBuild().getOutputDirectory()).toURI().toURL(); getLog().debug("Adding to classpath : " + mainClasses); path.add(mainClasses); Set<Artifact> dependencies = CastUtils.cast(project.getArtifacts()); // system scope dependencies are not returned by maven 2.0. See // MEXEC-17 dependencies.addAll(getAllNonTestScopedDependencies()); Iterator<Artifact> iter = dependencies.iterator(); while (iter.hasNext()) { Artifact classPathElement = iter.next(); getLog() .debug( "Adding project dependency artifact: " + classPathElement.getArtifactId() + " to classpath"); File file = classPathElement.getFile(); if (file != null) { path.add(file.toURI().toURL()); } } } catch (MalformedURLException e) { throw new MojoExecutionException("Error during setting up classpath", e); } } else { getLog().debug("Project Dependencies will be excluded."); } }
private void addDependencies(Archiver archiver) throws ArchiverException, MojoExecutionException { Log log = getLog(); AndArtifactFilter filter = new AndArtifactFilter(); filter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME)); filter.add( new ArtifactFilter() { public boolean include(Artifact artifact) { return !artifact.isOptional(); } }); filter.add(new TypeArtifactFilter("jar")); filter.add(buildSynapseRuntimeArtifactFilter()); for (Artifact artifact : filterArtifacts((Set<Artifact>) project.getArtifacts(), filter)) { String targetFileName = artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getArtifactHandler().getExtension(); log.info("Adding " + targetFileName + " (scope " + artifact.getScope() + ")"); archiver.addFile(artifact.getFile(), "lib/" + targetFileName); } }
/** Iterate through dependencies, find those specified in the whitelist */ private Set<Artifact> findThriftDependencies(Set<String> whitelist) throws IOException { Set<Artifact> thriftDependencies = new HashSet<Artifact>(); Set<Artifact> deps = new HashSet<Artifact>(); deps.addAll(project.getArtifacts()); deps.addAll(project.getDependencyArtifacts()); Map<String, Artifact> depsMap = new HashMap<String, Artifact>(); for (Artifact dep : deps) { depsMap.put(dep.getId(), dep); } for (Artifact artifact : deps) { // This artifact is on the whitelist directly. if (whitelist.contains(artifact.getArtifactId())) { thriftDependencies.add(artifact); // Check if this artifact is being pulled in by an idl jar that's been whitelisted } else { List<String> depTrail = artifact.getDependencyTrail(); // depTrail can be null sometimes, which seems like a maven bug if (depTrail != null) { for (String name : depTrail) { Artifact dep = depsMap.get(name); if (dep != null && "idl".equals(dep.getClassifier()) && whitelist.contains(dep.getArtifactId())) { thriftDependencies.add(artifact); break; } } } } } return thriftDependencies; }
/** * Provides transitive dependency artifacts only defined types based on {@code types} argument or * all types if {@code types} argument is empty * * @param filteredScopes List of scopes to be removed (ie filtered out). * @param types Zero or more artifact types to be selected. * @return a {@code List} of all project dependencies. Never {@code null}. This should maintain * dependency order to comply with library project resource precedence. */ protected Set<Artifact> getTransitiveDependencyArtifacts( List<String> filteredScopes, String... types) { return getArtifactResolverHelper() .getFilteredArtifacts(filteredScopes, project.getArtifacts(), types); }
/** * @return a {@code List} of all project dependencies. Never {@code null}. This excludes artifacts * of the {@code EXCLUDED_DEPENDENCY_SCOPES} scopes. And This should maintain dependency order * to comply with library project resource precedence. */ protected Set<Artifact> getAllRelevantDependencyArtifacts() { final Set<Artifact> allArtifacts = (Set<Artifact>) project.getArtifacts(); final Set<Artifact> results = filterOutIrrelevantArtifacts(allArtifacts); return results; }