1 11 package org.eclipse.pde.internal.build.builder; 12 13 import java.io.*; 14 import java.util.*; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.pde.internal.build.*; 17 import org.eclipse.update.core.IPlatformEnvironment; 18 19 22 public abstract class AbstractBuildScriptGenerator extends AbstractScriptGenerator { 23 24 protected DevClassPathHelper devEntries; 25 26 27 protected AssemblyInformation assemblyData; 28 29 30 protected Properties buildProperties; 31 private Set compiledElements; 33 private boolean includePlatformIndependent = true; 34 35 36 private boolean ignoreMissingPropertiesFile = true; 37 38 static private Properties executionEnvironmentMappings = null; 39 40 abstract protected Properties getBuildProperties() throws CoreException; 41 42 static public Properties getExecutionEnvironmentMappings(){ 43 if(executionEnvironmentMappings != null) 44 return executionEnvironmentMappings; 45 46 executionEnvironmentMappings = new Properties(); 47 InputStream stream = null; 48 try { 49 stream = BundleHelper.getDefault().getBundle().getEntry("data/env.properties").openStream(); executionEnvironmentMappings.load(stream); 51 } catch (IOException e) { 52 } finally { 54 try { 55 if (stream != null) 56 stream.close(); 57 } catch (IOException e) { 58 } 60 } 61 return executionEnvironmentMappings; 62 } 63 64 public void setDevEntries(String entries) { 65 devEntries = new DevClassPathHelper(entries); 66 } 67 68 public void setDevEntries(DevClassPathHelper entries) { 69 devEntries = entries; 70 } 71 72 public void includePlatformIndependent(boolean value) { 73 includePlatformIndependent = value; 74 } 75 76 public boolean isPlatformIndependentIncluded() { 77 return includePlatformIndependent; 78 } 79 80 87 protected int scan(StringBuffer buf, int start, String target) { 88 return scan(buf, start, new String [] {target}); 89 } 90 91 98 protected int scan(StringBuffer buf, int start, String [] targets) { 99 for (int i = start; i < buf.length(); i++) { 100 for (int j = 0; j < targets.length; j++) { 101 if (i < buf.length() - targets[j].length()) { 102 String match = buf.substring(i, i + targets[j].length()); 103 if (targets[j].equals(match)) 104 return i; 105 } 106 } 107 } 108 return -1; 109 } 110 111 118 protected StringBuffer readFile(File target) throws IOException { 119 return readFile(new FileInputStream(target)); 120 } 121 122 protected StringBuffer readFile(InputStream stream) throws IOException { 123 InputStreamReader reader = new InputStreamReader(new BufferedInputStream(stream)); 124 StringBuffer result = new StringBuffer (); 125 char[] buf = new char[4096]; 126 int count; 127 try { 128 count = reader.read(buf, 0, buf.length); 129 while (count != -1) { 130 result.append(buf, 0, count); 131 count = reader.read(buf, 0, buf.length); 132 } 133 } finally { 134 try { 135 reader.close(); 136 } catch (IOException e) { 137 } 139 } 140 return result; 141 } 142 143 155 protected void updateVersion(File buildFile, String propertyName, String version) throws IOException { 156 StringBuffer buffer = readFile(buildFile); 157 int pos = scan(buffer, 0, propertyName); 158 if (pos == -1) 159 return; 160 pos = scan(buffer, pos, "value"); if (pos == -1) 162 return; 163 int begin = scan(buffer, pos, "\""); if (begin == -1) 165 return; 166 begin++; 167 int end = scan(buffer, begin, "\""); if (end == -1) 169 return; 170 String currentVersion = buffer.substring(begin, end); 171 String newVersion = version; 172 if (currentVersion.equals(newVersion)) 173 return; 174 buffer.replace(begin, end, newVersion); 175 Utils.transferStreams(new ByteArrayInputStream(buffer.toString().getBytes()), new FileOutputStream(buildFile)); 176 } 177 178 185 public List selectConfigs(IPlatformEnvironment element) { 186 List result = new ArrayList(getConfigInfos()); 187 188 if (((element.getOS() == null || element.getOS().equals(Config.ANY)) && includePlatformIndependent == false) && 189 ((element.getWS() == null || element.getWS().equals(Config.ANY)) && includePlatformIndependent == false) && 190 ((element.getOSArch() == null || element.getOSArch().equals(Config.ANY)) && includePlatformIndependent == false)) { 191 result.clear(); 192 return result; 193 } 194 195 if (element.getOS() != null && !element.getOS().equals(Config.ANY)) { 196 for (Iterator iter = result.iterator(); iter.hasNext();) { 197 Config config = (Config) iter.next(); 198 if (! isMatching(element.getOS(), config.getOs()) ) 199 iter.remove(); 200 } 201 } 202 if (element.getWS() != null && !element.getWS().equals(Config.ANY)) { 203 for (Iterator iter = result.iterator(); iter.hasNext();) { 204 Config config = (Config) iter.next(); 205 if (! isMatching(element.getWS(), config.getWs()) ) 206 iter.remove(); 207 } 208 } 209 if (element.getOSArch() != null && !element.getOSArch().equals(Config.ANY)) { 210 for (Iterator iter = result.iterator(); iter.hasNext();) { 211 Config config = (Config) iter.next(); 212 if (! isMatching(element.getOSArch(), config.getArch())) 213 iter.remove(); 214 } 215 } 216 return result; 217 } 218 219 private boolean isMatching(String candidateValues, String configValue) { 220 StringTokenizer stok = new StringTokenizer(candidateValues, ","); while (stok.hasMoreTokens()) { 222 String token = stok.nextToken().toUpperCase(); 223 if (configValue.equalsIgnoreCase(token)) return true; 224 } 225 return false; 226 } 227 228 public Set getCompiledElements() { 229 if (compiledElements == null) 230 compiledElements = new HashSet(); 231 return compiledElements; 232 } 233 234 238 public void setCompiledElements(Set compiledElements) { 239 this.compiledElements = compiledElements; 240 } 241 242 public void setReportResolutionErrors(boolean value) { 243 reportResolutionErrors = value; 244 } 245 246 249 public boolean isIgnoreMissingPropertiesFile() { 250 if (BundleHelper.getDefault().isDebugging()) 251 return false; 252 return ignoreMissingPropertiesFile; 253 } 254 255 256 259 public void setIgnoreMissingPropertiesFile(boolean value) { 260 ignoreMissingPropertiesFile = value; 261 } 262 } 263 | Popular Tags |