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

Using URI instead of URL for file lookup #405

Merged
merged 3 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion _ext/eclipse-base/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# spotless-eclipse-base

### Version 3.2.0 - TBD
### Version 3.1.1 - TBD
* Fixed problem handling URL escaped characters in JAR file location. ([#401](https://github.com/diffplug/spotless/issues/401))

### Version 3.1.0 - February 10th 2019 ([artifact]([jcenter](https://bintray.com/diffplug/opensource/spotless-eclipse-base)))

Expand Down
2 changes: 1 addition & 1 deletion _ext/eclipse-base/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Mayor versions correspond to the supported Eclipse core version.
# Minor version is incremented for features or incompatible changes (including changes to supported dependency versions).
# Patch version is incremented for backward compatible patches of this library.
ext_version=3.2.0
ext_version=3.1.1
ext_artifactId=spotless-eclipse-base
ext_description=Eclipse bundle controller and services for Spotless

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -69,10 +71,10 @@ class ResourceAccessor {
}

private static BundleFile getBundlFile(Class<?> clazz) throws BundleException {
URL objUrl = clazz.getProtectionDomain().getCodeSource().getLocation();
File jarOrDirectory = new File(objUrl.getPath());
URI objUri = getBundleUri(clazz);
File jarOrDirectory = new File(objUri.getPath());
if (!(jarOrDirectory.exists() && jarOrDirectory.canRead())) {
throw new BundleException(String.format("Path '%s' for '%s' is not accessible exist on local file system.", objUrl, clazz.getName()), BundleException.READ_ERROR);
throw new BundleException(String.format("Path '%s' for '%s' is not accessible exist on local file system.", objUri, clazz.getName()), BundleException.READ_ERROR);
}
try {
return jarOrDirectory.isDirectory() ? new DirBundleFile(jarOrDirectory, false) : new ZipBundleFile(jarOrDirectory, null, null, null);
Expand All @@ -81,6 +83,15 @@ private static BundleFile getBundlFile(Class<?> clazz) throws BundleException {
}
}

private static URI getBundleUri(Class<?> clazz) throws BundleException {
URL objUrl = clazz.getProtectionDomain().getCodeSource().getLocation();
try {
return objUrl.toURI();
} catch (URISyntaxException e) {
throw new BundleException(String.format("Path '%s' for '%s' is invalid.", objUrl, clazz.getName()), BundleException.READ_ERROR, e);
}
}

/** Get the manifest name from the resources. */
String getManifestName() throws BundleException {
URL manifestUrl = getEntry(JarFile.MANIFEST_NAME);
Expand Down