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