From a3b9f963e63351f90bbcd3a43dd0085f579b9c99 Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Thu, 2 Feb 2023 16:13:39 +0100 Subject: [PATCH] Add Delombok option to keep full path within output directory --- src/delombok/lombok/delombok/Delombok.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index e4f1760222..e64ad1e2e8 100755 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -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; @@ -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; } @@ -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); @@ -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. " + @@ -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());