|
From: <tre...@us...> - 2007-09-06 19:05:00
|
Revision: 377
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=377&view=rev
Author: trevorolio
Date: 2007-09-06 12:05:00 -0700 (Thu, 06 Sep 2007)
Log Message:
-----------
Added door and setting handlers to populate and reverse mojos.
Modified Paths:
--------------
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java
maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/ReverseMojo.java
Modified: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java 2007-09-06 13:16:32 UTC (rev 376)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/OgServiceMojoBase.java 2007-09-06 19:05:00 UTC (rev 377)
@@ -78,7 +78,18 @@
}
protected String fileToTemplateName(File tempFile) {
- return tempFile.getName().substring(0, tempFile.getName().length() - 4);
+ String trimmed = tempFile.getName().substring(0, tempFile.getName().length() - 4);
+ trimmed = trimmed.replace('_', ' ');
+ trimmed = trimmed.replace('-', ' ');
+ StringBuffer result = new StringBuffer();
+ result.append(Character.toUpperCase(trimmed.charAt(0)));
+ for (int i = 1; i < trimmed.length(); i++) {
+ if(Character.isUpperCase(trimmed.charAt(i)) && !Character.isUpperCase(trimmed.charAt(i - 1))){
+ result.append(" ");
+ }
+ result.append(trimmed.charAt(i));
+ }
+ return result.toString();
}
protected int dirNameToTemplateNumber(File candidate) throws MojoExecutionException {
Modified: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java 2007-09-06 13:16:32 UTC (rev 376)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/PopulateMojo.java 2007-09-06 19:05:00 UTC (rev 377)
@@ -15,7 +15,9 @@
import com.ogoglio.client.WebAPIClient;
import com.ogoglio.util.StreamUtils;
+import com.ogoglio.xml.DoorDocument;
import com.ogoglio.xml.PossessionDocument;
+import com.ogoglio.xml.SettingDocument;
import com.ogoglio.xml.SpaceDocument;
import com.ogoglio.xml.TemplateDocument;
import com.ogoglio.xml.ThingDocument;
@@ -30,7 +32,7 @@
public void execute() throws MojoExecutionException {
WebAPIClient client = validateArgsAndConnect();
- if(client == null){
+ if (client == null) {
return;
}
File[] templates = populateDir.listFiles();
@@ -58,6 +60,15 @@
fakeSpaceDoc = spaces.get(i);
try {
realSpaceDoc = client.createSpace(fakeSpaceDoc.getDisplayName());
+ if (realSpaceDoc == null) {
+ throw new MojoExecutionException("Could not create a space for population: " + fakeSpaceDoc.getDisplayName());
+ }
+ long realSpaceID = realSpaceDoc.getSpaceID();
+ client.setSpaceMaxGuests(realSpaceID, fakeSpaceDoc.getMaxGuests());
+ client.setSpacePublished(realSpaceID, fakeSpaceDoc.isPublished());
+ client.setSpaceSeaLevel(realSpaceID, fakeSpaceDoc.getSeaLevel());
+ client.setSpaceDisplaySea(realSpaceID, fakeSpaceDoc.getDisplaySea());
+
ThingDocument things[] = fakeSpaceDoc.getThingDocuments();
for (int j = 0; j < things.length; ++j) {
ThingDocument thing = things[j];
@@ -71,13 +82,17 @@
client.updateThing(realSpaceDoc.getSpaceID(), newThingDoc);
}
- long realSpaceID = realSpaceDoc.getSpaceID();
- client.setSpaceSeaLevel(realSpaceID, fakeSpaceDoc.getSeaLevel());
- client.setSpaceMaxGuests(realSpaceID, fakeSpaceDoc.getMaxGuests());
- client.setSpaceDisplayName(realSpaceID, fakeSpaceDoc.getDisplayName());
- client.setSpaceSeaLevel(realSpaceID, fakeSpaceDoc.getSeaLevel());
- getLog().info("Patched up space "+realSpaceDoc.getDisplayName());
+ SettingDocument[] settingDocs = fakeSpaceDoc.getSettingDocuments();
+ for (int j = 0; j < settingDocs.length; j++) {
+ client.putSpaceSetting(realSpaceID, settingDocs[j].getKey(), settingDocs[j].getValue());
+ }
+ DoorDocument[] doorDocs = fakeSpaceDoc.getDoorDocuments();
+ for (int j = 0; j < doorDocs.length; j++) {
+ client.createDoor(realSpaceID, doorDocs[j].getTemplateID(), doorDocs[j].getTemplateOwner(), doorDocs[j].getDisplayName(), doorDocs[j].getLink(), doorDocs[j].getTransform());
+ }
+
+ getLog().info("Patched up space " + realSpaceDoc.getDisplayName());
} catch (IOException e) {
throw new MojoExecutionException("IOException patching space (" + fakeSpaceDoc.getDisplayName() + ":" + fakeSpaceDoc.getSpaceID() + ")", e);
}
Modified: maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/ReverseMojo.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/ReverseMojo.java 2007-09-06 13:16:32 UTC (rev 376)
+++ maven/trunk/dev-plugins/src/main/java/com/ogoglio/plugin/ReverseMojo.java 2007-09-06 19:05:00 UTC (rev 377)
@@ -1,6 +1,5 @@
package com.ogoglio.plugin;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -16,6 +15,8 @@
import com.ogoglio.client.WebAPIClient;
import com.ogoglio.util.StreamUtils;
+import com.ogoglio.xml.DoorDocument;
+import com.ogoglio.xml.SettingDocument;
import com.ogoglio.xml.SpaceDocument;
import com.ogoglio.xml.TemplateDocument;
import com.ogoglio.xml.ThingDocument;
@@ -24,135 +25,139 @@
* @goal reverse
*/
public class ReverseMojo extends OgServiceMojoBase {
- /**
- * @parameter
- */
- private File reverseFile;
+ /**
+ * @parameter
+ */
+ private File reverseFile;
- public void execute() throws MojoExecutionException, MojoFailureException {
- WebAPIClient client = validateArgsAndConnect();
- HashMap<String,Long> displayNameToLocalId = new HashMap<String, Long>();
- HashMap<Long,Long> remoteIdTolocalId = new HashMap<Long, Long>();
-
- long localThingId=1,localPossId=1;
-
- if (client==null) {
- return;
- }
-
- if (reverseFile==null) {
- getLog().info("No reverse file configured. Mojo ignored.");
- return;
- }
-
- if ((!reverseFile.isFile()) || (!reverseFile.canRead())) {
- throw new MojoExecutionException("Can't read reverse file "+reverseFile.getAbsolutePath());
- }
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ WebAPIClient client = validateArgsAndConnect();
+ HashMap<String, Long> displayNameToLocalId = new HashMap<String, Long>();
+ HashMap<Long, Long> remoteIdTolocalId = new HashMap<Long, Long>();
- SpaceDocument origSpaceDoc = buildTemplateMaps(displayNameToLocalId,
- remoteIdTolocalId);
-
- int localSpaceId=getNextLocalSpaceId();
-
- SpaceDocument result = rewhackSpaceDocument(remoteIdTolocalId,
- localThingId, localPossId, origSpaceDoc, localSpaceId);
-
- try {
- writeSpaceDoc(result,localSpaceId);
- } catch (IOException e) {
- throw new MojoExecutionException(e,"IOException","can't write output file");
- }
- }
+ if (client == null) {
+ return;
+ }
- private SpaceDocument rewhackSpaceDocument(
- HashMap<Long, Long> remoteIdTolocalId, long localThingId,
- long localPossId, SpaceDocument origSpaceDoc, int localSpaceId) {
- SpaceDocument result = new SpaceDocument(localSpaceId,origSpaceDoc.getDisplayName(),origSpaceDoc.getOwnerUsername(),
- true /*origSpaceDoc.getPublished()*/,origSpaceDoc.getMaxGuests(),origSpaceDoc.getDisplaySea(),
- origSpaceDoc.getSeaLevel(),origSpaceDoc.getSimID());
-
- ThingDocument[] things=origSpaceDoc.getThingDocuments();
- for (int i=0; i<things.length;++i) {
- ThingDocument remoteThing=things[i];
- ThingDocument localThing=new ThingDocument(localThingId++,remoteThing.getDisplayName(),
- remoteIdTolocalId.get(new Long(remoteThing.getTemplateID())).longValue(),
- remoteThing.getTemplateOwner(),remoteThing.getOwnerUsername(),
- localPossId++, remoteThing.getTransform(),remoteThing.getSplinePath());
- result.addThingDocument(localThing);
- getLog().info("Fixed thing "+localThing.getDisplayName());
- }
- return result;
- }
+ if (reverseFile == null) {
+ getLog().info("No reverse file configured. Mojo ignored.");
+ return;
+ }
- private SpaceDocument buildTemplateMaps(
- HashMap<String, Long> displayNameToLocalId,
- HashMap<Long, Long> remoteIdTolocalId)
- throws MojoExecutionException, MojoFailureException {
- SpaceDocument origSpaceDoc=null;
- try {
- String revContent = StreamUtils.readInput(new FileInputStream(reverseFile));
- origSpaceDoc = new SpaceDocument(XMLElement.parseElementFromString(revContent));
- } catch (IOException e) {
- throw new MojoExecutionException(e,"IOException","Can't read space document "+reverseFile.getAbsolutePath());
- }
- File[] templateDirs= populateDir.listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.startsWith(TEMPLATE_PREFIX);
- }
- });
- File[] objectFiles=new File[templateDirs.length];
- for (int i=0; i< templateDirs.length;++i) {
- File[] objs = templateDirs[i].listFiles(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".obj");
- }
- });
- if (objs.length!=1) {
- throw new MojoExecutionException("Directory "+templateDirs[i].getName()+" has wrong number of object files:"+objs.length);
- }
- objectFiles[i]=objs[0];
- }
- for (int i=0; i<objectFiles.length;++i) {
- String tName = fileToTemplateName(objectFiles[i]);
- int num = dirNameToTemplateNumber(objectFiles[i].getParentFile());
- displayNameToLocalId.put(tName,new Long(num));
- }
- TemplateDocument[] mentioned = origSpaceDoc.getTemplateDocuments();
- for (int i=0; i<mentioned.length;++i) {
- TemplateDocument candidate = mentioned[i];
- String remoteDisplayName = candidate.getDisplayName();
- if (!displayNameToLocalId.containsKey(remoteDisplayName)) {
- throw new MojoFailureException("Can't find a local template with display name "+remoteDisplayName);
- }
- Long local=displayNameToLocalId.get(remoteDisplayName);
- remoteIdTolocalId.put(new Long(candidate.getTemplateID()), local);
- getLog().info("Mapped "+remoteDisplayName+" ["+candidate.getTemplateID()+" ->"+local+"]");
- }
- return origSpaceDoc;
- }
+ if ((!reverseFile.isFile()) || (!reverseFile.canRead())) {
+ throw new MojoExecutionException("Can't read reverse file " + reverseFile.getAbsolutePath());
+ }
- private void writeSpaceDoc(SpaceDocument result, int localSpaceId) throws IOException {
- FileWriter wr=new FileWriter(new File(populateDir,SPACE_PREFIX+localSpaceId));
- wr.write(result.toString());
- wr.close();
- getLog().info("Wrote new space document:"+(SPACE_PREFIX+localSpaceId));
- }
+ SpaceDocument origSpaceDoc = buildTemplateMaps(displayNameToLocalId, remoteIdTolocalId);
- private int getNextLocalSpaceId() throws MojoExecutionException {
- int attempt=1,TOO_BIG=500;
- File f;
- do {
- attempt++;
- f=new File(populateDir,SPACE_PREFIX+(attempt));
- //sanity
- if (attempt==TOO_BIG) {
- break;
- }
- } while (f.exists());
- if (attempt==TOO_BIG) {
- throw new MojoExecutionException("Don't know why but there are way too many space documents...aborting at "+attempt);
- }
- return attempt-1;
- }
+ int localSpaceId = getNextLocalSpaceId();
+ SpaceDocument result = rewhackSpaceDocument(remoteIdTolocalId, origSpaceDoc, localSpaceId);
+
+ try {
+ writeSpaceDoc(result, localSpaceId);
+ } catch (IOException e) {
+ throw new MojoExecutionException(e, "IOException", "can't write output file");
+ }
+ }
+
+ private SpaceDocument rewhackSpaceDocument(HashMap<Long, Long> remoteIdTolocalId, SpaceDocument origSpaceDoc, int localSpaceId) {
+ long localThingId = 1;
+ long localPossId = 1;
+
+ SpaceDocument result = new SpaceDocument(localSpaceId, origSpaceDoc.getDisplayName(), origSpaceDoc.getOwnerUsername(), true /*origSpaceDoc.getPublished()*/, origSpaceDoc.getMaxGuests(), origSpaceDoc.getDisplaySea(), origSpaceDoc.getSeaLevel(), origSpaceDoc.getSimID());
+
+ ThingDocument[] thingDocs = origSpaceDoc.getThingDocuments();
+ for (int i = 0; i < thingDocs.length; ++i) {
+ ThingDocument remoteThing = thingDocs[i];
+ ThingDocument localThing = new ThingDocument(localThingId++, remoteThing.getDisplayName(), remoteIdTolocalId.get(new Long(remoteThing.getTemplateID())), remoteThing.getTemplateOwner(), remoteThing.getOwnerUsername(), localPossId++, remoteThing.getTransform(), remoteThing.getSplinePath());
+ result.addThingDocument(localThing);
+ getLog().info("Fixed thing " + localThing.getDisplayName());
+ }
+
+ DoorDocument[] doorDocs = origSpaceDoc.getDoorDocuments();
+ for (int i = 0; i < doorDocs.length; i++) {
+ DoorDocument remoteDoor = doorDocs[i];
+ DoorDocument localDoorDoc = new DoorDocument(localThingId++, remoteDoor.getDisplayName(), remoteIdTolocalId.get(new Long(remoteDoor.getTemplateID())), remoteDoor.getTemplateOwner(), remoteDoor.getLink(), remoteDoor.getTransform());
+ result.addDoorDocument(localDoorDoc);
+ getLog().info("Fixed door " + localDoorDoc.getDisplayName());
+ }
+
+ SettingDocument[] settingDocs = origSpaceDoc.getSettingDocuments();
+ for (int i = 0; i < settingDocs.length; i++) {
+ result.addSetting(settingDocs[i].getKey(), settingDocs[i].getValue());
+ }
+
+ return result;
+ }
+
+ private SpaceDocument buildTemplateMaps(HashMap<String, Long> displayNameToLocalId, HashMap<Long, Long> remoteIdTolocalId) throws MojoExecutionException, MojoFailureException {
+ SpaceDocument origSpaceDoc = null;
+ try {
+ String revContent = StreamUtils.readInput(new FileInputStream(reverseFile));
+ origSpaceDoc = new SpaceDocument(XMLElement.parseElementFromString(revContent));
+ } catch (IOException e) {
+ throw new MojoExecutionException(e, "IOException", "Can't read space document " + reverseFile.getAbsolutePath());
+ }
+ File[] templateDirs = populateDir.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.startsWith(TEMPLATE_PREFIX);
+ }
+ });
+ File[] objectFiles = new File[templateDirs.length];
+ for (int i = 0; i < templateDirs.length; ++i) {
+ File[] objs = templateDirs[i].listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".obj");
+ }
+ });
+ if (objs.length != 1) {
+ throw new MojoExecutionException("Directory " + templateDirs[i].getName() + " has wrong number of object files:" + objs.length);
+ }
+ objectFiles[i] = objs[0];
+ }
+ for (int i = 0; i < objectFiles.length; ++i) {
+ String tName = fileToTemplateName(objectFiles[i]);
+ int num = dirNameToTemplateNumber(objectFiles[i].getParentFile());
+ displayNameToLocalId.put(tName, new Long(num));
+ }
+ TemplateDocument[] mentioned = origSpaceDoc.getTemplateDocuments();
+ for (int i = 0; i < mentioned.length; ++i) {
+ TemplateDocument candidate = mentioned[i];
+ String remoteDisplayName = candidate.getDisplayName();
+ if (!displayNameToLocalId.containsKey(remoteDisplayName)) {
+ throw new MojoFailureException("Can't find a local template with display name " + remoteDisplayName);
+ }
+ Long local = displayNameToLocalId.get(remoteDisplayName);
+ remoteIdTolocalId.put(new Long(candidate.getTemplateID()), local);
+ getLog().info("Mapped " + remoteDisplayName + " [" + candidate.getTemplateID() + " ->" + local + "]");
+ }
+
+ return origSpaceDoc;
+ }
+
+ private void writeSpaceDoc(SpaceDocument result, int localSpaceId) throws IOException {
+ FileWriter wr = new FileWriter(new File(populateDir, SPACE_PREFIX + localSpaceId));
+ wr.write(result.toString());
+ wr.close();
+ getLog().info("Wrote new space document:" + (SPACE_PREFIX + localSpaceId));
+ }
+
+ private int getNextLocalSpaceId() throws MojoExecutionException {
+ int attempt = 1, TOO_BIG = 500;
+ File f;
+ do {
+ attempt++;
+ f = new File(populateDir, SPACE_PREFIX + (attempt));
+ //sanity
+ if (attempt == TOO_BIG) {
+ break;
+ }
+ } while (f.exists());
+ if (attempt == TOO_BIG) {
+ throw new MojoExecutionException("Don't know why but there are way too many space documents...aborting at " + attempt);
+ }
+ return attempt - 1;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|