List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * get the JDependReportBean which represents the Cobertura .ser file analysis * /*from w w w .ja va 2 s . c o m*/ * @param project * @return */ protected JDependReportBean getJDependReport(MavenProject project, Date generatedDate) { this.log.debug("JDependReportBean creation = " + project.getName() + "."); JDependReportBean jDependReport = new JDependReportBean(generatedDate); File coberturaFile = getCoberturaDataFile(project); File jDependFile = new File(project.getBuild().getDirectory(), this.jDependDataFile); ProjectData projectData = null; if (coberturaFile.exists() && coberturaFile.isFile()) { projectData = CoverageDataFileHandler.loadCoverageData(coberturaFile); } if (jDependFile.exists() && jDependFile.isFile()) { JDependXMLReportParser xmlParser; try { xmlParser = new JDependXMLReportParser(jDependFile); List packages = xmlParser.getPackages(); if (packages != null && packages.size() > 0) { Iterator iter = packages.iterator(); while (iter.hasNext()) { JDPackage pack = (JDPackage) iter.next(); XRefPackageBean bean = new XRefPackageBean(); bean.setPackageName(pack.getPackageName()); int iCa = Integer.parseInt(pack.getStats().getCa()); bean.setAfferentCoupling(new Integer(iCa)); if (projectData != null) { CoverageData data = projectData.getChild(pack.getPackageName()); if (data != null) { bean.setLineCoverRate(data.getLineCoverageRate()); bean.setBranchCoverRate(data.getBranchCoverageRate()); } } jDependReport.addPackage(bean); } } else { jDependReport = null; } } catch (ParserConfigurationException e) { this.log.error("JDependReportBean creation failed.", e); jDependReport = null; } catch (SAXException e) { this.log.error("JDependReportBean creation failed.", e); jDependReport = null; } catch (IOException e) { this.log.error("JDependReportBean creation failed.", e); jDependReport = null; } } else { jDependReport = null; } return jDependReport; }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * @param projectName/*from w ww . j a va2 s . c o m*/ * @param FindBugsDataFile * @return */ protected FindBugsReportBean getFindBugsReport(MavenProject project, Date generatedDate) { FindBugsReportBean findBugsReport = new FindBugsReportBean(generatedDate); File findBugsFile = new File(project.getBuild().getDirectory(), this.findBugsDataFile); if (findBugsFile.exists() && findBugsFile.isFile()) { Document doc = this.getDocument(findBugsFile); if (doc != null) { Element root = doc.getDocumentElement(); NodeList files = root.getElementsByTagName("file"); NodeList bugs = root.getElementsByTagName("BugInstance"); NodeList missing = root.getElementsByTagName("MissingClass"); findBugsReport.setNbClasses(files.getLength()); findBugsReport.setNbErrors(0); findBugsReport.setNbBugs(bugs.getLength()); findBugsReport.setNbMissingClasses(missing.getLength()); for (int i = 0; i < bugs.getLength(); i++) { Element bugInstance = (Element) bugs.item(i); String category = bugInstance.getAttribute("category"); findBugsReport.addCategory(category); String priority = bugInstance.getAttribute("priority"); findBugsReport.addPriority(priority); } } else { findBugsReport = null; } } else { findBugsReport = null; } return findBugsReport; }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * @param project/*from w w w. j a v a 2 s .com*/ * @param generatedDate * @return */ protected TagListReportBean getTaglistReport(MavenProject project, Date generatedDate) { TagListReportBean taglistReport = new TagListReportBean(generatedDate); File taglistFile = new File(project.getBuild().getDirectory(), taglistDataFile); if (taglistFile.exists() && taglistFile.isFile()) { Document doc = this.getDocument(taglistFile); if (doc != null) { Element root = doc.getDocumentElement(); NodeList tags = root.getElementsByTagName("tag"); for (int i = 0; i < tags.getLength(); i++) { Element tag = (Element) tags.item(i); String tagName = tag.getAttribute("name"); Integer tagCount = Integer.valueOf(tag.getAttribute("count")); taglistReport.setTag(tagName, tagCount); } NodeList files = root.getElementsByTagName("file"); Map classFiles = new HashMap(); for (int i = 0; i < files.getLength(); i++) { Element file = (Element) files.item(i); String className = file.getAttribute("name"); classFiles.put(className, new Integer(1)); } taglistReport.setNbClasses(classFiles.size()); } else { taglistReport = null; } } else { taglistReport = null; } return taglistReport; }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * @param project/*from w w w . j ava2s. c o m*/ * @param dashboardDataFile * @return */ protected DashBoardMavenProject readXMLDashBoardReport(MavenProject project, String dashboardDataFile) { DashBoardMavenProject mavenProject = null; try { // Instanciation de la classe XStream XStream xstream = new XStream(new DomDriver()); // Instanciation d'un fichier File fichier = new File(project.getBuild().getDirectory(), dashboardDataFile); // Redirection du fichier /target/dashboard-report.xml vers un flux // d'entre fichier FileInputStream fis = new FileInputStream(fichier); try { xstream.setMode(XStream.NO_REFERENCES); // Convertion du contenu de l'objet DashBoardReportBean en XML xstream.alias("MavenProject", DashBoardMavenProject.class); xstream.alias("xrefpackage", XRefPackageBean.class); xstream.alias("checkstyleerror", CheckstyleError.class); xstream.useAttributeFor("id", Long.class); xstream.useAttributeFor("artifactId", String.class); xstream.useAttributeFor("groupId", String.class); xstream.useAttributeFor("version", String.class); xstream.useAttributeFor("projectName", String.class); xstream.useAttributeFor("generatedDate", Date.class); xstream.useAttributeFor("averageAfferentCoupling", String.class); xstream.useAttributeFor("nbPackages", String.class); xstream.useAttributeFor("sumAC", String.class); // Dsrialisation du fichier /target/dashboard-multi-report.xml vers un nouvel // objet DashBoardReportBean mavenProject = (DashBoardMavenProject) xstream.fromXML(fis); } finally { // On s'assure de fermer le flux quoi qu'il arrive fis.close(); } } catch (FileNotFoundException e) { System.out.println( "readXMLDashBoardReport() for project " + project.getName() + " failed :" + e.getMessage()); mavenProject = null; } catch (IOException ioe) { System.out.println( "readXMLDashBoardReport() for project " + project.getName() + " failed :" + ioe.getMessage()); mavenProject = null; } return mavenProject; }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * @param project//w ww . j ava2 s. c o m * @param dashBoardReport * @param dashboardDataFile */ protected void saveXMLDashBoardReport(MavenProject project, DashBoardMavenProject mavenProject, String dashboardDataFile) { try { // Instanciation de la classe XStream XStream xstream = new XStream(new DomDriver()); // Instanciation d'un fichier File dir = new File(project.getBuild().getDirectory()); if (!dir.exists()) { dir.mkdirs(); } File fichier = new File(dir, dashboardDataFile); // Instanciation d'un flux de sortie fichier vers le xml FileOutputStream fos = new FileOutputStream(fichier); OutputStreamWriter output = new OutputStreamWriter(fos, "UTF-8"); try { output.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); xstream.setMode(XStream.NO_REFERENCES); // Convertion du contenu de l'objet DashBoardReportBean en XML xstream.alias("MavenProject", DashBoardMavenProject.class); xstream.alias("xrefpackage", XRefPackageBean.class); xstream.alias("checkstyleerror", CheckstyleError.class); xstream.useAttributeFor("id", Long.class); xstream.useAttributeFor("artifactId", String.class); xstream.useAttributeFor("groupId", String.class); xstream.useAttributeFor("version", String.class); xstream.useAttributeFor("projectName", String.class); xstream.useAttributeFor("generatedDate", Date.class); xstream.useAttributeFor("averageAfferentCoupling", String.class); xstream.useAttributeFor("nbPackages", String.class); xstream.useAttributeFor("sumAC", String.class); // Srialisation de l'objet dashBoardReport dans /target/dashboard-report.xml xstream.toXML(mavenProject, output); } finally { // On s'assure de fermer le flux quoi qu'il arrive fos.close(); } } catch (FileNotFoundException e) { this.log.error("saveXMLDashBoardReport() failed.", e); } catch (IOException ioe) { this.log.error("saveXMLDashBoardReport() failed.", ioe); } }
From source file:org.codehaus.mojo.dashboard.report.plugin.DashBoardUtils.java
License:Apache License
/** * get the Cobertura datafile. MOJO-644 : pb with different versions of Cobertura plugin. for cobertura 2.1 * default-value="${project.build.directory}/cobertura/cobertura.ser" for cobertura 2.0 * default-value="${basedir}/cobertura.ser" MOJO-674 : NumberFormatException fixed by using DefaultArtifactVersion * class MOJO-749 : NPE if dashboard called on parent project (when no cobertura version in pom.xml) * /*from ww w .j a v a 2s . c om*/ * @param project * MavenProject to be processed * @return cobertura.ser File object */ private File getCoberturaDataFile(MavenProject project) { /* * HACK to address the broken datafile location code in Cobertura See * https://sourceforge.net/tracker/index.php?func=detail&aid=1543280&group_id=130558&atid=720017 Until patch is * commited, this hack will be in place. */ File coberturaFile = null; File brokenDatafile = new File(project.getBasedir(), this.coberturaDataFile); File dataFile = new File(project.getBuild().getDirectory(), "cobertura/" + this.coberturaDataFile); if (brokenDatafile != null && brokenDatafile.exists()) { try { FileUtils.copyFile(brokenDatafile, dataFile); brokenDatafile.delete(); coberturaFile = dataFile; } catch (IOException e) { coberturaFile = null; } } if (dataFile != null && dataFile.exists()) { coberturaFile = dataFile; } else { coberturaFile = null; } return coberturaFile; }
From source file:org.codehaus.mojo.dashboard.report.plugin.utils.DashXStreamUtils.java
License:Apache License
/** * /* w ww . j av a2 s. co m*/ * @param project * @param dashboardDataFile * @return * @throws DashXStreamUtilsException */ public DashBoardMavenProject readXMLDashBoardReport(MavenProject project, String dashboardDataFile) throws DashXStreamUtilsException { DashBoardMavenProject mavenProject = null; try { // Instanciation d'un fichier File fichier = new File(project.getBuild().getDirectory(), dashboardDataFile); // Redirection du fichier /target/dashboard-report.xml vers un flux // d'entre fichier FileInputStream fis = new FileInputStream(fichier); try { // Dsrialisation du fichier /target/dashboard-multi-report.xml vers un nouvel // objet DashBoardReportBean mavenProject = (DashBoardMavenProject) xstream.fromXML(fis); } finally { // On s'assure de fermer le flux quoi qu'il arrive fis.close(); } } catch (FileNotFoundException e) { System.out.println( "readXMLDashBoardReport() for project " + project.getName() + " failed :" + e.getMessage()); throw new DashXStreamUtilsException( "readXMLDashBoardReport() for project " + project.getName() + " failed .", e.fillInStackTrace()); } catch (IOException ioe) { throw new DashXStreamUtilsException( "readXMLDashBoardReport() for project " + project.getName() + " failed .", ioe.fillInStackTrace()); } return mavenProject; }
From source file:org.codehaus.mojo.dashboard.report.plugin.utils.DashXStreamUtils.java
License:Apache License
/** * /*from ww w.jav a 2s .co m*/ * @param project * @param mavenProject * @param dashboardDataFile * @throws DashXStreamUtilsException */ public void saveXMLDashBoardReport(MavenProject project, DashBoardMavenProject mavenProject, String dashboardDataFile) throws DashXStreamUtilsException { try { // Instanciation d'un fichier File dir = new File(project.getBuild().getDirectory()); if (!dir.exists()) { dir.mkdirs(); } File fichier = new File(dir, dashboardDataFile); // Instanciation d'un flux de sortie fichier vers le xml FileOutputStream fos = new FileOutputStream(fichier); OutputStreamWriter output = new OutputStreamWriter(fos, "UTF-8"); try { output.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); // Srialisation de l'objet dashBoardReport dans /target/dashboard-report.xml xstream.toXML(mavenProject, output); } finally { // On s'assure de fermer le flux quoi qu'il arrive fos.close(); } } catch (FileNotFoundException e) { throw new DashXStreamUtilsException( "saveXMLDashBoardReport() for project " + project.getName() + " failed .", e.fillInStackTrace()); } catch (IOException ioe) { throw new DashXStreamUtilsException( "saveXMLDashBoardReport() for project " + project.getName() + " failed .", ioe.fillInStackTrace()); } }
From source file:org.codehaus.mojo.emma.EmmaUtils.java
License:Open Source License
/** * Fix EMMA data file locations. EMMA generates data files in wrong locations: this method moves these files to * valid locations.// w w w. ja v a 2 s . c o m * * @param project current Maven project * @param dataFiles to fix * @return new data file locations */ public static File[] fixDataFileLocations(MavenProject project, File[] dataFiles) { if (dataFiles == null) { return new File[0]; } final List newDataFiles = new ArrayList(dataFiles.length); for (int i = 0; i < dataFiles.length; ++i) { final File src = dataFiles[i]; if (!src.exists()) { // if the file does not exist, we cannot use it continue; } if (src.getParentFile().equals(project.getBasedir())) { // EMMA generates coverage data files in project root // (as it is actually the current directory): // move these files to the "target" directory final File dst = new File(project.getBuild().getDirectory(), "coverage-" + i + ".ec"); try { FileUtils.rename(src, dst); } catch (IOException e) { final RuntimeException e2 = new IllegalStateException( "Failed to move coverage data file: " + src.getAbsolutePath()); e2.initCause(e); throw e2; } newDataFiles.add(dst); } else { newDataFiles.add(src); } } return (File[]) newDataFiles.toArray(new File[newDataFiles.size()]); }
From source file:org.codehaus.mojo.gwt.ClasspathBuilder.java
License:Apache 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). 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)./*from w w w . j av a2 s . c om*/ * * @param project The maven project the Mojo is running for * @param artifacts the project artifacts (all scopes) * @param scope artifact scope to use * @param isGenerator whether to use processed resources and compiled classes (false), or raw resources (true). * @return file collection for classpath */ public Collection<File> buildClasspathList(final MavenProject project, final String scope, Set<Artifact> artifacts, boolean isGenerator) throws ClasspathBuilderException { getLogger().debug("establishing classpath list (scope = " + scope + ")"); Set<File> items = new LinkedHashSet<File>(); // Note : Don't call addSourceWithActiveProject as a GWT dependency MUST be a valid GWT library module : // * include java sources in the JAR as resources // * define a gwt.xml module file to declare the required inherits // addSourceWithActiveProject would make some java sources available to GWT compiler that should not be accessible in // a non-reactor build, making the build less deterministic and encouraging bad design. if (!isGenerator) { items.add(new File(project.getBuild().getOutputDirectory())); } addSources(items, project.getCompileSourceRoots()); if (isGenerator) { addResources(items, project.getResources()); } // Use our own ClasspathElements fitering, as for RUNTIME we need to include PROVIDED artifacts, // that is not the default Maven policy, as RUNTIME is used here to build the GWTShell execution classpath if (scope.equals(SCOPE_TEST)) { addSources(items, project.getTestCompileSourceRoots()); addResources(items, project.getTestResources()); items.add(new File(project.getBuild().getTestOutputDirectory())); // Add all project dependencies in classpath for (Artifact artifact : artifacts) { items.add(artifact.getFile()); } } else if (scope.equals(SCOPE_COMPILE)) { // Add all project dependencies in classpath getLogger().debug("candidate artifacts : " + artifacts.size()); for (Artifact artifact : artifacts) { String artifactScope = artifact.getScope(); if (SCOPE_COMPILE.equals(artifactScope) || SCOPE_PROVIDED.equals(artifactScope) || SCOPE_SYSTEM.equals(artifactScope)) { items.add(artifact.getFile()); } } } else if (scope.equals(SCOPE_RUNTIME)) { // Add all dependencies BUT "TEST" as we need PROVIDED ones to setup the execution // GWTShell that is NOT a full JEE server for (Artifact artifact : artifacts) { getLogger().debug("candidate artifact : " + artifact); if (!artifact.getScope().equals(SCOPE_TEST) && artifact.getArtifactHandler().isAddedToClasspath()) { items.add(artifact.getFile()); } } } else { throw new ClasspathBuilderException("unsupported scope " + scope); } return items; }