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

View File

@ -19,15 +19,15 @@
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
@ -35,7 +35,7 @@ public class HowPredicate implements Predicate
{
for (Selection selection : node.getSelections())
{
if (how.equalsIgnoreCase(selection.getHow()))
if (criteria.equalsIgnoreCase(selection.getCriteria()))
{
return true;
}

View File

@ -22,21 +22,21 @@ import java.util.HashSet;
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>
* 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;
}
Set<String> actualHows = node.getSelectedHowSet();
Set<String> actualCriterias = node.getSelectedCriteriaSet();
if (actualHows.size() != howSet.size())
if (actualCriterias.size() != criteriaSet.size())
{
// non-equal sized set
return false;
}
for (String how : actualHows)
for (String actualCriteria : actualCriterias)
{
if (!this.howSet.contains(how))
if (!this.criteriaSet.contains(actualCriteria))
{
return false;
}

View File

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

View File

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

View File

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

View File

@ -19,16 +19,16 @@
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.
*/
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
@ -45,11 +45,11 @@ public class HowUniquePredicate implements Predicate
for (Selection selection : node.getSelections())
{
if (how.equalsIgnoreCase(selection.getHow()))
if (criteria.equalsIgnoreCase(selection.getCriteria()))
{
// Found a match
ret = true;
continue; // this 'how' is always valid.
continue; // this criteria is always valid.
}
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.JettyBaseConfigSource;
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.RegexNamePredicate;
import org.eclipse.jetty.start.graph.Selection;
@ -479,12 +479,12 @@ public class ModulesTest
{
Module altMod = modules.get(expectedAlt);
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));
}
// 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
actualNames = new ArrayList<>();