List of usage examples for org.apache.maven.project MavenProject getResources
public List<Resource> getResources()
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 ww w . ja v a 2 s. c o m * * @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 resources for specific scope.//from w w w. j a v a 2s.c om * * @param project * @param scope * @return */ private List<Resource> getResources(final MavenProject project, final String scope) { if (SCOPE_COMPILE.equals(scope) || SCOPE_RUNTIME.equals(scope)) { return project.getResources(); } else if (SCOPE_TEST.equals(scope)) { List<Resource> resources = new ArrayList<Resource>(); resources.addAll(project.getTestResources()); resources.addAll(project.getResources()); return resources; } else { throw new RuntimeException("Not allowed scope " + scope); } }
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 ww.ja v a2s. 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 resources for specific scope.//from ww w . j av a2 s.c o m * * @param project * @param scope * @return */ @SuppressWarnings("unchecked") private List<Resource> getResources(final MavenProject project, final String scope) { if (SCOPE_COMPILE.equals(scope) || SCOPE_RUNTIME.equals(scope)) { return project.getResources(); } else if (SCOPE_TEST.equals(scope)) { List<Resource> resources = new ArrayList<Resource>(); resources.addAll(project.getTestResources()); resources.addAll(project.getResources()); return resources; } else { throw new RuntimeException("Not allowed scope " + scope); } }
From source file:org.codehaus.mojo.l10n.L10NStatusReport.java
License:Apache License
/** * Collects resource definitions from all projects in reactor. * * @return/*from w ww .j a v a2 s. c om*/ */ protected Map constructResourceDirs() { Map sourceDirs = new HashMap(); if (aggregate) { for (Iterator i = reactorProjects.iterator(); i.hasNext();) { MavenProject prj = (MavenProject) i.next(); if (prj.getResources() != null && !prj.getResources().isEmpty()) { sourceDirs.put(prj, new ArrayList(prj.getResources())); } } } else { if (resources != null && !resources.isEmpty()) { sourceDirs.put(project, new ArrayList(resources)); } } return sourceDirs; }
From source file:org.codehaus.mojo.license.MojoHelper.java
License:Open Source License
/** * Add the directory as a resource of the given project. * * @param dir the directory to add/* w w w . ja v a 2 s . c om*/ * @param project the project to update * @param includes the includes of the resource * @return {@code true} if the resources was added (not already existing) */ public static boolean addResourceDir(File dir, MavenProject project, String... includes) { List<?> resources = project.getResources(); return addResourceDir(dir, project, resources, includes); }
From source file:org.codehaus.mojo.xml.TransformMojo.java
License:Apache License
private void addToClasspath(File pOutputDir) { MavenProject project = getProject(); for (Iterator<Resource> iter = project.getResources().iterator(); iter.hasNext();) { Resource resource = iter.next(); if (resource.getDirectory().equals(pOutputDir)) { return; }// w w w . j a va 2 s .co m } Resource resource = new Resource(); resource.setDirectory(pOutputDir.getPath()); resource.setFiltering(false); project.addResource(resource); }
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//from w w w . j a v a2s.c om * @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.echocat.jomon.maven.OverwriteWithMavenResourcesClassLoader.java
License:Mozilla Public License
protected void enrichWithResources(@Nonnull Collection<File> what, @Nonnull MavenProject of) throws Exception { final List<Resource> resources = of.getResources(); if (resources != null) { for (final Resource resource : resources) { final String plainDirectory = resource.getDirectory(); if (plainDirectory != null) { final File directory = new File(plainDirectory).getCanonicalFile(); if (directory.isDirectory() && !what.contains(directory)) { what.add(directory); }//from w ww.ja v a 2 s . co m } } } }
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 w w . ja va 2 s .c o m } return snapshot; }