001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.deployment; 020 021import java.util.ArrayList; 022import java.util.Collection; 023import java.util.Collections; 024 025import org.eclipse.aether.RequestTrace; 026import org.eclipse.aether.artifact.Artifact; 027import org.eclipse.aether.metadata.Metadata; 028import org.eclipse.aether.repository.RemoteRepository; 029 030/** 031 * A request to deploy artifacts and their accompanying metadata into the a remote repository. 032 * 033 * @see org.eclipse.aether.RepositorySystem#deploy(org.eclipse.aether.RepositorySystemSession, DeployRequest) 034 */ 035public final class DeployRequest { 036 037 private Collection<Artifact> artifacts = Collections.emptyList(); 038 039 private Collection<Metadata> metadata = Collections.emptyList(); 040 041 private RemoteRepository repository; 042 043 private RequestTrace trace; 044 045 /** 046 * Creates an uninitialized request. 047 */ 048 public DeployRequest() {} 049 050 /** 051 * Gets the artifact to deploy. 052 * 053 * @return The artifacts to deploy, never {@code null}. 054 */ 055 public Collection<Artifact> getArtifacts() { 056 return artifacts; 057 } 058 059 /** 060 * Sets the artifacts to deploy. 061 * 062 * @param artifacts The artifacts to deploy, may be {@code null}. 063 * @return This request for chaining, never {@code null}. 064 */ 065 public DeployRequest setArtifacts(Collection<Artifact> artifacts) { 066 if (artifacts == null) { 067 this.artifacts = Collections.emptyList(); 068 } else { 069 this.artifacts = artifacts; 070 } 071 return this; 072 } 073 074 /** 075 * Adds the specified artifacts for deployment. 076 * 077 * @param artifact The artifact to add, may be {@code null}. 078 * @return This request for chaining, never {@code null}. 079 */ 080 public DeployRequest addArtifact(Artifact artifact) { 081 if (artifact != null) { 082 if (artifacts.isEmpty()) { 083 artifacts = new ArrayList<>(); 084 } 085 artifacts.add(artifact); 086 } 087 return this; 088 } 089 090 /** 091 * Gets the metadata to deploy. 092 * 093 * @return The metadata to deploy, never {@code null}. 094 */ 095 public Collection<Metadata> getMetadata() { 096 return metadata; 097 } 098 099 /** 100 * Sets the metadata to deploy. 101 * 102 * @param metadata The metadata to deploy, may be {@code null}. 103 * @return This request for chaining, never {@code null}. 104 */ 105 public DeployRequest setMetadata(Collection<Metadata> metadata) { 106 if (metadata == null) { 107 this.metadata = Collections.emptyList(); 108 } else { 109 this.metadata = metadata; 110 } 111 return this; 112 } 113 114 /** 115 * Adds the specified metadata for deployment. 116 * 117 * @param metadata The metadata to add, may be {@code null}. 118 * @return This request for chaining, never {@code null}. 119 */ 120 public DeployRequest addMetadata(Metadata metadata) { 121 if (metadata != null) { 122 if (this.metadata.isEmpty()) { 123 this.metadata = new ArrayList<>(); 124 } 125 this.metadata.add(metadata); 126 } 127 return this; 128 } 129 130 /** 131 * Gets the repository to deploy to. 132 * 133 * @return The repository to deploy to or {@code null} if not set. 134 */ 135 public RemoteRepository getRepository() { 136 return repository; 137 } 138 139 /** 140 * Sets the repository to deploy to. 141 * 142 * @param repository The repository to deploy to, may be {@code null}. 143 * @return This request for chaining, never {@code null}. 144 */ 145 public DeployRequest setRepository(RemoteRepository repository) { 146 this.repository = repository; 147 return this; 148 } 149 150 /** 151 * Gets the trace information that describes the higher level request/operation in which this request is issued. 152 * 153 * @return The trace information about the higher level operation or {@code null} if none. 154 */ 155 public RequestTrace getTrace() { 156 return trace; 157 } 158 159 /** 160 * Sets the trace information that describes the higher level request/operation in which this request is issued. 161 * 162 * @param trace The trace information about the higher level operation, may be {@code null}. 163 * @return This request for chaining, never {@code null}. 164 */ 165 public DeployRequest setTrace(RequestTrace trace) { 166 this.trace = trace; 167 return this; 168 } 169 170 @Override 171 public String toString() { 172 return getArtifacts() + ", " + getMetadata() + " > " + getRepository(); 173 } 174}