Author: rob.stryker(a)jboss.com
Date: 2012-10-11 05:08:31 -0400 (Thu, 11 Oct 2012)
New Revision: 44423
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBMarshallTest.java
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBUnmarshallTest.java
Log:
JBIDE-12813 to trunk
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java 2012-10-11
08:50:57 UTC (rev 44422)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java 2012-10-11
09:08:31 UTC (rev 44423)
@@ -31,6 +31,7 @@
import org.jboss.ide.eclipse.archives.core.model.IArchive;
import org.jboss.ide.eclipse.archives.core.model.IArchiveModelRootNode;
import org.jboss.ide.eclipse.archives.core.model.internal.ArchiveImpl;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbProperties.PropertiesExt;
/**
@@ -99,9 +100,8 @@
XMLMemento root = XMLMemento.createWriteRoot("packages"); //$NON-NLS-1$
root.putString("version", new Double(element.getVersion()).toString());
//$NON-NLS-1$
List packagesToAdd = element.getChildren(XbPackage.class);
- List props = element.getChildren(XbProperties.class);
marshallAddPackages(root, nullSafe(packagesToAdd));
- marshallAddProperties(root, nullSafe(props));
+ marshallAddProperties(root, element.getProperties());
try{
String s = root.saveToString();
writer.write(s);
@@ -137,7 +137,7 @@
addFileset(childMemento, nullSafe(childXb.getChildren(XbFileSet.class)));
addLibFileset(childMemento, nullSafe(childXb.getChildren(XbLibFileSet.class)));
addFolders(childMemento, nullSafe(childXb.getChildren(XbFolder.class)));
- marshallAddProperties(childMemento,
nullSafe(childXb.getChildren(XbProperties.class)));
+ marshallAddProperties(childMemento, childXb.getProperties());
}
}
@@ -155,7 +155,7 @@
addFileset(childMemento, nullSafe(childXb.getChildren(XbFileSet.class)));
addLibFileset(childMemento, nullSafe(childXb.getChildren(XbLibFileSet.class)));
addFolders(childMemento, nullSafe(childXb.getChildren(XbFolder.class)));
- marshallAddProperties(childMemento,
nullSafe(childXb.getChildren(XbProperties.class)));
+ marshallAddProperties(childMemento, childXb.getProperties());
}
}
@@ -175,7 +175,7 @@
fsMemento.putString("excludes", fsXb.getExcludes()); //$NON-NLS-1$
fsMemento.putString("inWorkspace",new
Boolean(fsXb.isInWorkspace()).toString()); //$NON-NLS-1$
fsMemento.putString("flatten", new Boolean(fsXb.isFlatten()).toString());
//$NON-NLS-1$
- marshallAddProperties(fsMemento, nullSafe(fsXb.getChildren(XbProperties.class)));
+ marshallAddProperties(fsMemento, fsXb.getProperties());
}
}
@@ -186,22 +186,23 @@
XbLibFileSet fsXb = (XbLibFileSet)i.next();
if( !isEmpty(fsXb.getId()))
fsMemento.putString("name", fsXb.getId()); //$NON-NLS-1$
- marshallAddProperties(fsMemento, nullSafe(fsXb.getChildren(XbProperties.class)));
+ marshallAddProperties(fsMemento, fsXb.getProperties());
}
}
- private static void marshallAddProperties(XMLMemento memento, List properties) {
+ private static void marshallAddProperties(XMLMemento memento, XbProperties properties)
{
// should only have one "properties"
- XbProperties propsObj = properties.size() == 0 ? null :
(XbProperties)properties.get(0);
XMLMemento props = (XMLMemento)memento.createChild("properties");
//$NON-NLS-1$
- if( propsObj != null ) {
- List indivProps = propsObj.getAllChildren();
- Iterator j = indivProps.iterator();
+ if( properties != null ) {
+ PropertiesExt ext = properties.getProperties();
+ Set<Object> set = ext.keySet();
+ Iterator j = set.iterator();
while(j.hasNext()) {
- XbProperty prop = (XbProperty)j.next();
+ String prop = (String)j.next();
+ String value = ext.getProperty(prop);
XMLMemento propMemento = (XMLMemento) props.createChild("property");
//$NON-NLS-1$
- propMemento.putString("name", prop.getName()); //$NON-NLS-1$
- propMemento.putString("value", prop.getValue()); //$NON-NLS-1$
+ propMemento.putString("name", prop); //$NON-NLS-1$
+ propMemento.putString("value", value); //$NON-NLS-1$
}
}
}
@@ -217,7 +218,7 @@
}
}
- protected static XbPackages unmarshal (final InputStream in,
+ public static XbPackages unmarshal (final InputStream in,
final IProgressMonitor monitor) throws XbException {
XMLMemento root = XMLMemento.createReadRoot(in);
if( root == null ) {
@@ -293,7 +294,7 @@
// properties
IMemento[] propertiesChild = packageChildren[i].getChildren("properties");
//$NON-NLS-1$
if( propertiesChild != null && propertiesChild.length == 1)
- unmarshallProperties(packs, propertiesChild[0]);
+ unmarshallProperties(pack, propertiesChild[0]);
packs.addChild(pack);
}
@@ -376,7 +377,7 @@
}
private static void unmarshallProperties(XbPackageNodeWithProperties node, IMemento
propNode) throws XbException {
XbProperties propsWrapper = new XbProperties();
- node.addChild(propsWrapper);
+ node.setProperties(propsWrapper);
String[] names = ((XMLMemento)propNode).getChildNames();
Set<String> set = new TreeSet<String>();
set.addAll(Arrays.asList(names));
@@ -397,7 +398,7 @@
throw new XbException(new Exception("Element 'property' contains unknown
attribute key")); //$NON-NLS-1$
p.setName(name);
p.setValue(val);
- propsWrapper.addChild(p);
+ propsWrapper.addProperty(p);
}
}
}
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2012-10-11
08:50:57 UTC (rev 44422)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2012-10-11
09:08:31 UTC (rev 44423)
@@ -20,6 +20,7 @@
import org.jboss.ide.eclipse.archives.test.model.ModelCreationTest;
import org.jboss.ide.eclipse.archives.test.model.ModelTruezipBridgeTest;
import org.jboss.ide.eclipse.archives.test.model.ModelUtilTest;
+import org.jboss.ide.eclipse.archives.test.model.ReadWriteTest;
import org.jboss.ide.eclipse.archives.test.model.XBMarshallTest;
import org.jboss.ide.eclipse.archives.test.model.XBUnmarshallTest;
import org.jboss.ide.eclipse.archives.test.projects.InnerZipResourceTimestampTest;
@@ -38,6 +39,7 @@
suite.addTestSuite(ArchivesCoreTest.class);
suite.addTestSuite(XBMarshallTest.class);
suite.addTestSuite(XBUnmarshallTest.class);
+ suite.addTestSuite(ReadWriteTest.class);
suite.addTestSuite(TruezipUtilTest.class);
suite.addTestSuite(ModelUtilTest.class);
suite.addTestSuite(DirectoryScannerTest.class);
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBMarshallTest.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBMarshallTest.java 2012-10-11
08:50:57 UTC (rev 44422)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBMarshallTest.java 2012-10-11
09:08:31 UTC (rev 44423)
@@ -111,7 +111,7 @@
}
}
}
- protected String writeToString(XbPackages packs, boolean shouldPass) {
+ public static String writeToString(XbPackages packs, boolean shouldPass) {
XbException e = null;
try {
return XMLBinding.serializePackages(packs, new NullProgressMonitor());
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBUnmarshallTest.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBUnmarshallTest.java 2012-10-11
08:50:57 UTC (rev 44422)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/model/XBUnmarshallTest.java 2012-10-11
09:08:31 UTC (rev 44423)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.ide.eclipse.archives.test.model;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.List;
@@ -188,10 +191,14 @@
* Utility
*/
- protected XbPackages parse(String file, boolean shouldSucceed, String failMsg) {
+ public XbPackages parse(String file, boolean shouldSucceed, String failMsg) {
+ File f = archiveDescriptors.append(file).toFile();
+ return parseFromFile(f, shouldSucceed, failMsg );
+ }
+ public static XbPackages parseFromFile(File f, boolean shouldSucceed, String failMsg) {
XbPackages packs = null;
try {
- packs = XMLBinding.unmarshal(archiveDescriptors.append(file).toFile(), new
NullProgressMonitor());
+ packs = XMLBinding.unmarshal(f, new NullProgressMonitor());
} catch( XbException e ) {
if( shouldSucceed )
fail(failMsg + " - " + e.getMessage());
@@ -202,6 +209,21 @@
return packs;
}
+ public static XbPackages parseFromString(String xml, boolean shouldSucceed, String
failMsg) {
+ XbPackages packs = null;
+ ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes());
+ try {
+ packs = XMLBinding.unmarshal(is, new NullProgressMonitor());
+ } catch( XbException e ) {
+ if( shouldSucceed )
+ fail(failMsg + " - " + e.getMessage());
+ return packs;
+ }
+ if( !shouldSucceed )
+ fail(failMsg);
+ return packs;
+ }
+
protected String failedMissingRequiredAtt(String att) {
return "File parsed while missing a required attribute: " + att;
}