List of usage examples for org.apache.maven.project MavenProject getReportArtifacts
@Deprecated
public Set<Artifact> getReportArtifacts()
From source file:org.nbheaven.sqe.core.maven.utils.MavenUtilities.java
License:Open Source License
/** * try to collect the plugin's dependency artifacts * as defined in <dependencies> section within <plugin>. Will only * return files currently in local repository * * @return list of files in local repository *///from w w w .j av a 2s . co m public static List<File> findDependencyArtifacts(Project project, String pluginGroupId, String pluginArtifactId, boolean includePluginArtifact) { List<File> cpFiles = new ArrayList<File>(); final NbMavenProject p = project.getLookup().lookup(NbMavenProject.class); final MavenEmbedder online = EmbedderFactory.getOnlineEmbedder(); MavenProject mp = p.getMavenProject(); if (includePluginArtifact) { Set<Artifact> arts = new HashSet<Artifact>(); arts.addAll(mp.getReportArtifacts()); arts.addAll(mp.getPluginArtifacts()); for (Artifact a : arts) { if (pluginArtifactId.equals(a.getArtifactId()) && pluginGroupId.equals(a.getGroupId())) { File f = a.getFile(); if (f == null) { //somehow the report plugins are not resolved, we need to workaround that.. f = FileUtil.normalizeFile(new File(new File(online.getLocalRepository().getBasedir()), online.getLocalRepository().pathOf(a))); } if (!f.exists()) { try { online.resolve(a, mp.getRemoteArtifactRepositories(), online.getLocalRepository()); } catch (ArtifactResolutionException ex) { Exceptions.printStackTrace(ex); } catch (ArtifactNotFoundException ex) { Exceptions.printStackTrace(ex); } } if (f.exists()) { cpFiles.add(f); try { ProjectBuildingRequest req = new DefaultProjectBuildingRequest(); req.setRemoteRepositories(mp.getRemoteArtifactRepositories()); req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); req.setSystemProperties(online.getSystemProperties()); ProjectBuildingResult res = online.buildProject(a, req); MavenProject mp2 = res.getProject(); if (mp2 != null) { // XXX this is not really right, but mp.dependencyArtifacts = null for some reason for (Dependency dep : mp2.getDependencies()) { Artifact a2 = online.createArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), "jar"); online.resolve(a2, mp.getRemoteArtifactRepositories(), online.getLocalRepository()); File df = a2.getFile(); if (df.exists()) { cpFiles.add(df); } } } } catch (Exception x) { Exceptions.printStackTrace(x); } } } } } List<Plugin> plugins = mp.getBuildPlugins(); for (Plugin plug : plugins) { if (pluginArtifactId.equals(plug.getArtifactId()) && pluginGroupId.equals(plug.getGroupId())) { try { List<Dependency> deps = plug.getDependencies(); ArtifactFactory artifactFactory = online.getPlexus().lookup(ArtifactFactory.class); for (Dependency d : deps) { final Artifact projectArtifact = artifactFactory.createArtifactWithClassifier( d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getType(), d.getClassifier()); String localPath = online.getLocalRepository().pathOf(projectArtifact); File f = FileUtil .normalizeFile(new File(online.getLocalRepository().getBasedir(), localPath)); if (!f.exists()) { try { online.resolve(projectArtifact, mp.getRemoteArtifactRepositories(), online.getLocalRepository()); } catch (ArtifactResolutionException ex) { ex.printStackTrace(); // Exceptions.printStackTrace(ex); } catch (ArtifactNotFoundException ex) { ex.printStackTrace(); // Exceptions.printStackTrace(ex); } } if (f.exists()) { cpFiles.add(f); } } } catch (ComponentLookupException ex) { Exceptions.printStackTrace(ex); } } } return cpFiles; }