author | tschatzl |
Tue, 10 Jul 2018 15:09:34 +0200 | |
changeset 51025 | e4ca45413ddd |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
1 |
/* |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
4 |
* |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
8 |
* |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
14 |
* |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
18 |
* |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
22 |
*/ |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
23 |
|
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
24 |
/* |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
25 |
* @test |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
26 |
* @bug 8043643 |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
27 |
* @summary Run the langtools coding rules over the langtools source code. |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.util |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
29 |
*/ |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
30 |
|
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
31 |
|
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
32 |
import java.io.*; |
37850
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
33 |
import java.lang.reflect.Method; |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
34 |
import java.net.URL; |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
35 |
import java.net.URLClassLoader; |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
36 |
import java.nio.file.Files; |
26391
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
37 |
import java.nio.file.Path; |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
38 |
import java.nio.file.Paths; |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
39 |
import java.nio.file.StandardOpenOption; |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
40 |
import java.util.*; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
41 |
import java.util.stream.Collectors; |
26391
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
42 |
import java.util.stream.Stream; |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
43 |
|
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
44 |
import javax.tools.Diagnostic; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
45 |
import javax.tools.DiagnosticListener; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
46 |
import javax.tools.JavaCompiler; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
47 |
import javax.tools.JavaFileObject; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
48 |
import javax.tools.StandardJavaFileManager; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
49 |
import javax.tools.ToolProvider; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
50 |
|
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
51 |
import com.sun.tools.javac.util.Assert; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
52 |
|
38510
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
53 |
/** |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
54 |
* This is a test to verify specific coding standards for source code in the langtools repository. |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
55 |
* |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
56 |
* As such, it is not a standard unit, regression or functional test, and will |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
57 |
* automatically skip if the langtools source code is not available. |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
58 |
* |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
59 |
* If the source code is available, it will find and compile the coding |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
60 |
* style analyzers found in langtools/make/tools/crules/*.java, and run the resulting |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
61 |
* code on all source files under langtools/src/share/classes. Any coding style |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
62 |
* violations will cause the test to fail. |
3f450a95c68f
8054562: document skip results in RunCodingRules.java
jlahoda
parents:
37850
diff
changeset
|
63 |
*/ |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
64 |
public class RunCodingRules { |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
65 |
public static void main(String... args) throws Exception { |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
66 |
new RunCodingRules().run(); |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
67 |
} |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
68 |
|
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
69 |
public void run() throws Exception { |
26391
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
70 |
Path testSrc = Paths.get(System.getProperty("test.src", ".")); |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
71 |
Path targetDir = Paths.get("."); |
26391
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
72 |
List<Path> sourceDirs = null; |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
73 |
Path crulesDir = null; |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
74 |
Path mainSrcDir = null; |
26391
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
75 |
for (Path d = testSrc; d != null; d = d.getParent()) { |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
76 |
if (Files.exists(d.resolve("TEST.ROOT"))) { |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
77 |
d = d.getParent(); |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
78 |
Path toolsPath = d.resolve("make/tools"); |
37850
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
79 |
if (Files.exists(toolsPath)) { |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
80 |
mainSrcDir = d.resolve("src"); |
26391
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
81 |
crulesDir = toolsPath; |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
82 |
sourceDirs = Files.walk(mainSrcDir, 1) |
26391
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
83 |
.map(p -> p.resolve("share/classes")) |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
84 |
.filter(p -> Files.isDirectory(p)) |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
85 |
.collect(Collectors.toList()); |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
86 |
break; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
87 |
} |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
88 |
} |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
89 |
} |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
90 |
|
37850
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
91 |
if (sourceDirs == null || crulesDir == null) { |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
92 |
System.err.println("Warning: sources not found, test skipped."); |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
93 |
return ; |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
94 |
} |
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
95 |
|
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
96 |
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
97 |
try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
98 |
DiagnosticListener<JavaFileObject> noErrors = diagnostic -> { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
99 |
Assert.check(diagnostic.getKind() != Diagnostic.Kind.ERROR, diagnostic.toString()); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
100 |
}; |
37850
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
101 |
String FS = File.separator; |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
102 |
String PS = File.pathSeparator; |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
103 |
|
37850
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
104 |
//compile crules: |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
105 |
List<File> crulesFiles = Files.walk(crulesDir) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
106 |
.filter(entry -> entry.getFileName().toString().endsWith(".java")) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
107 |
.filter(entry -> entry.getParent().endsWith("crules")) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
108 |
.map(entry -> entry.toFile()) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
109 |
.collect(Collectors.toList()); |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
110 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
111 |
Path crulesTarget = targetDir.resolve("crules"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
112 |
Files.createDirectories(crulesTarget); |
36526 | 113 |
List<String> crulesOptions = Arrays.asList( |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38510
diff
changeset
|
114 |
"--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38510
diff
changeset
|
115 |
"--add-exports", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38510
diff
changeset
|
116 |
"--add-exports", "jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38510
diff
changeset
|
117 |
"--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", |
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38510
diff
changeset
|
118 |
"--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", |
36526 | 119 |
"-d", crulesTarget.toString()); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
120 |
javaCompiler.getTask(null, fm, noErrors, crulesOptions, null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
121 |
fm.getJavaFileObjectsFromFiles(crulesFiles)).call(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
122 |
Path registration = crulesTarget.resolve("META-INF/services/com.sun.source.util.Plugin"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
123 |
Files.createDirectories(registration.getParent()); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
124 |
try (Writer metaInfServices = Files.newBufferedWriter(registration, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
125 |
metaInfServices.write("crules.CodingRulesAnalyzerPlugin\n"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
126 |
} |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
127 |
|
37850
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
128 |
//generate CompilerProperties.java: |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
129 |
List<File> propertiesParserFiles = |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
130 |
Files.walk(crulesDir.resolve("propertiesparser")) |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
131 |
.filter(entry -> entry.getFileName().toString().endsWith(".java")) |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
132 |
.map(entry -> entry.toFile()) |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
133 |
.collect(Collectors.toList()); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
134 |
|
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
135 |
Path propertiesParserTarget = targetDir.resolve("propertiesParser"); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
136 |
Files.createDirectories(propertiesParserTarget); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
137 |
List<String> propertiesParserOptions = Arrays.asList( |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
138 |
"-d", propertiesParserTarget.toString()); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
139 |
javaCompiler.getTask(null, fm, noErrors, propertiesParserOptions, null, |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
140 |
fm.getJavaFileObjectsFromFiles(propertiesParserFiles)).call(); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
141 |
|
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
142 |
Path genSrcTarget = targetDir.resolve("gensrc"); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
143 |
|
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
144 |
ClassLoader propertiesParserLoader = new URLClassLoader(new URL[] { |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
145 |
propertiesParserTarget.toUri().toURL(), |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
146 |
crulesDir.toUri().toURL() |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
147 |
}); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
148 |
Class propertiesParserClass = |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
149 |
Class.forName("propertiesparser.PropertiesParser", false, propertiesParserLoader); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
150 |
Method propertiesParserRun = |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
151 |
propertiesParserClass.getDeclaredMethod("run", String[].class, PrintStream.class); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
152 |
String compilerProperties = |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
153 |
"jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties"; |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
154 |
Path propertiesPath = mainSrcDir.resolve(compilerProperties.replace("/", FS)); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
155 |
Path genSrcTargetDir = genSrcTarget.resolve(mainSrcDir.relativize(propertiesPath.getParent())); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
156 |
|
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
157 |
Files.createDirectories(genSrcTargetDir); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
158 |
String[] propertiesParserRunOptions = new String[] { |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
159 |
"-compile", propertiesPath.toString(), genSrcTargetDir.toString() |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
160 |
}; |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
161 |
|
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
162 |
Object result = propertiesParserRun.invoke(null, propertiesParserRunOptions, System.err); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
163 |
|
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
164 |
if (!(result instanceof Boolean) || !(Boolean) result) { |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
165 |
throw new AssertionError("Cannot parse properties: " + result); |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
166 |
} |
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
167 |
|
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
168 |
//compile langtools sources with crules enabled: |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
169 |
List<File> sources = sourceDirs.stream() |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
170 |
.flatMap(dir -> silentFilesWalk(dir)) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
171 |
.filter(entry -> entry.getFileName().toString().endsWith(".java")) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
172 |
.map(p -> p.toFile()) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
173 |
.collect(Collectors.toList()); |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
174 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
175 |
Path sourceTarget = targetDir.resolve("classes"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
176 |
Files.createDirectories(sourceTarget); |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
177 |
String processorPath = crulesTarget + PS + crulesDir; |
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
178 |
|
36526 | 179 |
List<String> options = Arrays.asList( |
180 |
"-d", sourceTarget.toString(), |
|
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
38510
diff
changeset
|
181 |
"--module-source-path", mainSrcDir + FS + "*" + FS + "share" + FS + "classes" + PS |
37850
24e70308f4ea
8156000: tools/all/RunCodingRules.java fails if build dir exists, but generated sources do not
jlahoda
parents:
37848
diff
changeset
|
182 |
+ genSrcTarget + FS + "*" + FS + "share" + FS + "classes", |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36526
diff
changeset
|
183 |
"-XDaccessInternalAPI", |
36526 | 184 |
"-processorpath", processorPath, |
185 |
"-Xplugin:coding_rules"); |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
186 |
javaCompiler.getTask(null, fm, noErrors, options, null, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
187 |
fm.getJavaFileObjectsFromFiles(sources)).call(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26391
diff
changeset
|
188 |
} |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
189 |
} |
26391
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
190 |
|
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
191 |
Stream<Path> silentFilesWalk(Path dir) throws IllegalStateException { |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
192 |
try { |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
193 |
return Files.walk(dir); |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
194 |
} catch (IOException ex) { |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
195 |
throw new IllegalStateException(ex); |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
196 |
} |
c775a09a4faf
8054563: Update RunCodingRules.java for source code reorg
jlahoda
parents:
25848
diff
changeset
|
197 |
} |
25848
3bc09f4676a9
8043643: Add an crules analyzer avoiding string concatenation in messages of Assert checks.
jlahoda
parents:
diff
changeset
|
198 |
} |