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