X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fcommands%2FRunInOsgi.java;h=238e819d009c3fbceb2f33393d9b7c58abbaa614;hb=18458e0376be8f3c4e38d26c937112bdbda27617;hp=f89a9b0443bd5934fd4aa81e34e4fed55a35a7a0;hpb=996f89dad19dfa994ea33feff06543981b8f0182;p=gpl%2Fargeo-slc.git
diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RunInOsgi.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RunInOsgi.java
index f89a9b044..238e819d0 100644
--- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RunInOsgi.java
+++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RunInOsgi.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * Copyright (C) 2007-2012 Argeo GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,9 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
@@ -41,35 +43,62 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.core.execution.tasks.JvmProcess;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.osgi.framework.Bundle;
-/** UNDER DEVELOPMENT. Download and prepare an OSGi runtime*/
+/** UNDER DEVELOPMENT. Download and prepare an OSGi runtime */
public class RunInOsgi extends AbstractHandler implements SlcNames {
private final static Log log = LogFactory.getLog(RunInOsgi.class);
+ public final static String ID = DistPlugin.ID + ".runInOsgi";
+ public final static String DEFAULT_LABEL = "Run in OSGi";
+ public final static ImageDescriptor DEFAULT_ICON = DistPlugin
+ .getImageDescriptor("icons/runInOsgi.gif");
+
+ public final static String PARAM_WORKSPACE_NAME = "workspaceName";
+
+ /* DEPENDENCY INJECTION */
private Repository repository;
- private String workspace;
public Object execute(ExecutionEvent event) throws ExecutionException {
- File targetDirectory = new File(
- "/home/mbaudier/dev/work/120517-ArgeoTP/" + workspace);
+
+ String workspace = event.getParameter(PARAM_WORKSPACE_NAME);
InputStream jarStream = null;
OutputStream out = null;
Writer writer = null;
Session session = null;
try {
- FileUtils.deleteDirectory(targetDirectory);
+ // Target directory
+ Bundle distPluginBundle = DistPlugin.getDefault().getBundle();
+ File baseDirectory = distPluginBundle.getBundleContext()
+ .getDataFile("runInOSGi");
+ if (baseDirectory.exists())
+ FileUtils.deleteDirectory(baseDirectory);
+ File targetDirectory = new File(baseDirectory, "lib");
targetDirectory.mkdirs();
+ File confDir = new File(baseDirectory, "configuration");
+ confDir.mkdirs();
+ File dataDir = new File(baseDirectory, "data");
+ dataDir.mkdirs();
session = repository.login(workspace);
NodeIterator bundles = listBundleArtifacts(session);
+ if (log.isDebugEnabled())
+ log.debug("## Copying to " + targetDirectory);
+
+ File equinoxJar = null;
List files = new ArrayList();
bundles: while (bundles.hasNext()) {
Node bundleNode = bundles.nextNode();
@@ -92,7 +121,9 @@ public class RunInOsgi extends AbstractHandler implements SlcNames {
jarStream = bundleNode.getNode(Node.JCR_CONTENT)
.getProperty(Property.JCR_DATA).getBinary().getStream();
IOUtils.copy(jarStream, out);
- if (!symbolicName.equals("org.eclipse.osgi"))
+ if (symbolicName.equals("org.eclipse.osgi"))
+ equinoxJar = targetFile;
+ else
files.add(targetFile);
if (log.isDebugEnabled())
log.debug("Copied " + targetFile.getName());
@@ -108,15 +139,60 @@ public class RunInOsgi extends AbstractHandler implements SlcNames {
osgiBundles.append(files.get(i).getName());
}
- File confDir = new File(targetDirectory, "configuration");
- confDir.mkdirs();
File confIni = new File(confDir, "config.ini");
writer = new FileWriter(confIni);
writer.write(osgiBundles.toString());
IOUtils.closeQuietly(writer);
+
+ Map configuration = new HashMap();
+ configuration.put("osgi.configuration.area",
+ confDir.getCanonicalPath());
+ configuration.put("osgi.instance.area", dataDir.getCanonicalPath());
+ // Do clean
+ configuration.put("osgi.clean", "true");
+
+ JvmProcess osgiRuntime = new JvmProcess();
+ osgiRuntime.setExecDir(baseDirectory.getCanonicalPath());
+ if (equinoxJar == null)
+ throw new SlcException("Cannot find OSGi runtime.");
+ osgiRuntime.setMainJar(equinoxJar.getCanonicalPath());
+ osgiRuntime.arg("-configuration", confDir.getCanonicalPath())
+ .arg("-data", dataDir.getCanonicalPath())
+ .arg("-console", "7777").arg("-clean");
+ osgiRuntime.setLogCommand(true);
+ osgiRuntime.afterPropertiesSet();
+ osgiRuntime.run();
+
+ // Map configuration = new HashMap();
+ // configuration.put("osgi.configuration.area",
+ // confDir.getCanonicalPath());
+ // configuration.put("osgi.instance.area",
+ // dataDir.getCanonicalPath());
+ // // Do clean
+ // configuration.put("osgi.clean", "true");
+ // ServiceLoader ff = ServiceLoader
+ // .load(FrameworkFactory.class);
+ // FrameworkFactory frameworkFactory = ff.iterator().next();
+ // Framework framework =
+ // frameworkFactory.newFramework(configuration);
+ // framework.start();
+ // BundleContext testBundleContext = framework.getBundleContext();
+
+ // for (int i = 0; i < files.size(); i++) {
+ // testBundleContext.installBundle("file://"
+ // + files.get(i).getCanonicalPath());
+ // }
+ //
+ // Bundle[] testBundles = testBundleContext.getBundles();
+ // for (Bundle bundle : testBundles) {
+ // if (log.isDebugEnabled())
+ // log.debug(bundle.getSymbolicName() + " "
+ // + bundle.getVersion());
+ // }
+
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ ErrorFeedback.show("Cannot run in OSGi", e);
} finally {
IOUtils.closeQuietly(jarStream);
IOUtils.closeQuietly(out);
@@ -150,9 +226,4 @@ public class RunInOsgi extends AbstractHandler implements SlcNames {
public void setRepository(Repository repository) {
this.repository = repository;
}
-
- public void setWorkspace(String workspace) {
- this.workspace = workspace;
- }
-
}