BundleAllPluginTest xref

    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.plugin.testing.stubs.ArtifactStub;
    28  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
    29  import org.apache.maven.project.MavenProject;
    30  import org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter;
    31
    32
    33  /**
    34   * Test for {@link BundleAllPlugin}
    35   *
    36   * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
    37   */
    38  public class BundleAllPluginTest extends AbstractBundlePluginTest
    39  {
    40
    41      private BundleAllPlugin plugin;
    42
    43
    44      protected void setUp() throws Exception
    45      {
    46          super.setUp();
    47          init();
    48      }
    49
    50
    51      private void init()
    52      {
    53          plugin = new BundleAllPlugin();
    54          File baseDirectory = new File( getBasedir() );
    55          File buildDirectory = new File( baseDirectory, "target" );
    56          plugin.setBuildDirectory( buildDirectory.getPath() );
    57          File outputDirectory = new File( buildDirectory, "test-classes" );
    58          plugin.setOutputDirectory( outputDirectory );
    59          plugin.setMaven2OsgiConverter( new DefaultMaven2OsgiConverter() );
    60      }
    61
    62
    63      public void testSnapshotMatch()
    64      {
    65          ArtifactStub artifact = getArtifactStub();
    66          String bundleName;
    67
    68          artifact.setVersion( "2.1-SNAPSHOT" );
    69          bundleName = "group.artifact_2.1.0.20070207_193904_2.jar";
    70
    71          assertTrue( plugin.snapshotMatch( artifact, bundleName ) );
    72
    73          artifact.setVersion( "2-SNAPSHOT" );
    74          assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
    75
    76          artifact.setArtifactId( "artifactx" );
    77          artifact.setVersion( "2.1-SNAPSHOT" );
    78          assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
    79      }
    80
    81
    82      public void testNoReBundling() throws Exception
    83      {
    84          File testFile = getTestFile( "target/test-classes/org.apache.maven.maven-model_1.0.0.0.jar" );
    85          if ( testFile.exists() )
    86          {
    87              testFile.delete();
    88          }
    89
    90          ArtifactStub artifact = new ArtifactStub();
    91          artifact.setGroupId( "group" );
    92          artifact.setArtifactId( "artifact" );
    93          artifact.setVersion( "1.0.0.0" );
    94
    95          MavenProject project = new MavenProjectStub();
    96          project.setGroupId( artifact.getGroupId() );
    97          project.setArtifactId( artifact.getArtifactId() );
    98          project.setVersion( artifact.getVersion() );
    99          project.setArtifact( artifact );
    100         project.setArtifacts( Collections.EMPTY_SET );
    101         project.setDependencyArtifacts( Collections.EMPTY_SET );
    102         File bundleFile = getTestFile( "src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar" );
    103         artifact.setFile( bundleFile );
    104
    105         BundleInfo bundleInfo = plugin.bundle( project );
    106
    107         Map exports = bundleInfo.getExportedPackages();
    108         String[] packages = new String[]
    109             { "org.apache.maven.model.io.jdom", "org.apache.maven.model" };
    110
    111         for ( int i = 0; i < packages.length; i++ )
    112         {
    113             assertTrue( "Bundle info does not contain a package that it is  exported in the manifest: " + packages[i],
    114                 exports.containsKey( packages[i] ) );
    115         }
    116
    117         assertFalse( "Bundle info contains a package that it is not exported in the manifest",
    118             exports.containsKey( "org.apache.maven.model.io.xpp3" ) );
    119     }
    120
    121     //    public void testRewriting()
    122     //        throws Exception
    123     //    {
    124     //
    125     //        MavenProjectStub project = new MavenProjectStub();
    126     //        project.setArtifact( getArtifactStub() );
    127     //        project.getArtifact().setFile( getTestBundle() );
    128     //        project.setDependencyArtifacts( Collections.EMPTY_SET );
    129     //        project.setVersion( project.getArtifact().getVersion() );
    130     //
    131     //        File output = new File( plugin.getBuildDirectory(), plugin.getBundleName( project ) );
    132     //        boolean delete = output.delete();
    133     //
    134     //        plugin.bundle( project );
    135     //
    136     //        init();
    137     //        try
    138     //        {
    139     //            plugin.bundle( project );
    140     //            fail();
    141     //        }
    142     //        catch ( RuntimeException e )
    143     //        {
    144     //            // expected
    145     //        }
    146     //    }
    147 }