/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.apache.ivy.ant;

import org.apache.ivy.core.cache.CacheManager;
import org.apache.ivy.core.retrieve.RetrieveOptions;
import org.apache.ivy.util.filter.Filter;
import org.apache.tools.ant.BuildException;

/**
 * This task allow to retrieve dependencies from the cache to a local directory like a lib dir.
 */
public class IvyRetrieve extends IvyPostResolveTask {
    private String _pattern;

    private String _ivypattern = null;

    private boolean _sync = false;

    private boolean _symlink = false;

    public String getPattern() {
        return _pattern;
    }

    public void setPattern(String pattern) {
        _pattern = pattern;
    }

    public void doExecute() throws BuildException {
        prepareAndCheck();

        _pattern = getProperty(_pattern, getSettings(), "ivy.retrieve.pattern");
        try {
            Filter artifactFilter = getArtifactFilter();
            int targetsCopied = getIvyInstance().retrieve(
                getResolvedMrid(),
                _pattern,
                new RetrieveOptions().setConfs(splitConfs(getConf())).setCache(
                    CacheManager.getInstance(getIvyInstance().getSettings(), getCache()))
                        .setDestIvyPattern(_ivypattern).setArtifactFilter(artifactFilter).setSync(
                            _sync).setUseOrigin(isUseOrigin()).setMakeSymlinks(_symlink)
                        .setResolveId(getResolveId()));
            boolean haveTargetsBeenCopied = targetsCopied > 0;
            getProject().setProperty("ivy.nb.targets.copied", String.valueOf(targetsCopied));
            getProject().setProperty("ivy.targets.copied", String.valueOf(haveTargetsBeenCopied));
        } catch (Exception ex) {
            throw new BuildException("impossible to ivy retrieve: " + ex, ex);
        }
    }

    public String getIvypattern() {
        return _ivypattern;
    }

    public void setIvypattern(String ivypattern) {
        _ivypattern = ivypattern;
    }

    public boolean isSync() {
        return _sync;
    }

    public void setSync(boolean sync) {
        _sync = sync;
    }

    /**
     * Option to create symlinks instead of copying.
     */
    public void setSymlink(boolean symlink) {
        _symlink = symlink;
    }
}

@@ -882,24 +882,76 @@
 cheManager;%0A
+import org.apache.ivy.core.retrieve.RetrieveEngine;%0A
 import org.a
@@ -1178,16 +1178,43 @@
 ib dir.%0A
+ * %0A * @see RetrieveEngine%0A
  */%0Apubl
@@ -1282,17 +1282,16 @@
  String 
-_
 pattern;
@@ -1311,17 +1311,16 @@
  String 
-_
 ivypatte
@@ -1351,17 +1351,16 @@
 boolean 
-_
 sync = f
@@ -1386,17 +1386,16 @@
 boolean 
-_
 symlink 
@@ -1452,17 +1452,16 @@
  return 
-_
 pattern;
@@ -1513,33 +1513,37 @@
 tern) %7B%0A        
-_
+this.
 pattern = patter
@@ -1636,25 +1636,24 @@
 );%0A%0A        
-_
 pattern = ge
@@ -1662,17 +1662,16 @@
 roperty(
-_
 pattern,
@@ -1892,17 +1892,16 @@
         
-_
 pattern,
@@ -2114,17 +2114,16 @@
 Pattern(
-_
 ivypatte
@@ -2193,25 +2193,24 @@
             
-_
 sync).setUse
@@ -2247,17 +2247,16 @@
 ymlinks(
-_
 symlink)
@@ -2748,17 +2748,16 @@
  return 
-_
 ivypatte
@@ -2826,17 +2826,21 @@
         
-_
+this.
 ivypatte
@@ -2908,17 +2908,16 @@
  return 
-_
 sync;%0A  
@@ -2969,17 +2969,21 @@
         
-_
+this.
 sync = s
@@ -3121,9 +3121,13 @@
     
-_
+this.
 syml

clean code