Skip to content

Commit

Permalink
Fix FORGE-940
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jun 19, 2013
1 parent abba823 commit cbca116
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 76 deletions.
Expand Up @@ -56,7 +56,7 @@ public static ForgeArchive getDeployment()
}

@Inject
private AddonProjectConfigurator addonProjectFactory;
private AddonProjectConfigurator configurator;

@Inject
private ProjectFactory projectFactory;
Expand All @@ -65,13 +65,15 @@ public static ForgeArchive getDeployment()
public void testCreateAddonProject()
{
Project project = projectFactory.createTempProject();
project.getProjectRoot().deleteOnExit();

MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
metadataFacet.setProjectName("testproject");
metadataFacet.setProjectVersion("1.0.0-SNAPSHOT");
metadataFacet.setTopLevelPackage("com.acme.testproject");

SingleVersion forgeVersion = new SingleVersion("2.0.0-SNAPSHOT");
addonProjectFactory.setupAddonProject(project, forgeVersion, Collections.<AddonId> emptyList());
configurator.setupAddonProject(project, forgeVersion, Collections.<AddonId> emptyList());

DirectoryResource projectRoot = project.getProjectRoot();

Expand Down Expand Up @@ -240,13 +242,15 @@ public void testCreateAddonProject()
public void testSimpleAddonProject()
{
Project project = projectFactory.createTempProject();
project.getProjectRoot().deleteOnExit();

MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
metadataFacet.setProjectName("testproject");
metadataFacet.setProjectVersion("1.0.0-SNAPSHOT");
metadataFacet.setTopLevelPackage("com.acme.testproject");

SingleVersion forgeVersion = new SingleVersion("2.0.0-SNAPSHOT");
addonProjectFactory.setupSimpleAddonProject(project, forgeVersion, Collections.<AddonId> emptyList());
configurator.setupSimpleAddonProject(project, forgeVersion, Collections.<AddonId> emptyList());

Assert.assertTrue(project.hasFacet(CDIFacet.class));
Assert.assertTrue(project.hasFacet(JavaSourceFacet.class));
Expand All @@ -265,13 +269,15 @@ public void testSimpleAddonProject()
public void testDependencyResolution()
{
Project project = projectFactory.createTempProject();
project.getProjectRoot().deleteOnExit();

MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
metadataFacet.setProjectName("testproject");
metadataFacet.setProjectVersion("1.0.0-SNAPSHOT");
metadataFacet.setTopLevelPackage("com.acme.testproject");

SingleVersion forgeVersion = new SingleVersion("2.0.0.Alpha3");
addonProjectFactory.setupAddonProject(project, forgeVersion, Collections.<AddonId> emptyList());
configurator.setupAddonProject(project, forgeVersion, Collections.<AddonId> emptyList());

DirectoryResource projectRoot = project.getProjectRoot();

Expand Down
Expand Up @@ -29,6 +29,7 @@ public class ForgeSetArgsTest
public void init() throws IOException
{
repodir1 = File.createTempFile("forge", "repo1");
repodir1.deleteOnExit();
}

@After
Expand Down
Expand Up @@ -41,7 +41,9 @@ public class MultipleRepositoryTest
public void init() throws IOException
{
repodir1 = File.createTempFile("forge", "repo1");
repodir1.deleteOnExit();
repodir2 = File.createTempFile("forge", "repo2");
repodir2.deleteOnExit();
}

@After
Expand All @@ -54,12 +56,12 @@ public void teardown()
@Test
public void testAddonsCanReferenceDependenciesInOtherRepositories() throws IOException
{
Furnace forge = ForgeFactory.getInstance(Furnace.class.getClassLoader());
AddonRepository left = forge.addRepository(AddonRepositoryMode.MUTABLE, repodir1);
AddonRepository right = forge.addRepository(AddonRepositoryMode.MUTABLE, repodir2);
forge.startAsync();
Furnace furnace = ForgeFactory.getInstance(Furnace.class.getClassLoader());
AddonRepository left = furnace.addRepository(AddonRepositoryMode.MUTABLE, repodir1);
AddonRepository right = furnace.addRepository(AddonRepositoryMode.MUTABLE, repodir2);
furnace.startAsync();

AddonManager manager = new AddonManagerImpl(forge, new MavenDependencyResolver(new FileResourceFactory(),
AddonManager manager = new AddonManagerImpl(furnace, new MavenDependencyResolver(new FileResourceFactory(),
new MavenContainer()));

AddonId facets = AddonId.from("org.jboss.forge.addon:facets", "2.0.0-SNAPSHOT");
Expand All @@ -84,9 +86,9 @@ public void testAddonsCanReferenceDependenciesInOtherRepositories() throws IOExc
Assert.assertTrue(left.isDeployed(convert));
Assert.assertTrue(right.isDeployed(resources));

Addons.waitUntilStarted(forge.getAddonRegistry().getAddon(resources), 10, TimeUnit.SECONDS);
Addons.waitUntilStarted(furnace.getAddonRegistry().getAddon(resources), 10, TimeUnit.SECONDS);

forge.stop();
furnace.stop();
}

@Test
Expand Down
Expand Up @@ -8,11 +8,9 @@

import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jboss.forge.furnace.addons.AddonDependency;
import org.jboss.forge.furnace.impl.AddonImpl;
import org.jboss.forge.furnace.impl.AddonRunnable;

Expand All @@ -39,6 +37,7 @@ public Void call() throws Exception
{
if (addon != null)
{
Set<AddonDependency> dependencies = addon.getDependencies();
AddonRunnable runnable = ((AddonImpl) addon).getRunnable();
try
{
Expand All @@ -53,12 +52,6 @@ public Void call() throws Exception
}
finally
{
Future<Void> future = addon.getFuture();
if (future != null && !future.isDone())
future.cancel(true);

Set<AddonDependency> dependencies = addon.getDependencies();
((AddonImpl) addon).reset();
addon.setDirty(false);

for (AddonDependency dependency : dependencies)
Expand Down
Expand Up @@ -69,6 +69,15 @@ public boolean canBeStarted()
return getRunnable() == null && getStatus().isLoaded();
}

public boolean cancelFuture()
{
boolean result = false;
Future<Void> future = getFuture();
if (future != null && !future.isDone())
result = future.cancel(true);
return result;
}

public void reset()
{
if (getModuleLoader() != null)
Expand Down Expand Up @@ -156,9 +165,9 @@ public Addon setServiceRegistry(ServiceRegistry registry)

public void setDirty(boolean dirty)
{
this.state.dirty = dirty;
this.state.dirty = dirty;
}

public boolean isDirty()
{
return this.state.dirty;
Expand Down
Expand Up @@ -7,7 +7,6 @@
package org.jboss.forge.furnace.impl;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -132,7 +131,6 @@ public AddonImpl getAddon()

public class AddonContainerStartup implements Callable<Callable<Object>>
{
private Future<Object> operation;
private Callable<Void> postStartupTask;

@Override
Expand All @@ -159,7 +157,8 @@ public Callable<Object> call() throws Exception
@Override
public Object call() throws Exception
{
addon.setStatus(AddonStatus.LOADED);
addon.cancelFuture();
addon.reset();
return null;
}
};
Expand Down Expand Up @@ -215,9 +214,8 @@ public Object call() throws Exception
}
finally
{
addon.setStatus(AddonStatus.LOADED);
if (operation != null)
operation.cancel(true);
addon.cancelFuture();
addon.reset();
}

weld.shutdown();
Expand Down
Expand Up @@ -37,6 +37,7 @@ public void closeJarFileReferences(ModuleIdentifier id)
{
try
{
System.out.println("Closing JarFile [" + file.getName() + "]");
file.close();
}
catch (IOException e)
Expand All @@ -52,6 +53,7 @@ public void addJarFileReference(ModuleIdentifier id, JarFile file)
Assert.notNull(id, "Module reference must not be null.");
Assert.notNull(file, "JarFile reference must not be null.");

System.out.println("Adding JarFile [" + file.getName() + "] for module [" + id + "] ");
Set<JarFile> files = map.get(id);
if (files == null)
{
Expand Down

0 comments on commit cbca116

Please sign in to comment.