Skip to content

Commit

Permalink
Merge pull request #76 from crawljax/Issue-53-state-serialization
Browse files Browse the repository at this point in the history
fixes issues #52 and #53, resolved typo in StateVertix -> StateVertex.

A rather large pull request, but this is simply due to correcting the typo.
Time to merge.
  • Loading branch information
avandeursen committed Dec 19, 2012
2 parents ae0d2fc + 6378583 commit 262b2d4
Show file tree
Hide file tree
Showing 25 changed files with 407 additions and 343 deletions.
Expand Up @@ -22,7 +22,7 @@
import com.crawljax.condition.eventablecondition.EventableConditionChecker;
import com.crawljax.core.configuration.IgnoreFrameChecker;
import com.crawljax.core.state.Identification;
import com.crawljax.core.state.StateVertix;
import com.crawljax.core.state.StateVertex;
import com.crawljax.forms.FormHandler;
import com.crawljax.util.Helper;
import com.crawljax.util.XPathHelper;
Expand Down Expand Up @@ -83,7 +83,7 @@ public CandidateElementExtractor(ExtractorManager checker, EmbeddedBrowser brows
* if the method fails.
*/
public List<CandidateElement> extract(List<TagElement> crawlTagElements,
List<TagElement> crawlExcludeTagElements, boolean clickOnce, StateVertix currentState)
List<TagElement> crawlExcludeTagElements, boolean clickOnce, StateVertex currentState)
throws CrawljaxException {
List<CandidateElement> results = new ArrayList<CandidateElement>();

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/crawljax/core/CrawlSession.java
Expand Up @@ -9,7 +9,7 @@
import com.crawljax.core.state.CrawlPath;
import com.crawljax.core.state.Eventable;
import com.crawljax.core.state.StateFlowGraph;
import com.crawljax.core.state.StateVertix;
import com.crawljax.core.state.StateVertex;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -38,7 +38,7 @@ public class CrawlSession {
/**
* The initial State (indexState).
*/
private final StateVertix initialState;
private final StateVertex initialState;

/**
* Variable for reading the Configuration from.
Expand All @@ -55,7 +55,7 @@ public class CrawlSession {
/**
* ThreadLocal store the have a Thread<->Current State relation.
*/
private final ThreadLocal<StateVertix> tlState = new ThreadLocal<StateVertix>();
private final ThreadLocal<StateVertex> tlState = new ThreadLocal<StateVertex>();

/**
* The main BrowserPool where the current Browser is stored.
Expand All @@ -81,7 +81,7 @@ public CrawlSession(BrowserPool pool) {
* the time this session started in milliseconds.
*/
public CrawlSession(
BrowserPool pool, StateFlowGraph stateFlowGraph, StateVertix state, long startTime) {
BrowserPool pool, StateFlowGraph stateFlowGraph, StateVertex state, long startTime) {
this(pool, stateFlowGraph, state, startTime, null);
}

Expand All @@ -97,7 +97,7 @@ public CrawlSession(
* @param crawljaxConfiguration
* the configuration.
*/
public CrawlSession(BrowserPool pool, StateFlowGraph stateFlowGraph, StateVertix state,
public CrawlSession(BrowserPool pool, StateFlowGraph stateFlowGraph, StateVertex state,
long startTime, CrawljaxConfigurationReader crawljaxConfiguration) {
this.crawljaxConfiguration = crawljaxConfiguration;
this.browserPool = pool;
Expand All @@ -124,8 +124,8 @@ public StateFlowGraph getStateFlowGraph() {
/**
* @return the currentState
*/
public StateVertix getCurrentState() {
StateVertix sv = tlState.get();
public StateVertex getCurrentState() {
StateVertex sv = tlState.get();
if (sv == null) {
tlState.set(getInitialState());
} else {
Expand All @@ -138,7 +138,7 @@ public StateVertix getCurrentState() {
* @param currentState
* the currentState to set
*/
public void setCurrentState(StateVertix currentState) {
public void setCurrentState(StateVertex currentState) {
this.tlState.set(currentState);
}

Expand Down Expand Up @@ -167,7 +167,7 @@ public CrawljaxConfigurationReader getCrawljaxConfiguration() {
/**
* @return the initialState
*/
public final StateVertix getInitialState() {
public final StateVertex getInitialState() {
return initialState;
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/crawljax/core/Crawler.java
Expand Up @@ -19,7 +19,7 @@
import com.crawljax.core.state.Identification;
import com.crawljax.core.state.StateFlowGraph;
import com.crawljax.core.state.StateMachine;
import com.crawljax.core.state.StateVertix;
import com.crawljax.core.state.StateVertex;
import com.crawljax.forms.FormHandler;
import com.crawljax.forms.FormInput;
import com.crawljax.util.ElementResolver;
Expand Down Expand Up @@ -256,7 +256,7 @@ private void goBackExact() throws CrawljaxException {
/**
* Thread safe
*/
StateVertix curState = controller.getSession().getInitialState();
StateVertex curState = controller.getSession().getInitialState();

for (Eventable clickable : backTrackPath) {

Expand Down Expand Up @@ -326,8 +326,8 @@ private ClickResult clickTag(final Eventable eventable) throws CrawljaxException
LOGGER.info("Executing " + eventable.getEventType() + " on element: " + eventable
+ "; State: " + this.getStateMachine().getCurrentState().getName());
if (this.fireEvent(eventable)) {
StateVertix newState =
new StateVertix(getBrowser().getCurrentUrl(), controller.getSession()
StateVertex newState =
new StateVertex(getBrowser().getCurrentUrl(), controller.getSession()
.getStateFlowGraph().getNewStateName(), getBrowser().getDom(),
this.controller.getStrippedDom(getBrowser()));
if (isDomChanged(this.getStateMachine().getCurrentState(), newState)) {
Expand Down Expand Up @@ -385,7 +385,7 @@ private boolean depthLimitReached(int depth) {
}
}

private void spawnThreads(StateVertix state) {
private void spawnThreads(StateVertex state) {
Crawler c = null;
do {
if (c != null) {
Expand All @@ -401,7 +401,7 @@ private ClickResult crawlAction(CandidateCrawlAction action) throws CrawljaxExce
CandidateElement candidateElement = action.getCandidateElement();
EventType eventType = action.getEventType();

StateVertix orrigionalState = this.getStateMachine().getCurrentState();
StateVertex orrigionalState = this.getStateMachine().getCurrentState();

if (candidateElement.allConditionsSatisfied(getBrowser())) {
ClickResult clickResult = clickTag(new Eventable(candidateElement, eventType));
Expand Down Expand Up @@ -449,7 +449,7 @@ private boolean crawl() throws CrawljaxException {
}

// Store the currentState to be able to 'back-track' later.
StateVertix orrigionalState = this.getStateMachine().getCurrentState();
StateVertex orrigionalState = this.getStateMachine().getCurrentState();

if (orrigionalState.searchForCandidateElements(candidateExtractor, configurationReader
.getTagElements(), configurationReader.getExcludeTagElements(),
Expand Down Expand Up @@ -497,7 +497,7 @@ private boolean crawl() throws CrawljaxException {
* @return true if crawling must continue false otherwise.
* @throws CrawljaxException
*/
private boolean newStateDetected(StateVertix orrigionalState) throws CrawljaxException {
private boolean newStateDetected(StateVertex orrigionalState) throws CrawljaxException {

/**
* An event has been fired so we are one level deeper
Expand Down Expand Up @@ -663,7 +663,7 @@ public StateMachine getStateMachine() {
* the state after the event.
* @return true if the state is changed according to the compare method of the oracle.
*/
private boolean isDomChanged(final StateVertix stateBefore, final StateVertix stateAfter) {
private boolean isDomChanged(final StateVertex stateBefore, final StateVertex stateAfter) {
boolean isChanged = false;

// do not need Oracle Comparators now, because hash of stripped dom is
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/crawljax/core/InitialCrawler.java
Expand Up @@ -10,7 +10,7 @@
import com.crawljax.core.state.Eventable;
import com.crawljax.core.state.StateFlowGraph;
import com.crawljax.core.state.StateMachine;
import com.crawljax.core.state.StateVertix;
import com.crawljax.core.state.StateVertex;

/**
* This is the initial Crawler. An initial crawler crawls only the index page, creates the index
Expand Down Expand Up @@ -65,8 +65,8 @@ public void run() {
/**
* Build the index state
*/
StateVertix indexState =
new StateVertix(this.getBrowser().getCurrentUrl(), "index", this.getBrowser()
StateVertex indexState =
new StateVertex(this.getBrowser().getCurrentUrl(), "index", this.getBrowser()
.getDom(), controller.getStrippedDom(this.getBrowser()));

/**
Expand Down
Expand Up @@ -14,7 +14,7 @@
import com.crawljax.core.configuration.ProxyConfiguration;
import com.crawljax.core.state.Eventable;
import com.crawljax.core.state.StateMachine;
import com.crawljax.core.state.StateVertix;
import com.crawljax.core.state.StateVertex;
import com.google.common.collect.Lists;

/**
Expand Down Expand Up @@ -166,7 +166,7 @@ public static void runPostCrawlingPlugins(CrawlSession session) {
* @param currentState
* the state the 'back tracking' operation is currently in
*/
public static void runOnRevisitStatePlugins(CrawlSession session, StateVertix currentState) {
public static void runOnRevisitStatePlugins(CrawlSession session, StateVertex currentState) {
LOGGER.info("Running OnRevisitStatePlugins...");
for (Plugin plugin : CrawljaxPluginsUtil.PLUGINS) {
if (plugin instanceof OnRevisitStatePlugin) {
Expand Down Expand Up @@ -238,7 +238,7 @@ public static void runGuidedCrawlingPlugins(CrawljaxController controller,
for (Plugin plugin : CrawljaxPluginsUtil.PLUGINS) {
if (plugin instanceof GuidedCrawlingPlugin) {
LOGGER.info("Calling plugin " + plugin.getClass().getName());
StateVertix currentState = session.getCurrentState();
StateVertex currentState = session.getCurrentState();
((GuidedCrawlingPlugin) plugin).guidedCrawling(currentState, controller, session,
exactEventPaths, stateMachine);
}
Expand Down
Expand Up @@ -6,7 +6,7 @@
import com.crawljax.core.CrawljaxController;
import com.crawljax.core.state.Eventable;
import com.crawljax.core.state.StateMachine;
import com.crawljax.core.state.StateVertix;
import com.crawljax.core.state.StateVertex;

/**
* Plugin type that is called when the crawling control needs to be given to a plugin. After the
Expand All @@ -30,7 +30,7 @@ public interface GuidedCrawlingPlugin extends Plugin {
* @param stateMachine
* the state machine.
*/
void guidedCrawling(StateVertix currentState, CrawljaxController controller,
void guidedCrawling(StateVertex currentState, CrawljaxController controller,
CrawlSession session, List<Eventable> exactEventPaths, StateMachine stateMachine);

}
@@ -1,7 +1,7 @@
package com.crawljax.core.plugin;

import com.crawljax.core.CrawlSession;
import com.crawljax.core.state.StateVertix;
import com.crawljax.core.state.StateVertex;

/**
* Plugin type that is called every time a state is revisited by Crawljax. Example: Benchmarking.
Expand All @@ -22,6 +22,6 @@ public interface OnRevisitStatePlugin extends Plugin {
* @param currentState
* the state revisited
*/
void onRevisitState(CrawlSession session, StateVertix currentState);
void onRevisitState(CrawlSession session, StateVertex currentState);

}
9 changes: 5 additions & 4 deletions src/main/java/com/crawljax/core/state/Attribute.java
@@ -1,14 +1,15 @@
package com.crawljax.core.state;

import java.io.Serializable;

/**
* This class represents a attribute of a Element.
*
* @see Element#Element(org.w3c.dom.Node)
* @author mesbah
* @author Stefan Lenselink <S.R.Lenselink@student.tudelft.nl>
* @version $Id$
*/
public class Attribute {
public class Attribute implements Serializable {

private static final long serialVersionUID = -1608999189549539958L;

private long id;
private String name;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/crawljax/core/state/Eventable.java
Expand Up @@ -245,7 +245,7 @@ public void setRelatedFormInputs(List<FormInput> relatedFormInputs) {
* @throws CrawljaxException
* if the source cannot be found.
*/
public StateVertix getSourceStateVertix() throws CrawljaxException {
public StateVertex getSourceStateVertix() throws CrawljaxException {
return getSuperField("source");
}

Expand All @@ -254,13 +254,13 @@ public StateVertix getSourceStateVertix() throws CrawljaxException {
* @throws CrawljaxException
* if the target cannot be found.
*/
public StateVertix getTargetStateVertix() throws CrawljaxException {
public StateVertex getTargetStateVertix() throws CrawljaxException {
return getSuperField("target");
}

private StateVertix getSuperField(String name) throws CrawljaxException {
private StateVertex getSuperField(String name) throws CrawljaxException {
try {
return (StateVertix) searchSuperField(name).get(this);
return (StateVertex) searchSuperField(name).get(this);
} catch (IllegalArgumentException e) {
throw new CrawljaxException(e.getMessage(), e);
} catch (IllegalAccessException e) {
Expand Down

0 comments on commit 262b2d4

Please sign in to comment.