View Javadoc
1   package org.apache.maven.plugins.shade.custom;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.IOException;
23  import java.io.InputStream;
24  import java.util.List;
25  import java.util.jar.JarOutputStream;
26  
27  import org.apache.maven.plugins.shade.relocation.Relocator;
28  import org.apache.maven.plugins.shade.resource.ReproducibleResourceTransformer;
29  
30  /**
31   * Custom ReproducibleResourceTransformer for MSHADE-363_old-plugin IT, to check that it can be run with
32   * an older maven-shade-plugin that does not contain the ReproducibleResourceTransformer interface.
33   */
34  public class CustomReproducibleResourceTransformer
35      implements ReproducibleResourceTransformer
36  {
37      @Override
38      public boolean canTransformResource( final String resource )
39      {
40          return true;
41      }
42  
43      /**
44       * old non-reproducible RessourceTransformer API that will be used by maven-shade-plugin up to 3.2.2.
45       */
46      @Override
47      public final void processResource( final String resource, final InputStream is, final List<Relocator> relocators )
48          throws IOException
49      {
50          System.out.println( "Custom ResourceTransformer called through old API" );
51          // call new ReproducibleRessourceTransformer API using a conventional timestamp
52          processResource( resource, is, relocators, 0 );
53      }
54  
55      /**
56       * new reproducible API
57       */
58      @Override
59      public void processResource( final String resource, final InputStream is, final List<Relocator> relocators,
60                                   long time )
61          throws IOException
62      {
63          System.out.println( "Custom ResourceTransformer called through new Reprodcible API" );
64      }
65  
66      @Override
67      public boolean hasTransformedResource()
68      {
69          return true;
70      }
71  
72      @Override
73      public void modifyOutputStream( JarOutputStream os )
74          throws IOException
75      {
76          // do-op for this test
77      }
78  }