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.util.Collections;
22 import java.util.List;
23
24 import org.eclipse.aether.artifact.Artifact;
25
26 /**
27 * A query to the local repository for the existence of an artifact.
28 *
29 * @see LocalRepositoryManager#find(org.eclipse.aether.RepositorySystemSession, LocalArtifactRequest)
30 */
31 public final class LocalArtifactRequest {
32
33 private Artifact artifact;
34
35 private String context = "";
36
37 private List<RemoteRepository> repositories = Collections.emptyList();
38
39 /**
40 * Creates an uninitialized query.
41 */
42 public LocalArtifactRequest() {
43 // enables default constructor
44 }
45
46 /**
47 * Creates a query with the specified properties.
48 *
49 * @param artifact The artifact to query for, may be {@code null}.
50 * @param repositories The remote repositories that should be considered as potential sources for the artifact, may
51 * be {@code null} or empty to only consider locally installed artifacts.
52 * @param context The resolution context for the artifact, may be {@code null}.
53 */
54 public LocalArtifactRequest(Artifact artifact, List<RemoteRepository> repositories, String context) {
55 setArtifact(artifact);
56 setRepositories(repositories);
57 setContext(context);
58 }
59
60 /**
61 * Gets the artifact to query for.
62 *
63 * @return The artifact or {@code null} if not set.
64 */
65 public Artifact getArtifact() {
66 return artifact;
67 }
68
69 /**
70 * Sets the artifact to query for.
71 *
72 * @param artifact The artifact, may be {@code null}.
73 * @return This query for chaining, never {@code null}.
74 */
75 public LocalArtifactRequest setArtifact(Artifact artifact) {
76 this.artifact = artifact;
77 return this;
78 }
79
80 /**
81 * Gets the resolution context.
82 *
83 * @return The resolution context, never {@code null}.
84 */
85 public String getContext() {
86 return context;
87 }
88
89 /**
90 * Sets the resolution context.
91 *
92 * @param context The resolution context, may be {@code null}.
93 * @return This query for chaining, never {@code null}.
94 */
95 public LocalArtifactRequest setContext(String context) {
96 this.context = (context != null) ? context : "";
97 return this;
98 }
99
100 /**
101 * Gets the remote repositories to consider as sources of the artifact.
102 *
103 * @return The remote repositories, never {@code null}.
104 */
105 public List<RemoteRepository> getRepositories() {
106 return repositories;
107 }
108
109 /**
110 * Sets the remote repositories to consider as sources of the artifact.
111 *
112 * @param repositories The remote repositories, may be {@code null} or empty to only consider locally installed
113 * artifacts.
114 * @return This query for chaining, never {@code null}.
115 */
116 public LocalArtifactRequest setRepositories(List<RemoteRepository> repositories) {
117 if (repositories != null) {
118 this.repositories = repositories;
119 } else {
120 this.repositories = Collections.emptyList();
121 }
122 return this;
123 }
124
125 @Override
126 public String toString() {
127 return getArtifact() + " @ " + getRepositories();
128 }
129 }