Serialization.java revision 3195:88a874f33d6d
1168054Sflz/* 2168054Sflz * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. 3168054Sflz * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4168054Sflz * 5168064Sflz * This code is free software; you can redistribute it and/or modify it 6168064Sflz * under the terms of the GNU General Public License version 2 only, as 7168064Sflz * published by the Free Software Foundation. 8168064Sflz * 9168064Sflz * This code is distributed in the hope that it will be useful, but WITHOUT 10168064Sflz * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11168064Sflz * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12168064Sflz * version 2 for more details (a copy is included in the LICENSE file that 13168064Sflz * accompanied this code). 14168064Sflz * 15168064Sflz * You should have received a copy of the GNU General Public License version 16168064Sflz * 2 along with this work; if not, write to the Free Software Foundation, 17168064Sflz * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18168064Sflz * 19168054Sflz * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20168054Sflz * or visit www.oracle.com if you need additional information or have any 21168064Sflz * questions. 22168054Sflz */ 23168064Sflz 24168064Sflz/* 25168054Sflz * @test 26168054Sflz * @bug 8035063 27168054Sflz * 28168054Sflz * @summary Tests serialization of options. The options needs to be serialized 29168077Sflz * and saved in the state file since the files need to be recompiled 30168077Sflz * if new options are provided. 31168069Sgarga * 32168098Skrion * @modules jdk.compiler/com.sun.tools.sjavac 33168082Sgarga * jdk.compiler/com.sun.tools.sjavac.options 34168072Sehaupt * @build Wrapper 35168068Serwin * @run main Wrapper Serialization 36168072Sehaupt */ 37168059Sgabor 38168098Skrionimport static util.OptionTestUtil.assertEquals; 39168054Sflz 40168059Sgaborimport java.io.IOException; 41168054Sflzimport java.util.Map; 42168076Sjmelo 43168054Sflzimport com.sun.tools.sjavac.CompileJavaPackages; 44168055Spavimport com.sun.tools.sjavac.Transformer; 45168055Spavimport com.sun.tools.sjavac.options.Option; 46168098Skrionimport com.sun.tools.sjavac.options.Options; 47168055Spavimport com.sun.tools.sjavac.options.SourceLocation; 48168054Sflz 49168068Serwin 50168068Serwinpublic class Serialization { 51168055Spav 52168098Skrion public static void main(String[] args) throws IOException { 53168100Smnag 54168084Sehaupt // Create reference options 55168054Sflz Options options1 = Options.parseArgs( 56168098Skrion Option.H.arg, "headers", 57168098Skrion Option.S.arg, "gensrc", 58168098Skrion Option.D.arg, "dest", 59168098Skrion Option.I.arg, "pkg/*", 60168055Spav Option.X.arg, "pkg/pkg/*", 61168068Serwin Option.SRC.arg, "root", 62168061Sahze Option.SOURCEPATH.arg, "sourcepath", 63168069Sgarga Option.CLASSPATH.arg, "classpath", 64168054Sflz Option.MODULEPATH.arg, "modulepath", 65168054Sflz Option.PERMIT_SOURCES_WITHOUT_PACKAGE.arg, 66168064Sflz Option.PERMIT_UNIDENTIFIED_ARTIFACTS.arg, 67168064Sflz Option.TR.arg, ".prop=" + CompileJavaPackages.class.getName(), 68168054Sflz Option.J.arg, "999", 69168055Spav "-someJavacArg", 70168055Spav "-someOtherJavacArg"); 71168055Spav 72168055Spav // Serialize 73168055Spav String serialized = options1.getStateArgsString(); 74168055Spav 75168057Sahze // Deserialize 76168055Spav Options options2 = Options.parseArgs(serialized.split(" ")); 77168068Serwin 78168068Serwin // Make sure we got the same result 79168072Sehaupt assertEquals(options1.getHeaderDir(), options2.getHeaderDir()); 80168072Sehaupt assertEquals(options1.getGenSrcDir(), options2.getGenSrcDir()); 81168068Serwin assertEquals(options1.getDestDir(), options2.getDestDir()); 82168059Sgabor 83168068Serwin SourceLocation sl1 = options1.getSources().get(0); 84168068Serwin SourceLocation sl2 = options2.getSources().get(0); 85168068Serwin assertEquals(sl1.getPath(), sl2.getPath()); 86168059Sgabor assertEquals(sl1.getIncludes(), sl2.getIncludes()); 87168098Skrion assertEquals(sl1.getExcludes(), sl2.getExcludes()); 88168098Skrion 89168054Sflz assertEquals(options1.getClassSearchPath(), options2.getClassSearchPath()); 90168054Sflz assertEquals(options1.getSourceSearchPaths(), options2.getSourceSearchPaths()); 91168054Sflz assertEquals(options1.getModuleSearchPaths(), options2.getModuleSearchPaths()); 92168054Sflz 93168069Sgarga Map<String, Transformer> trRules1 = options1.getTranslationRules(); 94168069Sgarga Map<String, Transformer> trRules2 = options2.getTranslationRules(); 95168069Sgarga assertEquals(trRules1.keySet(), trRules2.keySet()); 96168069Sgarga assertEquals(trRules1.values().iterator().next().getClass(), 97168098Skrion trRules2.values().iterator().next().getClass()); 98168098Skrion assertEquals(options1.getJavacArgs(), options2.getJavacArgs()); 99168098Skrion 100168098Skrion assertEquals(999, options1.getNumCores()); 101168098Skrion if (options2.getNumCores() == 999) 102168098Skrion throw new AssertionError("Num cores should not be part of serialization"); 103168098Skrion } 104168098Skrion 105168076Sjmelo} 106168076Sjmelo