Coverage Report - org.apache.maven.plugins.site.wagon.repository.Repository
 
Classes in this File Line Coverage Branch Coverage Complexity
Repository
0%
0/93
0%
0/32
2,042
 
 1  
 package org.apache.maven.plugins.site.wagon.repository;
 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.plugins.site.wagon.PathUtils;
 23  
 import org.apache.maven.wagon.WagonConstants;
 24  
 import org.apache.maven.wagon.repository.RepositoryPermissions;
 25  
 import org.codehaus.plexus.util.StringUtils;
 26  
 
 27  
 import java.io.Serializable;
 28  
 import java.util.Properties;
 29  
 
 30  
 /**
 31  
  * This class is an abstraction of the location from/to resources
 32  
  * can be transfered.
 33  
  *
 34  
  * <strong>Note: </strong> This is a copy of a file from Wagon. It was copied here to be able to work around WAGON-307.
 35  
  * This class can be removed when the prerequisite Maven version uses wagon-provider-api:1.0-beta-7.
 36  
  *
 37  
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
 38  
  * @version $Id: org.apache.maven.plugins.site.wagon.repository.Repository.html 816554 2012-05-08 11:56:34Z hboutemy $
 39  
  * @todo [BP] some things are specific to certain wagons (eg key stuff in authInfo, permissions)
 40  
  */
 41  
 public class Repository
 42  
     implements Serializable
 43  
 {
 44  
     private static final long serialVersionUID = 1312227676322136247L;
 45  
 
 46  
     private String id;
 47  
 
 48  
     private String name;
 49  
 
 50  
     private String host;
 51  
 
 52  0
     private int port = WagonConstants.UNKNOWN_PORT;
 53  
 
 54  
     private String basedir;
 55  
 
 56  
     private String protocol;
 57  
 
 58  
     private String url;
 59  
 
 60  
     private RepositoryPermissions permissions;
 61  
 
 62  
     /**
 63  
      * Properties influencing wagon behaviour
 64  
      * which are very specific to particular wagon.
 65  
      */
 66  0
     private Properties parameters = new Properties();
 67  
 
 68  
     // Username/password are sometimes encoded in the URL
 69  0
     private String username = null;
 70  
 
 71  0
     private String password = null;
 72  
 
 73  
     /**
 74  
      * @deprecated use {@link #Repository(String, String)}
 75  
      */
 76  
     public Repository()
 77  0
     {
 78  
 
 79  0
     }
 80  
 
 81  
     public Repository( String id, String url )
 82  0
     {
 83  0
         if ( id == null )
 84  
         {
 85  0
             throw new NullPointerException( "id can not be null" );
 86  
         }
 87  
         
 88  0
         setId( id );
 89  
 
 90  0
         if ( url == null )
 91  
         {
 92  0
             throw new NullPointerException( "url can not be null" );
 93  
         }
 94  
         
 95  0
         setUrl( url );
 96  0
     }
 97  
 
 98  
     public String getId()
 99  
     {
 100  0
         return id;
 101  
     }
 102  
 
 103  
     public void setId( String id )
 104  
     {
 105  0
         this.id = id;
 106  0
     }
 107  
 
 108  
     /**
 109  
      * Retrieve the base directory of the repository. This is derived from the full repository URL, and
 110  
      * contains the entire path component.
 111  
      * 
 112  
      * @return the base directory
 113  
      */
 114  
     public String getBasedir()
 115  
     {
 116  0
         return basedir;
 117  
     }
 118  
 
 119  
     public void setBasedir( String basedir )
 120  
     {
 121  0
         this.basedir = basedir;
 122  0
     }
 123  
 
 124  
     public void setName( String name )
 125  
     {
 126  0
         this.name = name;
 127  0
     }
 128  
 
 129  
     public int getPort()
 130  
     {
 131  0
         return port;
 132  
     }
 133  
 
 134  
     public void setPort( int port )
 135  
     {
 136  0
         this.port = port;
 137  0
     }
 138  
 
 139  
     public void setUrl( String url )
 140  
     {
 141  0
         this.url = url;
 142  
 
 143  
         // TODO [BP]: refactor out the PathUtils URL stuff into a class like java.net.URL, so you only parse once
 144  
         //  can't use URL class as is because it won't recognise our protocols, though perhaps we could attempt to
 145  
         //  register handlers for scp, etc?
 146  
 
 147  0
         this.protocol = PathUtils.protocol( url );
 148  
 
 149  0
         this.host = PathUtils.host( url );
 150  
 
 151  0
         this.port = PathUtils.port( url );
 152  
 
 153  0
         this.basedir = PathUtils.basedir( url );
 154  
 
 155  0
         String username = PathUtils.user( url );
 156  0
         this.username = username;
 157  
 
 158  0
         if ( username != null )
 159  
         {
 160  0
             String password = PathUtils.password( url );
 161  
 
 162  0
             if ( password != null )
 163  
             {
 164  0
                 this.password = password;
 165  
 
 166  0
                 username += ":" + password;
 167  
             }
 168  
 
 169  0
             username += "@";
 170  
 
 171  0
             int index = url.indexOf( username );
 172  0
             this.url = url.substring( 0, index ) + url.substring( index + username.length() );
 173  
         }
 174  0
     }
 175  
 
 176  
     public String getUrl()
 177  
     {
 178  0
         if ( url != null )
 179  
         {
 180  0
             return url;
 181  
         }
 182  
 
 183  0
         StringBuffer sb = new StringBuffer();
 184  
 
 185  0
         sb.append( protocol );
 186  
 
 187  0
         sb.append( "://" );
 188  
 
 189  0
         sb.append( host );
 190  
 
 191  0
         if ( port != WagonConstants.UNKNOWN_PORT )
 192  
         {
 193  0
             sb.append( ":" );
 194  
 
 195  0
             sb.append( port );
 196  
         }
 197  
 
 198  0
         sb.append( basedir );
 199  
 
 200  0
         return sb.toString();
 201  
     }
 202  
 
 203  
     public String getHost()
 204  
     {
 205  0
         if ( host == null )
 206  
         {
 207  0
             return "localhost";
 208  
         }
 209  0
         return host;
 210  
     }
 211  
 
 212  
     public String getName()
 213  
     {
 214  0
         if ( name == null )
 215  
         {
 216  0
             return getId();
 217  
         }
 218  0
         return name;
 219  
     }
 220  
 
 221  
     public String toString()
 222  
     {
 223  0
         StringBuffer sb = new StringBuffer();
 224  
 
 225  0
         sb.append( "Repository[" );
 226  
 
 227  0
         if ( StringUtils.isNotEmpty( getName() ) )
 228  
         {
 229  0
             sb.append( getName() ).append( "|" );
 230  
         }
 231  
 
 232  0
         sb.append( getUrl() );
 233  0
         sb.append( "]" );
 234  
 
 235  0
         return sb.toString();
 236  
     }
 237  
 
 238  
     public String getProtocol()
 239  
     {
 240  0
         return protocol;
 241  
     }
 242  
 
 243  
     public RepositoryPermissions getPermissions()
 244  
     {
 245  0
         return permissions;
 246  
     }
 247  
 
 248  
     public void setPermissions( RepositoryPermissions permissions )
 249  
     {
 250  0
         this.permissions = permissions;
 251  0
     }
 252  
 
 253  
     public String getParameter( String key )
 254  
     {
 255  0
         return parameters.getProperty( key );
 256  
     }
 257  
 
 258  
     public void setParameters( Properties parameters )
 259  
     {
 260  0
         this.parameters = parameters;
 261  0
     }
 262  
 
 263  
     public int hashCode()
 264  
     {
 265  0
         final int prime = 31;
 266  0
         int result = 1;
 267  0
         result = prime * result + ( ( id == null ) ? 0 : id.hashCode() );
 268  0
         return result;
 269  
     }
 270  
 
 271  
     public boolean equals( Object obj )
 272  
     {
 273  0
         if ( this == obj )
 274  
         {
 275  0
             return true;
 276  
         }
 277  0
         if ( obj == null )
 278  
         {
 279  0
             return false;
 280  
         }
 281  0
         if ( getClass() != obj.getClass() )
 282  
         {
 283  0
             return false;
 284  
         }
 285  0
         final Repository other = (Repository) obj;
 286  0
         if ( id == null )
 287  
         {
 288  0
             if ( other.id != null )
 289  
             {
 290  0
                 return false;
 291  
             }
 292  
         }
 293  0
         else if ( !id.equals( other.id ) )
 294  
         {
 295  0
             return false;
 296  
         }
 297  0
         return true;
 298  
     }
 299  
 
 300  
     public String getUsername()
 301  
     {
 302  0
         return username;
 303  
     }
 304  
 
 305  
     public String getPassword()
 306  
     {
 307  0
         return password;
 308  
     }
 309  
 
 310  
     public void setProtocol( String protocol )
 311  
     {
 312  0
         this.protocol = protocol;
 313  0
     }
 314  
 
 315  
 }