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.ant;
019:
020: import org.apache.ivy.Ivy;
021: import org.apache.ivy.core.module.id.ModuleId;
022: import org.apache.ivy.core.module.id.ModuleRevisionId;
023: import org.apache.ivy.core.resolve.ResolvedModuleRevision;
024: import org.apache.ivy.core.settings.IvySettings;
025: import org.apache.tools.ant.BuildException;
026:
027: /**
028: * Look for the latest module in the repository matching the given criteria, and sets a set of
029: * properties according to what was found.
030: */
031: public class IvyFindRevision extends IvyTask {
032: private String organisation;
033:
034: private String module;
035:
036: private String branch;
037:
038: private String revision;
039:
040: private String property = "ivy.revision";
041:
042: public String getModule() {
043: return module;
044: }
045:
046: public void setModule(String module) {
047: this .module = module;
048: }
049:
050: public String getOrganisation() {
051: return organisation;
052: }
053:
054: public void setOrganisation(String organisation) {
055: this .organisation = organisation;
056: }
057:
058: public String getRevision() {
059: return revision;
060: }
061:
062: public void setRevision(String revision) {
063: this .revision = revision;
064: }
065:
066: public String getBranch() {
067: return branch;
068: }
069:
070: public void setBranch(String branch) {
071: this .branch = branch;
072: }
073:
074: public String getProperty() {
075: return property;
076: }
077:
078: public void setProperty(String prefix) {
079: this .property = prefix;
080: }
081:
082: public void doExecute() throws BuildException {
083: if (organisation == null) {
084: throw new BuildException(
085: "no organisation provided for ivy findmodules");
086: }
087: if (module == null) {
088: throw new BuildException(
089: "no module name provided for ivy findmodules");
090: }
091: if (revision == null) {
092: throw new BuildException(
093: "no revision provided for ivy findmodules");
094: }
095:
096: Ivy ivy = getIvyInstance();
097: IvySettings settings = ivy.getSettings();
098: if (branch == null) {
099: settings
100: .getDefaultBranch(new ModuleId(organisation, module));
101: }
102: ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId
103: .newInstance(organisation, module, branch, revision));
104: if (rmr != null) {
105: getProject().setProperty(property,
106: rmr.getId().getRevision());
107: }
108: }
109: }
|