[PATCH]: Still a problem with long classpath on Windows

Basil Peace grv87 at yandex.ru
Thu Feb 28 06:19:13 UTC 2019


Hi, Aleksey!

Could you take a look at the proposed patch?

-- 
Best regards,
Basil Peace


09.02.2019, 06:46, "Basil Peace" <grv87 at yandex.ru>:
>>   a) Sign the OCA, as per http://openjdk.java.net/contribute/
>
> Done.
>
>>   b) Put the patch somewhere on OpenJDK infra. Posting the simple patch in-line in this message would
>>  be good enough.
>
> Improved patch, using URI for percent encoding:
>
> # HG changeset patch
> # User Basil Peace <grv87 at yandex.ru>
> # Date 1549196743 -10800
> # Sun Feb 03 15:25:43 2019 +0300
> # Branch hotfix/long-classpath-absolute.v2
> # Node ID fba2e675a44b2b8aaee3fd63aefe926e17fac945
> # Parent 5984e353dca775da0e2208ddaed8427cd9a43acd
> fix: fix long classpath issue on Windows with different drives
>
> diff -r 5984e353dca7 -r fba2e675a44b jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
> --- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java Tue Jan 22 16:22:44 2019 +0100
> +++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java Sun Feb 03 15:25:43 2019 +0300
> @@ -42,10 +42,13 @@
>
>  import java.io.*;
>  import java.lang.management.ManagementFactory;
> +import java.net.URI;
> +import java.net.URISyntaxException;
>  import java.nio.channels.FileChannel;
>  import java.nio.channels.FileLock;
>  import java.nio.channels.OverlappingFileLockException;
>  import java.nio.file.Path;
> +import java.nio.file.Paths;
>  import java.util.*;
>  import java.util.concurrent.TimeUnit;
>  import java.util.jar.*;
> @@ -873,14 +876,25 @@
>              try {
>                  tmpFile = FileUtils.tempFile("classpath.jar");
>                  Path tmpFileDir = tmpFile.toPath().getParent();
> + String tmpFileRoot = tmpFileDir.toAbsolutePath().getRoot().toString();
>
>                  StringBuilder sb = new StringBuilder();
>                  for (String cp : cpProp.split(File.pathSeparator)) {
> - String rel = tmpFileDir.relativize(new File(cp).getAbsoluteFile().toPath()).toString();
> - sb.append(rel.replace('\\', '/').replace(" ", "%20"));
> - if (!cp.endsWith(".jar")) {
> - sb.append('/');
> + Path cpPath = Paths.get(cp).toAbsolutePath();
> + URI cpUri;
> + if (cpPath.getRoot().toString().equalsIgnoreCase(tmpFileRoot)) {
> + String rel = tmpFileDir.relativize(cpPath).toString();
> + if (File.separatorChar != '/') {
> + rel = rel.replace(File.separatorChar, '/');
> + }
> + if (!rel.endsWith(".jar")) {
> + rel = rel + '/';
> + }
> + cpUri = new URI(null, rel, null);
> + } else {
> + cpUri = cpPath.toUri();
>                      }
> + sb.append(cpUri.toString());
>                      sb.append(" ");
>                  }
>                  String classPath = sb.toString().trim();
> @@ -893,8 +907,10 @@
>                  try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(tmpFile), manifest)) {
>                      jos.putNextEntry(new ZipEntry("META-INF/"));
>                  }
> - } catch (IOException ex) {
> - // Something is wrong in file generation, give up and fall-through to usual thing
> + } catch (IOException | URISyntaxException ex) {
> + out.println("<failed to generate separate classpath JAR, caught " + ex.getClass().getSimpleName() + ": " + ex.getMessage() + ">");
> + out.println("<giving up and fall-through to usual thing>");
> + out.println("");
>                  tmpFile = null;
>              }
>          }
>
> --
> Best regards,
> Basil Peace


More information about the jmh-dev mailing list