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