From 5f40d8d483bdd509881bf09fa9eedf259146be65 Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Wed, 19 Mar 2014 21:10:07 +0000 Subject: [PATCH] Work on index policies. git-svn-id: https://svn.argeo.org/slc/trunk@6899 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/spring/services.xml | 3 +- .../META-INF/spring/commands.xml | 19 +- .../META-INF/spring/jcr.xml | 11 +- .../META-INF/spring/osgi.xml | 2 + .../org.argeo.slc.client.ui.dist/plugin.xml | 83 ++- .../dist/commands/CopyLocalJavaWorkspace.java | 180 ++++++ .../ui/dist/commands/CopyWorkspace.java | 49 +- .../commands/CreateLocalJavaWorkspace.java | 99 ++++ .../ui/dist/commands/CreateWorkspace.java | 4 +- .../dist/commands/MarkAsRelevantCategory.java | 6 +- .../ui/dist/commands/NormalizeWorkspace.java | 17 +- .../commands/OpenGenerateBinariesWizard.java | 23 +- .../ModularDistVersionOverviewPage.java | 35 +- .../editors/WkspCategoryBaseListPage.java | 6 +- .../ui/dist/model/ModularDistBaseElem.java | 18 +- .../client/ui/dist/model/WorkspaceElem.java | 2 +- .../ui/dist/views/DistributionsView.java | 114 +--- .../dist/wizards/GenerateBinariesWizard.java | 137 +++-- .../org/argeo/slc/repo/JarFileIndexer.java | 7 +- ...r.java => ModularDistributionIndexer.java} | 141 ++--- .../org/argeo/slc/repo/PdeSourcesIndexer.java | 38 +- .../slc/repo/maven/GenerateBinaries.java | 533 +++++++++--------- .../argeo/slc/repo/osgi/NormalizeGroup.java | 5 + .../argeo/slc/repo/osgi/OsgiFactoryImpl.java | 4 +- .../resources/org/argeo/slc/repo/repo.cnd | 4 +- .../main/java/org/argeo/slc/jcr/SlcNames.java | 2 +- .../main/java/org/argeo/slc/jcr/SlcTypes.java | 7 +- .../main/resources/org/argeo/slc/jcr/slc.cnd | 5 + 28 files changed, 927 insertions(+), 627 deletions(-) create mode 100644 plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CopyLocalJavaWorkspace.java create mode 100644 plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateLocalJavaWorkspace.java rename runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/{DistributionBundleIndexer.java => ModularDistributionIndexer.java} (72%) diff --git a/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml b/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml index 93fb545b1..a4b2c26e0 100644 --- a/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml +++ b/modules/org.argeo.slc.server.repo/META-INF/spring/services.xml @@ -27,7 +27,8 @@ - + + diff --git a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml index 5c59eae27..d5e75b8a9 100644 --- a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml +++ b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml @@ -42,7 +42,8 @@ - @@ -86,6 +87,22 @@ + + + + + + + + + + + + + + diff --git a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml index 3ddc3521f..1d2cd11c4 100644 --- a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml +++ b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml @@ -10,13 +10,6 @@ - - - - - - - - - + diff --git a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/osgi.xml b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/osgi.xml index 62036aac8..e8bc02d24 100644 --- a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/osgi.xml +++ b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/osgi.xml @@ -16,4 +16,6 @@ + + \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/plugin.xml b/plugins/org.argeo.slc.client.ui.dist/plugin.xml index 58623ebf5..530833b99 100644 --- a/plugins/org.argeo.slc.client.ui.dist/plugin.xml +++ b/plugins/org.argeo.slc.client.ui.dist/plugin.xml @@ -242,7 +242,30 @@ + + + + + + + + + + + + - - - - - - - - @@ -283,30 +292,42 @@ name="Target repo node path"> - + + name="Create Local Java Workspace"> - - - - + id="workspacePrefix" + name="Workspace prefix"> + + + id="srcWkspName" + name="Source Workspace Name"> + + + + + + + + - + 60) { + ErrorFeedback.show("Workspace name '" + enteredName + + "' is too long or contains" + + " too many special characters such as '.' or '-'."); + return null; + } + + String workspaceName = enteredName; + // Canceled by user + if (result == Dialog.CANCEL || workspaceName == null + || "".equals(workspaceName.trim())) + return null; + + // FIXME will throw an exception if this workspace name is already used. + javaRepoManager.createWorkspace(workspaceName); + + CommandHelpers.callCommand(RefreshDistributionsView.ID); + if (log.isTraceEnabled()) + log.trace("WORKSPACE " + workspaceName + " CREATED"); + + return null; + } + + /* DEPENDENCY INJECTION */ + public void setJavaRepoManager(JavaRepoManager javaRepoManager) { + this.javaRepoManager = javaRepoManager; + } +} \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java index 681e0fed7..95dee2b6e 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java @@ -41,7 +41,7 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.handlers.HandlerUtil; /** - * Create a new empty workspace in the current repository. + * Create a new empty workspace in a remote repository. */ public class CreateWorkspace extends AbstractHandler { private static final Log log = LogFactory.getLog(CreateWorkspace.class); @@ -81,7 +81,7 @@ public class CreateWorkspace extends AbstractHandler { .getActiveWorkbenchWindow(event).getShell(), "Workspace name?", "Choose a name for the workspace to create", - prefix == null ? "" : prefix + "_", null); + prefix == null ? "" : prefix + "-", null); int result = inputDialog.open(); String enteredName = inputDialog.getValue(); diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/MarkAsRelevantCategory.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/MarkAsRelevantCategory.java index ae617087f..f4f8bcbc3 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/MarkAsRelevantCategory.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/MarkAsRelevantCategory.java @@ -61,13 +61,13 @@ public class MarkAsRelevantCategory extends AbstractHandler { .iterator(); Node node = (Node) it.next(); - if (node.isNodeType(SlcTypes.SLC_RELEVANT_CATEGORY)) { + if (node.isNodeType(SlcTypes.SLC_CATEGORY)) { String msg = "Your are about to unlist this category from the relevant category list for current workspace" + ".\n" + "Are you sure you want to proceed?"; if (MessageDialog.openConfirm(DistPlugin.getDefault() .getWorkbench().getDisplay().getActiveShell(), "Confirm", msg)) { - node.removeMixin(SlcTypes.SLC_RELEVANT_CATEGORY); + node.removeMixin(SlcTypes.SLC_CATEGORY); node.getSession().save(); } } else { @@ -77,7 +77,7 @@ public class MarkAsRelevantCategory extends AbstractHandler { if (MessageDialog.openConfirm(DistPlugin.getDefault() .getWorkbench().getDisplay().getActiveShell(), "Confirm", msg)) { - node.addMixin(SlcTypes.SLC_RELEVANT_CATEGORY); + node.addMixin(SlcTypes.SLC_CATEGORY); node.getSession().save(); } } diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/NormalizeWorkspace.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/NormalizeWorkspace.java index d70d904f9..7f3f3b5a3 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/NormalizeWorkspace.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/NormalizeWorkspace.java @@ -36,7 +36,7 @@ import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.repo.ArtifactIndexer; -import org.argeo.slc.repo.DistributionBundleIndexer; +import org.argeo.slc.repo.ModularDistributionIndexer; import org.argeo.slc.repo.JarFileIndexer; import org.argeo.slc.repo.PdeSourcesIndexer; import org.argeo.slc.repo.RepoConstants; @@ -74,12 +74,11 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames { private Keyring keyring; private Repository repository; - // RElevant default node indexers + // Relevant default node indexers private ArtifactIndexer artifactIndexer = new ArtifactIndexer(); private JarFileIndexer jarFileIndexer = new JarFileIndexer(); - private DistributionBundleIndexer distBundleIndexer = new DistributionBundleIndexer(); - private PdeSourcesIndexer pdeSourceIndexer = new PdeSourcesIndexer( - artifactIndexer, jarFileIndexer); + private ModularDistributionIndexer distBundleIndexer = new ModularDistributionIndexer(); + private PdeSourcesIndexer pdeSourceIndexer = new PdeSourcesIndexer(); public Object execute(ExecutionEvent event) throws ExecutionException { String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH); @@ -201,11 +200,15 @@ public class NormalizeWorkspace extends AbstractHandler implements SlcNames { monitor.worked(1); } } else if (node.getName().endsWith(".pom")) { - distBundleIndexer.index(node); + if (distBundleIndexer.support(node.getPath())) + distBundleIndexer.index(node); + if (artifactIndexer.support(node.getPath())) + artifactIndexer.index(node); if (node.getSession().hasPendingChanges()) { node.getSession().save(); if (log.isDebugEnabled()) - log.debug("Processed pom artifact " + node.getPath()); + log.debug("Processed pom artifact " + + node.getPath()); } monitor.worked(1); } else { diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java index 288475f23..1c2ad68c3 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java @@ -17,9 +17,10 @@ package org.argeo.slc.client.ui.dist.commands; import java.util.Iterator; +import javax.jcr.Credentials; import javax.jcr.Node; +import javax.jcr.Repository; import javax.jcr.RepositoryException; -import javax.jcr.Session; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; @@ -62,14 +63,22 @@ public class OpenGenerateBinariesWizard extends AbstractHandler { Object element = it.next(); if (element instanceof ModularDistBaseElem) { ModularDistBaseElem elem = (ModularDistBaseElem) element; - Session newSession = null; + // Session newSession = null; try { Node cBase = elem.getCategoryBase(); - String path = cBase.getPath(); - newSession = ((WorkspaceElem) elem.getParent()) - .getNewSession(); + String catBasePath = cBase.getPath(); + // newSession = ((WorkspaceElem) elem.getParent()) + // .getNewSession(); + + String wkspName = ((WorkspaceElem) elem.getParent()) + .getWorkspaceName(); + Repository repository = ((WorkspaceElem) elem + .getParent()).getRepoElem().getRepository(); + Credentials credentials = ((WorkspaceElem) elem + .getParent()).getRepoElem().getCredentials(); + GenerateBinariesWizard wizard = new GenerateBinariesWizard( - newSession.getNode(path)); + repository, credentials, wkspName, catBasePath); WizardDialog dialog = new WizardDialog( HandlerUtil.getActiveShell(event), wizard); @@ -82,6 +91,8 @@ public class OpenGenerateBinariesWizard extends AbstractHandler { throw new SlcException( "Unable to duplicate session for node " + elem, re); + // } finally { + // JcrUtils.logoutQuietly(newSession); } } diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java index 66df95cc6..38b3a8b46 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java @@ -126,10 +126,8 @@ public class ModularDistVersionOverviewPage extends FormPage implements layout.verticalSpacing = 0; body.setLayout(layout); try { - form.setText(modularDistribution - .hasProperty(DistConstants.SLC_BUNDLE_NAME) ? modularDistribution - .getProperty(DistConstants.SLC_BUNDLE_NAME).getString() - : ""); + form.setText(modularDistribution.hasProperty(SlcNames.SLC_NAME) ? modularDistribution + .getProperty(SlcNames.SLC_NAME).getString() : ""); form.setMessage( modularDistribution .hasProperty(SlcNames.SLC_BUNDLE_DESCRIPTION) ? modularDistribution @@ -162,22 +160,19 @@ public class ModularDistVersionOverviewPage extends FormPage implements createLT( parent, "Category", - modularDistribution.hasProperty(SlcNames.SLC_GROUP_ID) ? modularDistribution - .getProperty(SlcNames.SLC_GROUP_ID).getString() + modularDistribution.hasProperty(SlcNames.SLC_CATEGORY) ? modularDistribution + .getProperty(SlcNames.SLC_CATEGORY).getString() : ""); createLT( parent, "Name", - modularDistribution.hasProperty(SlcNames.SLC_SYMBOLIC_NAME) ? modularDistribution - .getProperty(SlcNames.SLC_SYMBOLIC_NAME) - .getString() : ""); + modularDistribution.hasProperty(SlcNames.SLC_NAME) ? modularDistribution + .getProperty(SlcNames.SLC_NAME).getString() : ""); createLT( parent, "Version", - modularDistribution - .hasProperty(SlcNames.SLC_BUNDLE_VERSION) ? modularDistribution - .getProperty(SlcNames.SLC_BUNDLE_VERSION) - .getString() : ""); + modularDistribution.hasProperty(SlcNames.SLC_VERSION) ? modularDistribution + .getProperty(SlcNames.SLC_VERSION).getString() : ""); // 2nd Line: Vendor, licence, sources createLT( @@ -186,7 +181,7 @@ public class ModularDistVersionOverviewPage extends FormPage implements modularDistribution .hasProperty(DistConstants.SLC_BUNDLE_VENDOR) ? modularDistribution .getProperty(DistConstants.SLC_BUNDLE_VENDOR) - .getString() : ""); + .getString() : "N/A"); createHyperlink(parent, "Licence", DistConstants.SLC_BUNDLE_LICENCE); addSourceSourcesLink(parent); @@ -237,7 +232,7 @@ public class ModularDistVersionOverviewPage extends FormPage implements } }); } else - tk.createLabel(parent, "", SWT.NONE); + tk.createLabel(parent, "N/A", SWT.NONE); } // helper to check if sources are available @@ -252,12 +247,16 @@ public class ModularDistVersionOverviewPage extends FormPage implements Node sourcesNode = modularDistribution.getSession().getNode( srcPath); + String srcName = null; + if (sourcesNode.hasProperty(SlcNames.SLC_SYMBOLIC_NAME)) + srcName = sourcesNode.getProperty( + SlcNames.SLC_SYMBOLIC_NAME).getString(); + else + srcName = sourcesNode.getName(); Label label = tk.createLabel(parent, "Sources", SWT.RIGHT); label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); - - final Hyperlink link = tk.createHyperlink(parent, sourcesNode - .getProperty(SlcNames.SLC_SYMBOLIC_NAME).getString(), + final Hyperlink link = tk.createHyperlink(parent, srcName, SWT.NONE); link.addHyperlinkListener(new AbstractHyperlinkListener() { @Override diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/WkspCategoryBaseListPage.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/WkspCategoryBaseListPage.java index 6479eb534..c8b87c0a4 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/WkspCategoryBaseListPage.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/WkspCategoryBaseListPage.java @@ -287,7 +287,7 @@ public class WkspCategoryBaseListPage extends FormPage implements SlcNames { public String getText(Object element) { try { return ((Node) element) - .isNodeType(SlcTypes.SLC_RELEVANT_CATEGORY) ? "Yes" + .isNodeType(SlcTypes.SLC_CATEGORY) ? "Yes" : "No"; } catch (RepositoryException e) { throw new SlcException("unable to check type of node " @@ -344,9 +344,9 @@ public class WkspCategoryBaseListPage extends FormPage implements SlcNames { boolean isRelevant = false; try { isRelevant = currSelected - .isNodeType(SlcTypes.SLC_RELEVANT_CATEGORY); + .isNodeType(SlcTypes.SLC_CATEGORY); boolean canEdit = currSelected - .canAddMixin(SlcTypes.SLC_RELEVANT_CATEGORY); + .canAddMixin(SlcTypes.SLC_CATEGORY); } catch (RepositoryException e) { throw new SlcException("unable to check type of node " diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistBaseElem.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistBaseElem.java index 54fdf1070..b85659440 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistBaseElem.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistBaseElem.java @@ -49,7 +49,8 @@ public class ModularDistBaseElem extends DistParentElem { } /** - * Override normal behaviour to initialise children only when first requested + * Override normal behaviour to initialise children only when first + * requested */ @Override public synchronized boolean hasChildren() { @@ -61,7 +62,8 @@ public class ModularDistBaseElem extends DistParentElem { }; /** - * Override normal behaviour to initialise children only when first requested + * Override normal behaviour to initialise children only when first + * requested */ @Override public synchronized Object[] getChildren() { @@ -72,15 +74,15 @@ public class ModularDistBaseElem extends DistParentElem { NodeIterator ni = getDistVersions(); while (ni != null && ni.hasNext()) { Node curNode = ni.nextNode(); - addChild(new ModularDistVersionElem(this, curNode - .getProperty(SlcNames.SLC_ARTIFACT_VERSION) - .getString(), curNode)); + if (curNode.hasProperty(SlcNames.SLC_ARTIFACT_VERSION)) + addChild(new ModularDistVersionElem(this, curNode + .getProperty(SlcNames.SLC_ARTIFACT_VERSION) + .getString(), curNode)); } return super.getChildren(); } catch (RepositoryException re) { - throw new ArgeoException( - "Unable to retrieve children for " - + modularDistBase, re); + throw new ArgeoException("Unable to retrieve children for " + + modularDistBase, re); } } } diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java index 0567b3193..c3088ebb2 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java @@ -113,7 +113,7 @@ public class WorkspaceElem extends DistParentElem { .getQueryManager() .createQuery( "select * from [" - + SlcTypes.SLC_RELEVANT_CATEGORY + "]", + + SlcTypes.SLC_CATEGORY + "]", Query.JCR_SQL2); distributions = groupQuery.execute().getNodes(); while (distributions.hasNext()) { diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java index 283886317..84cb8e5ef 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java @@ -26,17 +26,17 @@ import org.argeo.eclipse.ui.utils.CommandUtils; import org.argeo.jcr.ArgeoNames; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; +import org.argeo.slc.client.ui.dist.commands.CopyLocalJavaWorkspace; import org.argeo.slc.client.ui.dist.commands.CopyWorkspace; +import org.argeo.slc.client.ui.dist.commands.CreateLocalJavaWorkspace; import org.argeo.slc.client.ui.dist.commands.CreateWorkspace; import org.argeo.slc.client.ui.dist.commands.DeleteWorkspace; import org.argeo.slc.client.ui.dist.commands.DisplayRepoInformation; import org.argeo.slc.client.ui.dist.commands.Fetch; -import org.argeo.slc.client.ui.dist.commands.MergeWorkspaces; import org.argeo.slc.client.ui.dist.commands.NormalizeDistribution; import org.argeo.slc.client.ui.dist.commands.NormalizeWorkspace; import org.argeo.slc.client.ui.dist.commands.OpenGenerateBinariesWizard; import org.argeo.slc.client.ui.dist.commands.PublishWorkspace; -import org.argeo.slc.client.ui.dist.commands.RefreshDistributionsView; import org.argeo.slc.client.ui.dist.commands.RegisterRepository; import org.argeo.slc.client.ui.dist.commands.RunInOsgi; import org.argeo.slc.client.ui.dist.commands.UnregisterRemoteRepo; @@ -50,26 +50,16 @@ import org.argeo.slc.client.ui.dist.model.ModularDistBaseElem; import org.argeo.slc.client.ui.dist.model.RepoElem; import org.argeo.slc.client.ui.dist.model.WkspGroupElem; import org.argeo.slc.client.ui.dist.model.WorkspaceElem; -import org.argeo.slc.client.ui.dist.utils.CommandHelpers; import org.argeo.slc.jcr.SlcNames; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewerColumn; -import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.viewers.ViewerDropAdapter; import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.DragSourceAdapter; -import org.eclipse.swt.dnd.DragSourceEvent; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.dnd.TransferData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Tree; @@ -119,12 +109,6 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames // Enable retrieving current tree selected items from outside the view getSite().setSelectionProvider(viewer); - // Drag and drop - Transfer[] tt = new Transfer[] { TextTransfer.getInstance() }; - int operations = DND.DROP_COPY | DND.DROP_MOVE; - viewer.addDragSupport(operations, tt, new ViewDragListener()); - viewer.addDropSupport(operations, tt, new ViewDropListener(viewer)); - MenuManager menuManager = new MenuManager(); Menu menu = menuManager.createContextMenu(viewer.getTree()); menuManager.addMenuListener(new IMenuListener() { @@ -214,8 +198,18 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames CreateWorkspace.ID, CreateWorkspace.DEFAULT_LABEL, CreateWorkspace.DEFAULT_ICON, (isRepoElem || isDistribGroupElem) && singleElement - && !isReadOnly, params); + && !isReadOnly && !isLocal, params); + // TODO Manage the case where it is not a java workspace + params = new HashMap(); + params.put(CreateLocalJavaWorkspace.PARAM_WORKSPACE_PREFIX, + workspacePrefix); + CommandUtils.refreshParametrizedCommand(menuManager, window, + CreateLocalJavaWorkspace.ID, CreateLocalJavaWorkspace.DEFAULT_LABEL, + CreateLocalJavaWorkspace.DEFAULT_ICON, + (isRepoElem || isDistribGroupElem) && singleElement + && !isReadOnly && isLocal, params); + // Register a remote repository CommandUtils.refreshCommand(menuManager, window, RegisterRepository.ID, @@ -260,7 +254,15 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames CommandUtils.refreshParametrizedCommand(menuManager, window, CopyWorkspace.ID, CopyWorkspace.DEFAULT_LABEL, CopyWorkspace.DEFAULT_ICON, isDistribElem - && singleElement, params); + && singleElement && !isLocal, params); + + params = new HashMap(); + params.put(CopyLocalJavaWorkspace.PARAM_SOURCE_WORKSPACE_NAME, + workspaceName); + CommandUtils.refreshParametrizedCommand(menuManager, window, + CopyLocalJavaWorkspace.ID, CopyLocalJavaWorkspace.DEFAULT_LABEL, + CopyLocalJavaWorkspace.DEFAULT_ICON, isDistribElem + && singleElement&& isLocal, params); // Clear Workspace params = new HashMap(); @@ -347,78 +349,6 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames viewer.expandToLevel(2); } - /** Listens to drag */ - class ViewDragListener extends DragSourceAdapter { - public void dragSetData(DragSourceEvent event) { - IStructuredSelection selection = (IStructuredSelection) viewer - .getSelection(); - if (selection.getFirstElement() instanceof WorkspaceElem) { - WorkspaceElem de = (WorkspaceElem) selection.getFirstElement(); - if (TextTransfer.getInstance().isSupportedType(event.dataType)) { - event.data = ((RepoElem) de.getParent().getParent()) - .getUri() + "/" + de.getWorkspaceName(); - } - } - } - } - - /** Listens to drop */ - class ViewDropListener extends ViewerDropAdapter { - - public ViewDropListener(Viewer viewer) { - super(viewer); - } - - @Override - public boolean performDrop(Object data) { - WorkspaceElem sourceWksp = (WorkspaceElem) getSelectedObject(); - RepoElem targetRepo = (RepoElem) getCurrentTarget(); - - Boolean ok = MessageDialog.openConfirm( - getSite().getShell(), - "Confirm distribution merge", - "Do you want to merge " - + sourceWksp.getWorkspaceName() - + " (from repo " - + ((RepoElem) sourceWksp.getParent().getParent()) - .getLabel() + ") to repo " - + targetRepo.getLabel() + "?"); - if (!ok) - return false; - - try { - Map params = new HashMap(); - params.put(MergeWorkspaces.PARAM_TARGET_REPO_PATH, targetRepo - .getRepoNode().getPath()); - params.put(MergeWorkspaces.PARAM_SOURCE_REPO_PATH, - ((RepoElem) sourceWksp.getParent().getParent()) - .getRepoNode().getPath()); - params.put(MergeWorkspaces.PARAM_SOURCE_WORKSPACE_NAME, - sourceWksp.getWorkspaceName()); - CommandHelpers.callCommand(RefreshDistributionsView.ID, params); - return true; - } catch (RepositoryException e) { - throw new SlcException("Cannot process drop from " + sourceWksp - + " to " + targetRepo, e); - } - } - - @Override - public boolean validateDrop(Object target, int operation, - TransferData transferType) { - if (target instanceof RepoElem) { - if (getSelectedObject() instanceof WorkspaceElem) { - // check if not same repository - String srcRepoUri = ((RepoElem) ((WorkspaceElem) getSelectedObject()) - .getParent().getParent()).getUri(); - String targetRepoUri = ((RepoElem) target).getUri(); - return !targetRepoUri.equals(srcRepoUri); - } - } - return false; - } - } - /* * DEPENDENCY INJECTION */ diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java index e0474a090..136eae150 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java @@ -18,14 +18,18 @@ package org.argeo.slc.client.ui.dist.wizards; import java.util.ArrayList; import java.util.List; +import javax.jcr.Credentials; import javax.jcr.Node; import javax.jcr.NodeIterator; +import javax.jcr.Repository; import javax.jcr.RepositoryException; +import javax.jcr.Session; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.ArgeoMonitor; import org.argeo.eclipse.ui.EclipseArgeoMonitor; +import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; import org.argeo.slc.client.ui.dist.PrivilegedJob; @@ -34,7 +38,6 @@ import org.argeo.slc.jcr.SlcTypes; import org.argeo.slc.repo.RepoConstants; import org.argeo.slc.repo.RepoUtils; import org.argeo.slc.repo.maven.GenerateBinaries; -import org.argeo.slc.repo.maven.IndexDistribution; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -60,30 +63,34 @@ import org.eclipse.swt.widgets.Text; import org.sonatype.aether.artifact.Artifact; /** - * Defines parameters to generate binaries (e.g. a specific modular - * distribution) using a {@link IndexDistribution} object + * Define parameters to asynchronously generate binaries, sources and sdk pom + * artifacts for this group using a {@link GenerateBinaries} runnable */ public class GenerateBinariesWizard extends Wizard { private final static Log log = LogFactory .getLog(GenerateBinariesWizard.class); // Business objects - private Node groupNode; + private String groupNodePath; + private Repository repository; + private Credentials credentials; + private String wkspName; // The pages private RecapPage recapPage; // Controls with parameters - private Button overridePomsBtn; private Text versionTxt; private Text latestVersionTxt; private Text highestArtifactVersionTxt; - // private CheckboxTableViewer wkspViewer; - - public GenerateBinariesWizard(Node groupNode) { + public GenerateBinariesWizard(Repository repository, + Credentials credentials, String wkspName, String groupNodePath) { super(); - this.groupNode = groupNode; + this.repository = repository; + this.credentials = credentials; + this.wkspName = wkspName; + this.groupNodePath = groupNodePath; } @Override @@ -107,15 +114,18 @@ public class GenerateBinariesWizard extends Wizard { if (!canFinish()) return false; try { - String msg = "Your are about to normalize group, do you really want to proceed ?"; + String msg = "Your are about to generate binaries, sources and sdk " + + "pom artifacts for this group, " + + "do you really want to proceed ?"; boolean result = MessageDialog.openConfirm(DistPlugin.getDefault() .getWorkbench().getDisplay().getActiveShell(), - "Confirm Process Launch", msg); + "Confirm Launch", msg); if (result) { - GenerateBinaryJob job = new GenerateBinaryJob(groupNode, - versionTxt.getText(), overridePomsBtn.getSelection()); + GenerateBinaryJob job = new GenerateBinaryJob(repository, + credentials, wkspName, groupNodePath, + versionTxt.getText()); job.setUser(true); job.schedule(); } @@ -143,20 +153,14 @@ public class GenerateBinariesWizard extends Wizard { } public IWizardPage getNextPage() { - // always last.... - return null; - } - - @Override - public void setVisible(boolean visible) { - if (visible) { - - } - super.setVisible(visible); + return null; // always last } private void refreshValues() { + Session session = null; try { + session = repository.login(credentials, wkspName); + Node groupNode = session.getNode(groupNodePath); GenerateBinaries gb = GenerateBinaries.preProcessGroupNode( groupNode, null); @@ -187,31 +191,40 @@ public class GenerateBinariesWizard extends Wizard { } } if (currHighestVersion != null) - latestVersionTxt.setText(highestVersion + latestVersionTxt.setText(currHighestVersion .getBaseVersion()); } - recapViewer.setInput(binaries); recapViewer.refresh(); } catch (RepositoryException re) { throw new SlcException("Unable to get repositories URIs", re); + } finally { + JcrUtils.logoutQuietly(session); } } public void createControl(Composite parent) { + setMessage("Configure Maven Indexing", IMessageProvider.NONE); + Composite composite = new Composite(parent, SWT.NO_FOCUS); composite.setLayout(new GridLayout(2, false)); versionTxt = createLT(composite, "Version"); + versionTxt + .setToolTipText("Enter a version for the new Modular Distribution"); + latestVersionTxt = createLT(composite, "Latest version"); latestVersionTxt.setEditable(false); + latestVersionTxt + .setToolTipText("The actual latest version of this modular distribution"); + highestArtifactVersionTxt = createLT(composite, "Highest version in current category"); highestArtifactVersionTxt.setEditable(false); + highestArtifactVersionTxt + .setToolTipText("The highest version among all version of the below listed modules."); - overridePomsBtn = createLC(composite, "Override POMs"); - setMessage("Configure Maven Indexing", IMessageProvider.NONE); - + // Creates the table Table table = new Table(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); table.setLinesVisible(true); @@ -220,7 +233,6 @@ public class GenerateBinariesWizard extends Wizard { 1)); recapViewer = new TableViewer(table); - // Artifact columns TableViewerColumn column = ViewerUtils.createTableViewerColumn( recapViewer, "Name", SWT.NONE, 250); column.setLabelProvider(new ColumnLabelProvider() { @@ -242,6 +254,7 @@ public class GenerateBinariesWizard extends Wizard { recapViewer.setContentProvider(new IStructuredContentProvider() { List artifacts; + @SuppressWarnings("unchecked") public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { artifacts = (List) newInput; @@ -264,52 +277,45 @@ public class GenerateBinariesWizard extends Wizard { } } - /** Creates label and text. */ - protected Text createLT(Composite parent, String label) { - new Label(parent, SWT.NONE).setText(label); - Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER - | SWT.NONE); - text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - return text; - } - - /** Creates label and check. */ - protected Button createLC(Composite parent, String label) { - new Label(parent, SWT.NONE).setText(label); - Button check = new Button(parent, SWT.CHECK); - check.setSelection(false); - check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - return check; - } - /** - * Define the privileged job that will be run asynchronously to real - * indexing + * Define the privileged job that will be run asynchronously generate + * corresponding artifacts */ private class GenerateBinaryJob extends PrivilegedJob { - private Node groupBaseNode; - private String version; - private boolean overridePoms; - public GenerateBinaryJob(Node groupBaseNode, String version, - boolean overridePoms) { + private final Repository repository; + private final Credentials credentials; + private final String wkspName; + private final String groupNodePath; + private final String version; + + public GenerateBinaryJob(Repository repository, + Credentials credentials, String wkspName, String groupNodePath, + String version) { super("Fetch"); - this.groupBaseNode = groupBaseNode; this.version = version; - this.overridePoms = overridePoms; + this.repository = repository; + this.credentials = credentials; + this.wkspName = wkspName; + this.groupNodePath = groupNodePath; } @Override protected IStatus doRun(IProgressMonitor progressMonitor) { + Session session = null; try { ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor); + session = repository.login(credentials, wkspName); + Node groupBaseNode = session.getNode(groupNodePath); GenerateBinaries.processGroupNode(groupBaseNode, version, - overridePoms, monitor); + monitor); } catch (Exception e) { if (log.isDebugEnabled()) e.printStackTrace(); return new Status(IStatus.ERROR, DistPlugin.ID, "Cannot normalize group", e); + } finally { + JcrUtils.logoutQuietly(session); } return Status.OK_STATUS; } @@ -317,4 +323,21 @@ public class GenerateBinariesWizard extends Wizard { // //////////////////////////// // // Helpers + /** Creates label and text. */ + protected Text createLT(Composite parent, String label) { + new Label(parent, SWT.NONE).setText(label); + Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER + | SWT.NONE); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + return text; + } + + /** Creates label and check. */ + protected Button createLC(Composite parent, String label) { + new Label(parent, SWT.NONE).setText(label); + Button check = new Button(parent, SWT.CHECK); + check.setSelection(false); + check.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + return check; + } } \ No newline at end of file diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/JarFileIndexer.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/JarFileIndexer.java index 7e41168aa..06e7129b4 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/JarFileIndexer.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/JarFileIndexer.java @@ -110,9 +110,10 @@ public class JarFileIndexer implements NodeIndexer, SlcNames { fileNode.setProperty(SlcNames.SLC_MANIFEST, manifestBinary); Attributes attrs = manifest.getMainAttributes(); - if (log.isTraceEnabled()) - for (Object key : attrs.keySet()) - log.trace(key + ": " + attrs.getValue(key.toString())); + + // if (log.isTraceEnabled()) + // for (Object key : attrs.keySet()) + // log.trace(key + ": " + attrs.getValue(key.toString())); // standard J2SE MANIFEST attributes addAttr(Attributes.Name.MANIFEST_VERSION, fileNode, attrs); diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/DistributionBundleIndexer.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ModularDistributionIndexer.java similarity index 72% rename from runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/DistributionBundleIndexer.java rename to runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ModularDistributionIndexer.java index 90d5a3980..7fee5a3f3 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/DistributionBundleIndexer.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/ModularDistributionIndexer.java @@ -27,11 +27,14 @@ 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.CategorizedNameVersion; +import org.argeo.slc.DefaultNameVersion; import org.argeo.slc.SlcException; import org.argeo.slc.aether.AetherUtils; import org.argeo.slc.aether.ArtifactIdComparator; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; +import org.osgi.framework.Constants; import org.sonatype.aether.artifact.Artifact; import org.sonatype.aether.util.artifact.DefaultArtifact; import org.w3c.dom.Document; @@ -39,30 +42,35 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** - * Create or update JCR meta-data for modularDistribution bundles:
  • - * .jar: dependency artifacts with csv index
  • .pom: group index artifact - * (binaries, sources) with tag dependency management
  • + * Create or update JCR meta-data for an SLC Modular Distribution + * + * Currently, following types are managed:
  • * .jar: dependency + * artifacts with csv index
  • .pom: artifact (binaries) that indexes a + * group, the .pom file contains a tag "dependencyManagement" that list all + * modules
  • */ -public class DistributionBundleIndexer implements NodeIndexer { +public class ModularDistributionIndexer implements NodeIndexer, SlcNames { private final static Log log = LogFactory - .getLog(DistributionBundleIndexer.class); + .getLog(ModularDistributionIndexer.class); + // Constants for csv indexing private final static String INDEX_FILE_NAME = "modularDistribution.csv"; + private String separator = ","; + + // Artifact indexing private final static List BINARIES_ARTIFACTS_NAME; static { List tmpList = new ArrayList(); tmpList.add(RepoConstants.BINARIES_ARTIFACT_ID); - //tmpList.add(RepoConstants.SOURCES_ARTIFACT_ID); - //tmpList.add(RepoConstants.SDK_ARTIFACT_ID); + // tmpList.add(RepoConstants.SOURCES_ARTIFACT_ID); + // tmpList.add(RepoConstants.SDK_ARTIFACT_ID); BINARIES_ARTIFACTS_NAME = Collections.unmodifiableList(tmpList); } private Manifest manifest; // private String symbolicName; // private String version; - // private List artifacts; - private String separator = ","; private Comparator artifactComparator = new ArtifactIdComparator(); @@ -98,11 +106,15 @@ public class DistributionBundleIndexer implements NodeIndexer { Set artifacts = new TreeSet(artifactComparator); + MyCategorizedNameVersion currCatNV = null; + if (FilenameUtils.getExtension(fileNode.getPath()).equals("jar")) - listModulesFromCsvIndex(artifacts, fileNode, fileBinary); + currCatNV = listModulesFromCsvIndex(artifacts, fileNode, + fileBinary); else if (FilenameUtils.getExtension(fileNode.getPath()).equals( "pom")) - listModulesFromPomIndex(artifacts, fileNode, fileBinary); + currCatNV = listModulesFromPomIndex(artifacts, fileNode, + fileBinary); if (artifacts.isEmpty()) return; // no modules found @@ -112,6 +124,12 @@ public class DistributionBundleIndexer implements NodeIndexer { modules = fileNode.getNode(SlcNames.SLC_MODULES); } else { fileNode.addMixin(SlcTypes.SLC_MODULAR_DISTRIBUTION); + fileNode.addMixin(SlcTypes.SLC_CATEGORIZED_NAME_VERSION); + if (currCatNV.getCategory() != null) + fileNode.setProperty(SLC_CATEGORY, + currCatNV.getCategory()); + fileNode.setProperty(SLC_NAME, currCatNV.getName()); + fileNode.setProperty(SLC_VERSION, currCatNV.getVersion()); modules = JcrUtils.mkdirs(fileNode, SlcNames.SLC_MODULES, NodeType.NT_UNSTRUCTURED); } @@ -133,62 +151,56 @@ public class DistributionBundleIndexer implements NodeIndexer { artifact.getGroupId()); } } - } - // find base URL - // won't work if distribution artifact is not listed - // for (int i = 0; i < artifacts.size(); i++) { - // OsgiArtifact osgiArtifact = artifacts.get(i); - // if (osgiArtifact.getSymbolicName().equals(symbolicName) - // && osgiArtifact.getVersion().equals(version)) { - // String relativeUrl = osgiArtifact.getRelativeUrl(); - // if (url.endsWith(relativeUrl)) { - // baseUrl = url.substring(0, url.length() - // - osgiArtifact.getRelativeUrl().length()); - // break; - // } - // } - // } + if (log.isTraceEnabled()) + log.trace("Indexed " + fileNode + " as modular distribution"); } catch (Exception e) { throw new SlcException("Cannot list dependencies from " + fileNode, e); } } - protected void listModulesFromCsvIndex(Set artifacts, - Node fileNode, Binary fileBinary) { - // List artifacts = new ArrayList(); + protected MyCategorizedNameVersion listModulesFromCsvIndex( + Set artifacts, Node fileNode, Binary fileBinary) { JarInputStream jarIn = null; BufferedReader reader = null; - try { jarIn = new JarInputStream(fileBinary.getStream()); // meta data - // symbolicName = manifest.getMainAttributes().getValue( - // Constants.BUNDLE_SYMBOLICNAME); - // version = manifest.getMainAttributes().getValue( - // Constants.BUNDLE_VERSION); - manifest = jarIn.getManifest(); if (manifest == null) { log.error(fileNode + " has no MANIFEST"); - return; + return null; } - + String symbolicName = manifest.getMainAttributes().getValue( + Constants.BUNDLE_SYMBOLICNAME); + String version = manifest.getMainAttributes().getValue( + Constants.BUNDLE_VERSION); + String category = manifest.getMainAttributes().getValue( + "SLC-GroupId"); + + // Retrieve the index file JarEntry indexEntry; while ((indexEntry = jarIn.getNextJarEntry()) != null) { String entryName = indexEntry.getName(); if (entryName.equals(INDEX_FILE_NAME)) { break; } - jarIn.closeEntry(); + try { + jarIn.closeEntry(); + } catch (SecurityException se) { + log.error("Invalid signature file digest " + + "for Manifest main attributes: " + entryName + + " while looking for an index in bundle " + + symbolicName); + } } - if (indexEntry == null) - return; // Not a modular definition artifact + return null; // Not a modular definition artifact + // Process the index reader = new BufferedReader(new InputStreamReader(jarIn)); String line = null; while ((line = reader.readLine()) != null) { @@ -196,12 +208,13 @@ public class DistributionBundleIndexer implements NodeIndexer { st.nextToken(); // moduleName st.nextToken(); // moduleVersion String relativeUrl = st.nextToken(); - artifacts.add(AetherUtils.convertPathToArtifact(relativeUrl, null)); if (log.isTraceEnabled()) log.debug("Processed dependency: " + line); } + + return new MyCategorizedNameVersion(category, symbolicName, version); } catch (Exception e) { throw new SlcException("Cannot list artifacts", e); } finally { @@ -210,8 +223,8 @@ public class DistributionBundleIndexer implements NodeIndexer { } } - protected void listModulesFromPomIndex(Set artifacts, - Node fileNode, Binary fileBinary) { + protected MyCategorizedNameVersion listModulesFromPomIndex( + Set artifacts, Node fileNode, Binary fileBinary) { InputStream input = null; try { input = fileBinary.getStream(); @@ -273,6 +286,16 @@ public class DistributionBundleIndexer implements NodeIndexer { artifacts.add(artifact); // } } + + String groupId = doc.getElementsByTagName("groupId").item(0) + .getTextContent().trim(); + String artifactId = doc.getElementsByTagName("artifactId").item(0) + .getTextContent().trim(); + String version = doc.getElementsByTagName("version").item(0) + .getTextContent().trim(); + + return new MyCategorizedNameVersion(groupId, artifactId, version); + } catch (Exception e) { throw new SlcException("Cannot process pom " + fileNode, e); } finally { @@ -285,37 +308,19 @@ public class DistributionBundleIndexer implements NodeIndexer { this.separator = modulesUrlSeparator; } - /** One of the listed artifact */ - protected static class OsgiArtifact { + /** The created modular distribution */ + private static class MyCategorizedNameVersion extends DefaultNameVersion + implements CategorizedNameVersion { private final String category; - private final String symbolicName; - private final String version; - private final String relativeUrl; - public OsgiArtifact(String category, String symbolicName, - String version, String relativeUrl) { - super(); + public MyCategorizedNameVersion(String category, String name, + String version) { + super(name, version); this.category = category; - this.symbolicName = symbolicName; - this.version = version; - this.relativeUrl = relativeUrl; } public String getCategory() { return category; } - - public String getSymbolicName() { - return symbolicName; - } - - public String getVersion() { - return version; - } - - public String getRelativeUrl() { - return relativeUrl; - } - } -} +} \ No newline at end of file diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/PdeSourcesIndexer.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/PdeSourcesIndexer.java index 589bd8924..97ca286ce 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/PdeSourcesIndexer.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/PdeSourcesIndexer.java @@ -22,6 +22,8 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.argeo.jcr.JcrUtils; import org.argeo.slc.NameVersion; import org.argeo.slc.SlcException; @@ -35,18 +37,19 @@ import org.sonatype.aether.util.artifact.DefaultArtifact; * "...-sources.jar" */ public class PdeSourcesIndexer implements NodeIndexer { - // private Log log = LogFactory.getLog(PdeSourcesIndexer.class); + private Log log = LogFactory.getLog(PdeSourcesIndexer.class); private String artifactBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH; - private ArtifactIndexer artifactIndexer; - private JarFileIndexer jarFileIndexer; + // private ArtifactIndexer artifactIndexer; + // private JarFileIndexer jarFileIndexer; - public PdeSourcesIndexer(ArtifactIndexer artifactIndexer, - JarFileIndexer jarFileIndexer) { - this.artifactIndexer = artifactIndexer; - this.jarFileIndexer = jarFileIndexer; - } + // public PdeSourcesIndexer(){ + // // ArtifactIndexer artifactIndexer, + // // JarFileIndexer jarFileIndexer) { + // // this.artifactIndexer = artifactIndexer; + // // this.jarFileIndexer = jarFileIndexer; + // } public Boolean support(String path) { // TODO implement clean management of same name siblings @@ -60,6 +63,9 @@ public class PdeSourcesIndexer implements NodeIndexer { public void index(Node sourcesNode) { try { + if (!support(sourcesNode.getPath())) + return; + packageSourcesAsPdeSource(sourcesNode); } catch (Exception e) { throw new SlcException("Cannot generate pde sources for node " @@ -99,8 +105,8 @@ public class PdeSourcesIndexer implements NodeIndexer { .artifactParentPath(artifactBasePath, pdeSourceArtifact); String targetSourceFileName = MavenConventionsUtils .artifactFileName(pdeSourceArtifact); - String targetSourceJarPath = targetSourceParentPath + '/' - + targetSourceFileName; + // String targetSourceJarPath = targetSourceParentPath + '/' + // + targetSourceFileName; Node targetSourceParentNode = JcrUtils.mkfolders(session, targetSourceParentPath); @@ -112,9 +118,15 @@ public class PdeSourcesIndexer implements NodeIndexer { targetSourceFileName, targetJarBytes); // reindex - Node targetSourceJarNode = session.getNode(targetSourceJarPath); - artifactIndexer.index(targetSourceJarNode); - jarFileIndexer.index(targetSourceJarNode); + // Automagically done via the various listeners or manually + // triggered. + // Node targetSourceJarNode = session.getNode(targetSourceJarPath); + // artifactIndexer.index(targetSourceJarNode); + // jarFileIndexer.index(targetSourceJarNode); + if (log.isTraceEnabled()) + log.trace("Created pde source artifact " + pdeSourceArtifact + + " from " + sourcesNode); + } catch (RepositoryException e) { throw new SlcException("Cannot add PDE sources for " + sourcesNode, e); diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/GenerateBinaries.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/GenerateBinaries.java index 6bcf01a25..ed22006ad 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/GenerateBinaries.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/maven/GenerateBinaries.java @@ -16,9 +16,7 @@ package org.argeo.slc.repo.maven; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; @@ -30,7 +28,6 @@ import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; -import org.apache.commons.io.FilenameUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.ArgeoMonitor; @@ -42,15 +39,13 @@ import org.argeo.slc.jcr.SlcTypes; import org.argeo.slc.repo.ArtifactIndexer; import org.argeo.slc.repo.RepoConstants; import org.argeo.slc.repo.RepoUtils; -import org.argeo.slc.repo.osgi.OsgiProfile; -import org.osgi.framework.Constants; import org.osgi.framework.Version; import org.sonatype.aether.artifact.Artifact; import org.sonatype.aether.util.artifact.DefaultArtifact; /** - * Make sure that all JCR metadata and Maven metadata are consistent for this - * group of OSGi bundles. + * Generates binaries-, sources- and sdk-version.pom artifacts for a given + * group. */ public class GenerateBinaries implements Runnable, SlcNames { private final static Log log = LogFactory.getLog(GenerateBinaries.class); @@ -63,35 +58,30 @@ public class GenerateBinaries implements Runnable, SlcNames { // Business info private String groupId; private String parentPomCoordinates; - private Boolean overridePoms = false; private String version = null; // Constants private String artifactBasePath = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH; private List excludedSuffixes = new ArrayList(); - /** TODO make it more generic */ - private List systemPackages = OsgiProfile.PROFILE_JAVA_SE_1_6 - .getSystemPackages(); - private ArtifactIndexer artifactIndexer = new ArtifactIndexer(); - - // Local indexes - private Map packagesToSymbolicNames = new HashMap(); - private Map symbolicNamesToNodes = new HashMap(); + // Indexes private Set binaries = new TreeSet( new ArtifactIdComparator()); private Set sources = new TreeSet( new ArtifactIdComparator()); + + // local cache + private ArtifactIndexer artifactIndexer = new ArtifactIndexer(); private Node allArtifactsHighestVersion; public void run() { Session session = null; try { - session = repository.login(workspace); + session = repository.login(credentials, workspace); Node groupNode = session.getNode(MavenConventionsUtils.groupPath( artifactBasePath, groupId)); internalPreProcessing(groupNode, null); - processGroupNode(groupNode, null); + internalProcessing(groupNode, null); } catch (Exception e) { throw new SlcException("Cannot normalize group " + groupId + " in " + workspace, e); @@ -100,8 +90,16 @@ public class GenerateBinaries implements Runnable, SlcNames { } } + /** + * Generates binaries-, sources- and sdk-version.pom artifacts for the given + * version (or the highest of all children version if none is precised). + * + * By default, it includes each latest version of all artifact of this group. + * + * The 3 generated artifacts are then marked as modular distributions and indexed. + */ public static void processGroupNode(Node groupNode, String version, - Boolean overridePoms, ArgeoMonitor monitor) + ArgeoMonitor monitor) throws RepositoryException { // TODO set artifactsBase based on group node GenerateBinaries gb = new GenerateBinaries(); @@ -109,10 +107,9 @@ public class GenerateBinaries implements Runnable, SlcNames { .getString(); gb.setGroupId(groupId); gb.setVersion(version); - gb.setOverridePoms(overridePoms); // TODO use already done pre-processing gb.internalPreProcessing(groupNode, monitor); - gb.processGroupNode(groupNode, monitor); + gb.internalProcessing(groupNode, monitor); } /** Only builds local indexes. Does not change anything in the local Session */ @@ -139,15 +136,26 @@ public class GenerateBinaries implements Runnable, SlcNames { .asArtifact(allArtifactsHighestVersion); } + // ////////////////////////////////////// + // INTERNAL METHODS + + /** + * Browse all children of a Node considered as a folder that follows Aether + * conventions i.e that has Aether's artifact base as children. + * + * Each of such child contains a set of Aether artifact versions. This + * methods build the binaries {@code Set} and other indexes. It + * does not impact the + */ protected void internalPreProcessing(Node groupNode, ArgeoMonitor monitor) throws RepositoryException { if (monitor != null) monitor.subTask("Pre processing group " + groupId); // Process all direct children nodes, - // gathering latest versions of all artifact base + // gathering latest versions of each artifact allArtifactsHighestVersion = null; - // Session session = groupNode.getSession(); + aBases: for (NodeIterator aBases = groupNode.getNodes(); aBases .hasNext();) { Node aBase = aBases.nextNode(); @@ -157,6 +165,7 @@ public class GenerateBinaries implements Runnable, SlcNames { continue aBases; else { // retrieve relevant child node + // Information is stored on the NT_FILE child node. for (NodeIterator files = highestAVersion.getNodes(); files .hasNext();) { Node file = files.nextNode(); @@ -169,15 +178,15 @@ public class GenerateBinaries implements Runnable, SlcNames { } } } - if (log.isDebugEnabled()) { - int bundleCount = symbolicNamesToNodes.size(); - log.debug("" + bundleCount + " bundles have been indexed for " - + groupId); - } +// if (log.isDebugEnabled()) { +// int bundleCount = symbolicNamesToNodes.size(); +// log.debug("" + bundleCount + " bundles have been indexed for " +// + groupId); +// } } /** Does the real job : writes JCR META-DATA and generates binaries */ - protected void processGroupNode(Node groupNode, ArgeoMonitor monitor) + protected void internalProcessing(Node groupNode, ArgeoMonitor monitor) throws RepositoryException { if (monitor != null) monitor.subTask("Processing group " + groupId); @@ -196,34 +205,132 @@ public class GenerateBinaries implements Runnable, SlcNames { throw new SlcException("Group version " + version + " is empty."); - int bundleCount = symbolicNamesToNodes.size(); - - int count = 1; - for (Node bundleNode : symbolicNamesToNodes.values()) { - if (log.isDebugEnabled()) - log.debug("Processing " + bundleNode.getName() + " ( " + count - + "/" + bundleCount + " )"); - - processBundleArtifact(bundleNode); - bundleNode.getSession().save(); - count++; - } +// int bundleCount = symbolicNamesToNodes.size(); +// +// int count = 1; +// for (Node bundleNode : symbolicNamesToNodes.values()) { +// if (log.isDebugEnabled()) +// log.debug("Processing " + bundleNode.getName() + " ( " + count +// + "/" + bundleCount + " )"); +// +// // processBundleArtifact(bundleNode); +// // bundleNode.getSession().save(); +// count++; +// } // indexes Set indexes = new TreeSet( new ArtifactIdComparator()); - Artifact indexArtifact = writeIndex(session, - RepoConstants.BINARIES_ARTIFACT_ID, binaries); + + Artifact indexArtifact; + indexArtifact = writeIndex(session, RepoConstants.BINARIES_ARTIFACT_ID, + binaries); indexes.add(indexArtifact); + indexArtifact = writeIndex(session, RepoConstants.SOURCES_ARTIFACT_ID, sources); indexes.add(indexArtifact); + // sdk writeIndex(session, RepoConstants.SDK_ARTIFACT_ID, indexes); + if (monitor != null) monitor.worked(1); } + protected void preProcessBundleArtifact(Node bundleNode) + throws RepositoryException { + + String symbolicName = JcrUtils.get(bundleNode, SLC_SYMBOLIC_NAME); + // Sanity check. + if (symbolicName == null) + log.warn("Symbolic name is null for bundle " + bundleNode); + + // Manage source bundles + if (symbolicName.endsWith(".source")) { + // TODO make a shared node with classifier 'sources'? + String bundleName = RepoUtils + .extractBundleNameFromSourceName(symbolicName); + for (String excludedSuffix : excludedSuffixes) { + if (bundleName.endsWith(excludedSuffix)) + return;// skip adding to sources + } + sources.add(RepoUtils.asArtifact(bundleNode)); + return; + } + + // // Build indexes + // NodeIterator exportPackages = bundleNode.getNodes(SLC_ + // + Constants.EXPORT_PACKAGE); + // while (exportPackages.hasNext()) { + // Node exportPackage = exportPackages.nextNode(); + // String pkg = JcrUtils.get(exportPackage, SLC_NAME); + // packagesToSymbolicNames.put(pkg, symbolicName); + // } + // + // symbolicNamesToNodes.put(symbolicName, bundleNode); + // for (String excludedSuffix : excludedSuffixes) { + // if (symbolicName.endsWith(excludedSuffix)) + // return;// skip adding to binaries + // } + + binaries.add(RepoUtils.asArtifact(bundleNode)); + + // Extra check. to remove + if (bundleNode.getSession().hasPendingChanges()) + throw new SlcException("Pending changes in the session, " + + "this should not be true here."); + } + + // protected void processBundleArtifact(Node bundleNode) + // throws RepositoryException { + // Node artifactFolder = bundleNode.getParent(); + // String baseName = FilenameUtils.getBaseName(bundleNode.getName()); + // + // // pom + // String pomName = baseName + ".pom"; + // if (artifactFolder.hasNode(pomName) && !overridePoms) + // return;// skip + // + // String pom = generatePomForBundle(bundleNode); + // Node pomNode = JcrUtils.copyBytesAsFile(artifactFolder, pomName, + // pom.getBytes()); + // // checksum + // String bundleSha = JcrUtils.checksumFile(bundleNode, "SHA-1"); + // JcrUtils.copyBytesAsFile(artifactFolder, + // bundleNode.getName() + ".sha1", bundleSha.getBytes()); + // String pomSha = JcrUtils.checksumFile(pomNode, "SHA-1"); + // JcrUtils.copyBytesAsFile(artifactFolder, pomNode.getName() + ".sha1", + // pomSha.getBytes()); + // } + + // //////////////////// + // LOCAL WRITERS + // + + private Artifact writeIndex(Session session, String artifactId, + Set artifacts) throws RepositoryException { + Artifact artifact = new DefaultArtifact(groupId, artifactId, "pom", + version); + Artifact parentArtifact = parentPomCoordinates != null ? new DefaultArtifact( + parentPomCoordinates) : null; + String pom = MavenConventionsUtils.artifactsAsDependencyPom(artifact, + artifacts, parentArtifact); + Node node = RepoUtils.copyBytesAsArtifact( + session.getNode(artifactBasePath), artifact, pom.getBytes()); + artifactIndexer.index(node); + + // TODO factorize + String pomSha = JcrUtils.checksumFile(node, "SHA-1"); + JcrUtils.copyBytesAsFile(node.getParent(), node.getName() + ".sha1", + pomSha.getBytes()); + String pomMd5 = JcrUtils.checksumFile(node, "MD5"); + JcrUtils.copyBytesAsFile(node.getParent(), node.getName() + ".md5", + pomMd5.getBytes()); + session.save(); + return artifact; + } + // Helpers private Node getArtifactLatestVersion(Node artifactBase) { try { @@ -312,219 +419,141 @@ public class GenerateBinaries implements Runnable, SlcNames { return tmpVersion; } - protected void preProcessBundleArtifact(Node bundleNode) - throws RepositoryException { - - String symbolicName = JcrUtils.get(bundleNode, SLC_SYMBOLIC_NAME); - if (symbolicName.endsWith(".source")) { - // TODO make a shared node with classifier 'sources'? - String bundleName = RepoUtils - .extractBundleNameFromSourceName(symbolicName); - for (String excludedSuffix : excludedSuffixes) { - if (bundleName.endsWith(excludedSuffix)) - return;// skip adding to sources - } - sources.add(RepoUtils.asArtifact(bundleNode)); - return; - } - - NodeIterator exportPackages = bundleNode.getNodes(SLC_ - + Constants.EXPORT_PACKAGE); - while (exportPackages.hasNext()) { - Node exportPackage = exportPackages.nextNode(); - String pkg = JcrUtils.get(exportPackage, SLC_NAME); - packagesToSymbolicNames.put(pkg, symbolicName); - } - - symbolicNamesToNodes.put(symbolicName, bundleNode); - for (String excludedSuffix : excludedSuffixes) { - if (symbolicName.endsWith(excludedSuffix)) - return;// skip adding to binaries - } - binaries.add(RepoUtils.asArtifact(bundleNode)); - - if (bundleNode.getSession().hasPendingChanges()) - throw new SlcException("Pending changes in the session, " - + "this should not be true here."); - // bundleNode.getSession().save(); - } - - protected void processBundleArtifact(Node bundleNode) - throws RepositoryException { - Node artifactFolder = bundleNode.getParent(); - String baseName = FilenameUtils.getBaseName(bundleNode.getName()); - - // pom - String pomName = baseName + ".pom"; - if (artifactFolder.hasNode(pomName) && !overridePoms) - return;// skip - - String pom = generatePomForBundle(bundleNode); - Node pomNode = JcrUtils.copyBytesAsFile(artifactFolder, pomName, - pom.getBytes()); - // checksum - String bundleSha = JcrUtils.checksumFile(bundleNode, "SHA-1"); - JcrUtils.copyBytesAsFile(artifactFolder, - bundleNode.getName() + ".sha1", bundleSha.getBytes()); - String pomSha = JcrUtils.checksumFile(pomNode, "SHA-1"); - JcrUtils.copyBytesAsFile(artifactFolder, pomNode.getName() + ".sha1", - pomSha.getBytes()); - } - - // Writers - private Artifact writeIndex(Session session, String artifactId, - Set artifacts) throws RepositoryException { - Artifact artifact = new DefaultArtifact(groupId, artifactId, "pom", - version); - Artifact parentArtifact = parentPomCoordinates != null ? new DefaultArtifact( - parentPomCoordinates) : null; - String pom = MavenConventionsUtils.artifactsAsDependencyPom(artifact, - artifacts, parentArtifact); - Node node = RepoUtils.copyBytesAsArtifact( - session.getNode(artifactBasePath), artifact, pom.getBytes()); - artifactIndexer.index(node); - - // TODO factorize - String pomSha = JcrUtils.checksumFile(node, "SHA-1"); - JcrUtils.copyBytesAsFile(node.getParent(), node.getName() + ".sha1", - pomSha.getBytes()); - String pomMd5 = JcrUtils.checksumFile(node, "MD5"); - JcrUtils.copyBytesAsFile(node.getParent(), node.getName() + ".md5", - pomMd5.getBytes()); - session.save(); - return artifact; - } - - private String generatePomForBundle(Node n) throws RepositoryException { - String ownSymbolicName = JcrUtils.get(n, SLC_SYMBOLIC_NAME); - - StringBuffer p = new StringBuffer(); - - // XML header - p.append("\n"); - p.append("\n"); - p.append("4.0.0"); - - // Artifact - p.append("").append(JcrUtils.get(n, SLC_GROUP_ID)) - .append("\n"); - p.append("").append(JcrUtils.get(n, SLC_ARTIFACT_ID)) - .append("\n"); - p.append("").append(JcrUtils.get(n, SLC_ARTIFACT_VERSION)) - .append("\n"); - p.append("pom\n"); - if (n.hasProperty(SLC_ + Constants.BUNDLE_NAME)) - p.append("") - .append(JcrUtils.get(n, SLC_ + Constants.BUNDLE_NAME)) - .append("\n"); - if (n.hasProperty(SLC_ + Constants.BUNDLE_DESCRIPTION)) - p.append("") - .append(JcrUtils - .get(n, SLC_ + Constants.BUNDLE_DESCRIPTION)) - .append("\n"); - - // Dependencies - Set dependenciesSymbolicNames = new TreeSet(); - Set optionalSymbolicNames = new TreeSet(); - NodeIterator importPackages = n.getNodes(SLC_ - + Constants.IMPORT_PACKAGE); - while (importPackages.hasNext()) { - Node importPackage = importPackages.nextNode(); - String pkg = JcrUtils.get(importPackage, SLC_NAME); - if (packagesToSymbolicNames.containsKey(pkg)) { - String dependencySymbolicName = packagesToSymbolicNames - .get(pkg); - if (JcrUtils.check(importPackage, SLC_OPTIONAL)) - optionalSymbolicNames.add(dependencySymbolicName); - else - dependenciesSymbolicNames.add(dependencySymbolicName); - } else { - if (!JcrUtils.check(importPackage, SLC_OPTIONAL) - && !systemPackages.contains(pkg)) - log.warn("No bundle found for pkg " + pkg); - } - } - - if (n.hasNode(SLC_ + Constants.FRAGMENT_HOST)) { - String fragmentHost = JcrUtils.get( - n.getNode(SLC_ + Constants.FRAGMENT_HOST), - SLC_SYMBOLIC_NAME); - dependenciesSymbolicNames.add(fragmentHost); - } - - // TODO require bundles - - List dependencyNodes = new ArrayList(); - for (String depSymbName : dependenciesSymbolicNames) { - if (depSymbName.equals(ownSymbolicName)) - continue;// skip self - - if (symbolicNamesToNodes.containsKey(depSymbName)) - dependencyNodes.add(symbolicNamesToNodes.get(depSymbName)); - else - log.warn("Could not find node for " + depSymbName); - } - List optionalDependencyNodes = new ArrayList(); - for (String depSymbName : optionalSymbolicNames) { - if (symbolicNamesToNodes.containsKey(depSymbName)) - optionalDependencyNodes.add(symbolicNamesToNodes - .get(depSymbName)); - else - log.warn("Could not find node for " + depSymbName); - } - - p.append("\n"); - for (Node dependencyNode : dependencyNodes) { - p.append("\n"); - p.append("\t") - .append(JcrUtils.get(dependencyNode, SLC_GROUP_ID)) - .append("\n"); - p.append("\t") - .append(JcrUtils.get(dependencyNode, SLC_ARTIFACT_ID)) - .append("\n"); - p.append("\n"); - } - - if (optionalDependencyNodes.size() > 0) - p.append("\n"); - for (Node dependencyNode : optionalDependencyNodes) { - p.append("\n"); - p.append("\t") - .append(JcrUtils.get(dependencyNode, SLC_GROUP_ID)) - .append("\n"); - p.append("\t") - .append(JcrUtils.get(dependencyNode, SLC_ARTIFACT_ID)) - .append("\n"); - p.append("\ttrue\n"); - p.append("\n"); - } - p.append("\n"); - - // Dependency management - p.append("\n"); - p.append("\n"); - p.append("\n"); - p.append("\t").append(groupId).append("\n"); - p.append("\t") - .append(ownSymbolicName.endsWith(".source") ? RepoConstants.SOURCES_ARTIFACT_ID - : RepoConstants.BINARIES_ARTIFACT_ID) - .append("\n"); - p.append("\t").append(version).append("\n"); - p.append("\tpom\n"); - p.append("\timport\n"); - p.append("\n"); - p.append("\n"); - p.append("\n"); - - p.append("\n"); - return p.toString(); - } + // private String generatePomForBundle(Node n) throws RepositoryException { + // String ownSymbolicName = JcrUtils.get(n, SLC_SYMBOLIC_NAME); + // + // StringBuffer p = new StringBuffer(); + // + // // XML header + // p.append("\n"); + // p.append("\n"); + // p.append("4.0.0"); + // + // // Artifact + // p.append("").append(JcrUtils.get(n, SLC_GROUP_ID)) + // .append("\n"); + // p.append("").append(JcrUtils.get(n, SLC_ARTIFACT_ID)) + // .append("\n"); + // p.append("").append(JcrUtils.get(n, SLC_ARTIFACT_VERSION)) + // .append("\n"); + // p.append("pom\n"); + // if (n.hasProperty(SLC_ + Constants.BUNDLE_NAME)) + // p.append("") + // .append(JcrUtils.get(n, SLC_ + Constants.BUNDLE_NAME)) + // .append("\n"); + // if (n.hasProperty(SLC_ + Constants.BUNDLE_DESCRIPTION)) + // p.append("") + // .append(JcrUtils + // .get(n, SLC_ + Constants.BUNDLE_DESCRIPTION)) + // .append("\n"); + // + // // Dependencies + // Set dependenciesSymbolicNames = new TreeSet(); + // Set optionalSymbolicNames = new TreeSet(); + // NodeIterator importPackages = n.getNodes(SLC_ + // + Constants.IMPORT_PACKAGE); + // while (importPackages.hasNext()) { + // Node importPackage = importPackages.nextNode(); + // String pkg = JcrUtils.get(importPackage, SLC_NAME); + // if (packagesToSymbolicNames.containsKey(pkg)) { + // String dependencySymbolicName = packagesToSymbolicNames + // .get(pkg); + // if (JcrUtils.check(importPackage, SLC_OPTIONAL)) + // optionalSymbolicNames.add(dependencySymbolicName); + // else + // dependenciesSymbolicNames.add(dependencySymbolicName); + // } else { + // if (!JcrUtils.check(importPackage, SLC_OPTIONAL) + // && !systemPackages.contains(pkg)) + // log.warn("No bundle found for pkg " + pkg); + // } + // } + // + // if (n.hasNode(SLC_ + Constants.FRAGMENT_HOST)) { + // String fragmentHost = JcrUtils.get( + // n.getNode(SLC_ + Constants.FRAGMENT_HOST), + // SLC_SYMBOLIC_NAME); + // dependenciesSymbolicNames.add(fragmentHost); + // } + // + // // TODO require bundles + // + // List dependencyNodes = new ArrayList(); + // for (String depSymbName : dependenciesSymbolicNames) { + // if (depSymbName.equals(ownSymbolicName)) + // continue;// skip self + // + // if (symbolicNamesToNodes.containsKey(depSymbName)) + // dependencyNodes.add(symbolicNamesToNodes.get(depSymbName)); + // else + // log.warn("Could not find node for " + depSymbName); + // } + // List optionalDependencyNodes = new ArrayList(); + // for (String depSymbName : optionalSymbolicNames) { + // if (symbolicNamesToNodes.containsKey(depSymbName)) + // optionalDependencyNodes.add(symbolicNamesToNodes + // .get(depSymbName)); + // else + // log.warn("Could not find node for " + depSymbName); + // } + // + // p.append("\n"); + // for (Node dependencyNode : dependencyNodes) { + // p.append("\n"); + // p.append("\t") + // .append(JcrUtils.get(dependencyNode, SLC_GROUP_ID)) + // .append("\n"); + // p.append("\t") + // .append(JcrUtils.get(dependencyNode, SLC_ARTIFACT_ID)) + // .append("\n"); + // p.append("\n"); + // } + // + // if (optionalDependencyNodes.size() > 0) + // p.append("\n"); + // for (Node dependencyNode : optionalDependencyNodes) { + // p.append("\n"); + // p.append("\t") + // .append(JcrUtils.get(dependencyNode, SLC_GROUP_ID)) + // .append("\n"); + // p.append("\t") + // .append(JcrUtils.get(dependencyNode, SLC_ARTIFACT_ID)) + // .append("\n"); + // p.append("\ttrue\n"); + // p.append("\n"); + // } + // p.append("\n"); + // + // // Dependency management + // p.append("\n"); + // p.append("\n"); + // p.append("\n"); + // p.append("\t").append(groupId).append("\n"); + // p.append("\t") + // .append(ownSymbolicName.endsWith(".source") ? + // RepoConstants.SOURCES_ARTIFACT_ID + // : RepoConstants.BINARIES_ARTIFACT_ID) + // .append("\n"); + // p.append("\t").append(version).append("\n"); + // p.append("\tpom\n"); + // p.append("\timport\n"); + // p.append("\n"); + // p.append("\n"); + // p.append("\n"); + // + // p.append("\n"); + // return p.toString(); + // } /* SETTERS */ public void setRepository(Repository repository) { this.repository = repository; } + public void setCredentials(Credentials credentials) { + this.credentials = credentials; + } + public void setWorkspace(String workspace) { this.workspace = workspace; } @@ -549,10 +578,6 @@ public class GenerateBinaries implements Runnable, SlcNames { this.excludedSuffixes = excludedSuffixes; } - public void setOverridePoms(Boolean overridePoms) { - this.overridePoms = overridePoms; - } - public void setArtifactIndexer(ArtifactIndexer artifactIndexer) { this.artifactIndexer = artifactIndexer; } diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java index 34e1aee24..716bf345c 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/NormalizeGroup.java @@ -38,6 +38,7 @@ import org.argeo.slc.aether.ArtifactIdComparator; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; import org.argeo.slc.repo.ArtifactIndexer; +import org.argeo.slc.repo.NodeIndexer; import org.argeo.slc.repo.RepoConstants; import org.argeo.slc.repo.RepoUtils; import org.argeo.slc.repo.maven.MavenConventionsUtils; @@ -49,7 +50,11 @@ import org.sonatype.aether.util.artifact.DefaultArtifact; /** * Make sure that all JCR metadata and Maven metadata are consistent for this * group of OSGi bundles. + * + * The job is now done via the various {@code NodeIndexer} of the WorkspaceManager. + * TODO import dependencies in the workspace. */ +@Deprecated public class NormalizeGroup implements Runnable, SlcNames { private final static Log log = LogFactory.getLog(NormalizeGroup.class); diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/OsgiFactoryImpl.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/OsgiFactoryImpl.java index e6b8b323e..86a15ef27 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/OsgiFactoryImpl.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/osgi/OsgiFactoryImpl.java @@ -58,6 +58,8 @@ public class OsgiFactoryImpl implements OsgiFactory, SlcNames { Session javaSession = null; Session distSession = null; try { + // TODO rather user a JavaRepoManager that will also implicitely + // manage the indexing of newly created nodes. javaSession = JcrUtils.loginOrCreateWorkspace(javaRepository, workspace); distSession = JcrUtils.loginOrCreateWorkspace(distRepository, @@ -169,7 +171,7 @@ public class OsgiFactoryImpl implements OsgiFactory, SlcNames { return loadUrlToPath(url, distSession, distPath); } catch (FileNotFoundException e) { if (log.isDebugEnabled()) - log.debug("Cannot download" + url + log.debug("Cannot download " + url + ", trying another mirror"); } } diff --git a/runtime/org.argeo.slc.repo/src/main/resources/org/argeo/slc/repo/repo.cnd b/runtime/org.argeo.slc.repo/src/main/resources/org/argeo/slc/repo/repo.cnd index 33d4444a4..1acaf9823 100644 --- a/runtime/org.argeo.slc.repo/src/main/resources/org/argeo/slc/repo/repo.cnd +++ b/runtime/org.argeo.slc.repo/src/main/resources/org/argeo/slc/repo/repo.cnd @@ -38,7 +38,9 @@ mixin [slc:modularDistributionBase] mixin -[slc:modularDistribution] +// Inherit from > slc:categorizedNameVersion ?? +// (not possible without migration) +[slc:modularDistribution] mixin + slc:modules (nt:unstructured) m diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java index d6ddd1921..c12f86c85 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java @@ -34,9 +34,9 @@ public interface SlcNames { public final static String SLC_AGGREGATED_STATUS = "slc:aggregatedStatus"; public final static String SLC_TYPE = "slc:type"; - public final static String SLC_CATEGORY = "slc:category"; public final static String SLC_NAME = "slc:name"; public final static String SLC_VERSION = "slc:version"; + public final static String SLC_CATEGORY = "slc:category"; public final static String SLC_VALUE = "slc:value"; public final static String SLC_ADDRESS = "slc:address"; public final static String SLC_METADATA = "slc:metadata"; diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java index 35f971dcc..177dbb369 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java @@ -18,6 +18,9 @@ package org.argeo.slc.jcr; /** JCR node types used by SLC */ public interface SlcTypes { + public final static String SLC_NAME_VERSION = "slc:nameVersion"; + public final static String SLC_CATEGORIZED_NAME_VERSION = "slc:categorizedNameVersion"; + public final static String SLC_AGENT_FACTORY = "slc:agentFactory"; public final static String SLC_AGENT = "slc:agent"; public final static String SLC_MODULE = "slc:module"; @@ -64,9 +67,9 @@ public interface SlcTypes { public final static String SLC_DYNAMIC_IMPORTED_PACKAGE = "slc:dynamicImportedPackage"; public final static String SLC_REQUIRED_BUNDLE = "slc:requiredBundle"; public final static String SLC_FRAGMENT_HOST = "slc:fragmentHost"; - + // Distribution management - public final static String SLC_RELEVANT_CATEGORY = "slc:category"; + public final static String SLC_CATEGORY = "slc:category"; public final static String SLC_MODULAR_DISTRIBUTION_BASE = "slc:modularDistributionBase"; public final static String SLC_MODULAR_DISTRIBUTION = "slc:modularDistribution"; public final static String SLC_MODULE_COORDINATES = "slc:moduleCoordinates"; diff --git a/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd b/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd index d76c517ef..6e23cf5e9 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd +++ b/runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd @@ -6,6 +6,11 @@ mixin - slc:name (STRING) m - slc:version (STRING) m +[slc:categorizedNameVersion] > slc:nameVersion +mixin +// define as mandatory? +- slc:category (STRING) + // AGENT [slc:agentFactory] > nt:unstructured, mix:title + * (slc:agent) -- 2.39.2