Example usage for org.apache.maven.project MavenProject getCompileSourceRoots

List of usage examples for org.apache.maven.project MavenProject getCompileSourceRoots

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getCompileSourceRoots.

Prototype

public List<String> getCompileSourceRoots() 

Source Link

Usage

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  ww  .j  av  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 a2s  .  co m*/
 *
 * @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);
    }
}

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  ww w . ja  v  a 2 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.//from  ww w  .j a  v  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  ava  2 s.c  om
 * @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 av a  2s.co 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.ebayopensource.turmeric.plugins.maven.util.ProjectClassLoader.java

License:Open Source License

private static URL[] getMavenProjectClassLoaderURLS(MavenProject project) throws MalformedURLException {
    List<File> searchPaths = new ArrayList<File>();

    // Project Compile Artifacts
    @SuppressWarnings("unchecked")
    final List<Artifact> arts = project.getCompileArtifacts();
    if (arts != null) {
        for (Artifact arti : arts) {
            File artiFile = arti.getFile();
            if ((artiFile != null) && (artiFile.exists())) {
                searchPaths.add(artiFile);
            }/*ww  w. j  a  v  a2  s .c  o  m*/
        }
    }

    // Project Resources
    @SuppressWarnings("unchecked")
    final List<Resource> resources = project.getBuild().getResources();

    for (Resource resource : resources) {
        String resDir = resource.getDirectory();
        File dir = new File(resDir);
        if (!dir.isAbsolute()) {
            dir = new File(project.getBasedir(), resDir);
        }
        searchPaths.add(dir);
    }

    // The Classes Dir
    File classesDir = new File(project.getBuild().getOutputDirectory());
    if (!classesDir.isAbsolute()) {
        classesDir = new File(project.getBasedir(), project.getBuild().getOutputDirectory());
    }

    searchPaths.add(classesDir);

    // Compile Source Roots - (needed for codegen javac)
    @SuppressWarnings("unchecked")
    List<String> sourceRoots = project.getCompileSourceRoots();
    if (sourceRoots != null) {
        for (String srcRoot : sourceRoots) {
            if (StringUtils.isBlank(srcRoot)) {
                // skip
                continue;
            }
            File src = new File(srcRoot);
            if (src.exists()) {
                searchPaths.add(new File(srcRoot));
            }
        }
    }

    int count = searchPaths.size();
    URL urls[] = new URL[count];
    for (int i = 0; i < count; i++) {
        urls[i] = searchPaths.get(i).toURI().toURL();
        System.out.printf("### ProjectClassLoader[%d]: %s%n", i, urls[i].toExternalForm());
    }

    return urls;
}

From source file:org.ebayopensource.turmeric.plugins.stubs.ProjectClassLoader.java

License:Open Source License

private static URL[] getMavenProjectClassLoaderURLS(MavenProject project) throws MalformedURLException {
    List<File> searchPaths = new ArrayList<File>();

    // Project Compile Artifacts
    @SuppressWarnings("unchecked")
    final List<Artifact> arts = project.getCompileArtifacts();
    if (arts != null) {
        for (Artifact arti : arts) {
            File artiFile = arti.getFile();
            if ((artiFile != null) && (artiFile.exists())) {
                searchPaths.add(artiFile);
            }//www .j  a  v  a2  s.  com
        }
    }

    // Project Resources
    final List<Resource> resources = project.getBuild().getResources();

    for (Resource resource : resources) {
        String resDir = resource.getDirectory();
        File dir = new File(resDir);
        if (!dir.isAbsolute()) {
            dir = new File(project.getBasedir(), resDir);
        }
        searchPaths.add(dir);
    }

    // The Classes Dir
    File classesDir = new File(project.getBuild().getOutputDirectory());
    if (!classesDir.isAbsolute()) {
        classesDir = new File(project.getBasedir(), project.getBuild().getOutputDirectory());
    }

    searchPaths.add(classesDir);

    // Compile Source Roots - (needed for codegen javac)
    @SuppressWarnings("unchecked")
    List<String> sourceRoots = project.getCompileSourceRoots();
    if (sourceRoots != null) {
        for (String srcRoot : sourceRoots) {
            if (StringUtils.isBlank(srcRoot)) {
                // skip
                continue;
            }
            File src = new File(srcRoot);
            if (src.exists()) {
                searchPaths.add(new File(srcRoot));
            }
        }
    }

    int count = searchPaths.size();
    URL urls[] = new URL[count];
    for (int i = 0; i < count; i++) {
        urls[i] = searchPaths.get(i).toURI().toURL();
        System.out.printf("### ProjectClassLoader[%d]: %s%n", i, urls[i].toExternalForm());
    }

    return urls;
}

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 ww w.  j a v  a2s.  c o m
    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 w w.  j a  v a2 s  .com
    }

    return snapshot;
}