org.apache.maven.plugin.PluginParameterExpressionEvaluator#org.apache.maven.model.Resource源码实例Demo

下面列出了org.apache.maven.plugin.PluginParameterExpressionEvaluator#org.apache.maven.model.Resource 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void collectConfig(MavenProject project, MavenSession session) {
    final Path projectDir = project.getBasedir().toPath();
    final ProjectConfig config = ProjectConfig.projectConfig(projectDir);
    final List<String> dependencies = dependencies(project, session);
    final Path outputDir = projectDir.resolve(project.getBuild().getOutputDirectory());
    final List<String> classesDirs = List.of(outputDir.toString());
    final List<String> resourceDirs = project.getResources()
            .stream()
            .map(Resource::getDirectory)
            .collect(Collectors.toList());
    config.property(PROJECT_DEPENDENCIES, dependencies);
    config.property(PROJECT_MAINCLASS, project.getProperties().getProperty(MAIN_CLASS_PROPERTY));
    config.property(PROJECT_VERSION, project.getVersion());
    config.property(PROJECT_CLASSDIRS, classesDirs);
    config.property(PROJECT_SOURCEDIRS, project.getCompileSourceRoots());
    config.property(PROJECT_RESOURCEDIRS, resourceDirs);
    this.projectConfig = config;
}
 
源代码2 项目: quarkus   文件: DevMojo.java
/**
 * Execute the resources:resources goal if resources have been configured on the project
 */
private void handleResources() throws MojoExecutionException {
    List<Resource> resources = project.getResources();
    if (!resources.isEmpty()) {
        Plugin resourcesPlugin = project.getPlugin(ORG_APACHE_MAVEN_PLUGINS + ":" + MAVEN_RESOURCES_PLUGIN);
        MojoExecutor.executeMojo(
                MojoExecutor.plugin(
                        MojoExecutor.groupId(ORG_APACHE_MAVEN_PLUGINS),
                        MojoExecutor.artifactId(MAVEN_RESOURCES_PLUGIN),
                        MojoExecutor.version(resourcesPlugin.getVersion()),
                        resourcesPlugin.getDependencies()),
                MojoExecutor.goal("resources"),
                getPluginConfig(resourcesPlugin),
                MojoExecutor.executionEnvironment(
                        project,
                        session,
                        pluginManager));
    }
}
 
源代码3 项目: netbeans   文件: MavenNbModuleImpl.java
@Override
public String getResourceDirectoryPath(boolean isTest) {
    NbMavenProject watch = project.getLookup().lookup(NbMavenProject.class);
    List<Resource> res;
    String defaultValue;
    
    if (isTest) {
        res = watch.getMavenProject().getTestResources();           
        defaultValue = "src/test/resources"; //NOI18N
    } else {
        res = watch.getMavenProject().getResources();
        defaultValue = "src/main/resources"; //NOI18N
    }
    for (Resource resource : res) {
        FileObject fo = FileUtilities.convertStringToFileObject(resource.getDirectory());
        if (fo != null && FileUtil.isParentOf(project.getProjectDirectory(), fo)) {
            return FileUtil.getRelativePath(project.getProjectDirectory(), fo);
        }
    }
    return defaultValue;
}
 
源代码4 项目: syndesis   文件: GenerateMapperInspectionsMojo.java
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {

        final Resource resource = new Resource();
        resource.setDirectory(outputDir.getCanonicalPath());
        project.addResource(resource);

        final Set<File> generated = new HashSet<>();

        final ReadApiClientData reader = new ReadApiClientData();
        final List<ModelData<?>> modelList = reader.readDataFromFile("io/syndesis/server/dao/deployment.json");
        for (final ModelData<?> model : modelList) {
            if (model.getKind() == Kind.Connector) {
                final Connector connector = (Connector) model.getData();

                for (final ConnectorAction action : connector.getActions()) {
                    process(generated, connector, action, action.getInputDataShape());
                    process(generated, connector, action, action.getOutputDataShape());
                }
            }
        }
    } catch (final IOException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
}
 
源代码5 项目: hyperjaxb3   文件: Hyperjaxb3Mojo.java
/**
 * Updates XJC's compilePath ans resources and update hyperjaxb2's
 * resources, that is, *.hbm.xml files and hibernate.config.xml file.
 * 
 * @param xjcOpts
 * @throws MojoExecutionException
 */
protected void setupMavenPaths() {
	super.setupMavenPaths();

	final Resource resource = new Resource();
	resource.setDirectory(getGenerateDirectory().getPath());
	for (String resourceInclude : resourceIncludes) {
		resource.addInclude(resourceInclude);
	}
	getProject().addResource(resource);

	if (this.roundtripTestClassName != null) {
		getProject().addTestCompileSourceRoot(
				getGenerateDirectory().getPath());
	}
}
 
源代码6 项目: proctor   文件: AbstractProctorMojo.java
private void addNonPartialsToResources(final File dir, final Resource resource) throws CodeGenException {
    if (dir.equals(null)) {
        throw new CodeGenException("Could not read from directory " + dir.getPath());
    }
    final File[] files = dir.listFiles();
    if (files == null) {
        return;
    }
    for (final File entry : files) {
        try {
            if (entry.isDirectory()) {
                addNonPartialsToResources(entry, resource);
            } else if (entry.getName().endsWith(".json") && ProctorUtils.readJsonFromFile(entry).has("tests")) {
                resource.addInclude(entry.getPath().substring(getTopDirectory().getPath().length() + 1));
            }
        } catch (final IOException e) {
            throw new CodeGenException("Could not read from file " + entry.getName(),e);
        }

    }
}
 
源代码7 项目: proctor   文件: AbstractProctorMojo.java
Resource[] getResources() throws MojoExecutionException {
    final Resource resourceNonGenerated = new Resource();
    resourceNonGenerated.setDirectory(getTopDirectory().getPath());
    try {
        addNonPartialsToResources(getTopDirectory(),resourceNonGenerated);
    } catch (final CodeGenException e) {
        throw new MojoExecutionException("Couldn't add non partial specifications to resources");
    }
    if (resourceNonGenerated.getIncludes().isEmpty()) {
        resourceNonGenerated.addExclude("**/*");
    }
    final Resource resourceGenerated = new Resource();
    final File specificationOutputDir = getSpecificationOutput();
    resourceGenerated.setDirectory(specificationOutputDir.getPath());
    resourceGenerated.addInclude("**/*.json");
    final Resource[] resources = {resourceNonGenerated,resourceGenerated};
    return resources;

}
 
源代码8 项目: wisdom   文件: MavenUtils.java
/**
 * Compute a String form the given list of resources. The list is structured as follows:
 * list:=resource[,resource]*
 * resource:=directory;target;filtering;
 *
 * @param resources the list of resources
 * @return the computed String form
 */
protected static String toString(List<Resource> resources) {
    StringBuilder builder = new StringBuilder();

    for (Resource resource : resources) {
        if (builder.length() == 0) {
            builder.append(resource.getDirectory())
                    .append(";")
                    .append(resource.getTargetPath() != null ? resource.getTargetPath() : "")
                    .append(";")
                    .append(resource.getFiltering() != null ? resource.getFiltering() : "true")
                    .append(";");
        } else {
            builder.append(",")
                    .append(resource.getDirectory())
                    .append(";")
                    .append(resource.getTargetPath() != null ? resource.getTargetPath() : "")
                    .append(";")
                    .append(resource.getFiltering() != null ? resource.getFiltering() : "true")
                    .append(";");
        }
    }

    return builder.toString();
}
 
源代码9 项目: wisdom   文件: ResourceCopy.java
private static void filterAndCopy(AbstractWisdomMojo mojo, MavenResourcesFiltering filtering, File in, File out) throws IOException {
    Resource resource = new Resource();
    resource.setDirectory(in.getAbsolutePath());
    resource.setFiltering(true);
    resource.setTargetPath(out.getAbsolutePath());

    List<String> excludedExtensions = new ArrayList<>();
    excludedExtensions.addAll(filtering.getDefaultNonFilteredFileExtensions());
    excludedExtensions.addAll(NON_FILTERED_EXTENSIONS);

    MavenResourcesExecution exec = new MavenResourcesExecution(ImmutableList.of(resource), out, mojo.project,
            "UTF-8", Collections.<String>emptyList(), excludedExtensions, mojo.session);
    exec.setEscapeString("\\");

    try {
        filtering.filterResources(exec);
    } catch (MavenFilteringException e) {
        throw new IOException("Error while copying resources", e);
    }
}
 
/**
 * Initializes the Scanner with the default values.
 * <br>
 * By default:
 * <ul>
 *     <li>includes adds extension .adoc, .ad, .asc and .asciidoc
 *     <li>excludes adds filters to avoid hidden files and directoris beginning with undersore
 * </ul>
 *
 * NOTE: Patterns both in inclusions and exclusions are automatically excluded.
 */
private void setupScanner(Scanner scanner, Resource resource) {

    if (resource.getIncludes() == null || resource.getIncludes().isEmpty()) {
        scanner.setIncludes(DEFAULT_FILE_EXTENSIONS);
    } else {
        scanner.setIncludes(resource.getIncludes().toArray(new String[] {}));
    }

    if (resource.getExcludes() == null || resource.getExcludes().isEmpty()) {
        scanner.setExcludes(IGNORED_FOLDERS_AND_FILES);
    } else {
        scanner.setExcludes(mergeAndConvert(resource.getExcludes(), IGNORED_FOLDERS_AND_FILES));
    }
    // adds exclusions like SVN or GIT files
    scanner.addDefaultExcludes();
}
 
源代码11 项目: jax-maven-plugin   文件: BaseMojo.java
private void addResources(Log log) {
    if (addResources) {
        cmd //
                .getResourceParameter() //
                .flatMap(parameterName -> Util.getNextArgument(arguments, parameterName)) //
                .ifPresent(x -> {
                    Resource resource = new Resource();
                    resource.setDirectory(x);
                    project.addResource(resource);
                    log.info("added resource folder: " + x);
                });
    }
}
 
源代码12 项目: yaks   文件: ProjectModelEnricher.java
/**
 * Dynamically add test resource directory pointing to mounted test directory. Mounted directory usually gets added
 * as volume mount and holds tests to execute in this project.
 * @param projectModel
 */
private void injectTestResources(Model projectModel) {
    if (ExtensionSettings.hasMountedTests()) {
        Resource mountedTests = new Resource();
        mountedTests.setDirectory(ExtensionSettings.getMountedTestsPath() + "/..data");
        mountedTests.setTargetPath(projectModel.getBuild().getTestOutputDirectory() + "/org/citrusframework/yaks");
        mountedTests.setFiltering(false);
        projectModel.getBuild().getTestResources().add(mountedTests);

        logger.info("Add mounted test resources in directory: " + ExtensionSettings.getMountedTestsPath());
    }
}
 
源代码13 项目: helidon-build-tools   文件: JarMojo.java
/**
 * Scan for project resources and produce a comma separated list of include resources.
 *
 * @return list of resources
 */
private Map<String, List<String>> scanResources() {
    getLog().debug("Scanning project resources");
    Map<String, List<String>> allResources = new HashMap<>();
    for (Resource resource : project.getResources()) {
        List<String> resources = new ArrayList<>();
        allResources.put(resource.getDirectory(), resources);
        File resourcesDir = new File(resource.getDirectory());
        Scanner scanner = buildContext.newScanner(resourcesDir);
        String[] includes = null;
        if (resource.getIncludes() != null
                && !resource.getIncludes().isEmpty()) {
            includes = (String[]) resource.getIncludes()
                    .toArray(new String[resource.getIncludes().size()]);
        }
        scanner.setIncludes(includes);
        String[] excludes = null;
        if (resource.getExcludes() != null
                && !resource.getExcludes().isEmpty()) {
            excludes = (String[]) resource.getExcludes()
                    .toArray(new String[resource.getExcludes().size()]);
        }
        scanner.setExcludes(excludes);
        scanner.scan();
        for (String included : scanner.getIncludedFiles()) {
            getLog().debug("Found resource: " + included);
            resources.add(included);
        }
    }
    return allResources;
}
 
源代码14 项目: quarkus   文件: LocalProject.java
public Path getResourcesSourcesDir() {
    final List<Resource> resources = rawModel.getBuild() == null ? Collections.emptyList()
            : rawModel.getBuild().getResources();
    //todo: support multiple resources dirs for config hot deployment
    final String resourcesDir = resources.isEmpty() ? null : resources.get(0).getDirectory();
    return resolveRelativeToBaseDir(resourcesDir, "src/main/resources");
}
 
源代码15 项目: quarkus   文件: BuildMojo.java
private static boolean hasSources(MavenProject project) {
    if (new File(project.getBuild().getSourceDirectory()).exists()) {
        return true;
    }
    for (Resource r : project.getBuild().getResources()) {
        if (new File(r.getDirectory()).exists()) {
            return true;
        }
    }
    return false;
}
 
源代码16 项目: netbeans   文件: NbMavenProjectImpl.java
public URI[] getResources(boolean test) {
        List<URI> toRet = new ArrayList<URI>();
        URI projectroot = getProjectDirectory().toURI();
        Set<URI> sourceRoots = null;
        List<Resource> res = test ? getOriginalMavenProject().getTestResources() : getOriginalMavenProject().getResources();
        LBL : for (Resource elem : res) {
            String dir = elem.getDirectory();
            if (dir == null) {
                continue; // #191742
            }
            URI uri = FileUtilities.getDirURI(getProjectDirectory(), dir);
            if (elem.getTargetPath() != null || !elem.getExcludes().isEmpty() || !elem.getIncludes().isEmpty()) {
                URI rel = projectroot.relativize(uri);
                if (rel.isAbsolute()) { //outside of project directory
                    continue;// #195928, #231517
                }
                if (sourceRoots == null) {
                    sourceRoots = new HashSet<URI>();
                    sourceRoots.addAll(Arrays.asList(getSourceRoots(true)));
                    sourceRoots.addAll(Arrays.asList(getSourceRoots(false)));
                    //should we also consider generated sources? most like not necessary
                }
                for (URI sr : sourceRoots) {
                    if (!uri.relativize(sr).isAbsolute()) {
                        continue LBL;// #195928, #231517
                    }
                }
                //hope for the best now
            }
//            if (new File(uri).exists()) {
            toRet.add(uri);
//            }
        }
        return toRet.toArray(new URI[toRet.size()]);
    }
 
源代码17 项目: netbeans   文件: CopyResourcesOnSave.java
final void refresh() {
    synchronized (resourceUris) {
        List<Resource> resources = new ArrayList<Resource>();
        resources.addAll(nbproject.getMavenProject().getResources());
        resources.addAll(nbproject.getMavenProject().getTestResources());
        Set<File> old = new HashSet<File>(resourceUris);
        Set<File> added = new HashSet<File>();
        
            for (Resource res : resources) {
                String dir = res.getDirectory();
                if (dir == null) {
                    continue;
                }
                URI uri = FileUtilities.getDirURI(project.getProjectDirectory(), dir);
                File file = Utilities.toFile(uri);
                if (!old.contains(file) && !added.contains(file)) { // if a given file is there multiple times, we get assertion back from FileUtil. there can be only one listener+file tuple
                    FileUtil.addRecursiveListener(this, file);
                }
                added.add(file);
            }
        
        old.removeAll(added);
        for (File oldFile : old) {
            FileUtil.removeRecursiveListener(this, oldFile);
        }
        resourceUris.removeAll(old);
        resourceUris.addAll(added);
    }
}
 
源代码18 项目: netbeans   文件: CopyResourcesOnSave.java
private String addTargetPath(String path, Resource resource) {
    String target = resource.getTargetPath();
    if (target != null) {
        target = target.replace("\\", "/");
        target = target.endsWith("/") ? target : (target + "/");
        path = target + path;
    }
    return path;
}
 
源代码19 项目: netbeans   文件: CopyResourcesOnSave.java
protected void logResources(FileObject fo, List<Resource> resources) {
    if(LOG.isLoggable(Level.FINE)) {
        for (Resource res : resources) {
            LOG.log(Level.FINE, " {0}", res);
        }
    }
}
 
源代码20 项目: netbeans   文件: FilteredResourcesCoSSkipper.java
private boolean hasChangedResources(Resource r, long stamp) {
        String dir = r.getDirectory();
        File dirFile = FileUtil.normalizeFile(new File(dir));
  //      System.out.println("checkresource dirfile =" + dirFile);
        if (dirFile.exists()) {
            List<File> toCopy = new ArrayList<File>();
            DirectoryScanner ds = new DirectoryScanner();
            ds.setBasedir(dirFile);
            //includes/excludes
            String[] incls = r.getIncludes().toArray(new String[0]);
            if (incls.length > 0) {
                ds.setIncludes(incls);
            } else {
                ds.setIncludes(DEFAULT_INCLUDES);
            }
            String[] excls = r.getExcludes().toArray(new String[0]);
            if (excls.length > 0) {
                ds.setExcludes(excls);
            }
            ds.addDefaultExcludes();
            ds.scan();
            String[] inclds = ds.getIncludedFiles();
//            System.out.println("found=" + inclds.length);
            for (String inc : inclds) {
                File f = new File(dirFile, inc);
                if (f.lastModified() >= stamp) { 
                    toCopy.add(FileUtil.normalizeFile(f));
                }
            }
            if (toCopy.size() > 0) {
                    //the case of filtering source roots, here we want to return false
                    //to skip CoS altogether.
                return true;
            }
        }
        return false;
    }
 
源代码21 项目: netbeans   文件: OthersRootChildren.java
@Override
@Messages({
    "# {0} - directory path",
    "TIP_Resource1=<html>Resource directory defined in POM.<br><i>Directory: </i><b>{0}</b><br>", 
    "# {0} - maven resource target path",
    "TIP_Resource2=<i>Target Path: </i><b>{0}</b><br>", 
    "# {0} - boolean value",
    "TIP_Resource6=<b><i>Filtering: </i>{0}. Please note that some IDE features rely on non-filtered content only.</b><br>", 
    "# {0} - includes string value",
    "TIP_Resource3=<i>Includes: </i><b>{0}</b><br>", 
    "# {0} - excludes string value",
    "TIP_Resource4=<i>Excludes: </i><b>{0}</b><br>", 
    "# {0} - directory path",
    "TIP_Resource5=<html>Configuration Directory<br><i>Directory: </i><b>{0}</b><br>"})
public String getShortDescription() {
    if (group.getResource() != null) {
        Resource rs = group.getResource();
        String str = TIP_Resource1(rs.getDirectory());
        if (rs.getTargetPath() != null) {
            str = str + TIP_Resource2(rs.getTargetPath());
        }
        if (rs.isFiltering()) {
            str = str + TIP_Resource6(rs.isFiltering());
        }
        if (rs.getIncludes() != null && rs.getIncludes().size() > 0) {
            str = str + TIP_Resource3(Arrays.toString(rs.getIncludes().toArray()));
        }
        if (rs.getExcludes() != null && rs.getExcludes().size() > 0) {
            str = str + TIP_Resource4(Arrays.toString(rs.getExcludes().toArray()));
        }
        return str;
    } else {
        return  TIP_Resource5(FileUtil.getFileDisplayName(group.getRootFolder()));
     }
}
 
源代码22 项目: netbeans   文件: MavenSourcesImpl.java
private Resource checkResource(FileObject rootFold, List<Resource> list) {
    for (Resource elem : list) {
        String dir = elem.getDirectory();
        if (dir == null) { // #203635
            continue;
        }
        URI uri = FileUtilities.getDirURI(project.getProjectDirectory(), dir);
        FileObject fo = FileUtilities.convertURItoFileObject(uri);
        if (fo != null && fo.equals(rootFold)) {
            return elem;
        }
    }
    return null;
}
 
源代码23 项目: graphql-apigen   文件: ApiGenMojo.java
@Override
public void execute() {
    try {
        sourceDirectory = makeAbsolute(sourceDirectory);
        outputDirectory = makeAbsolute(outputDirectory);
        if ( ! sourceDirectory.exists() ) return;
        getLog().debug("Running ApiGen\n\tsourceDirectory=" + sourceDirectory +
                       "\n\toutputDirectory=" + outputDirectory);
        ClassLoader cp = getCompileClassLoader();
        ApiGen apiGen = new ApiGen.Builder()
            .withOutputDirectory(outputDirectory.toPath())
            .withGuiceModuleName(guiceModuleName)
            .withDefaultPackageName(defaultPackageName)
            .build();
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cp);
        for ( org.springframework.core.io.Resource resource : resolver.getResources("classpath*:graphql-apigen-schema/*.graphql{,s}") ) {
            URL url = resource.getURL();
            getLog().debug("Processing "+url);
            apiGen.addForReference(url);
        }
        findGraphql(sourceDirectory, apiGen::addForGeneration);
        apiGen.generate();
        Resource schemaResource = new Resource();
        schemaResource.setTargetPath("graphql-apigen-schema");
        schemaResource.setFiltering(false);
        schemaResource.setIncludes(Arrays.asList("*.graphqls","*.graphql"));
        schemaResource.setDirectory(sourceDirectory.toString());
        project.addResource(schemaResource);
        project.addCompileSourceRoot(outputDirectory.getAbsolutePath());
    } catch (Exception e) {
        String msg = e.getMessage();
        if ( null == msg ) msg = e.getClass().getName();
        getLog().error(msg + " when trying to build sources from graphql.", e);
    }
}
 
源代码24 项目: appassembler   文件: AbstractScriptGeneratorMojo.java
protected void doCopyPreAssembleDirectory( final String targetDirectory )
    throws MojoFailureException
{
    // Create a Resource from the configuration source directory
    Resource resource = new Resource();
    resource.setDirectory( preAssembleDirectory.getAbsolutePath() );
    resource.setFiltering( filterPreAssembleDirectory );
    List<Resource> resources = new ArrayList<Resource>();
    resources.add( resource );

    MavenResourcesExecution mavenResourcesExecution =
        new MavenResourcesExecution( resources, new File( targetDirectory ), mavenProject, encoding, buildFilters,
                                     Collections.<String>emptyList(), session );

    mavenResourcesExecution.setEscapeString( escapeString );
    // Include empty directories, to be backwards compatible
    mavenResourcesExecution.setIncludeEmptyDirs( true );
    mavenResourcesExecution.setUseDefaultFilterWrappers( true );

    try
    {
        getLog().info( "Copy pre-assemble files from " + this.preAssembleDirectory.getAbsolutePath() + " to "
                            + targetDirectory );

        // Use a MavenResourcesFiltering component to filter and copy the configuration files
        mavenResourcesFiltering.filterResources( mavenResourcesExecution );
    }
    catch ( MavenFilteringException mfe )
    {
        throw new MojoFailureException( "Failed to copy/filter the configuration files." );
    }
}
 
/**
 * {@inheritDoc}
 */
@Override
protected void addResource(final Resource resource) {

    if (resource != null) {

        final String newDirectory = resource.getDirectory();

        // Is the supplied resource already added?
        final List<Resource> currentResources = getProject().getTestResources();

        if (getLog().isDebugEnabled()) {
            getLog().debug("Candidate Test Resource Directory [" + newDirectory + "]");
            getLog().debug("Found [" + currentResources.size() + "] current Test Resources: "
                    + currentResources);
        }

        for (Resource current : currentResources) {

            // Is the resource already added?
            if (current.getDirectory() != null && current.getDirectory().equalsIgnoreCase(newDirectory)) {
                getLog().debug("Test resource already added [" + newDirectory + "]. Not adding again.");
                return;
            }
        }

        // Add the new Resource
        currentResources.add(resource);

        if (getLog().isDebugEnabled()) {
            getLog().debug("Added test resource [" + newDirectory + "] to existing test resources.");
        }
    }
}
 
源代码26 项目: jaxb2-maven-plugin   文件: SchemaGenerationMojo.java
/**
 * {@inheritDoc}
 */
@Override
protected void addResource(final Resource resource) {

    if(resource != null) {

        final String newDirectory = resource.getDirectory();

        // Is the supplied resource already added?
        final List<Resource> currentResources = getProject().getResources();

        if(getLog().isDebugEnabled()) {
            getLog().debug("Candidate Resource Directory [" + newDirectory + "]");
            getLog().debug("Found [" + currentResources.size() + "] current Resources: "
                    + currentResources);
        }

        for (Resource current : currentResources) {

            // Is the resource already added?
            if(current.getDirectory() != null && current.getDirectory().equalsIgnoreCase(newDirectory)) {
                getLog().debug("Resource already added [" + newDirectory + "]. Not adding again.");
                return;
            }
        }

        // Add the new Resource
        currentResources.add(resource);

        if(getLog().isDebugEnabled()) {
            getLog().debug("Added resource [" + newDirectory + "] to existing resources.");
        }
    }
}
 
/**
 * Add the resource to the project.
 *
 * @param resource the resource to add
 */
public void addResource( Resource resource )
{
    getProject().addTestResource( resource );
    if ( getLog().isDebugEnabled() )
    {
        getLog().debug( "Added test resource: " + resource.getDirectory() );
    }
}
 
public void addResource( Resource resource )
{
    getProject().addResource( resource );
    if ( getLog().isDebugEnabled() )
    {
        getLog().debug( "Added resource: " + resource.getDirectory() );
    }
}
 
源代码29 项目: maven-jaxb2-plugin   文件: RawXJC2Mojo.java
/**
 * Augments Maven paths with generated resources.
 */
protected void setupMavenPaths() {

	if (getAddCompileSourceRoot()) {
		getProject().addCompileSourceRoot(getGenerateDirectory().getPath());
	}
	if (getAddTestCompileSourceRoot()) {
		getProject().addTestCompileSourceRoot(getGenerateDirectory().getPath());
	}
	if (getEpisode() && getEpisodeFile() != null) {
		final String episodeFilePath = getEpisodeFile().getAbsolutePath();
		final String generatedDirectoryPath = getGenerateDirectory().getAbsolutePath();

		if (episodeFilePath.startsWith(generatedDirectoryPath + File.separator)) {
			final String path = episodeFilePath.substring(generatedDirectoryPath.length() + 1);

			final Resource resource = new Resource();
			resource.setDirectory(generatedDirectoryPath);
			resource.addInclude(path);
			if (getAddCompileSourceRoot()) {
				getProject().addResource(resource);
			}
			if (getAddTestCompileSourceRoot()) {
				getProject().addTestResource(resource);

			}
		}
	}
}
 
源代码30 项目: roboconf-platform   文件: InitializeMojoTest.java
@Test
public void checkSourcesDirectoriesAreUpdated() throws Exception {

	// Find the project
	File baseDir = this.resources.getBasedir( "project--valid" );
	Assert.assertNotNull( baseDir );
	Assert.assertTrue( baseDir.exists());
	Assert.assertTrue( baseDir.isDirectory());

	File pom = new File( baseDir, "pom.xml" );
	InitializeMojo mojo = (InitializeMojo) this.rule.lookupMojo( "initialize", pom );
	Assert.assertNotNull( mojo );

	// Create the Maven project by hand (...)
	final MavenProject mvnProject = new MavenProject() ;
	mvnProject.setFile( pom ) ;
	this.rule.setVariableValueToObject( mojo, "project", mvnProject );
	Assert.assertNotNull( this.rule.getVariableValueFromObject( mojo, "project" ));

	// Execute the mojo
	List<Resource> list = mvnProject.getResources();
	Assert.assertEquals( 0, list.size());
	Assert.assertTrue( Utils.isEmptyOrWhitespaces( mvnProject.getBuild().getOutputDirectory()));

	mojo.execute();

	list = mvnProject.getResources();
	Assert.assertEquals( 2, list.size());

	Resource res = list.get( 0 );
	Assert.assertTrue( res.isFiltering());
	Assert.assertEquals( new File( baseDir, MavenPluginConstants.SOURCE_MODEL_DIRECTORY ).getAbsolutePath(), res.getDirectory());

	res = list.get( 1 );
	Assert.assertFalse( res.isFiltering());
	Assert.assertEquals( new File( baseDir, MavenPluginConstants.SOURCE_MODEL_DIRECTORY ).getAbsolutePath(), res.getDirectory());

	File expectedFile = new File( mvnProject.getBasedir(), MavenPluginConstants.TARGET_MODEL_DIRECTORY );
	Assert.assertEquals( expectedFile.getAbsolutePath(), mvnProject.getBuild().getOutputDirectory());
}