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