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 org.eclipse.aether.RepositorySystemSession;
022import org.eclipse.aether.artifact.Artifact;
023import org.eclipse.aether.metadata.Metadata;
024
025/**
026 * Manages access to a local repository.
027 *
028 * @see RepositorySystemSession#getLocalRepositoryManager()
029 * @see org.eclipse.aether.RepositorySystem#newLocalRepositoryManager(RepositorySystemSession, LocalRepository)
030 */
031public interface LocalRepositoryManager {
032
033    /**
034     * Gets the description of the local repository being managed.
035     *
036     * @return The description of the local repository, never {@code null}.
037     */
038    LocalRepository getRepository();
039
040    /**
041     * Gets the relative path for a locally installed artifact. Note that the artifact need not actually exist yet at
042     * the returned location, the path merely indicates where the artifact would eventually be stored. The path uses the
043     * forward slash as directory separator regardless of the underlying file system.
044     *
045     * @param artifact The artifact for which to determine the path, must not be {@code null}.
046     * @return The path, relative to the local repository's base directory.
047     */
048    String getPathForLocalArtifact(Artifact artifact);
049
050    /**
051     * Gets the relative path for an artifact cached from a remote repository. Note that the artifact need not actually
052     * exist yet at the returned location, the path merely indicates where the artifact would eventually be stored. The
053     * path uses the forward slash as directory separator regardless of the underlying file system.
054     *
055     * @param artifact The artifact for which to determine the path, must not be {@code null}.
056     * @param repository The source repository of the artifact, must not be {@code null}.
057     * @param context The resolution context in which the artifact is being requested, may be {@code null}.
058     * @return The path, relative to the local repository's base directory.
059     */
060    String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context);
061
062    /**
063     * Gets the relative path for locally installed metadata. Note that the metadata need not actually exist yet at the
064     * returned location, the path merely indicates where the metadata would eventually be stored. The path uses the
065     * forward slash as directory separator regardless of the underlying file system.
066     *
067     * @param metadata The metadata for which to determine the path, must not be {@code null}.
068     * @return The path, relative to the local repository's base directory.
069     */
070    String getPathForLocalMetadata(Metadata metadata);
071
072    /**
073     * Gets the relative path for metadata cached from a remote repository. Note that the metadata need not actually
074     * exist yet at the returned location, the path merely indicates where the metadata would eventually be stored. The
075     * path uses the forward slash as directory separator regardless of the underlying file system.
076     *
077     * @param metadata The metadata for which to determine the path, must not be {@code null}.
078     * @param repository The source repository of the metadata, must not be {@code null}.
079     * @param context The resolution context in which the metadata is being requested, may be {@code null}.
080     * @return The path, relative to the local repository's base directory.
081     */
082    String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context);
083
084    /**
085     * Queries for the existence of an artifact in the local repository. The request could be satisfied by a locally
086     * installed artifact or a previously downloaded artifact.
087     *
088     * @param session The repository system session during which the request is made, must not be {@code null}.
089     * @param request The artifact request, must not be {@code null}.
090     * @return The result of the request, never {@code null}.
091     */
092    LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request);
093
094    /**
095     * Registers an installed or resolved artifact with the local repository. Note that artifact registration is merely
096     * concerned about updating the local repository's internal state, not about actually installing the artifact or its
097     * accompanying metadata.
098     *
099     * @param session The repository system session during which the registration is made, must not be {@code null}.
100     * @param request The registration request, must not be {@code null}.
101     */
102    void add(RepositorySystemSession session, LocalArtifactRegistration request);
103
104    /**
105     * Queries for the existence of metadata in the local repository. The request could be satisfied by locally
106     * installed or previously downloaded metadata.
107     *
108     * @param session The repository system session during which the request is made, must not be {@code null}.
109     * @param request The metadata request, must not be {@code null}.
110     * @return The result of the request, never {@code null}.
111     */
112    LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request);
113
114    /**
115     * Registers installed or resolved metadata with the local repository. Note that metadata registration is merely
116     * concerned about updating the local repository's internal state, not about actually installing the metadata.
117     * However, this method MUST be called after the actual install to give the repository manager the opportunity to
118     * inspect the added metadata.
119     *
120     * @param session The repository system session during which the registration is made, must not be {@code null}.
121     * @param request The registration request, must not be {@code null}.
122     */
123    void add(RepositorySystemSession session, LocalMetadataRegistration request);
124}