You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2016/08/26 14:13:32 UTC

svn commit: r1757858 - in /openwebbeans/trunk: ./ webbeans-gradle/ webbeans-gradle/src/ webbeans-gradle/src/main/ webbeans-gradle/src/main/java/ webbeans-gradle/src/main/java/org/ webbeans-gradle/src/main/java/org/apache/ webbeans-gradle/src/main/java/...

Author: rmannibucau
Date: Fri Aug 26 14:13:31 2016
New Revision: 1757858

URL: http://svn.apache.org/viewvc?rev=1757858&view=rev
Log:
OWB-1142 OWB-1141  OWB gradle and maven fatjar integration

Added:
    openwebbeans/trunk/webbeans-gradle/
    openwebbeans/trunk/webbeans-gradle/pom.xml
    openwebbeans/trunk/webbeans-gradle/src/
    openwebbeans/trunk/webbeans-gradle/src/main/
    openwebbeans/trunk/webbeans-gradle/src/main/java/
    openwebbeans/trunk/webbeans-gradle/src/main/java/org/
    openwebbeans/trunk/webbeans-gradle/src/main/java/org/apache/
    openwebbeans/trunk/webbeans-gradle/src/main/java/org/apache/openwebbeans/
    openwebbeans/trunk/webbeans-gradle/src/main/java/org/apache/openwebbeans/gradle/
    openwebbeans/trunk/webbeans-gradle/src/main/java/org/apache/openwebbeans/gradle/shadow/
    openwebbeans/trunk/webbeans-gradle/src/main/java/org/apache/openwebbeans/gradle/shadow/OpenWebBeansPropertiesTransformer.java
    openwebbeans/trunk/webbeans-maven/
    openwebbeans/trunk/webbeans-maven/pom.xml
    openwebbeans/trunk/webbeans-maven/src/
    openwebbeans/trunk/webbeans-maven/src/main/
    openwebbeans/trunk/webbeans-maven/src/main/java/
    openwebbeans/trunk/webbeans-maven/src/main/java/org/
    openwebbeans/trunk/webbeans-maven/src/main/java/org/apache/
    openwebbeans/trunk/webbeans-maven/src/main/java/org/apache/openwebbeans/
    openwebbeans/trunk/webbeans-maven/src/main/java/org/apache/openwebbeans/maven/
    openwebbeans/trunk/webbeans-maven/src/main/java/org/apache/openwebbeans/maven/shade/
    openwebbeans/trunk/webbeans-maven/src/main/java/org/apache/openwebbeans/maven/shade/OpenWebBeansPropertiesTransformer.java
Modified:
    openwebbeans/trunk/pom.xml

Modified: openwebbeans/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/pom.xml?rev=1757858&r1=1757857&r2=1757858&view=diff
==============================================================================
--- openwebbeans/trunk/pom.xml (original)
+++ openwebbeans/trunk/pom.xml Fri Aug 26 14:13:31 2016
@@ -503,6 +503,8 @@
         <module>webbeans-tck</module>
         <module>distribution</module>
         <module>webbeans-doc</module>
+        <module>webbeans-maven</module>
+        <module>webbeans-gradle</module>
     </modules>
 
     <dependencyManagement>

Added: openwebbeans/trunk/webbeans-gradle/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-gradle/pom.xml?rev=1757858&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-gradle/pom.xml (added)
+++ openwebbeans/trunk/webbeans-gradle/pom.xml Fri Aug 26 14:13:31 2016
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>openwebbeans</artifactId>
+    <groupId>org.apache.openwebbeans</groupId>
+    <version>1.6.4-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>openwebbeans-gradle</artifactId>
+  <name>Gradle ShadowJar Plugin Integration</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.gradle</groupId>
+      <artifactId>gradle-core</artifactId>
+      <version>3.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.github.jengelman.gradle.plugins</groupId>
+      <artifactId>shadow</artifactId>
+      <version>1.2.3</version>
+      <scope>provided</scope>
+    </dependency>
+    <!-- no openwebbeans-impl there please to not pollute gradle buildscript classpath -->
+  </dependencies>
+
+  <repositories>
+    <repository>
+      <id>jcenter</id>
+      <url>http://jcenter.bintray.com</url>
+    </repository>
+  </repositories>
+</project>

Added: openwebbeans/trunk/webbeans-gradle/src/main/java/org/apache/openwebbeans/gradle/shadow/OpenWebBeansPropertiesTransformer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-gradle/src/main/java/org/apache/openwebbeans/gradle/shadow/OpenWebBeansPropertiesTransformer.java?rev=1757858&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-gradle/src/main/java/org/apache/openwebbeans/gradle/shadow/OpenWebBeansPropertiesTransformer.java (added)
+++ openwebbeans/trunk/webbeans-gradle/src/main/java/org/apache/openwebbeans/gradle/shadow/OpenWebBeansPropertiesTransformer.java Fri Aug 26 14:13:31 2016
@@ -0,0 +1,124 @@
+/*
+ * 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.openwebbeans.gradle.shadow;
+
+import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator;
+import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer;
+import org.apache.tools.zip.ZipOutputStream;
+import org.gradle.api.file.FileTreeElement;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+// note: it is very important to not bring webbeans-impl in the classpath there cause of gradle dep mecanism
+public class OpenWebBeansPropertiesTransformer implements Transformer
+{
+    private static final String CONFIGURATION_ORDINAL_PROPERTY_NAME = "configuration.ordinal";
+    private static final int CONFIGURATION_ORDINAL_DEFAULT_VALUE = 100;
+
+    private final List<Properties> configurations = new ArrayList<Properties>();
+
+    @Override
+    public boolean canTransformResource(final FileTreeElement s)
+    {
+        return "META-INF/openwebbeans/openwebbeans.properties".equals(s.getPath())
+                || "/META-INF/openwebbeans/openwebbeans.properties".equals(s.getPath());
+    }
+
+    @Override
+    public void transform(String s, InputStream inputStream, List<Relocator> list)
+    {
+        final Properties p = new Properties();
+        try
+        {
+            p.load(inputStream);
+        }
+        catch (final IOException e)
+        {
+            throw new IllegalStateException(e);
+        }
+        configurations.add(p);
+    }
+
+    @Override
+    public boolean hasTransformedResource()
+    {
+        return !configurations.isEmpty();
+    }
+
+    @Override
+    public void modifyOutputStream(final ZipOutputStream zipOutputStream)
+    {
+        final Properties out = mergeProperties(sortProperties(configurations));
+        try
+        {
+            zipOutputStream.putNextEntry(new org.apache.tools.zip.ZipEntry("META-INF/openwebbeans/openwebbeans.properties"));
+            out.store(zipOutputStream, "# gradle openwebbeans.properties merge");
+            zipOutputStream.closeEntry();
+        }
+        catch (final IOException ioe)
+        {
+            throw new IllegalStateException(ioe);
+        }
+    }
+
+    private static List<Properties> sortProperties(final List<Properties> allProperties)
+    {
+        final List<Properties> sortedProperties = new ArrayList<Properties>();
+        for (final Properties p : allProperties)
+        {
+            final int configOrder = getConfigurationOrdinal(p);
+
+            int i;
+            for (i = 0; i < sortedProperties.size(); i++)
+            {
+                final int listConfigOrder = getConfigurationOrdinal(sortedProperties.get(i));
+                if (listConfigOrder > configOrder)
+                {
+                    break;
+                }
+            }
+            sortedProperties.add(i, p);
+        }
+        return sortedProperties;
+    }
+
+    private static int getConfigurationOrdinal(final Properties p)
+    {
+        final String configOrderString = p.getProperty(CONFIGURATION_ORDINAL_PROPERTY_NAME);
+        if (configOrderString != null && configOrderString.length() > 0)
+        {
+            return Integer.parseInt(configOrderString);
+        }
+        return CONFIGURATION_ORDINAL_DEFAULT_VALUE;
+    }
+
+    private static Properties mergeProperties(final List<Properties> sortedProperties)
+    {
+        final Properties mergedProperties = new Properties();
+        for (final Properties p : sortedProperties)
+        {
+            mergedProperties.putAll(p);
+        }
+        return mergedProperties;
+    }
+}

Added: openwebbeans/trunk/webbeans-maven/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-maven/pom.xml?rev=1757858&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-maven/pom.xml (added)
+++ openwebbeans/trunk/webbeans-maven/pom.xml Fri Aug 26 14:13:31 2016
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>openwebbeans</artifactId>
+    <groupId>org.apache.openwebbeans</groupId>
+    <version>1.6.4-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>openwebbeans-maven</artifactId>
+  <name>Maven Shade Plugin Integration</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-shade-plugin</artifactId>
+      <version>2.4.3</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+</project>

Added: openwebbeans/trunk/webbeans-maven/src/main/java/org/apache/openwebbeans/maven/shade/OpenWebBeansPropertiesTransformer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-maven/src/main/java/org/apache/openwebbeans/maven/shade/OpenWebBeansPropertiesTransformer.java?rev=1757858&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-maven/src/main/java/org/apache/openwebbeans/maven/shade/OpenWebBeansPropertiesTransformer.java (added)
+++ openwebbeans/trunk/webbeans-maven/src/main/java/org/apache/openwebbeans/maven/shade/OpenWebBeansPropertiesTransformer.java Fri Aug 26 14:13:31 2016
@@ -0,0 +1,109 @@
+/*
+ * 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.openwebbeans.maven.shade;
+
+import org.apache.maven.plugins.shade.relocation.Relocator;
+import org.apache.maven.plugins.shade.resource.ResourceTransformer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarOutputStream;
+import java.util.zip.ZipEntry;
+
+public class OpenWebBeansPropertiesTransformer implements ResourceTransformer
+{
+    private static final String CONFIGURATION_ORDINAL_PROPERTY_NAME = "configuration.ordinal";
+    private static final int CONFIGURATION_ORDINAL_DEFAULT_VALUE = 100;
+
+    private final List<Properties> configurations = new ArrayList<Properties>();
+
+    @Override
+    public boolean canTransformResource(final String s)
+    {
+        return "META-INF/openwebbeans/openwebbeans.properties".equals(s) || "/META-INF/openwebbeans/openwebbeans.properties".equals(s);
+    }
+
+    @Override
+    public void processResource(final String s, final InputStream inputStream, final List<Relocator> list) throws IOException
+    {
+        final Properties p = new Properties();
+        p.load(inputStream);
+        configurations.add(p);
+    }
+
+    @Override
+    public boolean hasTransformedResource()
+    {
+        return !configurations.isEmpty();
+    }
+
+    @Override
+    public void modifyOutputStream(final JarOutputStream jarOutputStream) throws IOException
+    {
+        final Properties out = mergeProperties(sortProperties(configurations));
+        jarOutputStream.putNextEntry(new ZipEntry("META-INF/openwebbeans/openwebbeans.properties"));
+        out.store(jarOutputStream, "# gradle openwebbeans.properties merge");
+        jarOutputStream.closeEntry();
+    }
+
+    private static List<Properties> sortProperties(List<Properties> allProperties)
+    {
+        final List<Properties> sortedProperties = new ArrayList<Properties>();
+        for (final Properties p : allProperties)
+        {
+            final int configOrder = getConfigurationOrdinal(p);
+
+            int i;
+            for (i = 0; i < sortedProperties.size(); i++)
+            {
+                final int listConfigOrder = getConfigurationOrdinal(sortedProperties.get(i));
+                if (listConfigOrder > configOrder)
+                {
+                    break;
+                }
+            }
+            sortedProperties.add(i, p);
+        }
+        return sortedProperties;
+    }
+
+    private static int getConfigurationOrdinal(final Properties p)
+    {
+        final String configOrderString = p.getProperty(CONFIGURATION_ORDINAL_PROPERTY_NAME);
+        if (configOrderString != null && configOrderString.length() > 0)
+        {
+            return Integer.parseInt(configOrderString);
+        }
+        return CONFIGURATION_ORDINAL_DEFAULT_VALUE;
+    }
+
+    private static Properties mergeProperties(final List<Properties> sortedProperties)
+    {
+        final Properties mergedProperties = new Properties();
+        for (final Properties p : sortedProperties)
+        {
+            mergedProperties.putAll(p);
+        }
+
+        return mergedProperties;
+    }
+}