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.module.descriptor;
019:
020: import java.net.URL;
021: import java.util.Date;
022: import java.util.Map;
023:
024: import org.apache.ivy.core.module.id.ArtifactRevisionId;
025: import org.apache.ivy.core.module.id.ModuleRevisionId;
026:
027: /**
028: *
029: */
030: public class DefaultArtifact extends AbstractArtifact {
031:
032: public static Artifact newIvyArtifact(ModuleRevisionId mrid,
033: Date pubDate) {
034: return new DefaultArtifact(mrid, pubDate, "ivy", "ivy", "xml",
035: true);
036: }
037:
038: public static Artifact newPomArtifact(ModuleRevisionId mrid,
039: Date pubDate) {
040: return new DefaultArtifact(mrid, pubDate, mrid.getName(),
041: "pom", "pom", true);
042: }
043:
044: public static Artifact cloneWithAnotherExt(Artifact artifact,
045: String newExt) {
046: return cloneWithAnotherTypeAndExt(artifact, artifact.getType(),
047: newExt);
048: }
049:
050: public static Artifact cloneWithAnotherType(Artifact artifact,
051: String newType) {
052: return cloneWithAnotherTypeAndExt(artifact, newType, artifact
053: .getExt());
054: }
055:
056: public static Artifact cloneWithAnotherTypeAndExt(
057: Artifact artifact, String newType, String newExt) {
058: return new DefaultArtifact(ArtifactRevisionId.newInstance(
059: artifact.getModuleRevisionId(), artifact.getName(),
060: newType, newExt, artifact.getExtraAttributes()),
061: artifact.getPublicationDate(), artifact.getUrl(),
062: artifact.isMetadata());
063: }
064:
065: public static Artifact cloneWithAnotherName(Artifact artifact,
066: String name) {
067: return new DefaultArtifact(ArtifactRevisionId.newInstance(
068: artifact.getModuleRevisionId(), name, artifact
069: .getType(), artifact.getExt(), artifact
070: .getExtraAttributes()), artifact
071: .getPublicationDate(), artifact.getUrl(), artifact
072: .isMetadata());
073: }
074:
075: public static Artifact cloneWithAnotherMrid(Artifact artifact,
076: ModuleRevisionId mrid) {
077: return new DefaultArtifact(ArtifactRevisionId.newInstance(mrid,
078: artifact.getName(), artifact.getType(), artifact
079: .getExt(), artifact.getExtraAttributes()),
080: artifact.getPublicationDate(), artifact.getUrl(),
081: artifact.isMetadata());
082: }
083:
084: private Date publicationDate;
085:
086: private ArtifactRevisionId arid;
087:
088: private URL url;
089:
090: private boolean isMetadata = false;
091:
092: public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate,
093: String name, String type, String ext) {
094: this (mrid, publicationDate, name, type, ext, null, null);
095: }
096:
097: public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate,
098: String name, String type, String ext, boolean isMetadata) {
099: this (mrid, publicationDate, name, type, ext, null, null);
100: this .isMetadata = isMetadata;
101: }
102:
103: public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate,
104: String name, String type, String ext, Map extraAttributes) {
105: this (mrid, publicationDate, name, type, ext, null,
106: extraAttributes);
107: }
108:
109: public DefaultArtifact(ModuleRevisionId mrid, Date publicationDate,
110: String name, String type, String ext, URL url,
111: Map extraAttributes) {
112: this (ArtifactRevisionId.newInstance(mrid, name, type, ext,
113: extraAttributes), publicationDate, url, false);
114: }
115:
116: public DefaultArtifact(ArtifactRevisionId arid,
117: Date publicationDate, URL url, boolean isMetadata) {
118: if (arid == null) {
119: throw new NullPointerException("null arid not allowed");
120: }
121: if (publicationDate == null) {
122: publicationDate = new Date();
123: }
124: this .publicationDate = publicationDate;
125: this .arid = arid;
126: this .url = url;
127: this .isMetadata = isMetadata;
128: }
129:
130: public ModuleRevisionId getModuleRevisionId() {
131: return arid.getModuleRevisionId();
132: }
133:
134: public String getName() {
135: return arid.getName();
136: }
137:
138: public Date getPublicationDate() {
139: return publicationDate;
140: }
141:
142: public String getType() {
143: return arid.getType();
144: }
145:
146: public String getExt() {
147: return arid.getExt();
148: }
149:
150: public ArtifactRevisionId getId() {
151: return arid;
152: }
153:
154: public String[] getConfigurations() {
155: return new String[0];
156: }
157:
158: public URL getUrl() {
159: return url;
160: }
161:
162: public boolean isMetadata() {
163: return isMetadata;
164: }
165: }
|