8054461: Add @file support to sjavac
authorohrstrom
Fri, 08 Aug 2014 20:47:24 +0200
changeset 26087 93e7681752f6
parent 25851 cd6f4557e7fe
child 26088 f479ca655ba1
8054461: Add @file support to sjavac Summary: Add @file support to sjavac commandline. Reviewed-by: jjg, alundblad
langtools/src/share/classes/com/sun/tools/sjavac/Main.java
langtools/src/share/classes/com/sun/tools/sjavac/options/OptionHelper.java
langtools/src/share/classes/com/sun/tools/sjavac/options/Options.java
langtools/test/tools/sjavac/SJavac.java
--- a/langtools/src/share/classes/com/sun/tools/sjavac/Main.java	Wed Jul 05 19:53:51 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/Main.java	Fri Aug 08 20:47:24 2014 +0200
@@ -375,8 +375,6 @@
             err = "Please specify output directory.";
         } else if (options.isJavaFilesAmongJavacArgs()) {
             err = "Sjavac does not handle explicit compilation of single .java files.";
-        } else if (options.isAtFilePresent()) {
-            err = "Sjavac does not handle @-files.";
         } else if (options.getServerConf() == null) {
             err = "No server configuration provided.";
         } else if (!options.getImplicitPolicy().equals("none")) {
--- a/langtools/src/share/classes/com/sun/tools/sjavac/options/OptionHelper.java	Wed Jul 05 19:53:51 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/options/OptionHelper.java	Fri Aug 08 20:47:24 2014 +0200
@@ -25,12 +25,14 @@
 
 package com.sun.tools.sjavac.options;
 
+import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.List;
 
+import com.sun.tools.javac.main.CommandLine;
 import com.sun.tools.sjavac.Transformer;
 
 /**
@@ -112,7 +114,11 @@
      * @param args the arguments to traverse.
      */
     void traverse(String[] args) {
-
+        try {
+            args = CommandLine.parse(args); // Detect @file and load it as a command line.
+        } catch (java.io.IOException e) {
+            throw new IllegalArgumentException("Problem reading @"+e.getMessage());
+        }
         ArgumentIterator argIter = new ArgumentIterator(Arrays.asList(args));
 
         nextArg:
--- a/langtools/src/share/classes/com/sun/tools/sjavac/options/Options.java	Wed Jul 05 19:53:51 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/options/Options.java	Fri Aug 08 20:47:24 2014 +0200
@@ -176,14 +176,6 @@
         return false;
     }
 
-    /** Returns true iff an @-file is among the javac arguments */
-    public boolean isAtFilePresent() {
-        for (String javacArg : javacArgs)
-            if (javacArg.startsWith("@"))
-                return true;
-        return false;
-    }
-
     /**
      * Returns a string representation of the options that affect the result of
      * the compilation. (Used for saving the state of the options used in a
--- a/langtools/test/tools/sjavac/SJavac.java	Wed Jul 05 19:53:51 2017 +0200
+++ b/langtools/test/tools/sjavac/SJavac.java	Fri Aug 08 20:47:24 2014 +0200
@@ -25,7 +25,7 @@
 /*
  * @test
  * @summary Test all aspects of sjavac.
- * @bug 8004658 8042441 8042699
+ * @bug 8004658 8042441 8042699 8054461
  *
  * @build Wrapper
  * @run main Wrapper SJavac
@@ -99,6 +99,7 @@
         compileCircularSources();
         compileExcludingDependency();
         incrementalCompileTestFullyQualifiedRef();
+        compileWithAtFile();
 
         delete(gensrc);
         delete(gensrc2);
@@ -463,6 +464,37 @@
                          "bin/javac_state");
     }
 
+   /**
+     * Tests @atfile
+     * @throws Exception If test fails
+     */
+    void compileWithAtFile() throws Exception {
+        System.out.println("\nTest @atfile with command line content.");
+        System.out.println("---------------------------------------");
+
+        delete(gensrc);
+        delete(gensrc2);
+        delete(bin);
+
+        populate(gensrc,
+                 "list.txt",
+                 "-if */alfa/omega/A.java\n-if */beta/B.java\ngensrc\n-d bin\n",
+                 "alfa/omega/A.java",
+                 "package alfa.omega; import beta.B; public class A { B b; }",
+                 "beta/B.java",
+                 "package beta; public class B { }",
+                 "beta/C.java",
+                 "broken");
+        previous_bin_state = collectState(bin);
+        compile("@gensrc/list.txt", "--server:portfile=testserver,background=false");
+
+        Map<String,Long> new_bin_state = collectState(bin);
+        verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
+                         "bin/javac_state",
+                         "bin/alfa/omega/A.class",
+                         "bin/beta/B.class");
+    }
+
     void removeFrom(Path dir, String... args) throws IOException {
         for (String filename : args) {
             Path p = dir.resolve(filename);