]> git.argeo.org Git - gpl/argeo-slc.git/blob - WorkspaceRepository.java
811c589017640867af8089adda01c43bf5486f80
[gpl/argeo-slc.git] / WorkspaceRepository.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.util.UUID;
14
15 /**
16 * A repository backed by an IDE workspace, the output of a build session or similar ad-hoc collection of artifacts. As
17 * far as the repository system is concerned, a workspace repository is read-only, i.e. can only be used for artifact
18 * resolution but not installation/deployment. Note that this class merely describes such a repository, actual access to
19 * the contained artifacts is handled by a {@link WorkspaceReader}.
20 */
21 public final class WorkspaceRepository
22 implements ArtifactRepository
23 {
24
25 private final String type;
26
27 private final Object key;
28
29 /**
30 * Creates a new workspace repository of type {@code "workspace"} and a random key.
31 */
32 public WorkspaceRepository()
33 {
34 this( "workspace" );
35 }
36
37 /**
38 * Creates a new workspace repository with the specified type and a random key.
39 *
40 * @param type The type of the repository, may be {@code null}.
41 */
42 public WorkspaceRepository( String type )
43 {
44 this( type, null );
45 }
46
47 /**
48 * Creates a new workspace repository with the specified type and key. The key is used to distinguish one workspace
49 * from another and should be sensitive to the artifacts that are (potentially) available in the workspace.
50 *
51 * @param type The type of the repository, may be {@code null}.
52 * @param key The (comparison) key for the repository, may be {@code null} to generate a unique random key.
53 */
54 public WorkspaceRepository( String type, Object key )
55 {
56 this.type = ( type != null ) ? type : "";
57 this.key = ( key != null ) ? key : UUID.randomUUID().toString().replace( "-", "" );
58 }
59
60 public String getContentType()
61 {
62 return type;
63 }
64
65 public String getId()
66 {
67 return "workspace";
68 }
69
70 /**
71 * Gets the key of this workspace repository. The key is used to distinguish one workspace from another and should
72 * be sensitive to the artifacts that are (potentially) available in the workspace.
73 *
74 * @return The (comparison) key for this workspace repository, never {@code null}.
75 */
76 public Object getKey()
77 {
78 return key;
79 }
80
81 @Override
82 public String toString()
83 {
84 return "(" + 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 WorkspaceRepository that = (WorkspaceRepository) obj;
100
101 return getContentType().equals( that.getContentType() ) && getKey().equals( that.getKey() );
102 }
103
104 @Override
105 public int hashCode()
106 {
107 int hash = 17;
108 hash = hash * 31 + getKey().hashCode();
109 hash = hash * 31 + getContentType().hashCode();
110 return hash;
111 }
112
113 }