List of usage examples for org.apache.maven.project MavenProject getArtifacts
public Set<Artifact> getArtifacts()
From source file:org.efaps.maven_java5.EfapsAnnotationDescriptorExtractor.java
License:Open Source License
/** * * @param _project maven project/*from w w w.ja v a 2s . c om*/ * @return * @throws InvalidPluginDescriptorException */ protected ClassLoader getClassLoader(final MavenProject _project) throws InvalidPluginDescriptorException { final List<URL> urls = new ArrayList<URL>(); // append all compile dependencies to the urls final Set<Artifact> toResolve = new HashSet<Artifact>(); for (final Object obj : _project.getDependencies()) { final Dependency dependency = (Dependency) obj; final String scope = dependency.getScope(); if (isCompileScope(scope)) { final Artifact artifact = this.artifactFactory.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), scope, dependency.getType()); toResolve.add(artifact); } } try { final ArtifactResolutionResult result = this.artifactResolver.resolveTransitively(toResolve, _project.getArtifact(), getManagedVersionMap(_project), getLocalRepository(), _project.getRemoteArtifactRepositories(), this.artifactMetadataSource, this.filter); for (final Object obj : result.getArtifacts()) { final Artifact artifact = (Artifact) obj; urls.add(artifact.getFile().toURL()); } } catch (final Exception e) { throw new InvalidPluginDescriptorException( "Failed to resolve transitively artifacts: " + e.getMessage(), e); } // append compile class path elements for (final Object obj : _project.getArtifacts()) { final Artifact cpe = (Artifact) obj; try { urls.add(cpe.getFile().toURL()); // URI().toURL() ); } catch (final MalformedURLException e) { getLogger().warn("Cannot convert '" + cpe + "' to URL", e); } } // append target output directory (where the compiled files are) try { urls.add(new File(_project.getBuild().getOutputDirectory()).toURL()); } catch (final MalformedURLException e) { getLogger().warn("Cannot convert '" + _project.getBuild().getOutputDirectory() + "' to URL", e); } if (getLogger().isDebugEnabled()) { getLogger().debug("URLS: \n" + urls.toString().replaceAll(",", "\n ")); } else if (getLogger().isInfoEnabled()) { getLogger().info("URLS: \n" + urls.toString().replaceAll(",", "\n ")); } return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader()); }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
public static HashSet<Artifact> deployedDependency(File dirJar, File dirWar, MavenProject project, HashSet<String> ignoreProjects) throws IOException { HashSet<Artifact> dependencies = new HashSet<Artifact>(); Collection artifacts = project.getArtifacts(); List list = new ArrayList(); list.addAll(artifacts);/* w w w . j a v a2 s. co m*/ Collections.sort(list); Iterator i = list.iterator(); while (i.hasNext()) { Artifact da = (Artifact) i.next(); if (!da.getScope().equalsIgnoreCase("test") && !ignoreProjects.contains(da.getArtifactId())) { String projectType = da.getType(); if ("jar".equals(projectType)) { copyFileToDirectory(da.getFile(), dirJar); printMessage("deploy", " Deployed file '" + da.getArtifactId() + "' to " + dirJar.getPath()); dependencies.add(da); } else if (projectType.equals("war") || projectType.equals("exo-portal") || projectType.equals("exo-portlet") || dirWar != null) { String finalName = getFinalName(da.getArtifactId()); deleteFileOnExist(dirWar, finalName.substring(0, finalName.lastIndexOf("."))); copyFileToDirectory(da.getFile(), dirWar); dependencies.add(da); File[] fileChild = dirWar.listFiles(); for (int j = 0; j < fileChild.length; j++) { if (fileChild[j].getName().equals(da.getFile().getName())) { File reFile = new File(fileChild[j].getParent() + "/" + finalName); rename(fileChild[j], reFile); printMessage("deploy", " Deployed file '" + da.getArtifactId() + "' to " + dirWar.getPath()); } } } } } return dependencies; }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
public static HashSet<Artifact> deployedDependency2(File dirJar, File dirWar, File dirRar, MavenProject project, HashSet<String> ignoreProjects) throws IOException { HashSet<Artifact> dependencies = new HashSet<Artifact>(); Collection artifacts = project.getArtifacts(); List list = new ArrayList(); list.addAll(artifacts);/* www . ja v a 2s . c om*/ Collections.sort(list); Iterator i = list.iterator(); while (i.hasNext()) { Artifact da = (Artifact) i.next(); if (!da.getScope().equalsIgnoreCase("test") && !ignoreProjects.contains(da.getArtifactId())) { String projectType = da.getType(); if (projectType.equals("jar") && dirJar != null) { copyFileToDirectory(da.getFile(), dirJar); printMessage("deploy", " Deployed file '" + da.getArtifactId() + "' to " + dirJar.getPath()); dependencies.add(da); } else if (projectType.equals("rar") && dirRar != null) { copyFileToDirectory(da.getFile(), dirRar); printMessage("deploy", " Deployed file '" + da.getArtifactId() + "' to " + dirRar.getPath()); dependencies.add(da); } else if ((projectType.equals("war") || projectType.equals("exopc-war")) && dirWar != null) { String finalName = getFinalName(da.getArtifactId()); File finalname = new File(dirWar + "/" + finalName); deleteFileOnExist(dirWar, finalName.substring(0, finalName.lastIndexOf("."))); copyFile(da.getFile(), finalname); dependencies.add(da); File[] fileChild = dirWar.listFiles(); for (int j = 0; j < fileChild.length; j++) { if (fileChild[j].getName().equals(da.getFile().getName())) { File reFile = new File(fileChild[j].getParent() + "/" + finalName); rename(fileChild[j], reFile); printMessage("deploy", " Deployed file '" + da.getArtifactId() + "' to " + dirWar.getPath()); } } } } } return dependencies; }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
public static HashSet<Artifact> deployedDependency3(File dirJar, MavenProject project, HashSet<String> onlyToInclude) throws IOException { HashSet<Artifact> dependencies = new HashSet<Artifact>(); Collection artifacts = project.getArtifacts(); List list = new ArrayList(); list.addAll(artifacts);/*from www . j av a 2s .c o m*/ Collections.sort(list); Iterator i = list.iterator(); while (i.hasNext()) { Artifact da = (Artifact) i.next(); if (onlyToInclude.contains(da.getArtifactId())) { String projectType = da.getType(); if (projectType.equals("jar") && dirJar != null) { copyFileToDirectory(da.getFile(), dirJar); printMessage("deploy", " Deployed file '" + da.getArtifactId() + "' to " + dirJar.getPath()); dependencies.add(da); } } } return dependencies; }
From source file:org.exoplatform.maven2.plugin.Utils.java
License:Open Source License
private static HashSet<Artifact> allDependencies(MavenProject project, HashSet<String> ignoreProjects) { if (ignoreProjects == null) ignoreProjects = new HashSet<String>(); HashSet<Artifact> dependencies = new HashSet<Artifact>(); Collection artifacts = project.getArtifacts(); List list = new ArrayList(); list.addAll(artifacts);/*from w w w .j a v a 2 s . co m*/ Collections.sort(list); Iterator i = list.iterator(); while (i.hasNext()) { Artifact da = (Artifact) i.next(); if (!da.getScope().equalsIgnoreCase("test") && !ignoreProjects.contains(da.getArtifactId())) { dependencies.add(da); } } return dependencies; }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
protected Set<String> getOptionalPackages(MavenProject currentProject) throws IOException, MojoExecutionException { ArrayList<Artifact> inscope = new ArrayList<Artifact>(); final Collection<Artifact> artifacts = getSelectedDependencies(currentProject.getArtifacts()); for (Iterator<Artifact> it = artifacts.iterator(); it.hasNext();) { Artifact artifact = it.next();//from w ww . j a v a 2 s . com if (artifact.getArtifactHandler().isAddedToClasspath()) { if (!Artifact.SCOPE_TEST.equals(artifact.getScope())) { inscope.add(artifact); } } } HashSet<String> optionalArtifactIds = new HashSet<String>(); for (Iterator<Artifact> it = inscope.iterator(); it.hasNext();) { Artifact artifact = (Artifact) it.next(); if (artifact.isOptional()) { String id = artifact.toString(); if (artifact.getScope() != null) { // strip the scope... id = id.replaceFirst(":[^:]*$", ""); } optionalArtifactIds.add(id); } } HashSet<String> required = new HashSet<String>(); HashSet<String> optional = new HashSet<String>(); for (Iterator<Artifact> it = inscope.iterator(); it.hasNext();) { Artifact artifact = it.next(); File file = getFile(artifact); if (file == null) { continue; } Jar jar = new Jar(artifact.getArtifactId(), file); if (isTransitivelyOptional(optionalArtifactIds, artifact)) { optional.addAll(jar.getPackages()); } else { required.addAll(jar.getPackages()); } jar.close(); } optional.removeAll(required); return optional; }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
protected Jar[] getClasspath(MavenProject currentProject) throws IOException, MojoExecutionException { List<Jar> list = new ArrayList<Jar>(); if (getOutputDirectory() != null && getOutputDirectory().exists()) { list.add(new Jar(".", getOutputDirectory())); }/*from ww w. j a v a 2s. co m*/ final Collection<Artifact> artifacts = getSelectedDependencies(currentProject.getArtifacts()); for (Iterator<Artifact> it = artifacts.iterator(); it.hasNext();) { Artifact artifact = (Artifact) it.next(); if (artifact.getArtifactHandler().isAddedToClasspath()) { if (!Artifact.SCOPE_TEST.equals(artifact.getScope())) { File file = getFile(artifact); if (file == null) { getLog().warn("File is not available for artifact " + artifact + " in project " + currentProject.getArtifact()); continue; } Jar jar = new Jar(artifact.getArtifactId(), file); list.add(jar); } } } Jar[] cp = new Jar[list.size()]; list.toArray(cp); return cp; }
From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java
License:Apache License
protected Collection<Artifact> getEmbeddableArtifacts(MavenProject currentProject, Analyzer analyzer) throws MojoExecutionException { final Collection<Artifact> artifacts; String embedTransitive = analyzer.getProperty(DependencyEmbedder.EMBED_TRANSITIVE); if (Boolean.valueOf(embedTransitive).booleanValue()) { // includes transitive dependencies artifacts = currentProject.getArtifacts(); } else {//from w w w .ja va 2s . c om // only includes direct dependencies artifacts = currentProject.getDependencyArtifacts(); } return getSelectedDependencies(artifacts); }
From source file:org.hudsonci.maven.eventspy_30.handler.ProjectLogger.java
License:Open Source License
public static void log(MavenProject project, String where) { if (disabled) return;//from w ww .ja va 2 s . c om log.debug("MavenProject ({}) artifacts @ {}:", project.getId(), where); logArtifactContents("artifacts", project.getArtifacts()); logArtifactContents("attachedArtifacts", project.getAttachedArtifacts()); logArtifactContents("dependencyArtifacts", project.getDependencyArtifacts()); logArtifactContents("extensionArtifacts", project.getExtensionArtifacts()); logArtifactContents("pluginArtifacts", project.getPluginArtifacts()); for (Artifact artifact : project.getPluginArtifacts()) { if (artifact instanceof PluginArtifact) { List<Dependency> dependencies = ((PluginArtifact) artifact).getDependencies(); Integer maybeSize = (dependencies == null ? null : dependencies.size()); log.debug(" {} " + "pluginDependencies" + ": {}", maybeSize, dependencies); } } }
From source file:org.itcollege.valge.licenseaudit.LicenseAuditMojo.java
@SuppressWarnings("unchecked") public List<Dependency> loadAllDependencies(MavenProject project, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, MavenProjectBuilder mavenProjectBuilder) throws MojoExecutionException { Set<Artifact> artifacts = project.getArtifacts(); List<Dependency> deps = Lists.newArrayList(); for (Artifact artifact : artifacts) { try {/*from w w w . j a va 2s.c om*/ MavenProject depMavenProject = mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true); depMavenProject.getArtifact().setScope(artifact.getScope()); deps.add(new Dependency(artifact, depMavenProject)); } catch (ProjectBuildingException e) { throw new MojoExecutionException("Failed to load dependencies", e); } } return deps; }