r111169 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111168‎ | r111169 | r111170 >
Date:17:05, 10 February 2012
Author:oren
Status:ok
Tags:
Comment:
cleaned up MWdumper
* Added type safety to generic constructs
* Removed org.apache.*
* Fixed all compiler warnings.
* Deleted the libs folder
Modified paths:
  • /trunk/mwdumper/.classpath (modified) (history)
  • /trunk/mwdumper/.project (modified) (history)
  • /trunk/mwdumper/.settings (added) (history)
  • /trunk/mwdumper/.settings/org.eclipse.jdt.core.prefs (added) (history)
  • /trunk/mwdumper/.settings/org.eclipse.m2e.core.prefs (added) (history)
  • /trunk/mwdumper/libs (deleted) (history)
  • /trunk/mwdumper/pom.xml (modified) (history)
  • /trunk/mwdumper/src/org/apache/commons/compress/bzip2 (deleted) (history)
  • /trunk/mwdumper/src/org/mediawiki/dumper/Dumper.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/dumper/Tools.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperGui.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperWindow.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperWindowForm.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/Buffer.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/ListFilter.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/MultiWriter.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/NamespaceFilter.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/NamespaceSet.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/Page.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/RevisionListFilter.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/SphinxWriter.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/SqlWriter.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/XmlDumpReader.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/XmlDumpWriter.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/XmlWriter.java (modified) (history)

Diff [purge]

Index: trunk/mwdumper/.classpath
@@ -1,12 +1,7 @@
22 <?xml version="1.0" encoding="UTF-8"?>
33 <classpath>
4 - <classpathentry kind="src" path="src"/>
5 - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6 - <classpathentry kind="lib" path="libs/junit.jar"/>
7 - <classpathentry kind="lib" path="libs/mysql-connector-java-3.1.11-bin.jar"/>
8 - <classpathentry kind="lib" path="libs/postgresql-8.2-504.jdbc3.jar"/>
9 - <classpathentry kind="lib" path="libs/xercesImpl.jar"/>
10 - <classpathentry kind="lib" path="libs/xml-apis.jar"/>
11 - <classpathentry kind="lib" path="libs/swing-layout-1.0.jar"/>
12 - <classpathentry kind="output" path="bin"/>
 4+ <classpathentry excluding="**/*Test.java|org/apache/commons/compress/bzip2/BZip2Constants.java|org/apache/commons/compress/bzip2/CBZip2InputStream.java|org/apache/commons/compress/bzip2/CBZip2OutputStream.java|org/apache/commons/compress/bzip2/CRC.java" including="**/*.java" kind="src" output="build/classes" path="src"/>
 5+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 6+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
 7+ <classpathentry kind="output" path="build/classes"/>
138 </classpath>
Index: trunk/mwdumper/.project
@@ -10,8 +10,14 @@
1111 <arguments>
1212 </arguments>
1313 </buildCommand>
 14+ <buildCommand>
 15+ <name>org.eclipse.m2e.core.maven2Builder</name>
 16+ <arguments>
 17+ </arguments>
 18+ </buildCommand>
1419 </buildSpec>
1520 <natures>
 21+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
1622 <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
1723 <nature>org.eclipse.jdt.core.javanature</nature>
1824 <nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
Index: trunk/mwdumper/src/org/mediawiki/importer/RevisionListFilter.java
@@ -34,13 +34,13 @@
3535
3636 public class RevisionListFilter implements DumpWriter {
3737 DumpWriter sink;
38 - protected TreeSet revIds;
 38+ protected TreeSet<Integer> revIds;
3939 protected Page currentPage;
4040 protected boolean pageWritten;
4141
4242 public RevisionListFilter(DumpWriter sink, String sourceFileName) throws IOException {
4343 this.sink = sink;
44 - revIds = new TreeSet();
 44+ revIds = new TreeSet<Integer>();
4545 BufferedReader input = new BufferedReader(new InputStreamReader(
4646 new FileInputStream(sourceFileName), "utf-8"));
4747 String line = input.readLine();
Index: trunk/mwdumper/src/org/mediawiki/importer/NamespaceSet.java
@@ -31,12 +31,12 @@
3232 import java.util.Iterator;
3333
3434 public class NamespaceSet {
35 - Map byname;
36 - Map bynumber;
 35+ Map<String, Integer> byname;
 36+ Map<Integer, String> bynumber;
3737
3838 public NamespaceSet() {
39 - byname = new HashMap();
40 - bynumber = new LinkedHashMap();
 39+ byname = new HashMap<String, Integer>();
 40+ bynumber = new LinkedHashMap<Integer, String>();
4141 }
4242
4343 public void add(int index, String prefix) {
@@ -57,11 +57,11 @@
5858 }
5959
6060 public String getPrefix(Integer index) {
61 - return (String)bynumber.get(index);
 61+ return bynumber.get(index);
6262 }
6363
6464 public Integer getIndex(String prefix) {
65 - return (Integer)byname.get(prefix);
 65+ return byname.get(prefix);
6666 }
6767
6868 public String getColonPrefix(Integer index) {
@@ -71,7 +71,7 @@
7272 return prefix;
7373 }
7474
75 - public Iterator orderedEntries() {
 75+ public Iterator<Map.Entry<Integer, String>> orderedEntries() {
7676 return bynumber.entrySet().iterator();
7777 }
7878 }
Index: trunk/mwdumper/src/org/mediawiki/importer/Buffer.java
@@ -31,7 +31,7 @@
3232
3333 private Buffer() {}
3434
35 - private static final IdentityHashMap BUFFERS = new IdentityHashMap();
 35+ private static final IdentityHashMap<Thread, char[]> BUFFERS = new IdentityHashMap<Thread, char[]>();
3636
3737 private static Thread lastThread;
3838 private static char[] lastBuffer;
@@ -44,7 +44,7 @@
4545 buffer = lastBuffer;
4646 } else {
4747 lastThread = thread;
48 - buffer = lastBuffer = (char[]) BUFFERS.get(thread);
 48+ buffer = lastBuffer = BUFFERS.get(thread);
4949 }
5050
5151 if (buffer == null) {
Index: trunk/mwdumper/src/org/mediawiki/importer/Page.java
@@ -30,12 +30,12 @@
3131 public class Page {
3232 public Title Title;
3333 public int Id;
34 - public Hashtable DiscussionThreadingInfo;
 34+ public Hashtable<String,Object> DiscussionThreadingInfo;
3535 public String Restrictions;
3636
3737 public Page() {
3838 // <restrictions> is optional...
3939 Restrictions = "";
40 - DiscussionThreadingInfo = new Hashtable();
 40+ DiscussionThreadingInfo = new Hashtable<String, Object>();
4141 }
4242 }
Index: trunk/mwdumper/src/org/mediawiki/importer/ListFilter.java
@@ -32,11 +32,11 @@
3333 import java.util.HashMap;
3434
3535 public class ListFilter extends PageFilter {
36 - protected HashMap list;
 36+ protected HashMap<String, String> list;
3737
3838 public ListFilter(DumpWriter sink, String sourceFileName) throws IOException {
3939 super(sink);
40 - list = new HashMap();
 40+ list = new HashMap<String, String>();
4141 BufferedReader input = new BufferedReader(new InputStreamReader(
4242 new FileInputStream(sourceFileName), "utf-8"));
4343 String line = input.readLine();
Index: trunk/mwdumper/src/org/mediawiki/importer/MultiWriter.java
@@ -29,57 +29,57 @@
3030 import java.util.ArrayList;
3131
3232 public class MultiWriter implements DumpWriter {
33 - ArrayList sinks;
 33+ ArrayList<DumpWriter> sinks;
3434
3535 public MultiWriter() {
36 - sinks = new ArrayList();
 36+ sinks = new ArrayList<DumpWriter>();
3737 }
3838
3939 public void close() throws IOException {
4040 for (int i = 0; i < sinks.size(); i++) {
41 - DumpWriter sink = (DumpWriter)sinks.get(i);
 41+ DumpWriter sink = sinks.get(i);
4242 sink.close();
4343 }
4444 }
4545
4646 public void writeStartWiki() throws IOException {
4747 for (int i = 0; i < sinks.size(); i++) {
48 - DumpWriter sink = (DumpWriter)sinks.get(i);
 48+ DumpWriter sink = sinks.get(i);
4949 sink.writeStartWiki();
5050 }
5151 }
5252
5353 public void writeEndWiki() throws IOException {
5454 for (int i = 0; i < sinks.size(); i++) {
55 - DumpWriter sink = (DumpWriter)sinks.get(i);
 55+ DumpWriter sink = sinks.get(i);
5656 sink.writeEndWiki();
5757 }
5858 }
5959
6060 public void writeSiteinfo(Siteinfo info) throws IOException {
6161 for (int i = 0; i < sinks.size(); i++) {
62 - DumpWriter sink = (DumpWriter)sinks.get(i);
 62+ DumpWriter sink = sinks.get(i);
6363 sink.writeSiteinfo(info);
6464 }
6565 }
6666
6767 public void writeStartPage(Page page) throws IOException {
6868 for (int i = 0; i < sinks.size(); i++) {
69 - DumpWriter sink = (DumpWriter)sinks.get(i);
 69+ DumpWriter sink = sinks.get(i);
7070 sink.writeStartPage(page);
7171 }
7272 }
7373
7474 public void writeEndPage() throws IOException {
7575 for (int i = 0; i < sinks.size(); i++) {
76 - DumpWriter sink = (DumpWriter)sinks.get(i);
 76+ DumpWriter sink = sinks.get(i);
7777 sink.writeEndPage();
7878 }
7979 }
8080
8181 public void writeRevision(Revision revision) throws IOException {
8282 for (int i = 0; i < sinks.size(); i++) {
83 - DumpWriter sink = (DumpWriter)sinks.get(i);
 83+ DumpWriter sink = sinks.get(i);
8484 sink.writeRevision(revision);
8585 }
8686 }
Index: trunk/mwdumper/src/org/mediawiki/importer/SqlWriter.java
@@ -151,8 +151,8 @@
152152 stream.writeComment("-- Case: " + commentSafe(info.Case));
153153 stream.writeComment("--");
154154 stream.writeComment("-- Namespaces:");
155 - for (Iterator i = info.Namespaces.orderedEntries(); i.hasNext();) {
156 - Map.Entry e = (Map.Entry)i.next();
 155+ for (Iterator<Map.Entry<Integer, String>> i = info.Namespaces.orderedEntries(); i.hasNext();) {
 156+ Map.Entry<Integer, String> e = i.next();
157157 stream.writeComment("-- " + e.getKey() + ": " + e.getValue());
158158 }
159159 stream.writeComment("");
@@ -171,10 +171,10 @@
172172 return text;
173173 }
174174
175 - private HashMap insertBuffers = new HashMap();
 175+ private HashMap<String, StringBuffer> insertBuffers = new HashMap<String, StringBuffer>();
176176 private static final int blockSize = 1024 * 512; // default 512k inserts
177177 protected void bufferInsertRow(String table, Object[][] row) throws IOException {
178 - StringBuffer sql = (StringBuffer)insertBuffers.get(table);
 178+ StringBuffer sql = insertBuffers.get(table);
179179 if (sql != null) {
180180 if (traits.supportsMultiRowInsert() && (sql.length() < blockSize)) {
181181 sql.append(',');
@@ -192,14 +192,14 @@
193193 }
194194
195195 protected void flushInsertBuffer(String table) throws IOException {
196 - stream.writeStatement((CharSequence)insertBuffers.get(table));
 196+ stream.writeStatement(insertBuffers.get(table));
197197 insertBuffers.remove(table);
198198 }
199199
200200 protected void flushInsertBuffers() throws IOException {
201 - Iterator iter = insertBuffers.values().iterator();
 201+ Iterator<StringBuffer> iter = insertBuffers.values().iterator();
202202 while (iter.hasNext()) {
203 - stream.writeStatement((CharSequence)iter.next());
 203+ stream.writeStatement(iter.next());
204204 }
205205 insertBuffers.clear();
206206 }
Index: trunk/mwdumper/src/org/mediawiki/importer/NamespaceFilter.java
@@ -29,7 +29,7 @@
3030
3131 public class NamespaceFilter extends PageFilter {
3232 boolean invert;
33 - HashMap matches;
 33+ HashMap<Integer, String> matches;
3434
3535 public NamespaceFilter(DumpWriter sink, String configString) {
3636 super(sink);
@@ -37,7 +37,7 @@
3838 invert = configString.startsWith("!");
3939 if (invert)
4040 configString = configString.substring(1);
41 - matches = new HashMap();
 41+ matches = new HashMap<Integer, String>();
4242
4343 String[] namespaceKeys = {
4444 "NS_MAIN",
Index: trunk/mwdumper/src/org/mediawiki/importer/SphinxWriter.java
@@ -27,12 +27,7 @@
2828
2929 import java.io.IOException;
3030 import java.io.OutputStream;
31 -import java.text.DateFormat;
32 -import java.text.SimpleDateFormat;
3331 import java.util.Calendar;
34 -import java.util.Iterator;
35 -import java.util.Map;
36 -import java.util.TimeZone;
3732
3833 /**
3934 * Generates XML stream suitable for the Sphinx search engine's xmlpipe input.
Index: trunk/mwdumper/src/org/mediawiki/importer/XmlDumpReader.java
@@ -106,8 +106,8 @@
107107 // --------------------------
108108 // SAX handler interface methods:
109109
110 - private static final Map startElements = new HashMap(64);
111 - private static final Map endElements = new HashMap(64);
 110+ private static final Map<String, String> startElements = new HashMap<String, String>(64);
 111+ private static final Map<String, String> endElements = new HashMap<String, String>(64);
112112 static {
113113 startElements.put("revision","revision");
114114 startElements.put("contributor","contributor");
@@ -163,7 +163,7 @@
164164 deleted = (d!=null && d.equals("deleted"));
165165
166166 try {
167 - qName = (String)startElements.get(qName);
 167+ qName = startElements.get(qName);
168168 if (qName == null)
169169 return;
170170 // frequent tags:
@@ -196,7 +196,7 @@
197197
198198 public void endElement(String uri, String localname, String qName) throws SAXException {
199199 try {
200 - qName = (String)endElements.get(qName);
 200+ qName = endElements.get(qName);
201201 if (qName == null)
202202 return;
203203 // frequent tags:
Index: trunk/mwdumper/src/org/mediawiki/importer/XmlDumpWriter.java
@@ -80,8 +80,8 @@
8181 writer.textElement("case", info.Case);
8282
8383 writer.openElement("namespaces");
84 - for (Iterator i = info.Namespaces.orderedEntries(); i.hasNext();) {
85 - Map.Entry e = (Map.Entry)i.next();
 84+ for (Iterator<Map.Entry<Integer, String>> i = info.Namespaces.orderedEntries(); i.hasNext();) {
 85+ Map.Entry<Integer, String> e = i.next();
8686 writer.textElement("namespace", e.getValue().toString(), new String[][] {
8787 {"key", e.getKey().toString()}});
8888 }
Index: trunk/mwdumper/src/org/mediawiki/importer/XmlWriter.java
@@ -14,13 +14,13 @@
1515 public class XmlWriter {
1616 OutputStream stream;
1717 String encoding;
18 - ArrayList stack;
 18+ ArrayList<String> stack;
1919 BufferedWriter writer;
2020
2121 public XmlWriter(OutputStream stream) throws IOException {
2222 this.stream = stream;
2323 encoding = "utf-8";
24 - stack = new ArrayList();
 24+ stack = new ArrayList<String>();
2525 writer = new BufferedWriter(new OutputStreamWriter(stream, "UTF8"));
2626 }
2727
@@ -171,7 +171,7 @@
172172 }
173173
174174 private String[] deindent() {
175 - String element = (String)stack.remove(stack.size() - 1);
 175+ String element = stack.remove(stack.size() - 1);
176176 String space = spaces(stack.size());
177177 return new String[] {element, space};
178178 }
Index: trunk/mwdumper/src/org/mediawiki/dumper/Tools.java
@@ -11,8 +11,8 @@
1212 import java.io.OutputStream;
1313 import java.util.zip.GZIPInputStream;
1414
15 -import org.apache.commons.compress.bzip2.CBZip2InputStream;
16 -import org.apache.commons.compress.bzip2.CBZip2OutputStream;
 15+import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
 16+import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
1717
1818 public class Tools {
1919 static final int IN_BUF_SZ = 1024 * 1024;
@@ -39,7 +39,7 @@
4040 int second = infile.read();
4141 if (first != 'B' || second != 'Z')
4242 throw new IOException("Didn't find BZ file signature in .bz2 file");
43 - return new CBZip2InputStream(infile);
 43+ return new BZip2CompressorInputStream(infile);
4444 }
4545
4646 static OutputStream openStandardOutput() {
@@ -51,7 +51,7 @@
5252 // bzip2 expects a two-byte 'BZ' signature header
5353 outfile.write('B');
5454 outfile.write('Z');
55 - return new CBZip2OutputStream(outfile);
 55+ return new BZip2CompressorOutputStream(outfile);
5656 }
5757
5858 static OutputStream createOutputFile(String param) throws IOException, FileNotFoundException {
Index: trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperGui.java
@@ -250,6 +250,7 @@
251251 System.setProperty("apple.laf.useScreenMenuBar", "true");
252252 System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MediaWiki Import");
253253
 254+ @SuppressWarnings("unused")
254255 DumperGui manager = new DumperGui();
255256 }
256257
Index: trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperWindow.java
@@ -26,6 +26,10 @@
2727 * @author brion
2828 */
2929 public class DumperWindow extends DumperWindowForm {
 30+ /**
 31+ *
 32+ */
 33+ private static final long serialVersionUID = 154925660542049290L;
3034 protected DumperGui backend;
3135 private int dbtype = DumperGui.DBTYPE_MYSQL;
3236
@@ -160,7 +164,7 @@
161165 backend.connect(dbtype, serverText.getText(),
162166 portText.getText(),
163167 userText.getText(),
164 - passwordText.getText());
 168+ new String(passwordText.getPassword()));
165169 }
166170
167171 protected void onDbTypeButtonActionPerformed(java.awt.event.ActionEvent evt) {
Index: trunk/mwdumper/src/org/mediawiki/dumper/gui/DumperWindowForm.java
@@ -12,6 +12,11 @@
1313 */
1414 public class DumperWindowForm extends javax.swing.JFrame {
1515
 16+ /**
 17+ *
 18+ */
 19+ private static final long serialVersionUID = 9045740449396873205L;
 20+
1621 /** Creates new form DumperWindow */
1722 public DumperWindowForm() {
1823 initComponents();
Index: trunk/mwdumper/src/org/mediawiki/dumper/Dumper.java
@@ -66,7 +66,6 @@
6767 import java.sql.Connection;
6868 import java.sql.DriverManager;
6969 import java.util.zip.GZIPOutputStream;
70 -import java.lang.ClassNotFoundException;
7170
7271 import java.text.ParseException;
7372
Index: trunk/mwdumper/pom.xml
@@ -10,18 +10,17 @@
1111 <url>http://www.mediawiki.org/wiki/MWDumper</url>
1212
1313 <dependencies>
14 - <!-- provided in source. todo: use package. -->
15 - <!-- <dependency>
16 - <groupId>commons-compress</groupId>
17 - <artifactId>commons-compress</artifactId>
18 - <version>20050911</version>
19 - <scope>compile</scope>
20 - </dependency> -->
 14+ <dependency>
 15+ <groupId>org.apache.commons</groupId>
 16+ <artifactId>commons-compress</artifactId>
 17+ <version>1.3</version>
 18+ <scope>compile</scope>
 19+ </dependency>
2120 <dependency>
22 - <groupId>net.java.dev.swing-layout</groupId>
23 - <artifactId>swing-layout</artifactId>
24 - <version>1.0.1</version>
25 - <scope>compile</scope>
 21+ <groupId>net.java.dev.swing-layout</groupId>
 22+ <artifactId>swing-layout</artifactId>
 23+ <version>1.0.1</version>
 24+ <scope>compile</scope>
2625 </dependency>
2726 <dependency>
2827 <groupId>mysql</groupId>
@@ -52,7 +51,7 @@
5352 <artifactId>junit</artifactId>
5453 <version>3.8</version>
5554 <scope>test</scope>
56 - </dependency>
 55+ </dependency>
5756 </dependencies>
5857 <build>
5958 <directory>build</directory> <!-- where the jar goes -->
@@ -63,8 +62,8 @@
6463 <groupId>org.apache.maven.plugins</groupId>
6564 <artifactId>maven-compiler-plugin</artifactId>
6665 <configuration>
67 - <source>1.4</source> <!-- enable assertions -->
68 - <target>1.4</target>
 66+ <source>1.6</source> <!-- enable assertions -->
 67+ <target>1.6</target>
6968 <excludes> <!-- exclude tests here -->
7069 <exclude>**/*Test.java</exclude>
7170 </excludes>
Index: trunk/mwdumper/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,6 @@
 2+#Wed Feb 08 17:38:09 CET 2012
 3+eclipse.preferences.version=1
 4+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
 5+org.eclipse.jdt.core.compiler.compliance=1.6
 6+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
 7+org.eclipse.jdt.core.compiler.source=1.6
Property changes on: trunk/mwdumper/.settings/org.eclipse.jdt.core.prefs
___________________________________________________________________
Added: svn:keywords
18 + LastChangedDate LastChangedRevision LastChangedBy Id
Index: trunk/mwdumper/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,5 @@
 2+#Wed Feb 08 17:38:08 CET 2012
 3+activeProfiles=
 4+eclipse.preferences.version=1
 5+resolveWorkspaceProjects=true
 6+version=1
Property changes on: trunk/mwdumper/.settings/org.eclipse.m2e.core.prefs
___________________________________________________________________
Added: svn:keywords
17 + LastChangedDate LastChangedRevision LastChangedBy Id

Status & tagging log