Improve distribution
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 17 May 2012 14:53:02 +0000 (14:53 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 17 May 2012 14:53:02 +0000 (14:53 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5301 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

demo/slc_demo_rcp.properties
eclipse/plugins/org.argeo.slc.client.ui.dist/META-INF/MANIFEST.MF
eclipse/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml
eclipse/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/views.xml
eclipse/plugins/org.argeo.slc.client.ui.dist/plugin.xml
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/DistributionPerspective.java
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RunInOsgi.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java [new file with mode: 0644]

index 7ead159f6ca64c4c6b3b419ef0038e9fa11cfd7b..421fc6bba84c5d7a0b8815dd75c879359120fdab 100644 (file)
@@ -17,7 +17,8 @@ org.argeo.slc.demo.minimal,\
 spring.security.strategy=MODE_INHERITABLETHREADLOCAL
 
 eclipse.application=org.argeo.slc.client.rcp.application
-org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.slcExecutionPerspective
+#org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.slcExecutionPerspective
+org.argeo.security.ui.initialPerspective=org.argeo.slc.client.ui.dist.distributionPerspective
 
 log4j.configuration=file:../../log4j.properties
 
index 77993aa7022cd10fe4244965f543dae23dfe7892..dfe845a583d7c1867f398f85dbb8f71774a207ed 100644 (file)
@@ -14,6 +14,8 @@ Import-Package: aQute.lib.osgi;resolution:=optional,
  javax.jcr;version="[2.0.0,3.0.0)",
  javax.jcr.nodetype;version="2.0.0",
  javax.jcr.query,
+ javax.jcr.query.qom;version="2.0.0",
+ org.apache.commons.io;version="1.4.0",
  org.apache.commons.logging;version="1.1.1",
  org.argeo,
  org.argeo.eclipse.spring,
index aa006e8104ba13141d75bf69ecad62f43d0d678d..49d5e7d5e1a65585e9663223c0e63f91b9b0ff97 100644 (file)
                <property name="editorId"
                        value="org.argeo.slc.client.ui.dist.genericJcrQueryEditor" />
        </bean>
+
+       <bean id="runInOSGi" class="org.argeo.slc.client.ui.dist.commands.RunInOsgi"
+               scope="prototype">
+               <property name="repository" ref="javaRepository" />
+               <property name="workspace" value="argeo-tp-1-staging" />
+       </bean>
 </beans>
index 5b93dc562202eedc68438feff0a5697f55c9d0a0..60f75faf60f10c9a34c8ec1c5d94977a96326644 100644 (file)
                scope="prototype">
                <property name="session" ref="slcSession" />
        </bean>
+
+       <bean id="distributionsView" class="org.argeo.slc.client.ui.dist.views.DistributionsView"
+               scope="prototype">
+               <property name="repository" ref="javaRepository" />
+               <property name="workspace" value="argeo-tp-1-staging" />
+       </bean>
 </beans>
index cea5a492e3af3048ff53be4cf054b3cdd0736be0..617b746cef2615eb6f80edf4838dd70d7aa0cc0d 100644 (file)
             icon="icons/search.gif"
             name="Query builder">
       </view>
+      <view
+            class="org.argeo.eclipse.spring.SpringExtensionFactory"
+            id="org.argeo.slc.client.ui.dist.distributionsView"
+            icon="icons/search.gif"
+            name="Distributions">
+      </view>
    </extension>
    <!-- Editors -->
    <extension
             defaultHandler="org.argeo.slc.client.ui.dist.commands.RefreshArtifactBrowser"
             id="org.argeo.slc.client.ui.dist.refreshArtifactBrowser"
             name="Refresh Artifact Browser">
+       </command>
+               <command
+            id="org.argeo.slc.client.ui.dist.runInOSGi"
+            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+            name="Run in OSGi">
        </command>
     </extension>
        <extension
                 tooltip="Refresh the whole browser">
             </command>
         </menuContribution>
+               <menuContribution
+               locationURI="toolbar:org.argeo.slc.client.ui.dist.distributionsView">
+            <command
+               commandId="org.argeo.slc.client.ui.dist.runInOSGi"
+                icon="icons/showSize.gif"
+                label="Run in OSGi"
+                tooltip="Run in a spearate OSGi runtime">
+            </command>
+        </menuContribution>
        
         <!-- Queries --> 
                <!-- <menuContribution
index 65573e8e8edacbfd76783c5eb123fb9f24559698..65021dc78af996f9cd8d54f412e65b725d2aacac 100644 (file)
@@ -16,6 +16,7 @@
 package org.argeo.slc.client.ui.dist;
 
 import org.argeo.slc.client.ui.dist.views.ArtifactsBrowser;
+import org.argeo.slc.client.ui.dist.views.DistributionsView;
 import org.argeo.slc.client.ui.dist.views.QueryArtifactsForm;
 import org.argeo.slc.client.ui.dist.views.QueryArtifactsText;
 import org.argeo.slc.client.ui.dist.views.QueryBundlesForm;
@@ -34,6 +35,7 @@ public class DistributionPerspective implements IPerspectiveFactory {
 
                IFolderLayout main = layout.createFolder("main", IPageLayout.LEFT,
                                0.5f, editorArea);
+               main.addView(DistributionsView.ID);
                main.addView(ArtifactsBrowser.ID);
                main.addView(QueryArtifactsForm.ID);
                main.addView(QueryBundlesForm.ID);
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RunInOsgi.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/RunInOsgi.java
new file mode 100644 (file)
index 0000000..2929947
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.client.ui.dist.commands;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.qom.Ordering;
+import javax.jcr.query.qom.QueryObjectModel;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.Selector;
+
+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.jcr.JcrUtils;
+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;
+
+public class RunInOsgi extends AbstractHandler implements SlcNames {
+       private final static Log log = LogFactory.getLog(RunInOsgi.class);
+
+       private Repository repository;
+       private String workspace;
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               File targetDirectory = new File(
+                               "/home/mbaudier/dev/work/120517-ArgeoTP/lib");
+
+               InputStream jarStream = null;
+               OutputStream out = null;
+               Writer writer = null;
+               try {
+                       FileUtils.deleteDirectory(targetDirectory);
+                       targetDirectory.mkdirs();
+
+                       Session session = repository.login(workspace);
+                       NodeIterator bundles = listBundleArtifacts(session);
+
+                       List<File> files = new ArrayList<File>();
+                       bundles: while (bundles.hasNext()) {
+                               Node bundleNode = bundles.nextNode();
+                               String symbolicName = JcrUtils.get(bundleNode,
+                                               SLC_SYMBOLIC_NAME);
+
+                               // skip sources
+                               if (symbolicName.endsWith(".source"))
+                                       continue bundles;
+                               // skip eclipse
+                               if (symbolicName.startsWith("org.eclipse")
+                                               && !symbolicName.equals("org.eclipse.osgi"))
+                                       continue bundles;
+
+                               File targetFile = new File(targetDirectory,
+                                               bundleNode.getName());
+                               out = new FileOutputStream(targetFile);
+                               jarStream = bundleNode.getNode(Node.JCR_CONTENT)
+                                               .getProperty(Property.JCR_DATA).getBinary().getStream();
+                               IOUtils.copy(jarStream, out);
+                               if (!symbolicName.equals("org.eclipse.osgi"))
+                                       files.add(targetFile);
+                               if (log.isDebugEnabled())
+                                       log.debug("Copied " + targetFile.getName());
+
+                               IOUtils.closeQuietly(out);
+                               IOUtils.closeQuietly(jarStream);
+                       }
+
+                       StringBuffer osgiBundles = new StringBuffer("osgi.bundles=");
+                       for (int i = 0; i < files.size(); i++) {
+                               if (i != 0)
+                                       osgiBundles.append(',');
+                               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);
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               } finally {
+                       IOUtils.closeQuietly(jarStream);
+                       IOUtils.closeQuietly(out);
+                       IOUtils.closeQuietly(writer);
+               }
+
+               return null;
+       }
+
+       static NodeIterator listBundleArtifacts(Session session)
+                       throws RepositoryException {
+               QueryManager queryManager = session.getWorkspace().getQueryManager();
+               QueryObjectModelFactory factory = queryManager.getQOMFactory();
+
+               final String bundleArtifactsSelector = "bundleArtifacts";
+               Selector source = factory.selector(SlcTypes.SLC_BUNDLE_ARTIFACT,
+                               bundleArtifactsSelector);
+
+               Ordering order = factory.ascending(factory.propertyValue(
+                               bundleArtifactsSelector, SlcNames.SLC_SYMBOLIC_NAME));
+               Ordering[] orderings = { order };
+
+               QueryObjectModel query = factory.createQuery(source, null, orderings,
+                               null);
+
+               QueryResult result = query.execute();
+               return result.getNodes();
+       }
+
+       public void setRepository(Repository repository) {
+               this.repository = repository;
+       }
+
+       public void setWorkspace(String workspace) {
+               this.workspace = workspace;
+       }
+
+}
diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java
new file mode 100644 (file)
index 0000000..ec635c4
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.client.ui.dist.views;
+
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.qom.Ordering;
+import javax.jcr.query.qom.QueryObjectModel;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.Selector;
+
+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.client.ui.dist.DistPlugin;
+import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * Basic View to browse a maven based repository.
+ * 
+ * By Default size of the various bundles is not computed but it can be
+ * activated the view command.
+ */
+
+public class DistributionsView extends ViewPart implements SlcNames {
+       private final static Log log = LogFactory.getLog(DistributionsView.class);
+       public final static String ID = DistPlugin.ID + ".distributionsView";
+
+       private Repository repository;
+       private String workspace;
+
+       private Session session;
+       private TableViewer viewer;
+
+       @Override
+       public void createPartControl(Composite parent) {
+               try {
+                       session = repository.login(workspace);
+               } catch (RepositoryException e) {
+                       ErrorFeedback.show("Cannot log to workspace " + workspace, e);
+               }
+
+               // Define the TableViewer
+               viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
+                               | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+
+               TableViewerColumn col = new TableViewerColumn(viewer, SWT.NONE);
+               col.getColumn().setWidth(200);
+               col.getColumn().setText("Workspace");
+               col.setLabelProvider(new ColumnLabelProvider() {
+                       @Override
+                       public String getText(Object element) {
+                               return JcrUtils.get((Node) element, SLC_SYMBOLIC_NAME);
+                       }
+               });
+
+               final Table table = viewer.getTable();
+               table.setHeaderVisible(true);
+               table.setLinesVisible(true);
+
+               viewer.setContentProvider(new DistributionsContentProvider());
+               viewer.setInput(session);
+       }
+
+       @Override
+       public void setFocus() {
+               viewer.getTable().setFocus();
+       }
+
+       public void setRepository(Repository repository) {
+               this.repository = repository;
+       }
+
+       public void setWorkspace(String workspace) {
+               this.workspace = workspace;
+       }
+
+       private static class DistributionsContentProvider implements
+                       IStructuredContentProvider {
+               private Session session;
+
+               public void dispose() {
+               }
+
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+                       session = (Session) newInput;
+               }
+
+               public Object[] getElements(Object arg0) {
+                       try {
+                               List<Node> nodes = JcrUtils
+                                               .nodeIteratorToList(listBundleArtifacts(session));
+                               return nodes.toArray();
+                       } catch (RepositoryException e) {
+                               ErrorFeedback.show("Cannot list bundles", e);
+                               return null;
+                       }
+               }
+
+       }
+
+       static NodeIterator listBundleArtifacts(Session session)
+                       throws RepositoryException {
+               QueryManager queryManager = session.getWorkspace().getQueryManager();
+               QueryObjectModelFactory factory = queryManager.getQOMFactory();
+
+               final String bundleArtifactsSelector = "bundleArtifacts";
+               Selector source = factory.selector(SlcTypes.SLC_BUNDLE_ARTIFACT,
+                               bundleArtifactsSelector);
+
+               Ordering order = factory.ascending(factory.propertyValue(
+                               bundleArtifactsSelector, SlcNames.SLC_SYMBOLIC_NAME));
+               Ordering[] orderings = { order };
+
+               QueryObjectModel query = factory.createQuery(source, null, orderings,
+                               null);
+
+               QueryResult result = query.execute();
+               return result.getNodes();
+       }
+
+}