Skip to content

Commit

Permalink
better graph access and some cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
ltearno committed Jun 24, 2015
1 parent 1209722 commit 773d36d
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 134 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ Here's an example of a result :

It is possible to visualize dynamically the graph dependency. The graph is using WebGL and allows to walk in the 3D space with the W, S, A, D, Q and E keys. It is using the VivaGraph and NGraph libraries.

First you need to create a session, then you might go to this url :
You can enter the `graph` command :

http://localhost:90/graph.html
> graph
To display the graph, go to : graph.html?session=1441798206

Then click on the given link to see the graph for your current session.

![](pomgraph.png)

### The graph window

In the main part, you can navigate with W,A,S,D,E,A and the arrow keys. On the right side, you can edit javascript filters and customizers for node and links.

## Analysing dependencies

... Documentation to be written ...
Expand Down
9 changes: 8 additions & 1 deletion ngraph.pixel-master/demo/pom/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ document.addEventListener('DOMContentLoaded', function() {
window.animatedGraph = animateCheckbox.checked;
});

function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var req = new XMLHttpRequest();
req.open('GET', '/graph', true);
req.open('GET', '/graph?session=' + getParameterByName('session'), true);
req.onreadystatechange = function (e) {
if (req.readyState == 4) {
if (req.status == 200) {
Expand Down
9 changes: 8 additions & 1 deletion ngraph.pixel-master/demo/pom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ document.addEventListener('DOMContentLoaded', function() {
window.animatedGraph = animateCheckbox.checked;
});

function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var req = new XMLHttpRequest();
req.open('GET', '/graph', true);
req.open('GET', '/graph?session=' + getParameterByName('session'), true);
req.onreadystatechange = function (e) {
if (req.readyState == 4) {
if (req.status == 200) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/lteconsulting/pomexplorer/AppFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import fr.lteconsulting.pomexplorer.commands.Commands;
import fr.lteconsulting.pomexplorer.commands.DependsCommand;
import fr.lteconsulting.pomexplorer.commands.GavsCommand;
import fr.lteconsulting.pomexplorer.commands.GraphXCommand;
import fr.lteconsulting.pomexplorer.commands.GraphCommand;
import fr.lteconsulting.pomexplorer.commands.HelpCommand;
import fr.lteconsulting.pomexplorer.commands.ProjectsCommand;
import fr.lteconsulting.pomexplorer.commands.ReleaseCommand;
Expand Down Expand Up @@ -57,7 +57,7 @@ public Commands commands()
commands.addCommand( new ReleaseCommand() );
commands.addCommand( new ChangeCommand() );
commands.addCommand( new BuildCommand() );
commands.addCommand( new GraphXCommand() );
commands.addCommand( new GraphCommand() );
commands.addCommand( new CheckCommand() );
commands.addCommand( new ClassesCommand() );
}
Expand Down
135 changes: 74 additions & 61 deletions src/main/java/fr/lteconsulting/pomexplorer/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.IOException;
import java.nio.channels.Channel;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -28,7 +29,6 @@
import com.google.gson.Gson;

import fr.lteconsulting.hexa.client.tools.Func2;
import fr.lteconsulting.pomexplorer.graph.relation.DependencyRelation;
import fr.lteconsulting.pomexplorer.graph.relation.Relation;

public class WebServer
Expand All @@ -39,22 +39,22 @@ public class WebServer

private final Map<Integer, Client> clients = new HashMap<>();

public WebServer(XWebServer xWebServer, Func2<Client, String, String> socketCallback)
public WebServer( XWebServer xWebServer, Func2<Client, String, String> socketCallback )
{
this.xWebServer = xWebServer;
this.socketCallback = socketCallback;
}

public interface XWebServer
{
void onNewClient(Client client);
void onNewClient( Client client );

void onClientLeft(Client client);
void onClientLeft( Client client );
}

private Client getClient(Channel channel)
private Client getClient( Channel channel )
{
return clients.get(System.identityHashCode(channel));
return clients.get( System.identityHashCode( channel ) );
}

static class EdgeDto
Expand All @@ -64,15 +64,15 @@ static class EdgeDto
String to;

String label;

Relation relation;

public EdgeDto(String from, String to, Relation relation)
public EdgeDto( String from, String to, Relation relation )
{
this.from = from;
this.to = to;
this.relation = relation;

label = relation.toString();
}
}
Expand All @@ -84,105 +84,118 @@ static class GraphDto
Set<EdgeDto> relations;
}

private String getQueryParameter( HttpServerExchange exchange, String name )
{
Deque<String> de = exchange.getQueryParameters().get( name );
if( de == null || de.isEmpty() )
return null;

assert de.size() == 1;
String value = de.getFirst();
return value;
}

public void start()
{
PathHandler pathHandler = new PathHandler();

// web app static files
pathHandler.addPrefixPath("/", new ResourceHandler(new ClassPathResourceManager(getClass().getClassLoader(),
"fr/lteconsulting/pomexplorer/webapp")).addWelcomeFiles("index.html"));
pathHandler.addPrefixPath( "/", new ResourceHandler( new ClassPathResourceManager( getClass().getClassLoader(), "fr/lteconsulting/pomexplorer/webapp" ) ).addWelcomeFiles( "index.html" ) );

// http end point
pathHandler.addExactPath("/graph", new HttpHandler()
pathHandler.addExactPath( "/graph", new HttpHandler()
{
boolean takeGav(GAV gav)
{
return true;//gav.getGroupId().startsWith("fr");
}

boolean takeRelation(Relation relation)
{
return true;/*(relation instanceof DependencyRelation)
&& (((DependencyRelation)relation).getScope() == null || "COMPILE"
.equals(((DependencyRelation)relation).getScope()));*/
}

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception
public void handleRequest( HttpServerExchange exchange ) throws Exception
{
List<WorkingSession> sessions = AppFactory.get().sessions();
if (sessions == null || sessions.isEmpty())
if( sessions == null || sessions.isEmpty() )
{
exchange.getResponseSender().send( "No session available. Go to main page !" );
return;
}

WorkingSession session = null;

WorkingSession session = sessions.get(0);
try
{
Integer sessionId = Integer.parseInt( getQueryParameter( exchange, "session" ) );
if( sessionId != null )
{
for( WorkingSession s : sessions )
{
if( System.identityHashCode( s ) == sessionId )
{
session = s;
break;
}
}
}
}
catch( Exception e )
{
}

if(session == null )
session = sessions.get( 0 );

DirectedGraph<GAV, Relation> g = session.graph().internalGraph();

GraphDto dto = new GraphDto();
dto.gavs = new HashSet<>();
dto.relations = new HashSet<>();
for (GAV gav : g.vertexSet())
for( GAV gav : g.vertexSet() )
{
if (!takeGav(gav))
continue;
dto.gavs.add( gav.toString() );

dto.gavs.add(gav.toString());

for (Relation relation : g.outgoingEdgesOf(gav))
for( Relation relation : g.outgoingEdgesOf( gav ) )
{
if (!takeRelation(relation))
continue;

GAV target = g.getEdgeTarget(relation);
if (!takeGav(target))
continue;

EdgeDto edge = new EdgeDto(gav.toString(), target.toString(), relation);
dto.relations.add(edge);
GAV target = g.getEdgeTarget( relation );
EdgeDto edge = new EdgeDto( gav.toString(), target.toString(), relation );
dto.relations.add( edge );
}
}

Gson gson = new Gson();
exchange.getResponseSender().send(gson.toJson(dto));
exchange.getResponseSender().send( gson.toJson( dto ) );
}
});
} );

// web socket end point
pathHandler.addPrefixPath("/ws", websocket(new WebSocketConnectionCallback()
pathHandler.addPrefixPath( "/ws", websocket( new WebSocketConnectionCallback()
{
@Override
public void onConnect(WebSocketHttpExchange exchange, WebSocketChannel channel)
public void onConnect( WebSocketHttpExchange exchange, WebSocketChannel channel )
{
Client client = new Client(System.identityHashCode(channel), channel);
clients.put(client.getId(), client);
Client client = new Client( System.identityHashCode( channel ), channel );
clients.put( client.getId(), client );

xWebServer.onNewClient(client);
xWebServer.onNewClient( client );

channel.getReceiveSetter().set(new AbstractReceiveListener()
channel.getReceiveSetter().set( new AbstractReceiveListener()
{
@Override
protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message)
protected void onFullTextMessage( WebSocketChannel channel, BufferedTextMessage message )
{
String messageData = socketCallback.exec(getClient(channel), message.getData());
WebSockets.sendText(messageData, channel, null);
String messageData = socketCallback.exec( getClient( channel ), message.getData() );
WebSockets.sendText( messageData, channel, null );
}

@Override
protected void onClose(WebSocketChannel webSocketChannel, StreamSourceFrameChannel channel)
throws IOException
protected void onClose( WebSocketChannel webSocketChannel, StreamSourceFrameChannel channel ) throws IOException
{
super.onClose(webSocketChannel, channel);
super.onClose( webSocketChannel, channel );

xWebServer.onClientLeft(getClient(channel));
clients.remove(System.identityHashCode(channel));
xWebServer.onClientLeft( getClient( channel ) );
clients.remove( System.identityHashCode( channel ) );
}
});
} );

channel.resumeReceives();
}
}));
} ) );

Undertow server = Undertow.builder().addHttpListener(90, "0.0.0.0").setHandler(pathHandler).build();
Undertow server = Undertow.builder().addHttpListener( 90, "0.0.0.0" ).setHandler( pathHandler ).build();
server.start();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ public class AnalyzeCommand
@Help( "analyse all the pom files in a directory, recursively" )
public String directory( Client client, WorkingSession session, String directory )
{
StringBuilder log = new StringBuilder();

client.send( "Analyzing directoy '" + directory + "'...<br/>" );

PomAnalyzer analyzer = new PomAnalyzer();
analyzer.analyze( directory, session, client );

return "Analyzis completed for '" + directory + "'.";
log.append( "Analyzis completed for '" + directory + "'." );

return log.toString();
}
}
Loading

0 comments on commit 773d36d

Please sign in to comment.