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.IvyPatternHelper;
022: import org.apache.ivy.core.module.id.ModuleRevisionId;
023: import org.apache.ivy.core.settings.IvySettings;
024: import org.apache.ivy.plugins.matcher.PatternMatcher;
025: import org.apache.tools.ant.BuildException;
026:
027: /**
028: * Look for modules in the repository matching the given criteria, and sets a set of properties
029: * according to what was found.
030: */
031: public class IvyListModules extends IvyTask {
032: private String organisation;
033:
034: private String module;
035:
036: private String branch = PatternMatcher.ANY_EXPRESSION;
037:
038: private String revision;
039:
040: private String matcher = PatternMatcher.EXACT_OR_REGEXP;
041:
042: private String property;
043:
044: private String value;
045:
046: public String getMatcher() {
047: return matcher;
048: }
049:
050: public void setMatcher(String matcher) {
051: this .matcher = matcher;
052: }
053:
054: public String getModule() {
055: return module;
056: }
057:
058: public void setModule(String module) {
059: this .module = module;
060: }
061:
062: public String getProperty() {
063: return property;
064: }
065:
066: public void setProperty(String name) {
067: this .property = name;
068: }
069:
070: public String getOrganisation() {
071: return organisation;
072: }
073:
074: public void setOrganisation(String organisation) {
075: this .organisation = organisation;
076: }
077:
078: public String getRevision() {
079: return revision;
080: }
081:
082: public void setRevision(String revision) {
083: this .revision = revision;
084: }
085:
086: public String getValue() {
087: return value;
088: }
089:
090: public void setValue(String value) {
091: this .value = value;
092: }
093:
094: public String getBranch() {
095: return branch;
096: }
097:
098: public void setBranch(String branch) {
099: this .branch = branch;
100: }
101:
102: public void doExecute() throws BuildException {
103: if (organisation == null) {
104: throw new BuildException(
105: "no organisation provided for ivy findmodules");
106: }
107: if (module == null) {
108: throw new BuildException(
109: "no module name provided for ivy findmodules");
110: }
111: if (revision == null) {
112: throw new BuildException(
113: "no revision provided for ivy findmodules");
114: }
115: if (property == null) {
116: throw new BuildException(
117: "no property provided for ivy findmodules");
118: }
119: if (value == null) {
120: throw new BuildException(
121: "no value provided for ivy findmodules");
122: }
123: Ivy ivy = getIvyInstance();
124: IvySettings settings = ivy.getSettings();
125: ModuleRevisionId[] mrids = ivy.listModules(ModuleRevisionId
126: .newInstance(organisation, module, branch, revision),
127: settings.getMatcher(matcher));
128: for (int i = 0; i < mrids.length; i++) {
129: String name = IvyPatternHelper.substitute(settings
130: .substitute(property), mrids[i]);
131: String value = IvyPatternHelper.substitute(settings
132: .substitute(this.value), mrids[i]);
133: getProject().setProperty(name, value);
134: }
135: }
136: }
|