📄 auto.java
字号:
+ "\\build.xml" + ch + " db-load";
String deploy = "ant -buildfile " + ch + Auto.pathProject
+ "\\build.xml" + ch + " deploy";
// 判断根目录下有没有build.xml文件
File dirr = new File(Auto.pathProject);
if (dirr.exists() == true) {// 首先确认目录存在
String tempp[] = dirr.list();
for (int i = 0; i < tempp.length; i++) {
if (tempp[i].equals("build.xml") == true) {
buildFlagg = 1;
break;
}
}
}
if (buildFlagg == 1) {// 当根目录下build.xml存在时
if (model.size() != 0) {// 当已经有model的时候才开始构建appgen
// 进行判断\extras\appgen目录下是否有build.xml文件
File dir = new File(pathProject + "\\extras\\appgen");
if (dir.exists() == true) {// 判断\extras\appgen目录是否存在
String temp[] = dir.list();
int buildFlag = 0;
for (int i = 0; i < temp.length; i++) {
if (temp[i].equals("build.xml") == true) {
buildFlag = 1;
break;
}
}
if (buildFlag == 1) {// 当\extras\appgen目录下build.xml存在时
// String tomcat = "startup.bat";
Runtime rt = Runtime.getRuntime();
try {
// 循环生成model相关的文件
for (int i = 0; i < model.size(); i++) {
String name = model.get(i).toString();
if (checkInstall.getState() == true)
appgenBuild = "ant -buildfile " + ch
+ pathProject
+ "\\extras\\appgen\\build.xml"
+ ch + " -Dappgen.type=pojo"
+ " -Dobject.name=" + name
+ " install";
else
appgenBuild = "ant -buildfile " + ch
+ pathProject
+ "\\extras\\appgen\\build.xml"
+ ch + " -Dappgen.type=pojo"
+ " -Dobject.name=" + name
+ " install-detailed";
Process p = rt.exec(new String[] { "cmd.exe",
"/c", appgenBuild });
appgenBuildValue = doWaitFor(p);
if (appgenBuildValue == 0)
continue;
else
break;
}
if (appgenBuildValue == 0) {// 正常运行appgen之后
Process p1 = rt.exec(new String[] { "cmd.exe",
"/c", dbPrepare });
dbPrepareValue = doWaitFor(p1);
Process p2 = rt.exec(new String[] { "cmd.exe",
"/c", dbLoad });
dbLoadValue = doWaitFor(p2);
Process p3 = rt.exec(new String[] { "cmd.exe",
"/c", deploy });
deployValue = doWaitFor(p3);
if (deployValue == 0)// 正常运行appfrm之后
actionPanel.setText("构建程序已经运行全部完毕");
else
// 运行appfrm不成功
actionPanel.setText("appfrm未构建成功!");
} else
// 运行appgen不成功
actionPanel.setText("appgen未构建成功!");
// rt.exec(new String[] { "cmd.exe", "/c", tomcat
// });
} catch (IOException e) {
System.err.println("IO error: " + e);
}
} else
// appgen build.xml不存在
actionPanel
.setText(pathProject
+ "\\extras\\appgen路径下没有可用的build.xml文件,无法构建model相关文件");
} else
// appgen文件夹不存在
actionPanel.setText(path
+ "路径下extras\\appgen文件夹不存在,无法构建model相关文件");
} else {// 没有model已设置,只运行appfrm,不运行appgen
Runtime rt = Runtime.getRuntime();
try {
Process p = rt
.exec(new String[] { "cmd.exe", "/c", deploy });
deployValue = doWaitFor(p);
if (deployValue == 0) {
actionPanel.setText("appfrm构建程序完毕!");
} else
actionPanel.setText("appfrm未构建成功!");
} catch (IOException e) {
System.err.println("IO error: " + e);
}
}
} else
// appfrm build.xml不存在
actionPanel.setText(path + "路径下没有可用的build.xml文件,无法构建!");
}
/**
* 得到model目录下所有符合条件的model文件的名字,作为可用外键
*/
static ArrayList getAllName() {
File dir = new File(path);
ArrayList modelName = new ArrayList();
ArrayList model = new ArrayList();
String temp[] = dir.list();
// 进行转换,获得所有Model文件
ArrayList tempModel = new ArrayList();
/*
* 将当前目录下所有后缀名为java
* 且名称不为BaseObject.java,CommonObject.java,SubCommonObject.java的文件存入tempModel数组
*/
for (int i = 0; i < temp.length; i++) {
if (temp[i].endsWith(".java")
&& temp[i].equals("BaseObject.java") == false
&& temp[i].equals("CommonObject.java") == false
&& temp[i].equals("SubCommonObject.java") == false) {
tempModel.add(temp[i]);
}
}
// 获得所有Model文件的名字
/*
* 读tempModel数组中每一个文件是否含有extends CommonObject字符串,
* 以获得tempModel数组中所有CommonObject的子类,并把其存入model数组
*/
char data[] = new char[1000];
for (int i = 0; i < tempModel.size(); i++) {
try {
FileReader fr = new FileReader(path + "\\" + tempModel.get(i));
try {
int num = fr.read(data);
if (num > 0) {
String str = new String(data, 0, num);
// 判断当前文件是否含有extends CommonObject字段以取得可用外键
if (str.indexOf("extends CommonObject") >= 0) {
model.add(tempModel.get(i));
}
// 判断当前文件是否合法User.java文件,如果有,加入可用外键列表
if (str.indexOf("User extends BaseObject") >= 0) {
model.add("User.java");
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 读取model数组,将其去掉java后缀名存入modelName数组,modelName数组为最后返回的可用外键数组
if (model.size() != 0) {// 当存在符合条件的model时
for (int i = 0; i < model.size(); i++) {
if (model.get(i).equals(null) == false) {
int s = model.get(i).toString().length();
modelName.add(model.get(i).toString().substring(0, s - 5));
}
}
}
return modelName;
}
/**
* 判断目录下是是否存在符合条件的model目录,采用递归算法
*/
static ArrayList modelFind(String filePath) {
String path = filePath;
File check_dir = new File(filePath);
if (check_dir.exists()) {
File files[] = check_dir.listFiles();// 存文件和目录列表
String subs[] = check_dir.list();// 存文件名和目录名列表
ArrayList directory = new ArrayList();
// 将当前文件夹下目录放入directory数组
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
String directoryName = files[i].toString();
directory.add(directoryName);
}
}
modelFlag = 0;
// 判断是否有文件夹名为model
for (int i = 0; i < directory.size(); i++) {
// 判断最后五个字母是否是model,如果有才设置modelFlag=1
if (directory.get(i).toString().substring(
directory.get(i).toString().length() - 5,
directory.get(i).toString().length()).equals("model") == true)
modelFlag = 1;
}
if (modelFlag == 1) {
// 判断文件夹名是否为model,下面是否有BaseObject.java文件
for (int i = 0; i < subs.length; i++) {
if (subs[i].equals("model")) {
path = path + "\\" + subs[i];
File file = new File(path);
if (file.exists() == true) {
String models[] = file.list();
for (int d = 0; d < models.length; d++) {
if (models[d].equals("BaseObject.java") == true) {
modelDireList.add(path);
}
}
}
}
}
}
path += filePath;
// 递归文件夹
for (int i = 0; i < directory.size(); i++) {
path += directory.get(i).toString();
modelFind(directory.get(i).toString());
}
}
return modelDireList;
}
/**
* 设置鼠标指针
*/
static void setMouse(Window window) {
URLClassLoader urlLoader = (URLClassLoader) window.getClass()
.getClassLoader();
URL url = urlLoader.findResource("images/mouse.gif");
Image animateImage = new ImageIcon(url).getImage();
Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
animateImage, new Point(0, 0), "cursor");
window.setCursor(cursor);
window.addWindowListener(new WindowAdapter() {
});
}
/**
* 把外键加入所需要的列表
*/
static void setList(List list) {
ArrayList model = getAllName();
for (int i = 0; i < model.size(); i++) {
list.add(model.get(i).toString());
}
}
/**
* 替换系统的waitfor方法
*/
static int doWaitFor(Process p) {
int exitValue = -1; // returned to caller when p is finished
try {
InputStream in = p.getInputStream();
InputStream err = p.getErrorStream();
boolean finished = false; // Set to true when p is finished
while (!finished) {
try {
while (in.available() > 0) {
// Print the output of our system call
Character c = new Character((char) in.read());
System.out.print(c);
}
while (err.available() > 0) {
// Print the output of our system call
Character c = new Character((char) err.read());
System.out.print(c);
}
// Ask the process for its exitValue. If the process
// is not finished, an IllegalThreadStateException
// is thrown. If it is finished, we fall through and
// the variable finished is set to true.
exitValue = p.exitValue();
finished = true;
} catch (IllegalThreadStateException e) {
// Process is not finished yet;
// Sleep a little to save on CPU cycles
Thread.sleep(500);
}
}
} catch (Exception e) {
// unexpected exception! print it out for debugging...
System.err.println("doWaitFor(): unexpected exception - "
+ e.getMessage());
}
// return completion status to caller
return exitValue;
}
/**
* 获取当前时间
*/
private static String getNowDate() {
Date date = Calendar.getInstance().getTime();
StringBuffer dateStringBuffer = new StringBuffer(date.toString());
dateStringBuffer.delete(16,28);
return dateStringBuffer.toString();
}
private static void reloadTime(Frame frame){
timeField.setText(getNowDate());
}
}
/**
* 运行多线程
*/
class NewThread implements Runnable {
String name;
Thread t;
NewThread(String threadname) {
name = threadname;
t = new Thread(this, name);
t.start();
}
public void run() {
Runtime rt = Runtime.getRuntime();
try {
Process p = rt.exec(new String[] { "cmd.exe", "/c", name });
int n = p.exitValue();
System.out.println(n);
} catch (IOException e) {
System.err.println("IO error: " + e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -