List of usage examples for org.apache.maven.project MavenProject getTestCompileSourceRoots
public List<String> getTestCompileSourceRoots()
From source file:org.codehaus.mojo.gwt.shell.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 . ja va2 s .c o m * * @param project The maven project the Mojo is running for * @param scope * @param runtime * @param artifacts the project artifacts (all scopes) * @return file collection for classpath * @throws DependencyResolutionRequiredException */ @SuppressWarnings("unchecked") public Collection<File> buildClasspathList(final MavenProject project, final String scope, GwtRuntime runtime, Set<Artifact> artifacts) throws MojoExecutionException { getLogger().info("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. addSources(items, project.getCompileSourceRoots()); addResources(items, project.getResources()); items.add(new File(project.getBuild().getOutputDirectory())); // 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 IllegalArgumentException("unsupported scope " + scope); } if (runtime != null) { items.add(runtime.getGwtDevJar()); } getLogger().debug("GWT SDK execution classpath :"); for (File f : items) { getLogger().debug(" " + f.getAbsolutePath()); } return items; }
From source file:org.codehaus.mojo.gwt.shell.ClasspathBuilder.java
License:Apache License
/** * Get source roots for specific scope./* ww w . j av a 2 s. c o m*/ * * @param project * @param scope * @return */ @SuppressWarnings("unchecked") 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); } }
From source file:org.codehaus.mojo.taglist.TagListReport.java
License:Apache License
/** * Construct the list of source directories to analyze. * /*from w ww . j a v a 2 s . co m*/ * @return the list of dirs. */ public List constructSourceDirs() { List dirs = new ArrayList(project.getCompileSourceRoots()); if (!skipTestSources) { dirs.addAll(project.getTestCompileSourceRoots()); } if (aggregate) { for (Iterator i = reactorProjects.iterator(); i.hasNext();) { MavenProject reactorProject = (MavenProject) i.next(); if ("java".equals(reactorProject.getArtifact().getArtifactHandler().getLanguage())) { dirs.addAll(reactorProject.getCompileSourceRoots()); if (!skipTestSources) { dirs.addAll(reactorProject.getTestCompileSourceRoots()); } } } } dirs = pruneSourceDirs(dirs); return dirs; }
From source file:org.cruxframework.crux.plugin.maven.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). * * @param project The maven project the Mojo is running for * @param artifacts the project artifacts (all scopes) * @param scope artifact scope to use/*w w w . j a v a 2 s . c o m*/ * @param isGenerator whether to use processed resources and compiled classes (false), or raw resources (true). * @return file collection for classpath * @throws MojoExecutionException */ public Collection<File> buildClasspathList(final MavenProject project, final String scope, Set<Artifact> artifacts, boolean isGenerator, boolean addSources) 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())); } if (addSources) { 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.eclipse.che.maven.server.MavenModelUtil.java
License:Open Source License
public static MavenModel convertProjectToModel(MavenProject project, List<DependencyNode> dependencyNodes, File localRepository) {/*from w w w .j ava 2s. c om*/ Model model = project.getModel(); return convertModel(model, project.getCompileSourceRoots(), project.getTestCompileSourceRoots(), project.getArtifacts(), project.getExtensionArtifacts(), localRepository); }
From source file:org.eclipse.m2e.core.internal.embedder.MavenProjectMutableState.java
License:Open Source License
public static MavenProjectMutableState takeSnapshot(MavenProject project) { MavenProjectMutableState snapshot = new MavenProjectMutableState(); if (project.getContextValue(CTX_SNAPSHOT) == null) { snapshot.compileSourceRoots = new ArrayList<String>(project.getCompileSourceRoots()); snapshot.testCompileSourceRoots = new ArrayList<String>(project.getTestCompileSourceRoots()); snapshot.resources = new ArrayList<Resource>(project.getResources()); snapshot.testResources = new ArrayList<Resource>(project.getTestResources()); snapshot.properties = new Properties(); snapshot.properties.putAll(project.getProperties()); project.setContextValue(CTX_SNAPSHOT, Boolean.TRUE); snapshot.nested = false;/*from w ww.ja va2s.c o m*/ } return snapshot; }
From source file:org.eclipse.m2e.core.internal.embedder.MavenProjectMutableState.java
License:Open Source License
public void restore(MavenProject project) { if (nested) { return;/*from w w w .j a v a2 s. co m*/ } setElements(project.getCompileSourceRoots(), compileSourceRoots); setElements(project.getTestCompileSourceRoots(), testCompileSourceRoots); setElements(project.getResources(), resources); setElements(project.getTestResources(), testResources); if (properties != null) { project.getProperties().clear(); project.getProperties().putAll(properties); } project.setContextValue(CTX_SNAPSHOT, null); }
From source file:org.eclipse.m2e.core.internal.project.registry.MavenProjectFacade.java
License:Open Source License
public MavenProjectFacade(ProjectRegistryManager manager, IFile pom, MavenProject mavenProject, Map<String, List<MojoExecution>> executionPlans, ResolverConfiguration resolverConfiguration) { this.manager = manager; this.pom = pom; IPath location = pom.getLocation();/*from www .j a va 2 s.c o m*/ this.pomFile = location == null ? null : location.toFile(); // save pom file this.resolverConfiguration = resolverConfiguration; this.mavenProject = mavenProject; this.executionPlans = executionPlans; this.artifactKey = new ArtifactKey(mavenProject.getArtifact()); this.packaging = mavenProject.getPackaging(); this.modules = mavenProject.getModules(); this.resourceLocations = MavenProjectUtils.getResourceLocations(getProject(), mavenProject.getResources()); this.testResourceLocations = MavenProjectUtils.getResourceLocations(getProject(), mavenProject.getTestResources()); this.compileSourceLocations = MavenProjectUtils.getSourceLocations(getProject(), mavenProject.getCompileSourceRoots()); this.testCompileSourceLocations = MavenProjectUtils.getSourceLocations(getProject(), mavenProject.getTestCompileSourceRoots()); IPath fullPath = getProject().getFullPath(); IPath path = getProjectRelativePath(mavenProject.getBuild().getOutputDirectory()); this.outputLocation = (path != null) ? fullPath.append(path) : null; path = getProjectRelativePath(mavenProject.getBuild().getTestOutputDirectory()); this.testOutputLocation = path != null ? fullPath.append(path) : null; this.artifactRepositories = new LinkedHashSet<ArtifactRepositoryRef>(); for (ArtifactRepository repository : mavenProject.getRemoteArtifactRepositories()) { this.artifactRepositories.add(new ArtifactRepositoryRef(repository)); } this.pluginArtifactRepositories = new LinkedHashSet<ArtifactRepositoryRef>(); for (ArtifactRepository repository : mavenProject.getPluginArtifactRepositories()) { this.pluginArtifactRepositories.add(new ArtifactRepositoryRef(repository)); } setMavenProjectArtifacts(); updateTimestamp(); }
From source file:org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.java
License:Open Source License
protected void addProjectSourceFolders(IClasspathDescriptor classpath, ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { SubMonitor mon = SubMonitor.convert(monitor, 6); try {/* w w w . j a v a 2s . co m*/ IProject project = request.getProject(); MavenProject mavenProject = request.getMavenProject(); IMavenProjectFacade projectFacade = request.getMavenProjectFacade(); IFolder classes = getFolder(project, mavenProject.getBuild().getOutputDirectory()); IFolder testClasses = getFolder(project, mavenProject.getBuild().getTestOutputDirectory()); M2EUtils.createFolder(classes, true, mon.newChild(1)); M2EUtils.createFolder(testClasses, true, mon.newChild(1)); IPath[] inclusion = new IPath[0]; IPath[] exclusion = new IPath[0]; IPath[] inclusionTest = new IPath[0]; IPath[] exclusionTest = new IPath[0]; String mainSourceEncoding = null; String testSourceEncoding = null; String mainResourcesEncoding = null; String testResourcesEncoding = null; List<MojoExecution> executions = getCompilerMojoExecutions(request, mon.newChild(1)); for (MojoExecution compile : executions) { if (isCompileExecution(compile)) { mainSourceEncoding = maven.getMojoParameterValue(mavenProject, compile, "encoding", //$NON-NLS-1$ String.class, monitor); try { inclusion = toPaths(maven.getMojoParameterValue(mavenProject, compile, "includes", //$NON-NLS-1$ String[].class, monitor)); } catch (CoreException ex) { log.error("Failed to determine compiler inclusions, assuming defaults", ex); } try { exclusion = toPaths(maven.getMojoParameterValue(mavenProject, compile, "excludes", //$NON-NLS-1$ String[].class, monitor)); } catch (CoreException ex) { log.error("Failed to determine compiler exclusions, assuming defaults", ex); } } } for (MojoExecution compile : executions) { if (isTestCompileExecution(compile)) { testSourceEncoding = maven.getMojoParameterValue(mavenProject, compile, "encoding", //$NON-NLS-1$ String.class, monitor); try { inclusionTest = toPaths(maven.getMojoParameterValue(mavenProject, compile, "testIncludes", //$NON-NLS-1$ String[].class, monitor)); } catch (CoreException ex) { log.error("Failed to determine compiler test inclusions, assuming defaults", ex); } try { exclusionTest = toPaths(maven.getMojoParameterValue(mavenProject, compile, "testExcludes", //$NON-NLS-1$ String[].class, monitor)); } catch (CoreException ex) { log.error("Failed to determine compiler test exclusions, assuming defaults", ex); } } } for (MojoExecution resources : projectFacade.getMojoExecutions(RESOURCES_PLUGIN_GROUP_ID, RESOURCES_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_RESOURCES)) { mainResourcesEncoding = maven.getMojoParameterValue(mavenProject, resources, "encoding", //$NON-NLS-1$ String.class, monitor); } for (MojoExecution resources : projectFacade.getMojoExecutions(RESOURCES_PLUGIN_GROUP_ID, RESOURCES_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_TESTRESOURCES)) { testResourcesEncoding = maven.getMojoParameterValue(mavenProject, resources, "encoding", //$NON-NLS-1$ String.class, monitor); } addSourceDirs(classpath, project, mavenProject.getCompileSourceRoots(), classes.getFullPath(), inclusion, exclusion, mainSourceEncoding, mon.newChild(1)); addResourceDirs(classpath, project, mavenProject.getBuild().getResources(), classes.getFullPath(), mainResourcesEncoding, mon.newChild(1)); addSourceDirs(classpath, project, mavenProject.getTestCompileSourceRoots(), testClasses.getFullPath(), inclusionTest, exclusionTest, testSourceEncoding, mon.newChild(1)); addResourceDirs(classpath, project, mavenProject.getBuild().getTestResources(), testClasses.getFullPath(), testResourcesEncoding, mon.newChild(1)); } finally { mon.done(); } }
From source file:org.eclipse.m2e.wtp.WTPProjectsUtil.java
License:Open Source License
public static void removeTestFolderLinks(IProject project, MavenProject mavenProject, IProgressMonitor monitor, String folder) throws CoreException { IVirtualComponent component = ComponentCore.createComponent(project); if (component == null) { return;//from ww w. j a v a2s .co m } IVirtualFolder jsrc = component.getRootFolder().getFolder(folder); for (IPath location : MavenProjectUtils.getSourceLocations(project, mavenProject.getTestCompileSourceRoots())) { if (location == null) continue; jsrc.removeLink(location, 0, monitor); } for (IPath location : MavenProjectUtils.getResourceLocations(project, mavenProject.getTestResources())) { if (location == null) continue; jsrc.removeLink(location, 0, monitor); } //MECLIPSEWTP-217 : exclude other test source folders, added by build-helper for instance if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); if (javaProject == null) { return; } IPath testOutputDirPath = MavenProjectUtils.getProjectRelativePath(project, mavenProject.getBuild().getTestOutputDirectory()); if (testOutputDirPath == null) { return; } IPath testPath = project.getFullPath().append(testOutputDirPath); IClasspathEntry[] cpes = javaProject.getRawClasspath(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IClasspathEntry cpe : cpes) { if (cpe != null && cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath outputLocation = cpe.getOutputLocation(); if (testPath.equals(outputLocation)) { IPath sourcePath = root.getFolder(cpe.getPath()).getProjectRelativePath(); if (sourcePath != null) { jsrc.removeLink(sourcePath, 0, monitor); } } } } } }