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.io.File; 22 import java.nio.file.Path; 23 24 import static java.util.Objects.requireNonNull; 25 26 /** 27 * A result from the local repository about the existence of metadata. 28 * 29 * @see LocalRepositoryManager#find(org.eclipse.aether.RepositorySystemSession, LocalMetadataRequest) 30 */ 31 public final class LocalMetadataResult { 32 33 private final LocalMetadataRequest request; 34 35 private Path path; 36 37 private boolean stale; 38 39 /** 40 * Creates a new result for the specified request. 41 * 42 * @param request The local metadata request, must not be {@code null}. 43 */ 44 public LocalMetadataResult(LocalMetadataRequest request) { 45 this.request = requireNonNull(request, "local metadata request cannot be null"); 46 } 47 48 /** 49 * Gets the request corresponding to this result. 50 * 51 * @return The corresponding request, never {@code null}. 52 */ 53 public LocalMetadataRequest getRequest() { 54 return request; 55 } 56 57 /** 58 * Gets the file to the requested metadata if the metadata is available in the local repository. 59 * 60 * @return The file to the requested metadata or {@code null}. 61 * @deprecated Use {@link #getPath()} instead. 62 */ 63 @Deprecated 64 public File getFile() { 65 return path != null ? path.toFile() : null; 66 } 67 68 /** 69 * Gets the file to the requested metadata if the metadata is available in the local repository. 70 * 71 * @return The file to the requested metadata or {@code null}. 72 * @since 2.0.0 73 */ 74 public Path getPath() { 75 return path; 76 } 77 78 /** 79 * Sets the file to requested metadata. 80 * 81 * @param file The metadata file, may be {@code null}. 82 * @return This result for chaining, never {@code null}. 83 * @deprecated Use {@link #setPath(Path)} instead. 84 */ 85 @Deprecated 86 public LocalMetadataResult setFile(File file) { 87 return setPath(file != null ? file.toPath() : null); 88 } 89 90 /** 91 * Sets the file to requested metadata. 92 * 93 * @param path The metadata file, may be {@code null}. 94 * @return This result for chaining, never {@code null}. 95 * @since 2.0.0 96 */ 97 public LocalMetadataResult setPath(Path path) { 98 this.path = path; 99 return this; 100 } 101 102 /** 103 * This value indicates whether the metadata is stale and should be updated. 104 * 105 * @return {@code true} if the metadata is stale and should be updated, {@code false} otherwise. 106 */ 107 public boolean isStale() { 108 return stale; 109 } 110 111 /** 112 * Sets whether the metadata is stale. 113 * 114 * @param stale {@code true} if the metadata is stale and should be updated, {@code false} otherwise. 115 * @return This result for chaining, never {@code null}. 116 */ 117 public LocalMetadataResult setStale(boolean stale) { 118 this.stale = stale; 119 return this; 120 } 121 122 @Override 123 public String toString() { 124 return request.toString() + "(" + getPath() + ")"; 125 } 126 }