KickJava   Java API By Example, From Geeks To Geeks.

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


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
12 import org.apache.tools.ant.BuildException;
13 import org.apache.tools.ant.Project;
14
15 import fr.jayasoft.ivy.Ivy;
16 import fr.jayasoft.ivy.ModuleDescriptor;
17 import fr.jayasoft.ivy.external.m2.PomModuleDescriptorParser;
18 import fr.jayasoft.ivy.repository.url.URLResource;
19
20 /**
21  * Convert a pom to an ivy file
22  *
23  * @author Xavier Hanin
24  *
25  */

26 public class IvyConvertPom extends IvyTask {
27     private File JavaDoc _pomFile = null;
28     private File JavaDoc _ivyFile = null;
29     
30     public File JavaDoc getPomFile() {
31         return _pomFile;
32     }
33     public void setPomFile(File JavaDoc file) {
34         _pomFile = file;
35     }
36     public File JavaDoc getIvyFile() {
37         return _ivyFile;
38     }
39     public void setIvyFile(File JavaDoc ivyFile) {
40         _ivyFile = ivyFile;
41     }
42     
43     
44     public void execute() throws BuildException {
45         try {
46             if (_pomFile == null) {
47                 throw new BuildException("source pom file is required for convertpom task");
48             }
49             if (_ivyFile == null) {
50                 throw new BuildException("destination ivy file is required for convertpom task");
51             }
52             ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(new Ivy(), _pomFile.toURL(), false);
53             PomModuleDescriptorParser.getInstance().toIvyFile(_pomFile.toURL().openStream(), new URLResource(_pomFile.toURL()), getIvyFile(), md);
54         } catch (MalformedURLException JavaDoc e) {
55             throw new BuildException("unable to convert given pom file to url: "+_pomFile+": "+e, e);
56         } catch (ParseException JavaDoc e) {
57             log(e.getMessage(), Project.MSG_ERR);
58             throw new BuildException("syntax errors in pom file "+_pomFile+": "+e, e);
59         } catch (Exception JavaDoc e) {
60             throw new BuildException("impossible convert given pom file to ivy file: "+e+" from="+_pomFile+" to="+_ivyFile, e);
61         }
62     }
63 }
64
Popular Tags