You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by si...@apache.org on 2019/05/10 14:34:07 UTC

[sling-slingfeature-maven-plugin] 01/02: SLING-8412 - APIs jar MOJO includes wrapped classes which are not OSGi exported and potentially override public APIs

This is an automated email from the ASF dual-hosted git repository.

simonetripodi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git

commit 9e6c7017414e7af05e3977f30aef82bb4e7d2f61
Author: stripodi <st...@simos-mbp>
AuthorDate: Fri May 10 16:31:34 2019 +0200

    SLING-8412 - APIs jar MOJO includes wrapped classes which are not OSGi
    exported and potentially override public APIs
    
    added integration test
---
 .../invoker.properties                             | 17 +++++
 src/it/apis-jar-wrapped-flattened-classes/pom.xml  | 53 +++++++++++++
 .../src/main/features/main.json                    | 21 ++++++
 .../apis-jar-wrapped-flattened-classes/verify.bsh  | 88 ++++++++++++++++++++++
 4 files changed, 179 insertions(+)

diff --git a/src/it/apis-jar-wrapped-flattened-classes/invoker.properties b/src/it/apis-jar-wrapped-flattened-classes/invoker.properties
new file mode 100644
index 0000000..91f59c8
--- /dev/null
+++ b/src/it/apis-jar-wrapped-flattened-classes/invoker.properties
@@ -0,0 +1,17 @@
+# 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.
+
+invoker.goals = clean org.apache.sling:slingfeature-maven-plugin:apis-jar
+invoker.debug = true
diff --git a/src/it/apis-jar-wrapped-flattened-classes/pom.xml b/src/it/apis-jar-wrapped-flattened-classes/pom.xml
new file mode 100644
index 0000000..1ecf87e
--- /dev/null
+++ b/src/it/apis-jar-wrapped-flattened-classes/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.sling</groupId>
+  <artifactId>slingfeature-maven-plugin-test</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0.0-SNAPSHOT</version>
+
+  <name>Apache Sling Features Maven plugin test</name>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>@project.groupId@</groupId>
+        <artifactId>@project.artifactId@</artifactId>
+        <version>@project.version@</version>
+        <extensions>true</extensions>
+        <executions>
+          <execution>
+            <id>analyze</id>
+            <phase>package</phase>
+            <goals>
+              <goal>apis-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <selection>
+            <filesInclude>**/*.json</filesInclude>
+          </selection>
+          <includeResources>
+            <includeResource>*.cnd</includeResource>
+            <includeResource>*.tld</includeResource>
+          </includeResources>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/apis-jar-wrapped-flattened-classes/src/main/features/main.json b/src/it/apis-jar-wrapped-flattened-classes/src/main/features/main.json
new file mode 100644
index 0000000..1590cff
--- /dev/null
+++ b/src/it/apis-jar-wrapped-flattened-classes/src/main/features/main.json
@@ -0,0 +1,21 @@
+{
+  "id":"org.apache.sling:slingfeature-maven-plugin-test:1.0.0-SNAPSHOT",
+  "bundles":[
+    {
+      "id":"org.apache.jackrabbit:oak-lucene:1.10.2",
+      "start-level":"4"
+    },
+    {
+      "id":"org.apache.jackrabbit:oak-solr-osgi:1.10.2",
+      "start-level":"5"
+    }
+  ],
+  "api-regions:JSON|false": [
+    {
+      "name": "base",
+      "exports": [
+        "org.apache.lucene.analysis.standard"
+      ]
+    }
+  ]
+}
diff --git a/src/it/apis-jar-wrapped-flattened-classes/verify.bsh b/src/it/apis-jar-wrapped-flattened-classes/verify.bsh
new file mode 100644
index 0000000..a94a0cd
--- /dev/null
+++ b/src/it/apis-jar-wrapped-flattened-classes/verify.bsh
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+
+import org.codehaus.plexus.util.*;
+
+    boolean check() throws Exception {
+        File apisJarDir = new File(basedir, "target/apis-jars");
+
+        // base
+
+        File baseApiJar = new File(apisJarDir, "slingfeature-maven-plugin-test-1.0.0-SNAPSHOT-base-apis.jar");
+        if (!baseApiJar.exists()) {
+            System.out.println("FAILED!");
+            System.out.println("File '" + file + "' not found");
+            return false;
+        }
+
+        InputStream bytecodeStream = null;
+        JarFile jarFile = null;
+        try {
+            jarFile = new JarFile(baseApiJar);
+            Manifest manifest= jarFile.getManifest();
+            String exportPackageHeader = manifest.getMainAttributes().getValue("Export-Package");
+
+            if (exportPackageHeader.indexOf("org.apache.lucene.analysis.standard") < 0) {
+                System.out.println("FAILED!");
+                System.out.println("Export-Package header '" + exportPackageHeader + "' does not contain 'org.apache.lucene.analysis.standard' in bundle " + file);
+                return false;
+            }
+
+            JarEntry jarEntry = jarFile.getJarEntry("org/apache/lucene/analysis/standard/StandardAnalyzer.class");
+            if (jarEntry == null) {
+                System.out.println("FAILED!");
+                System.out.println("Entry 'org/apache/lucene/analysis/standard/StandardAnalyzer.class' does not exist in bundle " + file);
+            }
+
+            bytecodeStream = jarFile.getInputStream(jarEntry);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            byte[] buf = new byte[1024];
+            int len = 0;
+            while ((len = bytecodeStream.read(buf)) >= 0) {
+                baos.write(buf, 0, len);
+            }
+
+            if (!baos.toString().contains("#(Lorg/apache/lucene/util/Version;)V")) {
+                System.out.println("FAILED!");
+                System.out.println("Expected org.apache.lucene.analysis.standard.StandardAnalyzer class containing a constructor with 'org.apache.lucene.util.Version' argument");
+                return false;
+            }
+        } finally {
+            if (jarFile != null) {
+                jarFile.close();
+            }
+
+            if (bytecodeStream != null) {
+                bytecodeStream.close();
+            }
+        }
+
+        return true;
+    }
+
+    try {
+        return check();
+    } catch(Throwable t) {
+        t.printStackTrace();
+        return false;
+    }
+
+    return true;