On Mon, 21 Nov 2022 15:40:19 GMT, Christian Stein <cst...@openjdk.org> wrote:

> This PR copies the `CommandLine.java` file from module `jdk.compiler` 
> (package `com.sun.tools.javac.main`) into the `jdk.internal.opt` module, 
> creating a new package with name `jdk.internal.opt`. That new 
> `jdk.internal.opt` package is then exported to the following modules:
> - `jdk.jartool`
> - `jdk.jlink`
> - `jdk.jpackage`
> 
> Now, `jar`, `jlink`, and `jpackage` use a shared `CommandLine` class. In a 
> future commit (presumable for JDK 21)  the original `CommandLine.java` file 
> in `jdk.compiler` can and will be replaced with this new one in 
> `jdk.internal.opt`. Same goes for the `jdk.javadoc` module.
> 
> - [x] Keep `CommandLine.java` in `jdk.compiler` module for the time being due 
> to "JDK N-1 rule".
> - [x] Keep `CommandLine.java` in `jdk.javadoc` module for the time being due 
> to "JDK N-1 rule".
> - [x] Remove `CommandLine.java` from `jdk.jartool` module
> - [x] Remove `CommandLine.java` from `jdk.jlink` module
> - [x] Remove `CommandLine.java` from `jdk.jpackage` module
> - [x] Check for related but renamed(?) usages of `CommandLine.java` in other 
> JDK tools: `jshell`, `jdeps`, `jfr`, ...

Yes. I copied `CommandLine` class from module `jdk.compiler`. In addition to 
update of the copyright year and the name of the package, I also added small 
API changes that other tools developed in their copies of the class. Find a 
diff attached below:


diff --git 
a/open/src/jdk.compiler/share/classes/com/sun/tools/javac/main/CommandLine.java 
b/open/src/jdk.internal.opt/share/classes/jdk/internal/opt/CommandLine.java
index ec6f711f9b..9e4b0c6fe2 100644
--- 
a/open/src/jdk.compiler/share/classes/com/sun/tools/javac/main/CommandLine.java
+++ b/open/src/jdk.internal.opt/share/classes/jdk/internal/opt/CommandLine.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,17 +23,25 @@
  * questions.
  */
 
-package com.sun.tools.javac.main;
+package jdk.internal.opt;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
+/*
+ * This file was originally a copy of CommandLine.java in
+ * com.sun.tools.javac.main -- and it will be the last.
+ *
+ * Find details at https://bugs.openjdk.org/browse/JDK-8236919
+ */
+
 /**
  * Various utility methods for processing Java tool command line arguments.
  *
@@ -42,7 +50,16 @@ import java.util.List;
  *  This code and its internal interfaces are subject to change or
  *  deletion without notice.</b>
  */
-public class CommandLine {
+public final class CommandLine {
+    /**
+     * Convenient wrapper for the {@code List}-based parse method.
+     *
+     * @see #parse(List)
+     */
+    public static String[] parse(String... args) throws IOException {
+        return parse(List.of(args)).toArray(String[]::new);
+    }
+
     /**
      * Process Win32-style command files for the specified command line
      * arguments and return the resulting arguments. A command file argument
@@ -91,7 +108,7 @@ public class CommandLine {
      * @param args the arguments that may contain @files
      * @return the arguments, with environment variable's content and 
expansion of @files
      * @throws IOException if there is a problem reading any of the @files
-     * @throws com.sun.tools.javac.main.CommandLine.UnmatchedQuote
+     * @throws CommandLine.UnmatchedQuote
      */
     public static List<String> parse(String envVariable, List<String> args)
             throws IOException, UnmatchedQuote {
@@ -104,8 +121,18 @@ public class CommandLine {
         return newArgs;
     }
 
+    public static void loadCmdFile(InputStream in, List<String> args) throws 
IOException {
+        Reader reader = new InputStreamReader(in);
+        loadCmdFileAndCloseReader(reader, args);
+    }
+
     private static void loadCmdFile(String name, List<String> args) throws 
IOException {
-        try (Reader r = Files.newBufferedReader(Paths.get(name), 
Charset.defaultCharset())) {
+        Reader reader = Files.newBufferedReader(Paths.get(name), 
Charset.defaultCharset());
+        loadCmdFileAndCloseReader(reader, args);
+    }
+
+    private static void loadCmdFileAndCloseReader(Reader r, List<String> args) 
throws IOException {
+        try (r) {
             Tokenizer t = new Tokenizer(r);
             String s;
             while ((s = t.nextToken()) != null) {

-------------

PR: https://git.openjdk.org/jdk/pull/11272

Reply via email to