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.util.Arrays;
021: import java.util.Collection;
022:
023: import org.apache.ivy.core.LogOptions;
024: import org.apache.ivy.core.retrieve.RetrieveOptions;
025: import org.apache.ivy.util.filter.Filter;
026: import org.apache.tools.ant.BuildException;
027:
028: /**
029: * This task allow to retrieve dependencies from the cache to a local directory like a lib dir.
030: */
031: public class IvyRetrieve extends IvyPostResolveTask {
032: private String pattern;
033:
034: private String ivypattern = null;
035:
036: private boolean sync = false;
037:
038: private boolean symlink = false;
039:
040: public String getPattern() {
041: return pattern;
042: }
043:
044: public void setPattern(String pattern) {
045: this .pattern = pattern;
046: }
047:
048: public void doExecute() throws BuildException {
049: prepareAndCheck();
050:
051: if (!getAllowedLogOptions().contains(getLog())) {
052: throw new BuildException("invalid option for 'log': "
053: + getLog() + ". Available options are "
054: + getAllowedLogOptions());
055: }
056:
057: pattern = getProperty(pattern, getSettings(),
058: "ivy.retrieve.pattern");
059: try {
060: Filter artifactFilter = getArtifactFilter();
061: int targetsCopied = getIvyInstance().retrieve(
062: getResolvedMrid(),
063: pattern,
064: ((RetrieveOptions) new RetrieveOptions()
065: .setLog(getLog())).setConfs(
066: splitConfs(getConf())).setDestIvyPattern(
067: ivypattern).setArtifactFilter(
068: artifactFilter).setSync(sync).setUseOrigin(
069: isUseOrigin()).setMakeSymlinks(symlink)
070: .setResolveId(getResolveId()));
071: boolean haveTargetsBeenCopied = targetsCopied > 0;
072: getProject().setProperty("ivy.nb.targets.copied",
073: String.valueOf(targetsCopied));
074: getProject().setProperty("ivy.targets.copied",
075: String.valueOf(haveTargetsBeenCopied));
076: } catch (Exception ex) {
077: throw new BuildException("impossible to ivy retrieve: "
078: + ex, ex);
079: }
080: }
081:
082: protected Collection/*<String>*/getAllowedLogOptions() {
083: return Arrays.asList(new String[] { LogOptions.LOG_DEFAULT,
084: LogOptions.LOG_DOWNLOAD_ONLY, LogOptions.LOG_QUIET });
085: }
086:
087: public String getIvypattern() {
088: return ivypattern;
089: }
090:
091: public void setIvypattern(String ivypattern) {
092: this .ivypattern = ivypattern;
093: }
094:
095: public boolean isSync() {
096: return sync;
097: }
098:
099: public void setSync(boolean sync) {
100: this .sync = sync;
101: }
102:
103: /**
104: * Option to create symlinks instead of copying.
105: */
106: public void setSymlink(boolean symlink) {
107: this.symlink = symlink;
108: }
109: }
|