summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-07-11 14:37:34 (EDT)
committer pelder2007-07-11 14:37:34 (EDT)
commit41f81d40fc42738ee3b7a2847fc34bf6ab05595b (patch)
tree7287b15c756395fa83ae68513107f987d0aeeb50
parent613c2fd6cc0190811cbb16703b1e88af2a78ec42 (diff)
downloadorg.eclipse.jet-41f81d40fc42738ee3b7a2847fc34bf6ab05595b.zip
org.eclipse.jet-41f81d40fc42738ee3b7a2847fc34bf6ab05595b.tar.gz
org.eclipse.jet-41f81d40fc42738ee3b7a2847fc34bf6ab05595b.tar.bz2
[195924] Malformed URLs in JET
-rw-r--r--plugins/org.eclipse.jet-feature/feature.xml2
-rw-r--r--plugins/org.eclipse.jet.core/.classpath2
-rw-r--r--plugins/org.eclipse.jet.core/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateInput.java5
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateResolverHelper.java7
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/url/URLConstruction.aj25
-rw-r--r--plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/url/URLUtility.java114
-rw-r--r--plugins/org.eclipse.jet.sdk-feature/feature.xml2
-rw-r--r--plugins/org.eclipse.jet/.classpath2
-rw-r--r--plugins/org.eclipse.jet/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/devaspects/URLConstruction.aj24
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java3
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleProvider.java15
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/TransformLoadContext.java3
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java1
-rw-r--r--tests/org.eclipse.jet.tests-feature/feature.xml2
-rw-r--r--tests/org.eclipse.jet.tests.core/data/templates folder.jarbin0 -> 1567 bytes
-rw-r--r--tests/org.eclipse.jet.tests.core/data/templates folder.zipbin0 -> 1567 bytes
-rw-r--r--tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java1
-rw-r--r--tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/AllTests.java17
-rw-r--r--tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/TestURLUtility.java125
22 files changed, 337 insertions, 20 deletions
diff --git a/plugins/org.eclipse.jet-feature/feature.xml b/plugins/org.eclipse.jet-feature/feature.xml
index d766135..05a11b6 100644
--- a/plugins/org.eclipse.jet-feature/feature.xml
+++ b/plugins/org.eclipse.jet-feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jet"
label="%featureName"
- version="0.8.0.qualifier"
+ version="0.8.1.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/modeling/m2t">
diff --git a/plugins/org.eclipse.jet.core/.classpath b/plugins/org.eclipse.jet.core/.classpath
index ce73933..5289a9d 100644
--- a/plugins/org.eclipse.jet.core/.classpath
+++ b/plugins/org.eclipse.jet.core/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
+ <classpathentry excluding="org/eclipse/jet/internal/core/url/URLConstruction.aj" kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
diff --git a/plugins/org.eclipse.jet.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.jet.core/META-INF/MANIFEST.MF
index 5d30b65..803f27f 100644
--- a/plugins/org.eclipse.jet.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jet.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jet.core
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.0.1.qualifier
Bundle-Localization: plugin
Eclipse-LazyStart: true
Export-Package: org.eclipse.jet,
@@ -13,6 +13,7 @@ Export-Package: org.eclipse.jet,
org.eclipse.jet.internal.core.compiler;x-friends:="org.eclipse.jet,org.eclipse.jet.tests,org.eclipse.jet.tests.core",
org.eclipse.jet.internal.core.parser;x-friends:="org.eclipse.jet.tests.tools,org.eclipse.jet,org.eclipse.jet.tests.core",
org.eclipse.jet.internal.core.parser.jasper;x-friends:="org.eclipse.jet,org.eclipse.jet.tests,org.eclipse.jet.tests.core",
+ org.eclipse.jet.internal.core.url;x-friends:="org.eclipse.jet,org.eclipse.jet.editor,org.eclipse.jet.tests,org.eclipse.jet.tests.core,org.eclipse.jet.ui",
org.eclipse.jet.internal.taglib,
org.eclipse.jet.taglib
Require-Bundle: org.eclipse.text;bundle-version="[3.2.0,4.0.0)"
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateInput.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateInput.java
index 8797b56..e4b68a8 100644
--- a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateInput.java
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateInput.java
@@ -21,6 +21,7 @@ import java.net.URL;
import org.eclipse.jet.core.parser.ITemplateInput;
import org.eclipse.jet.core.parser.TemplateInputException;
+import org.eclipse.jet.internal.core.url.URLUtility;
/**
* Standard inplementation of ITemplateInput
@@ -57,9 +58,7 @@ public class DefaultTemplateInput implements ITemplateInput {
try {
URI templateURI = new URI(null, templatePath, null);
URI resolvedURI = baseLocation.resolve(templateURI);
- // Don't use URI.toURL(), platform:/ URI's don't properly transform into URLs
- // Instead, we use:
- URL url = new URL(resolvedURI.getScheme(), resolvedURI.getHost(), resolvedURI.getPort(), resolvedURI.getPath());
+ URL url = URLUtility.toURL(resolvedURI);
InputStream urlStream = url.openStream();
return new BufferedReader(new InputStreamReader(urlStream,
getEncoding()));
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateResolverHelper.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateResolverHelper.java
index 08d5416..7c19000 100644
--- a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateResolverHelper.java
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/parser/DefaultTemplateResolverHelper.java
@@ -12,7 +12,7 @@
*
* </copyright>
*
- * $Id: DefaultTemplateResolverHelper.java,v 1.2 2007/05/01 19:49:13 pelder Exp $
+ * $Id: DefaultTemplateResolverHelper.java,v 1.3 2007/07/11 18:37:28 pelder Exp $
*/
package org.eclipse.jet.internal.core.parser;
@@ -25,6 +25,7 @@ import java.net.URL;
import org.eclipse.jet.core.parser.ITemplateInput;
import org.eclipse.jet.core.parser.ITemplateResolverHelper;
+import org.eclipse.jet.internal.core.url.URLUtility;
/**
* @author pelder
@@ -63,9 +64,7 @@ public class DefaultTemplateResolverHelper implements ITemplateResolverHelper
private InputStream openStream(URI baseLocation, String templatePath) {
try {
URI resolvedURI = baseLocation.resolve(new URI(null, templatePath, null));
- // Don't use URI.toURL(), platform:/ URI's don't properly transform into URLs
- // Instead, we use
- URL templateURL = new URL(resolvedURI.getScheme(), resolvedURI.getHost(), resolvedURI.getPort(), resolvedURI.getPath());
+ URL templateURL = URLUtility.toURL(resolvedURI);
final InputStream input = templateURL.openStream();
return input;
} catch (MalformedURLException e) {
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/url/URLConstruction.aj b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/url/URLConstruction.aj
new file mode 100644
index 0000000..2d765ff
--- /dev/null
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/url/URLConstruction.aj
@@ -0,0 +1,25 @@
+package org.eclipse.jet.internal.core.url;
+
+import java.net.URI;
+import java.net.URL;
+import java.net.URLStreamHandler;
+
+public aspect URLConstruction {
+ pointcut newNonEncodingURL() : call(URL.new(String,String,int,String))
+ || call(URL.new(String,String,int,String,URLStreamHandler))
+ || call(URL.new(String,String,String));
+
+ pointcut newEncodingURL() : call(URL.new(String))
+ || call(URL.new(URL,String))
+ || call(URL.new(URL,String,URLStreamHandler));
+
+ pointcut uriToURL() : call(URL URI.toURL());
+
+ pointcut inURLUtilities() : within(org.eclipse.jet.internal.core.url.URLUtility);
+
+ declare error : newNonEncodingURL() && !inURLUtilities() : "Encoding of URL is suspect. Use or enhance URLUtility instead.";
+
+ declare error: uriToURL() && !inURLUtilities() : "Conversion to URL is suspect. Use URLUtility.toURL(URI) instead.";
+
+ declare error: newEncodingURL() && !inURLUtilities() : "Who is using this?";
+}
diff --git a/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/url/URLUtility.java b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/url/URLUtility.java
new file mode 100644
index 0000000..7d06f41
--- /dev/null
+++ b/plugins/org.eclipse.jet.core/src/org/eclipse/jet/internal/core/url/URLUtility.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ */
+package org.eclipse.jet.internal.core.url;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+
+/**
+ * A utility class for handling URLs, and in particular, for handling ensuring that URL formats are correct
+ * and that URLs are properly encoded.
+ * <p>
+ * <string>Important Note</strong>: Code in org.eclipse.jet should avoid using the following methods, as they
+ * are known to have invalid or unexpected results.
+ * <table>
+ * <tr><td>Class/Method</td><td>Problem</td></tr>
+ * <tr><td>{@link URL#URL(String, String, String)}</td><td>Arguments are not URL encoded</td></tr>
+ * <tr><td>{@link URL#URL(String, String, int, String)}</td><td>Arguments are not URL encoded</td></tr>
+ * <tr><td>{@link URL#URL(String, String, int, String, java.net.URLStreamHandler)}</td><td>Arguments are not URL encoded</td></tr>
+ * <tr><td>{@link java.net.URI#toURL()}</td><td>Properly encoded URI gets encoded again, platform:/ URI don't propertly converted</td></tr>
+ * </table>
+ * </p>
+ *
+ */
+public class URLUtility {
+
+ private URLUtility() {
+
+ }
+
+ /**
+ * Return an URL for an entry within the given JAR file
+ * @param jarFile an URL for the JAR file
+ * @param unEncodedPath the unencoded path for the entry within the JAR
+ * @return the JAR entry URL
+ * @throws NullPointerException if either argument is <code>null</code>
+ */
+ public static URL jarEntryURL(URL jarFile, String unEncodedPath) {
+ if(jarFile == null || unEncodedPath == null) {
+ throw new NullPointerException();
+ }
+ try {
+ return new URL(jarRootEntryURL(jarFile), unEncodedPath);
+ } catch (MalformedURLException e) {
+ // This should not happen. This exception only happens if no protocol specified
+ // or if the protocal is unknown. But neither of this is the case.
+ // Wrap in a runtime exception.
+ throw new RuntimeException("Unexpected exception", e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Return an URL for the root entry. The calculated URL may then be used as a base URL
+ * for resolving entries within the JAR.
+ * @param jarFile the URL for a JAR file
+ * @return the URL for the jar root entry.
+ * @throws NullPointerException if either argument is <code>null</code>.
+ */
+ public static URL jarRootEntryURL(URL jarFile) {
+ if(jarFile == null) {
+ throw new NullPointerException();
+ }
+ try {
+ // N.B. This is a legitimate use of URL(String,String,String)
+ // as URL.toExternalForm() returns a corrected encoded URL
+ // provided the original URL was properly constructed.
+ return new URL("jar", null, jarFile.toExternalForm() + "!/");
+ } catch (MalformedURLException e) {
+ // This should not happen, wrap in a runtime exception
+ throw new RuntimeException("Unexpected exception", e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Return the corresponding URL for the given URI. Use as an alternative for {@link URI#toURL()}.
+ * @param uri the URI to convert
+ * @return the converted URI
+ * @throws MalformedURLException if the URI includes an unknown protocol
+ * @throws NullPointerException if uri is <code>null</code>
+ */
+ public static URL toURL(URI uri) throws MalformedURLException {
+ if(uri == null) {
+ throw new NullPointerException();
+ }
+ // Don't use URI.toURL(), platform:/ URI's don't properly transform into URLs
+ // Instead, we use:
+ return new URL(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath());
+ }
+
+ public static URL relativeURL(URL baseLocation, String location) throws MalformedURLException {
+ if(baseLocation == null || location == null) {
+ throw new NullPointerException();
+ }
+
+ if("platform".equals(baseLocation.getProtocol())) {
+ final String basePath = baseLocation.getPath();
+ if(location.startsWith("/") && !basePath.endsWith("/")) {
+ String firstSegment = basePath.substring(0, basePath.indexOf('/'));
+ URL adjustedBase = new URL(baseLocation.getProtocol(), null, firstSegment);
+ return new URL(adjustedBase, location);
+ }
+ }
+
+ return new URL(baseLocation, location);
+ }
+}
diff --git a/plugins/org.eclipse.jet.sdk-feature/feature.xml b/plugins/org.eclipse.jet.sdk-feature/feature.xml
index f5b578c..e626535 100644
--- a/plugins/org.eclipse.jet.sdk-feature/feature.xml
+++ b/plugins/org.eclipse.jet.sdk-feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jet.sdk"
label="%featureName"
- version="0.8.0.qualifier"
+ version="0.8.1.qualifier"
provider-name="%providerName">
<description>
diff --git a/plugins/org.eclipse.jet/.classpath b/plugins/org.eclipse.jet/.classpath
index bd5f894..f2aabfa 100644
--- a/plugins/org.eclipse.jet/.classpath
+++ b/plugins/org.eclipse.jet/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
+ <classpathentry excluding="org/eclipse/jet/devaspects/URLConstruction.aj" kind="src" path="src"/>
<classpathentry kind="src" output="antbin" path="antsrc"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
diff --git a/plugins/org.eclipse.jet/META-INF/MANIFEST.MF b/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
index 1e695e4..04132c7 100644
--- a/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jet;singleton:=true
-Bundle-Version: 0.8.0.qualifier
+Bundle-Version: 0.8.1.qualifier
Bundle-Activator: org.eclipse.jet.internal.InternalJET2Platform
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ant.core;bundle-version="[3.1.100,4.0.0)",
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/devaspects/URLConstruction.aj b/plugins/org.eclipse.jet/src/org/eclipse/jet/devaspects/URLConstruction.aj
new file mode 100644
index 0000000..383f09b
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/devaspects/URLConstruction.aj
@@ -0,0 +1,24 @@
+package org.eclipse.jet.devaspects;
+
+import java.net.URI;
+import java.net.URL;
+import java.net.URLStreamHandler;
+
+public aspect URLConstruction {
+ pointcut newNonEncodingURL() : call(URL.new(String,String,int,String))
+ || call(URL.new(String,String,int,String,URLStreamHandler))
+ || call(URL.new(String,String,String));
+
+ pointcut newEncodingURL() : call(URL.new(String))
+ || call(URL.new(URL,String))
+ || call(URL.new(URL,String,URLStreamHandler));
+
+ pointcut uriToURL() : call(URL URI.toURL());
+
+
+declare error : newNonEncodingURL() : "Encoding of URL is suspect. Use or enhance URLUtility instead."; //$NON-NLS-1$
+
+//declare error: uriToURL() : "Conversion to URL is suspect. Use URLUtility.toURL(URI) instead."; //$NON-NLS-1$
+
+//declare error : newEncodingURL() : "Call to encoding URL";
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java
index e5461aa..a7c9eb3 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/extensionpoints/PluginProjectMonitor.java
@@ -199,7 +199,7 @@ public class PluginProjectMonitor implements IResourceChangeListener
try
{
- final URL projectURL = new URL("file", "", project.getLocation() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ final URL projectURL = new URL("platform:/resource/" + project.getName() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
final BundleManifest manifest = JETBundleManager.loadManifest(projectURL);
Object pluginDocumentRoot = null;
if(hasPluginManifest(project)) {
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
index 9d0bc7f..36a8fd4 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/JETBundleManager.java
@@ -34,6 +34,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jet.JET2TemplateLoader;
import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.core.url.URLUtility;
import org.eclipse.jet.internal.extensionpoints.TransformData;
import org.eclipse.jet.internal.extensionpoints.TransformDataFactory;
import org.eclipse.jet.internal.l10n.JET2Messages;
@@ -134,7 +135,7 @@ public class JETBundleManager implements IJETBundleManager
IJETBundleDescriptor descriptor = null;
try
{
- URL jarURL = new URL("jar", "", bundleURL.toExternalForm() + "!/"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ URL jarURL = URLUtility.jarRootEntryURL(bundleURL);
JETBundleManifest manifest = JETBundleManager.loadManifest(jarURL);
TransformData transformData = TransformDataFactory.INSTANCE.createTransformData(manifest.getTransformId(), jarURL);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleProvider.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleProvider.java
index a15a7dd..6f9298e 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleProvider.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/ProjectJETBundleProvider.java
@@ -18,6 +18,7 @@ package org.eclipse.jet.internal.runtime;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -35,6 +36,7 @@ import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
@@ -205,7 +207,7 @@ public class ProjectJETBundleProvider implements IResourceChangeListener, IJETBu
try
{
// final URL projectURL = new URL("file:/" + project.getLocation() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
- final URL projectURL = new URL("file", null, project.getLocation() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
+ final URL projectURL = new URL("platform:/resource/" + project.getName() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
final JETBundleManifest manifest = JETBundleManager.loadManifest(projectURL);
@@ -278,7 +280,16 @@ public class ProjectJETBundleProvider implements IResourceChangeListener, IJETBu
{
if (ensureProjectIsBuilt(descriptor.getProjectName(), monitor))
{
- bundle = InternalJET2Platform.getDefault().getJETBundleInstaller().installBundle(descriptor.getBaseURL());
+ final URL baseURL = descriptor.getBaseURL();
+ try
+ {
+ final URL baseFileURL = FileLocator.toFileURL(baseURL);
+ bundle = InternalJET2Platform.getDefault().getJETBundleInstaller().installBundle(baseFileURL);
+ }
+ catch (IOException e)
+ {
+ new BundleException(MessageFormat.format("Could not convert URL ''{0}'' to ''file'' protocol", new Object[] {baseURL}), e); //$NON-NLS-1$
+ }
}
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/TransformLoadContext.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/TransformLoadContext.java
index 8be2216..3c69e56 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/TransformLoadContext.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/runtime/model/TransformLoadContext.java
@@ -21,6 +21,7 @@ package org.eclipse.jet.internal.runtime.model;
import java.net.MalformedURLException;
import java.net.URL;
+import org.eclipse.jet.internal.core.url.URLUtility;
import org.eclipse.jet.runtime.model.ILoadContext;
@@ -36,7 +37,7 @@ public class TransformLoadContext implements ILoadContext
public TransformLoadContext(URL bundleURL) throws MalformedURLException
{
if(bundleURL.getFile().endsWith(".jar")) { //$NON-NLS-1$
- this.contextURL = new URL("jar", null, bundleURL.toExternalForm() + "!/"); //$NON-NLS-1$//$NON-NLS-2$
+ this.contextURL = URLUtility.jarRootEntryURL(bundleURL);
} else {
this.contextURL = bundleURL;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
index 462380e..f95a896 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/taglib/UserRegionHelper.java
@@ -19,7 +19,6 @@ import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.internal.taglib.DocumentHelper;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
diff --git a/tests/org.eclipse.jet.tests-feature/feature.xml b/tests/org.eclipse.jet.tests-feature/feature.xml
index d8731aa..4e8b72c 100644
--- a/tests/org.eclipse.jet.tests-feature/feature.xml
+++ b/tests/org.eclipse.jet.tests-feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jet.tests"
label="%featureName"
- version="0.8.0.qualifier"
+ version="0.8.1.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/modeling/m2t">
diff --git a/tests/org.eclipse.jet.tests.core/data/templates folder.jar b/tests/org.eclipse.jet.tests.core/data/templates folder.jar
new file mode 100644
index 0000000..055a260
--- /dev/null
+++ b/tests/org.eclipse.jet.tests.core/data/templates folder.jar
Binary files differ
diff --git a/tests/org.eclipse.jet.tests.core/data/templates folder.zip b/tests/org.eclipse.jet.tests.core/data/templates folder.zip
new file mode 100644
index 0000000..055a260
--- /dev/null
+++ b/tests/org.eclipse.jet.tests.core/data/templates folder.zip
Binary files differ
diff --git a/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java
index 9af446f..04964bd 100644
--- a/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java
+++ b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/AllTests.java
@@ -7,6 +7,7 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for org.eclipse.jet.tests.tools"); //$NON-NLS-1$
+ suite.addTest(org.eclipse.jet.tests.core.url.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.parser.jasper.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.tools.compiler.AllTests.suite());
suite.addTest(org.eclipse.jet.tests.tools.parser.AllTests.suite());
diff --git a/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/AllTests.java b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/AllTests.java
new file mode 100644
index 0000000..75ed8cf
--- /dev/null
+++ b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/AllTests.java
@@ -0,0 +1,17 @@
+package org.eclipse.jet.tests.core.url;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test for org.eclipse.jet.tests.core.url");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(TestURLUtility.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/TestURLUtility.java b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/TestURLUtility.java
new file mode 100644
index 0000000..7fff5f3
--- /dev/null
+++ b/tests/org.eclipse.jet.tests.core/src/org/eclipse/jet/tests/core/url/TestURLUtility.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ */
+package org.eclipse.jet.tests.core.url;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jet.internal.core.url.URLUtility;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author pelder
+ *
+ */
+public class TestURLUtility extends TestCase {
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.core.url.URLUtility#jarRootEntryURL(java.net.URL)}.
+ * @throws IOException
+ */
+ public void test_jar_platform_plugin() throws IOException {
+ URL platformURL = new URL("platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar");
+ assertEquals("platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar", platformURL.toExternalForm());
+
+ URL platformJARRoot = URLUtility.jarRootEntryURL(platformURL);
+ assertEquals("jar:platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar!/", platformJARRoot.toExternalForm());
+
+ URL test1TxtURL = URLUtility.jarEntryURL(platformURL, "templates/base1/Copy of test1.txt");
+ assertEquals("jar:platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar!/templates/base1/Copy of test1.txt",test1TxtURL.toExternalForm());
+ InputStream stream = test1TxtURL.openStream();
+ int nBytes = stream.available();
+ assertTrue(nBytes > 0);
+ byte[] buffer = new byte[nBytes];
+ int nRead = stream.read(buffer);
+ assertEquals(nBytes, nRead);
+ String content = new String(buffer,"Cp1252");
+ assertEquals("This is Copy of test1.txt in data/templates/base1.", content);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.core.url.URLUtility#jarRootEntryURL(java.net.URL)}.
+ * @throws IOException
+ */
+ public void test_jar_file() throws IOException {
+ final Bundle bundle = Platform.getBundle("org.eclipse.jet.tests.core");
+
+ final URL[] findEntries = FileLocator.findEntries(bundle, new Path("data/templates folder.jar"));
+ final URL entry = findEntries[0];
+ final URL resolved = FileLocator.resolve(entry);
+
+ URL test1TxtURL = URLUtility.jarEntryURL(resolved, "templates/base1/Copy of test1.txt");
+ InputStream stream = test1TxtURL.openStream();
+ int nBytes = stream.available();
+ assertTrue(nBytes > 0);
+ byte[] buffer = new byte[nBytes];
+ int nRead = stream.read(buffer);
+ assertEquals(nBytes, nRead);
+ String content = new String(buffer,"Cp1252");
+ assertEquals("This is Copy of test1.txt in data/templates/base1.", content);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.core.url.URLUtility#jarRootEntryURL(java.net.URL)}.
+ * @throws IOException
+ */
+ public void test_file_jar_file() throws IOException {
+ final Bundle bundle = Platform.getBundle("org.eclipse.jet.tests.core");
+
+ final URL[] findEntries = FileLocator.findEntries(bundle, new Path("data/templates folder.jar"));
+ final URL entry = findEntries[0];
+ final URL resolved = FileLocator.resolve(entry);
+
+ URL test1TxtURL = URLUtility.relativeURL(resolved, "templates/base1/Copy of test1.txt");
+// assertEquals("jar:platform:/plugin/org.eclipse.jet.tests.core/data/templates folder.jar!/templates/base1/Copy of test1.txt",test1TxtURL.toExternalForm());
+ InputStream stream = test1TxtURL.openStream();
+ int nBytes = stream.available();
+ assertTrue(nBytes > 0);
+ byte[] buffer = new byte[nBytes];
+ int nRead = stream.read(buffer);
+ assertEquals(nBytes, nRead);
+ String content = new String(buffer,"Cp1252");
+ assertEquals("This is Copy of test1.txt in data/templates/base1.", content);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.core.url.URLUtility#toURL(java.net.URI)}.
+ * @throws URISyntaxException
+ * @throws IOException
+ */
+ public void testToURL() throws URISyntaxException, IOException {
+ final Bundle bundle = Platform.getBundle("org.eclipse.jet.tests.core");
+
+ final URL[] findEntries = FileLocator.findEntries(bundle, new Path("data/templates/base1/Copy of test1.txt"));
+ final URL entry = findEntries[0];
+ final URL resolved = FileLocator.resolve(entry);
+ final File file = new File(resolved.getPath());
+
+
+ URL test1TxtURL = file.toURL();
+
+ final String URI_STRING = file.toURI().toString();
+
+ URI uri = new URI(URI_STRING);
+ URL converted = uri.toURL();
+ assertEquals(URI_STRING, converted.toString());
+ }
+
+}