Skip to content

Commit

Permalink
[ARQ-1780] Fix parsing of import-export packages in class AbstractOSG…
Browse files Browse the repository at this point in the history
…iApplicationArchiveProcessor
  • Loading branch information
Martin Basovnik authored and Thomas Diesler committed May 21, 2014
1 parent b2dce9e commit 3986a1e
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ private void enhanceApplicationArchive(Archive<?> appArchive, TestClass testClas
continue;

if (key.equals(Constants.IMPORT_PACKAGE)) {
String[] imports = value.split(",");
String[] imports = splitWithComma(value);
builder.addImportPackages(imports);
continue;
}

if (key.equals(Constants.EXPORT_PACKAGE)) {
String[] exports = value.split(",");
String[] exports = splitWithComma(value);
builder.addExportPackages(exports);
continue;
}
Expand Down Expand Up @@ -160,4 +160,24 @@ private Manifest getBundleManifest(Archive<?> archive) {
}
}

private static String[] splitWithComma(String value) {
// Header clauses are split with comma but comma can also appear in version parameter or in a custom parameter for "Attribute Matching"
// e.g. Import-Package: org.jboss.arquillian.junit;version="[X.0.0,Y.0.0)";extra="A,B",...

// After each comma must be even number of double-quotes
return value.split(
"(?x) " + // Free-Spacing Mode
", " + // Split with comma
"(?= " + // Followed by
" (?: " + // Start a non-capture group
" [^\"]* " + // 0 or more non-quote characters
" \" " + // 1 quote
" [^\"]* " + // 0 or more non-quote characters
" \" " + // 1 quote
" )* " + // 0 or more repetition of non-capture group (multiple of 2 quotes will be even)
" [^\"]* " + // Finally 0 or more non-quotes
" $ " + // Till the end (This is necessary, else every comma will satisfy the condition)
") " // End look-ahead
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.test.arquillian.container.osgi;

import static org.junit.Assert.assertTrue;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jboss.arquillian.container.osgi.AbstractOSGiApplicationArchiveProcessor;
import org.junit.Test;

/**
* Test {@link AbstractOSGiApplicationArchiveProcessor}
*
* @author mbasovni@redhat.com
* @since 19-May-2014
*/
public class AbstractOSGiApplicationArchiveProcessorTestCase {

@Test
public void splitWithComma() throws Exception {
Map<String, List<String>> map = new HashMap<String, List<String>>();
map.put(
"org.jboss.arquillian.junit",
Arrays.asList("org.jboss.arquillian.junit")
);
map.put(
"org.jboss.arquillian.junit,org.junit.runner,org.osgi.framework",
Arrays.asList("org.jboss.arquillian.junit", "org.junit.runner", "org.osgi.framework")
);
map.put(
"org.junit.runner;version=\"[0.0.0,5.0.0)\"",
Arrays.asList("org.junit.runner;version=\"[0.0.0,5.0.0)\"")
);
map.put(
"org.junit.runner;version=\"[0.0.0,5.0.0)\",org.jboss.arquillian.junit",
Arrays.asList("org.junit.runner;version=\"[0.0.0,5.0.0)\"", "org.jboss.arquillian.junit")
);
map.put(
"org.jboss.arquillian.junit;version=\"[0.0.0,3.0.0)\",org.junit.runner;version=\"[0.0.0,5.0.0)\"",
Arrays.asList("org.jboss.arquillian.junit;version=\"[0.0.0,3.0.0)\"", "org.junit.runner;version=\"[0.0.0,5.0.0)\"")
);
map.put(
"org.jboss.arquillian.junit;version=\"[0.0.0,3.0.0)\";extra=\"A,B\"",
Arrays.asList("org.jboss.arquillian.junit;version=\"[0.0.0,3.0.0)\";extra=\"A,B\"")
);
map.put(
"org.jboss.arquillian.junit;extra=\"A,B,C\",org.osgi.framework;version=\"[1.0.0,2.0.0)\"",
Arrays.asList("org.jboss.arquillian.junit;extra=\"A,B,C\"", "org.osgi.framework;version=\"[1.0.0,2.0.0)\"")
);
for (Map.Entry<String,List<String>> entry : map.entrySet()) {
assertTrue("Packages are not split correctly", splitWithComma(entry.getKey()).equals(entry.getValue()));
}
}

private static List<String> splitWithComma(String value) throws Exception{
Method method = AbstractOSGiApplicationArchiveProcessor.class.getDeclaredMethod("splitWithComma", String.class);
method.setAccessible(true);
return Arrays.asList((String [])method.invoke(null, value));
}
}

0 comments on commit 3986a1e

Please sign in to comment.