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