@Test
  public void testProcessDep_withConditionalizedAlias() throws Exception {
    DependencyList depList =
        new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false);
    configRef.set(
        new ConfigImpl(
            mockAggregator,
            tmpDir,
            "{aliases:[[/^foo\\//, function(s){return (has('test')?'xxx':'yyy')+'/'}]]}"));
    depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null);
    assertEquals(
        new HashSet<String>(Arrays.asList(new String[] {"yyy/test"})), explicitDeps.getModuleIds());
    assertEquals(
        new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures());
    depList.getDependentFeatures().clear();

    explicitDeps = new ModuleDeps();
    features.put("test", true);
    depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null);
    assertEquals(
        new HashSet<String>(Arrays.asList(new String[] {"xxx/test"})), explicitDeps.getModuleIds());
    assertEquals(
        new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures());
    depList.getDependentFeatures().clear();

    explicitDeps = new ModuleDeps();
    features.put("test", false);
    depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null);
    assertEquals(
        new HashSet<String>(Arrays.asList(new String[] {"yyy/test"})), explicitDeps.getModuleIds());
    assertEquals(
        new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures());
  }
 @Test
 public void testProcessDep_withCompoundHasExpressionAndDefinedFeatures() throws Exception {
   // Defined features should have no impact on results.
   features.put("test", true);
   features.put("test1", false);
   features.put("test2", false);
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false);
   depList.processDep(
       "dojo/has!test?test1?foo1/test:bar1/test:test2:foo2/test:bar2/test",
       explicitDeps,
       null,
       new HashSet<String>(),
       null);
   assertEquals(5, explicitDeps.size());
   assertEquals(
       new HashSet<String>(
           Arrays.asList(
               new String[] {
                 "dojo/has",
                 "dojo/has!test?test1?foo1/test",
                 "dojo/has!test?test1?:bar1/test",
                 "dojo/has!test?:test2?foo2/test",
                 "dojo/has!test?:test2?:bar2/test"
               })),
       explicitDeps.getModuleIds());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"test", "test1", "test2"})),
       depList.getDependentFeatures());
 }
Пример #3
0
 public ModuleDeps evaluateAll(
     String pluginName,
     Features features,
     Set<String> discovered,
     ModuleDepInfo terms,
     String comment) {
   ModuleDeps results = new ModuleDeps();
   evaluateAll(pluginName, features, discovered, BooleanTerm.TRUE, results, comment);
   return results.andWith(terms);
 }
 @Test
 public void loggingTests_withImplicitPluginDependency() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, true);
   depList.processDep("foo/plugin!foo/bar", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(2, explicitDeps.size());
   assertEquals(Messages.DependencyList_1, explicitDeps.get("foo/plugin").getComment());
   assertEquals(
       MessageFormat.format(Messages.DependencyList_5, "test"),
       explicitDeps.get("foo/plugin!foo/bar").getComment());
 }
 @Test
 public void loggingTests_simple() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, true);
   depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(1, explicitDeps.size());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"foo/test"})), explicitDeps.getModuleIds());
   assertEquals(
       MessageFormat.format(Messages.DependencyList_5, "test"),
       explicitDeps.get("foo/test").getComment().trim());
 }
 @Test
 public void loggingTests_withHasBranching() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, true);
   depList.processDep(
       "dojo/has!test?foo/test:bar/test", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(3, explicitDeps.size());
   assertEquals(Messages.DependencyList_1, explicitDeps.get("dojo/has").getComment());
   String msg =
       MessageFormat.format(
           Messages.DependencyList_2, new Object[] {"dojo/has!test?foo/test:bar/test"});
   assertEquals(msg, explicitDeps.get("foo/test").getComment());
   assertEquals(msg, explicitDeps.get("bar/test").getComment());
 }
 @Test
 public void loggingTests_withAliasing() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, true);
   configRef.set(new ConfigImpl(mockAggregator, tmpDir, "{aliases:[['foo/test', 'foo/bar']]}"));
   depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(1, explicitDeps.size());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"foo/bar"})), explicitDeps.getModuleIds());
   assertEquals(
       MessageFormat.format(Messages.DependencyList_5, "test")
           + ", Aliased from: foo/test --> foo/bar",
       explicitDeps.get("foo/bar").getComment());
 }
 @Test
 public void hasBranchingDisabledTests_withDefinedFeature() throws Exception {
   mockAggregator.getOptions().setOption(IOptions.DISABLE_HASPLUGINBRANCHING, true);
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false);
   features.put("test", true);
   depList.processDep(
       "dojo/has!test?foo/test:bar/test", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(2, explicitDeps.size());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"dojo/has", "foo/test"})),
       explicitDeps.getModuleIds());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures());
 }
Пример #9
0
 private void evaluateAll(
     String pluginName,
     Features features,
     Set<String> discovered,
     BooleanTerm term,
     ModuleDeps results,
     String comment) {
   if (feature != null && discovered != null) {
     discovered.add(feature);
   }
   if (feature == null) {
     if (nodeName != null && nodeName.length() > 0) {
       results.add(nodeName, new ModuleDepInfo(pluginName, term, comment, true));
     }
   } else if (!features.contains(feature)) {
     BooleanTerm newTerm = term.andWith(new BooleanTerm(new BooleanVar(feature, true)));
     trueNode.evaluateAll(pluginName, features, discovered, newTerm, results, comment);
     newTerm = term.andWith(new BooleanTerm(new BooleanVar(feature, false)));
     falseNode.evaluateAll(pluginName, features, discovered, newTerm, results, comment);
   } else {
     if (features.isFeature(feature)) {
       trueNode.evaluateAll(pluginName, features, discovered, term, results, comment);
     } else {
       falseNode.evaluateAll(pluginName, features, discovered, term, results, comment);
     }
   }
 }
 @Test
 public void testProcessDep_simple() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false);
   depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"foo/test"})), explicitDeps.getModuleIds());
   assertTrue(depList.getDependentFeatures().isEmpty());
 }
 @Test
 public void testProcessDep_withAlias() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false);
   configRef.set(new ConfigImpl(mockAggregator, tmpDir, "{aliases:[['foo/test', 'bar/test']]}"));
   depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"bar/test"})), explicitDeps.getModuleIds());
   assertTrue(depList.getDependentFeatures().isEmpty());
 }
 @Test
 public void testProcessDep_withHasPluginTermsThatCancel() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false);
   depList.processDep(
       "dojo/has!test?foo/test:foo/test", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"dojo/has", "foo/test"})),
       explicitDeps.getModuleIds());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures());
 }
 @Test
 public void resolveAliasesDisabledAndHasBranchingDisabled_withDefinedFeatures() throws Exception {
   mockAggregator.getOptions().setOption(IOptions.DISABLE_HASPLUGINBRANCHING, true);
   configRef.set(new ConfigImpl(mockAggregator, tmpDir, "{aliases:[['foo1/test', 'bar/test']]}"));
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, false, false);
   features.put("test", true);
   features.put("test1", true);
   depList.processDep(
       "dojo/has!test?test1?foo1/test:bar1/test:test2:foo2/test:bar2/test",
       explicitDeps,
       null,
       new HashSet<String>(),
       null);
   assertEquals(2, explicitDeps.size());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"dojo/has", "foo1/test"})),
       explicitDeps.getModuleIds());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"test", "test1"})),
       depList.getDependentFeatures());
 }
 @Test
 public void testProcessDep_withAliasedPluginAndModule() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false);
   configRef.set(
       new ConfigImpl(
           mockAggregator,
           tmpDir,
           "{aliases:[[/^foo\\//, function(s){return (has('testFoo')?'xxx':'yyy')+'/'}],[/^bar\\//, function(s){return (has('testBar')?'www':'zzz')+'/'}]]}"));
   depList.processDep("bar/plugin!foo/test", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"zzz/plugin!yyy/test", "zzz/plugin"})),
       explicitDeps.getModuleIds());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"testFoo", "testBar"})),
       depList.getDependentFeatures());
 }
 @Test
 public void testProcessDep_withAliasIntroducedHasPlugin() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false);
   configRef.set(
       new ConfigImpl(
           mockAggregator,
           tmpDir,
           "{aliases:[['foo/test', 'dojo/has!test?foo/fooTest:foo/barTest']]}"));
   depList.processDep("foo/test", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(
       new HashSet<String>(
           Arrays.asList(
               new String[] {
                 "dojo/has", "dojo/has!test?foo/fooTest", "dojo/has!test?:foo/barTest"
               })),
       explicitDeps.getModuleIds());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"test"})), depList.getDependentFeatures());
 }
 @Test
 public void testProcessDep_withCompoundHasBranchingWithAliasResolution() throws Exception {
   DependencyList depList =
       new DependencyList("test", new HashSet<String>(), mockAggregator, features, true, false);
   configRef.set(
       new ConfigImpl(
           mockAggregator,
           tmpDir,
           "{aliases:[['foo/bar', 'dojo/has!test1?foo/test:bar/test'],['bar/test','dojo/has!test2?foo/xxx:foo/yyy']]}"));
   depList.processDep("foo/bar", explicitDeps, null, new HashSet<String>(), null);
   assertEquals(
       new HashSet<String>(
           Arrays.asList(
               new String[] {
                 "dojo/has",
                 "dojo/has!test1?foo/test",
                 "dojo/has!test1?:test2?foo/xxx",
                 "dojo/has!test1?:test2?:foo/yyy"
               })),
       explicitDeps.getModuleIds());
   assertEquals(
       new HashSet<String>(Arrays.asList(new String[] {"test1", "test2"})),
       depList.getDependentFeatures());
 }