Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Delombok option to keep full path within output directory #3343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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