protected void copyFile()

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


    protected void copyFile(String sourceId, final WarPackagingContext context, final File file, String targetFilename)
            throws IOException
                // CHECKSTYLE_ON: LineLength
            {
        final File targetFile = new File(context.getWebappDirectory(), targetFilename);

        if (file.isFile()) {
            context.getWebappStructure()
                    .registerFile(sourceId, targetFilename, new WebappStructure.RegistrationCallback() {
                        public void registered(String ownerId, String targetFilename) throws IOException {
                            copyFile(context, file, targetFile, targetFilename, false);
                        }

                        public void alreadyRegistered(String ownerId, String targetFilename) throws IOException {
                            copyFile(context, file, targetFile, targetFilename, true);
                        }

                        public void refused(String ownerId, String targetFilename, String actualOwnerId)
                                throws IOException {
                            context.getLog()
                                    .debug(" - "
                                            + targetFilename
                                            + " wasn't copied because it has "
                                            + "already been packaged for overlay ["
                                            + actualOwnerId + "].");
                        }

                        public void superseded(String ownerId, String targetFilename, String deprecatedOwnerId)
                                throws IOException {
                            context.getLog()
                                    .info("File ["
                                            + targetFilename
                                            + "] belonged to overlay ["
                                            + deprecatedOwnerId
                                            + "] so it will be overwritten.");
                            copyFile(context, file, targetFile, targetFilename, false);
                        }

                        public void supersededUnknownOwner(String ownerId, String targetFilename, String unknownOwnerId)
                                throws IOException {
                            // CHECKSTYLE_OFF: LineLength
                            context.getLog()
                                    .warn("File ["
                                            + targetFilename
                                            + "] belonged to overlay ["
                                            + unknownOwnerId
                                            + "] which does not exist anymore in the current project. It is recommended to invoke "
                                            + "clean if the dependencies of the project changed.");
                            // CHECKSTYLE_ON: LineLength
                            copyFile(context, file, targetFile, targetFilename, false);
                        }
                    });
        } else if (!targetFile.exists() && !targetFile.mkdirs()) {
            context.getLog().info("Failed to create directory " + targetFile.getAbsolutePath());
        }
    }