1 package org.eclipse.aether.spi.connector;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.File;
23
24 import org.eclipse.aether.RequestTrace;
25 import org.eclipse.aether.artifact.Artifact;
26 import org.eclipse.aether.transfer.ArtifactTransferException;
27 import org.eclipse.aether.transfer.TransferListener;
28 import org.eclipse.aether.transform.FileTransformer;
29
30 /**
31 * An upload of an artifact to a remote repository. A repository connector processing this upload has to use
32 * {@link #setException(ArtifactTransferException)} to report the results of the transfer.
33 */
34 public final class ArtifactUpload
35 extends ArtifactTransfer
36 {
37 private FileTransformer fileTransformer;
38
39 /**
40 * Creates a new uninitialized upload.
41 */
42 public ArtifactUpload()
43 {
44 // enables default constructor
45 }
46
47 /**
48 * Creates a new upload with the specified properties.
49 *
50 * @param artifact The artifact to upload, may be {@code null}.
51 * @param file The local file to upload the artifact from, may be {@code null}.
52 */
53 public ArtifactUpload( Artifact artifact, File file )
54 {
55 setArtifact( artifact );
56 setFile( file );
57 }
58
59 /**
60 * <p>Creates a new upload with the specified properties.</p>
61 *
62 * <p><strong>IMPORTANT</strong> When using a fileTransformer, the
63 * content of the file is stored in memory to ensure that file content and checksums stay in sync!
64 * </p>
65 *
66 * @param artifact The artifact to upload, may be {@code null}.
67 * @param file The local file to upload the artifact from, may be {@code null}.
68 * @param fileTransformer The file transformer, may be {@code null}.
69 */
70 public ArtifactUpload( Artifact artifact, File file, FileTransformer fileTransformer )
71 {
72 setArtifact( artifact );
73 setFile( file );
74 setFileTransformer( fileTransformer );
75 }
76
77 @Override
78 public ArtifactUpload setArtifact( Artifact artifact )
79 {
80 super.setArtifact( artifact );
81 return this;
82 }
83
84 @Override
85 public ArtifactUpload setFile( File file )
86 {
87 super.setFile( file );
88 return this;
89 }
90
91 @Override
92 public ArtifactUpload setException( ArtifactTransferException exception )
93 {
94 super.setException( exception );
95 return this;
96 }
97
98 @Override
99 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 }