1 /*******************************************************************************
2 * Copyright (c) 2010, 2011 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
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.aether
.repository
;
15 import org
.eclipse
.aether
.RepositorySystemSession
;
18 * A result from the local repository about the existence of an artifact.
20 * @see LocalRepositoryManager#find(RepositorySystemSession, LocalArtifactRequest)
22 public final class LocalArtifactResult
25 private final LocalArtifactRequest request
;
29 private boolean available
;
31 private RemoteRepository repository
;
34 * Creates a new result for the specified request.
36 * @param request The local artifact request, must not be {@code null}.
38 public LocalArtifactResult( LocalArtifactRequest request
)
40 if ( request
== null )
42 throw new IllegalArgumentException( "local artifact request has not been specified" );
44 this.request
= request
;
48 * Gets the request corresponding to this result.
50 * @return The corresponding request, never {@code null}.
52 public LocalArtifactRequest
getRequest()
58 * Gets the file to the requested artifact. Note that this file must not be used unless {@link #isAvailable()}
59 * returns {@code true}. An artifact file can be found but considered unavailable if the artifact was cached from a
60 * remote repository that is not part of the list of remote repositories used for the query.
62 * @return The file to the requested artifact or {@code null} if the artifact does not exist locally.
70 * Sets the file to requested artifact.
72 * @param file The artifact file, may be {@code null}.
73 * @return This result for chaining, never {@code null}.
75 public LocalArtifactResult
setFile( File file
)
82 * Indicates whether the requested artifact is available for use. As a minimum, the file needs to be physically
83 * existent in the local repository to be available. Additionally, a local repository manager can consider the list
84 * of supplied remote repositories to determine whether the artifact is logically available and mark an artifact
85 * unavailable (despite its physical existence) if it is not known to be hosted by any of the provided repositories.
87 * @return {@code true} if the artifact is available, {@code false} otherwise.
88 * @see LocalArtifactRequest#getRepositories()
90 public boolean isAvailable()
96 * Sets whether the artifact is available.
98 * @param available {@code true} if the artifact is available, {@code false} otherwise.
99 * @return This result for chaining, never {@code null}.
101 public LocalArtifactResult
setAvailable( boolean available
)
103 this.available
= available
;
108 * Gets the (first) remote repository from which the artifact was cached (if any).
110 * @return The remote repository from which the artifact was originally retrieved or {@code null} if unknown or if
111 * the artifact has been locally installed.
112 * @see LocalArtifactRequest#getRepositories()
114 public RemoteRepository
getRepository()
120 * Sets the (first) remote repository from which the artifact was cached.
122 * @param repository The remote repository from which the artifact was originally retrieved, may be {@code null} if
123 * unknown or if the artifact has been locally installed.
124 * @return This result for chaining, never {@code null}.
126 public LocalArtifactResult
setRepository( RemoteRepository repository
)
128 this.repository
= repository
;
133 public String
toString()
135 return getFile() + " (" + ( isAvailable() ?
"available" : "unavailable" ) + ")";