Java Code Examples for org.apache.maven.model.Resource#getIncludes()

The following examples show how to use org.apache.maven.model.Resource#getIncludes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsciidoctorFileScanner.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example 2
Source File: JarMojo.java    From helidon-build-tools with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: OthersRootChildren.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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()));
     }
}
 
Example 4
Source File: GraalNativeMojo.java    From helidon-build-tools with Apache License 2.0 4 votes vote down vote up
/**
 * Scan for project resources and produce a comma separated list of include
 * resources.
 * @return String as comma separated list
 */
private String getResources() {
    // scan all resources
    getLog().debug("Building resources string");
    List<String> resources = new ArrayList<>();

    if (addProjectResources) {
        getLog().debug("Scanning project resources");
        for (Resource resource : project.getResources()) {
            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);
            }
        }
    }

    // add additional resources
    if (includeResources != null) {
        getLog().debug("Adding provided resources: " + includeResources);
        resources.addAll(includeResources);
    }

    // comma separated list
    StringBuilder sb = new StringBuilder();
    Iterator<String> it = resources.iterator();
    while (it.hasNext()) {
        sb.append(it.next());
        if (it.hasNext()) {
            sb.append("|");
        }
    }
    String resourcesStr = sb.toString();
    getLog().debug("Built resources string: " + resourcesStr);
    return resourcesStr;
}
 
Example 5
Source File: CopyResourcesOnSave.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Tuple findResource(List<Resource> resources, Project prj, NbMavenProject nbproj, FileObject child, boolean test) {
    LOG.log(Level.FINE, "findResource for {0}", child.getPath());        
    if (resources == null) {
        LOG.log(Level.FINE, "findResource for {0} : No Resources", child.getPath());
        return null;
    }
    FileObject target;
    //now figure the destination output folder
    File fil = nbproj.getOutputDirectory(test);
    File stamp = new File(fil, CosChecker.NB_COS);
    if (stamp.exists()) {
        target = FileUtil.toFileObject(fil);
    } else {
        LOG.log(Level.FINE, "findResource for {0} : No Stamp", child.getPath());
        // no compile on save stamp, means no copying, classes don't get copied/compiled either.
        return null;
    }
    
    logResources(child, resources);

    resourceLoop:
    for (Resource res : resources) {
        String dir = res.getDirectory();
        if (dir == null) {
            continue;
        }
        URI uri = FileUtilities.getDirURI(prj.getProjectDirectory(), dir);
        FileObject fo = FileUtil.toFileObject(Utilities.toFile(uri));
        if (fo != null && FileUtil.isParentOf(fo, child)) {
            String path = FileUtil.getRelativePath(fo, child);
            //now check includes and excludes
            List<String> incls = res.getIncludes();
            if (incls.isEmpty()) {
                incls = Arrays.asList(FilteredResourcesCoSSkipper.DEFAULT_INCLUDES);
            }
            boolean included = false;
            for (String incl : incls) {
                if (DirectoryScanner.match(incl, path)) {
                    included = true;
                    break;
                }
            }
            if (!included) {
                LOG.log(Level.FINE, "findResource for {0} : Not included {1}, {2} ", new Object[] {child.getPath(), included, res});
                if(res.isFiltering()) {
                    continue;
                } else {
                    break; 
                }
            }
            List<String> excls = new ArrayList<String>(res.getExcludes());
            excls.addAll(Arrays.asList(DirectoryScanner.DEFAULTEXCLUDES));
            for (String excl : excls) {
                if (DirectoryScanner.match(excl, path)) {
                    LOG.log(Level.FINER, "findResource for {0} : Excluded {1}, {2} ", new Object[] {child.getPath(), included, res});
                    continue resourceLoop;
                }
            }
            LOG.log(Level.FINE, "findResource for {0} : Returns {1}, {2}, {3} ", new Object[] {child.getPath(), res, fo.getPath(), target});
            return new Tuple(res, fo, target);
        } else {
            LOG.log(Level.FINE, "findResource {0} does not apply to file {1}", new Object[]{res, child.getPath()});
        }
    }
    LOG.log(Level.FINE, "findResource for {0} : Retuerns Null", child.getPath());
    return null;
}