Skip to content

Make plugin-maven use local config files if possible #572

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

Merged
merged 6 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
### Fixed
* Shared library used by the nodejs-based steps used to be extracted into the user home directory, but now it is extracted into a temporary directory and deleted on VM shutdown. ([#586](https://github.com/diffplug/spotless/pull/586))
* 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))
* Note: if you are extracting config files from resource jars, we still have bad performance for this case, see [#559](https://github.com/diffplug/spotless/issues/559) for details.

## [1.31.1] - 2020-05-21
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ 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 localFile = new File(path);
if (localFile.exists() && localFile.isFile()) {
return localFile;
}

String outputFile = tmpOutputFileName(path);
try {
return resourceManager.getResourceAsFile(path, outputFile);
Expand All @@ -60,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> configInline;
Expand All @@ -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");
}
Expand Down