|
From: <cr...@us...> - 2008-08-05 10:06:13
|
Revision: 4399
http://jnode.svn.sourceforge.net/jnode/?rev=4399&view=rev
Author: crawley
Date: 2008-08-05 10:06:10 +0000 (Tue, 05 Aug 2008)
Log Message:
-----------
This provides an (interim) way to incorporate overrides into the VMware .vmx
file created by the build.
Modified Paths:
--------------
trunk/all/build-x86.xml
trunk/builder/src/builder/org/jnode/build/VMwareBuilderTask.java
trunk/jnode.properties.dist
Modified: trunk/all/build-x86.xml
===================================================================
--- trunk/all/build-x86.xml 2008-08-04 22:39:28 UTC (rev 4398)
+++ trunk/all/build-x86.xml 2008-08-05 10:06:10 UTC (rev 4399)
@@ -78,6 +78,11 @@
<property name="build.native.dir" value="${my-build.dir}/${jnode.bits}bits/native" />
<property name="build.bootimage.dir" value="${my-build.dir}/${jnode.bits}bits/bootimage" />
+ <condition property="vmware.vmx.overrides" value="">
+ <not>
+ <isset property="vmware.vmx.overrides"/>
+ </not>
+ </condition>
</target>
<!-- Initialize all project directories -->
@@ -276,6 +281,7 @@
isofile="${jnode-x86.iso}"
logFile="${logFile}"
memsize="${jnode.virtual.memsize}"
+ overrideFile="${vmware.vmx.overrides}"
/>
</target>
@@ -284,11 +290,11 @@
<create-cdrom destfile="${jnode-x86-lite.iso}" dir="${my-build.dir}/cdrom-lite" />
<taskdef name="vmware" classname="org.jnode.build.VMwareBuilderTask" classpathref="cp-x86" />
-
<vmware
isofile="${jnode-x86-lite.iso}"
logFile="${logFile}"
memsize="${jnode.virtual.memsize}"
+ overrideFile="${vmware.vmx.overrides}"
/>
</target>
@@ -296,11 +302,11 @@
<create-cdrom destfile="${jnode-x86_64-lite.iso}" dir="${my-build.dir}/cdrom-lite" />
<taskdef name="vmware" classname="org.jnode.build.VMwareBuilderTask" classpathref="cp-x86" />
-
<vmware
isofile="${jnode-x86_64-lite.iso}"
logFile="${logFile}"
memsize="${jnode.virtual.memsize}"
+ overrideFile="${vmware.vmx.overrides}"
/>
</target>
Modified: trunk/builder/src/builder/org/jnode/build/VMwareBuilderTask.java
===================================================================
--- trunk/builder/src/builder/org/jnode/build/VMwareBuilderTask.java 2008-08-04 22:39:28 UTC (rev 4398)
+++ trunk/builder/src/builder/org/jnode/build/VMwareBuilderTask.java 2008-08-05 10:06:10 UTC (rev 4399)
@@ -21,18 +21,33 @@
package org.jnode.build;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.Properties;
+import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
+/**
+ * This task builds a VMWare '.vmx' file to allow JNode to be run using VMWare player.
+ *
+ * @author ...
+ * @author cr...@jn...
+ */
public class VMwareBuilderTask extends Task {
private String logFile; // log file use for kernel debugger messages
private String isoFile;
private int memorySize;
+ private String overrideFile;
/**
* @return Returns the memorySize.
@@ -63,71 +78,139 @@
}
/**
+ * The override file is a Java Properties file containing VMX settings
+ * to override the default ones hard-wired into this class.
+ *
+ * @return Returns the override file or <code>null</code>
+ */
+ public String getOverrideFile() {
+ return overrideFile;
+ }
+
+ /**
+ * @param overrideFile The override file to set.
+ */
+ public void setOverrideFile(String overrideFile) {
+ this.overrideFile = overrideFile;
+ }
+
+ /**
* @see org.apache.tools.ant.Task#execute()
*/
@Override
public void execute() throws BuildException {
+ // Build the default properties, based on the supplied memSize and logFile.
+ Properties props = new Properties();
+ buildDefaultProperties(props);
+
+ if (overrideFile != null && overrideFile.length() > 0) {
+ // If VMX overrides are provided, read them and add them to the properties;
+ BufferedReader br = null;
+ try {
+ // Unfortunately, we cannot use java.util.Property#load(...) because
+ // VMX properties can have ':' in the property name.
+ br = new BufferedReader(new FileReader(overrideFile));
+ String line;
+ final Pattern propertyPattern = Pattern.compile("^([a-zA-Z0-9\\.:]+)\\s*=\\s*\"([^\"]*)\"");
+ final Pattern commentPattern = Pattern.compile("^#");
+ while ((line = br.readLine()) != null) {
+ line = line.trim();
+ if (line.isEmpty() || commentPattern.matcher(line).find()) {
+ continue;
+ }
+ Matcher matcher = propertyPattern.matcher(line);
+ if (!matcher.find()) {
+ throw new BuildException(
+ "Cannot parse this VMX override: '" + line + "'");
+ }
+ props.put(matcher.group(1), matcher.group(2));
+ }
+ } catch (FileNotFoundException ex) {
+ throw new BuildException(
+ "Cannot open the VMX override file: " + overrideFile, ex);
+ } catch (IOException ex) {
+ throw new BuildException(
+ "Problem reading the VMX override file: " + overrideFile, ex);
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (IOException ex) {
+ /* ignore it */
+ }
+ }
+ }
+ }
+
+ // Now output the VMX file from the properties, sorted in key order for neatness.
+ File vmxFile = new File(isoFile + ".vmx");
try {
- FileWriter out = new FileWriter(new File(isoFile + ".vmx"));
+ FileWriter out = new FileWriter(vmxFile);
try {
PrintWriter w = new PrintWriter(out);
+ TreeSet<Object> keys = new TreeSet<Object>();
+ keys.addAll(props.keySet());
+ for (Object key : keys) {
+ Object value = props.get(key);
+ w.println(key + " = \"" + value + "\"");
+ }
+ } finally {
+ out.close();
+ }
+ } catch (IOException ex) {
+ throw new BuildException("Problem writing the VMX file: " + vmxFile);
+ }
+ }
- put(w, "config.version", "8");
- put(w, "virtualHW.version", "4");
- put(w, "memsize", String.valueOf(memorySize));
- put(w, "MemAllowAutoScaleDown", "FALSE");
- put(w, "ide0:0.present", "TRUE");
- put(w, "ide0:0.fileName", new File(isoFile).getName());
- put(w, "ide0:0.deviceType", "cdrom-image");
- put(w, "ide1:0.present", "FALSE");
- put(w, "floppy0.present", "FALSE");
- put(w, "usb.present", "TRUE");
- put(w, "sound.present", "FALSE");
- put(w, "sound.virtualDev", "es1371");
- put(w, "displayName", "JNode");
- put(w, "guestOS", "dos");
+ private void buildDefaultProperties(Properties props) {
+ props.put("config.version", "8");
+ props.put("virtualHW.version", "4");
+ props.put("memsize", String.valueOf(memorySize));
+ props.put("MemAllowAutoScaleDown", "FALSE");
- put(w, "nvram", "JNode.nvram");
- put(w, "MemTrimRate", "-1");
- put(w, "ide0:0.redo", "");
+ props.put("ide0:0.present", "TRUE");
+ props.put("ide0:0.startConnected", "TRUE");
+ props.put("ide0:0.fileName", new File(isoFile).getName());
+ props.put("ide0:0.deviceType", "cdrom-image");
+ props.put("ide0:0.redo", "");
- final String osName = System.getProperty("os.name").toLowerCase();
- if (osName.contains("linux") || osName.contains("unix") ||
- osName.contains("bsd")) {
- put(w, "ethernet0.connectionType", "bridged");
- put(w, "ethernet0.vnet", "/dev/vmnet1");
- }
- put(w, "ethernet0.addressType", "generated");
- put(w, "ethernet0.generatedAddress", "00:0c:29:2a:96:30");
- put(w, "ethernet0.generatedAddressOffset", "0");
- put(w, "ethernet0.present", "TRUE");
- put(w, "ethernet0.startConnected", "TRUE");
+ props.put("ide1:0.present", "FALSE");
+ props.put("ide1:0.startConnected", "TRUE");
- put(w, "uuid.location", "56 4d 94 59 c9 96 80 88-6c 3a 37 80 04 68 c9 b2");
- put(w, "uuid.bios", "56 4d 94 59 c9 96 80 88-6c 3a 37 80 04 68 c9 b2");
+ props.put("floppy0.present", "FALSE");
+ props.put("usb.present", "TRUE");
+ props.put("sound.present", "FALSE");
+ props.put("sound.virtualDev", "es1371");
+ props.put("displayName", "JNode");
+ props.put("guestOS", "dos");
+ props.put("nvram", "JNode.nvram");
+ props.put("MemTrimRate", "-1");
- if ((logFile != null) && (logFile.trim().length() != 0)) {
- put(w, "serial0.present", "TRUE");
- put(w, "serial0.fileType", "file");
- put(w, "serial0.fileName", logFile);
- }
+ final String osName = System.getProperty("os.name").toLowerCase();
+ if (osName.contains("linux") || osName.contains("unix") ||
+ osName.contains("bsd")) {
+ props.put("ethernet0.connectionType", "bridged");
+ props.put("ethernet0.vnet", "/dev/vmnet1");
+ }
+ props.put("ethernet0.addressType", "generated");
+ props.put("ethernet0.generatedAddress", "00:0c:29:2a:96:30");
+ props.put("ethernet0.generatedAddressOffset", "0");
+ props.put("ethernet0.present", "TRUE");
+ props.put("ethernet0.startConnected", "TRUE");
- put(w, "tools.syncTime", "TRUE");
- put(w, "ide1:0.startConnected", "TRUE");
- put(w, "uuid.action", "create");
- put(w, "checkpoint.vmState", "");
+ props.put("uuid.location", "56 4d 94 59 c9 96 80 88-6c 3a 37 80 04 68 c9 b2");
+ props.put("uuid.bios", "56 4d 94 59 c9 96 80 88-6c 3a 37 80 04 68 c9 b2");
- } finally {
- out.close();
- }
- } catch (IOException ex) {
- throw new BuildException(ex);
+ if (logFile != null && logFile.trim().length() != 0) {
+ props.put("serial0.present", "TRUE");
+ props.put("serial0.fileType", "file");
+ props.put("serial0.fileName", logFile);
}
- }
- private void put(PrintWriter w, String key, String value) {
- w.println(key + " = \"" + value + "\"");
+ props.put("tools.syncTime", "TRUE");
+ props.put("uuid.action", "create");
+ props.put("checkpoint.vmState", "");
}
/**
@@ -138,7 +221,8 @@
}
/**
- * @param isoFile The isoFile to set.
+ * @param isoFile
+ * The isoFile to set.
*/
public final void setIsoFile(String isoFile) {
this.isoFile = isoFile;
Modified: trunk/jnode.properties.dist
===================================================================
--- trunk/jnode.properties.dist 2008-08-04 22:39:28 UTC (rev 4398)
+++ trunk/jnode.properties.dist 2008-08-05 10:06:10 UTC (rev 4399)
@@ -67,3 +67,21 @@
# This is needed by the hotswap ant target.
jnode.debugger.host=
jnode.debugger.port=6789
+
+# -----------------------------------------------
+# Settings for a VMware virtual machine
+# -----------------------------------------------
+
+# Uncomment and edit this line if you want to override the settings
+# in the 'jnode-x86-*.vmx' file. For example, you may want to include
+# settings to configure a VMware virtual hard drive, or real hard drive.
+# Refer to the maintainers pages on the JNode website for details.
+# Notes:
+# - Settings in the override file should be in standard VMX syntax.
+# - The settings override the default settings, including (if you
+# set them) the memSize and/or logFile parameters set in the
+# ant build.xml files.
+# - Any non-absolute pathnames in the VMX settings are resolved relative
+# to the VMX file's location!
+
+#vmware.vmx.overrides=<some-file-containing-vmx-settings>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|