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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.ivy.core.module.descriptor;
20
import org.apache.ivy.core.module.id.ModuleRevisionId;
23
* DependencyDescriptorMediator used to override some dependency descriptors values, such as
24
* the branch or version of the dependency.
26
public class OverrideDependencyDescriptorMediator implements DependencyDescriptorMediator {
27
private String version;
28
private String branch;
31
* Constructs a new instance.
34
* the branch to give to mediated dependency descriptors, <code>null</code> to keep
35
* the original branch.
37
* the version to give to mediated dependency descriptors, <code>null</code> to
38
* keep the original one.
40
public OverrideDependencyDescriptorMediator(String branch, String version) {
42
this.version = version;
46
* Returns the version this mediator will give to mediated descriptors, or <code>null</code>
47
* if this mediator does not override version.
49
* @return the version this mediator will give to mediated descriptors.
51
public String getVersion() {
56
* Returns the branch this mediator will give to mediated descriptors, or <code>null</code>
57
* if this mediator does not override branch.
59
* @return the branch this mediator will give to mediated descriptors.
61
public String getBranch() {
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()))) {
72
String version = this.version == null ? mrid.getRevision() : this.version;
73
String branch = this.branch == null ? mrid.getBranch() : this.branch;
75
return dd.clone(ModuleRevisionId.newInstance(
76
mrid.getOrganisation(), mrid.getName(), branch, version,
77
mrid.getQualifiedExtraAttributes()));