Path: blob/master/test/langtools/tools/sjavac/Serialization.java
41144 views
/*1* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 803506326*27* @summary Tests serialization of options. The options needs to be serialized28* and saved in the state file since the files need to be recompiled29* if new options are provided.30*31* @modules jdk.compiler/com.sun.tools.sjavac32* jdk.compiler/com.sun.tools.sjavac.options33* @build Wrapper34* @run main Wrapper Serialization35*/3637import static util.OptionTestUtil.assertEquals;3839import java.io.IOException;40import java.util.Map;4142import com.sun.tools.sjavac.CompileJavaPackages;43import com.sun.tools.sjavac.Transformer;44import com.sun.tools.sjavac.options.Option;45import com.sun.tools.sjavac.options.Options;46import com.sun.tools.sjavac.options.SourceLocation;474849public class Serialization {5051public static void main(String[] args) throws IOException {5253// Create reference options54Options options1 = Options.parseArgs(55Option.H.arg, "headers",56Option.S.arg, "gensrc",57Option.D.arg, "dest",58Option.I.arg, "pkg/*",59Option.X.arg, "pkg/pkg/*",60Option.SRC.arg, "root",61Option.SOURCEPATH.arg, "sourcepath",62Option.CLASSPATH.arg, "classpath",63Option.MODULE_PATH.arg, "modulepath",64Option.PERMIT_SOURCES_WITHOUT_PACKAGE.arg,65Option.PERMIT_UNIDENTIFIED_ARTIFACTS.arg,66Option.TR.arg, ".prop=" + CompileJavaPackages.class.getName(),67Option.J.arg, "999",68"-someJavacArg",69"-someOtherJavacArg");7071// Serialize72String serialized = options1.getStateArgsString();7374// Deserialize75Options options2 = Options.parseArgs(serialized.split(" "));7677// Make sure we got the same result78assertEquals(options1.getHeaderDir(), options2.getHeaderDir());79assertEquals(options1.getGenSrcDir(), options2.getGenSrcDir());80assertEquals(options1.getDestDir(), options2.getDestDir());8182SourceLocation sl1 = options1.getSources().get(0);83SourceLocation sl2 = options2.getSources().get(0);84assertEquals(sl1.getPath(), sl2.getPath());85assertEquals(sl1.getIncludes(), sl2.getIncludes());86assertEquals(sl1.getExcludes(), sl2.getExcludes());8788assertEquals(options1.getClassSearchPath(), options2.getClassSearchPath());89assertEquals(options1.getSourceSearchPaths(), options2.getSourceSearchPaths());90assertEquals(options1.getModuleSearchPaths(), options2.getModuleSearchPaths());9192Map<String, Transformer> trRules1 = options1.getTranslationRules();93Map<String, Transformer> trRules2 = options2.getTranslationRules();94assertEquals(trRules1.keySet(), trRules2.keySet());95assertEquals(trRules1.values().iterator().next().getClass(),96trRules2.values().iterator().next().getClass());97assertEquals(options1.getJavacArgs(), options2.getJavacArgs());9899assertEquals(999, options1.getNumCores());100if (options2.getNumCores() == 999)101throw new AssertionError("Num cores should not be part of serialization");102}103104}105106107