diff options
| author | Markus Tiede | 2013-11-21 08:26:49 +0000 |
|---|---|---|
| committer | Markus Tiede | 2013-11-21 08:26:55 +0000 |
| commit | 06df02a29045fc7cecd348246144c6a8a922b959 (patch) | |
| tree | d619dfafda4843d08a77cbfc1cd66cbbd6fc7a0a | |
| parent | b4c80d91dfdb9255fd6dddaba4de8dd6d596bd86 (diff) | |
| download | org.eclipse.jubula.core-06df02a29045fc7cecd348246144c6a8a922b959.tar.gz org.eclipse.jubula.core-06df02a29045fc7cecd348246144c6a8a922b959.tar.xz org.eclipse.jubula.core-06df02a29045fc7cecd348246144c6a8a922b959.zip | |
Non-sprint task - major memory usage improvements for dbtool: http://bugzilla.bredex.de/1220
10 files changed, 56 insertions, 103 deletions
diff --git a/org.eclipse.jubula.client.archive/META-INF/MANIFEST.MF b/org.eclipse.jubula.client.archive/META-INF/MANIFEST.MF index ce7816ebd..946fe1f53 100644 --- a/org.eclipse.jubula.client.archive/META-INF/MANIFEST.MF +++ b/org.eclipse.jubula.client.archive/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)", org.eclipse.jubula.ui.compatibility;bundle-version="[2.3.0,2.4.0)", org.apache.commons.beanutils;bundle-version="[1.7.0,2.0.0)", org.apache.commons.lang;bundle-version="[2.4.0,3.0.0)", + org.apache.commons.io;bundle-version="[2.0.0,3.0.0)", javax.persistence;bundle-version="[2.0.3,2.1.0)", org.slf4j.api;bundle-version="[1.7.2,2.0.0)", org.eclipse.jubula.tools;bundle-version="[2.3.0,2.4.0)", diff --git a/org.eclipse.jubula.client.archive/src/org/eclipse/jubula/client/archive/XmlStorage.java b/org.eclipse.jubula.client.archive/src/org/eclipse/jubula/client/archive/XmlStorage.java index 8065e53e4..065613f1e 100644 --- a/org.eclipse.jubula.client.archive/src/org/eclipse/jubula/client/archive/XmlStorage.java +++ b/org.eclipse.jubula.client.archive/src/org/eclipse/jubula/client/archive/XmlStorage.java @@ -13,10 +13,9 @@ package org.eclipse.jubula.client.archive; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; -import java.io.OutputStream; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -28,6 +27,8 @@ import java.util.TimerTask; import javax.persistence.PersistenceException; +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.output.FileWriterWithEncoding; import org.apache.commons.lang.Validate; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlOptions; @@ -70,8 +71,8 @@ public class XmlStorage { /** The monitor for which the IO is taking place. */ private IProgressMonitor m_monitor; - /** The output stream in which the IO is taking place. */ - private OutputStream m_outputStream; + /** The writer in which the IO is taking place. */ + private FileWriterWithEncoding m_writer; /** The Timer used to schedule regular interruption checks. */ private Timer m_timer; @@ -79,14 +80,16 @@ public class XmlStorage { /** * Constructor * - * @param monitor The monitor for which the IO is taking place. - * @param outputStream The output stream in which the IO is taking place. + * @param monitor + * The monitor for which the IO is taking place. + * @param writer + * The writer in which the IO is taking place. */ - public IOCanceller(IProgressMonitor monitor, - OutputStream outputStream) { - + public IOCanceller(IProgressMonitor monitor, + FileWriterWithEncoding writer) { + m_monitor = monitor; - m_outputStream = outputStream; + m_writer = writer; m_timer = new Timer(); } @@ -111,7 +114,7 @@ public class XmlStorage { private void checkTask() { if (m_monitor.isCanceled()) { try { - m_outputStream.close(); + m_writer.close(); } catch (IOException e) { log.error(Messages.ErrorWhileCloseOS, e); } @@ -140,14 +143,8 @@ public class XmlStorage { /** XML header end */ private static final String XML_HEADER_END = "?>"; //$NON-NLS-1$ - /** centralized definition of characters for XML header */ - private static final char QUOTE = '"'; - /** centralized definition of characters for XML header */ - private static final char SPACE = ' '; - /** centralized definition of characters for XML header */ - /** - * the current xml schema namespace + * the current XML schema namespace */ private static final String SCHEMA_NAMESPACE = "http://www.eclipse.org/jubula/client/archive/schema"; //$NON-NLS-1$ @@ -183,7 +180,7 @@ public class XmlStorage { * @throws ProjectDeletedException * in case of current project is already deleted */ - private static String save(IProjectPO project, + private static InputStream save(IProjectPO project, boolean includeTestResultSummaries, IProgressMonitor monitor) throws ProjectDeletedException, PMException { XmlOptions genOpts = new XmlOptions(); @@ -233,7 +230,7 @@ public class XmlStorage { "XML" + Messages.ValidateFailed + msgs.toString(), //$NON-NLS-1$ MessageIDs.E_FILE_IO); } - return contentDoc.xmlText(genOpts); + return contentDoc.newInputStream(genOpts); } /** @@ -351,39 +348,7 @@ public class XmlStorage { * string, if fileName == null! * * @param proj - * proj to be saved - * @param fileName - * name for file to save or null, if wanting to get the project - * as serialized string - * @param includeTestResultSummaries - * Whether to save the Test Result Summaries as well. - * @param monitor - * The progress monitor for this potentially long-running - * operation. - * @return the serialized project as string, if fileName == null<br> - * or<br> - * <b>Returns:</b><br> - * null otherwise. Always returns <code>null</code> if the save - * operation was canceled. - * @throws PMException - * if save failed for any reason - * @throws ProjectDeletedException - * in case of current project is already deleted - */ - public static String save(IProjectPO proj, String fileName, - boolean includeTestResultSummaries, IProgressMonitor monitor) - throws ProjectDeletedException, PMException { - - return save(proj, fileName, includeTestResultSummaries, - monitor, false, null); - } - - /** - * Save a project as XML to a file or return the serialized project as - * string, if fileName == null! - * - * @param proj - * proj to be saved + * project to be saved * @param fileName * name for file to save or null, if wanting to get the project * as serialized string @@ -418,29 +383,31 @@ public class XmlStorage { getWorkToSave(proj)); Validate.notNull(proj); - FileOutputStream fOut = null; + FileWriterWithEncoding fWriter = null; try { - String xml = buildXmlHeader() - + XmlStorage.save(proj, includeTestResultSummaries, monitor); + InputStream projXMLStream = XmlStorage.save(proj, + includeTestResultSummaries, monitor); if (fileName == null) { - return xml; + return IOUtils.toString(projXMLStream, + RECOMMENDED_CHAR_ENCODING); } - + if (writeToSystemTempDir) { File fileInTempDir = createTempFile(fileName); if (listOfProjectFiles != null) { listOfProjectFiles.add(fileInTempDir); } - fOut = new FileOutputStream(fileInTempDir); - } else { - fOut = new FileOutputStream(fileName); + fWriter = new FileWriterWithEncoding(fileInTempDir, + RECOMMENDED_CHAR_ENCODING); + } else { + fWriter = new FileWriterWithEncoding(fileName, + RECOMMENDED_CHAR_ENCODING); } - - IOCanceller canceller = - new IOCanceller(monitor, fOut); + + IOCanceller canceller = new IOCanceller(monitor, fWriter); canceller.startTask(); - fOut.write(xml.getBytes(RECOMMENDED_CHAR_ENCODING)); + IOUtils.copy(projXMLStream, fWriter, RECOMMENDED_CHAR_ENCODING); canceller.taskFinished(); } catch (FileNotFoundException e) { log.debug(Messages.File + StringConstants.SPACE @@ -451,7 +418,7 @@ public class XmlStorage { + e.toString(), MessageIDs.E_FILE_IO); } catch (IOException e) { // If the operation has been canceled, then this is just - // a result of cancelling the IO. + // a result of canceling the IO. if (!monitor.isCanceled()) { log.debug(Messages.GeneralIoExeption, e); throw new PMSaveException(Messages.GeneralIoExeption @@ -463,12 +430,12 @@ public class XmlStorage { throw new PMSaveException(e.getMessage(), MessageIDs.E_DATABASE_GENERAL); } finally { - if (fOut != null) { + if (fWriter != null) { try { - fOut.close(); + fWriter.close(); } catch (IOException e) { // just log, we are already done - log.error(Messages.CantCloseOOS + fOut.toString(), e); + log.error(Messages.CantCloseOOS + fWriter.toString(), e); } } } @@ -500,34 +467,8 @@ public class XmlStorage { } /** - * @return the custom XML header containing the XML export version info - */ - private static String buildXmlHeader() { - StringBuilder res = new StringBuilder(XML_HEADER_START); - res.append(StringConstants.SPACE); - res.append("version"); //$NON-NLS-1$ - res.append(StringConstants.EQUALS_SIGN); - res.append(QUOTE); - res.append("1"); //$NON-NLS-1$ - res.append(StringConstants.DOT); - res.append("0"); //$NON-NLS-1$ - res.append(QUOTE); - res.append(StringConstants.SPACE); - res.append("encoding"); //$NON-NLS-1$ - res.append(StringConstants.EQUALS_SIGN); - res.append(QUOTE); - res.append(RECOMMENDED_CHAR_ENCODING); - res.append(QUOTE); - res.append(SPACE); - res.append(XML_HEADER_END); - res.append(StringConstants.NEWLINE); - - return res.toString(); - } - - /** * read data from a file using a specified character encoding - * @param projectURL the project xml URL + * @param projectURL the project XML URL * @param encoding character encoding. Must be a supported encoding or an * UnsupportedEncodingException will be thrown. Null is allowed and means * system default encoding. diff --git a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/CreateNewProjectVersionHandler.java b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/CreateNewProjectVersionHandler.java index 4ba0004a5..1f4200ebb 100644 --- a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/CreateNewProjectVersionHandler.java +++ b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/CreateNewProjectVersionHandler.java @@ -175,9 +175,9 @@ public class CreateNewProjectVersionHandler extends AbstractHandler { NodePM.getInstance().setUseCache(true); GeneralStorage.getInstance().validateProjectExists( GeneralStorage.getInstance().getProject()); - String serializedProject = XmlStorage.save( - GeneralStorage.getInstance().getProject(), null, - false, subMonitor.newChild(WORK_GET_PROJECT_FROM_DB)); + String serializedProject = XmlStorage.save(GeneralStorage + .getInstance().getProject(), null, false, subMonitor + .newChild(WORK_GET_PROJECT_FROM_DB), false, null); if (monitor.isCanceled() || serializedProject == null) { throw new InterruptedException(); } diff --git a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/project/ExportProjectHandler.java b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/project/ExportProjectHandler.java index 398423c84..3c1f22c9b 100644 --- a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/project/ExportProjectHandler.java +++ b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/project/ExportProjectHandler.java @@ -86,8 +86,8 @@ public class ExportProjectHandler extends AbstractProjectHandler { Messages.ExportFileActionExporting, 1); - XmlStorage.save(gstorage.getProject(), m_fileName, - true, subMonitor.newChild(1)); + XmlStorage.save(gstorage.getProject(), m_fileName, + true, subMonitor.newChild(1), false, null); } } catch (final PMException e) { ErrorHandlingUtil.createMessageDialog(e, null, null); diff --git a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/project/SaveProjectAsHandler.java b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/project/SaveProjectAsHandler.java index 7ea77ae62..b168daef5 100644 --- a/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/project/SaveProjectAsHandler.java +++ b/org.eclipse.jubula.client.ui.rcp/src/org/eclipse/jubula/client/ui/rcp/handlers/project/SaveProjectAsHandler.java @@ -315,8 +315,8 @@ public class SaveProjectAsHandler extends AbstractProjectHandler { throws ProjectDeletedException, InterruptedException, PMException { GeneralStorage.getInstance().validateProjectExists( GeneralStorage.getInstance().getProject()); - String serializedProject = XmlStorage.save( - GeneralStorage.getInstance().getProject(), null, false, monitor); + String serializedProject = XmlStorage.save(GeneralStorage.getInstance() + .getProject(), null, false, monitor, false, null); if (monitor.isCanceled()) { throw new InterruptedException(); diff --git a/org.eclipse.jubula.feature/feature.xml b/org.eclipse.jubula.feature/feature.xml index f32c63326..13e4ee147 100644 --- a/org.eclipse.jubula.feature/feature.xml +++ b/org.eclipse.jubula.feature/feature.xml @@ -224,6 +224,13 @@ BREDEX GmbH - initial API and implementation and/or initial documentation unpack="false"/> <plugin + id="org.apache.commons.io" + download-size="0" + install-size="0" + version="2.0.1" + unpack="false"/> + + <plugin id="org.apache.oro" download-size="0" install-size="0" diff --git a/org.eclipse.jubula.project.configuration/target/definitions/dashboard-local.target b/org.eclipse.jubula.project.configuration/target/definitions/dashboard-local.target index 1f8dc2fa9..bb5f350a5 100644 --- a/org.eclipse.jubula.project.configuration/target/definitions/dashboard-local.target +++ b/org.eclipse.jubula.project.configuration/target/definitions/dashboard-local.target @@ -4,6 +4,7 @@ <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit"> <unit id="org.apache.commons.cli" version="1.2.0.v201105210650"/> <unit id="org.apache.commons.logging" version="1.1.1.v201101211721"/> +<unit id="org.apache.commons.io" version="2.0.1.v201105210651"/> <unit id="org.apache.commons.beanutils" version="1.8.0.v201205091237"/> <unit id="org.apache.commons.codec" version="1.4.0.v201209201156"/> <unit id="org.apache.commons.collections" version="3.2.0.v2013030210310"/> diff --git a/org.eclipse.jubula.project.configuration/target/definitions/dashboard.target b/org.eclipse.jubula.project.configuration/target/definitions/dashboard.target index 8dec7c74a..e34b70029 100644 --- a/org.eclipse.jubula.project.configuration/target/definitions/dashboard.target +++ b/org.eclipse.jubula.project.configuration/target/definitions/dashboard.target @@ -4,6 +4,7 @@ <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit"> <unit id="org.apache.commons.cli" version="1.2.0.v201105210650"/> <unit id="org.apache.commons.logging" version="1.1.1.v201101211721"/> +<unit id="org.apache.commons.io" version="2.0.1.v201105210651"/> <unit id="org.apache.commons.beanutils" version="1.8.0.v201205091237"/> <unit id="org.apache.commons.codec" version="1.4.0.v201209201156"/> <unit id="org.apache.commons.collections" version="3.2.0.v2013030210310"/> diff --git a/org.eclipse.jubula.project.configuration/target/definitions/juno+nightly.target b/org.eclipse.jubula.project.configuration/target/definitions/juno+nightly.target index b4569c9e4..b5334dd2e 100644 --- a/org.eclipse.jubula.project.configuration/target/definitions/juno+nightly.target +++ b/org.eclipse.jubula.project.configuration/target/definitions/juno+nightly.target @@ -4,6 +4,7 @@ <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit"> <unit id="org.apache.commons.cli" version="1.2.0.v201105210650"/> <unit id="org.apache.commons.logging" version="1.1.1.v201101211721"/> +<unit id="org.apache.commons.io" version="2.0.1.v201105210651"/> <unit id="org.apache.commons.beanutils" version="1.8.0.v201205091237"/> <unit id="org.apache.commons.codec" version="1.4.0.v201209201156"/> <unit id="org.apache.commons.collections" version="3.2.0.v2013030210310"/> diff --git a/org.eclipse.jubula.project.configuration/target/definitions/juno.target b/org.eclipse.jubula.project.configuration/target/definitions/juno.target index b2891c4f0..9df9bd37b 100644 --- a/org.eclipse.jubula.project.configuration/target/definitions/juno.target +++ b/org.eclipse.jubula.project.configuration/target/definitions/juno.target @@ -4,6 +4,7 @@ <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit"> <unit id="org.apache.commons.cli" version="1.2.0.v201105210650"/> <unit id="org.apache.commons.logging" version="1.1.1.v201101211721"/> +<unit id="org.apache.commons.io" version="2.0.1.v201105210651"/> <unit id="org.apache.commons.beanutils" version="1.8.0.v201205091237"/> <unit id="org.apache.commons.codec" version="1.4.0.v201209201156"/> <unit id="org.apache.commons.collections" version="3.2.0.v2013030210310"/> |
