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