List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:org.wso2.maven.MavenReleasePrePrepareMojo.java
License:Open Source License
/** * check the project nature/*from w w w . ja v a2 s.c om*/ * * @param pomFile * pom file of the project * @param nature * project nature * @return */ private boolean hasNature(final File pomFile, final String nature) { Model model = null; FileReader reader = null; MavenXpp3Reader mavenreader = new MavenXpp3Reader(); try { reader = new FileReader(pomFile); model = mavenreader.read(reader); MavenProject project = new MavenProject(model); @SuppressWarnings("unchecked") List<Plugin> plugins = project.getBuild().getPlugins(); for (Plugin plugin : plugins) { if (plugin.getArtifactId().equals(MAVEN_ECLIPSE_PLUGIN)) { Xpp3Dom configurationNode = (Xpp3Dom) plugin.getConfiguration(); Xpp3Dom projectnatures = configurationNode.getChild(PROJECT_NATURES); Xpp3Dom[] natures = projectnatures.getChildren(); for (Xpp3Dom xpp3Dom : natures) { if (nature.equals(xpp3Dom.getValue())) { return true; } } break; } } } catch (FileNotFoundException e) { log.error("Cannot find the pom file", e); } catch (IOException e) { log.error("Error occurred while reading the pom file", e); } catch (XmlPullParserException e) { log.error("Error occurred while parse the pom file", e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { log.error("Error occurred while closing input stream", e); } } } return false; }
From source file:se.jguru.nazgul.tools.plugin.checkstyle.exec.DefaultCheckstyleExecutor.java
License:Apache License
private void prepareCheckstylePaths(CheckstyleExecutorRequest request, MavenProject project, List<String> classPathStrings, List<String> outputDirectories, Collection<File> sourceDirectories, Collection<File> testSourceDirectories) throws CheckstyleExecutorException { try {//from w w w . j ava2 s .c o m outputDirectories.add(project.getBuild().getOutputDirectory()); if (request.isIncludeTestSourceDirectory() && (testSourceDirectories != null) && anyDirectoryExists(testSourceDirectories)) { classPathStrings.addAll(project.getTestClasspathElements()); outputDirectories.add(project.getBuild().getTestOutputDirectory()); } else { classPathStrings.addAll(project.getCompileClasspathElements()); } } catch (DependencyResolutionRequiredException e) { throw new CheckstyleExecutorException(e.getMessage(), e); } }
From source file:se.jguru.nazgul.tools.plugin.checkstyle.exec.DefaultCheckstyleExecutor.java
License:Apache License
/** * Configures search paths in the resource locator. * This method should only be called once per execution. * * @param request executor request data. *//*from ww w. j ava 2s.com*/ private void configureResourceLocator(final ResourceManager resourceManager, final CheckstyleExecutorRequest request, final List<Artifact> additionalArtifacts) { final MavenProject project = request.getProject(); resourceManager.setOutputDirectory(new File(project.getBuild().getDirectory())); // Recurse up the parent hierarchy and add project directories to the search roots MavenProject parent = project; while (parent != null && parent.getFile() != null) { // MCHECKSTYLE-131 ( olamy ) I don't like this hack. // (dkulp) Me either. It really pollutes the location stuff // by allowing searches of stuff outside the current module. File dir = parent.getFile().getParentFile(); resourceManager.addSearchPath(FileResourceLoader.ID, dir.getAbsolutePath()); parent = parent.getParent(); } resourceManager.addSearchPath("url", ""); // MCHECKSTYLE-225: load licenses from additional artifacts, not from classpath if (additionalArtifacts != null) { for (Artifact licenseArtifact : additionalArtifacts) { try { // MCHECKSTYLE-287, MCHECKSTYLE-294: Ignore null licenseArtifacts ... if (licenseArtifact != null) { if (getLogger().isDebugEnabled()) { getLogger().debug("Adding licenceArtifact [" + licenseArtifact.getGroupId() + ":" + licenseArtifact.getArtifactId() + ":" + licenseArtifact.getVersion() + "] to resourceManager."); } resourceManager.addSearchPath("jar", "jar:" + licenseArtifact.getFile().toURI().toURL()); } } catch (MalformedURLException e) { // noop } } } }