List of usage examples for org.apache.maven.project MavenProject getVersion
public String getVersion()
From source file:governance.plugin.GovernanceMojo.java
License:Apache License
public void process(File file) throws MojoExecutionException { if (file.isFile() && file.getName().equals("pom.xml")) { pomFileCount++;//from ww w. j av a2 s.c o m getLog().debug("Processing " + file.getAbsoluteFile()); Model model = PomParser.parse(file); if (model == null) { throw new MojoExecutionException("Error while processing " + file.getAbsoluteFile()); } // Creating a module representing the artifact generated by pom file MavenProject project = new MavenProject(model); moduleCreator .create(new String[] { project.getArtifactId(), project.getVersion(), file.getAbsolutePath() }); String moduleAbsolutPath = moduleCreator.getAbsoluteArtifactResourcePath( new String[] { project.getArtifactId(), project.getVersion() }); // Creating dependency artifacts to represent dependencies of the module List<Dependency> dependencies = project.getDependencies(); for (Dependency dependency : dependencies) { dependencyCreator.create(new String[] { dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion() }); String dependencyAbsolutePath = dependencyCreator.getAbsoluteArtifactResourcePath( new String[] { dependency.getGroupId(), dependency.getArtifactId() }); // Adding association for each dependency with the module addAssociation(moduleAbsolutPath, dependencyAbsolutePath, "depends"); } } }
From source file:governance.plugin.ServiceGovernanceMojo.java
License:Apache License
public void linkServiceWithModule(Map<String, String> parameters, File file) throws MojoExecutionException { File currentPOM = findNearestPOMFile(file); if (currentPOM == null) { throw new MojoExecutionException( "Cannot find a POM related to this module. [file=" + file.getAbsolutePath() + "]"); }/*from w w w. ja v a 2 s .co m*/ Model model = PomParser.parse(currentPOM); if (model == null) { throw new MojoExecutionException("Error while processing " + currentPOM.getAbsoluteFile()); } // Creating a module representing the artifact generated by pom file MavenProject project = new MavenProject(model); String moduleAbsolutPath = moduleCreator .getAbsoluteArtifactResourcePath(new String[] { project.getArtifactId(), project.getVersion() }); String dependencyAbsolutePath = serviceCreator.getAbsoluteArtifactResourcePath( new String[] { parameters.get("name"), parameters.get("namespace") }); if (!artifactCreatorUtil.isArtifactExisting(moduleAbsolutPath)) { moduleCreator.create( new String[] { project.getArtifactId(), project.getVersion(), currentPOM.getAbsolutePath() }); } //Adding association for each service with the module addAssociation(moduleAbsolutPath, dependencyAbsolutePath, "depends"); addAssociation(dependencyAbsolutePath, moduleAbsolutPath, "usedBy"); }
From source file:governance.plugin.WebAppGovernanceMojo.java
License:Apache License
public void linkServiceWithModule(Map<String, String> parameters, File file) throws MojoExecutionException { File currentPOM = findNearestPOMFile(file); if (currentPOM == null) { throw new MojoExecutionException( "Cannot find a POM related to this module. [file=" + file.getAbsolutePath() + "]"); }//from w w w. ja v a 2 s. c o m Model model = PomParser.parse(currentPOM); if (model == null) { throw new MojoExecutionException("Error while processing " + currentPOM.getAbsoluteFile()); } // Creating a module representing the artifact generated by pom file MavenProject project = new MavenProject(model); String moduleAbsolutPath = moduleCreator .getAbsoluteArtifactResourcePath(new String[] { project.getArtifactId(), project.getVersion() }); String dependencyAbsolutePath = webApplicationCreator.getAbsoluteArtifactResourcePath( new String[] { parameters.get("name"), parameters.get("namespace") }); if (!artifactCreatorUtil.isArtifactExisting(moduleAbsolutPath)) { moduleCreator.create( new String[] { project.getArtifactId(), project.getVersion(), currentPOM.getAbsolutePath() }); } //Adding association for each service with the module addAssociation(moduleAbsolutPath, dependencyAbsolutePath, "depends"); addAssociation(dependencyAbsolutePath, moduleAbsolutPath, "usedBy"); }
From source file:hudson.gridmaven.ModuleDependency.java
License:Open Source License
public ModuleDependency(MavenProject project) { this(project.getGroupId(), project.getArtifactId(), project.getVersion()); }
From source file:hudson.gridmaven.PomInfo.java
License:Open Source License
public PomInfo(MavenProject project, PomInfo parent, String relPath) { this.name = new ModuleName(project); this.version = project.getVersion(); this.displayName = project.getName(); this.defaultGoal = project.getDefaultGoal(); this.relativePath = relPath; this.parent = parent; if (parent != null) parent.children.add(name);//from w w w. j a v a 2 s. com for (Dependency dep : (List<Dependency>) project.getDependencies()) dependencies.add(new ModuleDependency(dep)); MavenProject parentProject = project.getParent(); if (parentProject != null) dependencies.add(new ModuleDependency(parentProject)); if (parent != null) dependencies.add(parent.asDependency()); addPluginsAsDependencies(project.getBuildPlugins(), dependencies); addReportPluginsAsDependencies(project.getReportPlugins(), dependencies); List<Extension> extensions = project.getBuildExtensions(); if (extensions != null) for (Extension ext : extensions) dependencies.add(new ModuleDependency(ext)); // when the parent POM uses a plugin and builds a plugin at the same time, // the plugin module ends up depending on itself dependencies.remove(asDependency()); CiManagement ciMgmt = project.getCiManagement(); if ((ciMgmt != null) && (ciMgmt.getSystem() == null || ciMgmt.getSystem().equals("hudson"))) { Notifier mailNotifier = null; for (Notifier n : (List<Notifier>) ciMgmt.getNotifiers()) { if (n.getType().equals("mail")) { mailNotifier = n; break; } } this.mailNotifier = mailNotifier; } else this.mailNotifier = null; this.groupId = project.getGroupId(); this.artifactId = project.getArtifactId(); this.packaging = project.getPackaging(); }
From source file:hudson.gridmaven.reporters.MavenArtifactArchiver.java
License:Open Source License
public boolean postBuild(MavenBuildProxy build, MavenProject pom, final BuildListener listener) throws InterruptedException, IOException { // artifacts that are known to Maven. Set<File> mavenArtifacts = new HashSet<File>(); if (pom.getFile() != null) {// goals like 'clean' runs without loading POM, apparently. // record POM final MavenArtifact pomArtifact = new MavenArtifact(pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), null, "pom", pom.getFile().getName(), Util.getDigestOf(new FileInputStream(pom.getFile()))); final String repositoryUrl = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getUrl()); final String repositoryId = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getId()); mavenArtifacts.add(pom.getFile()); pomArtifact.archive(build, pom.getFile(), listener); // record main artifact (if packaging is POM, this doesn't exist) final MavenArtifact mainArtifact = MavenArtifact.create(pom.getArtifact()); if (mainArtifact != null) { File f = pom.getArtifact().getFile(); mavenArtifacts.add(f);/* w w w . j av a 2 s.c om*/ mainArtifact.archive(build, f, listener); } // record attached artifacts final List<MavenArtifact> attachedArtifacts = new ArrayList<MavenArtifact>(); for (Artifact a : pom.getAttachedArtifacts()) { MavenArtifact ma = MavenArtifact.create(a); if (ma != null) { mavenArtifacts.add(a.getFile()); ma.archive(build, a.getFile(), listener); attachedArtifacts.add(ma); } } // record the action build.executeAsync(new MavenBuildProxy.BuildCallable<Void, IOException>() { private static final long serialVersionUID = -7955474564875700905L; public Void call(MavenBuild build) throws IOException, InterruptedException { // if a build forks lifecycles, this method can be called multiple times List<MavenArtifactRecord> old = build.getActions(MavenArtifactRecord.class); if (!old.isEmpty()) build.getActions().removeAll(old); MavenArtifactRecord mar = new MavenArtifactRecord(build, pomArtifact, mainArtifact, attachedArtifacts, repositoryUrl, repositoryId); build.addAction(mar); // TODO kutzi: why are the fingerprints recorded here? // I thought that is the job of MavenFingerprinter mar.recordFingerprints(); return null; } }); } // do we have any assembly artifacts? // System.out.println("Considering "+assemblies+" at "+MavenArtifactArchiver.this); // new Exception().fillInStackTrace().printStackTrace(); if (assemblies != null) { for (File assembly : assemblies) { if (mavenArtifacts.contains(assembly)) continue; // looks like this is already archived if (build.isArchivingDisabled()) { listener.getLogger().println("[JENKINS] Archiving disabled - not archiving " + assembly); } else { FilePath target = build.getArtifactsDir().child(assembly.getName()); listener.getLogger().println("[JENKINS] Archiving " + assembly + " to " + target); new FilePath(assembly).copyTo(target); // TODO: fingerprint } } } return true; }
From source file:hudson.gridmaven.reporters.MavenFingerprinter.java
License:Open Source License
private Artifact getArtifact(MavenProject parent) { Artifact art = parent.getArtifact(); if (art == null) { // happens for Maven 2.x DefaultArtifactHandler artifactHandler = new DefaultArtifactHandler("pom"); art = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), VersionRange.createFromVersion(parent.getVersion()), null, "pom", "", artifactHandler); }// w w w . j a va2 s . c o m return art; }
From source file:hudson.maven.ReactorReader.java
License:Apache License
public List<String> findVersions(Artifact artifact) { String key = artifact.getGroupId() + ':' + artifact.getArtifactId(); List<MavenProject> projects = projectsByGA.get(key); if (projects == null || projects.isEmpty()) { return Collections.emptyList(); }//from ww w . ja v a2s .c o m List<String> versions = new ArrayList<String>(); for (MavenProject project : projects) { if (find(project, artifact) != null) { versions.add(project.getVersion()); } } return Collections.unmodifiableList(versions); }
From source file:hudson.maven.ReactorReader.java
License:Apache License
public void addProject(MavenProject mavenProject) { String key = mavenProject.getGroupId() + ':' + mavenProject.getArtifactId(); this.projectsByGA.put(key, Arrays.asList(mavenProject)); String projectKey = mavenProject.getGroupId() + ':' + mavenProject.getArtifactId() + ':' + mavenProject.getVersion(); this.projectsByGAV.put(projectKey, mavenProject); }
From source file:hudson.maven.reporters.MavenArtifactArchiver.java
License:Open Source License
public boolean postBuild(MavenBuildProxy build, MavenProject pom, final BuildListener listener) throws InterruptedException, IOException { // artifacts that are known to Maven. Set<File> mavenArtifacts = new HashSet<File>(); if (pom.getFile() != null) {// goals like 'clean' runs without loading POM, apparently. // record POM final MavenArtifact pomArtifact = new MavenArtifact(pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), null, "pom", pom.getFile().getName(), Util.getDigestOf(pom.getFile())); final String repositoryUrl = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getUrl()); final String repositoryId = pom.getDistributionManagementArtifactRepository() == null ? null : Util.fixEmptyAndTrim(pom.getDistributionManagementArtifactRepository().getId()); mavenArtifacts.add(pom.getFile()); pomArtifact.archive(build, pom.getFile(), listener); // record main artifact (if packaging is POM, this doesn't exist) final MavenArtifact mainArtifact = MavenArtifact.create(pom.getArtifact()); if (mainArtifact != null) { File f = pom.getArtifact().getFile(); mavenArtifacts.add(f);// w ww . j ava2s . co m mainArtifact.archive(build, f, listener); } // record attached artifacts final List<MavenArtifact> attachedArtifacts = new ArrayList<MavenArtifact>(); for (Artifact a : pom.getAttachedArtifacts()) { MavenArtifact ma = MavenArtifact.create(a); if (ma != null) { mavenArtifacts.add(a.getFile()); ma.archive(build, a.getFile(), listener); attachedArtifacts.add(ma); } } // record the action build.executeAsync(new MavenBuildProxy.BuildCallable<Void, IOException>() { private static final long serialVersionUID = -7955474564875700905L; public Void call(MavenBuild build) throws IOException, InterruptedException { // if a build forks lifecycles, this method can be called multiple times List<MavenArtifactRecord> old = build.getActions(MavenArtifactRecord.class); if (!old.isEmpty()) build.getActions().removeAll(old); MavenArtifactRecord mar = new MavenArtifactRecord(build, pomArtifact, mainArtifact, attachedArtifacts, repositoryUrl, repositoryId); build.addAction(mar); // TODO kutzi: why are the fingerprints recorded here? // I thought that is the job of MavenFingerprinter mar.recordFingerprints(); return null; } }); } // do we have any assembly artifacts? // System.out.println("Considering "+assemblies+" at "+MavenArtifactArchiver.this); // new Exception().fillInStackTrace().printStackTrace(); if (build.isArchivingDisabled()) { listener.getLogger().println("[JENKINS] Archiving disabled"); } else if (assemblies != null) { for (File assembly : assemblies) { if (mavenArtifacts.contains(assembly)) continue; // looks like this is already archived FilePath target = build.getArtifactsDir().child(assembly.getName()); listener.getLogger().println("[JENKINS] Archiving " + assembly + " to " + target); new FilePath(assembly).copyTo(target); // TODO: fingerprint } } return true; }