protected boolean copyFile()

in src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java [301:334]


    protected boolean copyFile(
            WarPackagingContext context, File source, File destination, String targetFilename, boolean onlyIfModified)
            throws IOException {
        context.addResource(targetFilename);

        BasicFileAttributes readAttributes = Files.readAttributes(source.toPath(), BasicFileAttributes.class);
        if (onlyIfModified
                && destination.lastModified()
                        >= readAttributes.lastModifiedTime().toMillis()) {
            context.getLog().debug(" * " + targetFilename + " is up to date.");
            return false;
        } else {
            if (readAttributes.isDirectory()) {
                context.getLog().warn(" + " + targetFilename + " is packaged from the source folder");

                try {
                    JarArchiver archiver = context.getJarArchiver();
                    archiver.addDirectory(source);
                    archiver.setDestFile(destination);
                    archiver.createArchive();
                } catch (ArchiverException e) {
                    String msg = "Failed to create " + targetFilename;
                    context.getLog().error(msg, e);
                    throw new IOException(msg, e);
                }
            } else {
                FileUtils.copyFile(source.getCanonicalFile(), destination);
                // preserve timestamp
                destination.setLastModified(readAttributes.lastModifiedTime().toMillis());
                context.getLog().debug(" + " + targetFilename + " has been copied.");
            }
            return true;
        }
    }