KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.ant;
7
8 import java.io.File JavaDoc;
9 import java.net.MalformedURLException JavaDoc;
10 import java.text.ParseException 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.Project;
16
17 import fr.jayasoft.ivy.Configuration;
18 import fr.jayasoft.ivy.Ivy;
19 import fr.jayasoft.ivy.ModuleDescriptor;
20 import fr.jayasoft.ivy.Configuration.Visibility;
21 import fr.jayasoft.ivy.parser.ModuleDescriptorParserRegistry;
22
23 /**
24  * Parses information about an ivy file and make them available in ant.
25  *
26  * @author Xavier Hanin
27  *
28  */

29 public class IvyInfo extends IvyTask {
30     private File JavaDoc _file = null;
31     
32     public File JavaDoc getFile() {
33         return _file;
34     }
35     public void setFile(File JavaDoc file) {
36         _file = file;
37     }
38
39     public void execute() throws BuildException {
40         Ivy ivy = getIvyInstance();
41         if (_file == null) {
42             _file = new File JavaDoc(getProject().getBaseDir(), getProperty(ivy, "ivy.dep.file"));
43         }
44         
45         try {
46             ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(ivy, _file.toURL(), doValidate(ivy));
47             getProject().setProperty("ivy.organisation", md.getModuleRevisionId().getOrganisation());
48             getProject().setProperty("ivy.module", md.getModuleRevisionId().getName());
49             if (md.getModuleRevisionId().getRevision() != null) {
50                 getProject().setProperty("ivy.revision", md.getModuleRevisionId().getRevision());
51             } else {
52                 getProject().setProperty("ivy.revision", "working@"+Ivy.getLocalHostName());
53             }
54             getProject().setProperty("ivy.configurations", mergeConfs(md.getConfigurationsNames()));
55             
56             // store the public configurations in a separate property
57
Configuration[] configs = md.getConfigurations();
58             List JavaDoc publicConfigsList = new ArrayList JavaDoc();
59             for (int i = 0; i < configs.length; i++) {
60                 if (Visibility.PUBLIC.equals(configs[i].getVisibility())) {
61                     publicConfigsList.add(configs[i].getName());
62                 }
63             }
64             String JavaDoc[] publicConfigs = (String JavaDoc[]) publicConfigsList.toArray(new String JavaDoc[publicConfigsList.size()]);
65             getProject().setProperty("ivy.public.configurations", mergeConfs(publicConfigs));
66         } catch (MalformedURLException JavaDoc e) {
67             throw new BuildException("unable to convert given ivy file to url: "+_file+": "+e, e);
68         } catch (ParseException JavaDoc e) {
69             log(e.getMessage(), Project.MSG_ERR);
70             throw new BuildException("syntax errors in ivy file: "+e, e);
71         } catch (Exception JavaDoc e) {
72             throw new BuildException("impossible to resolve dependencies: "+e, e);
73         }
74     }
75 }
76
Popular Tags