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.plugins.namespace;
019:
020: import org.apache.ivy.core.module.descriptor.Artifact;
021: import org.apache.ivy.core.module.descriptor.DefaultArtifact;
022: import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
023: import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
024: import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
025: import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
026: import org.apache.ivy.core.module.id.ArtifactId;
027: import org.apache.ivy.core.module.id.ModuleId;
028: import org.apache.ivy.core.module.id.ModuleRevisionId;
029: import org.apache.ivy.core.resolve.ResolvedModuleRevision;
030:
031: public final class NameSpaceHelper {
032: private NameSpaceHelper() {
033: }
034:
035: public static DependencyDescriptor toSystem(
036: DependencyDescriptor dd, Namespace ns) {
037: return DefaultDependencyDescriptor.transformInstance(dd, ns);
038: }
039:
040: public static DependencyDescriptor transform(
041: DependencyDescriptor dd, NamespaceTransformer t,
042: boolean fromSystem) {
043: return DefaultDependencyDescriptor.transformInstance(dd, t,
044: fromSystem);
045: }
046:
047: public static ModuleDescriptor toSystem(ModuleDescriptor md,
048: Namespace ns) {
049: return DefaultModuleDescriptor.transformInstance(md, ns);
050: }
051:
052: public static ResolvedModuleRevision toSystem(
053: ResolvedModuleRevision rmr, Namespace ns) {
054: if (ns.getToSystemTransformer().isIdentity()) {
055: return rmr;
056: }
057: ModuleDescriptor md = toSystem(rmr.getDescriptor(), ns);
058: if (md.equals(rmr.getDescriptor())) {
059: return rmr;
060: }
061: return new ResolvedModuleRevision(rmr.getResolver(), rmr
062: .getArtifactResolver(), md, rmr.getReport());
063: }
064:
065: public static Artifact transform(Artifact artifact,
066: NamespaceTransformer t) {
067: if (t.isIdentity()) {
068: return artifact;
069: }
070: ModuleRevisionId mrid = t.transform(artifact
071: .getModuleRevisionId());
072: if (artifact.getModuleRevisionId().equals(mrid)) {
073: return artifact;
074: }
075: return new DefaultArtifact(mrid, artifact.getPublicationDate(),
076: artifact.getName(), artifact.getType(), artifact
077: .getExt(), artifact.getUrl(), artifact
078: .getExtraAttributes());
079: }
080:
081: public static ArtifactId transform(ArtifactId artifactId,
082: NamespaceTransformer t) {
083: if (t.isIdentity()) {
084: return artifactId;
085: }
086: ModuleId mid = transform(artifactId.getModuleId(), t);
087: if (mid.equals(artifactId.getModuleId())) {
088: return artifactId;
089: }
090: return new ArtifactId(mid, artifactId.getName(), artifactId
091: .getType(), artifactId.getExt());
092: }
093:
094: public static ModuleId transform(ModuleId mid,
095: NamespaceTransformer t) {
096: if (t.isIdentity()) {
097: return mid;
098: }
099: return t.transform(new ModuleRevisionId(mid, "")).getModuleId();
100: }
101:
102: public static String transformOrganisation(String org,
103: NamespaceTransformer t) {
104: return transform(new ModuleId(org, ""), t).getOrganisation();
105: }
106: }
|