8054461: Add @file support to sjavac

Add @file support to sjavac commandline.

Reviewed-by: jjg, alundblad
This commit is contained in:
Fredrik Öhrström 2014-08-08 20:47:24 +02:00
parent 6b0a761ca3
commit ce6154a2fa
4 changed files with 40 additions and 12 deletions

View File

@ -375,8 +375,6 @@ public class Main {
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")) {

View File

@ -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 @@ public abstract class OptionHelper {
* @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:

View File

@ -176,14 +176,6 @@ public class Options {
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

View File

@ -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 @@ public class SJavac {
compileCircularSources();
compileExcludingDependency();
incrementalCompileTestFullyQualifiedRef();
compileWithAtFile();
delete(gensrc);
delete(gensrc2);
@ -463,6 +464,37 @@ public class SJavac {
"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);