diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java index 46eb4c0b..3a531d43 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.net.URL; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -383,7 +384,12 @@ private Collection generateFile(RoleFile roleFile, String File file = new File(nodeDir, dir != null ? FilenameUtils.concat(dir, generatedFileName) : generatedFileName); if (file.exists()) { - file.delete(); + try { + Files.delete(file.toPath()); + } + catch (IOException ex) { + throw new GeneratorException("Unable to delete: " + FileUtil.getCanonicalPath(file), ex); + } } FileGenerator fileGenerator = new FileGenerator(options, environmentName, diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java index 81bcaf8c..0434b48d 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java @@ -20,6 +20,7 @@ package io.wcm.devops.conga.generator.plugins.fileheader; import java.io.IOException; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -68,7 +69,7 @@ public final Void apply(FileContext file, FileHeaderContext context) { + StringUtils.defaultString(getBlockSuffix()) + StringUtils.substring(content, insertPosition); - file.getFile().delete(); + Files.delete(file.getFile().toPath()); FileUtils.write(file.getFile(), content, file.getCharset()); } catch (IOException ex) { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java index 9a3746fc..40b9bac8 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.file.Files; import org.apache.commons.lang3.StringUtils; @@ -90,7 +91,7 @@ public void deleteFile(String url, UrlFilePluginContext context) throws IOExcept if (!file.exists()) { throw new FileNotFoundException("File does not exist: " + FileUtil.getCanonicalPath(file)); } - file.delete(); + Files.delete(file.toPath()); } private static File getFileInternal(String url, UrlFilePluginContext context) { diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java index d8662854..94c804e0 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java @@ -30,6 +30,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -345,7 +346,7 @@ private void copyDefinitions(ResourceCollection sourceDir, File rootOutputDir, F getLog().info("Include " + getPathForLog(rootOutputDir, targetFile)); if (targetFile.exists()) { - targetFile.delete(); + Files.delete(targetFile.toPath()); } try (InputStream is = file.getInputStream()) { byte[] data = IOUtils.toByteArray(is); diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/GenerateVersionInfoMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/GenerateVersionInfoMojo.java index f30e47dd..fe5a8c26 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/GenerateVersionInfoMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/GenerateVersionInfoMojo.java @@ -23,6 +23,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.Files; import java.util.Properties; import org.apache.maven.plugin.AbstractMojo; @@ -64,7 +65,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { File propsFile = new File(outputDir, BuildConstants.FILE_VERSION_INFO); if (propsFile.exists()) { - propsFile.delete(); + try { + Files.delete(propsFile.toPath()); + } + catch (IOException ex) { + throw new MojoExecutionException("Unable to delete file: " + FileUtil.getCanonicalPath(propsFile), ex); + } } Properties versionInfo = VersionInfoUtil.getVersionInfoProperties(project); try (OutputStream os = new FileOutputStream(propsFile)) {