Skip to content

Commit

Permalink
Add Delombok option to keep full path within output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasvajk committed Feb 7, 2023
1 parent e5c324c commit a3b9f96
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/delombok/lombok/delombok/Delombok.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void setWriter(Writer writer) {
private boolean verbose;
private boolean noCopy;
private boolean onlyChanged;
private boolean keepPathInTargetDirectory = false;
private boolean force = false;
private boolean disablePreview;
private String classpath, sourcepath, bootclasspath, modulepath;
Expand Down Expand Up @@ -169,6 +170,10 @@ private static class CmdArgs {
@FullName("disable-preview")
private boolean disablePreview;

@Description("By default input files are delomboked directly to the target directory, which means files with the same name get overwritten. With this option, the target directory is kept as a prefix in the output file paths.")
@FullName("target-keep-path")
private boolean keepPathInTargetDirectory;

private boolean help;
}

Expand Down Expand Up @@ -302,6 +307,7 @@ public static void main(String[] rawArgs) {
delombok.setOutputToStandardOut();
} else {
delombok.setOutput(new File(args.target));
if (args.keepPathInTargetDirectory) delombok.setKeepPathInTargetDirectory(true);
}

if (args.classpath != null) delombok.setClasspath(args.classpath);
Expand Down Expand Up @@ -544,6 +550,10 @@ public void setOnlyChanged(boolean onlyChanged) {
this.onlyChanged = onlyChanged;
}

public void setKeepPathInTargetDirectory(boolean keepPathInTargetDirectory) {
this.keepPathInTargetDirectory = keepPathInTargetDirectory;
}

public void setOutput(File dir) {
if (dir.isFile() || (!dir.isDirectory() && dir.getName().endsWith(".java"))) throw new IllegalArgumentException(
"DELOMBOK: delombok will only write to a directory. " +
Expand Down Expand Up @@ -907,7 +917,9 @@ private Writer createFileWriter(File outBase, File inBase, URI file) throws IOEx
URI base = inBase.toURI();
URI relative = base.relativize(base.resolve(file));
File outFile;
if (relative.isAbsolute()) {
if (keepPathInTargetDirectory) {
outFile = new File(outBase, file.getPath().replace(":", ""));
} else if (relative.isAbsolute()) {
outFile = new File(outBase, new File(relative).getName());
} else {
outFile = new File(outBase, relative.getPath());
Expand Down

0 comments on commit a3b9f96

Please sign in to comment.