Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodor Boev2018-01-03 17:48:52 +0000
committerAlexander Kurtakov2018-01-16 18:56:02 +0000
commita7a99e1fa49938a8f62d44d5c443d38981afeace (patch)
tree8d9152f0908a5030f2a93a818d6bb0b07facb946 /bundles/org.eclipse.equinox.p2.repository/src/org/eclipse
parentf539d2ad9b77c9a9f03b9f4cdad08c5847dc8025 (diff)
downloadrt.equinox.p2-a7a99e1fa49938a8f62d44d5c443d38981afeace.tar.gz
rt.equinox.p2-a7a99e1fa49938a8f62d44d5c443d38981afeace.tar.xz
rt.equinox.p2-a7a99e1fa49938a8f62d44d5c443d38981afeace.zip
Bug 528387 - Dedicated xml elements for generic requirementsI20180119-0110I20180118-2000I20180117-2000
- Renamed IProvidedCapability.getAttributes() to getProperties(). This is in sync with other parts of p2 that use "properties" for such data. E.g. the IU properties. - Extended content.xml read/write with a new serialization format for requirements with the "requiredProperties" element. It is used to build an IRequirement that has a standard match expression that applies an LDAP filter to the capability properties. It was not possible to extend the existing "required" element in a way that will make old p2 builds ignore the extended version. - Extended the content.xml read/write shared properties handling logic with "type" attribute. Older p2 builds will ignore it and use strings. Also the "type" attribute only appears in the "properties" extension of "provides" which will be ignored by old p2 builds to begin with. - Some additional cleanup to the content.xml read/write - Increased the current content.xml format version from 1.1.0 to 1.2.0. Old p2 builds declare compatibility with [1.0.0, 2). - Made the handling of the property types supported by a capability safer. E.g. unknown types are converted to Strings. E.g. ProvidedCapability verifies that only supported types are used. - Made the handling of generic requirements reflect the real semantics. E.g. with correct handling of the resolution:=optional|mandatory flag rather than to declare everything optional to avoid breakages in older p2 builds. This is possible because the "requiredProperties" element is completely ignored by older builds. E.g. now if an extender or service is missing provisioning will fail as it is supposed to. - Added factory methods to MetadataFactory for LDAP based requirements. - Added a planner test for LDAP requirements - Cleaned up the AutomatedDirectorTest - Cleaned up some LDAP matching test cases. Change-Id: Ifff77b3ea4c9cea33fd236ed101b1f33c173891d Signed-off-by: Todor Boev <rinsvind@gmail.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository/src/org/eclipse')
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLConstants.java16
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java82
2 files changed, 84 insertions, 14 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLConstants.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLConstants.java
index f1af9f142..de1601d90 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLConstants.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLConstants.java
@@ -11,6 +11,9 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.persistence;
+import java.util.List;
+import org.eclipse.equinox.p2.metadata.Version;
+
public interface XMLConstants {
// Constants used in defining a default processing instruction
@@ -29,7 +32,20 @@ public interface XMLConstants {
public static final String PROPERTY_ELEMENT = "property"; //$NON-NLS-1$
public static final String PROPERTY_NAME_ATTRIBUTE = "name"; //$NON-NLS-1$
public static final String PROPERTY_VALUE_ATTRIBUTE = "value"; //$NON-NLS-1$
+ public static final String PROPERTY_TYPE_ATTRIBUTE = "type"; //$NON-NLS-1$
public static final String[] PROPERTY_ATTRIBUTES = new String[] {PROPERTY_NAME_ATTRIBUTE, PROPERTY_VALUE_ATTRIBUTE};
+ public static final String[] PROPERTY_OPTIONAL_ATTRIBUTES = new String[] {PROPERTY_TYPE_ATTRIBUTE};
+ public static final String PROPERTY_TYPE_LIST = List.class.getSimpleName();
+ public static final String PROPERTY_TYPE_STRING = String.class.getSimpleName();
+ public static final String PROPERTY_TYPE_INTEGER = Integer.class.getSimpleName();
+ public static final String PROPERTY_TYPE_LONG = Long.class.getSimpleName();
+ public static final String PROPERTY_TYPE_FLOAT = Float.class.getSimpleName();
+ public static final String PROPERTY_TYPE_DOUBLE = Double.class.getSimpleName();
+ public static final String PROPERTY_TYPE_BYTE = Byte.class.getSimpleName();
+ public static final String PROPERTY_TYPE_SHORT = Short.class.getSimpleName();
+ public static final String PROPERTY_TYPE_CHARACTER = Character.class.getSimpleName();
+ public static final String PROPERTY_TYPE_BOOLEAN = Boolean.class.getSimpleName();
+ public static final String PROPERTY_TYPE_VERSION = Version.class.getSimpleName();
// Constants for the names of common general attributes
public static final String ID_ATTRIBUTE = "id"; //$NON-NLS-1$
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java
index 6973a2f06..3a532f6ad 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/persistence/XMLWriter.java
@@ -10,11 +10,11 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.persistence;
+import static java.util.stream.Collectors.joining;
+
import java.io.*;
import java.nio.charset.StandardCharsets;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Stack;
+import java.util.*;
import org.eclipse.equinox.p2.metadata.Version;
public class XMLWriter implements XMLConstants {
@@ -220,28 +220,82 @@ public class XMLWriter implements XMLConstants {
this.pw.flush();
}
- public void writeProperties(Map<String, String> properties) {
+ public void writeProperties(Map<String, ?> properties) {
writeProperties(PROPERTIES_ELEMENT, properties);
}
- public void writeProperties(String propertiesElement, Map<String, String> properties) {
- if (properties != null && properties.size() > 0) {
- start(propertiesElement);
- attribute(COLLECTION_SIZE_ATTRIBUTE, properties.size());
- for (Entry<String, String> entry : properties.entrySet()) {
- writeProperty(entry.getKey(), entry.getValue());
- }
- end(propertiesElement);
+ public void writeProperties(String propertiesElement, Map<String, ?> properties) {
+ if (properties == null || properties.isEmpty()) {
+ return;
}
+
+ start(propertiesElement);
+ attribute(COLLECTION_SIZE_ATTRIBUTE, properties.size());
+ properties.forEach(this::writeProperty);
+ end();
}
- public void writeProperty(String name, String value) {
+ public void writeProperty(String name, Object value) {
+ String type;
+ String valueStr;
+
+ if (Collection.class.isAssignableFrom(value.getClass())) {
+ Collection<?> coll = (Collection<?>) value;
+
+ type = PROPERTY_TYPE_LIST;
+ String elType = resolvePropertyType(coll.iterator().next());
+ if (elType != null) {
+ type += String.format("<%s>", elType); //$NON-NLS-1$
+ }
+
+ valueStr = coll.stream().map(Object::toString).collect(joining(",")); //$NON-NLS-1$
+ } else {
+ type = resolvePropertyType(value);
+ valueStr = value.toString();
+ }
+
start(PROPERTY_ELEMENT);
attribute(PROPERTY_NAME_ATTRIBUTE, name);
- attribute(PROPERTY_VALUE_ATTRIBUTE, value);
+ attribute(PROPERTY_VALUE_ATTRIBUTE, valueStr);
+ attributeOptional(PROPERTY_TYPE_ATTRIBUTE, type);
end();
}
+ private String resolvePropertyType(Object value) {
+ if (value instanceof Integer) {
+ return PROPERTY_TYPE_INTEGER;
+ }
+ if (value instanceof Long) {
+ return PROPERTY_TYPE_LONG;
+ }
+ if (value instanceof Float) {
+ return PROPERTY_TYPE_FLOAT;
+ }
+ if (value instanceof Double) {
+ return PROPERTY_TYPE_DOUBLE;
+ }
+ if (value instanceof Byte) {
+ return PROPERTY_TYPE_BYTE;
+ }
+ if (value instanceof Short) {
+ return PROPERTY_TYPE_SHORT;
+ }
+ if (value instanceof Character) {
+ return PROPERTY_TYPE_CHARACTER;
+ }
+ if (value instanceof Boolean) {
+ return PROPERTY_TYPE_BOOLEAN;
+ }
+ if (value instanceof Version) {
+ return PROPERTY_TYPE_VERSION;
+ }
+
+ // Null is read back as String
+ // NOTE: Using string as default is needed for backward compatibility with properties that are always String like
+ // the IU properties
+ return null;
+ }
+
protected static String attributeImage(String name, String value) {
if (value == null) {
return ""; // optional attribute with no value //$NON-NLS-1$

Back to the top