aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarwa rostren2014-01-29 06:56:24 (EST)
committerEd Willink2014-03-06 10:07:22 (EST)
commitd98fe15fbd77d32ff8cd3d034bdbedb66b781301 (patch)
tree85dcea2443115f58c3d7af0bf3ad6c250a47d135
parent7c269a5b36adff8ed505d23a514a103aaad44482 (diff)
downloadorg.eclipse.ocl-d98fe15fbd77d32ff8cd3d034bdbedb66b781301.zip
org.eclipse.ocl-d98fe15fbd77d32ff8cd3d034bdbedb66b781301.tar.gz
org.eclipse.ocl-d98fe15fbd77d32ff8cd3d034bdbedb66b781301.tar.bz2
[425799] Use the Resource instead of IResource to initiate the exported file
content. Change-Id: I750138bbdc7109973d9299039ddb7a4431b57f93 Signed-off-by: marwa rostren <mrostren@obeo.fr>
-rw-r--r--emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/AbstractExport.java54
-rw-r--r--emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/HTMLExport.java5
-rw-r--r--emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/TextExport.java5
3 files changed, 42 insertions, 22 deletions
diff --git a/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/AbstractExport.java b/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/AbstractExport.java
index f9373a5..13f5edf 100644
--- a/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/AbstractExport.java
+++ b/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/AbstractExport.java
@@ -15,6 +15,8 @@
package org.eclipse.ocl.examples.emf.validation.validity.ui.export.util;
import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -48,6 +50,8 @@ import org.eclipse.ocl.examples.emf.validation.validity.ui.plugin.ValidityUIPlug
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.PlatformUI;
+import com.google.common.io.Files;
+
/**
* Exports ocl validation results.
*/
@@ -63,22 +67,40 @@ public abstract class AbstractExport implements IValidatorExport {
protected List<LeafConstrainingNode> validationSuccess = new ArrayList<LeafConstrainingNode>();
public void export(@NonNull Resource validatedResource, @NonNull RootNode rootNode, @NonNull IPath savePath) {
- final IFile exportedFile = ResourcesPlugin.getWorkspace().getRoot().getFile(savePath);
-
populateMaps(rootNode);
- final String initialContents = createContents(validatedResource, rootNode, exportedFile);
- final InputStream contentStream = new ByteArrayInputStream(initialContents.getBytes(Charset.forName("UTF-8")));
-
- IRunnableWithProgress op = new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) {
- try {
- exportedFile.create(contentStream, true, monitor);
- } catch (final CoreException e) {
- handleError(e.getCause(), true);
+ final File exportedFile = new File(savePath.toString());
+ final String initialContents = createContents(validatedResource,
+ rootNode, exportedFile.getName());
+ final byte[] byteArrayInputStream = initialContents.getBytes(Charset
+ .forName("UTF-8"));
+ final IRunnableWithProgress op;
+
+ if (exportedFile.isAbsolute()) {
+ op = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) {
+ try {
+ Files.write(byteArrayInputStream, exportedFile);
+ } catch (final IOException e) {
+ handleError(e.getCause(), true);
+ }
}
- }
- };
+ };
+ } else {
+ final InputStream contentStream = new ByteArrayInputStream(
+ byteArrayInputStream);
+ final IFile exportedIFile = ResourcesPlugin.getWorkspace()
+ .getRoot().getFile(savePath);
+ op = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) {
+ try {
+ exportedIFile.create(contentStream, true, monitor);
+ } catch (final CoreException e) {
+ handleError(e.getCause(), true);
+ }
+ }
+ };
+ }
try {
op.run(new NullProgressMonitor());
@@ -120,13 +142,13 @@ public abstract class AbstractExport implements IValidatorExport {
* The validated model
* @param rootNode
* The validation result model
- * @param exportedFile
- * The target file
+ * @param exportedFileName
+ * The target file name
*
* @return exported File contents to be given to new exported file resource
* instances
*/
- protected abstract String createContents(@NonNull Resource validatedResource, RootNode rootNode, IFile exportedFile);
+ protected abstract String createContents(@NonNull Resource validatedResource, RootNode rootNode, String exportedFileName);
private void populateMaps(RootNode rootNode) {
for (ValidatableNode validatableNode : rootNode.getValidatableNodes()) {
diff --git a/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/HTMLExport.java b/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/HTMLExport.java
index a46b472..01a41c6 100644
--- a/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/HTMLExport.java
+++ b/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/HTMLExport.java
@@ -18,7 +18,6 @@ import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang.StringEscapeUtils;
-import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.examples.emf.validation.validity.LeafConstrainingNode;
@@ -39,7 +38,7 @@ public class HTMLExport extends AbstractExport {
* instances
*/
@Override
- public String createContents(@NonNull Resource validatedResource, RootNode rootNode, IFile exportedFile) {
+ public String createContents(@NonNull Resource validatedResource, RootNode rootNode, String exportedFileName) {
StringBuilder html = new StringBuilder();
html.append("<html>\n");
html.append("\t<head></head>\n");
@@ -50,7 +49,7 @@ public class HTMLExport extends AbstractExport {
html.append("\t\t\t<tr>\n");
html.append("\t\t\t\t<td><b>Output file name: </b></td>\n");
- html.append("\t\t\t\t<td>" + exportedFile.getName() + "</td>\n");
+ html.append("\t\t\t\t<td>" + exportedFileName + "</td>\n");
html.append("\t\t\t</tr>\n");
html.append("\t\t\t<tr>\n");
diff --git a/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/TextExport.java b/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/TextExport.java
index b48c22f..1494e40 100644
--- a/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/TextExport.java
+++ b/emfv/org.eclipse.ocl.examples.emf.validation.validity.ui/src/org/eclipse/ocl/examples/emf/validation/validity/ui/export/util/TextExport.java
@@ -17,7 +17,6 @@ package org.eclipse.ocl.examples.emf.validation.validity.ui.export.util;
import java.util.HashSet;
import java.util.Set;
-import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.examples.emf.validation.validity.LeafConstrainingNode;
@@ -38,10 +37,10 @@ public class TextExport extends AbstractExport {
* instances
*/
@Override
- public String createContents(@NonNull Resource validatedResource, RootNode rootNode, IFile exportedFile) {
+ public String createContents(@NonNull Resource validatedResource, RootNode rootNode, String exportedFileName) {
StringBuilder text = new StringBuilder();
text.append("==== GENERAL INFORMATION ====\n");
- text.append("Output file name: " + exportedFile.getName() + "\n");
+ text.append("Output file name: " + exportedFileName + "\n");
text.append("Author: " + System.getProperty("user.name") + "\n");
text.append("\n");
text.append("\n");