1 package net.sf.invicta.process; 2 3 import java.io.File ; 4 import java.io.FilenameFilter ; 5 import java.util.ArrayList ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 import java.util.StringTokenizer ; 9 10 import net.sf.invicta.InvictaConstants; 11 import net.sf.invicta.InvictaException; 12 import net.sf.invicta.Logger; 13 import net.sf.invicta.api.InvictaProject; 14 15 23 public class InvictaMainFlow { 24 protected List definitionFiles; 25 protected List typeFiles; 26 protected InvictaProject project; 27 protected ConfigurationManager confManager; 28 protected DumpersManager dumpersManager; 29 protected boolean wasProcessed = false; 30 31 34 public InvictaMainFlow() throws InvictaException { 35 super(); 36 this.confManager = new ConfigurationManager(); 37 this.dumpersManager = new DumpersManager(this.confManager); 38 } 39 40 45 public void process() throws InvictaException { 46 47 readConfiguration(); 49 50 if (!this.dumpersManager.forceRun() && 53 !this.confManager.forceRun()) { 54 Logger.info("No settings were changed. No need to run Invicta."); 55 return; 56 } 57 58 ProjectResolver projectResolver = new ProjectResolver(this.definitionFiles, this.typeFiles); 61 62 this.project = projectResolver.resolveProject(); 64 65 this.dumpersManager.dump(this.project); 67 68 this.confManager.writeOutputProperties(); 71 72 this.wasProcessed = true; 73 Logger.info("Invicta finished running successfully !"); 74 } 75 76 79 public boolean getWasProcessed() { 80 return wasProcessed; 81 } 82 83 89 protected void readConfiguration() throws InvictaException { 90 91 String jarFileName = 94 this.confManager.getProperty(InvictaConstants.PROPERTY_JAR_FILE); 95 if (jarFileName != null) { 96 File jarFile = new File (jarFileName); 97 this.confManager.setOutputTimestampProperty 98 (InvictaConstants.OUTPUT_PROPERTY_JAR_FILE, jarFile); 99 } 100 101 List definitionLocations = 104 tokenizeList(this.confManager.getRequiredProperty(InvictaConstants.PROPERTY_DEFINITION_LIST)); 105 List typeLocations = 106 tokenizeList(this.confManager.getRequiredProperty(InvictaConstants.PROPERTY_TYPE_LIST)); 107 108 this.definitionFiles = 111 prepareFileList(definitionLocations, InvictaConstants.OUTPUT_PROPERTY_DEFINITION_FILES); 112 this.typeFiles = 113 prepareFileList(typeLocations, InvictaConstants.OUTPUT_PROPERTY_TYPE_FILES); 114 115 this.confManager.setOutputProperty( 118 InvictaConstants.OUTPUT_PROPERTY_DEFINITION_FILES, this.definitionFiles.toString()); 119 this.confManager.setOutputProperty( 120 InvictaConstants.OUTPUT_PROPERTY_TYPE_FILES, this.typeFiles.toString()); 121 122 Logger.info("Project definition list=" + this.definitionFiles); 123 } 124 125 134 protected List prepareFileList(List locations, String outputPropertyPrefix) throws InvictaException { 135 List fileList = new ArrayList (); 136 137 for (Iterator iter = locations.iterator(); iter.hasNext();) { 139 String oneLocation = (String ) iter.next(); 140 File oneFile = new File (oneLocation); 141 142 this.confManager.setOutputTimestampProperty(outputPropertyPrefix, oneFile); 144 145 if (!oneFile.exists()) 146 continue; 147 148 if (oneFile.isDirectory()) { 151 File [] files = oneFile.listFiles(new FilenameFilter () { 152 public boolean accept(File dir, String name) { 153 return name.endsWith(InvictaConstants.DEFINITION_FILE_EXTENSION); 154 } 155 }); 156 for (int index = 0; index < files.length; index++) { 159 fileList.add(files[index].getAbsolutePath()); 160 this.confManager.setOutputTimestampProperty(outputPropertyPrefix, files[index]); 161 } 162 } else { 163 fileList.add(oneFile.getPath()); 164 } 165 } 166 167 return fileList; 168 } 169 170 175 protected List tokenizeList(String listStr) { 176 List list = new ArrayList (); 177 178 StringTokenizer st = 179 new StringTokenizer (listStr, InvictaConstants.LIST_DELIMITER); 180 while (st.hasMoreTokens()) 181 list.add(st.nextToken().trim()); 182 return list; 183 } 184 185 } 186 | Popular Tags |