Created
May 8, 2013 18:25
-
-
Save chuckdumont/5542468 to your computer and use it in GitHub Desktop.
Patch for https://github.com/chuckdumont/JavascriptAggregator/commit/748f78e2578e850bc8839e824f8d408a1f429db5
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
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/modulebuilder/css/CSSModuleBuilder.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/modulebuilder/css/CSSModuleBuilder.java | |
index 07d50f1..3459503 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/modulebuilder/css/CSSModuleBuilder.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/modulebuilder/css/CSSModuleBuilder.java | |
@@ -221,14 +221,14 @@ | |
String css = readToString(new CommentStrippingReader(resource.getReader())); | |
// whitespace | |
- css = minify(css, resource.getURI()); | |
+ css = minify(css, resource); | |
// Inline images | |
- css = inlineImageUrls(request, css, resource.getURI()); | |
+ css = inlineImageUrls(request, css, resource); | |
// in-line @imports | |
if (inlineImports) { | |
- css = inlineImports(request, css, resource.getURI(), ""); //$NON-NLS-1$ | |
+ css = inlineImports(request, css, resource, ""); //$NON-NLS-1$ | |
} | |
return new StringReader(css); | |
} | |
@@ -265,7 +265,7 @@ | |
* @param uri The URI for the CSS file | |
* @return | |
*/ | |
- protected String minify(String css, URI uri) { | |
+ protected String minify(String css, IResource res) { | |
// replace all quoted strings and url(...) patterns with unique ids so that | |
// they won't be affected by whitespace removal. | |
@@ -334,7 +334,7 @@ | |
* | |
* @throws IOException | |
*/ | |
- protected String inlineImports(HttpServletRequest req, String css, URI uri, String path) throws IOException { | |
+ protected String inlineImports(HttpServletRequest req, String css, IResource res, String path) throws IOException { | |
// In-lining of imports can be disabled by request parameter for debugging | |
if (!TypeUtil.asBoolean(req.getParameter(INLINEIMPORTS_REQPARAM_NAME), true)) { | |
@@ -390,22 +390,22 @@ | |
continue; | |
} | |
- URI importUri = uri.resolve(importNameMatch); | |
+ IResource importRes = res.resolve(importNameMatch); | |
String importCss = null; | |
importCss = readToString( | |
new CommentStrippingReader( | |
new InputStreamReader( | |
- importUri.toURL().openStream(), | |
+ importRes.getURI().toURL().openStream(), | |
"UTF-8" //$NON-NLS-1$ | |
) | |
) | |
); | |
- importCss = minify(importCss, importUri); | |
+ importCss = minify(importCss, importRes); | |
// Inline images | |
- importCss = inlineImageUrls(req, importCss, importUri); | |
+ importCss = inlineImageUrls(req, importCss, importRes); | |
if (inlineImports) { | |
- importCss = inlineImports(req, importCss, importUri, importNameMatch); | |
+ importCss = inlineImports(req, importCss, importRes, importNameMatch); | |
} | |
m.appendReplacement(buf, ""); //$NON-NLS-1$ | |
buf.append(importCss); | |
@@ -485,7 +485,7 @@ | |
* @return The transformed CSS with images in-lined as determined by option | |
* settings. | |
*/ | |
- protected String inlineImageUrls(HttpServletRequest req, String css, URI uri) { | |
+ protected String inlineImageUrls(HttpServletRequest req, String css, IResource res) { | |
if (imageSizeThreshold == 0 && inlinedImageIncludeList.size() == 0) { | |
// nothing to do | |
return css; | |
@@ -513,7 +513,7 @@ | |
continue; | |
} | |
- URI imageUri = uri.resolve(urlMatch); | |
+ URI imageUri = res.getURI().resolve(urlMatch); | |
boolean exclude = false, include = false; | |
// Determine if this image is in the include list | |
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/BundleResource.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/BundleResource.java | |
index 54bc434..fb4721a 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/BundleResource.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/BundleResource.java | |
@@ -35,8 +35,8 @@ | |
import com.ibm.jaggr.service.util.PathUtil; | |
public class BundleResource implements IResource { | |
- URI uri; | |
- String symname = null; | |
+ final URI uri; | |
+ final String symname; | |
public BundleResource(URI uri, BundleContext context) { | |
this.uri = uri; | |
@@ -50,9 +50,12 @@ | |
bundle = context.getBundle(bundleid); | |
} catch (NumberFormatException ignore) { | |
} | |
- if (bundle != null) { | |
- this.symname = bundle.getSymbolicName(); | |
- } | |
+ symname = (bundle != null) ? bundle.getSymbolicName() : null; | |
+ } | |
+ | |
+ private BundleResource(URI uri, String symname) { | |
+ this.uri = uri; | |
+ this.symname = symname; | |
} | |
/* (non-Javadoc) | |
@@ -84,6 +87,14 @@ | |
} | |
/* (non-Javadoc) | |
+ * @see com.ibm.jaggr.service.resource.IResource#resolve(java.lang.String) | |
+ */ | |
+ @Override | |
+ public IResource resolve(String relative) { | |
+ return new BundleResource(getURI().resolve(relative), symname); | |
+ } | |
+ | |
+ /* (non-Javadoc) | |
* @see com.ibm.jaggr.service.resource.IResource#getReader() | |
*/ | |
@Override | |
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/BundleResourceFactory.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/BundleResourceFactory.java | |
index e6d63c6..15f047d 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/BundleResourceFactory.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/BundleResourceFactory.java | |
@@ -44,7 +44,6 @@ | |
private BundleContext context; | |
private ServiceReference urlConverterSR; | |
- private IAggregator aggregator = null; | |
public BundleResourceFactory() { | |
} | |
@@ -61,7 +60,7 @@ | |
URL fileUrl = null; | |
try { | |
fileUrl = converter.toFileURL(uri.toURL()); | |
- result = getAggregator().newResource(PathUtil.url2uri(fileUrl)); | |
+ result = new FileResource(uri, this, PathUtil.url2uri(fileUrl)); | |
} catch (FileNotFoundException e) { | |
if (log.isLoggable(Level.FINE)) { | |
log.log(Level.FINE, uri.toString(), e); | |
@@ -112,13 +111,8 @@ | |
@Override | |
public void initialize(IAggregator aggregator, IAggregatorExtension extension, IExtensionRegistrar registrar) { | |
- this.aggregator = aggregator; | |
} | |
- protected IAggregator getAggregator() { | |
- return aggregator; | |
- } | |
- | |
@Override | |
public boolean handles(URI uri) { | |
String scheme = uri.getScheme(); | |
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/ExceptionResource.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/ExceptionResource.java | |
index 73ab9a9..1ca1129 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/ExceptionResource.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/ExceptionResource.java | |
@@ -74,4 +74,9 @@ | |
return false; | |
} | |
+ @Override | |
+ public IResource resolve(String relative) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+ | |
} | |
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/FileResource.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/FileResource.java | |
index b32a90a..d823bdc 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/FileResource.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/FileResource.java | |
@@ -29,6 +29,7 @@ | |
import java.util.logging.Logger; | |
import com.ibm.jaggr.service.resource.IResource; | |
+import com.ibm.jaggr.service.resource.IResourceFactory; | |
import com.ibm.jaggr.service.resource.IResourceVisitor; | |
/** | |
@@ -37,7 +38,9 @@ | |
public class FileResource implements IResource { | |
static final Logger log = Logger.getLogger(FileResource.class.getName()); | |
- File file; | |
+ final File file; | |
+ URI ref; | |
+ IResourceFactory factory; | |
/** | |
* Public constructor used by factory | |
@@ -51,6 +54,17 @@ | |
file = new File("\\\\" + uri.getAuthority() + '/' + uri.getPath()); //$NON-NLS-1$ | |
} else { | |
file = new File(uri); | |
+ } | |
+ ref = null; | |
+ factory = null; | |
+ } | |
+ | |
+ public FileResource(URI ref, IResourceFactory factory, URI uri) { | |
+ this(uri); | |
+ this.ref = ref; | |
+ this.factory = factory; | |
+ if (ref == null || factory == null) { | |
+ throw new IllegalArgumentException(); | |
} | |
} | |
@@ -97,6 +111,20 @@ | |
return file.lastModified(); | |
} | |
+ /* (non-Javadoc) | |
+ * @see com.ibm.jaggr.service.resource.IResource#resolve(java.net.URI) | |
+ */ | |
+ @Override | |
+ public IResource resolve(String relative) { | |
+ IResource result = null; | |
+ if (ref == null) { | |
+ result = new FileResource(getURI().resolve(relative)); | |
+ } else { | |
+ result = factory.newResource(ref.resolve(relative)); | |
+ } | |
+ return result; | |
+ } | |
+ | |
/* | |
* (non-Javadoc) | |
* | |
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/NotFoundResource.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/NotFoundResource.java | |
index c0f62b6..831815b 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/NotFoundResource.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/resource/NotFoundResource.java | |
@@ -66,4 +66,9 @@ | |
throw new IOException(uri.toString()); | |
} | |
+ @Override | |
+ public IResource resolve(String relative) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+ | |
} | |
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/transport/AbstractHttpTransport.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/transport/AbstractHttpTransport.java | |
index 07afc6b..0c7cdee 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/transport/AbstractHttpTransport.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/impl/transport/AbstractHttpTransport.java | |
@@ -802,6 +802,14 @@ | |
public boolean isFolder() { | |
return false; | |
} | |
+ | |
+ /* (non-Javadoc) | |
+ * @see com.ibm.jaggr.service.resource.IResource#resolve(java.lang.String) | |
+ */ | |
+ @Override | |
+ public IResource resolve(String relative) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
} | |
} | |
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/AggregationResource.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/AggregationResource.java | |
index 8b7e873..0a46d18 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/AggregationResource.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/AggregationResource.java | |
@@ -124,4 +124,12 @@ | |
public boolean isFolder() { | |
return false; | |
} | |
+ | |
+ /* (non-Javadoc) | |
+ * @see com.ibm.jaggr.service.resource.IResource#resolve(java.lang.String) | |
+ */ | |
+ @Override | |
+ public IResource resolve(String relative) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
} | |
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/IResource.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/IResource.java | |
index 860674e..d05295d 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/IResource.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/IResource.java | |
@@ -21,6 +21,8 @@ | |
import java.io.Reader; | |
import java.net.URI; | |
+import org.eclipse.osgi.service.urlconversion.URLConverter; | |
+ | |
/** | |
* Defines the interface for AMD module resources. Implementations can provide | |
* support for resources on the file system, in zip and jar files, or any other | |
@@ -58,6 +60,15 @@ | |
public long lastModified(); | |
/** | |
+ * Returns an IResource for the resource obtained by resolving the URI of | |
+ * this resource with the specified relative URI. Use this method instead of | |
+ * {@link #getURI()#resolve(String)} to ensure that the cached resource for the | |
+ * URI exists in the event that resource URIs are derived from a service | |
+ * such as {@link URLConverter#toFileURL(java.net.URL)}. | |
+ */ | |
+ public IResource resolve(String relative); | |
+ | |
+ /** | |
* Returns a {@link Reader} object for the resource if the resource is not a | |
* directory/folder resource. | |
* | |
diff --git a/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/StringResource.java b/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/StringResource.java | |
index 0015535..4ace57b 100644 | |
--- a/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/StringResource.java | |
+++ b/jaggr-service/src/main/java/com/ibm/jaggr/service/resource/StringResource.java | |
@@ -74,5 +74,10 @@ | |
public boolean isFolder() { | |
return false; | |
} | |
+ | |
+ @Override | |
+ public IResource resolve(String relative) { | |
+ return new StringResource("", uri.resolve(relative)); | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment