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