1/*******************************************************************************
2 * Copyright (c) 2009 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.releng;
12
13import java.io.BufferedReader;
14import java.io.BufferedWriter;
15import java.io.FileReader;
16import java.io.FileWriter;
17import java.io.IOException;
18import java.util.ArrayList;
19import java.util.Iterator;
20
21import org.apache.tools.ant.BuildException;
22import org.apache.tools.ant.Task;
23
24public class GenerateExcludeListTask extends Task {
25
26	private ArrayList a = new ArrayList();
27	private String mapFile;
28	private String outputFile;
29
30	public GenerateExcludeListTask() {
31		super();
32	}
33
34	public static void main(String[] args) {
35		GenerateExcludeListTask parser = new GenerateExcludeListTask();
36		parser.setMapFile("c:\\temp\\orbit.map");
37		parser.setOutputFile("c:\\temp\\orbit.map.new");
38		parser.execute();
39	}
40
41	public String getOutputFile() {
42		return outputFile;
43	}
44
45	public void setOutputFile(String outputFile) {
46		this.outputFile = outputFile;
47	}
48
49	public String getMapFile() {
50		return mapFile;
51	}
52
53	public void setMapFile(String mapFile) {
54		this.mapFile = mapFile;
55	}
56
57	public void execute() throws BuildException {
58		readMap();
59		writeProp();
60	}
61
62	// for old map file format //
63
64	/* private void readMap() {
65		try {
66			BufferedReader r = new BufferedReader(new FileReader(mapFile));
67			String line;
68			while ((line = r.readLine()) != null) {
69				int start = line.lastIndexOf('/');
70				int lastcomma = line.lastIndexOf(',');
71				int end = line.length();
72				if (lastcomma > start) {
73					end = lastcomma;
74				}
75				int lastzip = line.lastIndexOf(".zip");
76				if (lastzip > start) {
77					String rstring = line.substring(0, lastzip);
78					line = rstring + ".jar";
79				}
80				if ((start < end) && (start > 0)) {
81					String substr = line.substring(start + 1, end);
82					a.add(substr);
83				}
84			}
85			r.close();
86		} catch (IOException e) {
87			e.printStackTrace();
88		}
89	} */
90
91	private void readMap() {
92		try {
93			BufferedReader r = new BufferedReader(new FileReader(mapFile));
94			String line;
95			while ((line = r.readLine()) != null) {
96				int start = line.indexOf("plugin@") + 7;
97				int end = line.indexOf(",");
98				String plugin = "";
99				if ((start > 0) && (end > 0)) {
100					plugin = line.substring(start, end);
101				}
102				String version = "";
103				int startv = line.indexOf("version=") + 8;
104				int endv = line.indexOf(",", startv);
105				if ((startv > 0) && (endv > 0)) {
106					version = line.substring(startv, endv);
107				}
108				if ((version != "") && (plugin != "")) {
109				String l = plugin + "_" + version + ".jar";
110				a.add(l);
111				}
112			}
113			r.close();
114		} catch (IOException e) {
115			e.printStackTrace();
116		}
117	}
118
119	private void writeProp() {
120
121		try {
122			BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));
123			for (Iterator iterator = a.iterator(); iterator.hasNext();) {
124				String s = iterator.next().toString();
125				if (iterator.hasNext()) {
126					out.write("plugins/" + s + ",");
127				} else {
128					out.write("plugins/" + s);
129				}
130			}
131			out.close();
132		} catch (IOException e) {
133			e.printStackTrace();
134		}
135	}
136
137}
138