description = "[ groupId :artifactId {:version :scope :packaging} ]",
help = "dependency identifier, ex: \"org.jboss.forge:forge-api:1.0.0\"") Dependency gav,
final PipeOut out
)
{
DependencyFacet deps = project.getFacet(DependencyFacet.class);
if (!deps.hasDependency(gav)
|| shell.promptBoolean("Dependency already exists [" + gav.getGroupId() + ":" + gav.getArtifactId()
+ "], continue?", true))
{
boolean requestProcessed = false;
if (deps.hasEffectiveManagedDependency(gav))
{
Dependency existingDep = deps.getEffectiveManagedDependency(gav);
if (shell.promptBoolean("Dependency is managed [" +
existingDep.getGroupId() + ":" +
existingDep.getArtifactId() + ":" + existingDep.getVersion()
+ "], reference the managed dependency?", true))
{
DependencyBuilder depToAdd = DependencyBuilder.create();
depToAdd.setGroupId(gav.getGroupId());
depToAdd.setArtifactId(gav.getArtifactId());
deps.addDependency(depToAdd);
out.println("Added dependency [" + depToAdd + "]");
requestProcessed = true;
}
}
if (!requestProcessed)
{
DependencyBuilder search = DependencyBuilder.create(gav).setVersion("[0,)");
List<Dependency> availableVersions = deps.resolveAvailableVersions(search);
if (availableVersions.isEmpty())
{
throw new RuntimeException("No available versions resolved for dependency [" + gav + "]");
}
if (!availableVersions.contains(gav))
{
ShellMessages.info(out, "No artifact found for dependency [" + gav + "]");
if (availableVersions.size() > 1)
{
gav = shell.promptChoiceTyped("Add which version?", availableVersions);
}
else if (shell.promptBoolean("Use [" + availableVersions.get(0) + "] instead?", true))
{
gav = availableVersions.get(0);
}
else
{
throw new RuntimeException("Could not add dependency [" + gav + "]");
}
}
if (deps.hasDependency(gav))
{
Dependency dependency = deps.getDependency(gav);
deps.removeDependency(dependency);
}
deps.addDependency(gav);
out.println("Added dependency [" + gav + "]");
}
}
else
{