List of usage examples for org.apache.maven.project MavenProject getArtifacts
public Set<Artifact> getArtifacts()
From source file:ar.com.fluxit.jqa.JQAMavenPlugin.java
License:Open Source License
private void doExecute(File buildDirectory, File outputDirectory, File testOutputDirectory, MavenProject project, File sourceDir, String sourceJavaVersion) throws IntrospectionException, TypeFormatException, FileNotFoundException, IOException, RulesContextFactoryException, ExporterException { // Add project dependencies to classpath getLog().debug("Adding project dependencies to classpath"); final Collection<File> classPath = new ArrayList<File>(); @SuppressWarnings("unchecked") final Set<Artifact> artifacts = project.getArtifacts(); for (final Artifact artifact : artifacts) { classPath.add(artifact.getFile()); }//from w ww. ja v a 2s . c om // Add project classes to classpath if (outputDirectory != null) { classPath.add(outputDirectory); } if (testOutputDirectory != null) { classPath.add(testOutputDirectory); } getLog().debug("Adding project classes to classpath"); final Collection<File> classFiles = FileUtils.listFiles(buildDirectory, new SuffixFileFilter(RulesContextChecker.CLASS_SUFFIX), TrueFileFilter.INSTANCE); // Reads the config file getLog().debug("Reading rules context"); final RulesContext rulesContext = RulesContextFactoryLocator.getRulesContextFactory() .getRulesContext(getRulesContextFile().getPath()); getLog().debug("Checking rules for " + classFiles.size() + " files"); final CheckingResult checkingResult = RulesContextChecker.INSTANCE.check(project.getArtifactId(), classFiles, classPath, rulesContext, new File[] { sourceDir }, sourceJavaVersion, getLogger()); CheckingResultExporter.INSTANCE.export(checkingResult, project.getArtifactId(), getResultsDirectory(), this.xslt, getLogger()); }
From source file:au.net.coldeq.enforcer.BanDuplicateClasses.java
License:Apache License
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { this.log = helper.getLog(); MavenProject project = getMavenProject(helper); Set<Artifact> artifacts = project.getArtifacts(); int numberOfArtifacts = artifacts.size(); int numberProcessed = 0; Map<Artifact, Set<String>> artifactToClasses = new HashMap<Artifact, Set<String>>(); for (Artifact artifact : artifacts) { HashSet<String> classesFoundInArtifact = new HashSet<String>(); artifactToClasses.put(artifact, classesFoundInArtifact); File file = artifact.getFile(); log.debug((numberProcessed + 1) + " / " + numberOfArtifacts + "\tSearching for duplicate classes in: " + file.getAbsolutePath()); if (file == null) { log.info("OK, file is null. WTF! " + artifact.toString() + ". Ignoring..."); } else if (!file.exists()) { log.info("OK, file does not exist. WTF! " + file.getAbsolutePath() + ". Ignoring..."); } else if (file.isDirectory()) { log.info("File is a directory. why?" + file.getAbsolutePath() + ". Ignoring..."); } else if (shouldIgnoreArtifactType(artifact)) { log.info("File is a..." + artifact.getType() + ": " + file.getAbsolutePath() + ". Ignoring..."); } else {/*w w w .j a v a 2 s . c om*/ classesFoundInArtifact.addAll(findClassesInJarFile(file)); } } Map<String, Set<Artifact>> classesToArtifact = invert(artifactToClasses); Map<String, Set<Artifact>> duplicates = filterForClassesFoundInMoreThanOneArtifact(classesToArtifact); if (duplicates.isEmpty()) { log.info("No duplicates found"); } else { assertThatAllDuplicatesAreOfClassesThatMatchToTheByte(duplicates); } }
From source file:cn.wanghaomiao.maven.plugin.seimi.util.WarUtils.java
License:Apache License
/** * @param project {@link MavenProject}/*w w w . j a v a 2s. c o m*/ * @param dependency {@link Dependency} * @return {@link Artifact} */ public static Artifact getArtifact(MavenProject project, Dependency dependency) { for (Object o : project.getArtifacts()) { Artifact artifact = (Artifact) o; if (artifact.getGroupId().equals(dependency.getGroupId()) && artifact.getArtifactId().equals(dependency.getArtifactId()) && artifact.getType().equals(dependency.getType())) { if (artifact.getClassifier() == null && dependency.getClassifier() == null) { return artifact; } else if (dependency.getClassifier() != null && dependency.getClassifier().equals(artifact.getClassifier())) { return artifact; } } } return null; }
From source file:com.agilejava.docbkx.maven.AbstractTransformerMojo.java
License:Apache License
/** * Configures and executes the given ant tasks, mainly preprocess and postprocess defined in the pom configuration. * * @param antTasks The tasks to execute/*from ww w . j a v a2 s. c o m*/ * @param mavenProject The current maven project * @throws MojoExecutionException If something wrong occurs while executing the ant tasks. */ protected void executeTasks(Target antTasks, MavenProject mavenProject) throws MojoExecutionException { try { ExpressionEvaluator exprEvaluator = (ExpressionEvaluator) antTasks.getProject() .getReference("maven.expressionEvaluator"); Project antProject = antTasks.getProject(); PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(antProject); propertyHelper.setNext(new AntPropertyHelper(exprEvaluator, getLog())); DefaultLogger antLogger = new DefaultLogger(); antLogger.setOutputPrintStream(System.out); antLogger.setErrorPrintStream(System.err); antLogger.setMessageOutputLevel(2); antProject.addBuildListener(antLogger); antProject.setBaseDir(mavenProject.getBasedir()); Path p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getArtifacts().iterator(), File.pathSeparator)); antProject.addReference("maven.dependency.classpath", p); p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getCompileClasspathElements().iterator(), File.pathSeparator)); antProject.addReference("maven.compile.classpath", p); p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getRuntimeClasspathElements().iterator(), File.pathSeparator)); antProject.addReference("maven.runtime.classpath", p); p = new Path(antProject); p.setPath(StringUtils.join(mavenProject.getTestClasspathElements().iterator(), File.pathSeparator)); antProject.addReference("maven.test.classpath", p); List artifacts = getArtifacts(); List list = new ArrayList(artifacts.size()); File file; for (Iterator i = artifacts.iterator(); i.hasNext(); list.add(file.getPath())) { Artifact a = (Artifact) i.next(); file = a.getFile(); if (file == null) throw new DependencyResolutionRequiredException(a); } p = new Path(antProject); p.setPath(StringUtils.join(list.iterator(), File.pathSeparator)); antProject.addReference("maven.plugin.classpath", p); getLog().info("Executing tasks"); antTasks.execute(); getLog().info("Executed tasks"); } catch (Exception e) { throw new MojoExecutionException("Error executing ant tasks", e); } }
From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java
License:Apache License
private static Artifact getDependancy(Inclusion inc, MavenProject mavenProject) throws MojoExecutionException { Set dependancy = mavenProject.getArtifacts(); for (Iterator i = dependancy.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); if (inc.match(artifact)) { return artifact; }/*from w w w . j av a2s . c o m*/ } throw new MojoExecutionException("artifactId Not found " + inc.artifactId); }
From source file:com.blackducksoftware.integration.hub.jenkins.maven.HubMavenReporter.java
License:Open Source License
/** * Mojos perform different dependency resolution, so we add dependencies for * each mojo.//from w w w .j a v a 2 s .c om * */ @Override public boolean postExecute(final MavenBuildProxy build, final MavenProject pom, final MojoInfo mojo, final BuildListener listener, final Throwable error) throws InterruptedException, IOException { final HubJenkinsLogger buildLogger = new HubJenkinsLogger(listener); buildLogger.setLogLevel(LogLevel.TRACE); buildLogger.debug("postExecute()"); recordMavenDependencies(pom.getArtifacts()); build.registerAsProjectAction(this); return super.postExecute(build, pom, mojo, listener, error); }
From source file:com.carrotgarden.maven.osgi.BaseMojo.java
License:BSD License
/** *///from w w w . jav a 2s.co m protected void addProjectDependencies(MavenProject project, String tab) { // getLog().warn("addProjectDependencies : " + project); @SuppressWarnings("unchecked") Set<Artifact> artifacts = project.getArtifacts(); // getLog().warn("artifacts.size : " + artifacts.size()); for (Artifact artifact : artifacts) { if (artifact.isOptional()) { continue; } if (Artifact.SCOPE_TEST.equals(artifact.getScope())) { continue; } provisionBundle(artifact, tab); } }
From source file:com.collir24.policyextractor.PolicyExtractorReport.java
License:Apache License
@Override protected void executeReport(Locale locale) throws MavenReportException { ResourceBundle localizedResources = getBundle(locale); Set<String> policySet = new TreeSet<String>(); Sink sink = getSink();//from www .j av a 2 s. co m sink.head(); sink.title(); sink.text(localizedResources.getString("report.pagetitle")); sink.title_(); sink.head_(); sink.body(); MavenProject project = getProject(); sink.sectionTitle1(); sink.text(localizedResources.getString("report.sectiontitle")); sink.sectionTitle1_(); Build build = project.getBuild(); sink.sectionTitle2(); sink.text(MessageFormat.format(localizedResources.getString("report.reportfor"), project.getName())); sink.sectionTitle2_(); sink.paragraph(); sink.text(localizedResources.getString("report.local.description")); sink.lineBreak(); sink.italic(); sink.text(localizedResources.getString("report.disclaimer")); sink.italic_(); sink.paragraph_(); Set<String> localProjectPolicySet = generateProjectPermissions(sink, project, build); generatePolicy(localProjectPolicySet, sink, null); policySet.addAll(localProjectPolicySet); sink.sectionTitle2(); sink.text(localizedResources.getString("report.allpermissions.title")); sink.sectionTitle2_(); sink.paragraph(); sink.text(localizedResources.getString("report.dependencies.description")); sink.paragraph_(); @SuppressWarnings("unchecked") Set<Artifact> artefacts = project.getArtifacts(); for (Artifact a : artefacts) { if (a.getScope().equals("test")) { continue; } JarFile jf; try { jf = new JarFile(a.getFile().getAbsolutePath()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Can't open file at: " + a.getFile().getAbsolutePath(), e); continue; } localProjectPolicySet = generateArtifactPermissions(sink, a, jf); generatePolicy(localProjectPolicySet, sink, a.getFile().getName()); policySet.addAll(localProjectPolicySet); } sink.sectionTitle2(); sink.text(localizedResources.getString("report.generatedpolicy.title")); sink.sectionTitle2_(); sink.paragraph(); sink.text(localizedResources.getString("report.generatedpolicy.description")); sink.paragraph_(); generatePolicy(policySet, sink, null); sink.sectionTitle2(); sink.text(localizedResources.getString("report.visualization.title")); sink.sectionTitle2_(); sink.paragraph(); String graphFilePath = outputDirectory + "/policyextractor.png"; new VisualizationGenerator(new File(graphFilePath)).generateVisualization(permissionList); sink.rawText("<img src=\"policyextractor.png\" width=\"300\">"); // sink.figure(); // sink.figureGraphics("policyextractor.png"); // sink.figure_(); sink.link("policyextractor.gexf"); sink.text("Graph Source"); sink.link_(); sink.paragraph_(); sink.body_(); sink.flush(); sink.close(); }
From source file:com.ericsson.research.trap.IndexConfigurator.java
License:Open Source License
private Collection<URL> buildAritfactDependencies(ExpressionEvaluator expressionEvaluator) throws ComponentConfigurationException { MavenProject project; try {/* w ww.jav a2s. c o m*/ project = (MavenProject) expressionEvaluator.evaluate("${project}"); } catch (ExpressionEvaluationException e1) { throw new ComponentConfigurationException("There was a problem evaluating: ${project}", e1); } Collection<URL> urls = new ArrayList<URL>(); for (Object a : project.getArtifacts()) { try { urls.add(((Artifact) a).getFile().toURI().toURL()); } catch (MalformedURLException e) { throw new ComponentConfigurationException("Unable to resolve artifact dependency: " + a, e); } } return urls; }
From source file:com.ericsson.tools.cpp.compiler.artifacts.ArtifactManager.java
License:Apache License
@SuppressWarnings("unchecked") public ArtifactManager(final Log log, final MavenProject project, final ArtifactFactory factory, final ArtifactResolver resolver, final ArtifactRepository localRepository, final List remoteRepositories) { this.factory = factory; this.resolver = resolver; this.localRepository = localRepository; this.remoteRepositories = remoteRepositories; this.carDependencies = new ArtifactFilter(log, "car").filter(project.getArtifacts()); }