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