KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > ant > taskdefs > ArtifactUncopyTask


1 /*
2  * Copyright (c) 2002-2004, Inversoft, All Rights Reserved
3  */

4 package com.inversoft.savant.ant.taskdefs;
5
6
7 import java.io.File JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import java.util.List JavaDoc;
10
11 import org.apache.tools.ant.BuildException;
12 import org.apache.tools.ant.types.FileSet;
13 import org.apache.tools.ant.types.PatternSet;
14
15 import com.inversoft.savant.Artifact;
16 import com.inversoft.savant.ArtifactGroup;
17 import com.inversoft.savant.LocalCacheStore;
18 import com.inversoft.savant.SavantException;
19 import com.inversoft.savant.ant.types.ArtifactGroupType;
20 import com.inversoft.savant.ant.types.ArtifactType;
21
22
23 /**
24  * <p>
25  * This class is a taskdef that performs an uncopy of an
26  * artifact.
27  * </p>
28  *
29  * @author Brian Pontarelli
30  */

31 public class ArtifactUncopyTask extends UncopyTask {
32
33     private File JavaDoc localCache;
34     private final List JavaDoc artifacts = new ArrayList JavaDoc();
35     private final List JavaDoc groups = new ArrayList JavaDoc();
36     //private int count = 0;
37

38
39     /**
40      * Sets the location of the local cache. This can also be changed via a
41      * System property. See {@link com.inversoft.savant.LocalCacheStore} for more details.
42      *
43      * @param localCache The local cache location
44      */

45     public void setLocalcache(File JavaDoc localCache) {
46         this.localCache = localCache;
47     }
48
49     /**
50      * Adds a new artifact definition to this list of artifacts to copy.
51      *
52      * @param artifact The artifact to copy
53      */

54     public void addArtifact(ArtifactType artifact) {
55         artifacts.add(artifact.getProxy());
56     }
57
58     /**
59      * Adds a new artifact group definition to this list of artifacts to copy.
60      *
61      * @param group The new group
62      */

63     public void addArtifactgroup(ArtifactGroupType group) {
64         groups.add(group.getProxy());
65     }
66
67     /**
68      * Performs the copy of all the artifacts.
69      */

70     public void execute() {
71         LocalCacheStore lcs;
72         try {
73             lcs = new LocalCacheStore(localCache);
74         } catch (SavantException se) {
75             log("Invalid local cache location [" + localCache.getAbsolutePath() + "]");
76             throw new BuildException(se);
77         }
78
79         FileSet fs = new FileSet();
80         fs.setProject(getProject());
81         fs.setDir(lcs.getLocation());
82         addIncludes(fs, artifacts);
83
84         for (int i = 0; i < groups.size(); i++) {
85             ArtifactGroup artifactGroup = (ArtifactGroup) groups.get(i);
86             addIncludes(fs, artifactGroup.getArtifacts());
87         }
88
89         super.addFileset(fs);
90         super.execute();
91
92         //log("Uncopied " + count + " artifact(s) to " + super.destDir.getAbsolutePath());
93
}
94
95     /**
96      * Creates a file set include definition for all the artifacts in the given
97      * list.
98      */

99     private void addIncludes(FileSet fs, List JavaDoc artifacts) {
100         for (int i = 0; i < artifacts.size(); i++) {
101             Artifact artifact = (Artifact) artifacts.get(i);
102             PatternSet.NameEntry ne = fs.createInclude();
103             ne.setName(artifact.getArtifactFile());
104         }
105     }
106 }
Popular Tags