Skip to content

Commit

Permalink
Eliminate SonarQube warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 22, 2024
1 parent 5d5a6f0 commit 5db961f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -383,7 +384,12 @@ private Collection<GeneratedFileContext> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 5db961f

Please sign in to comment.