Thu, 15 Aug 2013 17:24:35 +0200
8015145: Smartjavac needs more flexibility with linking to sources
Reviewed-by: jjg, ohrstrom
1.1 --- a/src/share/classes/com/sun/tools/sjavac/JavacState.java Wed Aug 14 21:44:51 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/sjavac/JavacState.java Thu Aug 15 17:24:35 2013 +0200 1.3 @@ -808,7 +808,10 @@ 1.4 1.5 // Create a set of filenames with full paths. 1.6 for (Source s : now.sources().values()) { 1.7 - calculatedSources.add(s.file().getPath()); 1.8 + // Don't include link only sources when comparing sources to compile 1.9 + if (!s.isLinkedOnly()) { 1.10 + calculatedSources.add(s.file().getPath()); 1.11 + } 1.12 } 1.13 // Read in the file and create another set of filenames with full paths. 1.14 try {
2.1 --- a/src/share/classes/com/sun/tools/sjavac/Main.java Wed Aug 14 21:44:51 2013 -0700 2.2 +++ b/src/share/classes/com/sun/tools/sjavac/Main.java Thu Aug 15 17:24:35 2013 +0200 2.3 @@ -249,16 +249,19 @@ 2.4 return -1; 2.5 } 2.6 2.7 - // Find all source files allowable for linking. 2.8 + // Create a map of all source files that are available for linking. Both -src and 2.9 + // -sourcepath point to such files. It is possible to specify multiple 2.10 + // -sourcepath options to enable different filtering rules. If the 2.11 + // filters are the same for multiple sourcepaths, they may be concatenated 2.12 + // using :(;). Before sending the list of sourcepaths to javac, they are 2.13 + // all concatenated. The list created here is used by the SmartFileWrapper to 2.14 + // make sure only the correct sources are actually available. 2.15 // We might find more modules here as well. 2.16 Map<String,Source> sources_to_link_to = new HashMap<String,Source>(); 2.17 - // Always reuse -src for linking as well! This means that we might 2.18 - // get two -sourcepath on the commandline after the rewrite, which is 2.19 - // fine. We can have as many as we like. You need to have separate -src/-sourcepath/-classpath 2.20 - // if you need different filtering rules for different roots. If you have the same filtering 2.21 - // rules for all sourcepath roots, you can concatenate them using :(;) as before. 2.22 - rewriteOptions(args, "-src", "-sourcepath"); 2.23 + findFiles(args, "-src", Util.set(".java"), sources_to_link_to, modules, current_module, true); 2.24 findFiles(args, "-sourcepath", Util.set(".java"), sources_to_link_to, modules, current_module, true); 2.25 + // Rewrite the -src option to make it through to the javac instances. 2.26 + rewriteOptions(args, "-src", "-sourcepath"); 2.27 2.28 // Find all class files allowable for linking. 2.29 // And pickup knowledge of all modules found here.
3.1 --- a/test/tools/sjavac/SJavac.java Wed Aug 14 21:44:51 2013 -0700 3.2 +++ b/test/tools/sjavac/SJavac.java Thu Aug 15 17:24:35 2013 +0200 3.3 @@ -21,6 +21,11 @@ 3.4 * questions. 3.5 */ 3.6 3.7 +/* 3.8 + * @test 3.9 + * @summary Tests sjavac basic functionality 3.10 + */ 3.11 + 3.12 import java.util.*; 3.13 import java.io.*; 3.14 import java.net.*; 3.15 @@ -82,11 +87,13 @@ 3.16 compileWithOverrideSource(); 3.17 compileWithInvisibleSources(); 3.18 compileCircularSources(); 3.19 + compileExcludingDependency(); 3.20 3.21 delete(gensrc); 3.22 delete(gensrc2); 3.23 delete(gensrc3); 3.24 delete(bin); 3.25 + delete(headers); 3.26 } 3.27 3.28 void initialCompile() throws Exception { 3.29 @@ -381,6 +388,33 @@ 3.30 delete(bin); 3.31 } 3.32 3.33 + /** 3.34 + * Tests compiling class A that depends on class B without compiling class B 3.35 + * @throws Exception If test fails 3.36 + */ 3.37 + void compileExcludingDependency() throws Exception { 3.38 + System.out.println("\nVerify that excluding classes from compilation but not from linking works."); 3.39 + System.out.println("---------------------------------------------------------------------------"); 3.40 + 3.41 + delete(gensrc); 3.42 + delete(bin); 3.43 + previous_bin_state = collectState(bin); 3.44 + 3.45 + populate(gensrc, 3.46 + "alfa/A.java", 3.47 + "package alfa; public class A { beta.B b; }", 3.48 + "beta/B.java", 3.49 + "package beta; public class B { }"); 3.50 + 3.51 + compile("-x", "beta", "-src", "gensrc", "-x", "alfa", "-sourcepath", "gensrc", 3.52 + "-d", "bin", "--server:portfile=testserver,background=false"); 3.53 + 3.54 + Map<String,Long> new_bin_state = collectState(bin); 3.55 + verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state, 3.56 + "bin/alfa/A.class", 3.57 + "bin/javac_state"); 3.58 + } 3.59 + 3.60 void removeFrom(Path dir, String... args) throws IOException { 3.61 for (String filename : args) { 3.62 Path p = dir.resolve(filename); 3.63 @@ -405,7 +439,7 @@ 3.64 } 3.65 } 3.66 3.67 - void delete(Path root) throws IOException { 3.68 + void delete(final Path root) throws IOException { 3.69 if (!Files.exists(root)) return; 3.70 Files.walkFileTree(root, new SimpleFileVisitor<Path>() { 3.71 @Override