-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for platform: URLs (fixes #12)
This commit creates a new EclipseRDFModel subclass which preprocesses platform:/ URLs into standard file:/ URLs that Jena can work with as usual. It also updates the Eclipse UI to make use of that subclass by default. --------- Co-authored-by: Antonio Garcia-Dominguez <[email protected]>
- Loading branch information
1 parent
698f834
commit e9ea6c7
Showing
14 changed files
with
445 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...es/org.eclipse.epsilon.emc.rdf.dt/src/org/eclipse/epsilon/emc/rdf/dt/EclipseRDFModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 University of York | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Antonio Garcia-Dominguez - initial API and implementation | ||
********************************************************************************/ | ||
package org.eclipse.epsilon.emc.rdf.dt; | ||
|
||
import java.net.URL; | ||
import java.util.List; | ||
|
||
import org.eclipse.core.runtime.FileLocator; | ||
import org.eclipse.epsilon.emc.rdf.RDFModel; | ||
import org.eclipse.epsilon.eol.exceptions.models.EolModelLoadingException; | ||
|
||
public class EclipseRDFModel extends RDFModel { | ||
|
||
@Override | ||
protected void loadModel() throws EolModelLoadingException { | ||
// Change any platform:/ URLs to file:/ URLs in these lists... | ||
processEclipsePlatformUrlsToFileUrls(schemaURIs); | ||
processEclipsePlatformUrlsToFileUrls(dataURIs); | ||
|
||
// Call the RDFModel load as normal, no platform URLs are passed to Jena | ||
super.loadModel(); | ||
} | ||
|
||
// Pushes a list of URLs through a process to turn any Platform:/ into File:/ | ||
private void processEclipsePlatformUrlsToFileUrls(List<String> urlList) throws EolModelLoadingException { | ||
for (int i = 0; i < urlList.size(); i++) { | ||
urlList.set(i, processPlatformURLtoFileUrl(urlList.get(i))); | ||
} | ||
} | ||
|
||
// A File:/ URL or relative path starting '/' or '.' is unchanged by this process, Platform:/ URLs become File:/ URLs | ||
// Attempts to resolve a String to a URI and then URL, then gets the File:/ URL and returns it | ||
private String processPlatformURLtoFileUrl(String urlString) throws EolModelLoadingException { | ||
if (!urlString.startsWith("platform:")) { | ||
return urlString; | ||
} | ||
|
||
try { | ||
URL url = new URL(urlString); | ||
URL fileSystemPathUrl = FileLocator.toFileURL(url); | ||
return fileSystemPathUrl.toString(); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
throw new EolModelLoadingException(ex, this); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="src" path="src"> | ||
<attributes> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.eclipse.epsilon.emc.rdf.dt.tests</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
9 changes: 9 additions & 0 deletions
9
tests/org.eclipse.epsilon.emc.rdf.dt.tests/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 | ||
org.eclipse.jdt.core.compiler.compliance=17 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=17 |
14 changes: 14 additions & 0 deletions
14
tests/org.eclipse.epsilon.emc.rdf.dt.tests/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: Tests for EMC RDF developer tools | ||
Bundle-SymbolicName: org.eclipse.epsilon.emc.rdf.dt.tests | ||
Bundle-Version: 1.0.0.qualifier | ||
Require-Bundle: org.eclipse.epsilon.emc.rdf, | ||
org.eclipse.epsilon.emc.rdf.dt, | ||
org.eclipse.equinox.registry;bundle-version="3.0.0", | ||
org.junit;bundle-version="[4.0.0,5.0.0)", | ||
org.eclipse.epsilon.eol.engine;bundle-version="2.0.0", | ||
org.eclipse.core.resources;bundle-version="3.0.0" | ||
Bundle-Vendor: University of York | ||
Automatic-Module-Name: org.eclipse.epsilon.emc.rdf.dt.tests | ||
Bundle-RequiredExecutionEnvironment: JavaSE-17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
. |
139 changes: 139 additions & 0 deletions
139
...ilon.emc.rdf.dt.tests/src/org/eclipse/epsilon/emc/rdf/dt/tests/EclipseProjectEnvTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 University of York | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Antonio Garcia-Dominguez - initial API and implementation | ||
********************************************************************************/ | ||
package org.eclipse.epsilon.emc.rdf.dt.tests; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.eclipse.core.resources.IContainer; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IFolder; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.resources.IWorkspace; | ||
import org.eclipse.core.resources.IWorkspaceRoot; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.eclipse.core.runtime.Path; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
public class EclipseProjectEnvTest { | ||
|
||
/** | ||
* <p> | ||
* Base class for tests requiring an Eclipse IDE project and workbench environment. | ||
* </p> | ||
* | ||
* <p> | ||
* Note: all tests based on this class must run as JUnit Plug-In tests, not as | ||
* regular tests, and the ui.workbench product (or Headless) needs to be run. We need a | ||
* working, open workbench for these tests. | ||
* </p> | ||
*/ | ||
|
||
private final int FILESYSTEM_SYNC_TIMEOUT_SECONDS = 10; | ||
|
||
private final String projectUrl; | ||
|
||
private IProject testProject; | ||
|
||
/** | ||
* Creates a new project with this URL | ||
* | ||
* @param projectUrl | ||
* Project URL to use for a project resource in Eclipse IDE Workbench that the test will use | ||
*/ | ||
public EclipseProjectEnvTest(String projectUrl) { | ||
this.projectUrl = projectUrl; | ||
} | ||
|
||
@Before | ||
public void createTestProject() throws Exception { | ||
final IWorkspace workspace = ResourcesPlugin.getWorkspace(); | ||
final IWorkspaceRoot root = workspace.getRoot(); | ||
|
||
testProject = root.getProject(projectUrl); | ||
if (testProject.exists()) { | ||
deleteTestProject(); | ||
} | ||
testProject.create(null); | ||
testProject.open(null); | ||
} | ||
|
||
@After | ||
public void deleteTestProject() throws Exception { | ||
testProject.delete(true, true, null); | ||
|
||
int count = 0; | ||
while (!testProject.isSynchronized(1)) { | ||
count = checkTimeOut(count, FILESYSTEM_SYNC_TIMEOUT_SECONDS,"Waiting for delete sync... "); | ||
} | ||
} | ||
|
||
public void copyIntoProject(String from, String to) throws Exception { | ||
IFile destFile=null; | ||
try (InputStream source = new FileInputStream(from)) { | ||
destFile = testProject.getFile(new Path(to)); | ||
createParentFolders(destFile); | ||
destFile.create(source, false, null); | ||
} | ||
if (null != destFile) { | ||
int count = 0; | ||
while (!destFile.isSynchronized(1)) { | ||
count = checkTimeOut(count, FILESYSTEM_SYNC_TIMEOUT_SECONDS,"Waiting for file sync"); | ||
} | ||
} | ||
} | ||
|
||
private static void createParentFolders(IResource res) throws Exception { | ||
final IContainer parent = res.getParent(); | ||
if (parent instanceof IFolder) { | ||
createParentFolders(parent); | ||
} | ||
if (res instanceof IFolder && !res.exists()) { | ||
((IFolder) res).create(false, true, null); | ||
} | ||
} | ||
|
||
// Delays 1 second, set limit to X seconds you want to wait | ||
private int checkTimeOut(int current, int limit, String errorLabel) throws Exception { | ||
System.out.println(" - " + errorLabel + " Time out: " + current + "/" + limit ); | ||
if (current >= limit) | ||
{ | ||
//System.err.println("Check time out error: " + errorLabel); | ||
throw new Exception("Check time out error: " + errorLabel); | ||
} | ||
delaySeconds(1); | ||
return ++current; | ||
} | ||
|
||
private void delaySeconds(int seconds) { | ||
try { | ||
TimeUnit.SECONDS.sleep(seconds); | ||
} catch (InterruptedException ie) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
|
||
public String getProjectUrl() { | ||
return projectUrl; | ||
} | ||
|
||
public String getTestProjectURIString() { | ||
return testProject.getLocationURI().toString(); | ||
} | ||
|
||
public IProject getTestProject() { | ||
return testProject; | ||
} | ||
} |
Oops, something went wrong.