List of usage examples for org.apache.maven.project MavenProject getCompileSourceRoots
public List<String> getCompileSourceRoots()
From source file:com.totsp.mavenplugin.gwt.util.BuildClasspathUtil.java
License:Open Source License
/** * Get source roots for specific scope.// w ww . jav a2 s .c om * * @param project * @param scope * @return */ private static List<String> getSourceRoots(final MavenProject project, final DependencyScope scope) { if (DependencyScope.COMPILE.equals(scope)) { return project.getCompileSourceRoots(); } else if (DependencyScope.TEST.equals(scope)) { return project.getTestCompileSourceRoots(); } else { throw new RuntimeException("Not allowed scope " + scope); } }
From source file:io.cloudslang.lang.enforcer.SpringCleansingRule.java
License:Open Source License
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { Log log = helper.getLog();//from w w w. j a v a2 s .c o m try { // get the various expressions out of the helper. MavenProject project = (MavenProject) helper.evaluate("${project}"); // MavenSession session = (MavenSession) helper.evaluate("${session}"); // String target = (String) helper.evaluate("${project.build.directory}"); // String artifactId = (String) helper.evaluate("${project.artifactId}"); // ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class); // RuntimeInfo rti = (RuntimeInfo) helper.getComponent(RuntimeInfo.class); List compileSourceRoots = project.getCompileSourceRoots(); for (Object compileSourceRoot : compileSourceRoots) { String path = (String) compileSourceRoot; applyForJavaSourcesInRoot(path, log); } } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } }
From source file:io.sarl.maven.compiler.CompileMojo.java
License:Apache License
private void compileSARL() throws MojoExecutionException, MojoFailureException { final Log log = getLog(); File outputDirectory = getOutput(); log.info(Locale.getString(CompileMojo.class, "COMPILING_SARL")); //$NON-NLS-1$ if (log.isDebugEnabled()) { final StringBuilder properties = new StringBuilder(); buildPropertyString(properties); log.debug(properties.toString()); }//w ww . ja v a 2 s.c om // If output is not explicitly set try to read SARL prefs from eclipse .settings folder if (getDefaultOutput().equals(getOutput())) { final String settingsValue = readSarlEclipseSetting(getProject().getBuild().getSourceDirectory()); if (settingsValue != null && !settingsValue.isEmpty()) { outputDirectory = new File(settingsValue); getLog().info(Locale.getString(CompileMojo.class, "OUTPUT_DIR_UPDATE", outputDirectory)); //$NON-NLS-1$ } } final MavenProject project = getProject(); final List<File> compileSourceRoots = new ArrayList<>(); for (final String filename : project.getCompileSourceRoots()) { final File file = new File(filename); if (!file.equals(outputDirectory)) { compileSourceRoots.add(file); } } final List<File> classPath = getClassPath(); project.addCompileSourceRoot(outputDirectory.getAbsolutePath()); compile(classPath, compileSourceRoots, outputDirectory); }
From source file:io.treefarm.plugins.haxe.components.HaxeCompiler.java
License:Apache License
public void compile(MavenProject project, Map<CompileTarget, String> targets, String main, boolean debug, boolean includeTestSources, boolean verbose, List<String> additionalArguments) throws Exception { List<String> args = new ArrayList<String>(); for (String sourceRoot : project.getCompileSourceRoots()) { addSourcePath(args, sourceRoot); }/*ww w . ja v a 2 s . c o m*/ if (includeTestSources) { for (String sourceRoot : project.getTestCompileSourceRoots()) { addSourcePath(args, sourceRoot); } } addLibs(args, project); addHars(args, project, targets.keySet()); addMain(args, main); addDebug(args, debug); if (additionalArguments != null) args.addAll(additionalArguments); for (CompileTarget target : targets.keySet()) { String output = targets.get(target); List<String> argsClone = new ArrayList<String>(); argsClone.addAll(args); addTarget(argsClone, target); argsClone.add(output); haxe.execute(argsClone); } }
From source file:net.wasdev.wlp.maven.plugins.applications.InstallAppMojoSupport.java
License:Open Source License
private boolean containsJavaSource(MavenProject proj) { @SuppressWarnings("unchecked") List<String> srcDirs = proj.getCompileSourceRoots(); for (String dir : srcDirs) { File javaSourceDir = new File(dir); if (javaSourceDir.exists() && javaSourceDir.isDirectory() && containsJavaSource(javaSourceDir)) { return true; }// w w w.j av a2 s.c o m } return false; }
From source file:org.apache.felix.bundleplugin.BundlePlugin.java
License:Apache License
protected Builder buildOSGiBundle(MavenProject currentProject, Map originalInstructions, Properties properties, Jar[] classpath) throws Exception { properties.putAll(getDefaultProperties(currentProject)); properties.putAll(transformDirectives(originalInstructions)); Builder builder = new Builder(); builder.setBase(currentProject.getBasedir()); builder.setProperties(properties);/* w ww.j a v a 2 s.c o m*/ builder.setClasspath(classpath); // update BND instructions to add included Maven resources includeMavenResources(currentProject, builder, getLog()); // calculate default export/private settings based on sources if (builder.getProperty(Analyzer.PRIVATE_PACKAGE) == null || builder.getProperty(Analyzer.EXPORT_PACKAGE) == null) { addLocalPackages(currentProject.getCompileSourceRoots(), builder); } // update BND instructions to embed selected Maven dependencies Collection embeddableArtifacts = getEmbeddableArtifacts(currentProject, builder); new DependencyEmbedder(getLog(), embeddableArtifacts).processHeaders(builder); dumpInstructions("BND Instructions:", builder.getProperties(), getLog()); dumpClasspath("BND Classpath:", builder.getClasspath(), getLog()); builder.build(); Jar jar = builder.getJar(); dumpManifest("BND Manifest:", jar.getManifest(), getLog()); String[] removeHeaders = builder.getProperty(Analyzer.REMOVE_HEADERS, "").split(","); mergeMavenManifest(currentProject, jar, removeHeaders, getLog()); builder.setJar(jar); dumpManifest("Final Manifest:", jar.getManifest(), getLog()); return builder; }
From source file:org.apache.james.mailet.DefaultDescriptorsExtractor.java
License:Apache License
@SuppressWarnings("unchecked") private JavaClass[] javaClasses(MavenProject project) { JavaDocBuilder builder = new JavaDocBuilder(); for (String s : (Iterable<String>) project.getCompileSourceRoots()) { builder.addSourceTree(new File(s)); }//from w w w .j a v a 2 s . c om return builder.getClasses(); }
From source file:org.apache.myfaces.trinidadbuild.plugin.jdeveloper.JDeveloperMojo.java
License:Apache License
private void generateProject() throws IOException, MojoExecutionException { if (!"pom".equals(project.getPackaging())) { File projectFile = getJProjectFile(project); // Get Project Properties to tell Mojo whether or not to add // library refs and taglibs to the project. Properties props = project.getProperties(); String addLibs = (String) props.get(_PROPERTY_ADD_LIBRARY); String addTagLibs = (String) props.get(_PROPERTY_ADD_TAGLIBS); final boolean webProject = this.isWebProject(); _addLibraries = (addLibs == null) ? true : (new Boolean(addLibs)).booleanValue(); _addLibraries = _addLibraries & webProject; _addTagLibs = (addTagLibs == null) ? true : (new Boolean(addTagLibs)).booleanValue(); _addTagLibs = _addTagLibs && webProject; // TODO: read configuration for war:war goal File webappDir = new File(project.getBasedir(), "src/main/webapp"); // TODO: read configuration for compiler:complie goal File outputDir = new File(project.getBuild().getDirectory(), "classes"); MavenProject executionProject = project.getExecutionProject(); List compileSourceRoots = executionProject.getCompileSourceRoots(); if (sourceRoots != null) { for (int i = 0; i < sourceRoots.length; i++) { compileSourceRoots.add(sourceRoots[i].getAbsolutePath()); }//from ww w.j a v a 2 s . c o m } List compileResourceRoots = executionProject.getResources(); if (resourceRoots != null) { for (int i = 0; i < resourceRoots.length; i++) { Resource resource = new Resource(); resource.setDirectory(resourceRoots[i].getAbsolutePath()); compileResourceRoots.add(resource); } } getLog().info("Generating JDeveloper " + release + " Project " + project.getArtifactId()); Set pluginArtifacts = new LinkedHashSet(); pluginArtifacts.addAll(project.getPluginArtifacts()); // Note: include "compile", "provided", "system" and "runtime" // scopes Set compileArtifacts = new LinkedHashSet(); compileArtifacts.addAll(project.getCompileArtifacts()); compileArtifacts.addAll(project.getRuntimeArtifacts()); // Note: separate "runtime" vs. "compile" dependencies in // JDeveloper? generateProject(projectFile, project.getArtifactId(), project.getPackaging(), project.getDependencies(), new ArrayList(compileArtifacts), compileSourceRoots, compileResourceRoots, Collections.singletonList(webappDir.getPath()), outputDir); } }
From source file:org.apache.tuscany.maven.plugin.eclipse.EclipsePlugin.java
License:Apache License
public final EclipseSourceDir[] buildDirectoryList(MavenProject project, File basedir, File buildOutputDirectory) throws MojoExecutionException { File projectBaseDir = project.getFile().getParentFile(); String mainOutput = IdeUtils.toRelativeAndFixSeparator(projectBaseDir, buildOutputDirectory, false); // If using the standard output location, don't mix the test output into it. String testOutput = null;/*from w w w .j a va 2 s . c o m*/ boolean useStandardOutputDir = buildOutputDirectory .equals(new File(project.getBuild().getOutputDirectory())); if (useStandardOutputDir) { getLog().debug("testOutput toRelativeAndFixSeparator " + projectBaseDir + " , " + project.getBuild().getTestOutputDirectory()); testOutput = IdeUtils.toRelativeAndFixSeparator(projectBaseDir, new File(project.getBuild().getTestOutputDirectory()), false); getLog().debug("testOutput after toRelative : " + testOutput); } Set mainDirectories = new LinkedHashSet(); extractSourceDirs(mainDirectories, project.getCompileSourceRoots(), basedir, projectBaseDir, false, null); extractResourceDirs(mainDirectories, project.getBuild().getResources(), basedir, projectBaseDir, false, mainOutput); Set testDirectories = new LinkedHashSet(); extractSourceDirs(testDirectories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true, testOutput); extractResourceDirs(testDirectories, project.getBuild().getTestResources(), basedir, projectBaseDir, true, testOutput); // avoid duplicated entries Set directories = new LinkedHashSet(); // NOTE: Since MNG-3118, test classes come before main classes boolean testBeforeMain = isMavenVersion("[2.0.8,)"); if (testBeforeMain) { directories.addAll(testDirectories); directories.removeAll(mainDirectories); directories.addAll(mainDirectories); } else { directories.addAll(mainDirectories); directories.addAll(testDirectories); } if (ajdt) extractAspectDirs(directories, project, basedir, projectBaseDir, testOutput); return (EclipseSourceDir[]) directories.toArray(new EclipseSourceDir[directories.size()]); }
From source file:org.codehaus.mojo.cobertura.CoberturaReportMojo.java
License:Apache License
/** * Generates an aggregate cobertura report for the given project. *///from w w w . j av a 2s . c o m private void executeAggregateReport(Locale locale, MavenProject curProject) throws MavenReportException { List<MavenProject> children = getAllChildren(curProject); if (children.isEmpty()) { return; } List<File> serFiles = getOutputFiles(children); if (serFiles.isEmpty()) { getLog().info("Not executing aggregate cobertura:report for " + curProject.getName() + " as no child cobertura data files could not be found"); return; } getLog().info("Executing aggregate cobertura:report for " + curProject.getName()); ProjectData aggProjectData = new ProjectData(); for (File serFile : serFiles) { ProjectData data = CoverageDataFileHandler.loadCoverageData(serFile); aggProjectData.merge(data); } File aggSerFile = new File(curProject.getBasedir(), relDataFileName); aggSerFile.getAbsoluteFile().getParentFile().mkdirs(); getLog().info("Saving aggregate cobertura information in " + aggSerFile.getAbsolutePath()); CoverageDataFileHandler.saveCoverageData(aggProjectData, aggSerFile); // get all compile source roots List<String> aggCompileSourceRoots = new ArrayList<String>(); for (MavenProject child : children) { aggCompileSourceRoots.addAll(child.getCompileSourceRoots()); } File reportDir = new File(curProject.getBasedir(), relAggregateOutputDir); reportDir.mkdirs(); executeReport(aggSerFile, reportDir, aggCompileSourceRoots); }