Skip to content

Commit

Permalink
Skip unpacked & asc files
Browse files Browse the repository at this point in the history
Pull some of the fixes from https://github.com/fzakaria/mvn2nix/pull/19/files
which skip asc & unpacked files.
  • Loading branch information
fzakaria committed Aug 28, 2020
1 parent 36cfbf4 commit 5ae4f60
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/com/fzakaria/mvn2nix/maven/Maven.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -125,13 +126,24 @@ public Collection<Artifact> collectAllArtifactsInLocalRepository() {
.filter(f -> !f.toFile().getName().equals("_remote.repositories"))
.filter(f -> !f.toFile().getName().equals("resolver-status.properties"))
.filter(f -> !f.toFile().getName().endsWith("lastUpdated"))
.filter(f -> !f.toFile().getName().endsWith("asc"))
.filter(f -> !f.toFile().getName().endsWith("unpacked"))
.map(file -> {
Path layout = localRepository.toPath().relativize(file);

String extension = com.google.common.io.Files.getFileExtension(layout.toString());
String nameAndVersionAndClassifier = com.google.common.io.Files.getNameWithoutExtension(layout.toFile().getName());
String version = layout.getParent().toFile().getName();
String name = layout.getParent().getParent().toFile().getName();

/*
* This is an easy safeguard to make sure we only capture correct artifacts regardless
* of the extension. The artifact must follow the pattern ${name}-${version} at the very least
*/
if (!(nameAndVersionAndClassifier.contains(name) && nameAndVersionAndClassifier.contains(version))) {
return null;
}

String classifier = nameAndVersionAndClassifier
.replaceAll(name + "-" + version, "")
.replaceFirst("^-", "");
Expand All @@ -147,7 +159,9 @@ public Collection<Artifact> collectAllArtifactsInLocalRepository() {
.setVersion(version)
.setExtension(extension)
.build();
}).collect(Collectors.toList());
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down

0 comments on commit 5ae4f60

Please sign in to comment.