| 1 package org.igfay.util; 2 3 import org.apache.log4j.Logger; 4 5 import org.igfay.jfig.JFig; 6 7 import java.lang.reflect.InvocationTargetException ; 8 import java.lang.reflect.Method ; 9 10 11 21 public class MavenFig { 22 private static Logger logger = Logger.getLogger(MavenFig.class); 23 24 private static final String FOREHEAD_CONF_FILE = "forehead.conf.file"; 25 private static final String MAVEN_HOME = "maven.home"; 26 private static final String MAVEN_MAIN_CLASS = "maven.main.class"; 27 private static final String JAVA_ENDORSED_DIRS = "java.endorsed.dirs"; 28 private static final String JAVAX_XML_PARSERS_SAXPARSERFACTORY = "javax.xml.parsers.SAXParserFactory"; 29 private static final String JAVAX_XML_PARSERS_DOCUMENTBUILDERFACTORY = "javax.xml.parsers.DocumentBuilderFactory"; 30 private static final String TOOLS_JAR = "tools.jar"; 31 32 public static void main(String [] args) { 33 JFig.getInstance(); 34 35 String mavenClass = System.getProperty(MAVEN_MAIN_CLASS,"com.werken.forehead.Forehead"); 36 37 if (!requiredPropertiesAreDefined()) { 38 logger.fatal("ERROR: You must define certain system properties for MavenFig to operate correctly. " + 39 "You can use the mavenfig script provided in the jFig distribution to automatically set them, " + 40 "or you can refer to the maven.config.xml if you want to set these properties via jFig and invoke this class directly. " + 41 " These properties are required: " 42 + FOREHEAD_CONF_FILE + ", " 43 + MAVEN_HOME + ", " 44 + MAVEN_MAIN_CLASS 45 + JAVA_ENDORSED_DIRS + ", " 46 + JAVAX_XML_PARSERS_SAXPARSERFACTORY + ", " 47 + JAVAX_XML_PARSERS_DOCUMENTBUILDERFACTORY + ", " 48 + TOOLS_JAR + ", " 49 ); 50 return; 51 } 52 53 try { 54 Class clazz = Class.forName(mavenClass); 57 Object object = clazz.newInstance(); 58 Class [] parameterTypes = new Class [] { String [].class }; 59 Method mainMethod = clazz.getMethod("main", parameterTypes); 60 Object [] arguments = new Object [] { args }; 61 62 mainMethod.invoke(object, arguments); 63 } catch (SecurityException e) { 64 logger.debug("Exception",e); 65 } catch (IllegalArgumentException e) { 66 logger.debug("Exception",e); 67 } catch (NoSuchMethodException e) { 68 logger.debug("Exception",e); 69 } catch (InvocationTargetException e) { 70 logger.debug("Exception",e); 71 } catch (InstantiationException e) { 72 logger.debug("Exception",e); 73 } catch (IllegalAccessException e) { 74 logger.debug("Exception",e); 75 } catch (ClassNotFoundException e) { 76 logger.debug("Exception",e); 77 } 78 } 79 80 85 private static boolean requiredPropertiesAreDefined() { 86 87 if (!isPropertyDefined(FOREHEAD_CONF_FILE)) { 88 return false; 89 } 90 91 if (!isPropertyDefined(JAVAX_XML_PARSERS_DOCUMENTBUILDERFACTORY)) { 92 return false; 93 } 94 95 if (!isPropertyDefined(JAVAX_XML_PARSERS_SAXPARSERFACTORY)) { 96 return false; 97 } 98 99 if (!isPropertyDefined(MAVEN_HOME)) { 100 return false; 101 } 102 103 if (!isPropertyDefined(TOOLS_JAR)) { 104 return false; 105 } 106 107 return true; 108 } 109 110 116 private static boolean isPropertyDefined(String propertyToCheck) { 117 if (System.getProperty(propertyToCheck) == null) { 118 logger.fatal("ERROR: Missing property - " + propertyToCheck); 119 return false; 120 } 121 return true; 122 } 123 } 124 | Popular Tags |