001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.repository;
020
021import java.nio.file.Path;
022
023import org.eclipse.aether.RepositorySystemSession;
024import org.eclipse.aether.artifact.Artifact;
025import org.eclipse.aether.metadata.Metadata;
026
027/**
028 * Manages access to a local repository.
029 *
030 * @see RepositorySystemSession#getLocalRepositoryManager()
031 * @see org.eclipse.aether.RepositorySystem#newLocalRepositoryManager(RepositorySystemSession, LocalRepository)
032 */
033public interface LocalRepositoryManager {
034
035    /**
036     * Gets the description of the local repository being managed.
037     *
038     * @return The description of the local repository, never {@code null}.
039     */
040    LocalRepository getRepository();
041
042    /**
043     * Gets the absolute path for a locally installed artifact. Note that the artifact need not actually exist yet at
044     * the returned location, the path merely indicates where the artifact would eventually be stored.
045     *
046     * @param artifact The artifact for which to determine the path, must not be {@code null}.
047     * @return The path, relative to the local repository's base directory.
048     * @since 2.0.5
049     */
050    default Path getAbsolutePathForLocalArtifact(Artifact artifact) {
051        return getRepository().getBasePath().resolve(getPathForLocalArtifact(artifact));
052    }
053
054    /**
055     * Gets the relative path for a locally installed artifact. Note that the artifact need not actually exist yet at
056     * the returned location, the path merely indicates where the artifact would eventually be stored. The path uses the
057     * forward slash as directory separator regardless of the underlying file system.
058     *
059     * @param artifact The artifact for which to determine the path, must not be {@code null}.
060     * @return The path, relative to the local repository's base directory.
061     * @deprecated See {@link #getAbsolutePathForLocalArtifact(Artifact)}
062     */
063    @Deprecated
064    String getPathForLocalArtifact(Artifact artifact);
065
066    /**
067     * Gets the absolute path for an artifact cached from a remote repository. Note that the artifact need not actually
068     * exist yet at the returned location, the path merely indicates where the artifact would eventually be stored.
069     *
070     * @param artifact The artifact for which to determine the path, must not be {@code null}.
071     * @param repository The source repository of the artifact, must not be {@code null}.
072     * @param context The resolution context in which the artifact is being requested, may be {@code null}.
073     * @return The path, relative to the local repository's base directory.
074     * @since 2.0.5
075     */
076    default Path getAbsolutePathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
077        return getRepository().getBasePath().resolve(getPathForRemoteArtifact(artifact, repository, context));
078    }
079
080    /**
081     * Gets the relative path for an artifact cached from a remote repository. Note that the artifact need not actually
082     * exist yet at the returned location, the path merely indicates where the artifact would eventually be stored. The
083     * path uses the forward slash as directory separator regardless of the underlying file system.
084     *
085     * @param artifact The artifact for which to determine the path, must not be {@code null}.
086     * @param repository The source repository of the artifact, must not be {@code null}.
087     * @param context The resolution context in which the artifact is being requested, may be {@code null}.
088     * @return The path, relative to the local repository's base directory.
089     * @deprecated See {@link #getAbsolutePathForRemoteArtifact(Artifact, RemoteRepository, String)}
090     */
091    @Deprecated
092    String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context);
093
094    /**
095     * Gets the absolute path for locally installed metadata. Note that the metadata need not actually exist yet at the
096     * returned location, the path merely indicates where the metadata would eventually be stored.
097     *
098     * @param metadata The metadata for which to determine the path, must not be {@code null}.
099     * @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}