Coverage Report - org.apache.maven.plugin.eclipse.writers.rad.RadManifestWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
RadManifestWriter
0%
0/37
0%
0/22
4
 
 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.writers.rad;
 20  
 
 21  
 import java.io.File;
 22  
 import java.util.Iterator;
 23  
 
 24  
 import org.apache.maven.model.Resource;
 25  
 import org.apache.maven.plugin.MojoExecutionException;
 26  
 import org.apache.maven.plugin.eclipse.Constants;
 27  
 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
 28  
 import org.apache.maven.plugin.eclipse.writers.AbstractEclipseManifestWriter;
 29  
 import org.apache.maven.plugin.ide.IdeUtils;
 30  
 import org.apache.maven.plugin.ide.JeeUtils;
 31  
 import org.apache.maven.project.MavenProject;
 32  
 
 33  
 /**
 34  
  * Create or adapt the manifest files for the RAD6 runtime dependencys. attention these will not be used for the real
 35  
  * ear these are just to get the runtime enviorment using the maven dependencies. WARNING: The manifest resources added
 36  
  * here will not have the benefit of the dependencies of the project, since that's not provided in the setup() apis, one
 37  
  * of the locations from which this writer is used in the RadPlugin.
 38  
  * 
 39  
  * @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven </a>
 40  
  */
 41  0
 public class RadManifestWriter
 42  
     extends AbstractEclipseManifestWriter
 43  
 {
 44  
 
 45  0
     private static final String DEFAULT_WEBAPP_RESOURCE_DIR =
 46  
         "src" + File.separatorChar + "main" + File.separatorChar + "webapp";
 47  
 
 48  
     /**
 49  
      * Search the project for the existing META-INF directory where the manifest should be located.
 50  
      * 
 51  
      * @return the apsolute path to the META-INF directory
 52  
      * @throws MojoExecutionException
 53  
      */
 54  
     protected String getMetaInfBaseDirectory( MavenProject project )
 55  
         throws MojoExecutionException
 56  
     {
 57  0
         String metaInfBaseDirectory = null;
 58  
 
 59  0
         if ( config.getProject().getPackaging().equals( Constants.PROJECT_PACKAGING_WAR ) )
 60  
         {
 61  
             // Generating web content settings based on war plug-in warSourceDirectory property
 62  0
             File warSourceDirectory =
 63  
                 new File( IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
 64  
                                                      "warSourceDirectory", //$NON-NLS-1$
 65  
                                                      DEFAULT_WEBAPP_RESOURCE_DIR ) );
 66  
 
 67  0
             String webContentDir =
 68  
                 IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), warSourceDirectory, false );
 69  
 
 70  0
             metaInfBaseDirectory =
 71  
                 config.getProject().getBasedir().getAbsolutePath() + File.separatorChar + webContentDir;
 72  
 
 73  0
             log.debug( "Attempting to use: " + metaInfBaseDirectory + " for location of META-INF in war project." );
 74  
 
 75  0
             File metaInfDirectoryFile = new File( metaInfBaseDirectory + File.separatorChar + META_INF_DIRECTORY );
 76  
 
 77  0
             if ( metaInfDirectoryFile.exists() && !metaInfDirectoryFile.isDirectory() )
 78  
             {
 79  0
                 metaInfBaseDirectory = null;
 80  
             }
 81  
         }
 82  
 
 83  0
         if ( metaInfBaseDirectory == null )
 84  
         {
 85  0
             for ( Iterator iterator = project.getResources().iterator(); iterator.hasNext(); )
 86  
             {
 87  0
                 metaInfBaseDirectory = ( (Resource) iterator.next() ).getDirectory();
 88  
 
 89  0
                 File metaInfDirectoryFile = new File( metaInfBaseDirectory + File.separatorChar + META_INF_DIRECTORY );
 90  
 
 91  0
                 log.debug( "Checking for existence of META-INF directory: " + metaInfDirectoryFile );
 92  
 
 93  0
                 if ( metaInfDirectoryFile.exists() && !metaInfDirectoryFile.isDirectory() )
 94  
                 {
 95  0
                     metaInfBaseDirectory = null;
 96  
                 }
 97  
             }
 98  
         }
 99  
 
 100  0
         return metaInfBaseDirectory;
 101  
     }
 102  
 
 103  
     /**
 104  
      * {@inheritDoc}
 105  
      */
 106  
     public void write()
 107  
         throws MojoExecutionException
 108  
     {
 109  0
         super.write();
 110  0
         verifyManifestBasedirInSourceDirs( getMetaInfBaseDirectory( config.getProject() ) );
 111  0
     }
 112  
 
 113  
 
 114  
 
 115  
     // NOTE: This could change the config!
 116  
     private void verifyManifestBasedirInSourceDirs( String metaInfBaseDirectory )
 117  
     {
 118  0
         EclipseSourceDir[] sourceDirs = config.getSourceDirs();
 119  
 
 120  0
         if ( sourceDirs != null )
 121  
         {
 122  0
             boolean foundMetaInfBaseDirectory = false;
 123  
 
 124  0
             for ( int i = 0; i < sourceDirs.length; i++ )
 125  
             {
 126  0
                 EclipseSourceDir esd = sourceDirs[i];
 127  
 
 128  0
                 if ( esd.getPath().equals( metaInfBaseDirectory ) )
 129  
                 {
 130  0
                     foundMetaInfBaseDirectory = true;
 131  0
                     break;
 132  
                 }
 133  
             }
 134  
 
 135  0
             if ( !foundMetaInfBaseDirectory )
 136  
             {
 137  0
                 EclipseSourceDir dir =
 138  
                     new EclipseSourceDir( metaInfBaseDirectory, null, true, false, null, null, false );
 139  
 
 140  0
                 EclipseSourceDir[] newSourceDirs = new EclipseSourceDir[sourceDirs.length + 1];
 141  0
                 newSourceDirs[sourceDirs.length] = dir;
 142  
 
 143  0
                 System.arraycopy( sourceDirs, 0, newSourceDirs, 0, sourceDirs.length );
 144  
 
 145  0
                 config.setSourceDirs( newSourceDirs );
 146  
             }
 147  
         }
 148  0
     }
 149  
 }