List of usage examples for org.apache.maven.project MavenProject getPluginArtifacts
public Set<Artifact> getPluginArtifacts()
From source file:info.ronjenkins.maven.rtr.steps.ValidateSmartReactorEligibility.java
License:Apache License
@Override public void execute(final MavenSession session, final RTRComponents components) throws MavenExecutionException { // Ensure that the Maven Release Plugin is not in the list of goals. for (final String goal : session.getGoals()) { if (goal.startsWith("release:") || goal.startsWith("org.apache.maven.plugins:maven-release-plugin:")) { this.logger.error(""); throw new SmartReactorSanityCheckException( "A goal from the Maven Release Plugin was specified for execution."); }/*w ww . ja va 2 s .co m*/ } // Ensure that the Maven Release Plugin is not declared in the POM. final List<MavenProject> projectsWithMavenReleasePlugin = new ArrayList<>(); for (final MavenProject project : session.getProjects()) { for (final Artifact artifact : project.getPluginArtifacts()) { if (artifact.getGroupId().equals("org.apache.maven.plugins") && artifact.getArtifactId().equals("maven-release-plugin")) { projectsWithMavenReleasePlugin.add(project); } } } if (!projectsWithMavenReleasePlugin.isEmpty()) { this.logger.error(""); for (final MavenProject project : projectsWithMavenReleasePlugin) { this.logger.error("Project " + project + " contains a reference to the Maven Release Plugin."); } this.logger.error(""); throw new SmartReactorSanityCheckException("Reactor is ineligible to become a Smart Reactor."); } // Ensure that the root is a SNAPSHOT. final MavenProject root = session.getTopLevelProject(); if (!root.getArtifact().isSnapshot()) { this.logger.error(""); this.logger.error("Top-level project " + root + " is not a SNAPSHOT."); this.logger.error(""); throw new SmartReactorSanityCheckException("Reactor is ineligible to become a Smart Reactor."); } // Ensure that the ancestors of every SNAPSHOT are also SNAPSHOTs. final ProjectDependencyGraph pdg = session.getProjectDependencyGraph(); final List<MavenProject> badProjects = new ArrayList<>(); for (final MavenProject project : session.getProjects()) { if (project.getArtifact().isSnapshot()) { for (final MavenProject ancestor : pdg.getUpstreamProjects(project, true)) { if (!ancestor.getArtifact().isSnapshot()) { badProjects.add(ancestor); } } } } // Fail if necessary. if (!badProjects.isEmpty()) { this.logger.error(""); this.logger.error( "The following release projects in the reactor have SNAPSHOT dependencies in the reactor, which is not allowed:"); for (final MavenProject badProject : badProjects) { this.logger.error(" " + badProject.getArtifact().toString() + " @ " + badProject.getFile().getAbsolutePath()); } this.logger.error(""); throw new SmartReactorSanityCheckException("Reactor is ineligible to become a Smart Reactor."); } }
From source file:net.oneandone.maven.plugins.prerelease.core.Descriptor.java
License:Apache License
/** @return this */ public Descriptor check(World world, MavenProject mavenProject, boolean allowSnapshots, boolean allowPrereleaseSnapshots) throws TagAlreadyExists, VersioningProblem, CannotDeterminTagBase, MissingScmTag, CannotBumpVersion, MissingDeveloperConnection { List<String> problems; MavenProject parent;//from ww w . j av a 2 s . c om problems = new ArrayList<>(); checkSnapshot("project", mavenProject.getVersion(), problems); parent = mavenProject.getParent(); if (parent != null) { checkRelease("project parent", parent.getVersion(), problems); } for (Dependency dependency : mavenProject.getDependencies()) { checkRelease(dependency.getGroupId() + ":" + dependency.getArtifactId(), dependency.getVersion(), problems); } for (Artifact artifact : mavenProject.getPluginArtifacts()) { if (allowPrereleaseSnapshots && "net.oneandone.maven.plugins".equals(artifact.getGroupId()) && "prerelease".equals(artifact.getArtifactId())) { // skip for integration tests } else { checkRelease(artifact.getGroupId() + ":" + artifact.getArtifactId(), artifact.getVersion(), problems); } } if (problems.size() > 0 && !allowSnapshots) { throw new VersioningProblem(problems); } if (Subversion.exists(world.getTemp(), svnTag)) { throw new TagAlreadyExists(svnTag); } return this; }
From source file:org.fedoraproject.tycho.TychoBootstrapMojo.java
License:Open Source License
private Set<String> getInitialBootstrapArtifacts() { Set<String> res = new HashSet<String>(); String tychoBootstrapVersion = session.getProjects().get(0).getProperties() .getProperty("tychoBootstrapVersion"); for (MavenProject proj : session.getProjects()) { for (Artifact plugin : proj.getPluginArtifacts()) { if (EXPECTED_GID.equals(plugin.getGroupId()) && plugin.getVersion().equals(tychoBootstrapVersion) && !isExcluded(proj)) { res.add(plugin.getArtifactId()); }//from w w w . j a v a 2s . co m } } return res; }
From source file:org.gephi.maven.GenerateUtils.java
License:Apache License
protected static String getPluginVersion(MavenProject project) { Set pluginArtifacts = project.getPluginArtifacts(); for (Iterator iterator = pluginArtifacts.iterator(); iterator.hasNext();) { Artifact artifact = (Artifact) iterator.next(); String groupId = artifact.getGroupId(); String artifactId = artifact.getArtifactId(); if (groupId.equals("org.gephi") && artifactId.equals("gephi-maven-plugin")) { return artifact.getVersion(); }/*ww w. j a v a 2 s .co m*/ } return null; }
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;// w w w.j a v a2 s .co m 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.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 ww.j ava 2 s. c o 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; }