View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.repository;
20  
21  import java.nio.file.Path;
22  
23  import org.eclipse.aether.RepositorySystemSession;
24  import org.eclipse.aether.artifact.Artifact;
25  import org.eclipse.aether.metadata.Metadata;
26  
27  /**
28   * Manages access to a local repository.
29   *
30   * @see RepositorySystemSession#getLocalRepositoryManager()
31   * @see org.eclipse.aether.RepositorySystem#newLocalRepositoryManager(RepositorySystemSession, LocalRepository)
32   */
33  public interface LocalRepositoryManager {
34  
35      /**
36       * Gets the description of the local repository being managed.
37       *
38       * @return The description of the local repository, never {@code null}.
39       */
40      LocalRepository getRepository();
41  
42      /**
43       * Gets the absolute path for a locally installed artifact. Note that the artifact need not actually exist yet at
44       * the returned location, the path merely indicates where the artifact would eventually be stored.
45       *
46       * @param artifact The artifact for which to determine the path, must not be {@code null}.
47       * @return The path, relative to the local repository's base directory.
48       * @since 2.0.5
49       */
50      default Path getAbsolutePathForLocalArtifact(Artifact artifact) {
51          return getRepository().getBasePath().resolve(getPathForLocalArtifact(artifact));
52      }
53  
54      /**
55       * Gets the relative path for a locally installed artifact. Note that the artifact need not actually exist yet at
56       * the returned location, the path merely indicates where the artifact would eventually be stored. The path uses the
57       * forward slash as directory separator regardless of the underlying file system.
58       *
59       * @param artifact The artifact for which to determine the path, must not be {@code null}.
60       * @return The path, relative to the local repository's base directory.
61       * @deprecated See {@link #getAbsolutePathForLocalArtifact(Artifact)}
62       */
63      @Deprecated
64      String getPathForLocalArtifact(Artifact artifact);
65  
66      /**
67       * Gets the absolute path for an artifact cached from a remote repository. Note that the artifact need not actually
68       * exist yet at the returned location, the path merely indicates where the artifact would eventually be stored.
69       *
70       * @param artifact The artifact for which to determine the path, must not be {@code null}.
71       * @param repository The source repository of the artifact, must not be {@code null}.
72       * @param context The resolution context in which the artifact is being requested, may be {@code null}.
73       * @return The path, relative to the local repository's base directory.
74       * @since 2.0.5
75       */
76      default Path getAbsolutePathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
77          return getRepository().getBasePath().resolve(getPathForRemoteArtifact(artifact, repository, context));
78      }
79  
80      /**
81       * Gets the relative path for an artifact cached from a remote repository. Note that the artifact need not actually
82       * exist yet at the returned location, the path merely indicates where the artifact would eventually be stored. The
83       * path uses the forward slash as directory separator regardless of the underlying file system.
84       *
85       * @param artifact The artifact for which to determine the path, must not be {@code null}.
86       * @param repository The source repository of the artifact, must not be {@code null}.
87       * @param context The resolution context in which the artifact is being requested, may be {@code null}.
88       * @return The path, relative to the local repository's base directory.
89       * @deprecated See {@link #getAbsolutePathForRemoteArtifact(Artifact, RemoteRepository, String)}
90       */
91      @Deprecated
92      String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context);
93  
94      /**
95       * Gets the absolute path for locally installed metadata. Note that the metadata need not actually exist yet at the
96       * returned location, the path merely indicates where the metadata would eventually be stored.
97       *
98       * @param metadata The metadata for which to determine the path, must not be {@code null}.
99       * @return The path, relative to the local repository's base directory.
100      * @since 2.0.5
101      */
102     default Path getAbsolutePathForLocalMetadata(Metadata metadata) {
103         return getRepository().getBasePath().resolve(getPathForLocalMetadata(metadata));
104     }
105 
106     /**
107      * Gets the relative path for locally installed metadata. Note that the metadata need not actually exist yet at the
108      * returned location, the path merely indicates where the metadata would eventually be stored. The path uses the
109      * forward slash as directory separator regardless of the underlying file system.
110      *
111      * @param metadata The metadata for which to determine the path, must not be {@code null}.
112      * @return The path, relative to the local repository's base directory.
113      * @deprecated See {@link #getAbsolutePathForLocalMetadata(Metadata)}
114      */
115     @Deprecated
116     String getPathForLocalMetadata(Metadata metadata);
117 
118     /**
119      * Gets the absolute path for metadata cached from a remote repository. Note that the metadata need not actually
120      * exist yet at the returned location, the path merely indicates where the metadata would eventually be stored.
121      *
122      * @param metadata The metadata for which to determine the path, must not be {@code null}.
123      * @param repository The source repository of the metadata, must not be {@code null}.
124      * @param context The resolution context in which the metadata is being requested, may be {@code null}.
125      * @return The path, relative to the local repository's base directory.
126      * @since 2.0.5
127      */
128     default Path getAbsolutePathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
129         return getRepository().getBasePath().resolve(getPathForRemoteMetadata(metadata, repository, context));
130     }
131 
132     /**
133      * Gets the relative path for metadata cached from a remote repository. Note that the metadata need not actually
134      * exist yet at the returned location, the path merely indicates where the metadata would eventually be stored. The
135      * path uses the forward slash as directory separator regardless of the underlying file system.
136      *
137      * @param metadata The metadata for which to determine the path, must not be {@code null}.
138      * @param repository The source repository of the metadata, must not be {@code null}.
139      * @param context The resolution context in which the metadata is being requested, may be {@code null}.
140      * @return The path, relative to the local repository's base directory.
141      * @deprecated See {@link #getAbsolutePathForRemoteMetadata(Metadata, RemoteRepository, String)}
142      */
143     @Deprecated
144     String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context);
145 
146     /**
147      * Queries for the existence of an artifact in the local repository. The request could be satisfied by a locally
148      * installed artifact or a previously downloaded artifact.
149      *
150      * @param session The repository system session during which the request is made, must not be {@code null}.
151      * @param request The artifact request, must not be {@code null}.
152      * @return The result of the request, never {@code null}.
153      */
154     LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request);
155 
156     /**
157      * Registers an installed or resolved artifact with the local repository. Note that artifact registration is merely
158      * concerned about updating the local repository's internal state, not about actually installing the artifact or its
159      * accompanying metadata.
160      *
161      * @param session The repository system session during which the registration is made, must not be {@code null}.
162      * @param request The registration request, must not be {@code null}.
163      */
164     void add(RepositorySystemSession session, LocalArtifactRegistration request);
165 
166     /**
167      * Queries for the existence of metadata in the local repository. The request could be satisfied by locally
168      * installed or previously downloaded metadata.
169      *
170      * @param session The repository system session during which the request is made, must not be {@code null}.
171      * @param request The metadata request, must not be {@code null}.
172      * @return The result of the request, never {@code null}.
173      */
174     LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request);
175 
176     /**
177      * Registers installed or resolved metadata with the local repository. Note that metadata registration is merely
178      * concerned about updating the local repository's internal state, not about actually installing the metadata.
179      * However, this method MUST be called after the actual install to give the repository manager the opportunity to
180      * inspect the added metadata.
181      *
182      * @param session The repository system session during which the registration is made, must not be {@code null}.
183      * @param request The registration request, must not be {@code null}.
184      */
185     void add(RepositorySystemSession session, LocalMetadataRegistration request);
186 }