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