~ubuntu-branches/ubuntu/karmic/ivy/karmic

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/core/module/descriptor/OverrideDependencyDescriptorMediator.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2009-03-06 22:04:56 UTC
  • Revision ID: james.westby@ubuntu.com-20090306220456-5v37luqiuqda8ewp
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 *  contributor license agreements.  See the NOTICE file distributed with
 
4
 *  this work for additional information regarding copyright ownership.
 
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 *  (the "License"); you may not use this file except in compliance with
 
7
 *  the License.  You may obtain a copy of the License at
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
11
 *  Unless required by applicable law or agreed to in writing, software
 
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 *  See the License for the specific language governing permissions and
 
15
 *  limitations under the License.
 
16
 *
 
17
 */
 
18
package org.apache.ivy.core.module.descriptor;
 
19
 
 
20
import org.apache.ivy.core.module.id.ModuleRevisionId;
 
21
 
 
22
/**
 
23
 * DependencyDescriptorMediator used to override some dependency descriptors values, such as 
 
24
 * the branch or version of the dependency. 
 
25
 */
 
26
public class OverrideDependencyDescriptorMediator implements DependencyDescriptorMediator {
 
27
    private String version;
 
28
    private String branch;
 
29
    
 
30
    /**
 
31
     * Constructs a new instance.
 
32
     * 
 
33
     * @param branch
 
34
     *            the branch to give to mediated dependency descriptors, <code>null</code> to keep
 
35
     *            the original branch.
 
36
     * @param version
 
37
     *            the version to give to mediated dependency descriptors, <code>null</code> to
 
38
     *            keep the original one.
 
39
     */
 
40
    public OverrideDependencyDescriptorMediator(String branch, String version) {
 
41
        this.branch = branch;
 
42
        this.version = version;
 
43
    }
 
44
 
 
45
    /**
 
46
     * Returns the version this mediator will give to mediated descriptors, or <code>null</code>
 
47
     * if this mediator does not override version.
 
48
     * 
 
49
     * @return the version this mediator will give to mediated descriptors.
 
50
     */
 
51
    public String getVersion() {
 
52
        return version;
 
53
    }
 
54
    
 
55
    /**
 
56
     * Returns the branch this mediator will give to mediated descriptors, or <code>null</code>
 
57
     * if this mediator does not override branch.
 
58
     * 
 
59
     * @return the branch this mediator will give to mediated descriptors.
 
60
     */
 
61
    public String getBranch() {
 
62
        return branch;
 
63
    }
 
64
 
 
65
    public DependencyDescriptor mediate(DependencyDescriptor dd) {
 
66
        ModuleRevisionId mrid = dd.getDependencyRevisionId();
 
67
        if ((version == null || version.equals(mrid.getRevision()))
 
68
                && (branch == null || branch.equals(mrid.getBranch()))) {
 
69
            return dd;
 
70
        }
 
71
        
 
72
        String version = this.version == null ? mrid.getRevision() : this.version;
 
73
        String branch = this.branch == null ? mrid.getBranch() : this.branch;
 
74
        
 
75
        return dd.clone(ModuleRevisionId.newInstance(
 
76
            mrid.getOrganisation(), mrid.getName(), branch, version, 
 
77
            mrid.getQualifiedExtraAttributes()));
 
78
    }
 
79
}