public void testResourcesVisible() throws Exception { TreeLogger logger = TreeLogger.NULL; ModuleDef one = ModuleDefLoader.loadFromClassPath( logger, compilerContext, "com.google.gwt.dev.cfg.testdata.merging.One"); // Sees the logo.png image but not the java source file. assertEquals( one.getBuildResourceOracle().getPathNames(), Sets.newHashSet("com/google/gwt/dev/cfg/testdata/merging/resources/logo.png")); }
public void testWritesTargetLibraryProperties() throws UnableToCompleteException { compilerContext = compilerContextBuilder.compileMonolithic(false).build(); ModuleDef libraryOneModule = ModuleDefLoader.loadFromClassPath( TreeLogger.NULL, compilerContext, "com.google.gwt.dev.cfg.testdata.separate.libraryone.LibraryOne", false); // Library one sees all defined values for the "libraryTwoProperty" binding property and knows // which one was defined in this target library. for (BindingProperty bindingProperty : libraryOneModule.getProperties().getBindingProperties()) { if (!bindingProperty.getName().equals("libraryTwoProperty")) { continue; } assertEquals( Sets.newHashSet(bindingProperty.getDefinedValues()), Sets.newHashSet("yes", "no", "maybe")); assertEquals( Sets.newHashSet(bindingProperty.getTargetLibraryDefinedValues()), Sets.newHashSet("maybe")); } // Library one added a new defined value of "maybe" for the "libraryTwoProperty" binding // property. assertEquals( Sets.newHashSet( mockLibraryWriter.getNewBindingPropertyValuesByName().get("libraryTwoProperty")), Sets.newHashSet("maybe")); // Library one sees all defined values for the "libraryTwoConfigProperty" property and knows // which one was defined in this target library. for (ConfigurationProperty configurationProperty : libraryOneModule.getProperties().getConfigurationProperties()) { if (!configurationProperty.getName().equals("libraryTwoConfigProperty")) { continue; } assertEquals(Sets.newHashSet(configurationProperty.getValues()), Sets.newHashSet("false")); assertEquals( Sets.newHashSet(configurationProperty.getTargetLibraryValues()), Sets.newHashSet("false")); } // Library one added a new defined value of "maybe" for the "libraryTwoConfigProperty" // property. assertEquals( Sets.newHashSet( mockLibraryWriter .getNewConfigurationPropertyValuesByName() .get("libraryTwoConfigProperty")), Sets.newHashSet("false")); }
public void testSeparateModuleReferences() throws UnableToCompleteException { compilerContext = compilerContextBuilder.compileMonolithic(false).build(); ModuleDef libraryOneModule = ModuleDefLoader.loadFromClassPath( TreeLogger.NULL, compilerContext, "com.google.gwt.dev.cfg.testdata.separate.libraryone.LibraryOne", false); // The module sees itself and it's direct fileset module as "target" modules. assertEquals( Sets.newHashSet( "com.google.gwt.dev.cfg.testdata.separate.libraryone.LibraryOne", "com.google.gwt.dev.cfg.testdata.separate.filesetone.FileSetOne"), libraryOneModule.getTargetLibraryModuleNames()); // The module sees the referenced library module as a "library" module. assertEquals( Sets.newHashSet("com.google.gwt.dev.cfg.testdata.separate.librarytwo.LibraryTwo"), libraryOneModule.getExternalLibraryModuleNames()); }
public void assertHonorsStrictResources(boolean strictResources) throws UnableToCompleteException { TreeLogger logger = TreeLogger.NULL; compilerContext.getOptions().setEnforceStrictResources(strictResources); ModuleDef emptyModule = ModuleDefLoader.loadFromClassPath( logger, compilerContext, "com.google.gwt.dev.cfg.testdata.merging.Empty"); Resource sourceFile = emptyModule.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/InOne.java"); Resource publicFile = emptyModule.findPublicFile("Public.java"); if (strictResources) { // Empty.gwt.xml did not register any source or public paths and the strictResource setting is // blocking the implicit addition of any default entries. So these resource searches should // fail. assertNull(sourceFile); assertNull(publicFile); } else { assertNotNull(sourceFile); assertNotNull(publicFile); } }
public void testSeparateModuleResourcesLibraryOne() throws UnableToCompleteException { compilerContext = compilerContextBuilder.compileMonolithic(false).build(); ModuleDef libraryOneModule = ModuleDefLoader.loadFromClassPath( TreeLogger.NULL, compilerContext, "com.google.gwt.dev.cfg.testdata.separate.libraryone.LibraryOne", false); // Includes own source. assertNotNull( libraryOneModule.findSourceFile( "com/google/gwt/dev/cfg/testdata/separate/libraryone/client/LibraryOne.java")); // Cascades to include the subtree of fileset sources. assertNotNull( libraryOneModule.findSourceFile( "com/google/gwt/dev/cfg/testdata/separate/filesetone/client/FileSetOne.java")); // Does not include source from referenced libraries. assertNull( libraryOneModule.findSourceFile( "com/google/gwt/dev/cfg/testdata/separate/librarytwo/client/LibraryTwo.java")); }
public void testModuleNamingValid() throws Exception { TreeLogger logger = TreeLogger.NULL; ModuleDef module; module = ModuleDefLoader.loadFromClassPath( logger, compilerContext, "com.google.gwt.dev.cfg.testdata.naming.Foo-test"); assertNotNull(module.findSourceFile("com/google/gwt/dev/cfg/testdata/naming/client/Mock.java")); module = ModuleDefLoader.loadFromClassPath( logger, compilerContext, "com.google.gwt.dev.cfg.testdata.naming.7Foo"); assertNotNull(module.findSourceFile("com/google/gwt/dev/cfg/testdata/naming/client/Mock.java")); module = ModuleDefLoader.loadFromClassPath( logger, compilerContext, "com.google.gwt.dev.cfg.testdata.naming.Nested7Foo"); assertNotNull(module.findSourceFile("com/google/gwt/dev/cfg/testdata/naming/client/Mock.java")); module = ModuleDefLoader.loadFromClassPath( logger, compilerContext, "com.google.gwt.dev.cfg.testdata.naming.Nested7Foo"); assertNotNull(module.findSourceFile("com/google/gwt/dev/cfg/testdata/naming/client/Mock.java")); }
public void testModule() { Properties p = moduleDef.getProperties(); { BindingProperty restricted = (BindingProperty) p.find("restricted"); assertNotNull(restricted); assertEquals(3, restricted.getAllowedValues(restricted.getRootCondition()).length); assertEquals( Arrays.asList("a", "b", "c"), Arrays.asList(restricted.getAllowedValues(restricted.getRootCondition()))); assertTrue(restricted.isDefinedValue("d")); assertFalse(restricted.isAllowedValue("d")); } { BindingProperty restricted1s = (BindingProperty) p.find("restricted1s"); assertNotNull(restricted1s); assertTrue(restricted1s.isAllowedValue("a")); assertEquals(1, restricted1s.getAllowedValues(restricted1s.getRootCondition()).length); assertEquals("a", restricted1s.getAllowedValues(restricted1s.getRootCondition())[0]); } { BindingProperty conditional = (BindingProperty) p.find("conditional"); assertNotNull(conditional); assertFalse(conditional.isDerived()); Set<String> required = conditional.getRequiredProperties(); assertEquals(required.size(), 1); assertTrue(required.contains("restricted")); assertEquals(3, conditional.getConditionalValues().size()); Iterator<Condition> it = conditional.getConditionalValues().keySet().iterator(); assertEquals( Arrays.asList("a", "b", "c"), Arrays.asList(conditional.getAllowedValues(it.next()))); assertEquals(Arrays.asList("a", "b"), Arrays.asList(conditional.getAllowedValues(it.next()))); assertEquals(Arrays.asList("c"), Arrays.asList(conditional.getAllowedValues(it.next()))); } { Property configProperty = p.find("configProperty"); assertEquals("Hello World!", ((ConfigurationProperty) configProperty).getValue()); } { Property configRedefined = p.find("configRedefined"); assertEquals("bar", ((ConfigurationProperty) configRedefined).getValue()); } { BindingProperty derived = (BindingProperty) p.find("derived"); assertNotNull(derived); assertTrue(derived.isDerived()); Set<String> required = derived.getRequiredProperties(); assertEquals(required.size(), 1); assertTrue(required.contains("restricted")); assertEquals(3, derived.getConditionalValues().size()); } { BindingProperty reset = (BindingProperty) p.find("reset"); assertNotNull(reset); assertTrue(reset.isDerived()); Set<String> required = reset.getRequiredProperties(); assertEquals(0, required.size()); assertEquals(1, reset.getConditionalValues().size()); assertSame(reset.getRootCondition(), reset.getConditionalValues().keySet().iterator().next()); } }
/** * according to .gwt.xml files generates a LinkedMap which has interfaces as keys array of * generators as values keys are sorted according order of <generate-with> elements in .gwt.xml * files * * @param context * @throws UnableToCompleteException */ private void fillUpGeneratorChainMap(TreeLogger logger, GeneratorContext context) throws UnableToCompleteException { GeneratorChain.customGenerators = new LinkedList<AbstractGenerator>(); GeneratorChain.replacers = new LinkedList<AbstractGenerator>(); GeneratorChain.thirdPartyGenerators = new LinkedHashMap<Generator, AbstractGenerator>(); ModuleDef moduleDef = ((CompilerContext) getPrivateField(context, "compilerContext")).getModule(); Rules rules = moduleDef.getRules(); Iterator<Rule> rulesIter = rules.iterator(); while (rulesIter.hasNext()) { Rule rul = rulesIter.next(); Generator gen = null; // =================replace with if (rul instanceof RuleReplaceWith) { String replaceClass = (String) getPrivateField(rul, "replacementTypeName"); gen = new ReplaceByGenerator(replaceClass); // gen = null; // =================generate with } else if (rul instanceof RuleGenerateWith) { Class<? extends Generator> generatorClass = (Class<? extends Generator>) getPrivateField(rul, "generatorClass"); Constructor<?> constructor; try { constructor = generatorClass.getDeclaredConstructor(); } catch (Exception e) { logger.log( Type.ERROR, "Unable to obtain default constructor of generator " + generatorClass); throw new UnableToCompleteException(); } constructor.setAccessible(true); try { gen = (Generator) constructor.newInstance(); } catch (Exception e) { logger.log(Type.ERROR, "Unable to create instance of generator " + generatorClass); throw new UnableToCompleteException(); } } if (gen != null) { if (gen instanceof AbstractGenerator) { GenPredicGroup newGroup = null; AbstractGenerator myGen = (AbstractGenerator) gen; if (GeneratorChain.customGenerators.contains(gen) || GeneratorChain.replacers.contains(gen)) { newGroup = addPredicsToExisting(rul, myGen.getConditions()); myGen.setConditions(newGroup); } else { newGroup = getGroupConditions(rul.getRootCondition().getConditions(), null); myGen.setConditions(newGroup); if (gen instanceof ReplaceByGenerator) { GeneratorChain.replacers.addFirst(myGen); } else { GeneratorChain.customGenerators.addFirst(myGen); } } } else { if (GeneratorChain.thirdPartyGenerators.containsKey(gen)) { AbstractGenerator myGen = GeneratorChain.thirdPartyGenerators.get(gen); GenPredicGroup newGroup = addPredicsToExisting(rul, myGen.getConditions()); myGen.setConditions(newGroup); GeneratorChain.thirdPartyGenerators.put(gen, myGen); } else { AbstractGenerator myGen = new AbstractGenerator() { @Override public String doGenerate( TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { return null; } }; myGen.setConditions(getGroupConditions(rul.getRootCondition().getConditions(), null)); GeneratorChain.thirdPartyGenerators.put(gen, myGen); } } } } }
/** * Test of merging multiple modules in the same package space. This exercises the interaction of * include, exclude, and skip attributes. */ public void testModuleMerging() throws Exception { TreeLogger logger = TreeLogger.NULL; ModuleDef one = ModuleDefLoader.loadFromClassPath( logger, compilerContext, "com.google.gwt.dev.cfg.testdata.merging.One"); assertNotNull(one.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/InOne.java")); assertNotNull(one.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/Shared.java")); assertNull(one.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/InTwo.java")); assertNull(one.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/Toxic.java")); ModuleDef two = ModuleDefLoader.loadFromClassPath( logger, compilerContext, "com.google.gwt.dev.cfg.testdata.merging.Two"); assertNotNull(two.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/InOne.java")); assertNotNull(two.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/Shared.java")); assertNotNull(two.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/InTwo.java")); assertNull(two.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/Toxic.java")); ModuleDef three = ModuleDefLoader.loadFromClassPath( logger, compilerContext, "com.google.gwt.dev.cfg.testdata.merging.Three"); assertNotNull( three.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/InOne.java")); assertNotNull( three.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/Shared.java")); assertNull(three.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/InTwo.java")); assertNull(three.findSourceFile("com/google/gwt/dev/cfg/testdata/merging/client/Toxic.java")); }