View Javadoc
1   package org.apache.maven.plugins.repository.it;
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 static org.apache.maven.plugins.repository.it.support.IntegrationTestUtils.bootstrap;
23  import static org.apache.maven.plugins.repository.it.support.IntegrationTestUtils.getCliPluginPrefix;
24  import static org.apache.maven.plugins.repository.it.support.IntegrationTestUtils.getTestDir;
25  import static org.apache.maven.plugins.repository.testutil.Assertions.assertZipContents;
26  
27  import org.apache.maven.it.VerificationException;
28  import org.apache.maven.it.Verifier;
29  import org.apache.maven.plugins.repository.testutil.Assertions;
30  import org.junit.BeforeClass;
31  import org.junit.Test;
32  
33  import java.io.File;
34  import java.io.IOException;
35  import java.net.URISyntaxException;
36  import java.util.HashSet;
37  import java.util.List;
38  import java.util.Set;
39  
40  public class BundlePackIT
41  {
42      
43      @BeforeClass
44      public static void doBootstrap()
45          throws VerificationException, IOException, URISyntaxException
46      {
47          bootstrap();
48      }
49  
50      @SuppressWarnings( "unchecked" )
51      @Test
52      public void packWithSCMInfoProvided()
53          throws IOException, URISyntaxException, VerificationException
54      {
55          File dir = getTestDir( "bundle-pack" );
56          
57          String prefix = getCliPluginPrefix();
58          String artifactId = "bundle-pack-target";
59          String groupId = "org.apache.maven.its.repository";
60          String version = "1.0";
61  
62          File bundleSource = new File( dir, artifactId + "-" + version + "-bundle.jar" );
63  
64          if ( bundleSource.exists() )
65          {
66              bundleSource.delete();
67          }
68          
69          Verifier verifier = new Verifier( dir.getAbsolutePath() );
70          
71          verifier.setAutoclean( false );
72  
73          List<String> cliOptions = verifier.getCliOptions();
74          cliOptions.add( "-DgroupId=" + groupId );
75          cliOptions.add( "-DartifactId=" + artifactId );
76          cliOptions.add( "-Dversion=" + version );
77  
78          verifier.executeGoal( prefix + "bundle-pack" );
79          verifier.verifyErrorFreeLog();
80          verifier.resetStreams();
81  
82          Set<String> requiredEntries = new HashSet<String>();
83          requiredEntries.add( "pom.xml" );
84          requiredEntries.add( artifactId + "-" + version + ".jar" );
85          
86          if ( !verifier.isMavenDebug() )
87          {
88              bundleSource.deleteOnExit();
89          }
90  
91          assertZipContents( requiredEntries, Assertions.EMPTY_ENTRY_NAMES, bundleSource );
92      }
93  
94      @SuppressWarnings( "unchecked" )
95      @Test
96      public void packWithSCMInfoMissing()
97          throws IOException, URISyntaxException, VerificationException
98      {
99          File dir = getTestDir( "bundle-pack" );
100         
101         String prefix = getCliPluginPrefix();
102         String artifactId = "bundle-pack-target-no-scm";
103         String groupId = "org.apache.maven.its.repository";
104         String version = "1.0";
105 
106         File bundleSource = new File( dir, artifactId + "-" + version + "-bundle.jar" );
107 
108         if ( bundleSource.exists() )
109         {
110             bundleSource.delete();
111         }
112         
113         Verifier verifier = new Verifier( dir.getAbsolutePath() );
114         
115         verifier.setAutoclean( false );
116 
117         List<String> cliOptions = verifier.getCliOptions();
118         cliOptions.add( "-DgroupId=" + groupId );
119         cliOptions.add( "-DartifactId=" + artifactId );
120         cliOptions.add( "-Dversion=" + version );
121         cliOptions.add( "-DscmUrl=http://foo/" );
122         cliOptions.add( "-DscmConnection=scm:svn:http://foo/" );
123 
124         verifier.executeGoal( prefix + "bundle-pack" );
125         verifier.verifyErrorFreeLog();
126         verifier.resetStreams();
127 
128         Set<String> requiredEntries = new HashSet<String>();
129         requiredEntries.add( "pom.xml" );
130         requiredEntries.add( artifactId + "-" + version + ".jar" );
131         
132         if ( !verifier.isMavenDebug() )
133         {
134             bundleSource.deleteOnExit();
135         }
136 
137         assertZipContents( requiredEntries, Assertions.EMPTY_ENTRY_NAMES, bundleSource );
138     }
139 
140 }