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 java.io.File;
021:
022: import org.apache.ivy.Ivy;
023: import org.apache.ivy.core.module.id.ModuleRevisionId;
024: import org.apache.ivy.core.report.ResolveReport;
025: import org.apache.ivy.core.settings.IvySettings;
026: import org.apache.ivy.plugins.matcher.PatternMatcher;
027: import org.apache.ivy.util.filter.FilterHelper;
028: import org.apache.tools.ant.BuildException;
029:
030: /**
031: * Allow to install a module or a set of module from repository to another one.
032: */
033: public class IvyInstall extends IvyTask {
034: private String organisation;
035:
036: private String module;
037:
038: private String revision;
039:
040: private boolean overwrite = false;
041:
042: private String from;
043:
044: private String to;
045:
046: private boolean transitive;
047:
048: private String type;
049:
050: private String matcher = PatternMatcher.EXACT;
051:
052: private boolean haltOnFailure = true;
053:
054: public void doExecute() throws BuildException {
055: Ivy ivy = getIvyInstance();
056: IvySettings settings = ivy.getSettings();
057: if (organisation == null) {
058: throw new BuildException(
059: "no organisation provided for ivy publish task: "
060: + "It can either be set explicitely via the attribute 'organisation' "
061: + "or via 'ivy.organisation' property or a prior call to <resolve/>");
062: }
063: if (module == null && PatternMatcher.EXACT.equals(matcher)) {
064: throw new BuildException(
065: "no module name provided for ivy publish task: "
066: + "It can either be set explicitely via the attribute 'module' "
067: + "or via 'ivy.module' property or a prior call to <resolve/>");
068: } else if (module == null
069: && !PatternMatcher.EXACT.equals(matcher)) {
070: module = PatternMatcher.ANY_EXPRESSION;
071: }
072: if (revision == null && PatternMatcher.EXACT.equals(matcher)) {
073: throw new BuildException(
074: "no module revision provided for ivy publish task: "
075: + "It can either be set explicitely via the attribute 'revision' "
076: + "or via 'ivy.revision' property or a prior call to <resolve/>");
077: } else if (revision == null
078: && !PatternMatcher.EXACT.equals(matcher)) {
079: revision = PatternMatcher.ANY_EXPRESSION;
080: }
081: if (from == null) {
082: throw new BuildException(
083: "no from resolver name: please provide it through parameter 'from'");
084: }
085: if (to == null) {
086: throw new BuildException(
087: "no to resolver name: please provide it through parameter 'to'");
088: }
089: ModuleRevisionId mrid = ModuleRevisionId.newInstance(
090: organisation, module, revision);
091: ResolveReport report;
092: try {
093: report = ivy.install(mrid, from, to, transitive,
094: doValidate(settings), overwrite, FilterHelper
095: .getArtifactTypeFilter(type), matcher);
096: } catch (Exception e) {
097: throw new BuildException("impossible to install " + mrid
098: + ": " + e, e);
099: }
100:
101: if (report.hasError() && isHaltonfailure()) {
102: throw new BuildException(
103: "Problem happened while installing modules - see output for details");
104: }
105: }
106:
107: public boolean isHaltonfailure() {
108: return haltOnFailure;
109: }
110:
111: public void setHaltonfailure(boolean haltOnFailure) {
112: this .haltOnFailure = haltOnFailure;
113: }
114:
115: public void setCache(File cache) {
116: cacheAttributeNotSupported();
117: }
118:
119: public String getModule() {
120: return module;
121: }
122:
123: public void setModule(String module) {
124: this .module = module;
125: }
126:
127: public String getOrganisation() {
128: return organisation;
129: }
130:
131: public void setOrganisation(String organisation) {
132: this .organisation = organisation;
133: }
134:
135: public String getRevision() {
136: return revision;
137: }
138:
139: public void setRevision(String revision) {
140: this .revision = revision;
141: }
142:
143: public boolean isOverwrite() {
144: return overwrite;
145: }
146:
147: public void setOverwrite(boolean overwrite) {
148: this .overwrite = overwrite;
149: }
150:
151: public String getFrom() {
152: return from;
153: }
154:
155: public void setFrom(String from) {
156: this .from = from;
157: }
158:
159: public String getTo() {
160: return to;
161: }
162:
163: public void setTo(String to) {
164: this .to = to;
165: }
166:
167: public boolean isTransitive() {
168: return transitive;
169: }
170:
171: public void setTransitive(boolean transitive) {
172: this .transitive = transitive;
173: }
174:
175: public String getType() {
176: return type;
177: }
178:
179: public void setType(String type) {
180: this .type = type;
181: }
182:
183: public String getMatcher() {
184: return matcher;
185: }
186:
187: public void setMatcher(String matcher) {
188: this.matcher = matcher;
189: }
190: }
|