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.artifact.Artifact; 026 027/** 028 * A query to the local repository for the existence of an artifact. 029 * 030 * @see LocalRepositoryManager#find(org.eclipse.aether.RepositorySystemSession, LocalArtifactRequest) 031 */ 032public final class LocalArtifactRequest 033{ 034 035 private Artifact artifact; 036 037 private String context = ""; 038 039 private List<RemoteRepository> repositories = Collections.emptyList(); 040 041 /** 042 * Creates an uninitialized query. 043 */ 044 public LocalArtifactRequest() 045 { 046 // enables default constructor 047 } 048 049 /** 050 * Creates a query with the specified properties. 051 * 052 * @param artifact The artifact to query for, may be {@code null}. 053 * @param repositories The remote repositories that should be considered as potential sources for the artifact, may 054 * be {@code null} or empty to only consider locally installed artifacts. 055 * @param context The resolution context for the artifact, may be {@code null}. 056 */ 057 public LocalArtifactRequest( Artifact artifact, List<RemoteRepository> repositories, String context ) 058 { 059 setArtifact( artifact ); 060 setRepositories( repositories ); 061 setContext( context ); 062 } 063 064 /** 065 * Gets the artifact to query for. 066 * 067 * @return The artifact or {@code null} if not set. 068 */ 069 public Artifact getArtifact() 070 { 071 return artifact; 072 } 073 074 /** 075 * Sets the artifact to query for. 076 * 077 * @param artifact The artifact, may be {@code null}. 078 * @return This query for chaining, never {@code null}. 079 */ 080 public LocalArtifactRequest setArtifact( Artifact artifact ) 081 { 082 this.artifact = artifact; 083 return this; 084 } 085 086 /** 087 * Gets the resolution context. 088 * 089 * @return The resolution context, never {@code null}. 090 */ 091 public String getContext() 092 { 093 return context; 094 } 095 096 /** 097 * Sets the resolution context. 098 * 099 * @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}