8135131: Enable thin server mode in Sjavac

State tracknig and incremental compilation disabled unless --state-dir is provided.

Reviewed-by: jlahoda
This commit is contained in:
Andreas Lundblad 2015-09-21 11:19:10 +02:00
parent 2a12715485
commit 6238d40db4
25 changed files with 304 additions and 182 deletions

View file

@ -322,6 +322,13 @@ public class Log extends AbstractLog {
return instance; return instance;
} }
/**
* Register a Context.Factory to create a Log.
*/
public static void preRegister(Context context, PrintWriter w) {
context.put(Log.class, (Context.Factory<Log>) (c -> new Log(c, w)));
}
/** The number of errors encountered so far. /** The number of errors encountered so far.
*/ */
public int nerrors = 0; public int nerrors = 0;

View file

@ -91,7 +91,7 @@ public class SjavacClient implements Sjavac {
String serverConf = (tmpServerConf!=null)? tmpServerConf : ""; String serverConf = (tmpServerConf!=null)? tmpServerConf : "";
String tmpId = Util.extractStringOption("id", serverConf); String tmpId = Util.extractStringOption("id", serverConf);
id = (tmpId!=null) ? tmpId : "id"+(((new java.util.Random()).nextLong())&Long.MAX_VALUE); id = (tmpId!=null) ? tmpId : "id"+(((new java.util.Random()).nextLong())&Long.MAX_VALUE);
String defaultPortfile = options.getStateDir() String defaultPortfile = options.getDestDir()
.resolve("javac_server") .resolve("javac_server")
.toAbsolutePath() .toAbsolutePath()
.toString(); .toString();

View file

@ -36,7 +36,11 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Stream;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.main.Main;
import com.sun.tools.javac.util.Context;
import com.sun.tools.sjavac.JavacState; import com.sun.tools.sjavac.JavacState;
import com.sun.tools.sjavac.Log; import com.sun.tools.sjavac.Log;
import com.sun.tools.sjavac.Module; import com.sun.tools.sjavac.Module;
@ -44,10 +48,13 @@ import com.sun.tools.sjavac.ProblemException;
import com.sun.tools.sjavac.Source; import com.sun.tools.sjavac.Source;
import com.sun.tools.sjavac.Transformer; import com.sun.tools.sjavac.Transformer;
import com.sun.tools.sjavac.Util; import com.sun.tools.sjavac.Util;
import com.sun.tools.sjavac.options.Option;
import com.sun.tools.sjavac.options.Options; import com.sun.tools.sjavac.options.Options;
import com.sun.tools.sjavac.options.SourceLocation; import com.sun.tools.sjavac.options.SourceLocation;
import com.sun.tools.sjavac.server.Sjavac; import com.sun.tools.sjavac.server.Sjavac;
import javax.tools.JavaFileManager;
/** /**
* The sjavac implementation that interacts with javac and performs the actual * The sjavac implementation that interacts with javac and performs the actual
* compilation. * compilation.
@ -77,7 +84,8 @@ public class SjavacImpl implements Sjavac {
if (!createIfMissing(options.getDestDir())) if (!createIfMissing(options.getDestDir()))
return RC_FATAL; return RC_FATAL;
if (!createIfMissing(options.getStateDir())) Path stateDir = options.getStateDir();
if (stateDir != null && !createIfMissing(options.getStateDir()))
return RC_FATAL; return RC_FATAL;
Path gensrc = options.getGenSrcDir(); Path gensrc = options.getGenSrcDir();
@ -88,6 +96,30 @@ public class SjavacImpl implements Sjavac {
if (hdrdir != null && !createIfMissing(hdrdir)) if (hdrdir != null && !createIfMissing(hdrdir))
return RC_FATAL; return RC_FATAL;
if (stateDir == null) {
// Prepare context. Direct logging to our byte array stream.
Context context = new Context();
PrintWriter writer = new PrintWriter(err);
com.sun.tools.javac.util.Log.preRegister(context, writer);
JavacFileManager.preRegister(context);
// Prepare arguments
String[] passThroughArgs = Stream.of(args)
.filter(arg -> !arg.startsWith(Option.SERVER.arg))
.toArray(String[]::new);
// Compile
com.sun.tools.javac.main.Main compiler = new com.sun.tools.javac.main.Main("javac", writer);
Main.Result result = compiler.compile(passThroughArgs, context);
// Clean up
JavaFileManager fileManager = context.get(JavaFileManager.class);
if (fileManager instanceof JavacFileManager) {
((JavacFileManager) fileManager).close();
}
return result.exitCode;
} else {
// Load the prev build state database. // Load the prev build state database.
JavacState javac_state = JavacState.load(options, out, err); JavacState javac_state = JavacState.load(options, out, err);
@ -248,6 +280,7 @@ public class SjavacImpl implements Sjavac {
return RC_FATAL; return RC_FATAL;
} }
} }
}
@Override @Override
public void shutdown() { public void shutdown() {
@ -266,8 +299,8 @@ public class SjavacImpl implements Sjavac {
err = "No server configuration provided."; err = "No server configuration provided.";
} else if (!options.getImplicitPolicy().equals("none")) { } else if (!options.getImplicitPolicy().equals("none")) {
err = "The only allowed setting for sjavac is -implicit:none"; err = "The only allowed setting for sjavac is -implicit:none";
} else if (options.getSources().isEmpty()) { } else if (options.getSources().isEmpty() && options.getStateDir() != null) {
err = "You have to specify -src."; err = "You have to specify -src when using --state-dir.";
} else if (options.getTranslationRules().size() > 1 } else if (options.getTranslationRules().size() > 1
&& options.getGenSrcDir() == null) { && options.getGenSrcDir() == null) {
err = "You have translators but no gensrc dir (-s) specified!"; err = "You have translators but no gensrc dir (-s) specified!";

View file

@ -97,7 +97,7 @@ public class Options {
/** Get the path for the state directory, defaults to destDir. */ /** Get the path for the state directory, defaults to destDir. */
public Path getStateDir() { public Path getStateDir() {
return stateDir != null ? stateDir : destDir; return stateDir;
} }
/** Get all source locations for files to be compiled */ /** Get all source locations for files to be compiled */

View file

@ -89,7 +89,7 @@ public class ApiExtraction {
new ToolBox().new JavacTask().sources(testSrc).run(); new ToolBox().new JavacTask().sources(testSrc).run();
// Extract PubApi // Extract PubApi
Options options = Options.parseArgs("-d", "bin", "-cp", "."); Options options = Options.parseArgs("-d", "bin", "--state-dir=bin", "-cp", ".");
PubApiExtractor pubApiExtr = new PubApiExtractor(options); PubApiExtractor pubApiExtr = new PubApiExtractor(options);
PubApi actualApi = pubApiExtr.getPubApi("TestClass"); PubApi actualApi = pubApiExtr.getPubApi("TestClass");

View file

@ -64,7 +64,7 @@ public class ClasspathDependencies extends SjavacBase {
headline("Create a test dependency, Dep.class, and put it in the classpath dir"); headline("Create a test dependency, Dep.class, and put it in the classpath dir");
String depCode = "package dep; public class Dep { public void m1() {} }"; String depCode = "package dep; public class Dep { public void m1() {} }";
toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode); toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode);
int rc = compile(server, "-d", classesDep, srcDep); int rc = compile(server, "-d", classesDep, "--state-dir=" + classesDep, srcDep);
check(rc == 0, "Compilation failed unexpectedly"); check(rc == 0, "Compilation failed unexpectedly");
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -73,7 +73,7 @@ public class ClasspathDependencies extends SjavacBase {
"package pkg;" + "package pkg;" +
"import dep.Dep;" + "import dep.Dep;" +
"public class C { Dep dep; public void m() { new Dep().m1(); } }"); "public class C { Dep dep; public void m() { new Dep().m1(); } }");
rc = compile(server, "-d", classes, src, "-cp", classesDep); rc = compile(server, "-d", classes, "--state-dir=" + classes, src, "-cp", classesDep);
check(rc == 0, "Compilation failed unexpectedly"); check(rc == 0, "Compilation failed unexpectedly");
FileTime modTime1 = Files.getLastModifiedTime(classes.resolve("pkg/C.class")); FileTime modTime1 = Files.getLastModifiedTime(classes.resolve("pkg/C.class"));
@ -82,12 +82,12 @@ public class ClasspathDependencies extends SjavacBase {
Thread.sleep(2000); Thread.sleep(2000);
depCode = depCode.replaceAll("}$", "private void m2() {} }"); depCode = depCode.replaceAll("}$", "private void m2() {} }");
toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode); toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode);
rc = compile(server, "-d", classesDep, srcDep); rc = compile(server, "-d", classesDep, "--state-dir=" + classesDep, srcDep);
check(rc == 0, "Compilation failed unexpectedly"); check(rc == 0, "Compilation failed unexpectedly");
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
headline("Make sure that this does not trigger recompilation of C.java"); headline("Make sure that this does not trigger recompilation of C.java");
rc = compile(server, "-d", classes, src, "-cp", classesDep); rc = compile(server, "-d", classes, "--state-dir=" + classes, src, "-cp", classesDep);
check(rc == 0, "Compilation failed unexpectedly"); check(rc == 0, "Compilation failed unexpectedly");
FileTime modTime2 = Files.getLastModifiedTime(classes.resolve("pkg/C.class")); FileTime modTime2 = Files.getLastModifiedTime(classes.resolve("pkg/C.class"));
check(modTime1.equals(modTime2), "Recompilation erroneously triggered"); check(modTime1.equals(modTime2), "Recompilation erroneously triggered");
@ -97,12 +97,12 @@ public class ClasspathDependencies extends SjavacBase {
Thread.sleep(2000); Thread.sleep(2000);
depCode = depCode.replace("m1()", "m1(String... arg)"); depCode = depCode.replace("m1()", "m1(String... arg)");
toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode); toolbox.writeFile(srcDep.resolve("dep/Dep.java"), depCode);
rc = compile(server, "-d", classesDep, srcDep); rc = compile(server, "-d", classesDep, "--state-dir=" + classesDep, srcDep);
check(rc == 0, "Compilation failed unexpectedly"); check(rc == 0, "Compilation failed unexpectedly");
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
headline("Make sure that recompilation of C.java is triggered"); headline("Make sure that recompilation of C.java is triggered");
rc = compile(server, "-d", classes, src, "-cp", classesDep); rc = compile(server, "-d", classes, "--state-dir=" + classes, src, "-cp", classesDep);
check(rc == 0, "Compilation failed unexpectedly"); check(rc == 0, "Compilation failed unexpectedly");
FileTime modTime3 = Files.getLastModifiedTime(classes.resolve("pkg/C.class")); FileTime modTime3 = Files.getLastModifiedTime(classes.resolve("pkg/C.class"));
check(modTime2.compareTo(modTime3) < 0, "Recompilation not triggered"); check(modTime2.compareTo(modTime3) < 0, "Recompilation not triggered");

View file

@ -63,6 +63,7 @@ public class CompileCircularSources extends SJavacTester {
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"--state-dir=" + BIN,
"-j", "3", "-j", "3",
SERVER_ARG, SERVER_ARG,
"--log=debug"); "--log=debug");

View file

@ -62,6 +62,7 @@ public class CompileExcludingDependency extends SJavacTester {
"-x", "alfa/omega", "-x", "alfa/omega",
"-sourcepath", GENSRC.toString(), "-sourcepath", GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
SERVER_ARG); SERVER_ARG);
Map<String,Long> new_bin_state = collectState(BIN); Map<String,Long> new_bin_state = collectState(BIN);

View file

@ -52,7 +52,8 @@ public class CompileWithAtFile extends SJavacTester {
"-if */alfa/omega/A.java\n" + "-if */alfa/omega/A.java\n" +
"-if */beta/B.java\n" + "-if */beta/B.java\n" +
GENSRC + "\n" + GENSRC + "\n" +
"-d " + BIN + "\n"); "-d " + BIN + "\n" +
"--state-dir=" + BIN + "\n");
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"), tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
"package alfa.omega; import beta.B; public class A { B b; }"); "package alfa.omega; import beta.B; public class A { B b; }");
tb.writeFile(GENSRC.resolve("beta/B.java"), tb.writeFile(GENSRC.resolve("beta/B.java"),

View file

@ -70,6 +70,7 @@ public class CompileWithInvisibleSources extends SJavacTester {
"-sourcepath", GENSRC2.toString(), "-sourcepath", GENSRC2.toString(),
"-sourcepath", GENSRC3.toString(), "-sourcepath", GENSRC3.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG); SERVER_ARG);
@ -86,6 +87,7 @@ public class CompileWithInvisibleSources extends SJavacTester {
"-sourcepath", GENSRC2.toString(), "-sourcepath", GENSRC2.toString(),
"-sourcepath", GENSRC3.toString(), "-sourcepath", GENSRC3.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG); SERVER_ARG);

View file

@ -68,6 +68,7 @@ public class CompileWithOverrideSources extends SJavacTester {
GENSRC.toString(), GENSRC.toString(),
GENSRC2.toString(), GENSRC2.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG); SERVER_ARG);
@ -83,6 +84,7 @@ public class CompileWithOverrideSources extends SJavacTester {
compileExpectFailure(GENSRC.toString(), compileExpectFailure(GENSRC.toString(),
GENSRC2.toString(), GENSRC2.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG); SERVER_ARG);

View file

@ -61,6 +61,7 @@ public class ExclPattern {
"-x", "pkg/excl-dir/*", "-x", "pkg/excl-dir/*",
"-src", "srcdir", "-src", "srcdir",
"-d", "dest", "-d", "dest",
"--state-dir=dest",
"-j", "1", "-j", "1",
"-copy", ".txt", "-copy", ".txt",
"--server:portfile=testserver,background=false", "--server:portfile=testserver,background=false",

View file

@ -56,11 +56,20 @@ public class IgnoreSymbolFile {
new File("classes").mkdirs(); new File("classes").mkdirs();
String server = "--server:portfile=testserver,background=false"; String server = "--server:portfile=testserver,background=false";
int rc1 = compile(server, "-d", "classes", "-Werror", "src"); int rc1 = compile(server,
"-d", "classes",
"--state-dir=classes",
"-Werror",
"src");
if (rc1 == 0) if (rc1 == 0)
error("compilation succeeded unexpectedly"); error("compilation succeeded unexpectedly");
int rc2 = compile(server, "-d", "classes", "-Werror", "-XDignore.symbol.file=true", "src"); int rc2 = compile(server,
"-d", "classes",
"--state-dir=classes",
"-Werror",
"-XDignore.symbol.file=true",
"src");
if (rc2 != 0) if (rc2 != 0)
error("compilation failed unexpectedly: rc=" + rc2); error("compilation failed unexpectedly: rc=" + rc2);

View file

@ -53,7 +53,7 @@ public class IncCompInheritance extends SjavacBase {
// Initial compile (should succeed) // Initial compile (should succeed)
String server = "--server:portfile=testserver,background=false"; String server = "--server:portfile=testserver,background=false";
int rc1 = compile(server, "-d", classes, src); int rc1 = compile(server, "-d", classes, "--state-dir=" + classes, src);
if (rc1 != 0) if (rc1 != 0)
throw new AssertionError("Compilation failed unexpectedly"); throw new AssertionError("Compilation failed unexpectedly");
@ -65,7 +65,7 @@ public class IncCompInheritance extends SjavacBase {
// Incremental compile (C should now be recompiled even though it // Incremental compile (C should now be recompiled even though it
// depends on A only through inheritance via B). // depends on A only through inheritance via B).
// Since A.m is removed, this should fail. // Since A.m is removed, this should fail.
int rc2 = compile(server, "-d", classes, src); int rc2 = compile(server, "-d", classes, "--state-dir=" + classes, src);
if (rc2 == 0) if (rc2 == 0)
throw new AssertionError("Compilation succeeded unexpectedly"); throw new AssertionError("Compilation succeeded unexpectedly");
} }

View file

@ -76,6 +76,7 @@ public class IncCompileChangeNative extends SJavacTester {
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG, SERVER_ARG,
@ -105,6 +106,7 @@ public class IncCompileChangeNative extends SJavacTester {
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG, SERVER_ARG,

View file

@ -71,6 +71,7 @@ public class IncCompileDropClasses extends SJavacTester {
removeFrom(GENSRC, "alfa/omega/AA.java"); removeFrom(GENSRC, "alfa/omega/AA.java");
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG, SERVER_ARG,

View file

@ -60,6 +60,7 @@ public class IncCompileFullyQualifiedRef extends SJavacTester {
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-j", "1", "-j", "1",
SERVER_ARG, SERVER_ARG,
"--log=debug"); "--log=debug");
@ -74,6 +75,7 @@ public class IncCompileFullyQualifiedRef extends SJavacTester {
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-j", "1", "-j", "1",
SERVER_ARG, SERVER_ARG,
"--log=debug"); "--log=debug");

View file

@ -69,6 +69,7 @@ public class IncCompileNoChanges extends SJavacTester {
System.out.println("Testing that no change in sources implies no change in binaries"); System.out.println("Testing that no change in sources implies no change in binaries");
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG, SERVER_ARG,

View file

@ -76,6 +76,7 @@ public class IncCompileUpdateNative extends SJavacTester {
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG, SERVER_ARG,

View file

@ -78,6 +78,7 @@ public class IncCompileWithChanges extends SJavacTester {
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG, SERVER_ARG,

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2015, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @summary Test --no-state option
* @bug 8135131
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.file
* jdk.compiler/com.sun.tools.javac.main
* jdk.compiler/com.sun.tools.sjavac
* @build Wrapper ToolBox
* @run main Wrapper NoState
*/
import com.sun.tools.javac.util.Assert;
import java.util.*;
import java.nio.file.*;
public class NoState extends SJavacTester {
public static void main(String... args) throws Exception {
new NoState().run();
}
public void run() throws Exception {
clean(TEST_ROOT);
ToolBox tb = new ToolBox();
tb.writeFile(GENSRC.resolve("pkg/A.java"), "package pkg; class A {}");
Files.createDirectory(BIN);
compile("-d", BIN.toString(),
"--server:portfile=testserver,background=false",
GENSRC + "/pkg/A.java");
// Make sure file was compiled
Assert.check(Files.exists(BIN.resolve("pkg/A.class")));
// Make sure we have no other files (such as a javac_state file) in the bin directory
Assert.check(Files.list(BIN).count() == 1);
Assert.check(Files.list(BIN.resolve("pkg")).count() == 1);
}
}

View file

@ -59,7 +59,6 @@ import com.sun.tools.sjavac.options.SourceLocation;
public class OptionDecoding { public class OptionDecoding {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
testPaths(); testPaths();
testDupPaths(); testDupPaths();
testSourceLocations(); testSourceLocations();
@ -67,30 +66,28 @@ public class OptionDecoding {
testServerConf(); testServerConf();
testSearchPaths(); testSearchPaths();
testTranslationRules(); testTranslationRules();
} }
// Test decoding of output paths // Test decoding of output paths
static void testPaths() throws IOException { static void testPaths() throws IOException {
final String H = "headers"; final String H = "headers";
final String G = "gensrc"; final String G = "gensrc";
final String D = "dest"; final String D = "dest";
final String stateDir = "stateDir";
final String CMP = "srcRefList.txt"; final String CMP = "srcRefList.txt";
Options options = Options.parseArgs("-h", H, "-s", G, "-d", D, Options options = Options.parseArgs("-h", H, "-s", G, "-d", D, "--state-dir=" + stateDir,
"--compare-found-sources", CMP); "--compare-found-sources", CMP);
assertEquals(Paths.get(H).toAbsolutePath(), options.getHeaderDir()); assertEquals(Paths.get(H).toAbsolutePath(), options.getHeaderDir());
assertEquals(Paths.get(G).toAbsolutePath(), options.getGenSrcDir()); assertEquals(Paths.get(G).toAbsolutePath(), options.getGenSrcDir());
assertEquals(Paths.get(D).toAbsolutePath(), options.getDestDir()); assertEquals(Paths.get(D).toAbsolutePath(), options.getDestDir());
assertEquals(Paths.get(stateDir).toAbsolutePath(), options.getStateDir());
assertEquals(Paths.get(CMP), options.getSourceReferenceList()); assertEquals(Paths.get(CMP), options.getSourceReferenceList());
} }
// Providing duplicate header / dest / gensrc paths should produce an error. // Providing duplicate header / dest / gensrc paths should produce an error.
static void testDupPaths() throws IOException { static void testDupPaths() throws IOException {
try { try {
Options.parseArgs("-h", "dir1", "-h", "dir2"); Options.parseArgs("-h", "dir1", "-h", "dir2");
throw new RuntimeException("Duplicate header directories should fail."); throw new RuntimeException("Duplicate header directories should fail.");
@ -111,12 +108,10 @@ public class OptionDecoding {
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
// Expected // Expected
} }
} }
// Test source locations and -x, -i, -xf, -if filters // Test source locations and -x, -i, -xf, -if filters
static void testSourceLocations() throws IOException { static void testSourceLocations() throws IOException {
Path a1 = Paths.get("root/pkg1/ClassA1.java"); Path a1 = Paths.get("root/pkg1/ClassA1.java");
Path a2 = Paths.get("root/pkg1/ClassA2.java"); Path a2 = Paths.get("root/pkg1/ClassA2.java");
Path b1 = Paths.get("root/pkg1/pkg2/ClassB1.java"); Path b1 = Paths.get("root/pkg1/pkg2/ClassB1.java");
@ -185,12 +180,10 @@ public class OptionDecoding {
checkFilesFound(foundFiles.keySet(), a1, a2); checkFilesFound(foundFiles.keySet(), a1, a2);
} }
} }
// Test basic options // Test basic options
static void testSimpleOptions() { static void testSimpleOptions() {
Options options = Options.parseArgs("-j", "17", "--log=debug"); Options options = Options.parseArgs("-j", "17", "--log=debug");
assertEquals(17, options.getNumCores()); assertEquals(17, options.getNumCores());
assertEquals("debug", options.getLogLevel()); assertEquals("debug", options.getLogLevel());
@ -239,7 +232,6 @@ public class OptionDecoding {
// Test -tr option // Test -tr option
static void testTranslationRules() { static void testTranslationRules() {
Class<?> cls = com.sun.tools.sjavac.CompileJavaPackages.class; Class<?> cls = com.sun.tools.sjavac.CompileJavaPackages.class;
Options options = Options.parseArgs( Options options = Options.parseArgs(
@ -250,6 +242,5 @@ public class OptionDecoding {
assertEquals(cls, options.getTranslationRules().get(".exa").getClass()); assertEquals(cls, options.getTranslationRules().get(".exa").getClass());
assertEquals(cls, options.getTranslationRules().get(".exb").getClass()); assertEquals(cls, options.getTranslationRules().get(".exb").getClass());
assertEquals(CopyFile.class, options.getTranslationRules().get(".html").getClass()); assertEquals(CopyFile.class, options.getTranslationRules().get(".html").getClass());
} }
} }

View file

@ -46,21 +46,22 @@ class ParallelCompilations extends SJavacTester {
public void run() throws Exception { public void run() throws Exception {
ToolBox tb = new ToolBox(); ToolBox tb = new ToolBox();
final String SERVER_ARG = "--server:"
+ "portfile=testportfile,"
+ "background=false";
// Generate 10 files // Generate 10 files
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
String fileName = "Test" + i;
String content = "package foo"+ i + ";\n" + String content = "package foo"+ i + ";\n" +
"public class "+ fileName + "{\n" + "public class Test" + i + "{\n" +
" public static void main(String[] args) {}\n" + " public static void main(String[] args) {}\n" +
"\n}"; "\n}";
Path srcDir = Paths.get("src"); Path srcDir = Paths.get("src");
tb.writeJavaFiles(srcDir,content); tb.writeJavaFiles(srcDir, content);
} }
//Method will throw an exception if compilation fails // Method will throw an exception if compilation fails
compile("src", "-d", "classes", "-j", "10", SERVER_ARG, "--log=debug"); compile("src",
"-d", BIN.toString(),
"--state-dir=" + BIN,
"-j", "10",
SERVER_ARG,
"--log=debug");
} }
} }

View file

@ -65,6 +65,7 @@ public class PermittedArtifact extends SJavacTester {
"--permit-artifact=" + BIN + "/alfa/omega/AA.class", "--permit-artifact=" + BIN + "/alfa/omega/AA.class",
"-src", GENSRC.toString(), "-src", GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
SERVER_ARG); SERVER_ARG);
Map<String,Long> new_bin_state = collectState(BIN); Map<String,Long> new_bin_state = collectState(BIN);

View file

@ -87,6 +87,7 @@ public class SJavacTester {
compile(GENSRC.toString(), compile(GENSRC.toString(),
"-d", BIN.toString(), "-d", BIN.toString(),
"--state-dir=" + BIN,
"-h", HEADERS.toString(), "-h", HEADERS.toString(),
"-j", "1", "-j", "1",
SERVER_ARG, SERVER_ARG,