Coverage Report - org.apache.maven.plugin.war.Overlay
 
Classes in this File Line Coverage Branch Coverage Complexity
Overlay
83%
71/86
48%
20/42
1,469
 
 1  
 package org.apache.maven.plugin.war;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.maven.artifact.Artifact;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.Arrays;
 26  
 import java.util.List;
 27  
 
 28  
 /**
 29  
  * An overlay is a skeleton WAR added to another WAR project in order to inject a
 30  
  * functionality, resources or any other shared component.
 31  
  * <p/>
 32  
  * Note that a particular WAR dependency can be added multiple times as an overlay
 33  
  * with different includes/excludes filter; this allows building a fine grained
 34  
  * overwriting policy.
 35  
  * <p/>
 36  
  * The current project can also be described as an overlay and can not be specified
 37  
  * twice. An overlay with no groupId and no artifactId represents the
 38  
  * current project.
 39  
  *
 40  
  * @author Stephane Nicoll
 41  
  * @version $Id: Overlay.java 985595 2010-08-14 22:29:50Z dennisl $
 42  
  */
 43  
 public class Overlay
 44  
 {
 45  
 
 46  1
     public static final String[] DEFAULT_INCLUDES = new String[]{"**/**"};
 47  
 
 48  1
     public static final String[] DEFAULT_EXCLUDES = new String[]{"META-INF/MANIFEST.MF"};
 49  
 
 50  
     private String id;
 51  
 
 52  
     private String groupId;
 53  
 
 54  
     private String artifactId;
 55  
 
 56  108
     private String classifier = null;
 57  
 
 58  108
     private String[] includes = DEFAULT_INCLUDES;
 59  
 
 60  108
     private String[] excludes = DEFAULT_EXCLUDES;
 61  
 
 62  108
     private boolean filtered = false;
 63  
 
 64  108
     private boolean skip = false;
 65  
 
 66  
     private Artifact artifact;
 67  
     
 68  
     private String targetPath;
 69  
     
 70  
     /** default overlay type is war */ 
 71  108
     private String type = "war";
 72  
 
 73  
     public Overlay()
 74  
     {
 75  108
         super();
 76  108
     }
 77  
 
 78  
 
 79  
     public Overlay( String groupId, String artifactId )
 80  
     {
 81  1
         this();
 82  1
         this.groupId = groupId;
 83  1
         this.artifactId = artifactId;
 84  1
     }
 85  
 
 86  
     /**
 87  
      * Specify whether this overlay represents the current project or not.
 88  
      *
 89  
      * @return true if the overlay represents the current project, false otherwise
 90  
      */
 91  
     public boolean isCurrentProject()
 92  
     {
 93  160
         return ( groupId == null && artifactId == null );
 94  
     }
 95  
 
 96  
     public static Overlay createInstance()
 97  
     {
 98  67
         Overlay overlay = new Overlay();
 99  67
         overlay.setId( "currentBuild" );
 100  67
         return overlay;
 101  
     }
 102  
 
 103  
     // Getters and Setters
 104  
 
 105  
     public String getId()
 106  
     {
 107  381
         if ( id == null )
 108  
         {
 109  37
             final StringBuffer sb = new StringBuffer();
 110  37
             sb.append( getGroupId() ).append( ":" ).append( getArtifactId() );
 111  37
             if ( getClassifier() != null )
 112  
             {
 113  0
                 sb.append( ":" ).append( getClassifier() );
 114  
             }
 115  37
             id = sb.toString();
 116  
         }
 117  381
         return id;
 118  
     }
 119  
 
 120  
     public void setId( String id )
 121  
     {
 122  67
         this.id = id;
 123  67
     }
 124  
 
 125  
     public String getGroupId()
 126  
     {
 127  119
         return groupId;
 128  
     }
 129  
 
 130  
     public void setGroupId( String groupId )
 131  
     {
 132  40
         this.groupId = groupId;
 133  40
     }
 134  
 
 135  
     public String getArtifactId()
 136  
     {
 137  119
         return artifactId;
 138  
     }
 139  
 
 140  
     public void setArtifactId( String artifactId )
 141  
     {
 142  40
         this.artifactId = artifactId;
 143  40
     }
 144  
 
 145  
     public String getClassifier()
 146  
     {
 147  99
         return classifier;
 148  
     }
 149  
 
 150  
     public void setClassifier( String classifier )
 151  
     {
 152  40
         this.classifier = classifier;
 153  40
     }
 154  
 
 155  
     public String[] getIncludes()
 156  
     {
 157  66
         return includes;
 158  
     }
 159  
 
 160  
     public void setIncludes( String includes )
 161  
     {
 162  42
         this.includes = parse( includes );
 163  42
     }
 164  
 
 165  
     public void setIncludes( String[] includes )
 166  
     {
 167  0
         this.includes = includes;
 168  0
     }
 169  
 
 170  
     public String[] getExcludes()
 171  
     {
 172  62
         return excludes;
 173  
     }
 174  
 
 175  
     public void setExcludes( String excludes )
 176  
     {
 177  43
         this.excludes = parse( excludes );
 178  43
     }
 179  
 
 180  
     public void setExcludes( String[] excludes )
 181  
     {
 182  0
         this.excludes = excludes;
 183  0
     }
 184  
 
 185  
     public boolean isFiltered()
 186  
     {
 187  33
         return filtered;
 188  
     }
 189  
 
 190  
     public void setFiltered( boolean filtered )
 191  
     {
 192  0
         this.filtered = filtered;
 193  0
     }
 194  
 
 195  
     public boolean shouldSkip()
 196  
     {
 197  34
         return skip;
 198  
     }
 199  
 
 200  
     public void setSkip( boolean skip )
 201  
     {
 202  2
         this.skip = skip;
 203  2
     }
 204  
 
 205  
     public Artifact getArtifact()
 206  
     {
 207  33
         return artifact;
 208  
     }
 209  
 
 210  
     public void setArtifact( Artifact artifact )
 211  
     {
 212  68
         this.artifact = artifact;
 213  68
     }
 214  
 
 215  
     public String getTargetPath()
 216  
     {
 217  68
         return targetPath;
 218  
     }
 219  
 
 220  
 
 221  
     public void setTargetPath( String targetPath )
 222  
     {
 223  1
         this.targetPath = targetPath;
 224  1
     }
 225  
 
 226  
     public String getType()
 227  
     {
 228  29
         return type;
 229  
     }
 230  
 
 231  
 
 232  
     public void setType( String type )
 233  
     {
 234  43
         this.type = type;
 235  43
     }
 236  
     
 237  
     public String toString()
 238  
     {
 239  68
         return " id " + getId();
 240  
     }
 241  
 
 242  
 
 243  
     public boolean equals( Object o )
 244  
     {
 245  80
         if ( this == o )
 246  
         {
 247  11
             return true;
 248  
         }
 249  69
         if ( o == null || getClass() != o.getClass() )
 250  
         {
 251  67
             return false;
 252  
         }
 253  
 
 254  2
         Overlay overlay = (Overlay) o;
 255  
 
 256  2
         if ( excludes != null ? !Arrays.equals( excludes, overlay.excludes ) : overlay.excludes != null )
 257  
         {
 258  0
             return false;
 259  
         }
 260  2
         if ( getId() != null ? !getId().equals( overlay.getId() ) : overlay.getId() != null )
 261  
         {
 262  0
             return false;
 263  
         }
 264  2
         if ( includes != null ? !Arrays.equals( includes, overlay.includes ) : overlay.includes != null )
 265  
         {
 266  0
             return false;
 267  
         }
 268  
 
 269  2
         return true;
 270  
     }
 271  
 
 272  
     public int hashCode()
 273  
     {
 274  
         int result;
 275  0
         result = ( getId() != null ? getId().hashCode() : 0 );
 276  0
         result = 31 * result + ( includes != null ? includes.hashCode() : 0 );
 277  0
         result = 31 * result + ( excludes != null ? excludes.hashCode() : 0 );
 278  0
         return result;
 279  
     }
 280  
 
 281  
     private String[] parse( String s )
 282  
     {
 283  85
         final List result = new ArrayList();
 284  85
         if ( s == null )
 285  
         {
 286  0
             return (String[]) result.toArray( new String[result.size()] );
 287  
         }
 288  
         else
 289  
         {
 290  85
             String[] tokens = s.split( "," );
 291  177
             for ( int i = 0; i < tokens.length; i++ )
 292  
             {
 293  92
                 String token = tokens[i];
 294  92
                 result.add( token.trim() );
 295  
             }
 296  85
             return (String[]) result.toArray( new String[result.size()] );
 297  
         }
 298  
     }
 299  
 
 300  
 }