* Include application name in source names.
* Make sure files from zip files are removed from prototypes and prototypes are updated properly when they are no longer present.
This commit is contained in:
parent
0620912aa2
commit
20ea453c35
5 changed files with 77 additions and 30 deletions
|
@ -416,10 +416,11 @@ public final class TypeManager {
|
||||||
String filename = file.getName();
|
String filename = file.getName();
|
||||||
int dot = filename.lastIndexOf(".");
|
int dot = filename.lastIndexOf(".");
|
||||||
String tmpname = filename.substring(0, dot);
|
String tmpname = filename.substring(0, dot);
|
||||||
|
String srcName = getSourceName(file);
|
||||||
|
|
||||||
if (filename.endsWith(templateExtension)) {
|
if (filename.endsWith(templateExtension)) {
|
||||||
try {
|
try {
|
||||||
Template t = new Template(file, tmpname, proto);
|
Template t = new Template(file, tmpname, srcName, proto);
|
||||||
|
|
||||||
proto.addTemplate(t);
|
proto.addTemplate(t);
|
||||||
} catch (Throwable x) {
|
} catch (Throwable x) {
|
||||||
|
@ -427,7 +428,7 @@ public final class TypeManager {
|
||||||
}
|
}
|
||||||
} else if (filename.endsWith(scriptExtension)) {
|
} else if (filename.endsWith(scriptExtension)) {
|
||||||
try {
|
try {
|
||||||
FunctionFile ff = new FunctionFile(file, proto);
|
FunctionFile ff = new FunctionFile(file, srcName, proto);
|
||||||
|
|
||||||
proto.addFunctionFile(ff);
|
proto.addFunctionFile(ff);
|
||||||
} catch (Throwable x) {
|
} catch (Throwable x) {
|
||||||
|
@ -435,7 +436,7 @@ public final class TypeManager {
|
||||||
}
|
}
|
||||||
} else if (filename.endsWith(actionExtension)) {
|
} else if (filename.endsWith(actionExtension)) {
|
||||||
try {
|
try {
|
||||||
ActionFile af = new ActionFile(file, tmpname, proto);
|
ActionFile af = new ActionFile(file, tmpname, srcName, proto);
|
||||||
|
|
||||||
proto.addActionFile(af);
|
proto.addActionFile(af);
|
||||||
} catch (Throwable x) {
|
} catch (Throwable x) {
|
||||||
|
@ -474,4 +475,13 @@ public final class TypeManager {
|
||||||
}
|
}
|
||||||
// end of synchronized (proto)
|
// end of synchronized (proto)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getSourceName(File file) {
|
||||||
|
StringBuffer b = new StringBuffer(app.getName());
|
||||||
|
b.append(":");
|
||||||
|
b.append(file.getParentFile().getName());
|
||||||
|
b.append("/");
|
||||||
|
b.append(file.getName());
|
||||||
|
return b.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,10 @@ public class ZippedAppFile implements Updatable {
|
||||||
Application app;
|
Application app;
|
||||||
File file;
|
File file;
|
||||||
long lastmod;
|
long lastmod;
|
||||||
|
// Set of updatables provided by this zip file
|
||||||
Set updatables;
|
Set updatables;
|
||||||
|
// Set of prototypes this zip files provides updatables for
|
||||||
|
Set prototypes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ZippedAppFile object.
|
* Creates a new ZippedAppFile object.
|
||||||
|
@ -42,8 +45,8 @@ public class ZippedAppFile implements Updatable {
|
||||||
public ZippedAppFile(File file, Application app) {
|
public ZippedAppFile(File file, Application app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
updatables = new HashSet();
|
||||||
// System.err.println ("CREATING ZIP FILE "+this);
|
prototypes = new HashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,18 +60,18 @@ public class ZippedAppFile implements Updatable {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void update() {
|
public synchronized void update() {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
remove();
|
remove();
|
||||||
} else {
|
} else {
|
||||||
ZipFile zip = null;
|
ZipFile zip = null;
|
||||||
|
Set newUpdatables = new HashSet();
|
||||||
|
Set newPrototypes = new HashSet();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lastmod = file.lastModified();
|
lastmod = file.lastModified();
|
||||||
|
|
||||||
// System.err.println ("UPDATING ZIP FILE "+this);
|
|
||||||
zip = new ZipFile(file);
|
zip = new ZipFile(file);
|
||||||
updatables = new HashSet();
|
|
||||||
|
|
||||||
for (Enumeration en = zip.entries(); en.hasMoreElements();) {
|
for (Enumeration en = zip.entries(); en.hasMoreElements();) {
|
||||||
ZipEntry entry = (ZipEntry) en.nextElement();
|
ZipEntry entry = (ZipEntry) en.nextElement();
|
||||||
|
@ -98,26 +101,26 @@ public class ZippedAppFile implements Updatable {
|
||||||
|
|
||||||
if (fname.endsWith(".hac")) {
|
if (fname.endsWith(".hac")) {
|
||||||
String name = fname.substring(0, fname.lastIndexOf("."));
|
String name = fname.substring(0, fname.lastIndexOf("."));
|
||||||
String sourceName = file.getName() + "/" + ename;
|
String srcName = getSourceName(ename);
|
||||||
String content = getZipEntryContent(zip, entry);
|
String content = getZipEntryContent(zip, entry);
|
||||||
|
|
||||||
// System.err.println ("["+content+"]");
|
// System.err.println ("["+content+"]");
|
||||||
ActionFile act = new ActionFile(content, name, sourceName,
|
ActionFile act = new ActionFile(content, name, srcName,
|
||||||
proto);
|
proto);
|
||||||
|
|
||||||
proto.addActionFile(act);
|
proto.addActionFile(act);
|
||||||
updatables.add(act);
|
newUpdatables.add(act);
|
||||||
|
|
||||||
} else if (fname.endsWith(".hsp")) {
|
} else if (fname.endsWith(".hsp")) {
|
||||||
String name = fname.substring(0, fname.lastIndexOf("."));
|
String name = fname.substring(0, fname.lastIndexOf("."));
|
||||||
String sourceName = file.getName() + "/" + ename;
|
String srcName = getSourceName(ename);
|
||||||
String content = getZipEntryContent(zip, entry);
|
String content = getZipEntryContent(zip, entry);
|
||||||
|
|
||||||
// System.err.println ("["+content+"]");
|
// System.err.println ("["+content+"]");
|
||||||
Template tmp = new Template(content, name, sourceName, proto);
|
Template tmp = new Template(content, name, srcName, proto);
|
||||||
|
|
||||||
proto.addTemplate(tmp);
|
proto.addTemplate(tmp);
|
||||||
updatables.add(tmp);
|
newUpdatables.add(tmp);
|
||||||
|
|
||||||
} else if (fname.endsWith(".skin")) {
|
} else if (fname.endsWith(".skin")) {
|
||||||
String name = fname.substring(0, fname.lastIndexOf("."));
|
String name = fname.substring(0, fname.lastIndexOf("."));
|
||||||
|
@ -127,17 +130,17 @@ public class ZippedAppFile implements Updatable {
|
||||||
SkinFile skin = new SkinFile(content, name, proto);
|
SkinFile skin = new SkinFile(content, name, proto);
|
||||||
|
|
||||||
proto.addSkinFile(skin);
|
proto.addSkinFile(skin);
|
||||||
updatables.add(skin);
|
newUpdatables.add(skin);
|
||||||
|
|
||||||
} else if (fname.endsWith(".js")) {
|
} else if (fname.endsWith(".js")) {
|
||||||
String sourceName = file.getName() + "/" + ename;
|
String srcName = getSourceName(ename);
|
||||||
String content = getZipEntryContent(zip, entry);
|
String content = getZipEntryContent(zip, entry);
|
||||||
|
|
||||||
// System.err.println ("["+content+"]");
|
// System.err.println ("["+content+"]");
|
||||||
FunctionFile ff = new FunctionFile(content, sourceName, proto);
|
FunctionFile ff = new FunctionFile(content, srcName, proto);
|
||||||
|
|
||||||
proto.addFunctionFile(ff);
|
proto.addFunctionFile(ff);
|
||||||
updatables.add(ff);
|
newUpdatables.add(ff);
|
||||||
|
|
||||||
} else if ("type.properties".equalsIgnoreCase(fname)) {
|
} else if ("type.properties".equalsIgnoreCase(fname)) {
|
||||||
DbMapping dbmap = proto.getDbMapping();
|
DbMapping dbmap = proto.getDbMapping();
|
||||||
|
@ -147,7 +150,7 @@ public class ZippedAppFile implements Updatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark prototype as updated
|
// mark prototype as updated
|
||||||
proto.markUpdated();
|
newPrototypes.add(proto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable x) {
|
} catch (Throwable x) {
|
||||||
|
@ -156,6 +159,20 @@ public class ZippedAppFile implements Updatable {
|
||||||
x.printStackTrace();
|
x.printStackTrace();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
// remove updatables that have gone
|
||||||
|
updatables.removeAll(newUpdatables);
|
||||||
|
for (Iterator it = updatables.iterator(); it.hasNext();) {
|
||||||
|
((Updatable) it.next()).remove();
|
||||||
|
}
|
||||||
|
updatables = newUpdatables;
|
||||||
|
|
||||||
|
// mark both old and new prototypes as updated
|
||||||
|
prototypes.addAll(newPrototypes);
|
||||||
|
for (Iterator it = prototypes.iterator(); it.hasNext();) {
|
||||||
|
((Prototype) it.next()).markUpdated();
|
||||||
|
}
|
||||||
|
prototypes = newPrototypes;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
zip.close();
|
zip.close();
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
|
@ -168,14 +185,17 @@ public class ZippedAppFile implements Updatable {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if (updatables != null) {
|
// remove updatables from prototypes
|
||||||
for (Iterator it = updatables.iterator(); it.hasNext();)
|
for (Iterator it = updatables.iterator(); it.hasNext();) {
|
||||||
((Updatable) it.next()).remove();
|
((Updatable) it.next()).remove();
|
||||||
}
|
}
|
||||||
|
// mark affected prototypes as updated
|
||||||
|
for (Iterator it = prototypes.iterator(); it.hasNext();) {
|
||||||
|
((Prototype) it.next()).markUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove self from type manager
|
||||||
app.typemgr.removeZipFile(file.getName());
|
app.typemgr.removeZipFile(file.getName());
|
||||||
|
|
||||||
// System.err.println ("REMOVING ZIP FILE "+this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,4 +227,14 @@ public class ZippedAppFile implements Updatable {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return file.getName();
|
return file.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getSourceName(String entry) {
|
||||||
|
StringBuffer b = new StringBuffer(app.getName());
|
||||||
|
b.append(":");
|
||||||
|
b.append(file.getName());
|
||||||
|
b.append("/");
|
||||||
|
b.append(entry);
|
||||||
|
return b.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,12 +39,13 @@ public class ActionFile implements Updatable {
|
||||||
*
|
*
|
||||||
* @param file ...
|
* @param file ...
|
||||||
* @param name ...
|
* @param name ...
|
||||||
|
* @param sourceName ...
|
||||||
* @param proto ...
|
* @param proto ...
|
||||||
*/
|
*/
|
||||||
public ActionFile(File file, String name, Prototype proto) {
|
public ActionFile(File file, String name, String sourceName, Prototype proto) {
|
||||||
this.prototype = proto;
|
this.prototype = proto;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.sourceName = file.getParentFile().getName() + "/" + file.getName();
|
this.sourceName = sourceName;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.lastmod = file.lastModified();
|
this.lastmod = file.lastModified();
|
||||||
this.content = null;
|
this.content = null;
|
||||||
|
|
|
@ -34,11 +34,12 @@ public class FunctionFile implements Updatable {
|
||||||
* Creates a new FunctionFile object.
|
* Creates a new FunctionFile object.
|
||||||
*
|
*
|
||||||
* @param file ...
|
* @param file ...
|
||||||
|
* @param sourceName ...
|
||||||
* @param proto ...
|
* @param proto ...
|
||||||
*/
|
*/
|
||||||
public FunctionFile(File file, Prototype proto) {
|
public FunctionFile(File file, String sourceName, Prototype proto) {
|
||||||
this.prototype = proto;
|
this.prototype = proto;
|
||||||
this.sourceName = file.getParentFile().getName() + "/" + file.getName();
|
this.sourceName = sourceName;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -47,6 +48,10 @@ public class FunctionFile implements Updatable {
|
||||||
* Create a function file without a file, passing the code directly. This is used for
|
* Create a function file without a file, passing the code directly. This is used for
|
||||||
* files contained in zipped applications. The whole update mechanism is bypassed
|
* files contained in zipped applications. The whole update mechanism is bypassed
|
||||||
* by immediately parsing the code.
|
* by immediately parsing the code.
|
||||||
|
*
|
||||||
|
* @param body ...
|
||||||
|
* @param sourceName ...
|
||||||
|
* @param proto ...
|
||||||
*/
|
*/
|
||||||
public FunctionFile(String body, String sourceName, Prototype proto) {
|
public FunctionFile(String body, String sourceName, Prototype proto) {
|
||||||
this.prototype = proto;
|
this.prototype = proto;
|
||||||
|
|
|
@ -37,10 +37,11 @@ public class Template extends ActionFile {
|
||||||
*
|
*
|
||||||
* @param file ...
|
* @param file ...
|
||||||
* @param name ...
|
* @param name ...
|
||||||
|
* @param sourceName
|
||||||
* @param proto ...
|
* @param proto ...
|
||||||
*/
|
*/
|
||||||
public Template(File file, String name, Prototype proto) {
|
public Template(File file, String name, String sourceName, Prototype proto) {
|
||||||
super(file, name, proto);
|
super(file, name, sourceName, proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue