From ac353e20a492ab653eea6c876bd8560323dde607 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 10 May 2020 13:50:53 -0700 Subject: [PATCH 1/5] Use local config files if possible. --- .../main/java/com/diffplug/spotless/maven/FileLocator.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java index 22a93d80d7..0ce6637723 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java @@ -45,6 +45,11 @@ public File locateFile(String path) { return null; } + File testExists = new File(path); + if (testExists.exists() && testExists.isFile()) { + return testExists; + } + String outputFile = tmpOutputFileName(path); try { return resourceManager.getResourceAsFile(path, outputFile); From 540cc5c5ed000dac1eb8f9a2d6a94e37fe37ebb4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 30 May 2020 00:45:37 -0700 Subject: [PATCH 2/5] Improve javadoc and naming. --- .../java/com/diffplug/spotless/maven/FileLocator.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java index 0ce6637723..ffbe95d801 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java @@ -39,15 +39,18 @@ public FileLocator(ResourceManager resourceManager, File baseDir, File buildDir) this.buildDir = Objects.requireNonNull(buildDir); } - /** Asserts that the given path is a file, then copies it with a new random name into the build folder. */ + /** + * If the given path is a local file returns it as such unchanged, + * otherwise extracts the given resource to a randomly-named file in the build folder. + */ public File locateFile(String path) { if (isNullOrEmpty(path)) { return null; } - File testExists = new File(path); - if (testExists.exists() && testExists.isFile()) { - return testExists; + File localFile = new File(path); + if (localFile.exists() && localFile.isFile()) { + return localFile; } String outputFile = tmpOutputFileName(path); From 0660b8270547e57d510eee686e5c8a92f699f86d Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 30 May 2020 00:48:14 -0700 Subject: [PATCH 3/5] There is no longer a need for FileLocator.locateLocal() --- .../com/diffplug/spotless/maven/FileLocator.java | 14 -------------- .../diffplug/spotless/maven/generic/Prettier.java | 4 ++-- .../diffplug/spotless/maven/typescript/Tsfmt.java | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java index ffbe95d801..b6d3490944 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/FileLocator.java @@ -68,20 +68,6 @@ private static String tmpOutputFileName(String path) { return TMP_RESOURCE_FILE_PREFIX + UUID.randomUUID() + '.' + extension; } - /** Asserts that the given path exists as a file or folder. */ - public File locateLocal(String path) { - if (isNullOrEmpty(path)) { - return null; - } - - File exists = new File(path); - if (exists.exists()) { - return exists; - } - - throw new RuntimeException("Unable to locate file with path: " + path); - } - public File getBaseDir() { return baseDir; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java index a82fcb8b83..7c2e12eea5 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/generic/Prettier.java @@ -61,12 +61,12 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { } } - File npm = npmExecutable != null ? stepConfig.getFileLocator().locateLocal(npmExecutable) : null; + File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; // process config file or inline config File configFileHandler; if (this.configFile != null) { - configFileHandler = stepConfig.getFileLocator().locateLocal(this.configFile); + configFileHandler = stepConfig.getFileLocator().locateFile(this.configFile); } else { configFileHandler = null; } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java index c57350c145..3291a26c41 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java @@ -70,7 +70,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { devDependencies.put("tslint", tslintVersion); } - File npm = npmExecutable != null ? stepConfig.getFileLocator().locateLocal(npmExecutable) : null; + File npm = npmExecutable != null ? stepConfig.getFileLocator().locateFile(npmExecutable) : null; TypedTsFmtConfigFile configFile; Map configInline; From ae83fd10237be78ba6b63076d5d8e15e4921adfb Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 30 May 2020 00:52:23 -0700 Subject: [PATCH 4/5] Update changelog. --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index cc53a6ee9b..6568d22052 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* If you specified a config file for a formatter, it used to be needlessly copied to a randomly-named file in the build folder. This could cause performance to suffer, especially for [large multi-project builds that use eclipse](https://github.com/diffplug/spotless/issues/559). ([#572](https://github.com/diffplug/spotless/pull/572)) ## [1.31.0] - 2020-05-05 ### Added From cf35e3aa2d5951f31501b079d2a0525f787340fc Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 30 May 2020 00:57:12 -0700 Subject: [PATCH 5/5] Oops, missed a spot. --- .../com/diffplug/spotless/maven/typescript/Tsfmt.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java index 3291a26c41..faea03f2a0 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Tsfmt.java @@ -84,13 +84,13 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { } configInline = null; if (this.tsconfigFile != null) { - configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSCONFIG, stepConfig.getFileLocator().locateLocal(tsconfigFile)); + configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSCONFIG, stepConfig.getFileLocator().locateFile(tsconfigFile)); } else if (this.tsfmtFile != null) { - configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSFMT, stepConfig.getFileLocator().locateLocal(tsfmtFile)); + configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSFMT, stepConfig.getFileLocator().locateFile(tsfmtFile)); } else if (this.tslintFile != null) { - configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSLINT, stepConfig.getFileLocator().locateLocal(tslintFile)); + configFile = new TypedTsFmtConfigFile(TsConfigFileType.TSLINT, stepConfig.getFileLocator().locateFile(tslintFile)); } else if (this.vscodeFile != null) { - configFile = new TypedTsFmtConfigFile(TsConfigFileType.VSCODE, stepConfig.getFileLocator().locateLocal(vscodeFile)); + configFile = new TypedTsFmtConfigFile(TsConfigFileType.VSCODE, stepConfig.getFileLocator().locateFile(vscodeFile)); } else { throw new Error("Programming error: the xors did not match the cases"); }