Skip to content

Commit

Permalink
dependency print finished
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKl committed Jun 22, 2015
1 parent ff163c5 commit f251219
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void setPepperConfiguration(PepperStarterConfiguration pepperConf) {
}

public enum COMMAND {
PRINT_DEPS("dependencies", "deps", "Bundle id or groupId, artifactId and version split by ::", "displays all dependencies of the specified component"),
PRINT_DEPS("dependencies", "deps", "Bundle id or GROUP_ID::ARTIFACT_ID::VERSION::MAVEN_REPOSITORY_URL or plugin names split by space; parameter all prints dependencies for all plugins", "displays all dependencies of the specified component"),
//
UPDATE("update", "u", "module name or location", "Updates the pepper module(s). Parameter \"all\" updates all modules listed in modules.xml."),
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,9 @@ private RemoteRepository buildRepo(String id, String url){
return repoBuilder.build();
}

/** This method starts invokes the computation of the dependency tree. If no version is
* provided, the highest version in the specified maven repository is used. If no repository
* is provided, maven central and the korpling maven repository are used for trial. */
public String printDependencies(String groupId, String artifactId, String version, String repositoryUrl){
/* repositories */
RemoteRepository repo = null;
Expand Down Expand Up @@ -747,29 +750,29 @@ public String printDependencies(String groupId, String artifactId, String versio
CollectResult collectResult;
try {
collectResult = mvnSystem.collectDependencies( session, collectRequest );
return getDependencyPrint(collectResult.getRoot(), 0, 0);
return getDependencyPrint(collectResult.getRoot(), 0);
} catch (DependencyCollectionException e) {
logger.error("Could not print dependencies for ".concat(artifactId).concat("."));
}
return null;
}

private String getDependencyPrint(DependencyNode startNode, int level, int depth){
/** this method recursively computes */
private String getDependencyPrint(DependencyNode startNode, int depth){
String d = "";
for (int i=0; i<level; i++){
for (int i=0; i<depth; i++){
d+=" ";
}
d+= depth==0? "" : "+";
for (int i=1; i<depth; i++){
d+="-";
}
d+= depth==0? "" : "+- ";
d+=startNode.getArtifact().toString().concat(" (").concat(startNode.getDependency().getScope()).concat(")");
for (DependencyNode node : startNode.getChildren()){
d+=System.lineSeparator().concat(getDependencyPrint(node, level+1,depth+1));
d+=System.lineSeparator().concat(getDependencyPrint(node, depth+1));
}
return d;
}

/** This method tries to determine maven project coordinates from a bundle id to
* invoke {@link #printDependencies(String, String, String, String)}. */
protected String printDependencies(Bundle bundle){
String[] coords = null;
for (String s : forbiddenFruits){
Expand All @@ -778,8 +781,10 @@ protected String printDependencies(Bundle bundle){
return printDependencies(coords[0], coords[1], coords[3].replace(".SNAPSHOT", "-SNAPSHOT"), null);
}
}
//bundle could not be determined
return null;
//maven coordinates could not be determined, assume, we talk about a pepper plugin:
return printDependencies(bundle.getSymbolicName().substring(0, bundle.getSymbolicName().lastIndexOf('.')),
bundle.getSymbolicName().substring(bundle.getSymbolicName().lastIndexOf('.')+1),
bundle.getVersion().toString(), KORPLING_MAVEN_REPO);
}

private class MavenRepositoryListener extends AbstractRepositoryListener{
Expand Down

0 comments on commit f251219

Please sign in to comment.