Coverage Report - org.apache.maven.plugin.eclipse.osgiplugin.ExplodedPlugin
 
Classes in this File Line Coverage Branch Coverage Complexity
ExplodedPlugin
0%
0/25
0%
0/4
2
 
 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.plugin.eclipse.osgiplugin;
 20  
 
 21  
 import java.io.File;
 22  
 import java.io.FileInputStream;
 23  
 import java.io.IOException;
 24  
 import java.util.Properties;
 25  
 import java.util.jar.JarFile;
 26  
 import java.util.jar.Manifest;
 27  
 
 28  
 import org.apache.maven.plugin.eclipse.InstallPluginsMojo;
 29  
 import org.codehaus.plexus.archiver.ArchiverException;
 30  
 import org.codehaus.plexus.archiver.jar.JarArchiver;
 31  
 
 32  
 /**
 33  
  * Represents an Eclipse plugin that it's exploded in a directory
 34  
  * 
 35  
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
 36  
  * @version $Id: ExplodedPlugin.java 728546 2008-12-21 22:56:51Z bentmann $
 37  
  */
 38  
 public class ExplodedPlugin
 39  
     extends AbstractEclipseOsgiPlugin
 40  
 {
 41  
 
 42  
     private File tempJarFile;
 43  
 
 44  
     public ExplodedPlugin( File folder )
 45  
     {
 46  0
         super( folder );
 47  0
     }
 48  
 
 49  
     private File getManifestFile()
 50  
     {
 51  0
         return new File( getFile(), "META-INF/MANIFEST.MF" );
 52  
     }
 53  
 
 54  
     public Manifest getManifest()
 55  
         throws IOException
 56  
     {
 57  0
         if ( !getManifestFile().exists() )
 58  
         {
 59  0
             return null;
 60  
         }
 61  
 
 62  0
         FileInputStream is = new FileInputStream( getManifestFile() );
 63  
         try
 64  
         {
 65  0
             return new Manifest( is );
 66  
         }
 67  
         finally
 68  
         {
 69  0
             is.close();
 70  
         }
 71  
     }
 72  
 
 73  
     public boolean hasManifest()
 74  
     {
 75  0
         return getManifestFile().exists();
 76  
     }
 77  
 
 78  
     public File getJarFile()
 79  
         throws IOException
 80  
     {
 81  0
         if ( tempJarFile == null )
 82  
         {
 83  
             try
 84  
             {
 85  0
                 tempJarFile = File.createTempFile( "mvn-eclipse", null );
 86  0
                 tempJarFile.deleteOnExit();
 87  
 
 88  0
                 JarArchiver jarArchiver = new JarArchiver();
 89  
 
 90  0
                 jarArchiver.setDestFile( tempJarFile );
 91  0
                 jarArchiver.addDirectory( getFile() );
 92  0
                 jarArchiver.setManifest( getManifestFile() );
 93  0
                 jarArchiver.createArchive();
 94  
 
 95  0
                 return tempJarFile;
 96  
             }
 97  0
             catch ( ArchiverException e )
 98  
             {
 99  
                 // TODO only accepts the cause as parameter in JDK 1.6+
 100  0
                 throw new IOException( e.getMessage() );
 101  
             }
 102  
         }
 103  0
         return tempJarFile;
 104  
     }
 105  
 
 106  
     public JarFile getJar()
 107  
         throws IOException
 108  
     {
 109  0
         return new JarFile( getJarFile(), false );
 110  
     }
 111  
 
 112  
     /**
 113  
      * set the pom property to install unpacked if it was unpacked
 114  
      */
 115  
     public Properties getPomProperties()
 116  
     {
 117  0
         Properties properties = new Properties();
 118  0
         properties.setProperty( InstallPluginsMojo.PROP_UNPACK_PLUGIN, Boolean.TRUE.toString() );
 119  0
         return properties;
 120  
     }
 121  
 
 122  
 }