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

Project: Generalize URI Normalization

Thereby, loading AF3 projects from plugin jars should be possible again.

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

Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent 7beb2a58
ExportProjectUtils.java 95b02d271335e46ce89f78c912f85236fc852988 GREEN ExportProjectUtils.java 95b02d271335e46ce89f78c912f85236fc852988 GREEN
FileNameValidatorUtil.java c566595d083e756c20c919458d81e8a91ab0e10e YELLOW FileNameValidatorUtil.java c566595d083e756c20c919458d81e8a91ab0e10e YELLOW
FolderOrProjectDialogUtils.java 14823ea1da085d019e21e50703f6f4e3fff8aa83 GREEN FolderOrProjectDialogUtils.java 14823ea1da085d019e21e50703f6f4e3fff8aa83 GREEN
ImportProjectUtils.java 575612da284662251a77cffb0ff395e962749ef3 YELLOW ImportProjectUtils.java 465ab042df40cac46d5b17a1d469e865f89c6623 YELLOW
NewProjectUiUtils.java cd17cec67769d1c62c9923869c43293036d103e4 YELLOW NewProjectUiUtils.java cd17cec67769d1c62c9923869c43293036d103e4 YELLOW
ParsingUtils.java 7bbc27436511ee9d88f8a31f0b19462406d01517 GREEN ParsingUtils.java 7bbc27436511ee9d88f8a31f0b19462406d01517 GREEN
...@@ -31,10 +31,7 @@ import static org.fortiss.tooling.kernel.utils.LoggingUtils.showInfo; ...@@ -31,10 +31,7 @@ import static org.fortiss.tooling.kernel.utils.LoggingUtils.showInfo;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI; import org.eclipse.emf.common.util.URI;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
...@@ -137,22 +134,12 @@ public class ImportProjectUtils { ...@@ -137,22 +134,12 @@ public class ImportProjectUtils {
} }
/** /**
* Imports a selected file into the AF3 workspace (by file copying). * Imports a selected file into the AF3 workspace.
* *
* @param sourceFileURI * @param sourceFileURI
* the URI of the file that should be imported * the URI of the file that should be imported
*/ */
public static void importUISelectedFile(URI sourceFileURI) { public static void importUISelectedFile(URI sourceFileURI) {
try {
// Resolve URIs encoded as eclipse platform URIs. For normal file URIs, the lines below
// are no-ops.
URL url = new URL(sourceFileURI.toString());
String uriString = FileLocator.resolve(url).toURI().toString();
sourceFileURI = createURI(uriString);
} catch(URISyntaxException | IOException e1) {
showError("Could not find and open the file located at " + sourceFileURI + ".");
return;
}
File sourceFile = new File(sourceFileURI.toString()); File sourceFile = new File(sourceFileURI.toString());
// Check if really an af3_2x project is given. // Check if really an af3_2x project is given.
......
ExternalFileUtils.java 4171a41060407cd4f19c99fcaf1ebfb9a390134a GREEN ExternalFileUtils.java 4171a41060407cd4f19c99fcaf1ebfb9a390134a GREEN
FileUtils.java 70e81c85ae7c2d8076e190ebad7eae648451b645 YELLOW FileUtils.java 100b2282c74cdcef3151833f25fc543a5b59b2b7 YELLOW
FunctionScopeUtils.java 054c92406affa0c0ad8ac7a067de9608d0bbca2b GREEN FunctionScopeUtils.java 054c92406affa0c0ad8ac7a067de9608d0bbca2b GREEN
LibraryModelElementFactory.java a5a30a0e6b274d220c397d9bf0f14756d49bd19f GREEN LibraryModelElementFactory.java a5a30a0e6b274d220c397d9bf0f14756d49bd19f GREEN
NewProjectUtils.java f89b4631468f8824499e23eb0f58f354e90930db YELLOW
ProjectModelElementFactory.java 2963d3a1fe651025bae3ae4dc0b6e0b77bbaadd5 GREEN ProjectModelElementFactory.java 2963d3a1fe651025bae3ae4dc0b6e0b77bbaadd5 GREEN
ProjectUtils.java 266e960426c0cee5c2c50c4d5271e4c0d314ad69 YELLOW ProjectUtils.java 3813f56e33bfee95e5a07370006e7946553bd82f YELLOW
TypeScopeUtils.java 54f2397f0d6720c90948ccc295f1a63b7319daac GREEN TypeScopeUtils.java 54f2397f0d6720c90948ccc295f1a63b7319daac GREEN
VariableScopeUtils.java 031591687c2461a990d0534cf4ed4d6df39b1551 GREEN VariableScopeUtils.java 031591687c2461a990d0534cf4ed4d6df39b1551 GREEN
...@@ -18,15 +18,19 @@ package org.fortiss.af3.project.utils; ...@@ -18,15 +18,19 @@ package org.fortiss.af3.project.utils;
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace; import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
import static org.eclipse.emf.common.util.URI.createFileURI; 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.error;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.showError;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.emf.common.util.URI; import org.eclipse.emf.common.util.URI;
import org.fortiss.af3.project.AF3ProjectActivator; import org.fortiss.af3.project.AF3ProjectActivator;
...@@ -56,6 +60,27 @@ public class FileUtils { ...@@ -56,6 +60,27 @@ public class FileUtils {
public static final File PROJECT_DIR = new File( public static final File PROJECT_DIR = new File(
WORKSPACE_ROOT.getLocation() + File.separator + FileUtils.AF3_PROJECT_DIRECTORY_NAME); 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. * Return the content of a text file that is located in the plugin.
* *
......
...@@ -24,6 +24,7 @@ import static org.fortiss.af3.project.AF3ProjectActivator.getDefault; ...@@ -24,6 +24,7 @@ import static org.fortiss.af3.project.AF3ProjectActivator.getDefault;
import static org.fortiss.af3.project.utils.ExternalFileUtils.doCopyExternalDocuments; 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.AF3_PROJECT_DIRECTORY_NAME;
import static org.fortiss.af3.project.utils.FileUtils.PROJECT_DIR; 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.createExecutionConfiguration;
import static org.fortiss.af3.project.utils.ProjectModelElementFactory.createExecutionConfigurationStore; import static org.fortiss.af3.project.utils.ProjectModelElementFactory.createExecutionConfigurationStore;
import static org.fortiss.tooling.kernel.utils.EMFResourceUtils.createNewEclipseWorkspaceProject; import static org.fortiss.tooling.kernel.utils.EMFResourceUtils.createNewEclipseWorkspaceProject;
...@@ -281,7 +282,9 @@ public final class ProjectUtils { ...@@ -281,7 +282,9 @@ public final class ProjectUtils {
doCopyExternalDocuments(sourceFileProject, sourceFileURI, targetFileURI); doCopyExternalDocuments(sourceFileProject, sourceFileURI, targetFileURI);
// Perform the copy to the actual target (workspace) for the kernel to perform the import. // Perform the copy to the actual target (workspace) for the kernel to perform the import.
copyFile(new File(sourceFileURI.toFileString()), new File(targetFileURI.toFileString())); sourceFileURI = normalizeURI(sourceFileURI);
targetFileURI = normalizeURI(targetFileURI);
copyFile(new File(sourceFileURI.toString()), new File(targetFileURI.toString()));
// Using the Java-API is not directly possible, as we would need to load the file before, // 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 // 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