Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodor Boev2017-06-06 10:39:11 -0400
committerAlexander Kurtakov2017-10-03 04:13:41 -0400
commit508127d71a2a2cbc3aad554f2931219ae190a410 (patch)
tree4968d0ab05eec2e9a986ee1eca6cca04153521c8
parent872431089780603782ca6de7c774059ed8620e3c (diff)
downloadrt.equinox.p2-508127d71a2a2cbc3aad554f2931219ae190a410.tar.gz
rt.equinox.p2-508127d71a2a2cbc3aad554f2931219ae190a410.tar.xz
rt.equinox.p2-508127d71a2a2cbc3aad554f2931219ae190a410.zip
Bug 313553 - Capability: add writing to a metadata repo
Change-Id: I4323f084b7b6b1107d0ccd95d375570dc9c35fb0 Signed-off-by: Todor Boev <rinsvind@gmail.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java63
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java8
-rw-r--r--bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java2
3 files changed, 68 insertions, 5 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java
index 89785d3c3..37559a7b9 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/MetadataWriter.java
@@ -14,6 +14,7 @@ package org.eclipse.equinox.internal.p2.metadata.repository.io;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.util.*;
+import java.util.Map.Entry;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
@@ -152,16 +153,68 @@ public class MetadataWriter extends XMLWriter implements XMLConstants {
start(PROVIDED_CAPABILITIES_ELEMENT);
attribute(COLLECTION_SIZE_ATTRIBUTE, capabilities.size());
for (IProvidedCapability capability : capabilities) {
- start(PROVIDED_CAPABILITY_ELEMENT);
- attribute(NAMESPACE_ATTRIBUTE, capability.getNamespace());
- attribute(NAME_ATTRIBUTE, capability.getName());
- attribute(VERSION_ATTRIBUTE, capability.getVersion());
- end(PROVIDED_CAPABILITY_ELEMENT);
+ writeProvidedCapability(capability);
}
end(PROVIDED_CAPABILITIES_ELEMENT);
}
}
+ protected void writeProvidedCapability(IProvidedCapability capability) {
+ start(PROVIDED_CAPABILITY_ELEMENT);
+
+ attribute(NAMESPACE_ATTRIBUTE, capability.getNamespace());
+ attribute(NAME_ATTRIBUTE, capability.getName());
+ attribute(VERSION_ATTRIBUTE, capability.getVersion());
+
+ Map<String, Object> attrs = new HashMap<>(capability.getAttributes());
+ attrs.remove(NAME_ATTRIBUTE);
+ attrs.remove(VERSION_ATTRIBUTE);
+
+ if (!attrs.isEmpty()) {
+ start(CAPABILITY_ATTRIBUTES_ELEMENT);
+ attribute(COLLECTION_SIZE_ATTRIBUTE, attrs.size());
+
+ for (Entry<String, Object> attr : attrs.entrySet()) {
+ start(CAPABILITY_ATTRIBUTE_ELEMENT);
+
+ String name = attr.getKey();
+ Object val = attr.getValue();
+ String type;
+
+ if (Collection.class.isAssignableFrom(val.getClass())) {
+ Collection<?> coll = (Collection<?>) val;
+
+ String elType = coll.iterator().next().getClass().getSimpleName();
+ type = "List<" + elType + ">"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ StringBuilder valBuff = new StringBuilder();
+ for (Iterator<?> iter = coll.iterator(); iter.hasNext();) {
+ String el = iter.next().toString();
+
+ valBuff.append(el);
+ if (iter.hasNext()) {
+ valBuff.append(","); //$NON-NLS-1$
+ }
+ }
+
+ val = valBuff.toString();
+ } else {
+ type = val.getClass().getSimpleName();
+ val = val.toString();
+ }
+
+ attribute(CAPABILITY_ATTRIBUTE_NAME_ATTRIBUTE, name);
+ attribute(CAPABILITY_ATTRIBUTE_TYPE_ATTRIBUTE, type);
+ attribute(CAPABILITY_ATTRIBUTE_VALUE_ATTRIBUTE, val);
+
+ end(CAPABILITY_ATTRIBUTE_ELEMENT);
+ }
+ end(CAPABILITY_ATTRIBUTES_ELEMENT);
+ }
+
+ end(PROVIDED_CAPABILITY_ELEMENT);
+ }
+
protected void writeMetaRequirements(Collection<IRequirement> metaRequirements) {
if (metaRequirements != null && metaRequirements.size() > 0) {
start(META_REQUIREMENTS_ELEMENT);
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java
index fd7e3ac59..44db99925 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/src/org/eclipse/equinox/internal/p2/metadata/repository/io/XMLConstants.java
@@ -71,6 +71,14 @@ public interface XMLConstants extends org.eclipse.equinox.internal.p2.persistenc
public static final String CAPABILITY_OPTIONAL_ATTRIBUTE = "optional"; //$NON-NLS-1$
public static final String CAPABILITY_MULTIPLE_ATTRIBUTE = "multiple"; //$NON-NLS-1$
public static final String CAPABILITY_GREED_ATTRIBUTE = "greedy"; //$NON-NLS-1$
+
+ public static final String CAPABILITY_ATTRIBUTES_ELEMENT = "attributes"; //$NON-NLS-1$
+ public static final String CAPABILITY_ATTRIBUTE_ELEMENT = "attribute"; //$NON-NLS-1$
+ public static final String CAPABILITY_ATTRIBUTE_NAME_ATTRIBUTE = "name"; //$NON-NLS-1$
+ public static final String CAPABILITY_ATTRIBUTE_TYPE_ATTRIBUTE = "type"; //$NON-NLS-1$
+ public static final String CAPABILITY_ATTRIBUTE_VALUE_ATTRIBUTE = "value"; //$NON-NLS-1$
+ public static final String[] CAPABILITY_ATTRIBUTE_REQUIRED_ATTRIBUTES = new String[] {CAPABILITY_ATTRIBUTE_NAME_ATTRIBUTE, CAPABILITY_ATTRIBUTE_VALUE_ATTRIBUTE, CAPABILITY_ATTRIBUTE_TYPE_ATTRIBUTE};
+
public static final String[] REQIURED_CAPABILITY_ATTRIBUTES = new String[] {NAMESPACE_ATTRIBUTE, NAME_ATTRIBUTE, VERSION_RANGE_ATTRIBUTE};
public static final String[] REQIUREMENT_ATTRIBUTES = new String[] {MATCH_ATTRIBUTE};
public static final String[] OPTIONAL_CAPABILITY_ATTRIBUTES = new String[] {CAPABILITY_OPTIONAL_ATTRIBUTE, CAPABILITY_MULTIPLE_ATTRIBUTE, CAPABILITY_GREED_ATTRIBUTE};
diff --git a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java
index 4cf0fc352..925f082eb 100644
--- a/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java
+++ b/bundles/org.eclipse.equinox.p2.publisher.eclipse/src/org/eclipse/equinox/p2/publisher/eclipse/BundlesAction.java
@@ -317,6 +317,8 @@ public class BundlesAction extends AbstractPublisherAction {
reqsDeps.add(MetadataFactory.createRequirement(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, importSpec.getName(), versionRange, null, optional ? 0 : 1, 1, greedy));
}
+ // TODO Handle all attributes and directives somehow? Especially the "effective" directive.
+ // TODO Make these optional and greedy for backward compatibility?
protected void addGenericRequirement(List<IRequirement> reqsDeps, GenericSpecification requireCapSpec, ManifestElement[] rawRequiresPackageHeader) {
String ldap = requireCapSpec.getMatchingFilter();
ldap = "(&(namespace=" + requireCapSpec.getType() + ")" + ldap + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

Back to the top