@Override protected WebResourceSet createMainResourceSet() { final Path docBase = config.docBase(); assert docBase.isAbsolute(); final String docBaseStr = docBase.toString(); getContext().setDocBase(docBaseStr); if (Files.isDirectory(docBase)) { return new DirResourceSet(this, "/", docBaseStr, "/"); } final Optional<String> jarRootOpt = config.jarRoot(); if (jarRootOpt.isPresent()) { // If docBase is a JAR file final String jarRoot = jarRootOpt.get(); if ("/".equals(jarRoot)) { return new JarResourceSet(this, "/", docBaseStr, "/"); } else { return new JarSubsetResourceSet(this, "/", docBaseStr, "/", jarRoot); } } throw new IllegalArgumentException(sm.getString("standardRoot.startInvalidMain", docBaseStr)); } }
@Override protected WebResource createArchiveResource(JarEntry jarEntry, String webAppPath, Manifest manifest) { return new JarResource(getRoot(), webAppPath, getBase(), getBaseUrlString(), jarEntry, getInternalPath(), manifest); }
@Override protected void initInternal() throws LifecycleException { try (JarFile jarFile = new JarFile(getBase())) { Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); getJarFileEntries().put(entry.getName(), entry); } setManifest(jarFile.getManifest()); } catch (IOException ioe) { throw new IllegalArgumentException(ioe); } try { setBaseUrl((new File(getBase())).toURI().toURL()); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } } }
@Override protected WebResource createArchiveResource(JarEntry jarEntry, String webAppPath, Manifest manifest) { return new JarResource(this, webAppPath, getBaseUrlString(), jarEntry); } }
@Override protected WebResource createArchiveResource(JarEntry jarEntry, String webAppPath, Manifest manifest) { return new JarResource(this, webAppPath, getBaseUrlString(), jarEntry); } }
main = new DirResourceSet(this, "/", f.getAbsolutePath(), "/"); } else if(f.isFile() && docBase.endsWith(".war")) { main = new JarResourceSet(this, "/", f.getAbsolutePath(), "/"); } else { throw new IllegalArgumentException(
archivePath, internalPath); } else if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) { resourceSet = new JarResourceSet(this, webAppMount, base, internalPath); } else {
archivePath, internalPath); } else if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) { resourceSet = new JarResourceSet(this, webAppMount, base, internalPath); } else {
archivePath, internalPath); } else if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) { resourceSet = new JarResourceSet(this, webAppMount, base, internalPath); } else {
@Test public void embeddedWarWithAppResources() throws LifecycleException { ContextMock contextMock = new ContextMock(); File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.war"); JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES); jarWarResourceSet.init(); JarResourceSet jarResourceSet = new JarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), METAINF_RESOURCES); contextMock.init(jarWarResourceSet, jarResourceSet); callApplicationEvent(contextMock); assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()) .isEqualTo(0); }
@Test public void embeddedJarWithAppResources() throws LifecycleException { ContextMock contextMock = new ContextMock(); File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.jar"); JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES); jarWarResourceSet.init(); JarResourceSet jarResourceSet = new JarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), METAINF_RESOURCES); contextMock.init(jarWarResourceSet, jarResourceSet); callApplicationEvent(contextMock); assertThat(contextMock.getWebResourceRoot().getCreateWebResourceSetCalls()) .isEqualTo(2); }
@Test public void embeddedJarWithAppResources() throws LifecycleException { ContextMock contextMock = new ContextMock(); File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.jar"); JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES); jarWarResourceSet.init(); JarResourceSet jarResourceSet = new JarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), METAINF_RESOURCES); contextMock.init(jarWarResourceSet, jarResourceSet); callApplicationEvent(contextMock); assertThat(contextMock.getCalledAnswer().getCalls()) .isEqualTo(1); }
@Test public void embeddedJarWithAppResources() throws LifecycleException { ContextMock contextMock = new ContextMock(); File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.jar"); JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES); jarWarResourceSet.init(); JarResourceSet jarResourceSet = new JarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), METAINF_RESOURCES); contextMock.init(jarWarResourceSet, jarResourceSet); callApplicationEvent(contextMock); assertThat(contextMock.getCalledAnswer().getCalls()) .isEqualTo(1); }
@Test public void embeddedWarWithAppResources() throws LifecycleException { ContextMock contextMock = new ContextMock(); File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.war"); JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES); jarWarResourceSet.init(); JarResourceSet jarResourceSet = new JarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), METAINF_RESOURCES); contextMock.init(jarWarResourceSet, jarResourceSet); callApplicationEvent(contextMock); assertThat(contextMock.getCalledAnswer().getCalls()) .isEqualTo(0); }
@Test public void embeddedWarWithAppResources() throws LifecycleException { ContextMock contextMock = new ContextMock(); File file = new File(TARGET + File.separator + TEST_CLASSES + File.separator + "test.war"); JarWarResourceSet jarWarResourceSet = new JarWarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), INTERNAL_JAR, METAINF_RESOURCES); jarWarResourceSet.init(); JarResourceSet jarResourceSet = new JarResourceSet(contextMock.getWebResourceRoot(), "/", file.getAbsolutePath(), METAINF_RESOURCES); contextMock.init(jarWarResourceSet, jarResourceSet); callApplicationEvent(contextMock); assertThat(contextMock.getCalledAnswer().getCalls()) .isEqualTo(0); }
jar = jar.substring("file:".length()); root.addPostResources(new JarResourceSet(root, mapping, jar, "/static/hawtio/"));