1 6 package fr.jayasoft.ivy.ant; 7 8 import java.io.File ; 9 import java.net.MalformedURLException ; 10 import java.text.ParseException ; 11 import java.util.ArrayList ; 12 import java.util.List ; 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 29 public class IvyInfo extends IvyTask { 30 private File _file = null; 31 32 public File getFile() { 33 return _file; 34 } 35 public void setFile(File file) { 36 _file = file; 37 } 38 39 public void execute() throws BuildException { 40 Ivy ivy = getIvyInstance(); 41 if (_file == null) { 42 _file = new File (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 Configuration[] configs = md.getConfigurations(); 58 List publicConfigsList = new ArrayList (); 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 [] publicConfigs = (String []) publicConfigsList.toArray(new String [publicConfigsList.size()]); 65 getProject().setProperty("ivy.public.configurations", mergeConfs(publicConfigs)); 66 } catch (MalformedURLException e) { 67 throw new BuildException("unable to convert given ivy file to url: "+_file+": "+e, e); 68 } catch (ParseException e) { 69 log(e.getMessage(), Project.MSG_ERR); 70 throw new BuildException("syntax errors in ivy file: "+e, e); 71 } catch (Exception e) { 72 throw new BuildException("impossible to resolve dependencies: "+e, e); 73 } 74 } 75 } 76 | Popular Tags |