Skip to content

Commit

Permalink
Merge branch 'container' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Mar 20, 2013
2 parents 3605d1f + 3b19b2d commit c2917b5
Show file tree
Hide file tree
Showing 145 changed files with 3,109 additions and 2,342 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

package org.jboss.forge.addon.manager;

import org.jboss.forge.container.AddonId;
import org.jboss.forge.container.addons.AddonId;
import org.jboss.forge.container.services.Exported;

@Exported
public interface AddonManager
{
public abstract InstallRequest install(AddonId addonId);
public abstract InstallRequest install(AddonId id);

public abstract boolean remove(AddonId entry);
public abstract boolean remove(AddonId id);

public abstract boolean disable(AddonId id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

import org.jboss.forge.addon.manager.AddonManager;
import org.jboss.forge.addon.manager.InstallRequest;
import org.jboss.forge.container.AddonId;
import org.jboss.forge.container.AddonRepository;
import org.jboss.forge.container.Forge;
import org.jboss.forge.container.addons.AddonId;
import org.jboss.forge.container.repositories.AddonRepository;
import org.jboss.forge.container.repositories.MutableAddonRepository;
import org.jboss.forge.dependencies.AddonDependencyResolver;
import org.jboss.forge.dependencies.DependencyNode;
import org.jboss.forge.dependencies.builder.DependencyQueryBuilder;
Expand All @@ -26,29 +28,45 @@
*/
public class AddonManagerImpl implements AddonManager
{
private AddonRepository repository;
private AddonDependencyResolver resolver;
private Forge forge;

@Inject
public AddonManagerImpl(AddonRepository repository, AddonDependencyResolver resolver)
public AddonManagerImpl(Forge forge, AddonDependencyResolver resolver)
{
this.repository = repository;
this.forge = forge;
this.resolver = resolver;
}

@Override
public InstallRequest install(AddonId addonId)
public InstallRequest install(AddonId id)
{
String coordinates = addonId.getName() + ":jar:forge-addon:" + addonId.getVersion();
String coordinates = id.getName() + ":jar:forge-addon:" + id.getVersion();
DependencyNode requestedAddonNode = resolver.resolveAddonDependencyHierarchy(DependencyQueryBuilder
.create(coordinates));

return new InstallRequestImpl(this, repository, requestedAddonNode);
return new InstallRequestImpl(this, forge, requestedAddonNode);
}

@Override
public boolean remove(AddonId entry)
public boolean remove(AddonId id)
{
return repository.disable(entry);
for (AddonRepository repository : forge.getRepositories())
{
if (repository instanceof MutableAddonRepository && repository.isEnabled(id))
return ((MutableAddonRepository) repository).undeploy(id);
}
return false;
}

@Override
public boolean disable(AddonId id)
{
for (AddonRepository repository : forge.getRepositories())
{
if (repository instanceof MutableAddonRepository && repository.isEnabled(id))
return ((MutableAddonRepository) repository).disable(id);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import org.jboss.forge.addon.manager.InstallRequest;
import org.jboss.forge.addon.manager.impl.filters.DirectAddonFilter;
import org.jboss.forge.addon.manager.impl.filters.LocalResourceFilter;
import org.jboss.forge.container.AddonDependency;
import org.jboss.forge.container.AddonId;
import org.jboss.forge.container.AddonRepository;
import org.jboss.forge.container.Forge;
import org.jboss.forge.container.addons.AddonId;
import org.jboss.forge.container.repositories.AddonDependencyEntry;
import org.jboss.forge.container.repositories.AddonRepository;
import org.jboss.forge.container.repositories.MutableAddonRepository;
import org.jboss.forge.container.util.Predicate;
import org.jboss.forge.dependencies.Coordinate;
import org.jboss.forge.dependencies.DependencyNode;
Expand All @@ -37,7 +39,7 @@
public class InstallRequestImpl implements InstallRequest
{
private AddonManager addonManager;
private AddonRepository repository;
private Forge forge;

private DependencyNode requestedAddonNode;
private Stack<DependencyNode> requiredAddons = new Stack<DependencyNode>();
Expand All @@ -50,10 +52,10 @@ public class InstallRequestImpl implements InstallRequest
*
* @param addonManager
*/
InstallRequestImpl(AddonManager addonManager, AddonRepository repository, DependencyNode requestedAddonNode)
InstallRequestImpl(AddonManager addonManager, Forge forge, DependencyNode requestedAddonNode)
{
this.addonManager = addonManager;
this.repository = repository;
this.forge = forge;
this.requestedAddonNode = requestedAddonNode;

/*
Expand Down Expand Up @@ -117,19 +119,35 @@ public void perform()
for (DependencyNode requiredAddon : getRequiredAddons())
{
AddonId requiredAddonId = toAddonId(requiredAddon);
if (repository.isDeployed(requiredAddonId))
boolean deployed = false;
for (AddonRepository repository : forge.getRepositories())
{
log.info("Addon " + requiredAddonId + " is already deployed. Skipping...");
if (repository.isDeployed(requiredAddonId))
{
log.info("Addon " + requiredAddonId + " is already deployed. Skipping...");
deployed = true;
break;
}
}
else

if (!deployed)
{
addonManager.install(requiredAddonId).perform();
}
}

AddonId requestedAddonId = toAddonId(requestedAddonNode);
deploy(requestedAddonId, requestedAddonNode);
repository.enable(requestedAddonId);

for (AddonRepository repository : forge.getRepositories())
{
if (repository instanceof MutableAddonRepository)
{
MutableAddonRepository mutableRespository = (MutableAddonRepository) repository;
deploy(mutableRespository, requestedAddonId, requestedAddonNode);
mutableRespository.enable(requestedAddonId);
break;
}
}
}

private AddonId toAddonId(DependencyNode node)
Expand All @@ -156,16 +174,17 @@ public boolean accept(DependencyNode node)
return AddonId.from(coord.getGroupId() + ":" + coord.getArtifactId(), coord.getVersion(), apiVersion);
}

private void deploy(AddonId addon, DependencyNode root)
private void deploy(MutableAddonRepository repository, AddonId addon, DependencyNode root)
{
List<File> resourceJars = toResourceJars(DependencyNodeUtil.select(root, new LocalResourceFilter(root)));

if (resourceJars.isEmpty())
{
log.fine("No resource JARs found for " + addon);
}
List<AddonDependency> addonDependencies =
toAddonDependencies(DependencyNodeUtil.select(root.getChildren().iterator(), new DirectAddonFilter(root)));
List<AddonDependencyEntry> addonDependencies =
toAddonDependencies(DependencyNodeUtil
.select(root.getChildren().iterator(), new DirectAddonFilter(root)));

if (addonDependencies.isEmpty())
{
Expand All @@ -175,9 +194,9 @@ private void deploy(AddonId addon, DependencyNode root)
repository.deploy(addon, addonDependencies, resourceJars);
}

private List<AddonDependency> toAddonDependencies(List<DependencyNode> dependencies)
private List<AddonDependencyEntry> toAddonDependencies(List<DependencyNode> dependencies)
{
List<AddonDependency> addonDependencies = new ArrayList<AddonDependency>();
List<AddonDependencyEntry> addonDependencies = new ArrayList<AddonDependencyEntry>();
for (DependencyNode dep : dependencies)
{
boolean export = false;
Expand All @@ -190,7 +209,7 @@ private List<AddonDependency> toAddonDependencies(List<DependencyNode> dependenc
else if ("provided".equalsIgnoreCase(scopeType))
export = false;
}
AddonDependency addonDep = AddonDependency.create(toAddonId(dep), export, optional);
AddonDependencyEntry addonDep = AddonDependencyEntry.create(toAddonId(dep), export, optional);
addonDependencies.add(addonDep);
}
return addonDependencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import javax.inject.Singleton;

import org.jboss.forge.addon.manager.AddonManager;
import org.jboss.forge.container.AddonId;
import org.jboss.forge.container.addons.AddonId;
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.context.UIBuilder;
import org.jboss.forge.ui.context.UIContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package org.jboss.forge.addon.manager.impl.commands;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import javax.inject.Inject;

import org.jboss.forge.container.AddonId;
import org.jboss.forge.addon.manager.AddonManager;
import org.jboss.forge.container.Forge;
import org.jboss.forge.container.addons.AddonId;
import org.jboss.forge.container.repositories.AddonRepository;
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.context.UIBuilder;
import org.jboss.forge.ui.context.UIContext;
Expand All @@ -22,6 +26,9 @@ public class AddonRemoveCommand implements UICommand, AddonCommandConstants
@Inject
private Forge forge;

@Inject
private AddonManager manager;

@Inject
private UISelectMany<AddonId> addons;

Expand All @@ -42,7 +49,15 @@ public UICommandMetadata getMetadata()
public void initializeUI(UIBuilder builder) throws Exception
{
addons.setLabel("Installed addons");
addons.setValueChoices(forge.getRepository().listEnabled());
Set<AddonId> choices = new HashSet<AddonId>();
for (AddonRepository repository : forge.getRepositories())
{
for (AddonId id : repository.listEnabled())
{
choices.add(id);
}
}
addons.setValueChoices(choices);
builder.add(addons);
}

Expand All @@ -55,13 +70,19 @@ public void validate(UIValidationContext context)
public Result execute(UIContext context) throws Exception
{
Iterator<AddonId> iterator = addons.getValue().iterator();
StringBuilder builder = new StringBuilder();
while (iterator.hasNext())
{
AddonId addonId = iterator.next();
forge.getRepository().disable(addonId);
forge.getRepository().undeploy(addonId);
builder.append(addonId.toCoordinates());

manager.disable(addonId);
manager.remove(addonId);

if (iterator.hasNext())
builder.append(", ");
}
return Results.success("hoorray");
return Results.success("Removed addons: " + builder.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@
import org.jboss.forge.arquillian.Addon;
import org.jboss.forge.arquillian.Dependencies;
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.container.AddonDependency;
import org.jboss.forge.container.AddonId;
import org.jboss.forge.container.AddonRegistry;
import org.jboss.forge.container.AddonRepository;
import org.jboss.forge.container.addons.AddonId;
import org.jboss.forge.container.addons.AddonRegistry;
import org.jboss.forge.container.repositories.AddonDependencyEntry;
import org.jboss.forge.container.repositories.AddonRepository;
import org.jboss.forge.container.versions.SingleVersion;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* FIXME This test needs to be refactored to be a bit less brittle. It breaks when addon POMs change.
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
@RunWith(Arquillian.class)
public class AddonManagerTest
{

@Deployment
@Dependencies({
@Addon(name = "org.jboss.forge:addon-manager", version = "2.0.0-SNAPSHOT"),
Expand All @@ -43,7 +48,7 @@ public static ForgeArchive getDeployment()
.create(ForgeArchive.class)
.addBeansXML()
.addAsAddonDependencies(
AddonDependency.create(AddonId.from("org.jboss.forge:addon-manager", "2.0.0-SNAPSHOT"))
AddonDependencyEntry.create(AddonId.from("org.jboss.forge:addon-manager", "2.0.0-SNAPSHOT"))
);

return archive;
Expand All @@ -69,7 +74,6 @@ public void testInstallingAddonWithSingleOptionalAddonDependency() throws Interr
Assert.assertEquals(1, request.getOptionalAddons().size());

request.perform();
Thread.sleep(500);

Assert.assertTrue(repository.isEnabled(addon));
Assert.assertEquals(2, repository.getAddonResources(addon).size());
Expand All @@ -78,19 +82,19 @@ public void testInstallingAddonWithSingleOptionalAddonDependency() throws Interr
Assert.assertTrue(repository.getAddonResources(addon).contains(
new File(repository.getAddonBaseDir(addon), "example-2.0.0-SNAPSHOT-forge-addon.jar")));

Set<AddonDependency> dependencies = repository.getAddonDependencies(addon);
Set<AddonDependencyEntry> dependencies = repository.getAddonDependencies(addon);
Assert.assertEquals(1, dependencies.size());
AddonDependency dependency = dependencies.toArray(new AddonDependency[dependencies.size()])[0];
AddonDependencyEntry dependency = dependencies.toArray(new AddonDependencyEntry[dependencies.size()])[0];
Assert.assertEquals("org.jboss.forge:example2", dependency
.getId().getName());
Assert.assertEquals("2.0.0-SNAPSHOT", dependency
Assert.assertEquals(new SingleVersion("2.0.0-SNAPSHOT"), dependency
.getId().getVersion());
Assert.assertTrue(dependency.isOptional());
Assert.assertFalse(dependency.isExport());
Assert.assertFalse(dependency.isExported());

Assert.assertFalse(registry.isRegistered(AddonId.from("org.jboss.forge:example2", "2.0.0-SNAPSHOT")));
Assert.assertTrue(registry.getRegisteredAddon(AddonId.from("org.jboss.forge:example2", "2.0.0-SNAPSHOT"))
.getStatus().isMissing());

Thread.sleep(500);
Assert.assertEquals(addonCount + 1, registry.getRegisteredAddons().size());
}

Expand All @@ -108,31 +112,22 @@ public void testInstallingAlreadyInstalledAddonWithTwoRequiredAddonDependency()

Assert.assertTrue(repository.isEnabled(resources));
Assert.assertEquals(3, repository.getAddonResources(resources).size());
Assert.assertTrue(repository.getAddonResources(resources).contains(
new File(repository.getAddonBaseDir(resources), "resources-2.0.0-SNAPSHOT-forge-addon.jar")));
Assert.assertTrue(repository.getAddonResources(resources).contains(
new File(repository.getAddonBaseDir(resources), "resources-api-2.0.0-SNAPSHOT.jar")));
Assert.assertTrue(repository.getAddonResources(resources).contains(
new File(repository.getAddonBaseDir(resources), "resources-impl-2.0.0-SNAPSHOT.jar")));

AddonId facets = AddonId.from("org.jboss.forge:facets", "2.0.0-SNAPSHOT");
Assert.assertTrue(repository.getAddonResources(facets)
.contains(new File(repository.getAddonBaseDir(facets), "facets-2.0.0-SNAPSHOT-forge-addon.jar")));
Assert.assertTrue(repository.getAddonResources(facets)
.contains(new File(repository.getAddonBaseDir(facets), "facets-api-2.0.0-SNAPSHOT.jar")));
Assert.assertTrue(repository.isEnabled(facets));

Set<AddonDependency> dependencies = repository.getAddonDependencies(resources);
Set<AddonDependencyEntry> dependencies = repository.getAddonDependencies(resources);
Assert.assertEquals(3, dependencies.size());
List<String> addonDependenciesIds = new ArrayList<String>();
addonDependenciesIds.add("org.jboss.forge:convert");
addonDependenciesIds.add("org.jboss.forge:facets");
addonDependenciesIds.add("org.jboss.forge:ui-hints");

for (AddonDependency dependency : dependencies)
for (AddonDependencyEntry dependency : dependencies)
{
Assert.assertTrue("Not a valid addon dependency: " + dependency.getId().getName(),
addonDependenciesIds.remove(dependency.getId().getName()));
Assert.assertEquals("2.0.0-SNAPSHOT", dependency.getId().getVersion());
Assert.assertEquals(new SingleVersion("2.0.0-SNAPSHOT"), dependency.getId().getVersion());
}
Assert.assertTrue("Addons not detected as dependency: " + addonDependenciesIds, addonDependenciesIds.isEmpty());

Expand Down
Loading

0 comments on commit c2917b5

Please sign in to comment.