Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit62df4f8

Browse files
author
zhourenjian
committed
Add a tool to compare the differences of two copies of J2S libraries and generate scripts for Java2Script classloader to adjust *.js path to latest version.
Usage:...J2SVersionDelta <folder holding 2.0.1-v*> <2.0.1-v1> <2.0.1-v1>And copy generated script to HTML/JS file before classloader loading *.s
1 parent33ad9cb commit62df4f8

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2010 java2script.org 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+
* Zhou Renjian - initial API and implementation
10+
*******************************************************************************/
11+
12+
packagenet.sf.j2s.lib.build;
13+
14+
importjava.io.ByteArrayOutputStream;
15+
importjava.io.File;
16+
importjava.io.FileInputStream;
17+
importjava.io.IOException;
18+
importjava.util.ArrayList;
19+
importjava.util.List;
20+
21+
/**
22+
* @author zhou renjian
23+
*
24+
* 2010-4-18
25+
*/
26+
publicclassJ2SVersionDelta {
27+
28+
privatestaticStringreadFileContent(Filefile) {
29+
FileInputStreamres =null;
30+
ByteArrayOutputStreambaos =newByteArrayOutputStream();
31+
byte[]buf =newbyte[1024];
32+
intread =0;
33+
try {
34+
res =newFileInputStream(file);
35+
while ((read =res.read(buf)) != -1) {
36+
baos.write(buf,0,read);
37+
}
38+
}catch (IOExceptione) {
39+
e.printStackTrace();
40+
}finally {
41+
if (res !=null) {
42+
try {
43+
res.close();
44+
}catch (IOExceptione) {
45+
e.printStackTrace();
46+
}
47+
}
48+
}
49+
returnbaos.toString();
50+
}
51+
52+
privatestaticvoidtraverseFolder(Filefile,StringbaseFolder,StringoldVersion,Listdeltas) {
53+
File[]files =file.listFiles();
54+
if (files !=null &&files.length >0) {
55+
for (inti =0;i <files.length;i++) {
56+
Filef =files[i];
57+
if (f.isDirectory()) {
58+
traverseFolder(f,baseFolder,oldVersion,deltas);
59+
}else {
60+
StringabsPath =f.getAbsolutePath();
61+
StringrelativePath =absPath.substring(baseFolder.length() +1);
62+
intidx =relativePath.indexOf(File.separator);
63+
relativePath =relativePath.substring(idx +1);
64+
StringoldPath =baseFolder +File.separator +oldVersion +File.separator +relativePath;
65+
FileoldFile =newFile(oldPath);
66+
67+
if (!oldFile.exists() ||oldFile.length() !=f.length()) {
68+
deltas.add(relativePath);
69+
}else {
70+
Stringcontent =readFileContent(f);
71+
StringoldContent =readFileContent(oldFile);
72+
if (!content.equals(oldContent)) {
73+
deltas.add(relativePath);
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}
80+
81+
publicstaticvoidmain(String[]args) {
82+
if (args ==null ||args.length !=3) {
83+
System.out.println("Usage:\r\nJ2SVersionDelta <base folder> <original version alias> <updated version alias>");
84+
return;
85+
}
86+
87+
StringoldVersion =args[1];
88+
StringnewVersion =args[2];
89+
FileoriginalFolder =newFile(args[0],oldVersion);
90+
FileupdatedFolder =newFile(args[0],newVersion);
91+
if (!originalFolder.exists()) {
92+
System.out.println("Folder " +oldVersion +" does not exist!");
93+
return;
94+
}
95+
if (!updatedFolder.exists()) {
96+
System.out.println("Folder " +newVersion +" does not exist!");
97+
return;
98+
}
99+
StringbasePath =newFile(args[0]).getAbsolutePath();
100+
ArrayListdeltas =newArrayList();
101+
traverseFolder(updatedFolder,basePath,oldVersion,deltas);
102+
intsize =deltas.size();
103+
if (size >0) {
104+
System.out.println("window[\"j2s.update.delta\"] = [");
105+
for (inti =0;i <size;i++) {
106+
Stringpath = (String)deltas.get(i);
107+
if (i >0) {
108+
System.out.print("\t\"$\",\"$\", ");
109+
}else {
110+
System.out.print("\t\"" +oldVersion +"\", ");
111+
System.out.print("\"" +newVersion +"\", ");
112+
}
113+
System.out.print("\"" +path.replace('\\','/') +"\"");
114+
if (i ==size -1) {
115+
System.out.println();
116+
}else {
117+
System.out.println(",");
118+
}
119+
}
120+
System.out.println("];");
121+
}else {
122+
System.out.println("There is no updates!");
123+
}
124+
}
125+
126+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp