Skip to content

Commit

Permalink
Implemented FORGE-1416 - Command to list which addons are installed a…
Browse files Browse the repository at this point in the history
…nd available
  • Loading branch information
lincolnthree committed Jan 3, 2014
1 parent 100b976 commit 63ff3dd
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ public interface AddonCommandConstants
String ADDON_INSTALL_COMMAND_NAME = "Install an Addon";
String ADDON_INSTALL_COMMAND_NAME_NO_GUI = "addon-install";
String ADDON_BUILD_INSTALL_COMMAND_NAME = "Build and Install an Addon";
String ADDON_BUILD_INSTALL_COMMAND_NAME_NO_GUI= "addon-build-and-install";
String ADDON_BUILD_INSTALL_COMMAND_NAME_NO_GUI = "addon-build-and-install";
String ADDON_INSTALL_COMMAND_DESCRIPTION = "Command to install a Furnace 2 addon.";
String ADDON_BUILD_INSTALL_COMMAND_DESCRIPTION = "Command to build and install a Furnace 2 addon.";
String ADDON_LIST_COMMAND_DESCRIPTION = "Command to list all currently installed Addons.";
String ADDON_LIST_COMMAND_NAME = "addon-list";
String ADDON_REMOVE_COMMAND_NAME = "Remove an Addon";
String ADDON_REMOVE_COMMAND_NAME_NO_GUI= "addon-remove";
String ADDON_REMOVE_COMMAND_NAME_NO_GUI = "addon-remove";
String ADDON_REMOVE_COMMAND_DESCRIPTION = "Command to remove a Furnace 2 addon.";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.jboss.forge.addon.manager.impl.commands;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import javax.inject.Inject;

import org.jboss.forge.addon.ui.AbstractUICommand;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.util.Categories;
import org.jboss.forge.addon.ui.util.Metadata;
import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.addons.AddonId;
import org.jboss.forge.furnace.repositories.AddonRepository;

public class AddonListCommand extends AbstractUICommand implements AddonCommandConstants
{

@Inject
private Furnace furnace;

@Override
public Metadata getMetadata(UIContext context)
{
return Metadata.from(super.getMetadata(context), getClass())
.name(ADDON_LIST_COMMAND_NAME)
.description(ADDON_LIST_COMMAND_DESCRIPTION)
.category(Categories.create(ADDON_MANAGER_CATEGORIES));
}

@Override
public void initializeUI(UIBuilder builder) throws Exception
{
}

@Override
public Result execute(UIExecutionContext context) throws Exception
{
Set<AddonId> choices = new TreeSet<>();
for (AddonRepository repository : furnace.getRepositories())
{
for (AddonId id : repository.listEnabled())
{
choices.add(id);
}
}

Iterator<AddonId> iterator = choices.iterator();
StringBuilder builder = new StringBuilder();
while (iterator.hasNext())
{
AddonId addonId = iterator.next();
builder.append(addonId.toCoordinates());

if (iterator.hasNext())
builder.append("\n");
}
return Results.success("Currently installed addons: " + builder.toString());
}

@Override
public boolean isEnabled(UIContext context)
{
return !context.getProvider().isGUI();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AddonRemoveCommand extends AbstractUICommand implements AddonComman
{

@Inject
private Furnace forge;
private Furnace furnace;

@Inject
private AddonManager manager;
Expand All @@ -48,15 +48,16 @@ public class AddonRemoveCommand extends AbstractUICommand implements AddonComman
public Metadata getMetadata(UIContext context)
{
boolean gui = context.getProvider().isGUI();
return Metadata.from(super.getMetadata(context), getClass()).name(gui ? ADDON_REMOVE_COMMAND_NAME : ADDON_REMOVE_COMMAND_NAME_NO_GUI)
return Metadata.from(super.getMetadata(context), getClass())
.name(gui ? ADDON_REMOVE_COMMAND_NAME : ADDON_REMOVE_COMMAND_NAME_NO_GUI)
.description(ADDON_REMOVE_COMMAND_DESCRIPTION).category(Categories.create(ADDON_MANAGER_CATEGORIES));
}

@Override
public void initializeUI(UIBuilder builder) throws Exception
{
Set<AddonId> choices = new TreeSet<AddonId>();
for (AddonRepository repository : forge.getRepositories())
Set<AddonId> choices = new TreeSet<>();
for (AddonRepository repository : furnace.getRepositories())
{
// Avoid immutable repositories
if (repository instanceof MutableAddonRepository)
Expand Down
13 changes: 12 additions & 1 deletion addon-manager/tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.forge.addon</groupId>
Expand Down Expand Up @@ -32,6 +33,11 @@
<artifactId>maven-impl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>projects</artifactId>
<classifier>forge-addon</classifier>
</dependency>

<dependency>
<groupId>org.jboss.forge.furnace.test</groupId>
Expand All @@ -43,6 +49,11 @@
<artifactId>arquillian-furnace-classpath</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>shell-test-harness</artifactId>
<classifier>forge-addon</classifier>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.addon.manager.commands;

import static org.hamcrest.CoreMatchers.containsString;

import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.addon.shell.test.ShellTest;
import org.jboss.forge.addon.ui.result.Failed;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.arquillian.AddonDependency;
import org.jboss.forge.arquillian.Dependencies;
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.furnace.repositories.AddonDependencyEntry;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
@RunWith(Arquillian.class)
public class AddonListCommandTest
{
@Deployment
@Dependencies({
@AddonDependency(name = "org.jboss.forge.addon:maven"),
@AddonDependency(name = "org.jboss.forge.addon:projects"),
@AddonDependency(name = "org.jboss.forge.addon:addon-manager"),
@AddonDependency(name = "org.jboss.forge.addon:shell-test-harness")
})
public static ForgeArchive getDeployment()
{
ForgeArchive archive = ShrinkWrap.create(ForgeArchive.class)
.addBeansXML()
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.forge.addon:maven"),
// TODO Not sure why projects addon must be included for this to work. Weld bug?
AddonDependencyEntry.create("org.jboss.forge.addon:projects"),
AddonDependencyEntry.create("org.jboss.forge.addon:addon-manager"),
AddonDependencyEntry.create("org.jboss.forge.addon:shell-test-harness"),
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi")
);

return archive;
}

private final int timeoutQuantity = 5;

@Inject
private ShellTest test;

@Test(timeout = 10000)
public void testAddonListCommand() throws Exception
{
test.clearScreen();
Result result = test.execute("addon-list", timeoutQuantity, TimeUnit.SECONDS);
Assert.assertFalse(result instanceof Failed);
String out = test.getStdOut();
Assert.assertThat(out, containsString("org.jboss.forge.addon:maven"));
Assert.assertThat(out, containsString("org.jboss.forge.addon:addon-manager"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static ForgeArchive getDeployment()
return archive;
}

private final int timeoutQuantity = 500;
private final int timeoutQuantity = 5;

@Inject
private ShellTest test;
Expand Down

0 comments on commit 63ff3dd

Please sign in to comment.