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.eclipse.m2e.core.internal.embedder.MavenProjectMutableState.java

License:Open Source License

public void restore(MavenProject project) {
    if (nested) {
        return;//  w ww  . ja  v a 2  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 va2  s . com*/
    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 va 2 s .  c o 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.AbstractProjectConfiguratorDelegate.java

License:Open Source License

protected void configureWtpUtil(IMavenProjectFacade facade, IProgressMonitor monitor) throws CoreException {
    // Adding utility facet on JEE projects is not allowed
    IProject project = facade.getProject();
    MavenProject mavenProject = facade.getMavenProject();
    if (!WTPProjectsUtil.isJavaProject(facade) || WTPProjectsUtil.isJavaEEProject(project)
            || WTPProjectsUtil.isQualifiedAsWebFragment(facade)) {
        return;/*from   w  w  w  .j  a  v a2  s.c  om*/
    }

    //MECLIPSEWTP-66 delete extra MANIFEST.MF
    IPath[] sourceRoots = MavenProjectUtils.getSourceLocations(project, mavenProject.getCompileSourceRoots());
    IPath[] resourceRoots = MavenProjectUtils.getResourceLocations(project, mavenProject.getResources());

    //MECLIPSEWTP-182 check if the Java Project configurator has been successfully run before doing anything : 
    if (!checkJavaConfiguration(project, sourceRoots, resourceRoots)) {
        LOG.warn("{} Utility Facet configuration is aborted as the Java Configuration is inconsistent",
                project.getName());
        return;
    }

    boolean isDebugEnabled = DebugUtilities.isDebugEnabled();
    if (isDebugEnabled) {
        DebugUtilities.debug(DebugUtilities.dumpProjectState("Before configuration ", project));
    }

    // 2 - check if the manifest already exists, and its parent folder

    IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
    Set<Action> actions = new LinkedHashSet<Action>();
    installJavaFacet(actions, project, facetedProject);

    if (!facetedProject.hasProjectFacet(WTPProjectsUtil.UTILITY_FACET)) {
        actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, WTPProjectsUtil.UTILITY_10,
                null));
    } else if (!facetedProject.hasProjectFacet(WTPProjectsUtil.UTILITY_10)) {
        actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE,
                WTPProjectsUtil.UTILITY_10, null));
    }

    if (!actions.isEmpty()) {
        ResourceCleaner fileCleaner = new ResourceCleaner(project);
        try {
            addFoldersToClean(fileCleaner, facade);
            facetedProject.modify(actions, monitor);
        } finally {
            //Remove any unwanted MANIFEST.MF the Facet installation has created
            fileCleaner.cleanUp();
        }
    }

    fixMissingModuleCoreNature(project, monitor);

    if (isDebugEnabled) {
        DebugUtilities.debug(DebugUtilities.dumpProjectState("after configuration ", project));
    }
    //MNGECLIPSE-904 remove tests folder links for utility jars
    removeTestFolderLinks(project, mavenProject, monitor, "/");

    //Remove "library unavailable at runtime" warning.
    if (isDebugEnabled) {
        DebugUtilities.debug(DebugUtilities.dumpProjectState("after removing test folders ", project));
    }

    setNonDependencyAttributeToContainer(project, monitor);

    WTPProjectsUtil.removeWTPClasspathContainer(project);
}

From source file:org.eclipse.m2e.wtp.ConnectorProjectConfiguratorDelegate.java

License:Open Source License

private void addSourceLinks(IVirtualComponent component, MavenProject mavenProject, IProgressMonitor monitor)
        throws CoreException {
    IProject project = component.getProject();
    IPath classesPath = MavenProjectUtils.getProjectRelativePath(project,
            mavenProject.getBuild().getOutputDirectory());
    if (classesPath != null) {
        for (IPath location : MavenProjectUtils.getSourceLocations(project,
                mavenProject.getCompileSourceRoots())) {
            addLinkIfNecessary(component, location, monitor);
        }// ww w  . java2 s. c  o  m
        for (IPath location : MavenProjectUtils.getResourceLocations(project, mavenProject.getResources())) {
            addLinkIfNecessary(component, location, monitor);
        }
    }
}

From source file:org.eclipse.m2e.wtp.ConnectorProjectConfiguratorDelegate.java

License:Open Source License

private void removeSourceLinks(IVirtualComponent component, MavenProject mavenProject, IProgressMonitor monitor)
        throws CoreException {
    IVirtualFolder jsrc = component.getRootFolder();
    IProject project = component.getProject();
    for (IPath location : MavenProjectUtils.getSourceLocations(project, mavenProject.getCompileSourceRoots())) {
        jsrc.removeLink(location, 0, monitor);
    }//from w ww .  ja  v a 2s  . c o m
    for (IPath location : MavenProjectUtils.getResourceLocations(project, mavenProject.getResources())) {
        jsrc.removeLink(location, 0, monitor);
    }
}

From source file:org.eluder.coveralls.maven.plugin.Environment.java

License:Open Source License

private void collectSourceDirectories(final MavenProject project, final List<File> directories) {
    for (String sourceRoot : project.getCompileSourceRoots()) {
        File directory = new File(sourceRoot);
        if (directory.exists() && directory.isDirectory()) {
            directories.add(directory);/*from  w w  w  .  j  av a2 s . com*/
        }
    }
    for (MavenProject collectedProject : project.getCollectedProjects()) {
        collectSourceDirectories(collectedProject, directories);
    }
}

From source file:org.eluder.coveralls.maven.plugin.util.SourceLoaderFactory.java

License:Open Source License

public SourceLoader createSourceLoader() {
    MultiSourceLoader multiSourceLoader = new MultiSourceLoader();
    List<MavenProject> modules = new MavenProjectCollector(project).collect();
    for (MavenProject module : modules) {
        for (String sourceRoot : module.getCompileSourceRoots()) {
            File sourceDirectory = new File(sourceRoot);
            if (sourceDirectory.exists() && sourceDirectory.isDirectory()) {
                DirectorySourceLoader moduleSourceLoader = new DirectorySourceLoader(baseDir, sourceDirectory,
                        sourceEncoding);
                multiSourceLoader.add(moduleSourceLoader);
            }/*from  www . j av a  2s  .  c o  m*/
        }
    }
    if (sourceDirectories != null) {
        for (File sourceDirectory : sourceDirectories) {
            if (sourceDirectory.exists() && sourceDirectory.isDirectory()) {
                DirectorySourceLoader moduleSourceLoader = new DirectorySourceLoader(baseDir, sourceDirectory,
                        sourceEncoding);
                multiSourceLoader.add(moduleSourceLoader);
            }
        }
    }
    return multiSourceLoader;
}

From source file:org.ensime.maven.plugins.ensime.EnsimeConfigGenerator.java

License:Apache License

private List<String> getSources(final MavenProject module, final String target) {
    Map<String, Plugin> plugins = project.getPluginManagement().getPluginsAsMap();

    Plugin scalacPlugin = plugins.get(SCALA_MAVEN_PLUGIN);

    List<String> sources = Optional.ofNullable(scalacPlugin).map(p -> p.getConfiguration()).flatMap(obj -> {
        if (obj instanceof Xpp3Dom) {
            Xpp3Dom config = (Xpp3Dom) obj;
            return Optional.ofNullable(config.getChild("sources"))
                    .map(c -> Arrays.stream(c.getChildren()).map(v -> v.getValue()).collect(toList()));
        } else//w w  w  .  j  a v  a 2  s .c o  m
            return Optional.empty();
    }).orElse(new ArrayList());

    if (sources.isEmpty()) {
        sources = Stream
                .of(new File(module.getBasedir().getAbsolutePath() + SP + "src" + SP + target + SP + "scala"),
                        new File(
                                module.getBasedir().getAbsolutePath() + SP + "src" + SP + target + SP + "java"))
                .map(f -> f.getAbsolutePath()).collect(toList());
    }

    sources.addAll(module.getCompileSourceRoots());

    return sources;
}

From source file:org.hsc.novelSpider.bundleplugin.BundlePlugin.java

License:Apache License

private static List<Resource> getMavenResources(MavenProject currentProject) {
    List<Resource> resources = new ArrayList<Resource>(currentProject.getResources());

    if (currentProject.getCompileSourceRoots() != null) {
        // also scan for any "packageinfo" files lurking in the source folders
        List<String> packageInfoIncludes = Collections.singletonList("**/packageinfo");
        for (Iterator<String> i = currentProject.getCompileSourceRoots().iterator(); i.hasNext();) {
            String sourceRoot = i.next();
            Resource packageInfoResource = new Resource();
            packageInfoResource.setDirectory(sourceRoot);
            packageInfoResource.setIncludes(packageInfoIncludes);
            resources.add(packageInfoResource);
        }/* w  w  w.j  a  v a2 s .  c  o m*/
    }

    return resources;
}