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