description = "[ groupId:artifactId ]",
help = "exclusion identifier, ex: \"org.jboss.forge:forge-api\"") final Dependency exclusion,
final PipeOut out
)
{
DependencyFacet deps = project.getFacet(DependencyFacet.class);
if (!deps.hasEffectiveDependency(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.addDirectDependency(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())
{
if (Strings.isNullOrEmpty(gav.getVersion())
|| !shell.promptBoolean("No artifacts resolved from available repositories, install anyway?"))
{
throw new RuntimeException("No available versions resolved for dependency [" + gav + "]");
}
}
else 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.hasEffectiveDependency(gav))
{
Dependency dependency = deps.getEffectiveDependency(gav);
deps.removeDependency(dependency);
}
if (exclusion != null)
{
gav.getExcludedDependencies().add(exclusion);
}
deps.addDirectDependency(gav);
out.println("Added dependency [" + gav + "]" + (exclusion != null ? " excluding [" + exclusion + "]" : ""));
}
}
else
{