diff options
author | Victor Mocanu | 2018-04-04 14:10:54 +0200 |
---|---|---|
committer | Victor Mocanu | 2018-04-04 14:10:54 +0200 |
commit | 625affe1a6b0fcecd826c1f4960074545f0def43 (patch) | |
tree | 859f8db451e0536e31d97bdf48aa47338684266e /src/main/java | |
parent | [Vbox] repaired a null pointer exception when disabling USB (diff) | |
download | master-sync-shared-625affe1a6b0fcecd826c1f4960074545f0def43.tar.gz master-sync-shared-625affe1a6b0fcecd826c1f4960074545f0def43.tar.xz master-sync-shared-625affe1a6b0fcecd826c1f4960074545f0def43.zip |
[Vbox] code formating
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/openslx/util/vm/VboxConfig.java | 59 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/VboxMetaData.java | 22 |
2 files changed, 39 insertions, 42 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java index 45dfb48..616aa7c 100644 --- a/src/main/java/org/openslx/util/vm/VboxConfig.java +++ b/src/main/java/org/openslx/util/vm/VboxConfig.java @@ -53,27 +53,23 @@ public class VboxConfig // a black list of sorts of tags that need to be removed from the .vbox file private static String[] blackList = { "HID", "USB", "ExtraData", "Adapter", "GuestProperties", "LPT", "StorageController", "FloppyImages", "DVDImages", "AttachedDevice" }; - public static enum PlaceHolder + public static enum PlaceHolder { - FLOPPYUUID("%OpenSLX_FloppyUUID%"), - FLOPPYLOCATION("%OpenSLX_Floppy_Location%"), - CPU("%OpenSLX_CPU%"), - MEMORY("%OpenSLX_MEMORY%"), - MACHINEUUID("%OpenSLX_MUUID%"), - NETWORKMAC("%OpenSLX_Networkcard_MACAddress%"), - HDDLOCATION("%OpenSLX_HDD_Location%"), - HDDUUID("%OpenSLX_HDDUUID_"); + FLOPPYUUID( "%OpenSLX_FloppyUUID%" ), FLOPPYLOCATION( "%OpenSLX_Floppy_Location%" ), CPU( "%OpenSLX_CPU%" ), MEMORY( "%OpenSLX_MEMORY%" ), MACHINEUUID( + "%OpenSLX_MUUID%" ), NETWORKMAC( "%OpenSLX_Networkcard_MACAddress%" ), HDDLOCATION( "%OpenSLX_HDD_Location%" ), HDDUUID( "%OpenSLX_HDDUUID_" ); private final String holderName; - private PlaceHolder(String name) + + private PlaceHolder( String name ) { this.holderName = name; } - + public String holderName() { return holderName; } } + /** * constructor with input xml file * used to set the doc variable of this class when creating vm @@ -164,35 +160,37 @@ public class VboxConfig } } - private void ensureHardwareUuid() throws XPathExpressionException { + private void ensureHardwareUuid() throws XPathExpressionException + { NodeList hwNodes = findNodes( "Hardware" ); int count = hwNodes.getLength(); // we will need the machine uuid, so get it String machineUuid = xPath.compile( "/VirtualBox/Machine/@uuid" ).evaluate( this.doc ); - if (machineUuid.isEmpty()) { - LOGGER.error("Machine UUID empty, should never happen!"); + if ( machineUuid.isEmpty() ) { + LOGGER.error( "Machine UUID empty, should never happen!" ); return; } // now check if we had a <Hardware/> node, which we always should - if (count == 1) { - Element hw = (Element) hwNodes.item(0); - String hwUuid = hw.getAttribute("uuid"); - if (!hwUuid.isEmpty()) { - LOGGER.info("Found hardware uuid: " + hwUuid); + if ( count == 1 ) { + Element hw = (Element)hwNodes.item( 0 ); + String hwUuid = hw.getAttribute( "uuid" ); + if ( !hwUuid.isEmpty() ) { + LOGGER.info( "Found hardware uuid: " + hwUuid ); return; } else { - if (!addAttributeToNode(hw, "uuid", machineUuid)) { - LOGGER.error("Failed to set machine UUID '" + machineUuid + "' as hardware UUID."); + if ( !addAttributeToNode( hw, "uuid", machineUuid ) ) { + LOGGER.error( "Failed to set machine UUID '" + machineUuid + "' as hardware UUID." ); return; } - LOGGER.info("Saved machine UUID as hardware UUID."); + LOGGER.info( "Saved machine UUID as hardware UUID." ); } } else { // zero or more than 1 <Hardware/> were found, fatal either way // HACK: hijack XPathExpressionException ... - throw new XPathExpressionException("Zero or more than one <Hardware> node found, should never happen!"); + throw new XPathExpressionException( "Zero or more than one <Hardware> node found, should never happen!" ); } } + /** * Function checks if the placeholders are present * @@ -283,7 +281,7 @@ public class VboxConfig { // placeholder for the MACAddress changeAttribute( "Adapter", "MACAddress", PlaceHolder.NETWORKMAC.holderName() ); - + // placeholder for the machine uuid changeAttribute( "Machine", "uuid", PlaceHolder.MACHINEUUID.holderName() ); @@ -318,7 +316,8 @@ public class VboxConfig /** * Function used to find nodes in the document - * Function returnes a NodeList of Nodes...not just a Node...even when the wanted Node is a single + * Function returnes a NodeList of Nodes...not just a Node...even when the wanted Node is a + * single * Node, you get a NodeList with just one element * * @param targetTag as String @@ -416,8 +415,8 @@ public class VboxConfig } try { ( (Element)targetNode ).setAttribute( attrName, value ); - } catch (DOMException e) { - LOGGER.error("Failed set '" + attrName + "' to '" + value + "' of xml node '" + targetNode.getNodeName() + "': ", e); + } catch ( DOMException e ) { + LOGGER.error( "Failed set '" + attrName + "' to '" + value + "' of xml node '" + targetNode.getNodeName() + "': ", e ); return false; } return true; @@ -461,8 +460,8 @@ public class VboxConfig newNode.appendChild( a ); } parent.appendChild( newNode ); - } catch (DOMException e) { - LOGGER.error("Something went wrong: ", e); + } catch ( DOMException e ) { + LOGGER.error( "Something went wrong: ", e ); return null; } @@ -497,7 +496,7 @@ public class VboxConfig // function removes a given child and the format childNode private void removeNode( Node node ) { - if (node == null ) { + if ( node == null ) { LOGGER.warn( "node is null; unsafe" ); return; } diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java index 1d857b0..c1b8a9b 100644 --- a/src/main/java/org/openslx/util/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java @@ -69,9 +69,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, public static enum EthernetType { - NAT( "vboxnet1" ), - BRIDGED( "vboxnet0" ), - HOST_ONLY( "vboxnet2" ); + NAT( "vboxnet1" ), BRIDGED( "vboxnet0" ), HOST_ONLY( "vboxnet2" ); public final String vnet; @@ -151,7 +149,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, config.changeAttribute( "HardDisk", "location", diskImagePath ); UUID newhdduuid = UUID.randomUUID(); - + // patching the new uuid in the vbox config file here String vboxUUid = "{" + newhdduuid.toString() + "}"; config.changeAttribute( "HardDisk", "uuid", vboxUUid ); @@ -163,15 +161,15 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, // order when we are adding them to the bytebuffer won't help // // the following is a workaround that works - ByteBuffer buffer = ByteBuffer.wrap( new byte[16] ); + ByteBuffer buffer = ByteBuffer.wrap( new byte[ 16 ] ); buffer.putLong( newhdduuid.getMostSignificantBits() ); buffer.putLong( newhdduuid.getLeastSignificantBits() ); byte[] oldOrder = buffer.array(); // make a coppy here because the last 8 Bytes don't need to change position byte[] bytesToWrite = Arrays.copyOf( oldOrder, oldOrder.length ); // use an offset int[] to help with the shuffle - int[] offsets = { 3, 2, 1, 0, 5, 4, 7, 6}; - for ( int index = 0; index < 8; index++) { + int[] offsets = { 3, 2, 1, 0, 5, 4, 7, 6 }; + for ( int index = 0; index < 8; index++ ) { bytesToWrite[index] = oldOrder[offsets[index]]; } try ( RandomAccessFile file = new RandomAccessFile( diskImage, "rw" ) ) { @@ -236,7 +234,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, } Element attachedDev = null; - + if ( image == null ) { attachedDev = (Element)config.addNewNode( "StorageController", "AttachedDevice", true, "name", "Floppy" ); LOGGER.warn( "Floppy controller has no image attached" ); @@ -250,7 +248,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, floppyImageTag.setAttribute( "uuid", VboxConfig.PlaceHolder.FLOPPYUUID.holderName() ); floppyImageTag.setAttribute( "location", VboxConfig.PlaceHolder.FLOPPYLOCATION.holderName() ); } - + attachedDev.setAttribute( "type", "Floppy" ); attachedDev.setAttribute( "hotpluggable", "false" ); attachedDev.setAttribute( "port", "0" ); @@ -435,11 +433,11 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, public boolean addEthernet( VmMetaData.EtherType type ) { Node hostOnlyInterfaceNode = config.addNewNode( "Adapter", "HostOnlyInterface", true, "slot", "0" ); - if (hostOnlyInterfaceNode == null) { - LOGGER.error("Failed to create node for HostOnlyInterface."); + if ( hostOnlyInterfaceNode == null ) { + LOGGER.error( "Failed to create node for HostOnlyInterface." ); return false; } - return config.addAttributeToNode(hostOnlyInterfaceNode, "name", EthernetType.valueOf(type.name()).vnet); + return config.addAttributeToNode( hostOnlyInterfaceNode, "name", EthernetType.valueOf( type.name() ).vnet ); } @Override |