1 6 package fr.jayasoft.ivy.ant; 7 8 import java.io.File ; 9 import java.net.MalformedURLException ; 10 import java.text.ParseException ; 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 26 public class IvyConvertPom extends IvyTask { 27 private File _pomFile = null; 28 private File _ivyFile = null; 29 30 public File getPomFile() { 31 return _pomFile; 32 } 33 public void setPomFile(File file) { 34 _pomFile = file; 35 } 36 public File getIvyFile() { 37 return _ivyFile; 38 } 39 public void setIvyFile(File 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 e) { 55 throw new BuildException("unable to convert given pom file to url: "+_pomFile+": "+e, e); 56 } catch (ParseException e) { 57 log(e.getMessage(), Project.MSG_ERR); 58 throw new BuildException("syntax errors in pom file "+_pomFile+": "+e, e); 59 } catch (Exception 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 |