openwebbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: Meecrowave and gradle
Date Thu, 06 Jun 2019 12:25:43 GMT
Awesome, very useful!
Thanks a lot for sharing!

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>


Le jeu. 6 juin 2019 à 12:09, Helge Waastad <helge@waastad.org> a écrit :

> Hi, I think I have working copy.
>
> Any comments are welcome.
> A bit unsure of the dep exclusions...
>
> build.gradle
> ---
>
> import com.github.jengelman.gradle.plugins.shadow.transformers.AppendingTransformer
> import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
> import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
> import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
> import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer
> import shadow.org.apache.tools.zip.ZipEntry
> import shadow.org.apache.tools.zip.ZipOutputStream
>
> class OpenWebBeansPropertiesTransformer implements Transformer {
>     String resource
>     private final List<Properties> configurations = new ArrayList<>()
>     private String ordinalKey = "configuration.ordinal"
>     private int defaultOrdinal = 100
>     private boolean reverseOrder
>
>     @Override
>     boolean canTransformResource(FileTreeElement element) {
>         def path = element.relativePath.pathString
>         if (resource != null && resource.equalsIgnoreCase(path)) {
>             return true
>         }
>
>         return false
>     }
>
>     @Override
>     void transform(TransformerContext context) {
>         Properties p = new Properties()
>         p.load(context.is)
>         configurations.add(p);
>     }
>
>     @Override
>     boolean hasTransformedResource() {
>         return !configurations.isEmpty()
>     }
>
>     void modifyOutputStream(ZipOutputStream jos, boolean preserveFileTimestamps) {
>         Properties out = mergeProperties(sortProperties(configurations))
>         jos.putNextEntry(new ZipEntry(resource))
>         out.store(jos, "# maven " + resource + " merge")
>         jos.closeEntry()
>     }
>
>     private List<Properties> sortProperties(List<Properties> allProperties)
{
>         List<Properties> sortedProperties = new ArrayList<>()
>         for (Properties p : allProperties) {
>             int configOrder = getConfigurationOrdinal(p)
>
>             int i;
>             for (i = 0; i < sortedProperties.size(); i++) {
>                 int listConfigOrder = getConfigurationOrdinal(sortedProperties.get(i));
>                 if ((!reverseOrder && listConfigOrder > configOrder) || (reverseOrder
&& listConfigOrder < configOrder)) {
>                     break;
>                 }
>             }
>             sortedProperties.add(i, p)
>         }
>         return sortedProperties;
>     }
>
>     private int getConfigurationOrdinal(Properties p) {
>         String configOrderString = p.getProperty(ordinalKey)
>         if (configOrderString != null && configOrderString.length() > 0) {
>             return Integer.parseInt(configOrderString)
>         }
>         return defaultOrdinal
>     }
>
>     private static Properties mergeProperties(List<Properties> sortedProperties)
{
>         Properties mergedProperties = new Properties();
>         for (Properties p : sortedProperties) {
>             mergedProperties.putAll(p)
>         }
>
>         return mergedProperties;
>     }
>
> }
>
>
> plugins {
>     id 'java'
>     id 'com.github.johnrengelman.shadow' version '5.0.0'
>     id 'io.freefair.lombok' version '3.6.6'
>     id 'project-report'
> }
>
> group 'org.waastad'
> version '1.0-SNAPSHOT'
>
> sourceCompatibility = 1.8
>
> repositories {
>     mavenCentral()
> }
>
> jar {
>     manifest {
>         attributes 'Main-Class': 'org.apache.meecrowave.runner.Cli'
>     }
> }
>
> shadowJar {
>     mergeServiceFiles()
>
>     transform(AppendingTransformer) {
>         resource = 'META-INF/cxf/bus-extensions.txt'
>     }
>     transform(AppendingTransformer) {
>         resource = 'log4j2.component.properties'
>     }
>     transform(Log4j2PluginsCacheFileTransformer)
>     transform(OpenWebBeansPropertiesTransformer) {
>         resource = 'META-INF/openwebbeans/openwebbeans.properties'
>     }
>     transform(ServiceFileTransformer)
> }
>
> dependencies {
>     compile('org.apache.meecrowave:meecrowave-core:1.2.8') {
>         exclude group: 'org.glassfish.jaxb'
>         exclude group: 'jakarta.xml.bind'
>         exclude group: 'org.jvnet.staxex'
>         exclude group: 'org.codehaus.woodstox'
>         exclude group: 'com.fasterxml.woodstox'
>         exclude group: 'jakarta.ws.rs'
>         exclude group: 'javax.annotation'
>         exclude group: 'org.apache.ws.xmlschema'
>     }
>     compile 'commons-cli:commons-cli:1.4'
>     testCompile group: 'junit', name: 'junit', version: '4.12'
> }
>
>
> ---
>
>
> on., 05.06.2019 kl. 22.32 +0200, skrev Romain Manni-Bucau:
>
> Did you port the excludes as well?
>
> Btw if you want to PR the doc on the website to add it would be welcomed ;)
>
> Le mer. 5 juin 2019 à 22:20, Helge Waastad <helge@waastad.org> a écrit :
>
> Just an update.
>
> I needed to implement the OpenWebBeansPropertiesTransformer
> in my gradle build.
>
> It's working now, but it seems to be some work left to trim down the jar.
> Currently I'm ~4M larger than the maven version.
>
> /hw
>
> on., 05.06.2019 kl. 10.50 +0200, skrev Romain Manni-Bucau:
>
> Hi Helge,
>
> Meecrowave supports shadowing but as explained on the maven page
> documenting how to do a fat jar with shade plugin (no need to build a
> capsule ;)) -
> http://openwebbeans.apache.org/meecrowave/meecrowave-maven/index.html (the
> end) - it requires to use custom transformers for cxf, openwebbeans, log4j2
> (until you exclude it) etc...
>
> If you do the same with shadowing plugin - transformers API was copied
> from shade plugin so it should be trivial to port them over - then the
> shadowing will work.
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://rmannibucau.metawerx.net/> | Old Blog
> <http://rmannibucau.wordpress.com> | Github
> <https://github.com/rmannibucau> | LinkedIn
> <https://www.linkedin.com/in/rmannibucau> | Book
> <https://www.packtpub.com/application-development/java-ee-8-high-performance>
>
>
> Le mer. 5 juin 2019 à 10:48, Helge Waastad <helge@waastad.org> a écrit :
>
> Hi,
> I've been running meecrowave and maven (and capsule-maven-plugin) to make
> a fat jar.
>
> However in my quest to use Gradle I'm struggling to get shadowing working
> for Meecrowave.
>
> running jar:
> Caused by: java.lang.NullPointerException
> at
> org.apache.meecrowave.tomcat.MeecrowaveContextConfig.webConfig(MeecrowaveContextConfig.java:111)
> at
> org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:768)
> at
> org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:301)
> at
> org.apache.meecrowave.tomcat.MeecrowaveContextConfig.lifecycleEvent(MeecrowaveContextConfig.java:165)
> at
> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
> at
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5034)
> at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
>
>
> Does anyone have an example for a gradle build and Meecrowave?
>
> /hw
>
>
>
> --
>
> Helge Waastad
> - The Undelstad Cup Champion 2017
>
>

Mime
View raw message