* @throws Abort
*/
public void installFromProject(final DirectoryResource buildDir, final Dependency coordinates) throws Abort
{
DirectoryResource root = projectFactory.findProjectRootRecusively(buildDir);
Project rootProject = projectFactory.findProject(root);
if (rootProject == null)
{
throw new IllegalArgumentException("Unable to recognise plugin project in ["
+ buildDir.getFullyQualifiedName() + "]");
}
Project pluginProject = findPluginProject(rootProject, coordinates);
if (pluginProject == null)
{
throw new Abort("The project does not contain a valid Forge Plugin project. Installation aborted");
}
DependencyFacet deps = pluginProject.getFacet(DependencyFacet.class);
String apiVersion = null;
Dependency directDependency = deps.getDirectDependency(SHELL_API);
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(SHELL_API);
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(SHELL_API);
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<String> providedDeps = Arrays.asList("forge-javaee-api", "forge-maven-api", "forge-scaffold-api",
"forge-scaffoldx-api", "forge-shell-api");
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(shell, "Dependency [" + dependency.toCoordinates()
+ "] was not correctly marked as PROVIDED scope; this has been corrected.");
deps.addDirectDependency(DependencyBuilder.create(dependency).setScopeType(ScopeType.PROVIDED));
}
else if (dependency.getGroupId().equals("org.jboss.forge")
&& !providedDeps.contains(dependency.getArtifactId())
&& !ScopeType.TEST.equals(deps.getEffectiveDependency(dependency).getScopeTypeEnum()))
{
ShellMessages.warn(shell,
"Plugin has a dependency on internal Forge API [" + dependency
+ "] - this is not allowed and may cause failures.");
}
}
ShellMessages.info(shell, "Invoking build with underlying build system.");
// Build the whole project
// Inter-module dependencies are not resolved when mvn package is just run. Perhaps it should install ?
Resource<?> artifact;
if (rootProject.equals(pluginProject))
{
artifact = rootProject.getFacet(PackagingFacet.class).createBuilder().runTests(false).build();
}
else
{
rootProject.getFacet(PackagingFacet.class).createBuilder().addArguments("clean", "install").runTests(false).build();
artifact = pluginProject.getFacet(PackagingFacet.class).getFinalArtifact();
}
// However, get only the necessary plugin artifact
if ((artifact != null) && artifact.exists())
{
MetadataFacet meta = rootProject.getFacet(MetadataFacet.class);