From 4f83ae693f5c9f8022fc2b75c83b2bd632a1b6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 3 May 2020 16:15:33 +0200 Subject: [PATCH] [MSHADE-363] IT to check new Reproducible transformer with old plugin --- pom.xml | 3 + src/it/projects/MSHADE-363_old-plugin/pom.xml | 65 ++++++++++++++++ .../src/main/resources/Message.properties | 18 +++++ ...CustomReproducibleResourceTransformer.java | 78 +++++++++++++++++++ .../ReproducibleResourceTransformer.java | 43 ++++++++++ 5 files changed, 207 insertions(+) create mode 100644 src/it/projects/MSHADE-363_old-plugin/pom.xml create mode 100644 src/it/projects/MSHADE-363_old-plugin/src/main/resources/Message.properties create mode 100644 src/test/java/org/apache/maven/plugins/shade/custom/CustomReproducibleResourceTransformer.java create mode 100644 src/test/java/org/apache/maven/plugins/shade/resource/ReproducibleResourceTransformer.java diff --git a/pom.xml b/pom.xml index 4dfbad46..b2e5a686 100644 --- a/pom.xml +++ b/pom.xml @@ -288,6 +288,9 @@ src/it/projects src/it/mrm/settings.xml + + org.apache.maven.plugins:maven-shade-plugin:${project.version}:test-jar + diff --git a/src/it/projects/MSHADE-363_old-plugin/pom.xml b/src/it/projects/MSHADE-363_old-plugin/pom.xml new file mode 100644 index 00000000..bf782676 --- /dev/null +++ b/src/it/projects/MSHADE-363_old-plugin/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.apache.maven.its.shade.pp + mshade-363-use-custom + 1.0-SNAPSHOT + + check new ReproducibleResourceTransformer API can be used with older shade plugin + if new extensions cannot be used with older shade plugin, it will add user-visible constraints... + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.2 + + + org.apache.maven.plugins + maven-shade-plugin + @project.version@ + tests + + + + + use-extra-resource-transformer + package + + shade + + + + + + + + + + + + diff --git a/src/it/projects/MSHADE-363_old-plugin/src/main/resources/Message.properties b/src/it/projects/MSHADE-363_old-plugin/src/main/resources/Message.properties new file mode 100644 index 00000000..f94d1d0b --- /dev/null +++ b/src/it/projects/MSHADE-363_old-plugin/src/main/resources/Message.properties @@ -0,0 +1,18 @@ +# 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. + +one = one diff --git a/src/test/java/org/apache/maven/plugins/shade/custom/CustomReproducibleResourceTransformer.java b/src/test/java/org/apache/maven/plugins/shade/custom/CustomReproducibleResourceTransformer.java new file mode 100644 index 00000000..eef5744c --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/shade/custom/CustomReproducibleResourceTransformer.java @@ -0,0 +1,78 @@ +package org.apache.maven.plugins.shade.custom; + +/* + * 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.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.jar.JarOutputStream; + +import org.apache.maven.plugins.shade.relocation.Relocator; +import org.apache.maven.plugins.shade.resource.ReproducibleResourceTransformer; + +/** + * Custom ReproducibleResourceTransformer for MSHADE-363_old-plugin IT, to check that it can be run with + * an older maven-shade-plugin that does not contain the ReproducibleResourceTransformer interface. + */ +public class CustomReproducibleResourceTransformer + implements ReproducibleResourceTransformer +{ + @Override + public boolean canTransformResource( final String resource ) + { + return true; + } + + /** + * old non-reproducible RessourceTransformer API that will be used by maven-shade-plugin up to 3.2.2. + */ + @Override + public final void processResource( final String resource, final InputStream is, final List relocators ) + throws IOException + { + System.out.println( "Custom ResourceTransformer called through old API" ); + // call new ReproducibleRessourceTransformer API using a conventional timestamp + processResource( resource, is, relocators, 0 ); + } + + /** + * new reproducible API + */ + @Override + public void processResource( final String resource, final InputStream is, final List relocators, + long time ) + throws IOException + { + System.out.println( "Custom ResourceTransformer called through new Reprodcible API" ); + } + + @Override + public boolean hasTransformedResource() + { + return true; + } + + @Override + public void modifyOutputStream( JarOutputStream os ) + throws IOException + { + // do-op for this test + } +} \ No newline at end of file diff --git a/src/test/java/org/apache/maven/plugins/shade/resource/ReproducibleResourceTransformer.java b/src/test/java/org/apache/maven/plugins/shade/resource/ReproducibleResourceTransformer.java new file mode 100644 index 00000000..c5b7ba8a --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/shade/resource/ReproducibleResourceTransformer.java @@ -0,0 +1,43 @@ +package org.apache.maven.plugins.shade.resource; + +/* + * 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 org.apache.maven.plugins.shade.relocation.Relocator; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +/** + * Copy of original interface necessary to MSHADE-363_old-plugin IT: + * CustomReproducibleResourceTransformer is built with ReproducibleResourceTransformer interface provided by + * recent maven-shade-plugin, but older maven-shade-plugin 3.2.2 will be used at runtime in the + * MSHADE-363_old-plugin IT, an older that does not provide the interface. Without the interface copy + * in the custom resource transformer code, this would lead to ClassNotFoundException... + * + * @since 3.2.4 + * @see org.apache.maven.plugins.shade.custom.CustomReproducibleResourceTransformer + */ +public interface ReproducibleResourceTransformer + extends ResourceTransformer +{ + void processResource( String resource, InputStream is, List relocators, long time ) + throws IOException; +}