001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.core.report;
019:
020: import java.io.File;
021:
022: import org.apache.ivy.core.cache.ArtifactOrigin;
023: import org.apache.ivy.core.module.descriptor.Artifact;
024:
025: /**
026: * Report on the download of an artifact from a repository to a local (cached) file.
027: * <p>
028: * Note that depending on cache implementation, the artifact may not be actually downloaded, but
029: * used directly from its original location.
030: * </p>
031: */
032: public class ArtifactDownloadReport {
033: /**
034: * download details used when the download "fails" when the artifact is simply missing on the
035: * remote repository.
036: * <p>
037: * For historical reason the status can't be used to distinguish a real failure from a missing
038: * artifact by using the status, in both cases it's DownloadStatus.FAILED. The details message
039: * can be used for this purpose though.
040: * </p>
041: */
042: public static final String MISSING_ARTIFACT = "missing artifact";
043:
044: private Artifact artifact;
045:
046: private ArtifactOrigin origin;
047:
048: private File localFile;
049:
050: private DownloadStatus downloadStatus;
051:
052: private long size;
053:
054: private String downloadDetails = "";
055:
056: private long downloadTimeMillis;
057:
058: public ArtifactDownloadReport(Artifact artifact) {
059: this .artifact = artifact;
060: }
061:
062: public DownloadStatus getDownloadStatus() {
063: return downloadStatus;
064: }
065:
066: public void setDownloadStatus(DownloadStatus downloadStatus) {
067: this .downloadStatus = downloadStatus;
068: }
069:
070: public String getName() {
071: return artifact.getName();
072: }
073:
074: /**
075: *
076: * @return the type of the downloaded artifact
077: */
078: public String getType() {
079: return artifact.getType();
080: }
081:
082: public Artifact getArtifact() {
083: return artifact;
084: }
085:
086: public String getExt() {
087: return artifact.getExt();
088: }
089:
090: public long getSize() {
091: return size;
092: }
093:
094: public void setSize(long size) {
095: this .size = size;
096: }
097:
098: public void setArtifactOrigin(ArtifactOrigin origin) {
099: this .origin = origin;
100: }
101:
102: public ArtifactOrigin getArtifactOrigin() {
103: return origin;
104: }
105:
106: public void setDownloadDetails(String message) {
107: downloadDetails = message;
108: }
109:
110: public String getDownloadDetails() {
111: return downloadDetails;
112: }
113:
114: public void setDownloadTimeMillis(long l) {
115: downloadTimeMillis = l;
116: }
117:
118: public long getDownloadTimeMillis() {
119: return downloadTimeMillis;
120: }
121:
122: public String toString() {
123: if (downloadStatus == DownloadStatus.SUCCESSFUL) {
124: return "[SUCCESSFUL ] " + artifact + " ("
125: + downloadTimeMillis + "ms)";
126: } else if (downloadStatus == DownloadStatus.FAILED) {
127: if (downloadDetails == MISSING_ARTIFACT) {
128: return "[NOT FOUND ] " + artifact + " ("
129: + downloadTimeMillis + "ms)";
130: } else {
131: return "[FAILED ] " + artifact + ": "
132: + downloadDetails + " (" + downloadTimeMillis
133: + "ms)";
134: }
135: } else if (downloadStatus == DownloadStatus.NO) {
136: return "[NOT REQUIRED] " + artifact;
137: } else {
138: return super .toString();
139: }
140: }
141:
142: /**
143: * Returns the File where the artifact is available on the local filesystem,
144: * or <code>null</code> if and only if the artifact caching failed.
145: *
146: * @return the file where the artifact is now available on the local filesystem.
147: */
148: public File getLocalFile() {
149: return localFile;
150: }
151:
152: public void setLocalFile(File localFile) {
153: this .localFile = localFile;
154: }
155:
156: public boolean isDownloaded() {
157: return DownloadStatus.SUCCESSFUL == downloadStatus;
158: }
159: }
|