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.io.File; 23 24 import org.eclipse.aether.RepositorySystemSession; 25 26 /** 27 * A result from the local repository about the existence of an artifact. 28 * 29 * @see LocalRepositoryManager#find(RepositorySystemSession, LocalArtifactRequest) 30 */ 31 public final class LocalArtifactResult 32 { 33 34 private final LocalArtifactRequest request; 35 36 private File file; 37 38 private boolean available; 39 40 private RemoteRepository repository; 41 42 /** 43 * Creates a new result for the specified request. 44 * 45 * @param request The local artifact request, must not be {@code null}. 46 */ 47 public LocalArtifactResult( LocalArtifactRequest request ) 48 { 49 if ( request == null ) 50 { 51 throw new IllegalArgumentException( "local artifact request has not been specified" ); 52 } 53 this.request = request; 54 } 55 56 /** 57 * Gets the request corresponding to this result. 58 * 59 * @return The corresponding request, never {@code null}. 60 */ 61 public LocalArtifactRequest getRequest() 62 { 63 return request; 64 } 65 66 /** 67 * Gets the file to the requested artifact. Note that this file must not be used unless {@link #isAvailable()} 68 * returns {@code true}. An artifact file can be found but considered unavailable if the artifact was cached from a 69 * remote repository that is not part of the list of remote repositories used for the query. 70 * 71 * @return The file to the requested artifact or {@code null} if the artifact does not exist locally. 72 */ 73 public File getFile() 74 { 75 return file; 76 } 77 78 /** 79 * Sets the file to requested artifact. 80 * 81 * @param file The artifact file, may be {@code null}. 82 * @return This result for chaining, never {@code null}. 83 */ 84 public LocalArtifactResult setFile( File file ) 85 { 86 this.file = file; 87 return this; 88 } 89 90 /** 91 * Indicates whether the requested artifact is available for use. As a minimum, the file needs to be physically 92 * existent in the local repository to be available. Additionally, a local repository manager can consider the list 93 * of supplied remote repositories to determine whether the artifact is logically available and mark an artifact 94 * unavailable (despite its physical existence) if it is not known to be hosted by any of the provided repositories. 95 * 96 * @return {@code true} if the artifact is available, {@code false} otherwise. 97 * @see LocalArtifactRequest#getRepositories() 98 */ 99 public boolean isAvailable() 100 { 101 return available; 102 } 103 104 /** 105 * Sets whether the artifact is available. 106 * 107 * @param available {@code true} if the artifact is available, {@code false} otherwise. 108 * @return This result for chaining, never {@code null}. 109 */ 110 public LocalArtifactResult setAvailable( boolean available ) 111 { 112 this.available = available; 113 return this; 114 } 115 116 /** 117 * Gets the (first) remote repository from which the artifact was cached (if any). 118 * 119 * @return The remote repository from which the artifact was originally retrieved or {@code null} if unknown or if 120 * the artifact has been locally installed. 121 * @see LocalArtifactRequest#getRepositories() 122 */ 123 public RemoteRepository getRepository() 124 { 125 return repository; 126 } 127 128 /** 129 * Sets the (first) remote repository from which the artifact was cached. 130 * 131 * @param repository The remote repository from which the artifact was originally retrieved, may be {@code null} if 132 * unknown or if the artifact has been locally installed. 133 * @return This result for chaining, never {@code null}. 134 */ 135 public LocalArtifactResult setRepository( RemoteRepository repository ) 136 { 137 this.repository = repository; 138 return this; 139 } 140 141 @Override 142 public String toString() 143 { 144 return getFile() + " (" + ( isAvailable() ? "available" : "unavailable" ) + ")"; 145 } 146 147 }