464633 - Change Selection.how to Selection.criteria

This commit is contained in:
Joakim Erdfelt 2015-04-14 11:38:34 -07:00
parent d9ffed0a07
commit 76080faaf0
8 changed files with 71 additions and 64 deletions

View File

@ -30,8 +30,8 @@ import org.eclipse.jetty.start.builders.StartIniBuilder;
import org.eclipse.jetty.start.fileinits.MavenLocalRepoFileInitializer; import org.eclipse.jetty.start.fileinits.MavenLocalRepoFileInitializer;
import org.eclipse.jetty.start.fileinits.TestFileInitializer; import org.eclipse.jetty.start.fileinits.TestFileInitializer;
import org.eclipse.jetty.start.fileinits.UriFileInitializer; import org.eclipse.jetty.start.fileinits.UriFileInitializer;
import org.eclipse.jetty.start.graph.HowSetPredicate; import org.eclipse.jetty.start.graph.CriteriaSetPredicate;
import org.eclipse.jetty.start.graph.HowUniquePredicate; import org.eclipse.jetty.start.graph.UniqueCriteriaPredicate;
import org.eclipse.jetty.start.graph.Predicate; import org.eclipse.jetty.start.graph.Predicate;
import org.eclipse.jetty.start.graph.Selection; import org.eclipse.jetty.start.graph.Selection;
@ -137,10 +137,10 @@ public class BaseBuilder
Modules modules = startArgs.getAllModules(); Modules modules = startArgs.getAllModules();
boolean dirty = false; boolean dirty = false;
String dirSource = "<add-to-startd>"; String dirCriteria = "<add-to-startd>";
String iniSource = "<add-to-start-ini>"; String iniCriteria = "<add-to-start-ini>";
Selection startDirSelection = new Selection(dirSource); Selection startDirSelection = new Selection(dirCriteria);
Selection startIniSelection = new Selection(iniSource); Selection startIniSelection = new Selection(iniCriteria);
List<String> startDNames = new ArrayList<>(); List<String> startDNames = new ArrayList<>();
startDNames.addAll(startArgs.getAddToStartdIni()); startDNames.addAll(startArgs.getAddToStartdIni());
@ -152,7 +152,7 @@ public class BaseBuilder
count += modules.selectNodes(startIniNames,startIniSelection); count += modules.selectNodes(startIniNames,startIniSelection);
// look for ambiguous declaration found in both places // look for ambiguous declaration found in both places
Predicate ambiguousPredicate = new HowSetPredicate(dirSource,iniSource); Predicate ambiguousPredicate = new CriteriaSetPredicate(dirCriteria,iniCriteria);
List<Module> ambiguous = modules.getMatching(ambiguousPredicate); List<Module> ambiguous = modules.getMatching(ambiguousPredicate);
if (ambiguous.size() > 0) if (ambiguous.size() > 0)
@ -179,9 +179,9 @@ public class BaseBuilder
ackLicenses(); ackLicenses();
// Collect specific modules to enable // Collect specific modules to enable
// Should match 'how', with no other selections.explicit // Should match 'criteria', with no other selections.explicit
Predicate startDMatcher = new HowUniquePredicate(dirSource); Predicate startDMatcher = new UniqueCriteriaPredicate(dirCriteria);
Predicate startIniMatcher = new HowUniquePredicate(iniSource); Predicate startIniMatcher = new UniqueCriteriaPredicate(iniCriteria);
List<Module> startDModules = modules.getMatching(startDMatcher); List<Module> startDModules = modules.getMatching(startDMatcher);
List<Module> startIniModules = modules.getMatching(startIniMatcher); List<Module> startIniModules = modules.getMatching(startIniMatcher);

View File

@ -19,15 +19,15 @@
package org.eclipse.jetty.start.graph; package org.eclipse.jetty.start.graph;
/** /**
* Predicate against a specific {@link Selection#getHow()} * Predicate against a specific {@link Selection#getCriteria()}
*/ */
public class HowPredicate implements Predicate public class CriteriaPredicate implements Predicate
{ {
private final String how; private final String criteria;
public HowPredicate(String how) public CriteriaPredicate(String criteria)
{ {
this.how = how; this.criteria = criteria;
} }
@Override @Override
@ -35,7 +35,7 @@ public class HowPredicate implements Predicate
{ {
for (Selection selection : node.getSelections()) for (Selection selection : node.getSelections())
{ {
if (how.equalsIgnoreCase(selection.getHow())) if (criteria.equalsIgnoreCase(selection.getCriteria()))
{ {
return true; return true;
} }

View File

@ -22,21 +22,21 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
* Should match against the provided set of {@link Selection#getHow()} values. * Should match against the provided set of {@link Selection#getCriteria()} values.
* <p> * <p>
* Incomplete set is considered to be no-match. * Incomplete set is considered to be no-match.
*/ */
public class HowSetPredicate implements Predicate public class CriteriaSetPredicate implements Predicate
{ {
private final Set<String> howSet; private final Set<String> criteriaSet;
public HowSetPredicate(String... hows) public CriteriaSetPredicate(String... criterias)
{ {
this.howSet = new HashSet<>(); this.criteriaSet = new HashSet<>();
for (String name : hows) for (String name : criterias)
{ {
this.howSet.add(name); this.criteriaSet.add(name);
} }
} }
@ -50,17 +50,17 @@ public class HowSetPredicate implements Predicate
return false; return false;
} }
Set<String> actualHows = node.getSelectedHowSet(); Set<String> actualCriterias = node.getSelectedCriteriaSet();
if (actualHows.size() != howSet.size()) if (actualCriterias.size() != criteriaSet.size())
{ {
// non-equal sized set // non-equal sized set
return false; return false;
} }
for (String how : actualHows) for (String actualCriteria : actualCriterias)
{ {
if (!this.howSet.contains(how)) if (!this.criteriaSet.contains(actualCriteria))
{ {
return false; return false;
} }

View File

@ -223,16 +223,16 @@ public abstract class Graph<T extends Node<T>> implements Iterable<T>
} }
else else
{ {
List<String> hows = new ArrayList<>(); List<String> criterias = new ArrayList<>();
for (Selection selection : module.getSelections()) for (Selection selection : module.getSelections())
{ {
if (selection.isExplicit()) if (selection.isExplicit())
{ {
hows.add(selection.getHow()); criterias.add(selection.getCriteria());
} }
} }
Collections.sort(hows); Collections.sort(criterias);
System.out.println(Utils.join(hows,", ")); System.out.println(Utils.join(criterias,", "));
} }
} }
} }

View File

@ -131,14 +131,14 @@ public abstract class Node<T>
return selections; return selections;
} }
public Set<String> getSelectedHowSet() public Set<String> getSelectedCriteriaSet()
{ {
Set<String> hows = new HashSet<>(); Set<String> criteriaSet = new HashSet<>();
for (Selection selection : selections) for (Selection selection : selections)
{ {
hows.add(selection.getHow()); criteriaSet.add(selection.getCriteria());
} }
return hows; return criteriaSet;
} }
public boolean isSelected() public boolean isSelected()

View File

@ -19,26 +19,33 @@
package org.eclipse.jetty.start.graph; package org.eclipse.jetty.start.graph;
/** /**
* Represents a selection technique. * Represents a selection criteria.
* <p> * <p>
* Each <code>Selection</code> can be used [0..n] times in the graph. * Each <code>Selection</code> can be used [0..n] times in the graph. The <code>Selection</code> must contain a unique
* The <code>Selection</code> must contain a unique 'how' description that represents * 'criteria' description that how selection was determined.
* how this selection was determined (what criteria the selection underwent)
* </p> * </p>
*/ */
public class Selection public class Selection
{ {
private final boolean explicit; private final boolean explicit;
private final String how; private final String criteria;
public Selection(String how) public Selection(String criteria)
{ {
this(how,true); this(criteria,true);
} }
public Selection(String how, boolean explicit) /**
* The Selection criteria
*
* @param criteria
* the selection criteria
* @param explicit
* true if explicitly selected, false if transitively selected.
*/
public Selection(String criteria, boolean explicit)
{ {
this.how = how; this.criteria = criteria;
this.explicit = explicit; this.explicit = explicit;
} }
@ -46,7 +53,7 @@ public class Selection
{ {
if (this.explicit) if (this.explicit)
{ {
return new Selection(how,false); return new Selection(criteria,false);
} }
return this; return this;
} }
@ -71,14 +78,14 @@ public class Selection
{ {
return false; return false;
} }
if (how == null) if (criteria == null)
{ {
if (other.how != null) if (other.criteria != null)
{ {
return false; return false;
} }
} }
else if (!how.equals(other.how)) else if (!criteria.equals(other.criteria))
{ {
return false; return false;
} }
@ -86,11 +93,11 @@ public class Selection
} }
/** /**
* Get how this node was selected. * Get the criteria for this selection
*/ */
public String getHow() public String getCriteria()
{ {
return how; return criteria;
} }
@Override @Override
@ -98,8 +105,8 @@ public class Selection
{ {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = (prime * result) + (explicit?1231:1237); result = (prime * result) + (explicit ? 1231 : 1237);
result = (prime * result) + ((how == null)?0:how.hashCode()); result = (prime * result) + ((criteria == null) ? 0 : criteria.hashCode());
return result; return result;
} }
@ -116,7 +123,7 @@ public class Selection
{ {
str.append("<transitive from> "); str.append("<transitive from> ");
} }
str.append(how); str.append(criteria);
return str.toString(); return str.toString();
} }
} }

View File

@ -19,16 +19,16 @@
package org.eclipse.jetty.start.graph; package org.eclipse.jetty.start.graph;
/** /**
* Match against a specific {@link Selection#getHow()}, where * Match against a specific {@link Selection#getCriteria()}, where
* there are no other {@link Selection#isExplicit()} specified. * there are no other {@link Selection#isExplicit()} specified.
*/ */
public class HowUniquePredicate implements Predicate public class UniqueCriteriaPredicate implements Predicate
{ {
private final String how; private final String criteria;
public HowUniquePredicate(String how) public UniqueCriteriaPredicate(String criteria)
{ {
this.how = how; this.criteria = criteria;
} }
@Override @Override
@ -45,11 +45,11 @@ public class HowUniquePredicate implements Predicate
for (Selection selection : node.getSelections()) for (Selection selection : node.getSelections())
{ {
if (how.equalsIgnoreCase(selection.getHow())) if (criteria.equalsIgnoreCase(selection.getCriteria()))
{ {
// Found a match // Found a match
ret = true; ret = true;
continue; // this 'how' is always valid. continue; // this criteria is always valid.
} }
else if (selection.isExplicit()) else if (selection.isExplicit())
{ {

View File

@ -28,7 +28,7 @@ import org.eclipse.jetty.start.config.CommandLineConfigSource;
import org.eclipse.jetty.start.config.ConfigSources; import org.eclipse.jetty.start.config.ConfigSources;
import org.eclipse.jetty.start.config.JettyBaseConfigSource; import org.eclipse.jetty.start.config.JettyBaseConfigSource;
import org.eclipse.jetty.start.config.JettyHomeConfigSource; import org.eclipse.jetty.start.config.JettyHomeConfigSource;
import org.eclipse.jetty.start.graph.HowSetPredicate; import org.eclipse.jetty.start.graph.CriteriaSetPredicate;
import org.eclipse.jetty.start.graph.Predicate; import org.eclipse.jetty.start.graph.Predicate;
import org.eclipse.jetty.start.graph.RegexNamePredicate; import org.eclipse.jetty.start.graph.RegexNamePredicate;
import org.eclipse.jetty.start.graph.Selection; import org.eclipse.jetty.start.graph.Selection;
@ -479,12 +479,12 @@ public class ModulesTest
{ {
Module altMod = modules.get(expectedAlt); Module altMod = modules.get(expectedAlt);
assertThat("Alt.mod[" + expectedAlt + "].selected",altMod.isSelected(),is(true)); assertThat("Alt.mod[" + expectedAlt + "].selected",altMod.isSelected(),is(true));
Set<String> sources = altMod.getSelectedHowSet(); Set<String> sources = altMod.getSelectedCriteriaSet();
assertThat("Alt.mod[" + expectedAlt + "].sources: [" + Utils.join(sources,", ") + "]",sources,contains(alt)); assertThat("Alt.mod[" + expectedAlt + "].sources: [" + Utils.join(sources,", ") + "]",sources,contains(alt));
} }
// Now collect the unique source list // Now collect the unique source list
List<Module> alts = modules.getMatching(new HowSetPredicate(alt)); List<Module> alts = modules.getMatching(new CriteriaSetPredicate(alt));
// Assert names are correct, and in the right order // Assert names are correct, and in the right order
actualNames = new ArrayList<>(); actualNames = new ArrayList<>();