diff --git a/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/ClassPathResource.java b/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/ClassPathResource.java new file mode 100644 index 00000000..3d35c092 --- /dev/null +++ b/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/ClassPathResource.java @@ -0,0 +1,349 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ibm.jaggr.core.impl.resource; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import com.ibm.jaggr.core.resource.IResource; +import com.ibm.jaggr.core.resource.IResourceVisitor; + +/** + * An implementation of {@link IResource} for classpath resources + */ +public class ClassPathResource implements IResource { + static final Logger log = Logger.getLogger(ClassPathResource.class.getName()); + + + final String zipEntryUri; + final ArrayList zipFileEntries; + URL classPathUrl; + URI classPathUri; + String classPathName; + String zipFileEntry; + ZipEntry zipEntry; + ZipFile zipFile; + + + + /** + * Public constructor used by factory + * + * @param entry + * the entry within the jar + * @param entries + * list of all entries within the jar + */ + public ClassPathResource(String entry, List entries) { + zipEntryUri = entry; + zipFileEntries = (ArrayList) entries; + try { + if (entry.startsWith("file:") && entry.contains("!")) { //$NON-NLS-1$ //$NON-NLS-2$ + String[] split = entry.split("!"); //$NON-NLS-1$ + classPathUrl = new URL(split[0]); + classPathUri = new URI(split[0]); + classPathName = split[0].substring(split[0].lastIndexOf("/") + 1); //$NON-NLS-1$ + zipFileEntry = split[1].substring(1); // need to remove the forward slash + + zipFile = new ZipFile(new File(classPathUri)); + zipEntry = zipFile.getEntry(zipFileEntry); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.Resource#getURI() + */ + @Override + public URI getURI() { + URI uri = null; + try { + uri = new URI("jar:" + zipEntryUri); //$NON-NLS-1$ + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return uri; + } + + @Override + public String getPath() { + return "classPath:///" + zipFileEntry; //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.Resource#exists() + */ + @Override + public boolean exists() { + return lastModified() != 0; + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.Resource#lastModified() + */ + @Override + public long lastModified() { + long lastmod = 0L; + try { + lastmod = getURI().toURL().openConnection().getLastModified(); + } catch (IOException ignore) {} + return lastmod; + } + + /* (non-Javadoc) + * @see com.ibm.jaggr.service.resource.IResource#resolve(java.net.URI) + */ + @Override + public IResource resolve(String relative) { + String classPathUriString, finalclassPathString = null; + URI fileUri, finalFileUri = null; + ClassPathResource classPathResource = null; + try { + classPathUriString = getURI().toString(); + if (classPathUriString.startsWith("jar:")) { //$NON-NLS-1$ + classPathUriString = classPathUriString.substring(4); + } + + fileUri = new URI(classPathUriString).resolve(relative); + finalclassPathString = "classPath:/" + fileUri; //$NON-NLS-1$ + finalFileUri = new URI(finalclassPathString); + + } catch (Exception e) { + + } + if(finalFileUri == null) + classPathResource = newInstance(getURI().resolve(relative)); + else + classPathResource = newInstance(finalFileUri); + return classPathResource; + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.Resource#getReader() + */ + @Override + public Reader getReader() throws IOException { + return new InputStreamReader(getURI().toURL().openConnection().getInputStream(), "UTF-8"); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see com.ibm.jaggr.service.resource.IResource#getInputStream() + */ + @Override + public InputStream getInputStream() throws IOException { + return getURI().toURL().openConnection().getInputStream(); + } + + /* + * (non-Javadoc) + * + * @see + * com.ibm.jaggr.service.modules.Resource#walkTree(com.ibm.jaggr.modules + * .ResourceVisitor, boolean) + */ + @Override + public void walkTree(IResourceVisitor visitor) throws IOException { + if (!exists()) { + throw new FileNotFoundException(zipEntry.getName()); + } + if (!zipEntry.isDirectory()) { + return; + } + recurse(zipEntry, visitor); + } + + /* + * (non-Javadoc) + * + * @see + * com.ibm.jaggr.service.resource.IResource#asVisitorResource() + */ + @Override + public VisitorResource asVisitorResource() throws IOException { + if (!exists()) { + throw new IOException(zipEntry.getName()); + } + return new VisitorResource(zipEntry, zipEntryUri); + } + + /** + * Internal method for recursing sub directories. + * + * @param file + * The file object + * @param visitor + * The {@link IResourceVisitor} to call for non-folder resources + * @throws IOException + */ + private void recurse(ZipEntry file, IResourceVisitor visitor) + throws IOException { + ArrayList files = getChildZipEntries(file); + + if (files == null) { + return; + } + for (ZipEntry child : files) { + String childName = child.getName().substring(file.getName().length()); + String childEntryUri = zipEntryUri + childName; + visitor.visitResource(new VisitorResource(child, + childEntryUri), childName); + } + } + + protected ClassPathResource newInstance(URI uri) { + return (ClassPathResource) new ClassPathResourceFactory().newResource(uri); + } + + private ArrayList getChildZipEntries(ZipEntry entry){ + + String entryName = entry.getName(); + ArrayList files = new ArrayList(); + for (int i = 0; i < zipFileEntries.size(); i ++){ + if(zipFileEntries.get(i).startsWith(entryName) && !(zipFileEntries.get(i).equalsIgnoreCase(entryName)) && zipFileEntries.get(i).endsWith(".js")){ //$NON-NLS-1$ + files.add(zipFile.getEntry(zipFileEntries.get(i))); + } + } + + return files; + } + + /** + * Implementation of {@link IResourceVisitor.Resource} for files. + */ + private static class VisitorResource implements IResourceVisitor.Resource { + + ZipEntry entry; + String ZipFileUri; + + + private VisitorResource(ZipEntry entry, String uri) { + this.entry = entry; + this.ZipFileUri = uri; + + } + + /* + * (non-Javadoc) + * + * @see + * com.ibm.jaggr.service.resource.IResourceVisitor.Resource + * #isFolder() + */ + @Override + public boolean isFolder() { + return entry.isDirectory(); + } + + /* + * (non-Javadoc) + * + * @see + * com.ibm.jaggr.service.modules.ResourceVisitor.Resource# + * getURI() + */ + @Override + public URI getURI() { + URI uri = null; + try { + uri = new URI("jar:" + ZipFileUri); //$NON-NLS-1$ + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return uri; + + } + + /* + * (non-Javadoc) + * + * @see + * com.ibm.jaggr.service.modules.ResourceVisitor.Resource# + * getPath() + */ + @Override + public String getPath() { + return ZipFileUri; + } + + /* + * (non-Javadoc) + * + * @see + * com.ibm.jaggr.service.modules.ResourceVisitor.Resource# + * lastModified() + */ + @Override + public long lastModified() { + long lastmodified = 0; + try { + lastmodified = getURI().toURL().openConnection().getLastModified(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return lastmodified; + } + + /* + * (non-Javadoc) + * + * @see + * com.ibm.jaggr.service.modules.ResourceVisitor.Resource# + * getReader() + */ + @Override + public Reader getReader() throws IOException { + return new InputStreamReader(getURI().toURL().openConnection().getInputStream(), "UTF-8"); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see com.ibm.jaggr.service.resource.IResourceVisitor.Resource#getInputStream() + */ + @Override + public InputStream getInputStream() throws IOException { + return getURI().toURL().openConnection().getInputStream(); + } + } + + + + +} diff --git a/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/ClassPathResourceFactory.java b/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/ClassPathResourceFactory.java new file mode 100644 index 00000000..766012ca --- /dev/null +++ b/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/ClassPathResourceFactory.java @@ -0,0 +1,98 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ibm.jaggr.core.impl.resource; + +import java.net.URI; +import java.net.URL; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import com.ibm.jaggr.core.resource.IResource; +import com.ibm.jaggr.core.resource.IResourceFactory; + +/** + * Default implementation for {@link IResourceFactory} that currently supports + * only file resources. + */ +public class ClassPathResourceFactory implements IResourceFactory { + + static public Map> classPathResourceMap = new HashMap>(); + + @Override + public IResource newResource(URI uri) { + IResource result = null; + try { + String scheme = uri.getScheme(); + String extractedResourceString = ""; //$NON-NLS-1$ + if ("classPath".equals(scheme)) { //$NON-NLS-1$ + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + if(uri.toString().indexOf("!") == -1){ //$NON-NLS-1$ + String uriPath = uri.getPath(); + extractedResourceString = uriPath.startsWith("/") ? uriPath.substring(1) : uriPath; //$NON-NLS-1$ + } else { + extractedResourceString = uri.toString().substring(uri.toString().indexOf("!") + 2); //$NON-NLS-1$ + } + Enumeration resources = classLoader.getResources(extractedResourceString); + String filePath = null; + while (resources.hasMoreElements()) { + URL resource = resources.nextElement(); + filePath = URLDecoder.decode(resource.getFile(), "UTF-8"); //$NON-NLS-1$ + } + + + ZipEntry entry = null; + String classPathName = null; + List resourceNames = new ArrayList(); + + if(filePath != null){ + if (filePath.startsWith("file:") && filePath.contains("!")) { //$NON-NLS-1$ //$NON-NLS-2$ + String[] split = filePath.split("!"); //$NON-NLS-1$ + URL classPathUrl = new URL(split[0]); + classPathName = split[0].substring(split[0].lastIndexOf("/") + 1); //$NON-NLS-1$ + if(!classPathResourceMap.containsKey(classPathName)){ + ZipInputStream zip = new ZipInputStream(classPathUrl.openStream()); + while ((entry = zip.getNextEntry()) != null) { + resourceNames.add(entry.getName()); + } + classPathResourceMap.put(classPathName, resourceNames); + } + result = new ClassPathResource(filePath, classPathResourceMap.get(classPathName)); + } + } else{ + result = new NotFoundResource(uri); + } + } else { + throw new UnsupportedOperationException(uri.getScheme()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + @Override + public boolean handles(URI uri) { + return ("classPath".equals(uri.getScheme())); //$NON-NLS-1$ + } +} diff --git a/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/JarResource.java b/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/JarResource.java new file mode 100644 index 00000000..8fa442b4 --- /dev/null +++ b/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/JarResource.java @@ -0,0 +1,355 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ibm.jaggr.core.impl.resource; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import com.ibm.jaggr.core.resource.IResource; +import com.ibm.jaggr.core.resource.IResourceVisitor; + +/** + * An implementation of {@link IResource} for Jar resources + */ +public class JarResource implements IResource { + static final Logger log = Logger.getLogger(JarResource.class.getName()); + + final String zipEntryUri; + final ArrayList zipFileEntries; + URL jarUrl; + URI jarUri; + String jarName; + String zipFileEntry; + ZipEntry zipEntry; + ZipFile zipFile; + + /** + * Public constructor used by factory + * + *@param entry + * the entry within the jar + * @param entries + * list of all entries within the jar + */ + public JarResource(String entry, List entries) { + zipEntryUri = entry; + zipFileEntries = (ArrayList) entries; + try { + if (entry.startsWith("file:") && entry.contains("!")) { //$NON-NLS-1$ //$NON-NLS-2$ + String[] split = entry.split("!"); //$NON-NLS-1$ + jarUrl = new URL(split[0]); + jarUri = new URI(split[0]); + jarName = split[0].substring(split[0].lastIndexOf("/") + 1); //$NON-NLS-1$ + zipFileEntry = split[1].substring(1); // need to remove the + // forward slash + + zipFile = new ZipFile(new File(jarUri)); + zipEntry = zipFile.getEntry(zipFileEntry); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.Resource#getURI() + */ + @Override + public URI getURI() { + URI uri = null; + try { + uri = new URI("jar:" + zipEntryUri); //$NON-NLS-1$ + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return uri; + } + + @Override + public String getPath() { + return "jar:///" + zipFileEntry; //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.Resource#exists() + */ + @Override + public boolean exists() { + return lastModified() != 0; + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.Resource#lastModified() + */ + @Override + public long lastModified() { + long lastmod = 0L; + try { + lastmod = getURI().toURL().openConnection().getLastModified(); + } catch (IOException e) { + } + return lastmod; + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.resource.IResource#resolve(java.net.URI) + */ + @Override + public IResource resolve(String relative) { + String jarUriString, finaljarString = null; + URI fileUri, finalFileUri = null; + JarResource jarResource = null; + try { + jarUriString = getURI().toString(); + if (jarUriString.startsWith("jar:")) { //$NON-NLS-1$ + jarUriString = jarUriString.substring(4); + } + + fileUri = new URI(jarUriString).resolve(relative); + finaljarString = "jar:/" + fileUri; //$NON-NLS-1$ + finalFileUri = new URI(finaljarString); + + } catch (Exception e) { + + } + if (finalFileUri == null) + jarResource = newInstance(getURI().resolve(relative)); + else + jarResource = newInstance(finalFileUri); + return jarResource; + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.Resource#getReader() + */ + @Override + public Reader getReader() throws IOException { + return new InputStreamReader(getURI().toURL().openConnection() + .getInputStream(), "UTF-8"); //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.resource.IResource#getInputStream() + */ + @Override + public InputStream getInputStream() throws IOException { + return getURI().toURL().openConnection().getInputStream(); + } + + /* + * (non-Javadoc) + * + * @see + * com.ibm.jaggr.service.modules.Resource#walkTree(com.ibm.jaggr.modules + * .ResourceVisitor, boolean) + */ + @Override + public void walkTree(IResourceVisitor visitor) throws IOException { + if (!exists()) { + throw new FileNotFoundException(zipEntry.getName()); + } + if (!zipEntry.isDirectory()) { + return; + } + recurse(zipEntry, visitor); + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.resource.IResource#asVisitorResource() + */ + @Override + public VisitorResource asVisitorResource() throws IOException { + if (!exists()) { + throw new IOException(zipEntry.getName()); + } + return new VisitorResource(zipEntry, zipEntryUri); + } + + /** + * Internal method for recursing sub directories. + * + * @param file + * The file object + * @param visitor + * The {@link IResourceVisitor} to call for non-folder resources + * @throws IOException + */ + private void recurse(ZipEntry file, IResourceVisitor visitor) + throws IOException { + ArrayList files = getChildZipEntries(file); + + if (files == null) { + return; + } + for (ZipEntry child : files) { + String childName = child.getName().substring( + file.getName().length()); + String childEntryUri = zipEntryUri + childName; + visitor.visitResource(new VisitorResource(child, childEntryUri), + childName); + } + } + + protected JarResource newInstance(URI uri) { + return (JarResource) new JarResourceFactory().newResource(uri); + } + + private ArrayList getChildZipEntries(ZipEntry entry) { + + String entryName = entry.getName(); + + ArrayList files = new ArrayList(); + for (int i = 0; i < zipFileEntries.size(); i++) { + if (zipFileEntries.get(i).startsWith(entryName) + && !(zipFileEntries.get(i).equalsIgnoreCase(entryName)) + && zipFileEntries.get(i).endsWith(".js")) { //$NON-NLS-1$ + files.add(zipFile.getEntry(zipFileEntries.get(i))); + } + } + + return files; + } + + /** + * Implementation of {@link IResourceVisitor.Resource} for files. + */ + private static class VisitorResource implements IResourceVisitor.Resource { + + ZipEntry entry; + String ZipFileUri; + + private VisitorResource(ZipEntry entry, String uri) { + this.entry = entry; + this.ZipFileUri = uri; + + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.resource.IResourceVisitor.Resource + * #isFolder() + */ + @Override + public boolean isFolder() { + if (entry == null) { + return false; + } + return entry.isDirectory(); + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.ResourceVisitor.Resource# getURI() + */ + @Override + public URI getURI() { + URI uri = null; + try { + uri = new URI("jar:" + ZipFileUri); //$NON-NLS-1$ + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return uri; + + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.ResourceVisitor.Resource# + * getPath() + */ + @Override + public String getPath() { + return ZipFileUri; + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.ResourceVisitor.Resource# + * lastModified() + */ + @Override + public long lastModified() { + long lastmodified = 0; + try { + lastmodified = getURI().toURL().openConnection() + .getLastModified(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return lastmodified; + } + + /* + * (non-Javadoc) + * + * @see com.ibm.jaggr.service.modules.ResourceVisitor.Resource# + * getReader() + */ + @Override + public Reader getReader() throws IOException { + return new InputStreamReader(getURI().toURL().openConnection() + .getInputStream(), "UTF-8"); //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see + * com.ibm.jaggr.service.resource.IResourceVisitor.Resource#getInputStream + * () + */ + @Override + public InputStream getInputStream() throws IOException { + return getURI().toURL().openConnection().getInputStream(); + } + } + +} diff --git a/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/JarResourceFactory.java b/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/JarResourceFactory.java new file mode 100644 index 00000000..343167be --- /dev/null +++ b/jaggr-core/src/main/java/com/ibm/jaggr/core/impl/resource/JarResourceFactory.java @@ -0,0 +1,90 @@ +/* + * (C) Copyright 2012, IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ibm.jaggr.core.impl.resource; + +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import com.ibm.jaggr.core.resource.IResource; +import com.ibm.jaggr.core.resource.IResourceFactory; + +/** + * Default implementation for {@link IResourceFactory} that currently supports + * only file resources. + */ +public class JarResourceFactory implements IResourceFactory { + + static public Map> jarResourceMap = new HashMap>(); + + @Override + public IResource newResource(URI uri) { + IResource result = null; + try { + String scheme = uri.getScheme(); + if ("jar".equals(scheme)) { //$NON-NLS-1$ + String filePath = null; + int startIndex = uri.toString().indexOf("file:"); //$NON-NLS-1$ + filePath = uri.toString().substring(startIndex); + + URL classPathUrl = null; + ZipEntry entry = null; + String classPathName = null; + String zipFileEntry = null; + List resourceNames = new ArrayList(); + + + if (filePath.startsWith("file:") && filePath.contains("!")) { //$NON-NLS-1$ //$NON-NLS-2$ + String[] split = filePath.split("!"); //$NON-NLS-1$ + classPathUrl = new URL(split[0]); + classPathName = split[0].substring(split[0].lastIndexOf("/") + 1); //$NON-NLS-1$ + zipFileEntry = split[1]; + if(!jarResourceMap.containsKey(classPathName)){ + ZipInputStream zip = new ZipInputStream(classPathUrl.openStream()); + while ((entry = zip.getNextEntry()) != null) { + resourceNames.add(entry.getName()); + } + jarResourceMap.put(classPathName, resourceNames); + } + String resourceName = zipFileEntry.startsWith("/")?zipFileEntry.substring(1):zipFileEntry; //$NON-NLS-1$ + if(jarResourceMap.get(classPathName).contains(resourceName)){ + result = new JarResource(filePath, jarResourceMap.get(classPathName)); + }else{ + result = new NotFoundResource(uri); + } + } + + } else { + throw new UnsupportedOperationException(uri.getScheme()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + @Override + public boolean handles(URI uri) { + return ("jar".equals(uri.getScheme())); //$NON-NLS-1$ + } +} diff --git a/jaggr-service/plugin.xml b/jaggr-service/plugin.xml index cdc7f0fe..f367a6c8 100644 --- a/jaggr-service/plugin.xml +++ b/jaggr-service/plugin.xml @@ -46,6 +46,10 @@ class="com.ibm.jaggr.service.impl.resource.BundleResourceFactory"/> + +