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