You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2018/04/18 09:36:05 UTC
[sling-whiteboard] branch master updated: Remove dependency to
commons.osgi
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new 0e81e6a Remove dependency to commons.osgi
0e81e6a is described below
commit 0e81e6aae1d400f227635e501c6c770b02204288
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Apr 18 11:35:56 2018 +0200
Remove dependency to commons.osgi
---
featuremodel/feature-support/pom.xml | 6 ---
.../sling/feature/support/util/ManifestUtil.java | 38 ++++++++++---------
.../feature/support/util/ManifestUtilTest.java | 43 ++++++++++++++++++++++
3 files changed, 63 insertions(+), 24 deletions(-)
diff --git a/featuremodel/feature-support/pom.xml b/featuremodel/feature-support/pom.xml
index 35cc179..5c9247b 100644
--- a/featuremodel/feature-support/pom.xml
+++ b/featuremodel/feature-support/pom.xml
@@ -81,12 +81,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.4.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.converter</artifactId>
<version>0.1.0-SNAPSHOT</version>
diff --git a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/ManifestUtil.java b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/ManifestUtil.java
index cacc4c3..c453fa0 100644
--- a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/ManifestUtil.java
+++ b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/util/ManifestUtil.java
@@ -16,12 +16,6 @@
*/
package org.apache.sling.feature.support.util;
-import org.apache.sling.commons.osgi.ManifestHeader;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Version;
-import org.osgi.resource.Capability;
-import org.osgi.resource.Requirement;
-
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -34,9 +28,11 @@ import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
-import static org.apache.sling.feature.support.util.ManifestParser.convertProvideCapabilities;
-import static org.apache.sling.feature.support.util.ManifestParser.normalizeCapabilityClauses;
-import static org.apache.sling.feature.support.util.ManifestParser.parseStandardHeader;
+import org.apache.sling.feature.support.util.ManifestParser.ParsedHeaderClause;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
public class ManifestUtil {
@@ -57,23 +53,29 @@ public class ManifestUtil {
final boolean checkOptional) {
final String pckInfo = m.getMainAttributes().getValue(headerName);
if (pckInfo != null) {
- final ManifestHeader header = ManifestHeader.parse(pckInfo);
+ final List<ParsedHeaderClause> clauses = ManifestParser.parseStandardHeader(pckInfo);
final List<PackageInfo> pcks = new ArrayList<>();
- for(final ManifestHeader.Entry entry : header.getEntries()) {
- String version = entry.getAttributeValue("version");
- if ( version == null ) {
+ for(final ParsedHeaderClause entry : clauses) {
+ Object versionObj = entry.m_attrs.get("version");
+ final String version;
+ if ( versionObj == null ) {
version = defaultVersion;
+ } else {
+ version = versionObj.toString();
}
+
boolean optional = false;
if ( checkOptional ) {
- final String resolution = entry.getDirectiveValue("resolution");
+ final String resolution = entry.m_dirs.get("resolution");
optional = "optional".equalsIgnoreCase(resolution);
}
- final PackageInfo pck = new PackageInfo(entry.getValue(),
+ for(final String path : entry.m_paths) {
+ final PackageInfo pck = new PackageInfo(path,
version,
optional);
- pcks.add(pck);
+ pcks.add(pck);
+ }
}
return pcks;
@@ -111,8 +113,8 @@ public class ManifestUtil {
private static <T> void unmarshal(String header, Function<Capability, Map<String, T>> lookup, BiConsumer<String, T> sink) throws IOException {
try {
- convertProvideCapabilities(
- normalizeCapabilityClauses(parseStandardHeader("foo;" + header), "2"))
+ ManifestParser.convertProvideCapabilities(
+ ManifestParser.normalizeCapabilityClauses(ManifestParser.parseStandardHeader("foo;" + header), "2"))
.forEach(capability -> lookup.apply(capability).forEach(sink));
} catch (Exception e) {
throw new IOException(e);
diff --git a/featuremodel/feature-support/src/test/java/org/apache/sling/feature/support/util/ManifestUtilTest.java b/featuremodel/feature-support/src/test/java/org/apache/sling/feature/support/util/ManifestUtilTest.java
new file mode 100644
index 0000000..ea62869
--- /dev/null
+++ b/featuremodel/feature-support/src/test/java/org/apache/sling/feature/support/util/ManifestUtilTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.sling.feature.support.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+import java.util.jar.Manifest;
+
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+public class ManifestUtilTest {
+
+ private void assertPackageInfo(final String name, final Version version, final PackageInfo info) {
+ assertEquals(name, info.getName());
+ assertEquals(version, info.getPackageVersion());
+ }
+
+ @Test public void testExportPackage() throws Exception {
+ final Manifest mf = new Manifest();
+ mf.getMainAttributes().putValue(Constants.EXPORT_PACKAGE, "org.apache.sling;version=1.0,org.apache.felix;version=2.0");
+ final List<PackageInfo> infos = ManifestUtil.extractExportedPackages(mf);
+ assertEquals(2, infos.size());
+ assertPackageInfo("org.apache.sling", Version.parseVersion("1.0"), infos.get(0));
+ assertPackageInfo("org.apache.felix", Version.parseVersion("2.0"), infos.get(1));
+ }
+}
--
To stop receiving notification emails like this one, please contact
cziegeler@apache.org.