001package org.eclipse.aether.repository; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.Collections; 023import java.util.List; 024 025import org.eclipse.aether.RepositorySystemSession; 026import org.eclipse.aether.artifact.Artifact; 027 028/** 029 * A query to the local repository for the existence of an artifact. 030 * 031 * @see LocalRepositoryManager#find(RepositorySystemSession, LocalArtifactRequest) 032 */ 033public final class LocalArtifactRequest 034{ 035 036 private Artifact artifact; 037 038 private String context = ""; 039 040 private List<RemoteRepository> repositories = Collections.emptyList(); 041 042 /** 043 * Creates an uninitialized query. 044 */ 045 public LocalArtifactRequest() 046 { 047 // enables default constructor 048 } 049 050 /** 051 * Creates a query with the specified properties. 052 * 053 * @param artifact The artifact to query for, may be {@code null}. 054 * @param repositories The remote repositories that should be considered as potential sources for the artifact, may 055 * be {@code null} or empty to only consider locally installed artifacts. 056 * @param context The resolution context for the artifact, may be {@code null}. 057 */ 058 public LocalArtifactRequest( Artifact artifact, List<RemoteRepository> repositories, String context ) 059 { 060 setArtifact( artifact ); 061 setRepositories( repositories ); 062 setContext( context ); 063 } 064 065 /** 066 * Gets the artifact to query for. 067 * 068 * @return The artifact or {@code null} if not set. 069 */ 070 public Artifact getArtifact() 071 { 072 return artifact; 073 } 074 075 /** 076 * Sets the artifact to query for. 077 * 078 * @param artifact The artifact, may be {@code null}. 079 * @return This query for chaining, never {@code null}. 080 */ 081 public LocalArtifactRequest setArtifact( Artifact artifact ) 082 { 083 this.artifact = artifact; 084 return this; 085 } 086 087 /** 088 * Gets the resolution context. 089 * 090 * @return The resolution context, never {@code null}. 091 */ 092 public String getContext() 093 { 094 return context; 095 } 096 097 /** 098 * Sets the resolution context. 099 * 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}