-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented FORGE-1416 - Command to list which addons are installed a…
…nd available
- Loading branch information
1 parent
100b976
commit 63ff3dd
Showing
6 changed files
with
167 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ager/impl/src/main/java/org/jboss/forge/addon/manager/impl/commands/AddonListCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ager/tests/src/test/java/org/jboss/forge/addon/manager/commands/AddonListCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters