Package com.crawljax.fragmentation
Class FragmentManager
- java.lang.Object
-
- com.crawljax.fragmentation.FragmentManager
-
public class FragmentManager extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFragmentManager.ACCESS
-
Field Summary
Fields Modifier and Type Field Description (package private) ArrayList<Fragment>fragmentsGlobal list of unique fragments(package private) HashMap<Integer,Double>hopsprivate static org.slf4j.LoggerLOG(package private) List<Set<StateVertex>>nearDuplicatesGlobal map that maintains clusters of states.private HashMap<Integer,Double>numNonSelectionsprivate javax.inject.Provider<InMemoryStateFlowGraph>sfg(package private) HashMap<StatePair,StatePair>stateComparisionCachestatic FragmentRulesUSEFUL_FRAGMENT_RULES
-
Constructor Summary
Constructors Constructor Description FragmentManager(javax.inject.Provider<InMemoryStateFlowGraph> graphProvider)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFragment(Fragment fragment, boolean fast)Every fragment that is discovered during the crawl will be compared with the global map of unique fragmentsprivate voidaddToNearDuplicates(StateVertex state)private voidaddToNearDuplicates(StateVertex newState, StateVertex expectedState)StatePair.StateComparisionareND2(StateVertex newState, StateVertex expectedState)Uses mapping of leaf fragments to determine if given two states are near-duplicatesbooleanareRelated(Fragment frag, Fragment frag2)voidcacheStateComparision(StatePair statePair, boolean assignDynamic)StatePair.StateComparisioncacheStateComparision(StateVertex newState, StateVertex expectedState, boolean assignDynamic)The main function that compares two given states and outputs a classification [clone, near-duplicates (ND-data ND-struct), different]voidcacheStateComparisions(StateVertex newState)doublecalculateCandidateInfluence(CandidateElement candidate)doublecalculateDuplicationFactor(CandidateElement element, StateVertex state)private doublecalculateFragmentCandidateInfluence(Fragment fragment)private doublecalculateHops(Fragment fragment, StateVertex currentState, List<StateVertex> onURLSet)booleancompareImages(BufferedImage image1, BufferedImage image2)Color histogram comparisonprivate List<Fragment>getAffectedFragments(List<Node> changedNodes, StateVertex state)Computes which fragments contain the changed nodes.List<Fragment>getAllFragments()StatePairgetCachedComparision(StateVertex state1, StateVertex state2)StateVertexgetClosestUnexploredState(StateVertex currentState, List<StateVertex> onURLSet, BlockingQueue<Integer> statesWithCandidates, boolean applyNonSelAdvantage)Computes the influences of the states based on the influence of candidates and returns the state that has the highest priority Also takes into consideration the back-tracking effort required to reach the stateArrayList<Fragment>getDuplicateFragments(Fragment fragment)ArrayList<Fragment>getEquivalentFragments(Fragment fragment)private static intgetFragmentWidth(Fragment fragment)HashMap<Integer,Integer>getLeafFragmentMapping(StateVertex state1, StateVertex state2)static List<Fragment>getLeafFragments(List<Fragment> fragments)Leaf fragments are fragments that do not have any useful child fragmentsList<Set<StateVertex>>getNearDuplicates()private Set<StateVertex>getNearDuplicates(StateVertex state)ArrayList<Fragment>getRelatedFragments(Fragment fragment)Set<StatePair>getStateComparisionCache()private booleanhasExploredNearDuplicate(StateVertex state)booleanrecordAccess(CandidateElement element, StateVertex state)Called after a crawl action is performed.booleanrecordCoverage(Node node, StateVertex state, VipsUtils.Coverage coverage)Can be invoked from a coverage plugin to determine how much of the state DOM is covered by test suitesprivate voidrecordDuplicateAccess(CandidateElement element, ArrayList<CandidateElement> coveredCandidates, Fragment closestFragment)private voidrecordEquivalentAccess(CandidateElement element, ArrayList<CandidateElement> coveredCandidates, Fragment closestFragment)private voidrecordNearDuplicateAccess(CandidateElement element, StateVertex state)voidseenState(StateVertex currentState)Updates no of times state has not been polled during crawl (Helps prevent crawler getting stuck in similar states)voidsetAccess(StateVertex state)voidsetAccess(Fragment newFragment)Used to transfer information regarding already performed actions that can have duplicates in this new-fragmentvoidsetCoverage(Fragment newFragment)private voidsetDynamic(Fragment dyn)static voidsetThresholds(FragmentRules fragRules)voidstopCrawling()voidupdateInfluence(Fragment fragment, FragmentManager.ACCESS access)After every action is performed, the priority score or influence is adjustedstatic booleanusefulFragment(Fragment fragment)To decide if the fragment is large enough to be a functional entity This is an approximation and can be configured usingFragmentRules
-
-
-
Field Detail
-
USEFUL_FRAGMENT_RULES
public static FragmentRules USEFUL_FRAGMENT_RULES
-
LOG
private static final org.slf4j.Logger LOG
-
nearDuplicates
List<Set<StateVertex>> nearDuplicates
Global map that maintains clusters of states. Each entry in the list is a set of states that are near-duplicates to each other
-
sfg
private javax.inject.Provider<InMemoryStateFlowGraph> sfg
-
-
Constructor Detail
-
FragmentManager
public FragmentManager(javax.inject.Provider<InMemoryStateFlowGraph> graphProvider)
-
-
Method Detail
-
getFragmentWidth
private static int getFragmentWidth(Fragment fragment) throws XPathExpressionException
- Throws:
XPathExpressionException
-
usefulFragment
public static boolean usefulFragment(Fragment fragment)
To decide if the fragment is large enough to be a functional entity This is an approximation and can be configured usingFragmentRules- Parameters:
fragment-- Returns:
-
getLeafFragments
public static List<Fragment> getLeafFragments(List<Fragment> fragments)
Leaf fragments are fragments that do not have any useful child fragments- Parameters:
fragments-- Returns:
-
setThresholds
public static void setThresholds(FragmentRules fragRules)
-
getNearDuplicates
public List<Set<StateVertex>> getNearDuplicates()
-
getCachedComparision
public StatePair getCachedComparision(StateVertex state1, StateVertex state2)
-
cacheStateComparision
public void cacheStateComparision(StatePair statePair, boolean assignDynamic)
-
setDynamic
private void setDynamic(Fragment dyn)
-
setCoverage
public void setCoverage(Fragment newFragment)
-
setAccess
public void setAccess(Fragment newFragment)
Used to transfer information regarding already performed actions that can have duplicates in this new-fragment- Parameters:
newFragment- a fragment that is being added to the graph
-
addFragment
public void addFragment(Fragment fragment, boolean fast)
Every fragment that is discovered during the crawl will be compared with the global map of unique fragments- Parameters:
fragment- the fragment to be addedfast- if true, the comparison will be done using the fast comparison algorithm
-
updateInfluence
public void updateInfluence(Fragment fragment, FragmentManager.ACCESS access)
After every action is performed, the priority score or influence is adjusted- Parameters:
fragment- the fragment that was just visitedaccess- the type of access that was performed
-
recordCoverage
public boolean recordCoverage(Node node, StateVertex state, VipsUtils.Coverage coverage)
Can be invoked from a coverage plugin to determine how much of the state DOM is covered by test suites- Parameters:
node- the node to be checkedstate- the state to be checkedcoverage- the coverage type- Returns:
- true if the coverage was recorded, false otherwise
-
recordAccess
public boolean recordAccess(CandidateElement element, StateVertex state)
Called after a crawl action is performed. Priority of the remaining candidate elements is updated based on their relationship with the action perfomed.- Parameters:
element-state-- Returns:
-
recordNearDuplicateAccess
private void recordNearDuplicateAccess(CandidateElement element, StateVertex state)
-
recordEquivalentAccess
private void recordEquivalentAccess(CandidateElement element, ArrayList<CandidateElement> coveredCandidates, Fragment closestFragment)
-
recordDuplicateAccess
private void recordDuplicateAccess(CandidateElement element, ArrayList<CandidateElement> coveredCandidates, Fragment closestFragment)
-
getNearDuplicates
private Set<StateVertex> getNearDuplicates(StateVertex state)
-
setAccess
public void setAccess(StateVertex state)
-
getClosestUnexploredState
public StateVertex getClosestUnexploredState(StateVertex currentState, List<StateVertex> onURLSet, BlockingQueue<Integer> statesWithCandidates, boolean applyNonSelAdvantage)
Computes the influences of the states based on the influence of candidates and returns the state that has the highest priority Also takes into consideration the back-tracking effort required to reach the state- Parameters:
currentState-onURLSet-statesWithCandidates-applyNonSelAdvantage-- Returns:
-
calculateHops
private double calculateHops(Fragment fragment, StateVertex currentState, List<StateVertex> onURLSet)
-
calculateCandidateInfluence
public double calculateCandidateInfluence(CandidateElement candidate)
-
calculateFragmentCandidateInfluence
private double calculateFragmentCandidateInfluence(Fragment fragment)
-
calculateDuplicationFactor
public double calculateDuplicationFactor(CandidateElement element, StateVertex state)
-
getLeafFragmentMapping
public HashMap<Integer,Integer> getLeafFragmentMapping(StateVertex state1, StateVertex state2)
-
areND2
public StatePair.StateComparision areND2(StateVertex newState, StateVertex expectedState)
Uses mapping of leaf fragments to determine if given two states are near-duplicates- Parameters:
newState-expectedState-- Returns:
-
compareImages
public boolean compareImages(BufferedImage image1, BufferedImage image2)
Color histogram comparison- Parameters:
image1-image2-- Returns:
-
cacheStateComparision
public StatePair.StateComparision cacheStateComparision(StateVertex newState, StateVertex expectedState, boolean assignDynamic)
The main function that compares two given states and outputs a classification [clone, near-duplicates (ND-data ND-struct), different]- Parameters:
newState-expectedState-assignDynamic-- Returns:
-
getAffectedFragments
private List<Fragment> getAffectedFragments(List<Node> changedNodes, StateVertex state)
Computes which fragments contain the changed nodes. Changed nodes are the result of DOM differencing between two states being compared.- Parameters:
changedNodes-state-- Returns:
-
addToNearDuplicates
private void addToNearDuplicates(StateVertex state)
-
hasExploredNearDuplicate
private boolean hasExploredNearDuplicate(StateVertex state)
-
addToNearDuplicates
private void addToNearDuplicates(StateVertex newState, StateVertex expectedState)
-
stopCrawling
public void stopCrawling()
-
cacheStateComparisions
public void cacheStateComparisions(StateVertex newState)
-
seenState
public void seenState(StateVertex currentState)
Updates no of times state has not been polled during crawl (Helps prevent crawler getting stuck in similar states)- Parameters:
currentState-
-
-