List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:org.codehaus.cargo.maven2.util.CargoProject.java
License:Apache License
/** * Saves all attributes./*from ww w.j a v a 2 s .c o m*/ * @param project Maven2 project. * @param log Logger. */ public CargoProject(MavenProject project, Log log) { this(project.getPackaging(), project.getGroupId(), project.getArtifactId(), project.getBuild().getDirectory(), project.getBuild().getFinalName(), project.getArtifact(), project.getAttachedArtifacts(), project.getArtifacts(), log); }
From source file:org.codehaus.continuum.builder.maven2.Maven2ContinuumBuilder.java
License:Open Source License
public ContinuumProject createProject(File workingDirectory) throws ContinuumException { Maven2ProjectDescriptor descriptor = new Maven2ProjectDescriptor(); // try // {//from w w w . j av a 2s.com // scm.checkOutProject( project ); // } // catch( ContinuumScmException ex ) // { // throw new ContinuumException( "Error while checking out the project.", ex ); // } MavenProject mavenProject; File pomFile = getPomFile(workingDirectory); mavenProject = mavenTool.getProject(pomFile); List goals = new LinkedList(); goals.add("pom:install"); mavenTool.execute(mavenProject, goals); // ---------------------------------------------------------------------- // Populating the descriptor // ---------------------------------------------------------------------- if (mavenProject.getScm() == null) { throw new ContinuumException("The project descriptor is missing the SCM section."); } if (mavenProject.getCiManagement() == null) { throw new ContinuumException("The project descriptor is missing the CI section."); } Build build = mavenProject.getBuild(); boolean isPom = true; if (build != null) { String sourceDirectory = build.getSourceDirectory(); if (sourceDirectory != null && sourceDirectory.trim().length() > 0) { if (new File(sourceDirectory).isDirectory()) { isPom = false; } } } if (isPom) { descriptor.getGoals().add("pom:install"); } else { descriptor.getGoals().add("clean:clean"); descriptor.getGoals().add("jar:install"); } // descriptor.setName( mavenProject.getName() ); // The public Url takes priority over the developer connection Scm scm = mavenProject.getScm(); String scmUrl = scm.getConnection(); if (StringUtils.isEmpty(scmUrl)) { scmUrl = scm.getDeveloperConnection(); } if (StringUtils.isEmpty(scmUrl)) { throw new ContinuumException("Missing both anonymous and developer scm connection urls."); } // descriptor.setScmUrl( scmUrl ); CiManagement ciManagement = mavenProject.getCiManagement(); String nagEmailAddress = ciManagement.getNagEmailAddress(); if (StringUtils.isEmpty(nagEmailAddress)) { throw new ContinuumException( "Missing nag email address from the ci section of the project descriptor."); } // descriptor.setNagEmailAddress( nagEmailAddress ); String version = mavenProject.getVersion(); if (StringUtils.isEmpty(version)) { throw new ContinuumException("Missing version from the project descriptor."); } // descriptor.setVersion( version ); // ---------------------------------------------------------------------- // Make the project // ---------------------------------------------------------------------- ContinuumProject project = new GenericContinuumProject(); if (StringUtils.isEmpty(mavenProject.getName())) { throw new ContinuumException("The project name cannot be empty."); } project.setName(mavenProject.getName()); project.setScmUrl(scmUrl); project.setNagEmailAddress(nagEmailAddress); project.setVersion(version); project.setDescriptor(descriptor); return project; }
From source file:org.codehaus.griffon.maven.plugin.tools.DefaultGriffonServices.java
License:Apache License
public MavenProject createPOM(String groupId, GriffonProject griffonProjectDescriptor, String mtgGroupId, String griffonPluginArtifactId, String mtgVersion, boolean addEclipseSettings) { MavenProject pom = new MavenProject(); if (pom.getBuild().getPluginManagement() == null) { pom.getBuild().setPluginManagement(new PluginManagement()); }/*from w w w. j av a2 s.co m*/ PluginManagement pluginMgt = pom.getPluginManagement(); // Those four properties are needed. pom.setModelVersion("4.0.0"); pom.setPackaging("griffon-app"); // Specific for GRAILS pom.getModel().getProperties().setProperty("griffonHome", "${env.GRIFFON_HOME}"); pom.getModel().getProperties().setProperty("griffonVersion", griffonProjectDescriptor.getAppGriffonVersion()); // Add our own plugin Plugin griffonPlugin = new Plugin(); griffonPlugin.setGroupId(mtgGroupId); griffonPlugin.setArtifactId(griffonPluginArtifactId); griffonPlugin.setVersion(mtgVersion); griffonPlugin.setExtensions(true); pom.addPlugin(griffonPlugin); // Add compiler plugin settings Plugin compilerPlugin = new Plugin(); compilerPlugin.setGroupId("org.apache.maven.plugins"); compilerPlugin.setArtifactId("maven-compiler-plugin"); Xpp3Dom compilerConfig = new Xpp3Dom("configuration"); Xpp3Dom source = new Xpp3Dom("source"); source.setValue("1.5"); compilerConfig.addChild(source); Xpp3Dom target = new Xpp3Dom("target"); target.setValue("1.5"); compilerConfig.addChild(target); compilerPlugin.setConfiguration(compilerConfig); pom.addPlugin(compilerPlugin); // Add eclipse plugin settings if (addEclipseSettings) { Plugin eclipsePlugin = new Plugin(); eclipsePlugin.setGroupId("org.apache.maven.plugins"); eclipsePlugin.setArtifactId("maven-eclipse-plugin"); Xpp3Dom configuration = new Xpp3Dom("configuration"); Xpp3Dom projectnatures = new Xpp3Dom("additionalProjectnatures"); Xpp3Dom projectnature = new Xpp3Dom("projectnature"); projectnature.setValue("org.codehaus.groovy.eclipse.groovyNature"); projectnatures.addChild(projectnature); configuration.addChild(projectnatures); Xpp3Dom additionalBuildcommands = new Xpp3Dom("additionalBuildcommands"); Xpp3Dom buildcommand = new Xpp3Dom("buildcommand"); buildcommand.setValue("org.codehaus.groovy.eclipse.groovyBuilder"); additionalBuildcommands.addChild(buildcommand); configuration.addChild(additionalBuildcommands); Xpp3Dom packaging = new Xpp3Dom("packaging"); packaging.setValue("zip"); configuration.addChild(packaging); eclipsePlugin.setConfiguration(configuration); pluginMgt.addPlugin(eclipsePlugin); } // Change the default output directory to generate classes pom.getModel().getBuild().setOutputDirectory("web-app/WEB-INF/classes"); pom.setArtifactId(griffonProjectDescriptor.getAppName()); pom.setName(griffonProjectDescriptor.getAppName()); pom.setGroupId(groupId); pom.setVersion(griffonProjectDescriptor.getAppVersion()); if (!griffonProjectDescriptor.getAppVersion().endsWith("SNAPSHOT")) { getLogger().warn("====================================================================="); getLogger().warn("If your project is currently in development, in accordance with maven "); getLogger().warn("standards, its version must be " + griffonProjectDescriptor.getAppVersion() + "-SNAPSHOT and not " + griffonProjectDescriptor.getAppVersion() + "."); getLogger().warn("Please, change your version in the application.properties descriptor"); getLogger().warn("and regenerate your pom."); getLogger().warn("====================================================================="); } return pom; }
From source file:org.codehaus.mojo.apt.MavenProjectUtils.java
License:Open Source License
private static void addArtifactPath(MavenProject project, Artifact artifact, List<String> list) throws DependencyResolutionRequiredException { String refId = getProjectReferenceId(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());/*from w ww . j a v a 2s.co m*/ MavenProject refProject = (MavenProject) project.getProjectReferences().get(refId); boolean projectDirFound = false; if (refProject != null) { if (artifact.getType().equals("test-jar")) { File testOutputDir = new File(refProject.getBuild().getTestOutputDirectory()); if (testOutputDir.exists()) { list.add(testOutputDir.getAbsolutePath()); projectDirFound = true; } } else { list.add(refProject.getBuild().getOutputDirectory()); projectDirFound = true; } } if (!projectDirFound) { File file = artifact.getFile(); if (file == null) { throw new DependencyResolutionRequiredException(artifact); } list.add(file.getPath()); } }
From source file:org.codehaus.mojo.cpp.tools.settings.PluginSettingsImpl.java
License:Apache License
public PluginSettingsImpl(final MavenProject project, final Map<String, String> configuredSources, final File outputDirectory, final File testOutputDirectory) { this.project = project; this.outputDirectory = outputDirectory; this.testOutputDirectory = testOutputDirectory; this.sources = createSourcesMapping(configuredSources); this.extractedDependenciesDirectory = new File(project.getBuild().getDirectory(), "extractedDependencies"); this.objBaseDirectory = new File(project.getBuild().getDirectory(), "obj"); this.testObjBaseDirectory = new File(project.getBuild().getDirectory(), "testObj"); }
From source file:org.codehaus.mojo.cruisecontrol.CruiseControlMojo.java
License:Apache License
private void addLog(XMLWriter writer, MavenProject reactorProject) throws MojoExecutionException { writer.startElement("log"); {//w w w .ja v a 2s . c o m File sureFireDir = new File(reactorProject.getBuild().getDirectory() + "/surefire-reports"); writer.startElement("merge"); writer.addAttribute("dir", "checkout/" + toRelativeAndFixSeparator(basedir, sureFireDir)); writer.endElement(); } writer.endElement(); }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * @param projectName//from w w w. j a v a2 s .c o m * @param checkstyleDataFile * @return */ protected CheckstyleReportBean getCheckstyleReport(MavenProject project, Date generatedDate) { CheckstyleReportBean checkstyleReport = new CheckstyleReportBean(generatedDate); File checkstyleFile = new File(project.getBuild().getDirectory(), this.checkstyleDataFile); if (checkstyleFile.exists() && checkstyleFile.isFile()) { Document doc = this.getDocument(checkstyleFile); if (doc != null) { Element cpd = doc.getDocumentElement(); NodeList files = cpd.getElementsByTagName("file"); NodeList total = cpd.getElementsByTagName("error"); int nbInfos = 0; int nbWarnings = 0; int nbErrors = 0; for (int i = 0; i < total.getLength(); i++) { Element error = (Element) total.item(i); CheckstyleError checkstyleError = new CheckstyleError(); String severity = error.getAttribute("severity"); if (severity.equalsIgnoreCase("info")) { nbInfos++; } else if (severity.equalsIgnoreCase("warning")) { nbWarnings++; } else if (severity.equalsIgnoreCase("error")) { nbErrors++; } // error management for Checkstyle Violations Chart. Fixes MOJO-679 . // Written by <a href="mailto:srivollet@objectif-informatique.fr">Sylvain Rivollet</a>. checkstyleError.setType(error.getAttribute("severity")); checkstyleError.setNameClass(error.getAttribute("source")); checkstyleError.setMessage(error.getAttribute("message")); checkstyleReport.addError(checkstyleError); } checkstyleReport.setNbClasses(files.getLength()); checkstyleReport.setNbErrors(nbErrors); checkstyleReport.setNbInfos(nbInfos); checkstyleReport.setNbTotal(total.getLength()); checkstyleReport.setNbWarnings(nbWarnings); } else { checkstyleReport = null; } } else { checkstyleReport = null; } return checkstyleReport; }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * @param project/*from www .j a v a 2 s . c o m*/ * @return */ protected CpdReportBean getCpdReport(MavenProject project, Date generatedDate) { CpdReportBean cpdReport = new CpdReportBean(generatedDate); File cpdFile = new File(project.getBuild().getDirectory(), this.cpdDataFile); if (cpdFile.exists() && cpdFile.isFile()) { Document doc = this.getDocument(cpdFile); if (doc != null) { Element cpd = doc.getDocumentElement(); NodeList duplications = cpd.getElementsByTagName("duplication"); NodeList files = cpd.getElementsByTagName("file"); Vector filelist = new Vector(); for (int i = 0; i < files.getLength(); i++) { Element file = (Element) files.item(i); if (!filelist.contains(file.getAttribute("path"))) { filelist.add(file.getAttribute("path")); } } cpdReport.setNbClasses(filelist.size()); cpdReport.setNbDuplicate(duplications.getLength()); } else { cpdReport = null; } } else { cpdReport = null; } return cpdReport; }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * @param project//from w w w . ja v a 2 s .c o m * @return */ protected PmdReportBean getPmdReport(MavenProject project, Date generatedDate) { PmdReportBean pmdReport = new PmdReportBean(generatedDate); File pmdFile = new File(project.getBuild().getDirectory(), this.pmdDataFile); if (pmdFile.exists() && pmdFile.isFile()) { Document doc = this.getDocument(pmdFile); if (doc != null) { Element pmd = doc.getDocumentElement(); NodeList files = pmd.getElementsByTagName("file"); NodeList violations = pmd.getElementsByTagName("violation"); pmdReport.setNbClasses(files.getLength()); pmdReport.setNbViolations(violations.getLength()); } else { pmdReport = null; } } else { pmdReport = null; } return pmdReport; }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * Fixes MOJO-813. addition of Clover support written by <a href="mailto:mbeerman@yahoo.com">Matthew Beermann</a> * /*from ww w.j a v a 2 s. c om*/ * @param project * @return */ protected CloverReportBean getCloverReport(MavenProject project, Date generatedDate) { CloverReportBean cloverReport = new CloverReportBean(generatedDate); File cloverReportFile = new File(project.getBuild().getDirectory(), this.cloverDataFile); if (cloverReportFile != null && cloverReportFile.exists() && cloverReportFile.isFile()) { try { Document doc = this.getDocument(cloverReportFile); if (doc != null) { NodeList allMetrics = doc.getElementsByTagName("metrics"); Element metrics = null; for (int i = 0; i < allMetrics.getLength(); i++) { Element candidate = (Element) allMetrics.item(i); if (candidate.getParentNode().getNodeName().equals("project")) { metrics = candidate; break; } } if (metrics == null) { return null; } cloverReport.setConditionals(Integer.parseInt(metrics.getAttribute("conditionals"))); cloverReport.setStatements(Integer.parseInt(metrics.getAttribute("statements"))); cloverReport.setMethods(Integer.parseInt(metrics.getAttribute("methods"))); cloverReport.setElements(Integer.parseInt(metrics.getAttribute("elements"))); cloverReport .setCoveredConditionals(Integer.parseInt(metrics.getAttribute("coveredconditionals"))); cloverReport.setCoveredStatements(Integer.parseInt(metrics.getAttribute("coveredstatements"))); cloverReport.setCoveredMethods(Integer.parseInt(metrics.getAttribute("coveredmethods"))); cloverReport.setCoveredElements(Integer.parseInt(metrics.getAttribute("coveredelements"))); } else { cloverReport = null; } } catch (Exception e) { this.log.error("CloverReportBean creation failed.", e); cloverReport = null; } } else { cloverReport = null; } return cloverReport; }