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; 025import static java.util.Objects.requireNonNull; 026 027import org.eclipse.aether.RepositorySystem; 028import org.eclipse.aether.artifact.Artifact; 029import org.eclipse.aether.metadata.Metadata; 030 031/** 032 * The result of deploying artifacts and their accompanying metadata into the a remote repository. 033 * 034 * @see RepositorySystem#deploy(org.eclipse.aether.RepositorySystemSession, DeployRequest) 035 */ 036public final class DeployResult 037{ 038 039 private final DeployRequest request; 040 041 private Collection<Artifact> artifacts; 042 043 private Collection<Metadata> metadata; 044 045 /** 046 * Creates a new result for the specified request. 047 * 048 * @param request The deployment request, must not be {@code null}. 049 */ 050 public DeployResult( DeployRequest request ) 051 { 052 this.request = requireNonNull( request, "deploy request cannot be null" ); 053 artifacts = Collections.emptyList(); 054 metadata = Collections.emptyList(); 055 } 056 057 /** 058 * Gets the deploy request that was made. 059 * 060 * @return The deploy request, never {@code null}. 061 */ 062 public DeployRequest getRequest() 063 { 064 return request; 065 } 066 067 /** 068 * Gets the artifacts that got deployed. 069 * 070 * @return The deployed artifacts, never {@code null}. 071 */ 072 public Collection<Artifact> getArtifacts() 073 { 074 return artifacts; 075 } 076 077 /** 078 * Sets the artifacts that got deployed. 079 * 080 * @param artifacts The deployed artifacts, may be {@code null}. 081 * @return This result for chaining, never {@code null}. 082 */ 083 public DeployResult setArtifacts( Collection<Artifact> artifacts ) 084 { 085 if ( artifacts == null ) 086 { 087 this.artifacts = Collections.emptyList(); 088 } 089 else 090 { 091 this.artifacts = artifacts; 092 } 093 return this; 094 } 095 096 /** 097 * Adds the specified artifacts to the result. 098 * 099 * @param artifact The deployed artifact to add, may be {@code null}. 100 * @return This result for chaining, never {@code null}. 101 */ 102 public DeployResult addArtifact( Artifact artifact ) 103 { 104 if ( artifact != null ) 105 { 106 if ( artifacts.isEmpty() ) 107 { 108 artifacts = new ArrayList<>(); 109 } 110 artifacts.add( artifact ); 111 } 112 return this; 113 } 114 115 /** 116 * Gets the metadata that got deployed. Note that due to automatically generated metadata, there might have been 117 * more metadata deployed than originally specified in the deploy request. 118 * 119 * @return The deployed metadata, never {@code null}. 120 */ 121 public Collection<Metadata> getMetadata() 122 { 123 return metadata; 124 } 125 126 /** 127 * Sets the metadata that got deployed. 128 * 129 * @param metadata The deployed metadata, may be {@code null}. 130 * @return This result for chaining, never {@code null}. 131 */ 132 public DeployResult setMetadata( Collection<Metadata> metadata ) 133 { 134 if ( metadata == null ) 135 { 136 this.metadata = Collections.emptyList(); 137 } 138 else 139 { 140 this.metadata = metadata; 141 } 142 return this; 143 } 144 145 /** 146 * Adds the specified metadata to this result. 147 * 148 * @param metadata The deployed metadata to add, may be {@code null}. 149 * @return This result for chaining, never {@code null}. 150 */ 151 public DeployResult addMetadata( Metadata metadata ) 152 { 153 if ( metadata != null ) 154 { 155 if ( this.metadata.isEmpty() ) 156 { 157 this.metadata = new ArrayList<>(); 158 } 159 this.metadata.add( metadata ); 160 } 161 return this; 162 } 163 164 @Override 165 public String toString() 166 { 167 return getArtifacts() + ", " + getMetadata(); 168 } 169 170}