}
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);
Dependency dep = meta.getOutputDependency();
ShellMessages.info(shell, "Installing plugin artifact.");
// TODO Figure out a better plugin versioning strategy than random numbers, also see if unloading is
// possible to avoid this entirely.
createModule(
pluginProject,
DependencyBuilder.create(dep).setVersion(
dep.getVersion() + "-" + UUID.randomUUID().toString()),
artifact, apiVersion);
}
else
{
throw new IllegalStateException("Build artifact [" + artifact