Commit b5478258 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Project: save files instead of plain copying for import

* Allows to ditch URI normalization.
* Enables loading examples in the product again by using the eclipe URI
  notion to reference files from plugins. The resolution w.r.t. packed
  jars is handled by eclipse internally.

Issue-Ref: 3993
Issue-Url: https://af3-developer.fortiss.org/issues/3993

Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent c9ca002f
ExternalFileUtils.java 4171a41060407cd4f19c99fcaf1ebfb9a390134a GREEN
FileUtils.java 100b2282c74cdcef3151833f25fc543a5b59b2b7 YELLOW
FileUtils.java 70e81c85ae7c2d8076e190ebad7eae648451b645 YELLOW
FunctionScopeUtils.java 054c92406affa0c0ad8ac7a067de9608d0bbca2b GREEN
LibraryModelElementFactory.java a5a30a0e6b274d220c397d9bf0f14756d49bd19f GREEN
ProjectModelElementFactory.java 2963d3a1fe651025bae3ae4dc0b6e0b77bbaadd5 GREEN
ProjectUtils.java 3813f56e33bfee95e5a07370006e7946553bd82f YELLOW
ProjectUtils.java 6383d593c18155e325d1ad830451fe514ec1c9ae YELLOW
TypeScopeUtils.java 54f2397f0d6720c90948ccc295f1a63b7319daac GREEN
VariableScopeUtils.java 031591687c2461a990d0534cf4ed4d6df39b1551 GREEN
......@@ -18,19 +18,15 @@ package org.fortiss.af3.project.utils;
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
import static org.eclipse.emf.common.util.URI.createFileURI;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.showError;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.emf.common.util.URI;
import org.fortiss.af3.project.AF3ProjectActivator;
......@@ -60,27 +56,6 @@ public class FileUtils {
public static final File PROJECT_DIR = new File(
WORKSPACE_ROOT.getLocation() + File.separator + FileUtils.AF3_PROJECT_DIRECTORY_NAME);
/**
* Normalizes URIs such as eclipse workspace URIs to machine-local URI. By that, resources
* within plugins can be accessed, in the developer version or the product (packed plugin jars).
* For standard file-URIs, this method is a no-op.
*/
public static URI normalizeURI(URI uri) {
try {
// Resolve URIs encoded as eclipse platform URIs. For normal file URIs, the lines below
// are no-ops.
URL url = new URL(uri.toString());
String uriString = FileLocator.resolve(url).toURI().toString();
uri = URI.createURI(uriString);
} catch(URISyntaxException | IOException e) {
String errMsg = "Could not find and open the file located at " + uri + ".";
error(AF3ProjectActivator.getDefault(), errMsg, e);
showError(errMsg);
return null;
}
return uri;
}
/**
* Return the content of a text file that is located in the plugin.
*
......
......@@ -15,7 +15,6 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.project.utils;
import static org.conqat.lib.commons.filesystem.FileSystemUtils.copyFile;
import static org.conqat.lib.commons.reflect.ReflectionUtils.pickInstanceOf;
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
import static org.eclipse.emf.common.util.URI.createPlatformPluginURI;
......@@ -24,7 +23,6 @@ import static org.fortiss.af3.project.AF3ProjectActivator.getDefault;
import static org.fortiss.af3.project.utils.ExternalFileUtils.doCopyExternalDocuments;
import static org.fortiss.af3.project.utils.FileUtils.AF3_PROJECT_DIRECTORY_NAME;
import static org.fortiss.af3.project.utils.FileUtils.PROJECT_DIR;
import static org.fortiss.af3.project.utils.FileUtils.normalizeURI;
import static org.fortiss.af3.project.utils.ProjectModelElementFactory.createExecutionConfiguration;
import static org.fortiss.af3.project.utils.ProjectModelElementFactory.createExecutionConfigurationStore;
import static org.fortiss.tooling.kernel.utils.EMFResourceUtils.createNewEclipseWorkspaceProject;
......@@ -282,9 +280,7 @@ public final class ProjectUtils {
doCopyExternalDocuments(sourceFileProject, sourceFileURI, targetFileURI);
// Perform the copy to the actual target (workspace) for the kernel to perform the import.
sourceFileURI = normalizeURI(sourceFileURI);
targetFileURI = normalizeURI(targetFileURI);
copyFile(new File(sourceFileURI.toString()), new File(targetFileURI.toString()));
saveProject(sourceFileProject, targetFileURI);
// Using the Java-API is not directly possible, as we would need to load the file before,
// which could destroy some element references. Using listeners we can avoid the problem by
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment