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

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

Introduction

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

Prototype

public List<Resource> getResources() 

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;//from www .j a v  a  2  s .  c o 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 w  w w .  j  a v  a 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.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;/* w w w. j  av a  2  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);
        }//  w  ww. j a v  a  2s. c  om
        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.j a  v  a2s .co  m*/
    for (IPath location : MavenProjectUtils.getResourceLocations(project, mavenProject.getResources())) {
        jsrc.removeLink(location, 0, monitor);
    }
}

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);
        }//from ww  w  .  j av a  2  s .c  o m
    }

    return resources;
}

From source file:org.hsc.novelSpider.obrplugin.ObrUtils.java

License:Apache License

/**
 * @param project current project/*from w w w. ja  v a 2s  .co m*/
 * @return URI pointing to correct obr.xml, null if not found
 */
public static URI findObrXml(MavenProject project) {
    File obrFile = new File(project.getBuild().getOutputDirectory(), OBR_XML);
    if (obrFile.exists()) {
        return obrFile.toURI();
    }
    for (Iterator i = project.getResources().iterator(); i.hasNext();) {
        Resource resource = (Resource) i.next();
        obrFile = new File(resource.getDirectory(), OBR_XML);
        if (obrFile.exists()) {
            return obrFile.toURI();
        }
    }
    return null;
}

From source file:org.jboss.tools.maven.jbosspackaging.configurators.SarProjectConfigurator.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;/* w  w w .  j av  a  2s .  c  om*/
    }

    IPath[] sourceRoots = MavenProjectUtils.getSourceLocations(project, mavenProject.getCompileSourceRoots());
    IPath[] resourceRoots = MavenProjectUtils.getResourceLocations(project, mavenProject.getResources());

    if (!checkJavaConfiguration(project, sourceRoots, resourceRoots)) {
        return;
    }

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

    WTPProjectsUtil.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();
        }
    }

    WTPProjectsUtil.fixMissingModuleCoreNature(project, monitor);

    //MNGECLIPSE-904 remove tests folder links for utility jars
    removeTestFolderLinks(project, mavenProject, monitor, "/");

    //Remove "library unavailable at runtime" warning.
    WTPProjectsUtil.setNonDependencyAttributeToContainer(project, monitor);

    WTPProjectsUtil.removeWTPClasspathContainer(project);
}

From source file:org.jboss.tools.maven.seam.configurators.FixClasspathConfigurator.java

License:Open Source License

private void configureInternal(MavenProject mavenProject, IProject project, IProgressMonitor monitor)
        throws CoreException {
    if (!project.hasNature(JavaCore.NATURE_ID)) {
        return;/*from w  w  w  .  ja v a  2  s . co m*/
    }
    List<Resource> resources = mavenProject.getResources();
    for (Resource resource : resources) {

        File directory = new File(resource.getDirectory());
        String absolutePath = directory.getAbsolutePath();
        try {
            absolutePath = directory.getCanonicalPath();
        } catch (IOException e) {
            MavenSeamActivator.log(e);
        }
        if (!new File(absolutePath).exists()) {
            continue;
        }
        IPath relativePath = getProjectRelativePath(project, absolutePath);
        IResource r = project.findMember(relativePath);
        if (r != null) {
            continue;
        }
        String path = getWorkspaceRelativePath(absolutePath);
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        boolean exists = false;
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath entryPath = entry.getPath();
                if (entryPath != null && path.equals(entryPath.toString())) {
                    exists = true;
                    break;
                }
            }
        }
        if (!exists) {
            IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
            for (int i = 0; i < entries.length; i++) {
                newEntries[i] = entries[i];
            }
            IClasspathEntry pathEntry = JavaCore.newLibraryEntry(new Path(path), null, null);
            newEntries[entries.length] = pathEntry;
            javaProject.setRawClasspath(newEntries, monitor);
        }
    }
}

From source file:org.jooby.JoobyMojo.java

License:Apache License

@SuppressWarnings("unchecked")
private static Watcher setupCompiler(final MavenProject project, final String compiler,
        final Consumer<String> task) throws MojoFailureException {
    File eclipseClasspath = new File(project.getBasedir(), ".classpath");
    if ("off".equalsIgnoreCase(compiler) || eclipseClasspath.exists()) {
        return null;
    }//from w  ww  .  j  av  a  2 s. com
    List<File> resources = resources(project.getResources());
    resources.add(0, new File(project.getBuild().getSourceDirectory()));
    List<Path> paths = resources.stream().filter(File::exists).map(File::toPath).collect(Collectors.toList());
    try {
        ClassLoader backloader = Thread.currentThread().getContextClassLoader();
        return new Watcher((kind, path) -> {
            ClassLoader currentloader = Thread.currentThread().getContextClassLoader();
            try {
                Thread.currentThread().setContextClassLoader(backloader);
                if (path.toString().endsWith(".java")) {
                    task.accept("compile");
                } else if (path.toString().endsWith(".conf") || path.toString().endsWith(".properties")) {
                    task.accept("compile");
                }
            } finally {
                Thread.currentThread().setContextClassLoader(currentloader);
            }
        }, paths.toArray(new Path[paths.size()]));
    } catch (Exception ex) {
        throw new MojoFailureException("Can't compile source code", ex);
    }
}