Skip to content

Commit

Permalink
[MSHADE-363] IT to check new Reproducible transformer with old plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed May 3, 2020
1 parent 3d0af77 commit 1242255
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@
</goals>
<projectsDirectory>src/it/projects</projectsDirectory>
<settingsFile>src/it/mrm/settings.xml</settingsFile>
<extraArtifacts>
<extraArtifact>org.apache.maven.plugins:maven-shade-plugin:${project.version}:test-jar</extraArtifact>
</extraArtifacts>
</configuration>
</plugin>
<plugin>
Expand Down
65 changes: 65 additions & 0 deletions src/it/projects/MSHADE-363_old-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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
https://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="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.shade.pp</groupId>
<artifactId>mshade-363-use-custom</artifactId>
<version>1.0-SNAPSHOT</version>

<name>check new ReproducibleResourceTransformer API can be used with older shade plugin</name>
<description>if new extensions cannot be used with older shade plugin, it will add user-visible constraints...</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version><!-- last version of maven-shade-plugin without the new ReproducibleResourceTransformer interface -->
<dependencies>
<dependency><!-- tests.jar adds an extra ResourceTransformer released a few years ago, with the missing ReproducibleResourceTransformer interface -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>@project.version@</version>
<classifier>tests</classifier>
</dependency>
</dependencies>
<executions>
<execution>
<id>use-extra-resource-transformer</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers><!-- use the extra transformer that implements ReproducibleResourceTransformer -->
<transformer implementation="org.apache.maven.plugins.shade.custom.CustomReproducibleResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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
#
# https://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
Original file line number Diff line number Diff line change
@@ -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
*
* https://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<Relocator> 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<Relocator> 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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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
*
* https://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;

/**
* Transform resource ensuring reproducible output: that requires to get the timestamp of
* the initial resources to define in a reproducible way the timestamp of the transformed
* resource.
*
* @author Hervé Boutemy
* @since 3.2.4
*/
public interface ReproducibleResourceTransformer
extends ResourceTransformer
{
/**
* Transform an individual resource
* @param resource The resource name
* @param is An input stream for the resource, the implementation should *not* close this stream
* @param relocators A list of relocators
* @param time the time of the resource to process
* @throws IOException When the IO blows up
*/
void processResource( String resource, InputStream is, List<Relocator> relocators, long time )
throws IOException;
}

0 comments on commit 1242255

Please sign in to comment.