public Result execute(UIExecutionContext context) throws Exception
{
// TODO: Option to save sources?
File tempDir = OperatingSystemUtils.createTempDir();
DirectoryResource projectRoot = resourceFactory.create(DirectoryResource.class, tempDir);
UIProgressMonitor progressMonitor = context.getProgressMonitor();
UIOutput output = context.getUIContext().getProvider().getOutput();
progressMonitor.beginTask("Installing Addon from Git", 4);
progressMonitor.subTask("Cloning repository in " + tempDir);
// Clone repository
cloneTo(projectRoot);
progressMonitor.worked(1);
progressMonitor.subTask("Installing project into local repository");
// Build project
Project project = projectFactory.findProject(projectRoot);
if (project == null)
{
return Results.fail("No project found in root " + projectRoot.getFullyQualifiedName());
}
Coordinate buildCoordinate = project.getFacet(MetadataFacet.class).getOutputDependency().getCoordinate();
try
{
project.getFacet(PackagingFacet.class).createBuilder()
.addArguments("clean", "install", "-Dversion.furnace=" + furnace.getVersion())
.runTests(false)
.build(output.out(), output.err());
}
catch (BuildException e)
{
return Results.fail("Unable to execute project build", e);
}
progressMonitor.worked(1);
AddonId id = null;
try
{
if (coordinate.hasValue())
{
try
{
id = AddonId.fromCoordinates(coordinate.getValue());
}
catch (IllegalArgumentException e)
{
id = AddonId.from(coordinate.getValue(), buildCoordinate.getVersion());
}
}
else
{
id = AddonId.from(buildCoordinate.getGroupId() + ":" + buildCoordinate.getArtifactId(),
buildCoordinate.getVersion());
}
progressMonitor.subTask("Removing previous addon installation (" + id + ")");
RemoveRequest removeRequest = addonManager.remove(id);
removeRequest.perform();
Addons.waitUntilStopped(registry.getAddon(id));
progressMonitor.worked(1);
progressMonitor.subTask("Installing addon (" + id + ")");
InstallRequest installRequest = addonManager.install(id);
installRequest.perform();
progressMonitor.done();
return Results.success("Addon " + id + " was installed successfully.");
}
catch (Throwable t)
{
return Results.fail("Addon " + id + " could not be installed: " + t.getMessage(), t);