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