Coverage Report - org.apache.maven.plugin.eclipse.osgiplugin.AbstractEclipseOsgiPlugin
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractEclipseOsgiPlugin
0%
0/31
0%
0/12
2.143
 
 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.IOException;
 23  
 import java.io.InputStream;
 24  
 import java.util.Properties;
 25  
 import java.util.jar.JarFile;
 26  
 import java.util.zip.ZipEntry;
 27  
 
 28  
 /**
 29  
  * Common functionality for both exploded and packaged plugins.
 30  
  * 
 31  
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
 32  
  * @version $Id: AbstractEclipseOsgiPlugin.java 728546 2008-12-21 22:56:51Z bentmann $
 33  
  */
 34  
 public abstract class AbstractEclipseOsgiPlugin
 35  
     implements EclipseOsgiPlugin
 36  
 {
 37  
 
 38  
     private File file;
 39  
 
 40  
     private Properties pluginProperties;
 41  
 
 42  
     public AbstractEclipseOsgiPlugin( File file )
 43  0
     {
 44  0
         this.setFile( file );
 45  0
     }
 46  
 
 47  
     public void setFile( File file )
 48  
     {
 49  0
         this.file = file;
 50  0
     }
 51  
 
 52  
     public File getFile()
 53  
     {
 54  0
         return file;
 55  
     }
 56  
 
 57  
     public String toString()
 58  
     {
 59  0
         return getFile().getAbsolutePath();
 60  
     }
 61  
 
 62  
     public Properties getPluginProperties()
 63  
         throws IOException
 64  
     {
 65  0
         if ( pluginProperties == null )
 66  
         {
 67  0
             JarFile file = getJar();
 68  0
             InputStream pluginPropertiesStream = null;
 69  
             try
 70  
             {
 71  0
                 pluginProperties = new Properties();
 72  0
                 ZipEntry jarEntry = file.getEntry( "plugin.properties" );
 73  0
                 if ( jarEntry != null )
 74  
                 {
 75  0
                     pluginPropertiesStream = file.getInputStream( jarEntry );
 76  0
                     pluginProperties.load( pluginPropertiesStream );
 77  
                 }
 78  0
             }
 79  
             finally
 80  
             {
 81  0
                 if ( pluginPropertiesStream != null )
 82  
                 {
 83  
                     try
 84  
                     {
 85  0
                         pluginPropertiesStream.close();
 86  
                     }
 87  0
                     catch ( IOException e )
 88  
                     {
 89  
                         // ignore
 90  0
                     }
 91  
                 }
 92  0
             }
 93  
         }
 94  0
         return pluginProperties;
 95  
     }
 96  
 
 97  
     public Properties getPomProperties()
 98  
     {
 99  0
         return new Properties();
 100  
     }
 101  
 
 102  
     public String getManifestAttribute( String key )
 103  
         throws IOException
 104  
     {
 105  0
         String value = getManifest().getMainAttributes().getValue( key );
 106  
 
 107  0
         if ( value == null )
 108  
         {
 109  0
             return null;
 110  
         }
 111  
 
 112  
         /* check the plugin properties for translations */
 113  0
         if ( value.startsWith( "%" ) )
 114  
         {
 115  0
             String valueFromProperties = getPluginProperties().getProperty( value.substring( 1 ) );
 116  0
             if ( valueFromProperties != null )
 117  
             {
 118  0
                 value = valueFromProperties;
 119  
             }
 120  
         }
 121  
 
 122  0
         return value;
 123  
     }
 124  
 }