List of usage examples for org.apache.maven.project MavenProject getArtifacts
public Set<Artifact> getArtifacts()
From source file:com.secristfamily.maven.plugin.ZipMojo.java
/** * Retrieves all artifact dependencies./*from w w w .ja v a2 s.c o m*/ * * @return A HashSet of artifacts */ protected Set<Artifact> getDependencies() { MavenProject project = getProject(); Set<Artifact> dependenciesSet = new HashSet<Artifact>(); if (project.getArtifact() != null && project.getArtifact().getFile() != null) dependenciesSet.add(project.getArtifact()); // As of version 1.5, project dependencies require runtime resolution: // see requiresDependencyResolution definition at top of class. Set projectArtifacts = project.getArtifacts(); if (projectArtifacts != null) dependenciesSet.addAll(projectArtifacts); this.filterArtifacts(dependenciesSet); return dependenciesSet; }
From source file:com.sun.enterprise.module.maven.MavenProjectRepository.java
License:Open Source License
public MavenProjectRepository(MavenProject project, ArtifactResolver artifactResolver, ArtifactRepository localRepository, ArtifactFactory artifactFactory) { super(project.getName(), project.getFile().toURI()); this.project = project; this.artifactResolver = artifactResolver; this.localRepository = localRepository; this.artifactFactory = artifactFactory; // adds the ones that we already know of. Artifact ma = project.getArtifact(); if (ma.getFile() != null) { // if the 'ma' is the distribution module, it won't have its own output. artifacts.put(ma.getId(), ma);//from w ww. j a v a 2 s .c o m } for (Artifact a : (Set<Artifact>) project.getArtifacts()) artifacts.put(a.getId(), a); }
From source file:com.sun.enterprise.module.maven.Packager.java
License:Open Source License
public Map<String, String> configureManifest(MavenProject pom, MavenArchiveConfiguration archive, File classesDirectory) throws IOException { Map<String, String> entries; if (archive != null) entries = archive.getManifestEntries(); else//w w w .jav a2s. c o m entries = new HashMap<String, String>(); entries.put(ManifestConstants.BUNDLE_NAME, pom.getGroupId() + '.' + pom.getArtifactId()); // check META-INF/services/xxx.ImportPolicy to fill in Import-Policy configureImportPolicy(classesDirectory, entries, ImportPolicy.class, ManifestConstants.IMPORT_POLICY); configureImportPolicy(classesDirectory, entries, LifecyclePolicy.class, ManifestConstants.LIFECYLE_POLICY); // check direct dependencies to find out dependency modules. // we don't need to list transitive dependencies here, so use getDependencyArtifacts(). TokenListBuilder dependencyModuleNames = new TokenListBuilder(); Set<String> dependencyModules = new HashSet<String>(); // used to find transitive dependencies through other modules. for (Artifact a : (Set<Artifact>) pom.getDependencyArtifacts()) { if (a.getScope() != null && a.getScope().equals("test")) continue; // http://www.nabble.com/V3-gf%3Arun-throws-NPE-tf4816802.html indicates // that some artifacts are not resolved at this point. Not sure when that could happen // so aborting with diagnostics if we find it. We need to better understand what this // means and work accordingly. - KK if (a.getFile() == null) { throw new AssertionError(a.getId() + " is not resolved. a=" + a); } Jar jar; try { jar = Jar.create(a.getFile()); } catch (IOException ioe) { // not a jar file, so continue. continue; } Manifest manifest = jar.getManifest(); String name = null; if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); name = attributes.getValue(ManifestConstants.BUNDLE_NAME); } if (name != null) { // this is a hk2 module if (!a.isOptional()) dependencyModuleNames.add(name); // even optional modules need to be listed here dependencyModules.add(a.getGroupId() + '.' + a.getArtifactId() + ':' + a.getVersion()); } } // find jar files to be listed in Class-Path. This needs to include transitive // dependencies, except when the path involves a hk2 module. TokenListBuilder classPathNames = new TokenListBuilder(" "); TokenListBuilder classPathIds = new TokenListBuilder(" "); for (Artifact a : (Set<Artifact>) pom.getArtifacts()) { // check the trail. does that include hk2 module in the path? boolean throughModule = false; for (String module : dependencyModules) throughModule |= a.getDependencyTrail().get(1).toString().startsWith(module); if (throughModule) continue; // yep if (a.getScope().equals("system") || a.getScope().equals("provided") || a.getScope().equals("test")) continue; // ignore tools.jar and such dependencies. if (a.isOptional()) continue; // optional dependency classPathNames.add(stripVersion(a)); classPathIds.add(a.getId()); } if (!classPathNames.isEmpty()) { String existingClassPath = entries.get(ManifestConstants.CLASS_PATH); if (existingClassPath != null) entries.put(ManifestConstants.CLASS_PATH, existingClassPath + " " + classPathNames); else entries.put(ManifestConstants.CLASS_PATH, classPathNames.toString()); entries.put(ManifestConstants.CLASS_PATH_ID, classPathIds.toString()); } return entries; }
From source file:com.tenderowls.opensource.haxemojos.components.HaxeCompiler.java
License:Apache License
private void addLibs(List<String> argumentsList, MavenProject project, ArtifactFilter artifactFilter) { for (Artifact artifact : project.getArtifacts()) { boolean filtered = artifactFilter != null && !artifactFilter.include(artifact); if (!filtered && artifact.getType().equals(HaxeFileExtensions.HAXELIB)) { String haxelibId = artifact.getArtifactId() + ":" + artifact.getVersion(); argumentsList.add("-lib"); argumentsList.add(haxelibId); }//from w w w .ja va2 s. c om } }
From source file:com.tenderowls.opensource.haxemojos.components.HaxeCompiler.java
License:Apache License
private void addHars(List<String> argumentsList, MavenProject project, Set<CompileTarget> targets, ArtifactFilter artifactFilter) { Map<String, MavenProject> projectReferences = project.getProjectReferences(); for (Artifact artifact : project.getArtifacts()) { boolean filtered = artifactFilter != null && !artifactFilter.include(artifact); if (!filtered && artifact.getType().equals(HaxeFileExtensions.HAR)) { String artifactKey = getProjectReferenceKey(artifact, ":"); MavenProject reference = projectReferences.get(artifactKey); if (reference == null) { File harUnpackDirectory = new File(getDependenciesDirectory(), getProjectReferenceKey(artifact, "-")); unpackHar(artifact, harUnpackDirectory); validateHarMetadata(targets, artifact, new File(harUnpackDirectory, HarMetadata.METADATA_FILE_NAME)); addSourcePath(argumentsList, harUnpackDirectory.getAbsolutePath()); } else { String dirName = OutputNamesHelper.getHarValidationOutput(artifact); File validationDirectory = new File(reference.getBuild().getDirectory(), dirName); validateHarMetadata(targets, artifact, new File(validationDirectory, HarMetadata.METADATA_FILE_NAME)); for (String cp : reference.getCompileSourceRoots()) { addSourcePath(argumentsList, cp); }//from w ww . j a v a 2 s .c o m } } } }
From source file:com.totsp.mavenplugin.gwt.util.BuildClasspathUtil.java
License:Open Source License
/** * Build classpath list using either gwtHome (if present) or using *project* dependencies. Note * that this is ONLY used for the script/cmd writers (so the scopes are not for the compiler, or * war plugins, etc).//from w w w . ja va 2 s. c o m * * This is required so that the script writers can get the dependencies they need regardless of * the Maven scopes (still want to use the Maven scopes for everything else Maven, but for * GWT-Maven we need to access deps differently - directly at times). * * * @param mojo * @param scope * @return file collection for classpath * @throws DependencyResolutionRequiredException */ public static Collection<File> buildClasspathList(final AbstractGWTMojo mojo, final DependencyScope scope) throws DependencyResolutionRequiredException, MojoExecutionException { mojo.getLog().info("establishing classpath list (buildClaspathList - scope = " + scope + ")"); File gwtHome = mojo.getGwtHome(); MavenProject project = mojo.getProject(); Set<File> items = new LinkedHashSet<File>(); // inject GWT jars and relative native libs for all scopes // (gwt-user and gwt-dev should be scoped provided to keep them out of // other maven stuff - not end up in war, etc - this util is only used for GWT-Maven // scripts) // TODO filter the rest of the stuff so we don't double add these if (gwtHome != null) { mojo.getLog().info("google.webtoolkit.home (gwtHome) set, using it for GWT dependencies - " + gwtHome.getAbsolutePath()); items.addAll(BuildClasspathUtil.injectGwtDepsFromGwtHome(gwtHome, mojo)); } else { mojo.getLog() .info("google.webtoolkit.home (gwtHome) *not* set, using project POM for GWT dependencies"); items.addAll(BuildClasspathUtil.injectGwtDepsFromRepo(mojo)); } // add sources if (mojo.getSourcesOnPath()) { BuildClasspathUtil.addSourcesWithActiveProjects(project, items, DependencyScope.COMPILE); } // add resources if (mojo.getResourcesOnPath()) { BuildClasspathUtil.addResourcesWithActiveProjects(project, items, DependencyScope.COMPILE); } // add classes dir items.add(new File(project.getBuild().getDirectory() + File.separator + "classes")); // if runtime add runtime if (scope == DependencyScope.RUNTIME) { // use Collection<Artifact> because sometimes it's LinkedHashSet, sometimes it's List, and NO TIMES is it documented for (Artifact a : (Collection<Artifact>) project.getRuntimeArtifacts()) { items.add(a.getFile()); } } // if test add test if (scope == DependencyScope.TEST) { for (Artifact a : (Collection<Artifact>) project.getTestArtifacts()) { items.add(a.getFile()); } // add test classes dir items.add(new File(project.getBuild().getDirectory() + File.separator + "test-classes")); // add test sources and resources BuildClasspathUtil.addSourcesWithActiveProjects(project, items, scope); BuildClasspathUtil.addResourcesWithActiveProjects(project, items, scope); } // add compile (even when scope is other than) for (Artifact a : (Collection<Artifact>) project.getCompileArtifacts()) { items.add(a.getFile()); } // add all source artifacts for (Artifact a : (Collection<Artifact>) project.getArtifacts()) { if ("sources".equals(a.getClassifier())) { items.add(a.getFile()); } } mojo.getLog().debug("SCRIPT INJECTION CLASSPATH LIST"); for (File f : items) { mojo.getLog().debug(" " + f.getAbsolutePath()); } return items; }
From source file:com.webguys.maven.plugin.st.Controller.java
License:Open Source License
private Set<Artifact> configureArtifacts(MavenProject project) { Set<Artifact> originalArtifacts = project.getArtifacts(); project.setArtifacts(project.getDependencyArtifacts()); return originalArtifacts; }
From source file:de.fct.companian.analyze.mvn.MvnAnalyzer.java
License:Apache License
public static void main(String[] args) { long beforeStart = System.currentTimeMillis(); logger.info("main() start"); if (args != null && args.length > 0) { PomInfo pomInfo = null;/*ww w . ja va2s . c o m*/ File pomFile = new File(args[0]); try { PomHelper pomHelper = new PomHelper(pomFile); pomInfo = pomHelper.extractPomInfo(); } catch (DocumentException e) { logger.error("main() error extracting POM info", e); } if (pomInfo != null) { if (logger.isInfoEnabled()) { logger.info("main() analyzing " + pomFile.getParentFile()); } new Analyzer().analyze(pomFile.getParentFile().getAbsolutePath(), null, null); if (logger.isInfoEnabled()) { logger.info("main() building Maven project"); } MavenProject mvnProject = MvnProjectBuilder.buildMavenProject(pomFile); if (mvnProject != null) { Set<Artifact> artifactSet = mvnProject.getArtifacts(); if (artifactSet != null) { if (logger.isDebugEnabled()) { logger.debug("main() found " + artifactSet.size() + " artifacts"); } for (Artifact artifact : artifactSet) { if (!artifact.getScope().equalsIgnoreCase(Artifact.SCOPE_TEST)) { if (artifact.getType().equalsIgnoreCase("jar")) { File jarFile = artifact.getFile(); if (jarFile != null) { // File parentFile = new File(jarFile.getParentFile(), "../"); File parentFile = jarFile.getParentFile(); String parentPath = null; try { parentPath = parentFile.getCanonicalPath(); if (parentPath != null) { if (logger.isInfoEnabled()) { logger.info("main() analyzing " + parentPath); } new Analyzer().analyze(parentPath, null, null); } } catch (IOException e) { logger.error("main() could not get parent artifact path of " + jarFile.getAbsolutePath(), e); } } } } } } } else { logger.error("main() no project returned"); } } else { logger.error("main() no POM info found"); } } else { logger.error("main() no arguments given"); System.err.println("No arguments given."); } if (logger.isInfoEnabled()) { long now = System.currentTimeMillis(); long secs = (now - beforeStart) / 1000; long min = 0; if (secs >= 60) { min = secs / 60; secs = secs - (min * 60); } logger.info("main() finished in " + min + ":" + secs + " min"); } }
From source file:de.fct.companian.analyze.mvn.VersionRangeAnalysis.java
License:Apache License
public void analyseVersionRange(MavenProject mvnProject) { logger.info("analyseVersionRanges() start"); if (mvnProject != null) { logger.info("analyseVersionRanges() project=" + mvnProject.getArtifact().getArtifactId()); Set<Artifact> artifactSet = mvnProject.getArtifacts(); boolean versionRangeUsed = false; if (artifactSet != null) { for (Artifact artifact : artifactSet) { if (!artifact.getScope().equalsIgnoreCase(Artifact.SCOPE_TEST)) { if (artifact.getType().equalsIgnoreCase("jar")) { if (isRangeSet(artifact.getVersionRange().toString())) { logger.info("analyseVersionRanges() artifact=" + artifact.getArtifactId() + ", versionRange=" + artifact.getVersionRange()); versionRangeUsed = true; }// w ww.j a va2 s.c o m } } } } else { logger.info("analyseVersionRanges() no artifacts found for this Maven project"); } if (!versionRangeUsed) { logger.info("analyseVersionRanges() no version ranges where used by the dependencies of project " + mvnProject.getArtifact().getDependencyConflictId()); } } else { logger.error("analyseVersionRanges() no Maven project found"); } logger.info("analyseVersionRanges() finished"); }
From source file:de.fct.companian.analyze.prover.DepProver.java
License:Apache License
public void prove(String pomFileName) { long beforeStart = System.currentTimeMillis(); logger.info("prove() start " + pomFileName); dataSource = DbHelper.createDataSource(null); if (dataSource != null) { File pomFile = new File(pomFileName); if (pomFile.exists() && pomFile.isFile() && pomFile.canRead()) { PomInfo pomInfo = null;//from w w w . j a v a2 s .co m try { PomHelper pomHelper = new PomHelper(pomFile); pomInfo = pomHelper.extractPomInfo(); } catch (DocumentException e) { logger.error("prove() error extracting POM info", e); } if (pomInfo != null) { MavenProject mvnProject = MvnProjectBuilder.buildMavenProject(pomFile); if (mvnProject != null) { Set<Artifact> artifactSet = mvnProject.getArtifacts(); if (artifactSet != null) { JarProver jarProver = new JarProver(dataSource); jarProver.prove(pomInfo, artifactSet); } else { logger.error("prove() no dependency artifacts returned by Maven"); } } else { logger.error("prove() no Maven project returned"); } } } } else { logger.error("prove() data source creation failed"); System.err.println("Error creating data source."); System.exit(-1); } if (logger.isInfoEnabled()) { long now = System.currentTimeMillis(); long secs = (now - beforeStart) / 1000; long min = 0; if (secs >= 60) { min = secs / 60; secs = secs - (min * 60); } logger.info("prove() finished in " + min + ":" + secs + " min"); } }