001package org.eclipse.aether.deployment; 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.ArrayList; 023import java.util.Collection; 024import java.util.Collections; 025 026import org.eclipse.aether.RequestTrace; 027import org.eclipse.aether.artifact.Artifact; 028import org.eclipse.aether.metadata.Metadata; 029import org.eclipse.aether.repository.RemoteRepository; 030 031/** 032 * A request to deploy artifacts and their accompanying metadata into the a remote repository. 033 * 034 * @see org.eclipse.aether.RepositorySystem#deploy(org.eclipse.aether.RepositorySystemSession, DeployRequest) 035 */ 036public final class DeployRequest 037{ 038 039 private Collection<Artifact> artifacts = Collections.emptyList(); 040 041 private Collection<Metadata> metadata = Collections.emptyList(); 042 043 private RemoteRepository repository; 044 045 private RequestTrace trace; 046 047 /** 048 * Creates an uninitialized request. 049 */ 050 public DeployRequest() 051 { 052 } 053 054 /** 055 * Gets the artifact to deploy. 056 * 057 * @return The artifacts to deploy, never {@code null}. 058 */ 059 public Collection<Artifact> getArtifacts() 060 { 061 return artifacts; 062 } 063 064 /** 065 * Sets the artifacts to deploy. 066 * 067 * @param artifacts The artifacts to deploy, may be {@code null}. 068 * @return This request for chaining, never {@code null}. 069 */ 070 public DeployRequest setArtifacts( Collection<Artifact> artifacts ) 071 { 072 if ( artifacts == null ) 073 { 074 this.artifacts = Collections.emptyList(); 075 } 076 else 077 { 078 this.artifacts = artifacts; 079 } 080 return this; 081 } 082 083 /** 084 * Adds the specified artifacts for deployment. 085 * 086 * @param artifact The artifact to add, may be {@code null}. 087 * @return This request for chaining, never {@code null}. 088 */ 089 public DeployRequest addArtifact( Artifact artifact ) 090 { 091 if ( artifact != null ) 092 { 093 if ( artifacts.isEmpty() ) 094 { 095 artifacts = new ArrayList<>(); 096 } 097 artifacts.add( artifact ); 098 } 099 return this; 100 } 101 102 /** 103 * Gets the metadata to deploy. 104 * 105 * @return The metadata to deploy, never {@code null}. 106 */ 107 public Collection<Metadata> getMetadata() 108 { 109 return metadata; 110 } 111 112 /** 113 * Sets the metadata to deploy. 114 * 115 * @param metadata The metadata to deploy, may be {@code null}. 116 * @return This request for chaining, never {@code null}. 117 */ 118 public DeployRequest setMetadata( Collection<Metadata> metadata ) 119 { 120 if ( metadata == null ) 121 { 122 this.metadata = Collections.emptyList(); 123 } 124 else 125 { 126 this.metadata = metadata; 127 } 128 return this; 129 } 130 131 /** 132 * Adds the specified metadata for deployment. 133 * 134 * @param metadata The metadata to add, may be {@code null}. 135 * @return This request for chaining, never {@code null}. 136 */ 137 public DeployRequest addMetadata( Metadata metadata ) 138 { 139 if ( metadata != null ) 140 { 141 if ( this.metadata.isEmpty() ) 142 { 143 this.metadata = new ArrayList<>(); 144 } 145 this.metadata.add( metadata ); 146 } 147 return this; 148 } 149 150 /** 151 * Gets the repository to deploy to. 152 * 153 * @return The repository to deploy to or {@code null} if not set. 154 */ 155 public RemoteRepository getRepository() 156 { 157 return repository; 158 } 159 160 /** 161 * Sets the repository to deploy to. 162 * 163 * @param repository The repository to deploy to, may be {@code null}. 164 * @return This request for chaining, never {@code null}. 165 */ 166 public DeployRequest setRepository( RemoteRepository repository ) 167 { 168 this.repository = repository; 169 return this; 170 } 171 172 /** 173 * Gets the trace information that describes the higher level request/operation in which this request is issued. 174 * 175 * @return The trace information about the higher level operation or {@code null} if none. 176 */ 177 public RequestTrace getTrace() 178 { 179 return trace; 180 } 181 182 /** 183 * Sets the trace information that describes the higher level request/operation in which this request is issued. 184 * 185 * @param trace The trace information about the higher level operation, may be {@code null}. 186 * @return This request for chaining, never {@code null}. 187 */ 188 public DeployRequest setTrace( RequestTrace trace ) 189 { 190 this.trace = trace; 191 return this; 192 } 193 194 @Override 195 public String toString() 196 { 197 return getArtifacts() + ", " + getMetadata() + " > " + getRepository(); 198 } 199 200}