]> git.argeo.org Git - gpl/argeo-slc.git/blob - LocalRepository.java
91b09d8b17f76e2ad121d10b74d031b7207eeb2b
[gpl/argeo-slc.git] / LocalRepository.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 Sonatype, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.aether.repository;
12
13 import java.io.File;
14
15 /**
16 * A repository on the local file system used to cache contents of remote repositories and to store locally installed
17 * artifacts. Note that this class merely describes such a repository, actual access to the contained artifacts is
18 * handled by a {@link LocalRepositoryManager} which is usually determined from the {@link #getContentType() type} of
19 * the repository.
20 */
21 public final class LocalRepository
22 implements ArtifactRepository
23 {
24
25 private final File basedir;
26
27 private final String type;
28
29 /**
30 * Creates a new local repository with the specified base directory and unknown type.
31 *
32 * @param basedir The base directory of the repository, may be {@code null}.
33 */
34 public LocalRepository( String basedir )
35 {
36 this( ( basedir != null ) ? new File( basedir ) : null, "" );
37 }
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( File basedir )
45 {
46 this( basedir, "" );
47 }
48
49 /**
50 * Creates a new local repository with the specified properties.
51 *
52 * @param basedir The base directory of the repository, may be {@code null}.
53 * @param type The type of the repository, may be {@code null}.
54 */
55 public LocalRepository( File basedir, String type )
56 {
57 this.basedir = basedir;
58 this.type = ( type != null ) ? type : "";
59 }
60
61 public String getContentType()
62 {
63 return type;
64 }
65
66 public String getId()
67 {
68 return "local";
69 }
70
71 /**
72 * Gets the base directory of the repository.
73 *
74 * @return The base directory or {@code null} if none.
75 */
76 public File getBasedir()
77 {
78 return basedir;
79 }
80
81 @Override
82 public String toString()
83 {
84 return getBasedir() + " (" + getContentType() + ")";
85 }
86
87 @Override
88 public boolean equals( Object obj )
89 {
90 if ( this == obj )
91 {
92 return true;
93 }
94 if ( obj == null || !getClass().equals( obj.getClass() ) )
95 {
96 return false;
97 }
98
99 LocalRepository that = (LocalRepository) obj;
100
101 return eq( basedir, that.basedir ) && eq( type, that.type );
102 }
103
104 private static <T> boolean eq( T s1, T s2 )
105 {
106 return s1 != null ? s1.equals( s2 ) : s2 == null;
107 }
108
109 @Override
110 public int hashCode()
111 {
112 int hash = 17;
113 hash = hash * 31 + hash( basedir );
114 hash = hash * 31 + hash( type );
115 return hash;
116 }
117
118 private static int hash( Object obj )
119 {
120 return obj != null ? obj.hashCode() : 0;
121 }
122
123 }