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