KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > ant > IvyCheck


1 /*
2  * This file is subject to the licence found in LICENCE.TXT in the root directory of the project.
3  * Copyright Jayasoft 2005 - All rights reserved
4  *
5  * #SNAPSHOT#
6  */

7 package fr.jayasoft.ivy.ant;
8
9 import java.io.File JavaDoc;
10 import java.net.MalformedURLException JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
13
14 import org.apache.tools.ant.BuildException;
15 import org.apache.tools.ant.DirectoryScanner;
16 import org.apache.tools.ant.types.FileSet;
17
18 import fr.jayasoft.ivy.Ivy;
19 import fr.jayasoft.ivy.util.Message;
20
21 /**
22  * Checks the given ivy file using current configuration to see if all dependencies
23  * are available, with good confs. If a resolver name is given, it also checks that the declared
24  * publications are available in the corresponding resolver.
25  * Note that the check is not performed recursively, i.e. if a dependency has itself dependencies
26  * badly described or not available, this check will not discover it.
27  *
28  * @author Xavier Hanin
29  */

30 public class IvyCheck extends IvyTask {
31     private File JavaDoc _file = null;
32     private List JavaDoc _filesets = new ArrayList JavaDoc();
33     private String JavaDoc _resolvername;
34     public File JavaDoc getFile() {
35         return _file;
36     }
37     public void setFile(File JavaDoc file) {
38         _file = file;
39     }
40     /**
41      * Adds a set of files to check.
42      * @param set a set of files to check
43      */

44     public void addFileset(FileSet set) {
45         _filesets.add(set);
46     }
47     public String JavaDoc getResolvername() {
48         return _resolvername;
49     }
50     
51     public void setResolvername(String JavaDoc resolverName) {
52         _resolvername = resolverName;
53     }
54     
55
56     public void execute() throws BuildException {
57         try {
58         Ivy ivy = getIvyInstance();
59         if (_file != null) {
60             if (ivy.check(_file.toURL(), _resolvername)) {
61                 Message.verbose("checked "+_file+": OK");
62             }
63         }
64         for (int i = 0; i < _filesets.size(); i++) {
65             FileSet fs = (FileSet) _filesets.get(i);
66             DirectoryScanner ds = fs.getDirectoryScanner(getProject());
67             
68             File JavaDoc fromDir = fs.getDir(getProject());
69             
70             String JavaDoc[] srcFiles = ds.getIncludedFiles();
71             for (int j = 0; j < srcFiles.length; j++) {
72                 File JavaDoc file = new File JavaDoc(fromDir, srcFiles[j]);
73                 if (ivy.check(file.toURL(), _resolvername)) {
74                     Message.verbose("checked "+file+": OK");
75                 }
76             }
77         }
78         } catch (MalformedURLException JavaDoc e) {
79             throw new BuildException("impossible to convert a file to an url! "+e, e);
80         }
81     }
82     
83 }
84
Popular Tags