Skip to content
Snippets Groups Projects
Commit 6ee28872 authored by Simon Barner's avatar Simon Barner
Browse files

- Add EcoreSerializerBase.createTemporaryFileURI() and use it to fix...

- Add EcoreSerializerBase.createTemporaryFileURI() and use it to fix generation of PikeOS vmit.xml configuration files
- Adjust other configuration generators (in particular: test cases for configuration generators) that relied on writing to pre-existing resources in Eclipse bundles (which, however, only worked in the developer installation and never in the pre-compiled RCP)
- Hence, remove output placeholder files that are no longer required.
refs 2844
parent ad1736ff
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.utils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
......@@ -40,7 +41,7 @@ import org.osgi.framework.Bundle;
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: C32245AE9177E3958D86E91CFA9926D1
* @ConQAT.Rating YELLOW Hash: 508ACCB8807CAB7A20A9FDF0ED658688
*/
public abstract class EcoreSerializerBase<R extends EObject> {
......@@ -125,10 +126,15 @@ public abstract class EcoreSerializerBase<R extends EObject> {
* @param pathName
* File to which configuration is to be written to.
*
* @return {@link URI} to which EMF model has been saved.
*
* @throws IOException
*/
public final void save(final R rootElement, final String pathName) throws IOException {
save(rootElement, createSaveURI(pathName));
public final URI save(final R rootElement, final String pathName) throws IOException {
final URI uri = createSaveURI(pathName);
save(rootElement, uri);
return uri;
}
/**
......@@ -215,6 +221,34 @@ public abstract class EcoreSerializerBase<R extends EObject> {
.append(bundlePathName).toString(), true);
}
/**
* Creates a temporary file and returns an {@link URI} pointing to it.
*
* @param fileName
* File name (=base name + extension) to be used to derive the name of the temporary
* file.
* @param extension
* File extension to be used to derive the name of the temporary file.
* @return {@link URI} pointing to temporary file.
*
* @throws IOException
* in case the creation of the temporary file failed.
*/
protected final URI createTemporaryFileURI(String fileName, String extension)
throws IOException {
if(!extension.startsWith(".")) {
extension = "." + extension;
}
if(fileName.endsWith(extension)) {
fileName = fileName.substring(0, fileName.length() - extension.length());
}
File tempFile = File.createTempFile(fileName, extension);
tempFile.deleteOnExit();
return URI.createFileURI(tempFile.getAbsolutePath());
}
/**
* From the given {@code pathName}, derives the URI that is actually being {@link #load(String)}
* ed. Sub-classes may override this method, e.g. to load files from a different context (such
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment