1 package org.eclipse.aether.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 java.io.File; 23 import java.util.Objects; 24 25 /** 26 * A repository on the local file system used to cache contents of remote repositories and to store locally installed 27 * artifacts. Note that this class merely describes such a repository, actual access to the contained artifacts is 28 * handled by a {@link LocalRepositoryManager} which is usually determined from the {@link #getContentType() type} of 29 * the repository. 30 */ 31 public final class LocalRepository 32 implements ArtifactRepository 33 { 34 35 private final File basedir; 36 37 private final String type; 38 39 /** 40 * Creates a new local repository with the specified base directory and unknown type. 41 * 42 * @param basedir The base directory of the repository, may be {@code null}. 43 */ 44 public LocalRepository( String basedir ) 45 { 46 this( ( basedir != null ) ? new File( basedir ) : null, "" ); 47 } 48 49 /** 50 * Creates a new local repository with the specified base directory and unknown type. 51 * 52 * @param basedir The base directory of the repository, may be {@code null}. 53 */ 54 public LocalRepository( File basedir ) 55 { 56 this( basedir, "" ); 57 } 58 59 /** 60 * Creates a new local repository with the specified properties. 61 * 62 * @param basedir The base directory of the repository, may be {@code null}. 63 * @param type The type of the repository, may be {@code null}. 64 */ 65 public LocalRepository( File basedir, String type ) 66 { 67 this.basedir = basedir; 68 this.type = ( type != null ) ? type : ""; 69 } 70 71 public String getContentType() 72 { 73 return type; 74 } 75 76 public String getId() 77 { 78 return "local"; 79 } 80 81 /** 82 * Gets the base directory of the repository. 83 * 84 * @return The base directory or {@code null} if none. 85 */ 86 public File getBasedir() 87 { 88 return basedir; 89 } 90 91 @Override 92 public String toString() 93 { 94 return getBasedir() + " (" + getContentType() + ")"; 95 } 96 97 @Override 98 public boolean equals( Object obj ) 99 { 100 if ( this == obj ) 101 { 102 return true; 103 } 104 if ( obj == null || !getClass().equals( obj.getClass() ) ) 105 { 106 return false; 107 } 108 109 LocalRepository that = (LocalRepository) obj; 110 111 return Objects.equals( basedir, that.basedir ) && Objects.equals( type, that.type ); 112 } 113 114 @Override 115 public int hashCode() 116 { 117 int hash = 17; 118 hash = hash * 31 + hash( basedir ); 119 hash = hash * 31 + hash( type ); 120 return hash; 121 } 122 123 private static int hash( Object obj ) 124 { 125 return obj != null ? obj.hashCode() : 0; 126 } 127 128 }