package org.eclipse.internal.orbit; import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MapFileGenerator { File root; String username; String pwd; String addressPrefix; String inputFile; String outpuFile; public void execute() { BufferedReader reader = null; BufferedWriter writer = null; try { try { reader = new BufferedReader(new FileReader(inputFile)); writer = new BufferedWriter(new FileWriter(outpuFile)); Pattern replacementExpression = Pattern .compile("^([a-zA-Z0-9\\-.]*)_?([0-9]*\\.[0-9]*\\.[0-9]*)?=(.*)$"); Matcher m = null; String current = null; while ((current = reader.readLine()) != null) { m = replacementExpression.matcher(current); m.matches(); if (!m.matches()) continue; String fileName = m.group(1) + "_" + m.group(3); boolean isJar = isJar(fileName); writer.write("bundle@" + m.group(1) + (m.group(2) == null ? "" : m.group(2)) + "=GET," + addressPrefix + fileName + (isJar ? ".jar" : ".zip,unpack=true") + (username == null ? "" : ',' + username) + (pwd == null ? "" : ',' + pwd) + '\n'); } } finally { if (writer != null) writer.close(); if (reader != null) reader.close(); } } catch (IO e) { } } private boolean isJar(String path) { File checked = new File(root, path + ".jar"); if (checked.exists()) return true; return false; } public static void main(String[] args) { MapFileGenerator mfg = new MapFileGenerator(); mfg.root = new File("d:/foo"); mfg.addressPrefix = "http://eclipse.org/"; mfg.inputFile = "D:\\pdeBuildTutorial\\BuildPlace\\finalPluginsVersions.properties"; mfg.outpuFile = "d:\\tmp\\map.txt"; mfg.execute(); } public void setRoot(File root) { this.root = root; } public void setUsername(String username) { this.username = username; } public void setPwd(String pwd) { this.pwd = pwd; } public void setAddressPrefix(String addressPrefix) { this.addressPrefix = addressPrefix; } public void setInputFile(String inputFile) { this.inputFile = inputFile; } public void setOutpuFile(String outpuFile) { this.outpuFile = outpuFile; } }