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

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

Introduction

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

Prototype

public List<Resource> getTestResources() 

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

From source file:org.jboss.tools.maven.jbosspackaging.configurators.SarProjectConfigurator.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) {
        IVirtualFolder jsrc = component.getRootFolder().getFolder(folder);
        for (IPath location : MavenProjectUtils.getSourceLocations(project,
                mavenProject.getTestCompileSourceRoots())) {
            if (location == null)
                continue;
            jsrc.removeLink(location, 0, monitor);
        }//from  w  w w.ja v a  2s  . co  m
        for (IPath location : MavenProjectUtils.getResourceLocations(project,
                mavenProject.getTestResources())) {
            if (location == null)
                continue;
            jsrc.removeLink(location, 0, monitor);
        }
    }
}

From source file:org.mobicents.maven.plugin.eclipse.ClasspathWriter.java

License:Open Source License

/**
 * Writes the source roots for the given project.
 * //from w  ww. j  av a 2s. co m
 * @param project
 *            the project for which to write the source roots.
 * @param rootDirectory
 *            the root project's base directory
 * @param writer
 *            the XMLWriter used to write the source roots.
 * @param includeResourcesDirectory
 */
private Set<String> collectSourceRoots(final MavenProject project, final String rootDirectory,
        final XMLWriter writer, boolean includeResourcesDirectory) {

    Set<String> sourcePaths = new TreeSet<String>();

    // collect source roots
    List<String> sourceRoots = new ArrayList<String>();
    sourceRoots.addAll(project.getCompileSourceRoots());
    sourceRoots.addAll(project.getTestCompileSourceRoots());
    for (String s : sourceRoots) {
        final String sourceRoot = PathNormalizer.normalizePath(s);
        if (new File(sourceRoot).isDirectory()) {
            String sourceRootPath = StringUtils.replace(sourceRoot, rootDirectory, "");
            if (sourceRootPath.startsWith("/")) {
                sourceRootPath = sourceRootPath.substring(1, sourceRootPath.length());
            }
            sourcePaths.add(sourceRootPath);
        }
    }

    if (includeResourcesDirectory) {

        // collect resources
        List<Resource> resources = new ArrayList<Resource>();
        resources.addAll(project.getResources());
        resources.addAll(project.getTestResources());
        for (Resource resource : resources) {
            final String resourceRoot = PathNormalizer.normalizePath(resource.getDirectory());
            File resourceDirectory = new File(resourceRoot);
            if (resourceDirectory.exists() && resourceDirectory.isDirectory()) {
                String resourceSourceRootPath = StringUtils.replace(resourceRoot, rootDirectory, "");
                if (resourceSourceRootPath.startsWith("/")) {
                    resourceSourceRootPath = resourceSourceRootPath.substring(1,
                            resourceSourceRootPath.length());
                }
                // we need to avoid nested paths, eclipse doesn't
                // support them
                // check if there is already a parent resource path
                boolean add = true;
                for (String resourcePath : sourcePaths) {
                    if (resourceSourceRootPath.startsWith(resourcePath)) {
                        // the one we are processing is a child folder,
                        // ignore it
                        add = false;
                        break;
                    }
                }
                if (add) {
                    for (String resourcePath : sourcePaths) {
                        if (resourcePath.startsWith(resourceSourceRootPath)) {
                            // the one we are processing is a parent
                            // folder, remove the child
                            sourcePaths.remove(resourcePath);
                        }
                    }
                    sourcePaths.add(resourceSourceRootPath);
                }
            }
        }
    }
    return sourcePaths;
}

From source file:org.ops4j.pax.construct.clone.CloneMojo.java

License:Apache License

/**
 * Create a new archetype for a bundle project, with potentially customized POM and Bnd settings
 * // ww w  .ja v  a2 s . c o  m
 * @param project Maven project
 * @param namespace Java namespace, may be null
 * @param customizedPom customized Maven project model, may be null
 * @return clause identifying the archetype fragment
 * @throws MojoExecutionException
 */
private String createBundleArchetype(MavenProject project, String namespace, Pom customizedPom)
        throws MojoExecutionException {
    File baseDir = project.getBasedir();

    getLog().info("Cloning bundle project " + project.getArtifactId());
    ArchetypeFragment fragment = new ArchetypeFragment(getFragmentDir(), namespace, false);
    fragment.addPom(baseDir, customizedPom);

    if (null != namespace) {
        fragment.addSources(baseDir, project.getBuild().getSourceDirectory(), false);
        fragment.addSources(baseDir, project.getBuild().getTestSourceDirectory(), true);
    }

    for (Iterator i = project.getTestResources().iterator(); i.hasNext();) {
        Resource r = (Resource) i.next();
        fragment.addResources(baseDir, r.getDirectory(), r.getIncludes(), r.getExcludes(), true);
    }

    List excludes = new ArrayList();
    excludes.addAll(fragment.getIncludedFiles());
    excludes.add("target/");
    excludes.add("runner/");
    excludes.add("pom.xml");

    // consider everything else in the bundle directory to be a resource
    fragment.addResources(baseDir, baseDir.getPath(), null, excludes, false);

    // archetype must use different id
    String groupId = project.getGroupId();
    String artifactId = project.getArtifactId() + "-archetype";
    String version = project.getVersion();

    // archive customized bundle sources, POM and Bnd instructions
    String fragmentId = groupId + ':' + artifactId + ':' + version;
    fragment.createArchive(fragmentId.replace(':', '_'), newJarArchiver());

    return fragmentId;
}

From source file:org.wisdom.maven.utils.MavenUtils.java

License:Apache License

/**
 * Gets the default set of properties for the given project.
 *
 * @param currentProject the project/*w w  w  . j a  v a  2s.c  om*/
 * @return the set of properties, containing default bundle packaging instructions.
 */
public static Properties getDefaultProperties(MavenProject currentProject) {
    Properties properties = new Properties();
    String bsn = DefaultMaven2OsgiConverter.getBundleSymbolicName(currentProject.getArtifact());

    // Setup defaults
    properties.put(MAVEN_SYMBOLICNAME, bsn);
    properties.put("bundle.file.name",
            DefaultMaven2OsgiConverter.getBundleFileName(currentProject.getArtifact()));
    properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
    properties.put(Analyzer.IMPORT_PACKAGE, "*");
    properties.put(Analyzer.BUNDLE_VERSION, DefaultMaven2OsgiConverter.getVersion(currentProject.getVersion()));

    header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription());
    StringBuilder licenseText = printLicenses(currentProject.getLicenses());
    if (licenseText != null) {
        header(properties, Analyzer.BUNDLE_LICENSE, licenseText);
    }
    header(properties, Analyzer.BUNDLE_NAME, currentProject.getName());

    if (currentProject.getOrganization() != null) {
        if (currentProject.getOrganization().getName() != null) {
            String organizationName = currentProject.getOrganization().getName();
            header(properties, Analyzer.BUNDLE_VENDOR, organizationName);
            properties.put("project.organization.name", organizationName);
            properties.put("pom.organization.name", organizationName);
        }
        if (currentProject.getOrganization().getUrl() != null) {
            String organizationUrl = currentProject.getOrganization().getUrl();
            header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl);
            properties.put("project.organization.url", organizationUrl);
            properties.put("pom.organization.url", organizationUrl);
        }
    }

    properties.putAll(currentProject.getModel().getProperties());

    for (String s : currentProject.getFilters()) {
        File filterFile = new File(s);
        if (filterFile.isFile()) {
            properties.putAll(PropertyUtils.loadProperties(filterFile));
        }
    }

    properties.putAll(getProperties(currentProject.getModel(), "project.build."));
    properties.putAll(getProperties(currentProject.getModel(), "pom."));
    properties.putAll(getProperties(currentProject.getModel(), "project."));

    properties.put("project.baseDir", currentProject.getBasedir().getAbsolutePath());
    properties.put("project.build.directory", currentProject.getBuild().getDirectory());
    properties.put("project.build.outputdirectory", currentProject.getBuild().getOutputDirectory());

    properties.put("project.source.roots", getArray(currentProject.getCompileSourceRoots()));
    properties.put("project.testSource.roots", getArray(currentProject.getTestCompileSourceRoots()));

    properties.put("project.resources", toString(currentProject.getResources()));
    properties.put("project.testResources", toString(currentProject.getTestResources()));

    return properties;
}

From source file:se.jguru.nazgul.tools.plugin.checkstyle.exec.DefaultCheckstyleExecutor.java

License:Apache License

private List<File> getFilesToProcess(CheckstyleExecutorRequest request) throws IOException {
    StringBuilder excludesStr = new StringBuilder();

    if (StringUtils.isNotEmpty(request.getExcludes())) {
        excludesStr.append(request.getExcludes());
    }//from  w w w.  j a  v a 2  s  . c o m

    String[] defaultExcludes = FileUtils.getDefaultExcludes();
    for (String defaultExclude : defaultExcludes) {
        if (excludesStr.length() > 0) {
            excludesStr.append(",");
        }

        excludesStr.append(defaultExclude);
    }

    Set<File> files = new LinkedHashSet<>();
    if (request.isAggregate()) {
        for (MavenProject project : request.getReactorProjects()) {
            Set<File> sourceDirectories = new LinkedHashSet<>();

            // CompileSourceRoots are absolute paths
            List<String> compileSourceRoots = project.getCompileSourceRoots();
            for (String compileSourceRoot : compileSourceRoots) {
                sourceDirectories.add(new File(compileSourceRoot));
            }

            Set<File> testSourceDirectories = new LinkedHashSet<>();
            // CompileSourceRoots are absolute paths
            List<String> testCompileSourceRoots = project.getTestCompileSourceRoots();
            for (String testCompileSourceRoot : testCompileSourceRoots) {
                testSourceDirectories.add(new File(testCompileSourceRoot));
            }

            addFilesToProcess(request, sourceDirectories, project.getResources(), project.getTestResources(),
                    files, testSourceDirectories);
        }
    } else {
        Collection<File> sourceDirectories = request.getSourceDirectories();
        addFilesToProcess(request, sourceDirectories, request.getResources(), request.getTestResources(), files,
                request.getTestSourceDirectories());
    }

    getLogger().debug("Added " + files.size() + " files to process.");

    return new ArrayList<>(files);
}