aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1348661 - in /aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive: ExportPackageHeader.java GenericClause.java GenericHeader.java ImportPackageHeader.java
Date Sun, 10 Jun 2012 21:04:03 GMT
Author: jwross
Date: Sun Jun 10 21:04:03 2012
New Revision: 1348661

URL: http://svn.apache.org/viewvc?rev=1348661&view=rev
Log:
ARIES-825: Multiple changes.
(1) Fixed ClassCastException when import package header clause declares the version attribute.
(2) Now accepts all unknown headers as is with no syntax validation instead of failing the
installation.
(3) Fixed StackOverflowError caused by regex due to complex pattern combined with lengthy
export package headers.

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ExportPackageHeader.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericClause.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericHeader.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ExportPackageHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ExportPackageHeader.java?rev=1348661&r1=1348660&r2=1348661&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ExportPackageHeader.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ExportPackageHeader.java
Sun Jun 10 21:04:03 2012
@@ -146,14 +146,28 @@ public class ExportPackageHeader impleme
 	
 	public static final String NAME = Constants.EXPORT_PACKAGE;
 	
-	private static final Pattern PATTERN = Pattern.compile('(' + Grammar.EXPORT + ")(?=,|\\z)");
-	
 	private final Set<Clause> clauses = new HashSet<Clause>();
 	
 	public ExportPackageHeader(String value) {
-		Matcher matcher = PATTERN.matcher(value);
-		while (matcher.find())
-			clauses.add(new Clause(matcher.group()));
+		int numOfChars = value.length();
+		StringBuilder builder = new StringBuilder(numOfChars);
+		int numOfQuotes = 0;
+		for (char c : value.toCharArray()) {
+			numOfChars--;
+			if (c == ',') {
+				if (numOfQuotes % 2 == 0) {
+					clauses.add(new Clause(builder.toString()));
+					builder = new StringBuilder(numOfChars);
+				}
+				else
+					builder.append(c);
+			}
+			else if (c == '"')
+				numOfQuotes++;
+			else
+				builder.append(c);
+		}
+		clauses.add(new Clause(builder.toString()));
 		if (clauses.isEmpty())
 			throw new IllegalArgumentException("An " + NAME + " header must have at least one clause");
 	}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericClause.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericClause.java?rev=1348661&r1=1348660&r2=1348661&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericClause.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericClause.java
Sun Jun 10 21:04:03 2012
@@ -22,9 +22,6 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public class GenericClause implements Clause {
-	// TODO The introduction of the whitespace (\\s*) before a parameter was added to get around
a grammatically
-	// incorrect clause in Equinox: org.eclipse.osgi; singleton:=true;deployed-version=3.7.0.v20110221;type=osgi.bundle.
-	// Note the space before the singleton directive.
 	private static final String REGEX = '(' + Grammar.PATH + "(?:;" + Grammar.PATH + ")*)(?:;\\s*("
+ Grammar.PARAMETER + "))*";
 	
 	private static final Pattern PATTERN = Pattern.compile(REGEX);

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericHeader.java?rev=1348661&r1=1348660&r2=1348661&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericHeader.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/GenericHeader.java
Sun Jun 10 21:04:03 2012
@@ -13,8 +13,93 @@
  */
 package org.apache.aries.subsystem.core.archive;
 
-public class GenericHeader extends AbstractHeader {
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class GenericHeader implements Header<GenericHeader.Clause> {
+	public static class Clause implements org.apache.aries.subsystem.core.archive.Clause {
+		private final String path;
+		
+		public Clause(String clause) {
+			path = clause;
+		}
+		
+		public Attribute getAttribute(String name) {
+			return null;
+		}
+		
+		public Collection<Attribute> getAttributes() {
+			return Collections.emptyList();
+		}
+		
+		public Directive getDirective(String name) {
+			return null;
+		}
+		
+		public Collection<Directive> getDirectives() {
+			return Collections.emptyList();
+		}
+		
+		public Parameter getParameter(String name) {
+			return null;
+		}
+		
+		public Collection<Parameter> getParameters() {
+			return Collections.emptyList();
+		}
+		
+		public String getPath() {
+			return path;
+		}
+		
+		@Override
+		public String toString() {
+			StringBuilder builder = new StringBuilder()
+					.append(getPath());
+			for (Parameter parameter : getParameters()) {
+				builder.append(';').append(parameter);
+			}
+			return builder.toString();
+		}
+	}
+	
+	private final Set<Clause> clauses;
+	private final String name;
+	
+	public GenericHeader(String name, Collection<Clause> clauses) {
+		this.name = name;
+		this.clauses = new HashSet<Clause>(clauses);
+	}
+	
 	public GenericHeader(String name, String value) {
-		super(name, value);
+		this(name, Collections.singletonList(new Clause(value)));
+	}
+
+	@Override
+	public Collection<Clause> getClauses() {
+		return Collections.unmodifiableSet(clauses);
+	}
+
+	@Override
+	public String getName() {
+		return name;
+	}
+
+	@Override
+	public String getValue() {
+		return toString();
+	}
+	
+	@Override
+	public String toString() {
+		StringBuilder builder = new StringBuilder();
+		for (Clause clause : getClauses()) {
+			builder.append(clause).append(',');
+		}
+		// Remove the trailing comma. Note at least one clause is guaranteed to exist.
+		builder.deleteCharAt(builder.length() - 1);
+		return builder.toString();
 	}
 }

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java?rev=1348661&r1=1348660&r2=1348661&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java
Sun Jun 10 21:04:03 2012
@@ -79,6 +79,12 @@ public class ImportPackageHeader impleme
 			matcher.usePattern(PATTERN2);
 			while (matcher.find()) {
 				Parameter parameter = ParameterFactory.create(matcher.group());
+				// TODO Revisit the following fix.
+				// All version attributes on an ImportPackage header are ranges. The ParameterFactory
will return
+				// a VersionAttribute when the value is a single version (e.g., version=1.0.0). This
causes a
+				// ClassCastException in getVersionRangeAttribute().
+				if (parameter instanceof VersionAttribute)
+					parameter = new VersionRangeAttribute(String.valueOf(parameter.getValue()));
 				myParameters.put(parameter.getName(), parameter);
 			}
 			fillInDefaults(myParameters);



Mime
View raw message