List of usage examples for org.apache.maven.project MavenProject getTestCompileSourceRoots
public List<String> getTestCompileSourceRoots()
From source file:br.com.anteros.restdoc.maven.plugin.util.ResourceResolver.java
License:Apache License
@SuppressWarnings("unchecked") private static List<String> resolveFromProject(final SourceResolverConfig config, final MavenProject reactorProject, final Artifact artifact) { final List<String> dirs = new ArrayList<String>(); if (config.filter() == null || config.filter().include(artifact)) { if (config.includeCompileSources()) { final List<String> srcRoots = reactorProject.getCompileSourceRoots(); for (final String root : srcRoots) { dirs.add(root);/*from w w w . jav a2 s. c o m*/ } } if (config.includeTestSources()) { final List<String> srcRoots = reactorProject.getTestCompileSourceRoots(); for (final String root : srcRoots) { dirs.add(root); } } } return JavadocUtil.pruneDirs(reactorProject, dirs); }
From source file:com.alibaba.citrus.maven.eclipse.base.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 ww w .j a v a2s .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,)"); // let users override this if needed, they need to simulate more than the test phase in eclipse if (testSourcesLast) { testBeforeMain = false; } 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:com.atlassian.maven.plugin.clover.CloverLogMojo.java
License:Apache License
/** * Configures test source roots for clover log task for a single maven project. * It takes original test directory and directories from maven compilation. * @param cloverLogTask//from ww w. ja v a2 s . co m * @param project */ private void setTestSourceRootsForProject(final CloverLogTask cloverLogTask, final MavenProject project) { // original src/test directory String originalSrcTestDir = CloverSetupMojo.getOriginalSrcTestDir(project.getId()); if (originalSrcTestDir != null) { addTestSrcDir(cloverLogTask, originalSrcTestDir); } // src/test directories from maven compilation final List<String> testSourceRoots = project.getTestCompileSourceRoots(); addTestSrcDirs(cloverLogTask, testSourceRoots.iterator()); }
From source file:com.tenderowls.opensource.haxemojos.components.HaxeCompiler.java
License:Apache License
public void compile(MavenProject project, Map<CompileTarget, String> targets, String main, boolean debug, boolean includeTestSources, ArtifactFilter artifactFilter, List<String> additionalArguments) throws Exception { List<String> args = new ArrayList<String>(); for (String sourceRoot : project.getCompileSourceRoots()) { addSourcePath(args, sourceRoot); }//from w w w . jav a2s . c o m if (includeTestSources) { for (String sourceRoot : project.getTestCompileSourceRoots()) { addSourcePath(args, sourceRoot); } } addLibs(args, project, artifactFilter); addHars(args, project, targets.keySet(), artifactFilter); addDebug(args, debug); if (main != null) addMain(args, main); 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); CompilerLogger compilerLogger = new CompilerLogger(logger); int returnCode = haxe.execute(argsClone, compilerLogger); if (compilerLogger.getErrors().size() > 0) { logger.info("-------------------------------------------------------------"); logger.error("COMPILATION ERROR :"); logger.info("-------------------------------------------------------------"); for (String error : compilerLogger.getErrors()) { logger.error(error); } throw new Exception("Compilation failure"); } else if (returnCode > 0) { throw new Exception("Compilation failure"); } } }
From source file:com.totsp.mavenplugin.gwt.util.BuildClasspathUtil.java
License:Open Source License
/** * Get source roots for specific scope.//from w w w .java2 s .co m * * @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.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); }//from w ww. j a va 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:org.apache.myfaces.trinidadbuild.plugin.jdeveloper.JDeveloperMojo.java
License:Apache License
private void generateTestProject() throws IOException, MojoExecutionException { if (!"pom".equals(project.getPackaging()) && projectHasTests) { File projectFile = getJProjectTestFile(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); _addLibraries = (addLibs == null) ? true : (new Boolean(addLibs)).booleanValue(); _addTagLibs = (addTagLibs == null) ? true : (new Boolean(addTagLibs)).booleanValue(); File webappDir = new File(project.getBasedir(), "src/test/webapp"); // TODO: read configuration for compiler:testCompile goal File outputDir = new File(project.getBuild().getDirectory(), "test-classes"); // self dependency needed for test project List testDependencies = new ArrayList(project.getTestDependencies()); Dependency selfDependency = new Dependency(); selfDependency.setArtifactId(project.getArtifactId()); selfDependency.setGroupId(project.getGroupId()); selfDependency.setType(project.getPackaging()); testDependencies.add(selfDependency); MavenProject executionProject = project.getExecutionProject(); List compileSourceRoots = executionProject.getTestCompileSourceRoots(); if (testResourceRoots != null) { for (int i = 0; i < testSourceRoots.length; i++) { compileSourceRoots.add(testSourceRoots[i].getAbsolutePath()); }/*from w w w .j av a 2 s .c o m*/ } List compileResourceRoots = executionProject.getTestResources(); if (testResourceRoots != null) { for (int i = 0; i < testResourceRoots.length; i++) { Resource resource = new Resource(); resource.setDirectory(testSourceRoots[i].getAbsolutePath()); compileResourceRoots.add(resource); } } getLog().info("Generating JDeveloper " + release + " Project " + project.getArtifactId() + "-test"); // Note: all artifacts implicitly included in "test" scope generateProject(projectFile, project.getArtifactId() + "-test", project.getPackaging(), testDependencies, project.getTestArtifacts(), 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 v a 2s . c om*/ 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.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. jav 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; }
From source file:org.codehaus.mojo.gwt.ClasspathBuilder.java
License:Apache License
/** * Get source roots for specific scope./* w w w. j a v a 2 s . c om*/ * * @param project * @param scope * @return */ private List<String> getSourceRoots(final MavenProject project, final String scope) { if (SCOPE_COMPILE.equals(scope) || SCOPE_RUNTIME.equals(scope)) { return project.getCompileSourceRoots(); } else if (SCOPE_TEST.equals(scope)) { List<String> sourceRoots = new ArrayList<String>(); sourceRoots.addAll(project.getTestCompileSourceRoots()); sourceRoots.addAll(project.getCompileSourceRoots()); return sourceRoots; } else { throw new RuntimeException("Not allowed scope " + scope); } }