001package org.eclipse.aether.spi.connector;
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.io.File;
023
024import org.eclipse.aether.RequestTrace;
025import org.eclipse.aether.artifact.Artifact;
026import org.eclipse.aether.transfer.ArtifactTransferException;
027import org.eclipse.aether.transfer.TransferListener;
028import org.eclipse.aether.transform.FileTransformer;
029
030/**
031 * An upload of an artifact to a remote repository. A repository connector processing this upload has to use
032 * {@link #setException(ArtifactTransferException)} to report the results of the transfer.
033 */
034public final class ArtifactUpload
035    extends ArtifactTransfer
036{
037    private FileTransformer fileTransformer;
038
039    /**
040     * Creates a new uninitialized upload.
041     */
042    public ArtifactUpload()
043    {
044        // enables default constructor
045    }
046
047    /**
048     * Creates a new upload with the specified properties.
049     * 
050     * @param artifact The artifact to upload, may be {@code null}.
051     * @param file The local file to upload the artifact from, may be {@code null}.
052     */
053    public ArtifactUpload( Artifact artifact, File file )
054    {
055        setArtifact( artifact );
056        setFile( file );
057    }
058
059    /**
060     * <p>Creates a new upload with the specified properties.</p> 
061     * 
062     * <p><strong>IMPORTANT</strong> When using a fileTransformer, the
063     * content of the file is stored in memory to ensure that file content and checksums stay in sync!
064     * </p>
065     * 
066     * @param artifact The artifact to upload, may be {@code null}.
067     * @param file The local file to upload the artifact from, may be {@code null}.
068     * @param fileTransformer The file transformer, may be {@code null}.
069     */
070    public ArtifactUpload( Artifact artifact, File file, FileTransformer fileTransformer )
071    {
072        setArtifact( artifact );
073        setFile( file );
074        setFileTransformer( fileTransformer );
075    }
076
077    @Override
078    public ArtifactUpload setArtifact( Artifact artifact )
079    {
080        super.setArtifact( artifact );
081        return this;
082    }
083
084    @Override
085    public ArtifactUpload setFile( File file )
086    {
087        super.setFile( file );
088        return this;
089    }
090
091    @Override
092    public ArtifactUpload setException( ArtifactTransferException exception )
093    {
094        super.setException( exception );
095        return this;
096    }
097
098    @Override
099    public ArtifactUpload setListener( TransferListener listener )
100    {
101        super.setListener( listener );
102        return this;
103    }
104
105    @Override
106    public ArtifactUpload setTrace( RequestTrace trace )
107    {
108        super.setTrace( trace );
109        return this;
110    }
111    
112    public ArtifactUpload setFileTransformer( FileTransformer fileTransformer )
113    {
114        this.fileTransformer = fileTransformer;
115        return this;
116    }
117    
118    public FileTransformer getFileTransformer()
119    {
120        return fileTransformer;
121    }
122
123    @Override
124    public String toString()
125    {
126        if ( getFileTransformer() != null )
127        {
128            return getArtifact() + " >>> " + getFileTransformer().transformArtifact( getArtifact() )
129                + " - " + getFile();
130        }
131        else
132        {
133            return getArtifact() + " - " + getFile();
134        }
135    }
136
137}