Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/sjavac/Serialization.java
41144 views
1
/*
2
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8035063
27
*
28
* @summary Tests serialization of options. The options needs to be serialized
29
* and saved in the state file since the files need to be recompiled
30
* if new options are provided.
31
*
32
* @modules jdk.compiler/com.sun.tools.sjavac
33
* jdk.compiler/com.sun.tools.sjavac.options
34
* @build Wrapper
35
* @run main Wrapper Serialization
36
*/
37
38
import static util.OptionTestUtil.assertEquals;
39
40
import java.io.IOException;
41
import java.util.Map;
42
43
import com.sun.tools.sjavac.CompileJavaPackages;
44
import com.sun.tools.sjavac.Transformer;
45
import com.sun.tools.sjavac.options.Option;
46
import com.sun.tools.sjavac.options.Options;
47
import com.sun.tools.sjavac.options.SourceLocation;
48
49
50
public class Serialization {
51
52
public static void main(String[] args) throws IOException {
53
54
// Create reference options
55
Options options1 = Options.parseArgs(
56
Option.H.arg, "headers",
57
Option.S.arg, "gensrc",
58
Option.D.arg, "dest",
59
Option.I.arg, "pkg/*",
60
Option.X.arg, "pkg/pkg/*",
61
Option.SRC.arg, "root",
62
Option.SOURCEPATH.arg, "sourcepath",
63
Option.CLASSPATH.arg, "classpath",
64
Option.MODULE_PATH.arg, "modulepath",
65
Option.PERMIT_SOURCES_WITHOUT_PACKAGE.arg,
66
Option.PERMIT_UNIDENTIFIED_ARTIFACTS.arg,
67
Option.TR.arg, ".prop=" + CompileJavaPackages.class.getName(),
68
Option.J.arg, "999",
69
"-someJavacArg",
70
"-someOtherJavacArg");
71
72
// Serialize
73
String serialized = options1.getStateArgsString();
74
75
// Deserialize
76
Options options2 = Options.parseArgs(serialized.split(" "));
77
78
// Make sure we got the same result
79
assertEquals(options1.getHeaderDir(), options2.getHeaderDir());
80
assertEquals(options1.getGenSrcDir(), options2.getGenSrcDir());
81
assertEquals(options1.getDestDir(), options2.getDestDir());
82
83
SourceLocation sl1 = options1.getSources().get(0);
84
SourceLocation sl2 = options2.getSources().get(0);
85
assertEquals(sl1.getPath(), sl2.getPath());
86
assertEquals(sl1.getIncludes(), sl2.getIncludes());
87
assertEquals(sl1.getExcludes(), sl2.getExcludes());
88
89
assertEquals(options1.getClassSearchPath(), options2.getClassSearchPath());
90
assertEquals(options1.getSourceSearchPaths(), options2.getSourceSearchPaths());
91
assertEquals(options1.getModuleSearchPaths(), options2.getModuleSearchPaths());
92
93
Map<String, Transformer> trRules1 = options1.getTranslationRules();
94
Map<String, Transformer> trRules2 = options2.getTranslationRules();
95
assertEquals(trRules1.keySet(), trRules2.keySet());
96
assertEquals(trRules1.values().iterator().next().getClass(),
97
trRules2.values().iterator().next().getClass());
98
assertEquals(options1.getJavacArgs(), options2.getJavacArgs());
99
100
assertEquals(999, options1.getNumCores());
101
if (options2.getNumCores() == 999)
102
throw new AssertionError("Num cores should not be part of serialization");
103
}
104
105
}
106
107