MapValidator script: add option to write map errors to a log file.
git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@7396 282e977c-c81d-0410-88c4-b93c2d0d6712master
parent
c53a6eebd6
commit
86f0b48c4c
|
|
@ -1,17 +1,27 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<script>
|
<script>
|
||||||
<name>MapValidator</name>
|
<name>MapValidator</name>
|
||||||
<code><![CDATA[import java.io.File;
|
<code><![CDATA[import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import net.sf.gridarta.gameobject.GameObject;
|
import net.sf.gridarta.gameobject.GameObject;
|
||||||
import net.sf.gridarta.map.validation.ErrorCollector;
|
import net.sf.gridarta.map.validation.ErrorCollector;
|
||||||
import net.sf.gridarta.map.validation.ValidationError;
|
import net.sf.gridarta.map.validation.ValidationError;
|
||||||
|
|
||||||
|
void log(String message) {
|
||||||
|
print(message);
|
||||||
|
if (logFile != null) {
|
||||||
|
logFile.write(message);
|
||||||
|
logFile.write('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void checkMap(File mapFile, String mapPath) {
|
void checkMap(File mapFile, String mapPath) {
|
||||||
map = mainControl.getMapManager().openMapFile(mapFile, false);
|
map = mainControl.getMapManager().openMapFile(mapFile, false);
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
print(mapPath + ":");
|
log(mapPath + ":");
|
||||||
print("- cannot load map file");
|
log("- cannot load map file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ErrorCollector errorCollector;
|
ErrorCollector errorCollector;
|
||||||
|
|
@ -30,12 +40,12 @@ void checkMap(File mapFile, String mapPath) {
|
||||||
ValidationError validationError = it.next();
|
ValidationError validationError = it.next();
|
||||||
|
|
||||||
if (errorLimit > 0 && numberOfErrors >= errorLimit) {
|
if (errorLimit > 0 && numberOfErrors >= errorLimit) {
|
||||||
print("- <skipping more errors>");
|
log("- <skipping more errors>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numberOfErrors == 0) {
|
if (numberOfErrors == 0) {
|
||||||
print(mapPath + ":");
|
log(mapPath + ":");
|
||||||
}
|
}
|
||||||
numberOfErrors++;
|
numberOfErrors++;
|
||||||
|
|
||||||
|
|
@ -54,7 +64,7 @@ void checkMap(File mapFile, String mapPath) {
|
||||||
sb.append(" [").append(parameter).append(']');
|
sb.append(" [").append(parameter).append(']');
|
||||||
}
|
}
|
||||||
|
|
||||||
print(sb);
|
log(sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,17 +86,24 @@ void checkMaps(File mapFile, String mapPath) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Writer logFile = logFilename == null ? null : new BufferedWriter(new FileWriter(logFilename));
|
||||||
|
try {
|
||||||
if (baseDirectory == null || baseDirectory.length() <= 0) {
|
if (baseDirectory == null || baseDirectory.length() <= 0) {
|
||||||
baseDirectory = "/";
|
baseDirectory = "/";
|
||||||
}
|
}
|
||||||
print("Checking maps below " + baseDirectory + "...");
|
log("Checking maps below " + baseDirectory + "...");
|
||||||
if (baseDirectory.endsWith("/")) {
|
if (baseDirectory.endsWith("/")) {
|
||||||
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
|
baseDirectory = baseDirectory.substring(0, baseDirectory.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkMaps(new File(mainControl.getMapDefaultFolder() + baseDirectory), baseDirectory);
|
checkMaps(new File(mainControl.getMapDefaultFolder() + baseDirectory), baseDirectory);
|
||||||
|
|
||||||
print("Done.");]]></code>
|
log("Done.");
|
||||||
|
} finally {
|
||||||
|
if (logFile != null) {
|
||||||
|
logFile.close();
|
||||||
|
}
|
||||||
|
}]]></code>
|
||||||
<mode>
|
<mode>
|
||||||
<autoboot>false</autoboot>
|
<autoboot>false</autoboot>
|
||||||
<bash>true</bash>
|
<bash>true</bash>
|
||||||
|
|
@ -106,5 +123,11 @@ print("Done.");]]></code>
|
||||||
<minimum>0</minimum>
|
<minimum>0</minimum>
|
||||||
<maximum>2147483647</maximum>
|
<maximum>2147483647</maximum>
|
||||||
</parameter>
|
</parameter>
|
||||||
|
<parameter>
|
||||||
|
<name>logFilename</name>
|
||||||
|
<description>Copy errors to this file; empty=no copy to file</description>
|
||||||
|
<type>java.lang.String</type>
|
||||||
|
<value />
|
||||||
|
</parameter>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue