Skip to content

Commit

Permalink
refactor: Fix Sonar violations
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jan 26, 2024
1 parent 375467e commit 3d9930b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
22 changes: 11 additions & 11 deletions api/jreleaser-utils/src/main/java/org/jreleaser/util/FileUtils.java
Expand Up @@ -260,7 +260,7 @@ private static void tar(Path src, TarArchiveOutputStream out, ArchiveOptions opt
for (Path path : paths) {
String entryName = src.relativize(path).toString();
File inputFile = path.toFile();
TarArchiveEntry archiveEntry = (TarArchiveEntry) out.createArchiveEntry(inputFile, entryName);
TarArchiveEntry archiveEntry = out.createArchiveEntry(inputFile, entryName);
if (null != fileTime) archiveEntry.setModTime(fileTime);

if (inputFile.isFile() && Files.isExecutable(path)) {
Expand Down Expand Up @@ -416,7 +416,7 @@ public static void unpackArchive(Path src, Path dest, boolean removeRootEntry, b

try (InputStream fi = Files.newInputStream(src);
InputStream bi = new BufferedInputStream(fi);
ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(bi)) {
ArchiveInputStream<?> in = new ArchiveStreamFactory().createArchiveInputStream(bi)) {

unpackArchive(removeRootEntry ? rootEntryName + "/" : "", destinationDir, in);
} catch (ArchiveException e) {
Expand Down Expand Up @@ -446,7 +446,7 @@ public static void unpackArchiveCompressed(Path src, Path dest, boolean removeRo
try (InputStream fi = Files.newInputStream(src);
InputStream bi = new BufferedInputStream(fi);
InputStream gzi = resolveCompressorInputStream(fileType, bi);
ArchiveInputStream in = new TarArchiveInputStream(gzi)) {
ArchiveInputStream<?> in = new TarArchiveInputStream(gzi)) {
unpackArchive(removeRootEntry ? rootEntryName + "/" : "", destinationDir, in);
}
}
Expand All @@ -472,7 +472,7 @@ private static InputStream resolveCompressorInputStream(FileType fileType, Input
return null;
}

private static void unpackArchive(String basename, File destinationDir, ArchiveInputStream in) throws IOException {
private static void unpackArchive(String basename, File destinationDir, ArchiveInputStream<?> in) throws IOException {
ArchiveEntry entry = null;
while (null != (entry = in.getNextEntry())) {
if (!in.canReadEntryData(entry)) {
Expand Down Expand Up @@ -568,7 +568,7 @@ private static boolean isSymbolicLink(ArchiveEntry entry) {
return false;
}

private static String getLinkName(ArchiveInputStream in, ArchiveEntry entry) throws IOException {
private static String getLinkName(ArchiveInputStream<?> in, ArchiveEntry entry) throws IOException {
if (entry instanceof ZipArchiveEntry) {
try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
IOUtils.copy(in, o);
Expand Down Expand Up @@ -672,7 +672,7 @@ public static List<String> inspectArchive(Path src) throws IOException {

try (InputStream fi = Files.newInputStream(src);
InputStream bi = new BufferedInputStream(fi);
ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(bi)) {
ArchiveInputStream<?> in = new ArchiveStreamFactory().createArchiveInputStream(bi)) {
return inspectArchive(in);
} catch (ArchiveException e) {
throw new IOException(e.getMessage(), e);
Expand All @@ -691,7 +691,7 @@ public static String resolveRootEntryName(Path src) {
if (filename.endsWith(ZIP.extension()) || filename.endsWith(TAR.extension())) {
try (InputStream fi = Files.newInputStream(src);
InputStream bi = new BufferedInputStream(fi);
ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(bi)) {
ArchiveInputStream<?> in = new ArchiveStreamFactory().createArchiveInputStream(bi)) {
return resolveRootEntryName(in);
} catch (ArchiveException e) {
throw new IOException(e.getMessage(), e);
Expand All @@ -713,12 +713,12 @@ public static String resolveRootEntryNameCompressed(Path src) throws IOException
try (InputStream fi = Files.newInputStream(src);
InputStream bi = new BufferedInputStream(fi);
InputStream gzi = resolveCompressorInputStream(fileType, bi);
ArchiveInputStream in = new TarArchiveInputStream(gzi)) {
ArchiveInputStream<?> in = new TarArchiveInputStream(gzi)) {
return resolveRootEntryName(in);
}
}

private static String resolveRootEntryName(ArchiveInputStream in) throws IOException {
private static String resolveRootEntryName(ArchiveInputStream<?> in) throws IOException {
ArchiveEntry entry = null;
while (null != (entry = in.getNextEntry())) {
if (!in.canReadEntryData(entry)) {
Expand Down Expand Up @@ -781,12 +781,12 @@ public static List<String> inspectArchiveCompressed(Path src) throws IOException
try (InputStream fi = Files.newInputStream(src);
InputStream bi = new BufferedInputStream(fi);
InputStream gzi = resolveCompressorInputStream(fileType, bi);
ArchiveInputStream in = new TarArchiveInputStream(gzi)) {
ArchiveInputStream<?> in = new TarArchiveInputStream(gzi)) {
return inspectArchive(in);
}
}

private static List<String> inspectArchive(ArchiveInputStream in) throws IOException {
private static List<String> inspectArchive(ArchiveInputStream<?> in) throws IOException {
List<String> entries = new ArrayList<>();

ArchiveEntry entry = null;
Expand Down
Expand Up @@ -40,11 +40,13 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -127,7 +129,7 @@ private static void addPayload(JReleaserContext context, SoftwareIdentity softwa

private static class FileTagger implements FileVisitor<Path> {
private final JReleaserLogger logger;
private final Stack<Directory> directories = new Stack<>();
private final Deque<Directory> directories = new ArrayDeque<>();
private Directory root = new Directory();
private boolean success = true;

Expand Down Expand Up @@ -178,7 +180,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO

@Override
public FileVisitResult visitFileFailed(Path file, IOException e) throws IOException {
e.printStackTrace();
if (e instanceof FileSystemLoopException) {
logger.error(RB.$("ERROR_files_cycle"), file);
} else {
Expand Down Expand Up @@ -339,6 +340,19 @@ public void setRole(String role) {
public int compareTo(Entity o) {
return Comparator.comparing(Entity::getName).compare(this, o);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Entity entity = (Entity) o;
return name.equals(entity.name);
}

@Override
public int hashCode() {
return Objects.hash(name);
}
}

public static abstract class ResourceCollection {
Expand Down

0 comments on commit 3d9930b

Please sign in to comment.