View Javadoc
1   package org.apache.felix.bundleplugin;
2   
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   * http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
21   */
22  
23  import java.io.File;
24  import java.util.Collections;
25  import java.util.Map;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.artifact.DefaultArtifact;
29  import org.apache.maven.artifact.handler.ArtifactHandler;
30  import org.apache.maven.artifact.handler.DefaultArtifactHandler;
31  import org.apache.maven.artifact.versioning.VersionRange;
32  import org.apache.maven.plugin.testing.stubs.ArtifactStub;
33  import org.apache.maven.project.MavenProject;
34  import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
35  
36  
37  /**
38   * Test for {@link BundleAllPlugin}
39   *
40   * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
41   */
42  public class BundleAllPluginTest extends AbstractBundlePluginTest
43  {
44  
45      private BundleAllPlugin plugin;
46  
47  
48      @Override
49      protected void setUp() throws Exception
50      {
51          super.setUp();
52          init();
53      }
54  
55  
56      private void init() throws Exception
57      {
58          plugin = new BundleAllPlugin();
59          File baseDirectory = new File( getBasedir() );
60          File buildDirectory = new File( baseDirectory, "target" );
61          plugin.setBuildDirectory( buildDirectory.getPath() );
62          File outputDirectory = new File( buildDirectory, "test-classes" );
63          plugin.setOutputDirectory( outputDirectory );
64      }
65  
66  
67      public void testSnapshotMatch()
68      {
69          ArtifactStub artifact = getArtifactStub();
70          String bundleName;
71  
72          artifact.setVersion( "2.1-SNAPSHOT" );
73          bundleName = "group.artifact_2.1.0.20070207_193904_2.jar";
74  
75          assertTrue( plugin.snapshotMatch( artifact, bundleName ) );
76  
77          artifact.setVersion( "2-SNAPSHOT" );
78          assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
79  
80          artifact.setArtifactId( "artifactx" );
81          artifact.setVersion( "2.1-SNAPSHOT" );
82          assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
83      }
84  
85  
86      public void testNoReBundling() throws Exception
87      {
88          File testFile = getTestFile( "target/test-classes/org.apache.maven.maven-model_1.0.0.0.jar" );
89          if ( testFile.exists() )
90          {
91              testFile.delete();
92          }
93  
94          VersionRange versionRange = VersionRange.createFromVersion("1.0.0.0");
95          ArtifactHandler artifactHandler = new DefaultArtifactHandler( "jar" );
96          Artifact artifact = new DefaultArtifact("group","artifact",versionRange, null, "jar", null, artifactHandler);
97  
98          MavenProject project = getMavenProjectStub();
99          project.setGroupId( artifact.getGroupId() );
100         project.setArtifactId( artifact.getArtifactId() );
101         project.setVersion( artifact.getVersion() );
102         project.setArtifact( artifact );
103         project.setArtifacts( Collections.EMPTY_SET );
104         project.setDependencyArtifacts( Collections.EMPTY_SET );
105         File bundleFile = getTestFile( "src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar" );
106         artifact.setFile( bundleFile );
107 
108         BundleInfo bundleInfo = plugin.bundle( project );
109 
110         Map exports = bundleInfo.getExportedPackages();
111         String[] packages = new String[]
112             { "org.apache.maven.model.io.jdom", "org.apache.maven.model" };
113 
114         for ( int i = 0; i < packages.length; i++ )
115         {
116             assertTrue( "Bundle info does not contain a package that it is  exported in the manifest: " + packages[i],
117                 exports.containsKey( packages[i] ) );
118         }
119 
120         assertFalse( "Bundle info contains a package that it is not exported in the manifest",
121             exports.containsKey( "org.apache.maven.model.io.xpp3" ) );
122     }
123 
124     //    public void testRewriting()
125     //        throws Exception
126     //    {
127     //
128     //        MavenProjectStub project = new MavenProjectStub();
129     //        project.setArtifact( getArtifactStub() );
130     //        project.getArtifact().setFile( getTestBundle() );
131     //        project.setDependencyArtifacts( Collections.EMPTY_SET );
132     //        project.setVersion( project.getArtifact().getVersion() );
133     //
134     //        File output = new File( plugin.getBuildDirectory(), plugin.getBundleName( project ) );
135     //        boolean delete = output.delete();
136     //
137     //        plugin.bundle( project );
138     //
139     //        init();
140     //        try
141     //        {
142     //            plugin.bundle( project );
143     //            fail();
144     //        }
145     //        catch ( RuntimeException e )
146     //        {
147     //            // expected
148     //        }
149     //    }
150 }