Skip to content

Commit

Permalink
Merge pull request #2 from techpavan/issue#1-fix
Browse files Browse the repository at this point in the history
Fix for issue #1. Non-latest versions can now be retained
  • Loading branch information
techpavan authored Jun 3, 2018
2 parents 548d0e1 + bbb9dfb commit a1a313f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ appropriate switches as provided below.
Comma separated list of groupIds (full or part) to be ignored.
--path, -p
Path to m2 directory, if using a custom path.
--retainOld, -ro
Retain the artifacts even if old versions. Only process the configured inputs.
Default: false

Feel free to raise any issues or recommend any changes or improvements.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.github.techpavan</groupId>
<artifactId>mvn-repo-cleaner</artifactId>
<version>1.0</version>
<version>1.0.1</version>

<dependencies>
<dependency>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/github/techpavan/maven/ArgData.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.commons.lang3.time.DateUtils;

import java.text.ParseException;
import java.util.Arrays;
import java.util.List;

@Data
Expand Down Expand Up @@ -51,6 +50,9 @@ public class ArgData {
@Parameter(names = {"--dryrun", "-dr"}, description = "Do not delete files, just simulate and print result.")
private boolean dryRun;

@Parameter(names = {"--retainOld", "-ro"}, description = "Retain the artifacts even if old versions. Only process the configured inputs.")
private boolean retainOld;

static class DateToMillisConverter implements IStringConverter<Long> {

@Override
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/github/techpavan/maven/CleanM2.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class CleanM2 {
SKIP_MAP.put(SkipReason.RESERVED, new HashSet<>());
SKIP_MAP.put(SkipReason.IGNORED_ARTIFACT, new HashSet<>());
SKIP_MAP.put(SkipReason.IGNORED_GROUP, new HashSet<>());
SKIP_MAP.put(SkipReason.RETAIN_OLD, new HashSet<>());
SKIP_MAP.put(SkipReason.LATEST, new HashSet<>());
}

Expand Down Expand Up @@ -157,6 +158,10 @@ private static void parseAndEvaluate(File file) {
DELETE_MAP.get(DeleteReason.DOWNLOAD_DATE).add(file.getParentFile());
return;
}
if (argData.isRetainOld()) {
SKIP_MAP.get(SkipReason.RETAIN_OLD).add(file.getParentFile().getAbsolutePath());
return;
}
// When none of the above are matched, add it for latest / oldest processing
addToProcessMap(fileInfo);
} catch (IOException e) {
Expand Down Expand Up @@ -199,7 +204,6 @@ private static FileInfo createFileInfo(File file) {
fileInfo.setFile(file);
fileInfo.setArtifactId(findArtifactId(file));
fileInfo.setGroupId(findGroupId(file, fileInfo.getArtifactId()));
String gaId = fileInfo.getGroupId() + ":" + fileInfo.getArtifactId();
fileInfo.setVersion(findVersion(file));
return fileInfo;
}
Expand Down Expand Up @@ -240,7 +244,7 @@ private enum DeleteReason {
}

private enum SkipReason {
IGNORED_ARTIFACT, IGNORED_GROUP, LATEST, RESERVED
IGNORED_ARTIFACT, IGNORED_GROUP, LATEST, RESERVED, RETAIN_OLD
}

}

0 comments on commit a1a313f

Please sign in to comment.