View Javadoc
1   /*******************************************************************************
2    * Copyright (c) 2010, 2011 Sonatype, Inc.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *    Sonatype, Inc. - initial API and implementation
10   *******************************************************************************/
11  package org.eclipse.aether.repository;
12  
13  import java.util.Collections;
14  import java.util.List;
15  
16  import org.eclipse.aether.RepositorySystemSession;
17  import org.eclipse.aether.artifact.Artifact;
18  
19  /**
20   * A query to the local repository for the existence of an artifact.
21   * 
22   * @see LocalRepositoryManager#find(RepositorySystemSession, LocalArtifactRequest)
23   */
24  public final class LocalArtifactRequest
25  {
26  
27      private Artifact artifact;
28  
29      private String context = "";
30  
31      private List<RemoteRepository> repositories = Collections.emptyList();
32  
33      /**
34       * Creates an uninitialized query.
35       */
36      public LocalArtifactRequest()
37      {
38          // enables default constructor
39      }
40  
41      /**
42       * Creates a query with the specified properties.
43       * 
44       * @param artifact The artifact to query for, may be {@code null}.
45       * @param repositories The remote repositories that should be considered as potential sources for the artifact, may
46       *            be {@code null} or empty to only consider locally installed artifacts.
47       * @param context The resolution context for the artifact, may be {@code null}.
48       */
49      public LocalArtifactRequest( Artifact artifact, List<RemoteRepository> repositories, String context )
50      {
51          setArtifact( artifact );
52          setRepositories( repositories );
53          setContext( context );
54      }
55  
56      /**
57       * Gets the artifact to query for.
58       * 
59       * @return The artifact or {@code null} if not set.
60       */
61      public Artifact getArtifact()
62      {
63          return artifact;
64      }
65  
66      /**
67       * Sets the artifact to query for.
68       * 
69       * @param artifact The artifact, may be {@code null}.
70       * @return This query for chaining, never {@code null}.
71       */
72      public LocalArtifactRequest setArtifact( Artifact artifact )
73      {
74          this.artifact = artifact;
75          return this;
76      }
77  
78      /**
79       * Gets the resolution context.
80       * 
81       * @return The resolution context, never {@code null}.
82       */
83      public String getContext()
84      {
85          return context;
86      }
87  
88      /**
89       * Sets the resolution context.
90       * 
91       * @param context The resolution context, may be {@code null}.
92       * @return This query for chaining, never {@code null}.
93       */
94      public LocalArtifactRequest setContext( String context )
95      {
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     {
107         return repositories;
108     }
109 
110     /**
111      * Sets the remote repositories to consider as sources of the artifact.
112      * 
113      * @param repositories The remote repositories, may be {@code null} or empty to only consider locally installed
114      *            artifacts.
115      * @return This query for chaining, never {@code null}.
116      */
117     public LocalArtifactRequest setRepositories( List<RemoteRepository> repositories )
118     {
119         if ( repositories != null )
120         {
121             this.repositories = repositories;
122         }
123         else
124         {
125             this.repositories = Collections.emptyList();
126         }
127         return this;
128     }
129 
130     @Override
131     public String toString()
132     {
133         return getArtifact() + " @ " + getRepositories();
134     }
135 
136 }