-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JBIDE-16481: Starting F2 twice is now possible
- Loading branch information
Showing
8 changed files
with
144 additions
and
147 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
133 changes: 0 additions & 133 deletions
133
...ns/org.jboss.tools.forge.core.ext/src/org/jboss/tools/forge/ext/core/ForgeCorePlugin.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
130 changes: 130 additions & 0 deletions
130
...ns/org.jboss.tools.forge.core.ext/src/org/jboss/tools/forge/ext/core/FurnaceProvider.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,130 @@ | ||
package org.jboss.tools.forge.ext.core; | ||
|
||
import java.io.Closeable; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.concurrent.Callable; | ||
|
||
import org.eclipse.core.runtime.FileLocator; | ||
import org.eclipse.core.runtime.Platform; | ||
import org.jboss.forge.furnace.Furnace; | ||
import org.jboss.forge.furnace.proxy.ClassLoaderAdapterCallback; | ||
import org.jboss.forge.furnace.repositories.AddonRepositoryMode; | ||
import org.jboss.forge.furnace.util.ClassLoaders; | ||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.wiring.BundleWiring; | ||
|
||
import bootpath.BootpathMarker; | ||
|
||
public class FurnaceProvider { | ||
|
||
public static final FurnaceProvider INSTANCE = new FurnaceProvider(); | ||
|
||
private static final String RUNTIME_PLUGIN_ID = "org.jboss.tools.forge2.runtime"; | ||
|
||
private URLClassLoader loader; | ||
|
||
private FurnaceProvider() {} | ||
|
||
public Furnace createFurnace() throws Exception { | ||
|
||
Furnace forge = ClassLoaders.executeIn(loader, new Callable<Furnace>() { | ||
@Override | ||
public Furnace call() throws Exception { | ||
BundleWiring wiring = ForgeCorePlugin.getDefault().getBundle().adapt( | ||
BundleWiring.class); | ||
Collection<String> entries = wiring.listResources("bootpath", | ||
"*.jar", BundleWiring.LISTRESOURCES_RECURSE); | ||
Collection<URL> resources = new HashSet<URL>(); | ||
File jarDir = File.createTempFile("forge", "jars"); | ||
if (entries != null) | ||
for (String resource : entries) { | ||
URL jar = BootpathMarker.class.getResource("/" | ||
+ resource); | ||
if (jar != null) { | ||
resources.add(copy(jarDir, resource, | ||
jar.openStream())); | ||
} | ||
} | ||
|
||
loader = new URLClassLoader(resources.toArray(new URL[resources | ||
.size()]), null); | ||
|
||
Class<?> bootstrapType = loader | ||
.loadClass("org.jboss.forge.furnace.impl.FurnaceImpl"); | ||
|
||
Object nativeForge = bootstrapType.newInstance(); | ||
Furnace furnace = (Furnace) ClassLoaderAdapterCallback.enhance( | ||
Furnace.class.getClassLoader(), loader, nativeForge, | ||
Furnace.class); | ||
setupRepositories(furnace); | ||
return furnace; | ||
} | ||
}); | ||
return forge; | ||
} | ||
|
||
private void setupRepositories(final Furnace furnace) throws IOException { | ||
Bundle runtimeBundle = Platform.getBundle(RUNTIME_PLUGIN_ID); | ||
File bundleFile = FileLocator.getBundleFile(runtimeBundle); | ||
furnace.addRepository(AddonRepositoryMode.IMMUTABLE, new File( | ||
bundleFile, "addon-repository")); | ||
furnace.addRepository(AddonRepositoryMode.MUTABLE, new File( | ||
ForgeExtPreferences.INSTANCE.getAddonDir())); | ||
} | ||
|
||
public void startFurnace() { | ||
try { | ||
FurnaceService.INSTANCE.setFurnace(createFurnace()); | ||
FurnaceService.INSTANCE.start(loader); | ||
} catch (Exception e) { | ||
ForgeCorePlugin.log(e); | ||
} | ||
} | ||
|
||
private URL copy(File directory, String name, InputStream input) | ||
throws IOException { | ||
File outputFile = new File(directory, name); | ||
|
||
FileOutputStream output = null; | ||
try { | ||
directory.delete(); | ||
outputFile.getParentFile().mkdirs(); | ||
outputFile.createNewFile(); | ||
|
||
output = new FileOutputStream(outputFile); | ||
final byte[] buffer = new byte[4096]; | ||
int read = 0; | ||
while ((read = input.read(buffer)) != -1) { | ||
output.write(buffer, 0, read); | ||
} | ||
output.flush(); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Could not write out jar file " + name, | ||
e); | ||
} finally { | ||
close(input); | ||
close(output); | ||
} | ||
return outputFile.toURI().toURL(); | ||
} | ||
|
||
private void close(Closeable closeable) { | ||
try { | ||
if (closeable != null) { | ||
closeable.close(); | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException("Could not close stream", e); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
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
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
Oops, something went wrong.