protected boolean copyResourceIfExists()

in src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java [614:664]


    protected boolean copyResourceIfExists(
            File outputFile, String bundleResourceName, VelocityContext context, String encoding)
            throws IOException, MojoExecutionException {
        for (Resource resource : project.getResources()) {
            File resourceDirectory = new File(resource.getDirectory());

            if (!resourceDirectory.exists()) {
                continue;
            }

            // TODO - really should use the resource includes/excludes and name mapping
            File source = new File(resourceDirectory, bundleResourceName);
            File templateSource = new File(resourceDirectory, bundleResourceName + TEMPLATE_SUFFIX);

            if (!source.exists() && templateSource.exists()) {
                source = templateSource;
            }

            if (source.exists() && !source.equals(outputFile)) {
                if (source == templateSource) {
                    getLog().debug("Use project resource '" + source + "' as resource with Velocity");
                    try (CachingOutputStream os = new CachingOutputStream(outputFile);
                            Writer writer = getWriter(encoding, os);
                            Reader reader = getReader(encoding, source)) {
                        velocity.evaluate(context, writer, "", reader);
                    } catch (ParseErrorException | MethodInvocationException | ResourceNotFoundException e) {
                        throw new MojoExecutionException("Error rendering velocity resource: " + source, e);
                    }
                } else if (resource.isFiltering()) {
                    getLog().debug("Use project resource '" + source + "' as resource with filtering");

                    MavenFileFilterRequest req = setupRequest(resource, source, outputFile);

                    try {
                        fileFilter.copyFile(req);
                    } catch (MavenFilteringException e) {
                        throw new MojoExecutionException("Error filtering resource: " + source, e);
                    }
                } else {
                    getLog().debug("Use project resource '" + source + "' as resource");
                    FilteringUtils.copyFile(source, outputFile, null, null);
                }

                // exclude the original (so eclipse doesn't complain about duplicate resources)
                resource.addExclude(bundleResourceName);

                return true;
            }
        }
        return false;
    }