{
DirectoryResource savedLocation = shell.getCurrentDirectory();
try
{
shell.setCurrentResource(buildDir);
Project project = shell.getCurrentProject();
if (project == null)
{
throw new IllegalStateException("Unable to recognise plugin project in ["
+ buildDir.getFullyQualifiedName() + "]");
}
DependencyFacet deps = project.getFacet(DependencyFacet.class);
DependencyBuilder shellApi = DependencyBuilder.create("org.jboss.forge:forge-shell-api");
String apiVersion = null;
if (!deps.hasEffectiveDependency(shellApi)
&& !prompt.promptBoolean(
"The project does not appear to be a Forge Plugin Project, install anyway?",
false))
{
throw new Abort("Installation aborted");
}
else
{
if (apiVersion == null)
{
Dependency directDependency = deps.getDirectDependency(shellApi);
if ((directDependency != null) && !Strings.isNullOrEmpty(directDependency.getVersion()))
apiVersion = directDependency.getVersion();
}
if (apiVersion == null)
{
// Fall back to checking managed dependencies for a version
Dependency managedDependency = deps.getManagedDependency(shellApi);
if ((managedDependency != null) && !Strings.isNullOrEmpty(managedDependency.getVersion()))
apiVersion = managedDependency.getVersion();
}
if (apiVersion == null)
{
// Now completely give up and just use the result from the build
Dependency effectiveDependency = deps.getEffectiveDependency(shellApi);
if (effectiveDependency != null)
apiVersion = effectiveDependency.getVersion();
else
apiVersion = environment.getRuntimeVersion();
}
}
/**
* Make sure that our PROVIDED modules are not included in the module dependencies
*/
// TODO Weld bug requires us to correct /add module for Seam Render dependency
List<String> groupIds = Arrays.asList("org.jboss.seam.render", "org.jboss.forge");
List<Dependency> dependencies = deps.getDependencies();
for (Dependency dependency : dependencies)
{
if (groupIds.contains(dependency.getGroupId())
&& !(ScopeType.PROVIDED.equals(dependency.getScopeTypeEnum())
|| ScopeType.TEST.equals(dependency.getScopeTypeEnum())))
{
ShellMessages.warn(out, "Dependency [" + dependency.toCoordinates()
+ "] was not correctly marked as PROVIDED scope; this has been corrected.");
deps.addDirectDependency(DependencyBuilder.create(dependency).setScopeType(ScopeType.PROVIDED));
}
}
ShellMessages.info(out, "Invoking build with underlying build system.");
Resource<?> artifact = project.getFacet(PackagingFacet.class).createBuilder().runTests(false).build();
if ((artifact != null) && artifact.exists())
{
MetadataFacet meta = project.getFacet(MetadataFacet.class);
Dependency dep = meta.getOutputDependency();
ShellMessages.info(out, "Installing plugin artifact.");
// TODO Figure out a better plugin versioning strategy than random numbers, also see if unloading is