Last active
August 29, 2015 14:22
-
-
Save thescouser89/1819c9d843907b953d29 to your computer and use it in GitHub Desktop.
Cartographer quickstart attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.commonjava.maven.plugins.betterdep.impl; | |
import org.commonjava.maven.atlas.graph.RelationshipGraph; | |
import org.commonjava.maven.atlas.graph.ViewParams; | |
import org.commonjava.maven.atlas.graph.filter.ProjectRelationshipFilter; | |
import org.commonjava.maven.atlas.graph.mutate.ManagedDependencyMutator; | |
import org.commonjava.maven.atlas.graph.spi.neo4j.FileNeo4jConnectionFactory; | |
import org.commonjava.maven.atlas.ident.ref.ProjectVersionRef; | |
import org.commonjava.maven.cartographer.Cartographer; | |
import org.commonjava.maven.cartographer.CartographerBuilder; | |
import org.commonjava.maven.cartographer.discover.DefaultDiscoveryConfig; | |
import org.commonjava.maven.cartographer.discover.DiscoveryResult; | |
import org.commonjava.maven.cartographer.preset.PresetSelector; | |
import org.commonjava.maven.galley.model.Location; | |
import org.commonjava.maven.galley.model.SimpleLocation; | |
import java.io.File; | |
import java.nio.file.Files; | |
import java.util.*; | |
public class Test { | |
public static void main(String[] args) throws Exception { | |
// just create temp dirs that cartographer seems to need. | |
File tempDir = Files.createTempDirectory("test").toFile(); | |
File tempDirFac = Files.createTempDirectory("test2").toFile(); | |
// tell cartographer where to look for stuff | |
Location loc = new SimpleLocation(MavenLocationExpander.EXPANSION_TARGET); | |
List<Location> haha = new LinkedList<Location>(); | |
haha.add(loc); | |
// TODO: need to tell it where to look for artifacts. | |
// TODO: so what is the simple location thing then? | |
MavenLocationExpander mavenLocations = new MavenLocationExpander(haha, null, null); | |
// build the cartographer builder | |
CartographerBuilder cartoBuilder = | |
new CartographerBuilder(tempDir, | |
1, | |
new FileNeo4jConnectionFactory(tempDirFac, true)) | |
.withLocationExpander(mavenLocations) | |
.withSourceManager(mavenLocations) | |
.withDefaultTransports(); | |
// get the carto object | |
Cartographer carto = cartoBuilder.build(); | |
Set<ProjectVersionRef> roots = new HashSet<ProjectVersionRef>(); | |
// why do we need a preset selector? | |
PresetSelector presets = new PresetSelector(); | |
String preset = "betterdep"; | |
Map<String, Object> presetParams = new HashMap<String, Object>(); | |
// ? | |
ProjectRelationshipFilter filter = presets.getPresetFilter(preset, "betterdep", presetParams); | |
// so here we specify which GAV we want to see. | |
ProjectVersionRef projectRef = new ProjectVersionRef("com.google.code.gson", "gson", "2.3.1"); | |
roots.add(projectRef); | |
// ? | |
RelationshipGraph graph = carto.getGraphFactory().open(new ViewParams("betterdep", filter, new ManagedDependencyMutator(), roots), true); | |
// ? | |
DefaultDiscoveryConfig config = new DefaultDiscoveryConfig(MavenLocationExpander.EXPANSION_TARGET); | |
// get the result of the relationship? | |
DiscoveryResult result = cartoBuilder.getDiscoverer().discoverRelationships(projectRef, graph, config); | |
// print out the result | |
System.out.println(result); | |
// debug line to see if we've reached here. | |
System.out.println("Hello world"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment