Skip to content

Commit

Permalink
Distributing furnace exploded in Netbeans to avoid initial IO
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Mar 16, 2015
1 parent 7ab1880 commit 3c56908
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 30 deletions.
35 changes: 35 additions & 0 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,33 @@ Contributors:
<packaging>nbm</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-furnace</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>furnace-se</artifactId>
<version>${furnace.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>bootpath/*.jar</includes>
<excludes>**/*.class</excludes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>furnace-maven-plugin</artifactId>
Expand All @@ -36,6 +63,7 @@ Contributors:
<addonRepository>${project.build.directory}/addon-repository</addonRepository>
<addonIds>
<addonId>org.jboss.forge.addon:core,${forge.version}</addonId>
<addonId>org.jboss.forge.addon:ui-example,${forge.version}</addonId>
<addonId>org.jboss.forge.addon:angularjs,${angularjs.addon.version}</addonId>
</addonIds>
</configuration>
Expand All @@ -58,6 +86,7 @@ Contributors:
<publicPackage>org.jboss.forge.furnace.proxy</publicPackage>
<publicPackage>org.jboss.forge.furnace.services</publicPackage>
<publicPackage>org.jboss.forge.furnace.spi</publicPackage>
<publicPackage>org.jboss.forge.furnace.util</publicPackage>
<publicPackage>org.jboss.forge.addon.convert</publicPackage>
<publicPackage>org.jboss.forge.addon.projects</publicPackage>
<publicPackage>org.jboss.forge.addon.projects.facets</publicPackage>
Expand All @@ -81,6 +110,12 @@ Contributors:
<!-- This is the path relative to the installed module -->
<targetPath>addon-repository</targetPath>
</nbmResource>
<nbmResource>
<!-- This is the sourcedir -->
<directory>${project.build.directory}/bootpath</directory>
<!-- This is the path relative to the installed module -->
<targetPath>bootpath</targetPath>
</nbmResource>
</nbmResources>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.jboss.forge.addon.convert.ConverterFactory;
import org.jboss.forge.addon.resource.ResourceFactory;
import org.jboss.forge.addon.ui.command.CommandFactory;
Expand Down Expand Up @@ -103,21 +98,12 @@ private void createFurnace() {
try {
// MODULES-136
System.setProperty("modules.ignore.jdk.factory", "true");
URL codeSourceLocation = bootpath.BootpathMarker.class.getProtectionDomain().getCodeSource().getLocation();
URL location = new URL(codeSourceLocation.toString().replace("jar:", "").replace("!/", ""));
List<URL> urls = new ArrayList<>();
try (ZipInputStream zis = new ZipInputStream(location.openStream())) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.getName().contains(".jar")) {
urls.add(bootpath.BootpathMarker.class.getResource(entry.getName().replace("bootpath/", "")));
}
}
}
urls = flushURLs(urls);
final URLClassLoader furnaceClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
furnace = FurnaceFactory.getInstance(getClass().getClassLoader(), furnaceClassLoader);
String cnb = Modules.getDefault().ownerOf(getClass()).getCodeNameBase();
File bootpath = InstalledFileLocator.getDefault().locate("bootpath", cnb, false);
URL[] urls = toURLs(bootpath.listFiles());
final URLClassLoader furnaceClassLoader = new URLClassLoader(urls);
furnace = FurnaceFactory.getInstance(getClass().getClassLoader(), furnaceClassLoader);

File locate = InstalledFileLocator.getDefault().locate("addon-repository", cnb, false);
if (locate != null) {
furnace.addRepository(AddonRepositoryMode.IMMUTABLE, locate);
Expand Down Expand Up @@ -171,17 +157,13 @@ public void afterStop(Furnace furnace) throws ContainerException {
Exceptions.printStackTrace(ex);
}
}

private List<URL> flushURLs(List<URL> urls) throws IOException {
List<URL> result = new ArrayList<>();
File tmpDir = OperatingSystemUtils.createTempDir();
for (URL url : urls) {
String path = url.getPath();
path = path.substring(path.lastIndexOf("/") + 1);
File newFile = new File(tmpDir, path);
Files.copy(url.openStream(), newFile.toPath());
result.add(Utilities.toURI(newFile).toURL());

private URL[] toURLs(File[] files) throws IOException {
int length = files.length;
URL[] urls = new URL[length];
for (int i = 0; i < length; i++) {
urls[i] = Utilities.toURI(files[i]).toURL();
}
return result;
return urls;
}
}

0 comments on commit 3c56908

Please sign in to comment.