View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.repository;
20  
21  import static org.apache.maven.plugins.repository.testutil.Assertions.assertZipContents;
22  
23  import org.apache.maven.artifact.repository.DefaultArtifactRepository;
24  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
25  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
26  import org.apache.maven.plugins.repository.testutil.Assertions;
27  import org.apache.maven.plugins.repository.testutil.TestInputHandler;
28  import org.codehaus.plexus.components.interactivity.InputHandler;
29  
30  import java.io.File;
31  import java.net.URL;
32  import java.util.HashSet;
33  import java.util.Set;
34  import java.util.Stack;
35  
36  /**
37   * @author Fabrizio Giustina
38   * @version $Id: BundlePackMojoTest.java 820163 2009-09-30 03:14:30Z jdcasey $
39   */
40  public class BundlePackMojoTest
41      extends AbstractMojoTestCase
42  {
43      
44      public void testPack_PomPackaging()
45          throws Exception
46      {
47          File testPom = new File( getBasedir(), "src/test/resources/unit/bundle-pack-parent/pom.xml" );
48  
49          BundlePackMojo mojo = (BundlePackMojo) lookupMojo( "bundle-pack", testPom );
50          URL repoURL = new File( getBasedir(), "src/test/resources/repo" ).toURL();
51          mojo.localRepository =
52              new DefaultArtifactRepository( "test", repoURL.toString(), new DefaultRepositoryLayout() );
53  
54          File generatedFilesDir = new File( getBasedir(), "target/bundle-pack-parent-tests" );
55          mojo.basedir = generatedFilesDir.getAbsolutePath();
56          
57          // NOTE: This is sensitive to the lookupMojo method timing...
58          TestInputHandler ih = (TestInputHandler) lookup( InputHandler.ROLE, "default" );
59  
60          Stack<String> responses = new Stack<String>();
61          responses.push( "http://foo/" );
62          responses.push( "scm:svn:http://foo/" );
63          responses.push( "2,3" );
64          responses.push( "0" );
65          ih.setLineResponses( responses );
66  
67          mojo.execute();
68  
69          File bundleSource = new File( generatedFilesDir, "testparent-1.0-bundle.jar" );
70          Set<String> entryNames = new HashSet<String>();
71          entryNames.add( "pom.xml" );
72          entryNames.add( "META-INF/MANIFEST.MF" );
73          entryNames.add( "META-INF/" );
74  
75          assertZipContents( entryNames, Assertions.EMPTY_ENTRY_NAMES, bundleSource );
76      }
77  
78      public void testPack()
79          throws Exception
80      {
81          File testPom = new File( getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml" );
82  
83          BundlePackMojo mojo = (BundlePackMojo) lookupMojo( "bundle-pack", testPom );
84          URL repoURL = new File( getBasedir(), "src/test/resources/repo" ).toURL();
85          mojo.localRepository =
86              new DefaultArtifactRepository( "test", repoURL.toString(), new DefaultRepositoryLayout() );
87  
88          File generatedFilesDir = new File( getBasedir(), "target/bundle-pack-tests" );
89          mojo.basedir = generatedFilesDir.getAbsolutePath();
90          mojo.execute();
91  
92          File bundleSource = new File( generatedFilesDir, "testartifact-1.0-bundle.jar" );
93          Set<String> entryNames = new HashSet<String>();
94          entryNames.add( "testartifact-1.0-javadoc.jar" );
95          entryNames.add( "testartifact-1.0-sources.jar" );
96          entryNames.add( "testartifact-1.0.jar" );
97          entryNames.add( "pom.xml" );
98          entryNames.add( "META-INF/MANIFEST.MF" );
99          entryNames.add( "META-INF/" );
100 
101         assertZipContents( entryNames, Assertions.EMPTY_ENTRY_NAMES, bundleSource );
102     }
103 
104     public void testPack_RemoveOne()
105         throws Exception
106     {
107         File testPom = new File( getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml" );
108 
109         BundlePackMojo mojo = (BundlePackMojo) lookupMojo( "bundle-pack", testPom );
110         URL repoURL = new File( getBasedir(), "src/test/resources/repo" ).toURL();
111         mojo.localRepository =
112             new DefaultArtifactRepository( "test", repoURL.toString(), new DefaultRepositoryLayout() );
113 
114         // NOTE: This is sensitive to the lookupMojo method timing...
115         TestInputHandler ih = (TestInputHandler) lookup( InputHandler.ROLE, "default" );
116 
117         Stack<String> responses = new Stack<String>();
118         responses.push( "3" );
119         ih.setLineResponses( responses );
120 
121         File generatedFilesDir = new File( getBasedir(), "target/bundle-pack-tests" );
122         mojo.basedir = generatedFilesDir.getAbsolutePath();
123         mojo.execute();
124 
125         File bundleSource = new File( generatedFilesDir, "testartifact-1.0-bundle.jar" );
126         Set<String> entryNames = new HashSet<String>();
127         entryNames.add( "testartifact-1.0-javadoc.jar" );
128         entryNames.add( "testartifact-1.0.jar" );
129         entryNames.add( "pom.xml" );
130         entryNames.add( "META-INF/MANIFEST.MF" );
131         entryNames.add( "META-INF/" );
132 
133         Set<String> bannedNames = new HashSet<String>();
134         // determined experimentally, so this could change!
135         bannedNames.add( "testartifact-1.0-sources.jar" );
136 
137         assertZipContents( entryNames, bannedNames, bundleSource );
138     }
139 
140     public void testPack_RemoveTwo()
141         throws Exception
142     {
143         File testPom = new File( getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml" );
144 
145         BundlePackMojo mojo = (BundlePackMojo) lookupMojo( "bundle-pack", testPom );
146         URL repoURL = new File( getBasedir(), "src/test/resources/repo" ).toURL();
147         mojo.localRepository =
148             new DefaultArtifactRepository( "test", repoURL.toString(), new DefaultRepositoryLayout() );
149 
150         // NOTE: This is sensitive to the lookupMojo method timing...
151         TestInputHandler ih = (TestInputHandler) lookup( InputHandler.ROLE, "default" );
152 
153         Stack<String> responses = new Stack<String>();
154         responses.push( "2,3" );
155         ih.setLineResponses( responses );
156 
157         File generatedFilesDir = new File( getBasedir(), "target/bundle-pack-tests" );
158         mojo.basedir = generatedFilesDir.getAbsolutePath();
159         mojo.execute();
160 
161         File bundleSource = new File( generatedFilesDir, "testartifact-1.0-bundle.jar" );
162         Set<String> entryNames = new HashSet<String>();
163         entryNames.add( "testartifact-1.0.jar" );
164         entryNames.add( "pom.xml" );
165         entryNames.add( "META-INF/MANIFEST.MF" );
166         entryNames.add( "META-INF/" );
167 
168         Set<String> bannedNames = new HashSet<String>();
169         // determined experimentally, so this could change!
170         bannedNames.add( "testartifact-1.0-sources.jar" );
171         bannedNames.add( "testartifact-1.0-javadoc.jar" );
172 
173         assertZipContents( entryNames, bannedNames, bundleSource );
174     }
175 
176     public void testPack_RemoveTwoUnordered()
177         throws Exception
178     {
179         File testPom = new File( getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml" );
180 
181         BundlePackMojo mojo = (BundlePackMojo) lookupMojo( "bundle-pack", testPom );
182         URL repoURL = new File( getBasedir(), "src/test/resources/repo" ).toURL();
183         mojo.localRepository =
184             new DefaultArtifactRepository( "test", repoURL.toString(), new DefaultRepositoryLayout() );
185 
186         // NOTE: This is sensitive to the lookupMojo method timing...
187         TestInputHandler ih = (TestInputHandler) lookup( InputHandler.ROLE, "default" );
188 
189         Stack<String> responses = new Stack<String>();
190         responses.push( "3,2" );
191         ih.setLineResponses( responses );
192 
193         File generatedFilesDir = new File( getBasedir(), "target/bundle-pack-tests" );
194         mojo.basedir = generatedFilesDir.getAbsolutePath();
195         mojo.execute();
196 
197         File bundleSource = new File( generatedFilesDir, "testartifact-1.0-bundle.jar" );
198         Set<String> entryNames = new HashSet<String>();
199         entryNames.add( "testartifact-1.0.jar" );
200         entryNames.add( "pom.xml" );
201         entryNames.add( "META-INF/MANIFEST.MF" );
202         entryNames.add( "META-INF/" );
203 
204         Set<String> bannedNames = new HashSet<String>();
205         // determined experimentally, so this could change!
206         bannedNames.add( "testartifact-1.0-sources.jar" );
207         bannedNames.add( "testartifact-1.0-javadoc.jar" );
208 
209         assertZipContents( entryNames, bannedNames, bundleSource );
210     }
211 
212     public void testPack_RemoveTwoWithSpace()
213         throws Exception
214     {
215         File testPom = new File( getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml" );
216 
217         BundlePackMojo mojo = (BundlePackMojo) lookupMojo( "bundle-pack", testPom );
218         URL repoURL = new File( getBasedir(), "src/test/resources/repo" ).toURL();
219         mojo.localRepository =
220             new DefaultArtifactRepository( "test", repoURL.toString(), new DefaultRepositoryLayout() );
221 
222         // NOTE: This is sensitive to the lookupMojo method timing...
223         TestInputHandler ih = (TestInputHandler) lookup( InputHandler.ROLE, "default" );
224 
225         Stack<String> responses = new Stack<String>();
226         responses.push( "2, 3" );
227         ih.setLineResponses( responses );
228 
229         File generatedFilesDir = new File( getBasedir(), "target/bundle-pack-tests" );
230         mojo.basedir = generatedFilesDir.getAbsolutePath();
231         mojo.execute();
232 
233         File bundleSource = new File( generatedFilesDir, "testartifact-1.0-bundle.jar" );
234         Set<String> entryNames = new HashSet<String>();
235         entryNames.add( "testartifact-1.0.jar" );
236         entryNames.add( "pom.xml" );
237         entryNames.add( "META-INF/MANIFEST.MF" );
238         entryNames.add( "META-INF/" );
239 
240         Set<String> bannedNames = new HashSet<String>();
241         // determined experimentally, so this could change!
242         bannedNames.add( "testartifact-1.0-sources.jar" );
243         bannedNames.add( "testartifact-1.0-javadoc.jar" );
244 
245         assertZipContents( entryNames, bannedNames, bundleSource );
246     }
247 
248 }