| 1 package org.antmod.scm; 2 3 import java.text.ParseException ; 4 import java.util.Iterator ; 5 6 import org.antmod.conf.AntmodProperties; 7 import org.apache.commons.lang.StringUtils; 8 9 10 18 public final class ScmSystemFactory { 19 20 23 private ScmSystemFactory() { 24 } 25 26 34 public static ScmSystem getScmSystemByType(String scmType) throws IllegalArgumentException { 35 String providerPropStart = "antmod.scm.providers."; 36 Iterator scmProviders = AntmodProperties.getPropertyNamesStartingWith(providerPropStart); 37 while (scmProviders.hasNext()) { 38 String providerPropName = (String )scmProviders.next(); 39 if (providerPropName.substring(providerPropStart.length()).equals(scmType)) { 40 String providerImpl = AntmodProperties.getProperty(providerPropName); 41 try { 42 return (ScmSystem)Class.forName(providerImpl).newInstance(); 43 } catch (InstantiationException e) { 44 e.printStackTrace(); 45 } catch (IllegalAccessException e) { 46 e.printStackTrace(); 47 } catch (ClassNotFoundException e) { 48 e.printStackTrace(); 49 } 50 } 51 } 52 throw new IllegalArgumentException ("Unknown scm system type: \"" + scmType + "\""); 53 } 54 55 62 public static ScmSystem getScmSystemByName(String reposName) throws IllegalArgumentException { 63 if (StringUtils.isBlank(reposName)) { 64 reposName = "default"; 65 } 66 67 String reposUrlString = AntmodProperties.getProperty("antmod.repositories." + reposName); 68 if (StringUtils.isBlank(reposUrlString)) { 69 throw new IllegalArgumentException ("No such scm repository configured: \"" + reposName + "\", property 'antmod.repositories." + reposName + "' apparently not set."); 70 } else { 71 try { 72 return getScmSystemByUrl(reposUrlString); 73 } catch (ParseException pe) { 74 throw new IllegalArgumentException (pe.toString()); 75 } 76 } 77 } 78 79 83 public static ScmSystem getScmSystemByUrl(String scmUrl) throws IllegalArgumentException , ParseException { 84 if (StringUtils.isBlank(scmUrl)) { 85 throw new IllegalArgumentException ("Cannot return scm system with an empty or null url."); 86 } 87 return getScmSystemByUrl(new ScmUrl(scmUrl)); 88 } 89 90 93 public static ScmSystem getScmSystemByUrl(ScmUrl scmUrl) throws IllegalArgumentException { 94 ScmSystem scm = getScmSystemByType(scmUrl.getType()); 95 scm.setUrl(scmUrl); 96 return scm; 97 } 98 } 99 | Popular Tags |