some simplifications of the graph classes
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1133 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
02c44adede
commit
07d9656136
|
@ -35,12 +35,13 @@ import org.xml.sax.SAXException;
|
|||
*/
|
||||
public class App
|
||||
{
|
||||
private File archivePath;
|
||||
private ContextHandler handler;
|
||||
private boolean extractWars = false;
|
||||
private boolean parentLoaderPriority = false;
|
||||
private String defaultsDescriptor;
|
||||
private String originId;
|
||||
private final DeploymentManager _manager;
|
||||
private final String _originId;
|
||||
private final File _archivePath;
|
||||
private ContextHandler _context;
|
||||
private boolean _extractWars = false;
|
||||
private boolean _parentLoaderPriority = false;
|
||||
private String _defaultsDescriptor;
|
||||
|
||||
/**
|
||||
* Create an App with specified Origin ID and archivePath
|
||||
|
@ -52,10 +53,20 @@ public class App
|
|||
* @see App#getOriginId()
|
||||
* @see App#getContextId()
|
||||
*/
|
||||
public App(String originId, File archivePath)
|
||||
public App(DeploymentManager manager, String originId, File archivePath)
|
||||
{
|
||||
this.originId = originId;
|
||||
this.archivePath = archivePath;
|
||||
_manager=manager;
|
||||
_originId = originId;
|
||||
_archivePath = archivePath;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return The deployment manager
|
||||
*/
|
||||
public DeploymentManager getDeploymentManager()
|
||||
{
|
||||
return _manager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,7 +78,7 @@ public class App
|
|||
*/
|
||||
public File getArchivePath()
|
||||
{
|
||||
return this.archivePath;
|
||||
return this._archivePath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,35 +90,35 @@ public class App
|
|||
* when App is in the {@link AppState#STAGED} state}
|
||||
* @throws Exception
|
||||
*/
|
||||
public ContextHandler getContextHandler(DeploymentManager deployMgr) throws Exception
|
||||
public ContextHandler getContextHandler() throws Exception
|
||||
{
|
||||
if (handler == null)
|
||||
if (_context == null)
|
||||
{
|
||||
if (FileID.isXmlFile(archivePath))
|
||||
if (FileID.isXmlFile(_archivePath))
|
||||
{
|
||||
this.handler = createContextFromXml(deployMgr);
|
||||
this._context = createContextFromXml(_manager);
|
||||
}
|
||||
else if (FileID.isWebArchive(archivePath))
|
||||
else if (FileID.isWebArchive(_archivePath))
|
||||
{
|
||||
// Treat as a Web Archive.
|
||||
this.handler = createContextDefault(deployMgr);
|
||||
this._context = createContextDefault(_manager);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("Not an XML or Web Archive: " + archivePath.getAbsolutePath());
|
||||
throw new IllegalStateException("Not an XML or Web Archive: " + _archivePath.getAbsolutePath());
|
||||
}
|
||||
|
||||
this.handler.setAttributes(new AttributesMap(deployMgr.getContextAttributes()));
|
||||
this._context.setAttributes(new AttributesMap(_manager.getContextAttributes()));
|
||||
}
|
||||
return handler;
|
||||
return _context;
|
||||
}
|
||||
|
||||
private ContextHandler createContextDefault(DeploymentManager deploymgr)
|
||||
{
|
||||
String context = archivePath.getName();
|
||||
String context = _archivePath.getName();
|
||||
|
||||
// Context Path is the same as the archive.
|
||||
if (FileID.isWebArchiveFile(archivePath))
|
||||
if (FileID.isWebArchiveFile(_archivePath))
|
||||
{
|
||||
context = context.substring(0,context.length() - 4);
|
||||
}
|
||||
|
@ -132,13 +143,13 @@ public class App
|
|||
|
||||
WebAppContext wah = new WebAppContext();
|
||||
wah.setContextPath(context);
|
||||
wah.setWar(archivePath.getAbsolutePath());
|
||||
if (defaultsDescriptor != null)
|
||||
wah.setWar(_archivePath.getAbsolutePath());
|
||||
if (_defaultsDescriptor != null)
|
||||
{
|
||||
wah.setDefaultsDescriptor(defaultsDescriptor);
|
||||
wah.setDefaultsDescriptor(_defaultsDescriptor);
|
||||
}
|
||||
wah.setExtractWAR(extractWars);
|
||||
wah.setParentLoaderPriority(parentLoaderPriority);
|
||||
wah.setExtractWAR(_extractWars);
|
||||
wah.setParentLoaderPriority(_parentLoaderPriority);
|
||||
|
||||
return wah;
|
||||
}
|
||||
|
@ -146,7 +157,7 @@ public class App
|
|||
@SuppressWarnings("unchecked")
|
||||
private ContextHandler createContextFromXml(DeploymentManager deploymgr) throws MalformedURLException, IOException, SAXException, Exception
|
||||
{
|
||||
Resource resource = Resource.newResource(this.archivePath.toURI());
|
||||
Resource resource = Resource.newResource(this._archivePath.toURI());
|
||||
if (!resource.exists())
|
||||
{
|
||||
return null;
|
||||
|
@ -166,32 +177,32 @@ public class App
|
|||
|
||||
public boolean isExtractWars()
|
||||
{
|
||||
return extractWars;
|
||||
return _extractWars;
|
||||
}
|
||||
|
||||
public void setExtractWars(boolean extractWars)
|
||||
{
|
||||
this.extractWars = extractWars;
|
||||
this._extractWars = extractWars;
|
||||
}
|
||||
|
||||
public boolean isParentLoaderPriority()
|
||||
{
|
||||
return parentLoaderPriority;
|
||||
return _parentLoaderPriority;
|
||||
}
|
||||
|
||||
public void setParentLoaderPriority(boolean parentLoaderPriority)
|
||||
{
|
||||
this.parentLoaderPriority = parentLoaderPriority;
|
||||
this._parentLoaderPriority = parentLoaderPriority;
|
||||
}
|
||||
|
||||
public String getDefaultsDescriptor()
|
||||
{
|
||||
return defaultsDescriptor;
|
||||
return _defaultsDescriptor;
|
||||
}
|
||||
|
||||
public void setDefaultsDescriptor(String defaultsDescriptor)
|
||||
{
|
||||
this.defaultsDescriptor = defaultsDescriptor;
|
||||
this._defaultsDescriptor = defaultsDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,11 +212,11 @@ public class App
|
|||
*/
|
||||
public String getContextId()
|
||||
{
|
||||
if (this.handler == null)
|
||||
if (this._context == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.handler.getContextPath();
|
||||
return this._context.getContextPath();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -215,6 +226,6 @@ public class App
|
|||
*/
|
||||
public String getOriginId()
|
||||
{
|
||||
return this.originId;
|
||||
return this._originId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class AppLifeCycle extends Graph
|
|||
* @throws Exception
|
||||
* if any problem severe enough to halt the AppLifeCycle processing
|
||||
*/
|
||||
void processBinding(Node node, App app, DeploymentManager deploymentManager) throws Exception;
|
||||
void processBinding(Node node, App app) throws Exception;
|
||||
}
|
||||
|
||||
// Private string constants defined to avoid typos on repeatedly used strings
|
||||
|
@ -178,7 +178,7 @@ public class AppLifeCycle extends Graph
|
|||
for (Binding binding : bindings)
|
||||
{
|
||||
Log.info("Calling " + binding.getClass().getName());
|
||||
binding.processBinding(node,app,deploymentManager);
|
||||
binding.processBinding(node,app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ package org.eclipse.jetty.deploy;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
|
||||
/**
|
||||
* ConfigurationManager
|
||||
*
|
||||
|
@ -23,6 +25,5 @@ import java.util.Map;
|
|||
*/
|
||||
public interface ConfigurationManager
|
||||
{
|
||||
public Map getProperties();
|
||||
|
||||
public Map<?,?> getProperties();
|
||||
}
|
||||
|
|
|
@ -29,8 +29,7 @@ import org.eclipse.jetty.deploy.bindings.StandardStarter;
|
|||
import org.eclipse.jetty.deploy.bindings.StandardStopper;
|
||||
import org.eclipse.jetty.deploy.bindings.StandardUndeployer;
|
||||
import org.eclipse.jetty.deploy.graph.Node;
|
||||
import org.eclipse.jetty.deploy.graph.NodePath;
|
||||
import org.eclipse.jetty.deploy.support.ConfigurationManager;
|
||||
import org.eclipse.jetty.deploy.graph.Path;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.util.AttributesMap;
|
||||
|
@ -107,9 +106,9 @@ public class DeploymentManager extends AbstractLifeCycle
|
|||
}
|
||||
}
|
||||
|
||||
private List<AppProvider> providers = new ArrayList<AppProvider>();
|
||||
private AppLifeCycle lifecycle = new AppLifeCycle();
|
||||
private LinkedList<AppEntry> apps = new LinkedList<AppEntry>();
|
||||
private final List<AppProvider> providers = new ArrayList<AppProvider>();
|
||||
private final AppLifeCycle lifecycle = new AppLifeCycle();
|
||||
private final LinkedList<AppEntry> apps = new LinkedList<AppEntry>();
|
||||
private AttributesMap contextAttributes = new AttributesMap();
|
||||
private ConfigurationManager configurationManager;
|
||||
private ContextHandlerCollection contexts;
|
||||
|
@ -441,7 +440,7 @@ public class DeploymentManager extends AbstractLifeCycle
|
|||
{
|
||||
Node destinationNode = lifecycle.getNodeByName(nodeName);
|
||||
// Compute lifecycle steps
|
||||
NodePath path = lifecycle.getPath(appentry.lifecyleNode,destinationNode);
|
||||
Path path = lifecycle.getPath(appentry.lifecyleNode,destinationNode);
|
||||
if (path.isEmpty())
|
||||
{
|
||||
// nothing to do. already there.
|
||||
|
@ -451,7 +450,7 @@ public class DeploymentManager extends AbstractLifeCycle
|
|||
// Execute each Node binding. Stopping at any thrown exception.
|
||||
try
|
||||
{
|
||||
Iterator<Node> it = path.iterator();
|
||||
Iterator<Node> it = path.getNodes().iterator();
|
||||
if (it.hasNext()) // Any entries?
|
||||
{
|
||||
// The first entry in the path is always the start node
|
||||
|
|
|
@ -46,7 +46,7 @@ public class FileConfigurationManager implements ConfigurationManager
|
|||
/**
|
||||
* @see org.eclipse.jetty.deploy.ConfigurationManager#getProperties()
|
||||
*/
|
||||
public Map getProperties()
|
||||
public Map<?,?> getProperties()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -29,13 +29,13 @@ public class StandardDeployer implements AppLifeCycle.Binding
|
|||
{ "deploying" };
|
||||
}
|
||||
|
||||
public void processBinding(Node node, App app, DeploymentManager deploymentManager) throws Exception
|
||||
public void processBinding(Node node, App app) throws Exception
|
||||
{
|
||||
ContextHandler handler = app.getContextHandler(deploymentManager);
|
||||
ContextHandler handler = app.getContextHandler();
|
||||
if (handler == null)
|
||||
{
|
||||
throw new NullPointerException("No Handler created for App: " + app);
|
||||
}
|
||||
deploymentManager.getContexts().addHandler(handler);
|
||||
app.getDeploymentManager().getContexts().addHandler(handler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,19 +28,19 @@ public class StandardStarter implements AppLifeCycle.Binding
|
|||
return new String[] { "starting" };
|
||||
}
|
||||
|
||||
public void processBinding(Node node, App app, DeploymentManager deploymentManager) throws Exception
|
||||
public void processBinding(Node node, App app) throws Exception
|
||||
{
|
||||
ContextHandler handler = app.getContextHandler(deploymentManager);
|
||||
ContextHandler handler = app.getContextHandler();
|
||||
if (!handler.isStarted())
|
||||
{
|
||||
handler.start();
|
||||
}
|
||||
|
||||
// Remove other apps at same context
|
||||
for (App other : deploymentManager.getAppsWithSameContext(app))
|
||||
for (App other : app.getDeploymentManager().getAppsWithSameContext(app))
|
||||
{
|
||||
Log.info("Removing apps with same context: " + other);
|
||||
deploymentManager.requestAppGoal(other,"undeployed");
|
||||
app.getDeploymentManager().requestAppGoal(other,"undeployed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ public class StandardStopper implements AppLifeCycle.Binding
|
|||
{ "stopping" };
|
||||
}
|
||||
|
||||
public void processBinding(Node node, App app, DeploymentManager deploymentManager) throws Exception
|
||||
public void processBinding(Node node, App app) throws Exception
|
||||
{
|
||||
ContextHandler handler = app.getContextHandler(deploymentManager);
|
||||
ContextHandler handler = app.getContextHandler();
|
||||
if (!handler.isStopped())
|
||||
{
|
||||
handler.stop();
|
||||
|
|
|
@ -33,14 +33,14 @@ public class StandardUndeployer implements AppLifeCycle.Binding
|
|||
{ "undeploying" };
|
||||
}
|
||||
|
||||
public void processBinding(Node node, App app, DeploymentManager deploymentManager) throws Exception
|
||||
public void processBinding(Node node, App app) throws Exception
|
||||
{
|
||||
ContextHandler handler = app.getContextHandler(deploymentManager);
|
||||
ContextHandlerCollection chcoll = deploymentManager.getContexts();
|
||||
ContextHandler handler = app.getContextHandler();
|
||||
ContextHandlerCollection chcoll = app.getDeploymentManager().getContexts();
|
||||
|
||||
recursiveRemoveContext(chcoll,handler);
|
||||
|
||||
deploymentManager.removeApp(app);
|
||||
app.getDeploymentManager().removeApp(app);
|
||||
}
|
||||
|
||||
private void recursiveRemoveContext(HandlerCollection coll, ContextHandler context)
|
||||
|
|
|
@ -18,25 +18,23 @@ package org.eclipse.jetty.deploy.graph;
|
|||
/**
|
||||
* Basic Graph Edge
|
||||
*/
|
||||
public class Edge
|
||||
public final class Edge
|
||||
{
|
||||
private Node from;
|
||||
private Node to;
|
||||
private Node _from;
|
||||
private Node _to;
|
||||
|
||||
public Edge(Node from, Node to)
|
||||
{
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
if (from==null || to==null || from==to)
|
||||
throw new IllegalArgumentException("from "+from+" to "+to);
|
||||
_from = from;
|
||||
_to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((from == null)?0:from.hashCode());
|
||||
result = prime * result + ((to == null)?0:to.hashCode());
|
||||
return result;
|
||||
return _from.hashCode() ^ _to.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,30 +47,36 @@ public class Edge
|
|||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Edge other = (Edge)obj;
|
||||
if (from == null)
|
||||
if (_from == null)
|
||||
{
|
||||
if (other.from != null)
|
||||
if (other._from != null)
|
||||
return false;
|
||||
}
|
||||
else if (!from.equals(other.from))
|
||||
else if (!_from.equals(other._from))
|
||||
return false;
|
||||
if (to == null)
|
||||
if (_to == null)
|
||||
{
|
||||
if (other.to != null)
|
||||
if (other._to != null)
|
||||
return false;
|
||||
}
|
||||
else if (!to.equals(other.to))
|
||||
else if (!_to.equals(other._to))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public Node getFrom()
|
||||
{
|
||||
return from;
|
||||
return _from;
|
||||
}
|
||||
|
||||
public Node getTo()
|
||||
{
|
||||
return to;
|
||||
return _to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return _from+"->"+_to;
|
||||
}
|
||||
}
|
|
@ -15,190 +15,45 @@
|
|||
// ========================================================================
|
||||
package org.eclipse.jetty.deploy.graph;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* Basic directed graph implementation
|
||||
*/
|
||||
public class Graph
|
||||
{
|
||||
private class EdgeSearch
|
||||
{
|
||||
private Set<Edge> seenEdges = new HashSet<Edge>();
|
||||
private List<NodePath> paths = new ArrayList<NodePath>();
|
||||
|
||||
public EdgeSearch(Node from)
|
||||
{
|
||||
NodePath path = new NodePath();
|
||||
path.add(from);
|
||||
paths.add(path);
|
||||
}
|
||||
|
||||
public void breadthFirst(Node destination)
|
||||
{
|
||||
// Test existing edge endpoints
|
||||
if (hasReachedDestination(destination))
|
||||
{
|
||||
// Found our destination!
|
||||
|
||||
// Now remove the other paths that do not end at the destination
|
||||
ListIterator<NodePath> pathiter = paths.listIterator();
|
||||
while (pathiter.hasNext())
|
||||
{
|
||||
NodePath path = pathiter.next();
|
||||
if (path.lastNode() != destination)
|
||||
{
|
||||
pathiter.remove();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
List<NodePath> extrapaths = null;
|
||||
|
||||
// Add next unseen segments to paths.
|
||||
boolean pathsAdded = false;
|
||||
|
||||
for (NodePath path : paths)
|
||||
{
|
||||
List<Edge> next = nextUnseenEdges(path);
|
||||
if (next.size() == 0)
|
||||
{
|
||||
continue; // no new edges
|
||||
}
|
||||
|
||||
pathsAdded = true;
|
||||
|
||||
// More than 1 path out? Split it.
|
||||
if (next.size() > 1)
|
||||
{
|
||||
if (extrapaths == null)
|
||||
{
|
||||
extrapaths = new ArrayList<NodePath>();
|
||||
}
|
||||
|
||||
// Split path for other edges
|
||||
for (int i = 1, n = next.size(); i < n; i++)
|
||||
{
|
||||
NodePath split = path.forkPath();
|
||||
// Add segment to split'd path
|
||||
split.add(next.get(i).getTo());
|
||||
|
||||
// Add to extra paths
|
||||
extrapaths.add(split);
|
||||
}
|
||||
}
|
||||
|
||||
// Add edge to current path
|
||||
Edge edge = next.get(0);
|
||||
path.add(edge.getTo());
|
||||
|
||||
// Mark all edges as seen
|
||||
for (Edge e : next)
|
||||
{
|
||||
seenEdges.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Do we have any extra paths?
|
||||
if (extrapaths != null)
|
||||
{
|
||||
paths.addAll(extrapaths);
|
||||
}
|
||||
|
||||
if (pathsAdded)
|
||||
{
|
||||
// recurse
|
||||
breadthFirst(destination);
|
||||
}
|
||||
}
|
||||
|
||||
public NodePath getShortestPath()
|
||||
{
|
||||
NodePath shortest = null;
|
||||
int shortestlen = Integer.MAX_VALUE;
|
||||
|
||||
for (NodePath path : paths)
|
||||
{
|
||||
if (shortest == null)
|
||||
{
|
||||
shortest = path;
|
||||
continue;
|
||||
}
|
||||
|
||||
int len = path.length();
|
||||
|
||||
if (len < shortestlen)
|
||||
{
|
||||
shortest = path;
|
||||
shortestlen = len;
|
||||
}
|
||||
}
|
||||
|
||||
return shortest;
|
||||
}
|
||||
|
||||
private boolean hasReachedDestination(Node destination)
|
||||
{
|
||||
for (NodePath path : paths)
|
||||
{
|
||||
if (path.lastNode() == destination)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<Edge> nextUnseenEdges(NodePath path)
|
||||
{
|
||||
List<Edge> next = new ArrayList<Edge>();
|
||||
|
||||
for (Edge edge : findEdgesFrom(path.lastNode()))
|
||||
{
|
||||
if (seenEdges.contains(edge) == false)
|
||||
{
|
||||
next.add(edge);
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Node> nodes = new HashSet<Node>();
|
||||
private Set<Edge> edges = new HashSet<Edge>();
|
||||
private Set<Node> _nodes = new HashSet<Node>();
|
||||
private Set<Edge> _edges = new HashSet<Edge>();
|
||||
|
||||
public void addEdge(Edge edge)
|
||||
{
|
||||
this.edges.add(edge);
|
||||
Node fromNode = getNodeByName(edge.getFrom().getName());
|
||||
if (fromNode==null)
|
||||
addNode(fromNode=edge.getFrom());
|
||||
Node toNode = getNodeByName(edge.getTo().getName());
|
||||
if (toNode==null)
|
||||
addNode(toNode=edge.getTo());
|
||||
|
||||
// replace edge with normalized edge
|
||||
if (edge.getFrom()!=fromNode || edge.getTo()!=toNode)
|
||||
edge=new Edge(fromNode,toNode);
|
||||
|
||||
this._edges.add(edge);
|
||||
}
|
||||
|
||||
public void addEdge(String from, String to)
|
||||
{
|
||||
Node fromNode = null;
|
||||
Node toNode = null;
|
||||
|
||||
try
|
||||
{
|
||||
fromNode = getNodeByName(from);
|
||||
}
|
||||
catch (NodeNotFoundException e)
|
||||
Node fromNode = getNodeByName(from);
|
||||
if (fromNode==null)
|
||||
{
|
||||
fromNode = new Node(from);
|
||||
addNode(fromNode);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
toNode = getNodeByName(to);
|
||||
}
|
||||
catch (NodeNotFoundException e)
|
||||
Node toNode = getNodeByName(to);
|
||||
if (toNode==null)
|
||||
{
|
||||
toNode = new Node(to);
|
||||
addNode(toNode);
|
||||
|
@ -215,12 +70,7 @@ public class Graph
|
|||
|
||||
public void addNode(Node node)
|
||||
{
|
||||
this.nodes.add(node);
|
||||
}
|
||||
|
||||
public void writeGraph(GraphOutput output) throws IOException
|
||||
{
|
||||
output.write(this);
|
||||
this._nodes.add(node);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,13 +83,8 @@ public class Graph
|
|||
*/
|
||||
public void insertNode(Edge edge, String nodeName)
|
||||
{
|
||||
Node node;
|
||||
|
||||
try
|
||||
{
|
||||
node = getNodeByName(nodeName);
|
||||
}
|
||||
catch (NodeNotFoundException e)
|
||||
Node node = getNodeByName(nodeName);
|
||||
if (node==null)
|
||||
{
|
||||
node = new Node(nodeName);
|
||||
}
|
||||
|
@ -279,7 +124,7 @@ public class Graph
|
|||
{
|
||||
Set<Edge> fromedges = new HashSet<Edge>();
|
||||
|
||||
for (Edge edge : this.edges)
|
||||
for (Edge edge : this._edges)
|
||||
{
|
||||
if ((edge.getFrom() == node) || (edge.getTo() == node))
|
||||
{
|
||||
|
@ -301,7 +146,7 @@ public class Graph
|
|||
{
|
||||
Set<Edge> fromedges = new HashSet<Edge>();
|
||||
|
||||
for (Edge edge : this.edges)
|
||||
for (Edge edge : this._edges)
|
||||
{
|
||||
if (edge.getFrom() == from)
|
||||
{
|
||||
|
@ -321,11 +166,11 @@ public class Graph
|
|||
* the name of the node to the path destination.
|
||||
* @return the path to take
|
||||
*/
|
||||
public NodePath getPath(String nodeNameOrigin, String nodeNameDest)
|
||||
public Path getPath(String nodeNameOrigin, String nodeNameDest)
|
||||
{
|
||||
if (nodeNameOrigin.equals(nodeNameDest))
|
||||
{
|
||||
return new NodePath();
|
||||
return new Path();
|
||||
}
|
||||
|
||||
Node from = getNodeByName(nodeNameOrigin);
|
||||
|
@ -340,25 +185,66 @@ public class Graph
|
|||
* the node from
|
||||
* @param to
|
||||
* the node to
|
||||
* @return the path to take
|
||||
* @return the path to take or null if there is no path.
|
||||
*/
|
||||
public NodePath getPath(Node from, Node to)
|
||||
public Path getPath(Node from, Node to)
|
||||
{
|
||||
if (from == to)
|
||||
{
|
||||
return new NodePath();
|
||||
return new Path();
|
||||
}
|
||||
|
||||
// Perform a Breadth First Search (BFS) of the tree.
|
||||
EdgeSearch search = new EdgeSearch(from);
|
||||
search.breadthFirst(to);
|
||||
|
||||
return search.getShortestPath();
|
||||
Path path = breadthFirst(from,to,new CopyOnWriteArrayList<Path>(),new HashSet<Edge>());
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
private Path breadthFirst(Node from, Node destination, CopyOnWriteArrayList<Path> paths, Set<Edge> seen)
|
||||
{
|
||||
// Add next unseen segments to paths.
|
||||
boolean edgesAdded = false;
|
||||
if (paths.size()==0)
|
||||
paths.add(new Path());
|
||||
|
||||
for (Path path : paths)
|
||||
{
|
||||
Set<Edge> next = findEdgesFrom(path.nodes()==0?from:path.lastNode());
|
||||
if (next.size() == 0)
|
||||
continue; // no new edges
|
||||
|
||||
// Split path for other edges
|
||||
int splits=0;
|
||||
for (Edge edge:next)
|
||||
{
|
||||
if (seen.contains(edge))
|
||||
continue;
|
||||
seen.add(edge);
|
||||
Path nextPath = (++splits==next.size())?path:path.forkPath();
|
||||
// Add segment to split'd path
|
||||
nextPath.add(edge);
|
||||
|
||||
// Are we there yet?
|
||||
if (destination.equals(edge.getTo()))
|
||||
return nextPath;
|
||||
|
||||
edgesAdded = true;
|
||||
|
||||
// Add to extra paths
|
||||
if (nextPath!=path)
|
||||
paths.add(nextPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (edgesAdded)
|
||||
return breadthFirst(from,destination,paths,seen);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Set<Edge> getEdges()
|
||||
{
|
||||
return edges;
|
||||
return _edges;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -366,31 +252,28 @@ public class Graph
|
|||
*
|
||||
* @param name
|
||||
* the name to lookup
|
||||
* @return the node if found
|
||||
* @throws NodeNotFoundException
|
||||
* if node not found
|
||||
* @return the node if found or null if not found.
|
||||
*/
|
||||
public Node getNodeByName(String name)
|
||||
{
|
||||
for (Node node : nodes)
|
||||
for (Node node : _nodes)
|
||||
{
|
||||
if (node.getName().equals(name))
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NodeNotFoundException("Unable to find node: " + name);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Set<Node> getNodes()
|
||||
{
|
||||
return nodes;
|
||||
return _nodes;
|
||||
}
|
||||
|
||||
public void removeEdge(Edge edge)
|
||||
{
|
||||
this.edges.remove(edge);
|
||||
this._edges.remove(edge);
|
||||
}
|
||||
|
||||
public void removeEdge(String fromNodeName, String toNodeName)
|
||||
|
@ -403,16 +286,16 @@ public class Graph
|
|||
|
||||
public void removeNode(Node node)
|
||||
{
|
||||
this.nodes.remove(node);
|
||||
this._nodes.remove(node);
|
||||
}
|
||||
|
||||
public void setEdges(Set<Edge> edges)
|
||||
{
|
||||
this.edges = edges;
|
||||
this._edges = edges;
|
||||
}
|
||||
|
||||
public void setNodes(Set<Node> nodes)
|
||||
{
|
||||
this.nodes = nodes;
|
||||
this._nodes = nodes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
package org.eclipse.jetty.deploy.graph;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* GraphOutput for writing in-memory graph to the a stream of some sort.
|
||||
*
|
||||
* Useful for outputting the graph in other formats.
|
||||
*/
|
||||
public interface GraphOutput
|
||||
{
|
||||
void write(Graph graph) throws IOException;
|
||||
}
|
|
@ -25,16 +25,13 @@ import org.eclipse.jetty.util.IO;
|
|||
/**
|
||||
* Output the Graph in GraphViz Dot format.
|
||||
*/
|
||||
public class GraphOutputDot implements GraphOutput
|
||||
public class GraphOutputDot
|
||||
{
|
||||
private File outputFile;
|
||||
|
||||
public GraphOutputDot(File outputFile)
|
||||
private GraphOutputDot()
|
||||
{
|
||||
this.outputFile = outputFile;
|
||||
}
|
||||
|
||||
public void write(Graph graph) throws IOException
|
||||
public static void write(Graph graph,File outputFile) throws IOException
|
||||
{
|
||||
FileWriter writer = null;
|
||||
PrintWriter out = null;
|
||||
|
@ -44,7 +41,7 @@ public class GraphOutputDot implements GraphOutput
|
|||
writer = new FileWriter(outputFile);
|
||||
out = new PrintWriter(writer);
|
||||
|
||||
out.println("// Autogenerated by " + this.getClass().getName());
|
||||
out.println("// Autogenerated by " + GraphOutputDot.class.getName());
|
||||
out.println("digraph Graf {");
|
||||
|
||||
writeGraphDefaults(out);
|
||||
|
@ -70,7 +67,7 @@ public class GraphOutputDot implements GraphOutput
|
|||
}
|
||||
}
|
||||
|
||||
private void writeEdge(PrintWriter out, Edge edge)
|
||||
private static void writeEdge(PrintWriter out, Edge edge)
|
||||
{
|
||||
out.println();
|
||||
out.println(" // Edge");
|
||||
|
@ -80,7 +77,7 @@ public class GraphOutputDot implements GraphOutput
|
|||
out.println(" ];");
|
||||
}
|
||||
|
||||
private void writeNode(PrintWriter out, Node node)
|
||||
private static void writeNode(PrintWriter out, Node node)
|
||||
{
|
||||
out.println();
|
||||
out.println(" // Node");
|
||||
|
@ -95,7 +92,7 @@ public class GraphOutputDot implements GraphOutput
|
|||
out.println(" ];");
|
||||
}
|
||||
|
||||
private CharSequence toId(Node node)
|
||||
private static CharSequence toId(Node node)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
|
@ -123,7 +120,7 @@ public class GraphOutputDot implements GraphOutput
|
|||
return buf;
|
||||
}
|
||||
|
||||
private void writeEdgeDefaults(PrintWriter out)
|
||||
private static void writeEdgeDefaults(PrintWriter out)
|
||||
{
|
||||
out.println();
|
||||
out.println(" // Edge Defaults ");
|
||||
|
@ -133,7 +130,7 @@ public class GraphOutputDot implements GraphOutput
|
|||
out.println(" ];");
|
||||
}
|
||||
|
||||
private void writeGraphDefaults(PrintWriter out)
|
||||
private static void writeGraphDefaults(PrintWriter out)
|
||||
{
|
||||
out.println();
|
||||
out.println(" // Graph Defaults ");
|
||||
|
@ -147,7 +144,7 @@ public class GraphOutputDot implements GraphOutput
|
|||
out.println(" ];");
|
||||
}
|
||||
|
||||
private void writeNodeDefaults(PrintWriter out)
|
||||
private static void writeNodeDefaults(PrintWriter out)
|
||||
{
|
||||
out.println();
|
||||
out.println(" // Node Defaults ");
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
package org.eclipse.jetty.deploy.graph;
|
||||
|
||||
public class ImpossiblePathException extends RuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 8423437443748056467L;
|
||||
|
||||
public ImpossiblePathException(String message, Throwable cause)
|
||||
{
|
||||
super(message,cause);
|
||||
}
|
||||
|
||||
public ImpossiblePathException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -18,33 +18,31 @@ package org.eclipse.jetty.deploy.graph;
|
|||
/**
|
||||
* Basic Graph Node
|
||||
*/
|
||||
public class Node
|
||||
public final class Node
|
||||
{
|
||||
private String name;
|
||||
private final String _name;
|
||||
|
||||
public Node(String name)
|
||||
{
|
||||
this.name = name;
|
||||
assert name!=null;
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Node[" + name + "]";
|
||||
return "Node[" + _name + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null)?0:name.hashCode());
|
||||
return result;
|
||||
return _name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,12 +55,12 @@ public class Node
|
|||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Node other = (Node)obj;
|
||||
if (name == null)
|
||||
if (_name == null)
|
||||
{
|
||||
if (other.name != null)
|
||||
if (other._name != null)
|
||||
return false;
|
||||
}
|
||||
else if (!name.equals(other.name))
|
||||
else if (!_name.equals(other._name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
package org.eclipse.jetty.deploy.graph;
|
||||
|
||||
/**
|
||||
* NodeNotFoundException for when a referenced node cannot be found.
|
||||
*/
|
||||
public class NodeNotFoundException extends RuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = -7126395440535048386L;
|
||||
|
||||
public NodeNotFoundException(String message, Throwable cause)
|
||||
{
|
||||
super(message,cause);
|
||||
}
|
||||
|
||||
public NodeNotFoundException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
package org.eclipse.jetty.deploy.graph;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Stack;
|
||||
|
||||
public class NodePath implements Iterable<Node>
|
||||
{
|
||||
private Stack<Node> path;
|
||||
|
||||
public NodePath()
|
||||
{
|
||||
path = new Stack<Node>();
|
||||
}
|
||||
|
||||
public void add(Node node)
|
||||
{
|
||||
path.push(node);
|
||||
}
|
||||
|
||||
public NodePath forkPath()
|
||||
{
|
||||
NodePath ep = new NodePath();
|
||||
for (Node node : this)
|
||||
{
|
||||
ep.add(node);
|
||||
}
|
||||
return ep;
|
||||
}
|
||||
|
||||
public Collection<Node> getCollection()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
public Iterator<Node> iterator()
|
||||
{
|
||||
return path.iterator();
|
||||
}
|
||||
|
||||
public Node lastNode()
|
||||
{
|
||||
return path.peek();
|
||||
}
|
||||
|
||||
public int length()
|
||||
{
|
||||
return path.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return path.isEmpty();
|
||||
}
|
||||
|
||||
public Edge getEdge(int index)
|
||||
{
|
||||
if (index < 0)
|
||||
{
|
||||
throw new IndexOutOfBoundsException("Unable to use a negative index " + index);
|
||||
}
|
||||
|
||||
int upperBound = path.size() - 1;
|
||||
|
||||
if (index > upperBound)
|
||||
{
|
||||
throw new IndexOutOfBoundsException("Index " + index + " not within range (0 - " + upperBound + ")");
|
||||
}
|
||||
|
||||
Node from = path.get(index);
|
||||
Node to = path.get(index + 1);
|
||||
return new Edge(from,to); // TODO: if edge has more details than from/to node, then this will need to be persisted within the NodePath as well.
|
||||
}
|
||||
|
||||
public Node getNode(int index)
|
||||
{
|
||||
return path.get(index);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
package org.eclipse.jetty.deploy.graph;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class Path
|
||||
{
|
||||
private final List<Edge> _edges = new CopyOnWriteArrayList<Edge>();
|
||||
private final List<Node> _nodes = new CopyOnWriteArrayList<Node>();
|
||||
|
||||
public Path()
|
||||
{
|
||||
}
|
||||
|
||||
public void add(Edge edge)
|
||||
{
|
||||
_edges.add(edge);
|
||||
if (_nodes.size()==0)
|
||||
_nodes.add(edge.getFrom());
|
||||
else
|
||||
assert _nodes.get(_nodes.size()-1).equals(edge.getFrom());
|
||||
_nodes.add(edge.getTo());
|
||||
}
|
||||
|
||||
public Path forkPath()
|
||||
{
|
||||
Path ep = new Path();
|
||||
for (Edge edge : _edges)
|
||||
{
|
||||
ep.add(edge);
|
||||
}
|
||||
return ep;
|
||||
}
|
||||
|
||||
public List<Node> getNodes()
|
||||
{
|
||||
return _nodes;
|
||||
}
|
||||
|
||||
public List<Node> getEdges()
|
||||
{
|
||||
return _nodes;
|
||||
}
|
||||
|
||||
public Node getNode(int index)
|
||||
{
|
||||
return _nodes.get(index);
|
||||
}
|
||||
|
||||
public Node firstNode()
|
||||
{
|
||||
if (_nodes.size()==0)
|
||||
return null;
|
||||
return _nodes.get(0);
|
||||
}
|
||||
|
||||
public Node lastNode()
|
||||
{
|
||||
if (_nodes.size()==0)
|
||||
return null;
|
||||
return _nodes.get(_nodes.size()-1);
|
||||
}
|
||||
|
||||
public int nodes()
|
||||
{
|
||||
return _nodes.size();
|
||||
}
|
||||
|
||||
public int edges()
|
||||
{
|
||||
return _edges.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return _edges.isEmpty();
|
||||
}
|
||||
|
||||
public Edge firstEdge()
|
||||
{
|
||||
if (_edges.size()==0)
|
||||
return null;
|
||||
return _edges.get(0);
|
||||
}
|
||||
|
||||
public Edge lastEdge()
|
||||
{
|
||||
if (_edges.size()==0)
|
||||
return null;
|
||||
return _edges.get(_edges.size()-1);
|
||||
}
|
||||
public Edge getEdge(int index)
|
||||
{
|
||||
return _edges.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return super.toString()+_nodes.toString();
|
||||
}
|
||||
}
|
|
@ -76,7 +76,7 @@ public class MonitoredDirAppProvider extends AbstractLifeCycle implements AppPro
|
|||
private void addConfiguredContextApp(String filename)
|
||||
{
|
||||
String originId = filename;
|
||||
App app = new App(originId,new File(filename));
|
||||
App app = new App(deploymgr,originId,new File(filename));
|
||||
app.setExtractWars(this.extractWars);
|
||||
app.setParentLoaderPriority(this.parentLoaderPriority);
|
||||
app.setDefaultsDescriptor(this.defaultsDescriptor);
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.deploy.support;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ConfigurationManager
|
||||
*
|
||||
* Type for allow injection of property values
|
||||
* for replacement in jetty xml files during deployment.
|
||||
*/
|
||||
public interface ConfigurationManager
|
||||
{
|
||||
public Map<?, ?> getProperties();
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.deploy.support;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
/**
|
||||
* FileConfigurationManager
|
||||
*
|
||||
* Supplies properties defined in a file.
|
||||
*/
|
||||
public class FileConfigurationManager implements ConfigurationManager
|
||||
{
|
||||
private Resource _file;
|
||||
private Properties _properties = new Properties();
|
||||
|
||||
public FileConfigurationManager()
|
||||
{
|
||||
}
|
||||
|
||||
public void setFile(String filename) throws MalformedURLException, IOException
|
||||
{
|
||||
_file = Resource.newResource(filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.deploy.ConfigurationManager#getProperties()
|
||||
*/
|
||||
public Map<?, ?> getProperties()
|
||||
{
|
||||
try
|
||||
{
|
||||
loadProperties();
|
||||
return _properties;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadProperties() throws FileNotFoundException, IOException
|
||||
{
|
||||
if (_properties.isEmpty())
|
||||
{
|
||||
_properties.load(_file.getInputStream());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@ public class AppLifeCyclePathCollector implements AppLifeCycle.Binding
|
|||
{ "*" };
|
||||
}
|
||||
|
||||
public void processBinding(Node node, App app, DeploymentManager deploymentManager) throws Exception
|
||||
public void processBinding(Node node, App app) throws Exception
|
||||
{
|
||||
actualOrder.add(node);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.jetty.deploy.graph.GraphOutputDot;
|
||||
import org.eclipse.jetty.deploy.graph.Node;
|
||||
import org.eclipse.jetty.deploy.graph.NodePath;
|
||||
import org.eclipse.jetty.deploy.graph.Path;
|
||||
import org.eclipse.jetty.deploy.test.MavenTestingUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -41,11 +41,11 @@ public class AppLifeCycleTest
|
|||
{
|
||||
Node fromNode = lifecycle.getNodeByName(from);
|
||||
Node toNode = lifecycle.getNodeByName(to);
|
||||
NodePath actual = lifecycle.getPath(fromNode,toNode);
|
||||
Path actual = lifecycle.getPath(fromNode,toNode);
|
||||
String msg = "LifeCycle path from " + from + " to " + to;
|
||||
Assert.assertNotNull(msg + " should never be null",actual);
|
||||
|
||||
if (expected.size() != actual.length())
|
||||
if (expected.size() != actual.nodes())
|
||||
{
|
||||
System.out.println();
|
||||
System.out.printf("/* from '%s' -> '%s' */%n",from,to);
|
||||
|
@ -55,12 +55,12 @@ public class AppLifeCycleTest
|
|||
System.out.println(path);
|
||||
}
|
||||
System.out.println("/* Actual Path */");
|
||||
for (Node path : actual)
|
||||
for (Node path : actual.getNodes())
|
||||
{
|
||||
System.out.println(path.getName());
|
||||
}
|
||||
|
||||
Assert.assertEquals(msg + " / count",expected.size(),actual.length());
|
||||
Assert.assertEquals(msg + " / count",expected.size(),actual.nodes());
|
||||
}
|
||||
|
||||
for (int i = 0, n = expected.size(); i < n; i++)
|
||||
|
@ -173,11 +173,11 @@ public class AppLifeCycleTest
|
|||
outputDir.mkdirs();
|
||||
|
||||
// Modify graph to add new 'staging' -> 'staged' between 'deployed' and 'started'
|
||||
lifecycle.writeGraph(new GraphOutputDot(new File(outputDir,"multiple-1.dot"))); // before change
|
||||
GraphOutputDot.write(lifecycle,new File(outputDir,"multiple-1.dot")); // before change
|
||||
lifecycle.insertNode(lifecycle.getPath("deployed","started").getEdge(0),"staging");
|
||||
lifecycle.writeGraph(new GraphOutputDot(new File(outputDir,"multiple-2.dot"))); // after first change
|
||||
GraphOutputDot.write(lifecycle,new File(outputDir,"multiple-2.dot")); // after first change
|
||||
lifecycle.insertNode(lifecycle.getPath("staging","started").getEdge(0),"staged");
|
||||
lifecycle.writeGraph(new GraphOutputDot(new File(outputDir,"multiple-3.dot"))); // after second change
|
||||
GraphOutputDot.write(lifecycle,new File(outputDir,"multiple-3.dot")); // after second change
|
||||
|
||||
// Deployed -> Deployed
|
||||
expected.clear();
|
||||
|
|
|
@ -39,7 +39,7 @@ public class MockAppProvider extends AbstractLifeCycle implements AppProvider
|
|||
public void findWebapp(String name)
|
||||
{
|
||||
File war = new File(webappsDir,name);
|
||||
App app = new App("mock-" + name,war);
|
||||
App app = new App(deployMan,"mock-" + name,war);
|
||||
this.deployMan.addApp(app);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
package org.eclipse.jetty.deploy.graph;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
|
||||
public class GraphTest
|
||||
{
|
||||
final Node nodeA = new Node("A");
|
||||
final Node nodeB = new Node("B");
|
||||
final Node nodeC = new Node("C");
|
||||
final Node nodeD = new Node("D");
|
||||
final Node nodeE = new Node("E");
|
||||
|
||||
|
||||
@Test
|
||||
public void testPath()
|
||||
{
|
||||
|
||||
Path path = new Path();
|
||||
|
||||
Assert.assertEquals(0,path.nodes());
|
||||
Assert.assertEquals(null,path.firstNode());
|
||||
Assert.assertEquals(null,path.lastNode());
|
||||
|
||||
path.add(new Edge(nodeA ,nodeB));
|
||||
Assert.assertEquals(2,path.nodes());
|
||||
Assert.assertEquals(nodeA,path.firstNode());
|
||||
Assert.assertEquals(nodeB,path.lastNode());
|
||||
|
||||
path.add(new Edge(nodeB ,nodeC));
|
||||
Assert.assertEquals(3,path.nodes());
|
||||
Assert.assertEquals(nodeA,path.firstNode());
|
||||
Assert.assertEquals(nodeC,path.lastNode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPoint()
|
||||
{
|
||||
Graph graph = new Graph();
|
||||
graph.addNode(nodeA);
|
||||
Assert.assertEquals(1,graph.getNodes().size());
|
||||
Assert.assertEquals(0,graph.getEdges().size());
|
||||
Path path = graph.getPath(nodeA,nodeA);
|
||||
Assert.assertEquals(0,path.nodes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLine()
|
||||
{
|
||||
Graph graph = new Graph();
|
||||
graph.addEdge(new Edge(nodeA,nodeB));
|
||||
Assert.assertEquals(2,graph.getNodes().size());
|
||||
Assert.assertEquals(1,graph.getEdges().size());
|
||||
Path path = graph.getPath(nodeA,nodeB);
|
||||
Assert.assertEquals(2,path.nodes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTriangleDirected()
|
||||
{
|
||||
Graph graph = new Graph();
|
||||
graph.addEdge(new Edge(nodeA,nodeB));
|
||||
graph.addEdge(new Edge(nodeA,nodeC));
|
||||
graph.addEdge(new Edge(nodeB,nodeC));
|
||||
Assert.assertEquals(3,graph.getNodes().size());
|
||||
Assert.assertEquals(3,graph.getEdges().size());
|
||||
Path path = graph.getPath(nodeA,nodeB);
|
||||
Assert.assertEquals(2,path.nodes());
|
||||
path = graph.getPath(nodeA,nodeC);
|
||||
Assert.assertEquals(2,path.nodes());
|
||||
path = graph.getPath(nodeB,nodeC);
|
||||
Assert.assertEquals(2,path.nodes());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSquareDirected()
|
||||
{
|
||||
Graph graph = new Graph();
|
||||
graph.addEdge(new Edge(nodeA,nodeB));
|
||||
graph.addEdge(new Edge(nodeB,nodeC));
|
||||
graph.addEdge(new Edge(nodeA,nodeD));
|
||||
graph.addEdge(new Edge(nodeD,nodeC));
|
||||
Assert.assertEquals(4,graph.getNodes().size());
|
||||
Assert.assertEquals(4,graph.getEdges().size());
|
||||
Path path = graph.getPath(nodeA,nodeC);
|
||||
Assert.assertEquals(3,path.nodes());
|
||||
|
||||
path = graph.getPath(nodeC,nodeA);
|
||||
Assert.assertEquals(null,path);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSquareCyclic()
|
||||
{
|
||||
Graph graph = new Graph();
|
||||
graph.addEdge(new Edge(nodeA,nodeB));
|
||||
graph.addEdge(new Edge(nodeB,nodeC));
|
||||
graph.addEdge(new Edge(nodeC,nodeD));
|
||||
graph.addEdge(new Edge(nodeD,nodeA));
|
||||
Assert.assertEquals(4,graph.getNodes().size());
|
||||
Assert.assertEquals(4,graph.getEdges().size());
|
||||
Path path = graph.getPath(nodeA,nodeB);
|
||||
Assert.assertEquals(2,path.nodes());
|
||||
|
||||
path = graph.getPath(nodeA,nodeC);
|
||||
Assert.assertEquals(3,path.nodes());
|
||||
path = graph.getPath(nodeA,nodeD);
|
||||
Assert.assertEquals(4,path.nodes());
|
||||
|
||||
graph.addNode(nodeE);
|
||||
path = graph.getPath(nodeA,nodeE);
|
||||
Assert.assertEquals(null,path);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
<Ref id="Contexts" />
|
||||
</Set>
|
||||
<Set name="configurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.support.FileConfigurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.FileConfigurationManager">
|
||||
<Set name="file">
|
||||
<Property name="test.targetdir" default="target" />/xml-configured-jetty.properties
|
||||
</Set>
|
||||
|
|
Loading…
Reference in New Issue