提交 de69210a authored 作者: christian.peter.io's avatar christian.peter.io

Add upgrade classes to 1.1 branch

上级 88fcdf0f
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.build.upgrade;
import java.io.File;
import org.h2.build.BuildBase;
/**
* Creates the v 1.1 upgrade sources
*/
public class UpgradeCreator {
private static final String[] TEXT_FILE_EXTENSIONS = { ".java", ".xml", ".bat", ".sh", ".txt", ".html", ".csv" };
/**
* This method is called when executing this application from the command
* line.
*
* @param args the command line parameters
*/
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("Usage: java -cp . org.h2.build.upgrade.UpgradeCreator <srcDir> <destDir>");
System.exit(1);
}
File srcDir = new File(args[0]);
if (!srcDir.exists()) {
System.out.println("Source dir does not exist");
System.exit(1);
}
File destDir = new File(args[1]);
if (destDir.exists()) {
System.out.println("Destination dir already exists");
System.exit(1);
}
destDir.mkdirs();
convert(srcDir, srcDir, destDir);
}
private static void convert(File file, File srcDir, File destDir) throws Exception {
String pathInDestDir = file.getCanonicalPath().substring(srcDir.getCanonicalPath().length());
pathInDestDir = pathInDestDir.replaceAll("org" + File.separator + "h2",
"org" + File.separator +
"h2" + File.separator +
"upgrade" + File.separator +
"v1_1");
File fileInDestDir = new File(destDir, pathInDestDir);
// System.out.println(fileInDestDir.getAbsoluteFile());
if (file.isDirectory()) {
fileInDestDir.mkdirs();
File[] files = file.listFiles();
for (File child : files) {
convert(child, srcDir, destDir);
}
} else {
byte[] content = BuildBase.readFile(file);
String contentString = new String(content);
if (isTextFile(file)) {
contentString = replace(file, contentString);
}
content = contentString.getBytes();
BuildBase.writeFile(fileInDestDir, content);
}
}
private static String replace(File file, String content) {
content = content.replaceAll("org\\.h2", "org.h2.upgrade.v1_1");
content = content.replaceAll("org/h2/", "org/h2/upgrade/v1_1/");
content = content.replaceAll("jdbc:h2:", "jdbc:h2v1_1:");
if (file.getName().equals("ConnectionInfo.java")) {
content = content.replaceAll("boolean isPersistent\\(\\) \\{", "public boolean isPersistent() {");
content = content.replaceAll("String getName\\(\\) throws SQLException \\{", "public String getName() throws SQLException {");
}
return content;
}
private static boolean isTextFile(File file) {
for (String extension : TEXT_FILE_EXTENSIONS) {
if (file.getName().toLowerCase().endsWith(extension)) {
return true;
}
}
return false;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License, Version 1.0,
and under the Eclipse Public License, Version 1.0
(http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
Javadoc package documentation
</title></head><body style="font: 9pt/130% Tahoma, Arial, Helvetica, sans-serif; font-weight: normal;"><p>
A tool to change the package name 'org.h2.' to a new name, to create a migration jar file.
</p></body></html>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论