Skip to content

Commit

Permalink
Adds support for WAR files
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanue1 committed May 13, 2015
1 parent b9f5177 commit 5f8b151
Show file tree
Hide file tree
Showing 34 changed files with 632 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class GenericContainer implements Container {
}

protected Collection<Container.Entry> loadChildrenFromFileEntry() {
def tmpFile = File.createTempFile('jd-gui.', '.tmp.zip')
def tmpFile = File.createTempFile('jd-gui.', '.tmp.' + fsPath.fileName.toString())
def tmpPath = Paths.get(tmpFile.toURI())

tmpFile.withOutputStream { OutputStream os ->
Expand All @@ -130,7 +130,7 @@ class GenericContainer implements Container {
tmpFile.deleteOnExit()

def rootPath = rootDirectories.next()
def container = api.getContainerFactory(subFileSystem)?.make(api, this, rootPath)
def container = api.getContainerFactory(rootPath)?.make(api, this, rootPath)
if (container) {
return container.root.children
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2008-2015 Emmanuel Dupuy
* This program is made available under the terms of the GPLv3 License.
*/

package jd.gui.model.container

import groovy.transform.CompileStatic
import jd.gui.api.API
import jd.gui.api.model.Container

import java.nio.file.Path

@CompileStatic
class WarContainer extends GenericContainer {

WarContainer(API api, Container.Entry parentEntry, Path rootPath) {
super(api, parentEntry, rootPath)
}

String getType() { 'war' }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import jd.gui.api.model.Container
import jd.gui.model.container.GenericContainer
import jd.gui.spi.ContainerFactory

import java.nio.file.FileSystem
import java.nio.file.Path

class GenericContainerFactoryProvider implements ContainerFactory {

String getType() { 'generic' }

boolean accept(API api, FileSystem fileSystem) { true }
boolean accept(API api, Path rootPath) { true }

Container make(API api, Container.Entry parentEntry, Path rootPath) {
return new GenericContainer(api, parentEntry, rootPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import jd.gui.api.model.Container
import jd.gui.model.container.JarContainer
import jd.gui.spi.ContainerFactory

import java.nio.file.FileSystem
import java.nio.file.Files
import java.nio.file.InvalidPathException
import java.nio.file.Path
Expand All @@ -19,25 +18,17 @@ class JarContainerFactoryProvider implements ContainerFactory {

String getType() { 'jar' }

boolean accept(API api, FileSystem fileSystem) {
def rootDirectories = fileSystem.rootDirectories.iterator()

if (rootDirectories.hasNext()) {
def rootPath = rootDirectories.next()

if (rootPath.toUri().toString().toLowerCase().endsWith('.jar!/')) {
// Specification: http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html
return true
} else {
// Extension: accept uncompressed JAR file containing a folder 'META-INF'
try {
return Files.exists(fileSystem.getPath('/META-INF'))
} catch (InvalidPathException e) {
return false
}
}
boolean accept(API api, Path rootPath) {
if (rootPath.toUri().toString().toLowerCase().endsWith('.jar!/')) {
// Specification: http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html
return true
} else {
return false
// Extension: accept uncompressed JAR file containing a folder 'META-INF'
try {
return rootPath.fileSystem.provider().scheme.equals('file') && Files.exists(rootPath.resolve('META-INF'))
} catch (InvalidPathException e) {
return false
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2008-2015 Emmanuel Dupuy
* This program is made available under the terms of the GPLv3 License.
*/

package jd.gui.service.container

import jd.gui.api.API
import jd.gui.api.model.Container
import jd.gui.model.container.WarContainer
import jd.gui.spi.ContainerFactory

import java.nio.file.Files
import java.nio.file.InvalidPathException
import java.nio.file.Path

class WarContainerFactoryProvider implements ContainerFactory {

String getType() { 'war' }

boolean accept(API api, Path rootPath) {
if (rootPath.toUri().toString().toLowerCase().endsWith('.war!/')) {
return true
} else {
// Extension: accept uncompressed JAR file containing a folder 'WEB-INF'
try {
return rootPath.fileSystem.provider().scheme.equals('file') && Files.exists(rootPath.resolve('WEB-INF'))
} catch (InvalidPathException e) {
return false
}
}
}

Container make(API api, Container.Entry parentEntry, Path rootPath) {
return new WarContainer(api, parentEntry, rootPath)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class AbstractFileLoaderProvider implements FileLoader {
InputStream getInputStream() { null }
Collection<Container.Entry> getChildren() { children }
}
def container = api.getContainerFactory(rootPath.fileSystem)?.make(api, parentEntry, rootPath)
def container = api.getContainerFactory(rootPath)?.make(api, parentEntry, rootPath)

if (container) {
parentEntry.children = container.root.children
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package jd.gui.service.fileloader

import jd.gui.api.API

class WarFileLoaderProvider extends ZipFileLoaderProvider {

String[] getExtensions() { ['war'] }
String getDescription() { 'War files (*.war)' }

boolean accept(API api, File file) {
return file.exists() && file.canRead() && file.name.toLowerCase().endsWith('.war')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import java.util.regex.Pattern

class TextFileIndexerProvider implements Indexer {
String[] getTypes() { [
'*:file:*.txt', '*:file:*.html', '*:file:*.js', '*:file:*.jsp', '*:file:*.xml',
'*:file:*.xsl', '*:file:*.xslt', '*:file:*.xsd', '*:file:*.properties', '*:file:*.sql'] }
'*:file:*.txt', '*:file:*.html', '*:file:*.xhtml', '*:file:*.js', '*:file:*.jsp', '*:file:*.jspf',
'*:file:*.xml', '*:file:*.xsl', '*:file:*.xslt', '*:file:*.xsd', '*:file:*.properties', '*:file:*.sql'] }

Pattern getPathPattern() { null }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2008-2015 Emmanuel Dupuy
* This program is made available under the terms of the GPLv3 License.
*/

package jd.gui.service.indexer

import jd.gui.api.API
import jd.gui.api.model.Container
import jd.gui.api.model.Indexes
import jd.gui.util.xml.AbstractXmlPathFinder

class WebXmlFileIndexerProvider extends XmlFileIndexerProvider {
String[] getTypes() { ['*:file:WEB-INF/web.xml'] }

void index(API api, Container.Entry entry, Indexes indexes) {
super.index(api, entry, indexes)

new WebXmlPathFinder(entry, indexes).find(entry.inputStream.text)
}

static class WebXmlPathFinder extends AbstractXmlPathFinder {
Container.Entry entry
Map<String, Collection> index

WebXmlPathFinder(Container.Entry entry, Indexes indexes) {
super([
'web-app/filter/filter-class',
'web-app/listener/listener-class',
'web-app/servlet/servlet-class'
])
this.entry = entry
this.index = indexes.getIndex('typeReferences');
}

void handle(String path, String text, int position) {
index.get(text.replace('.', '/')).add(entry);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import jd.gui.spi.Indexer
import java.util.regex.Pattern

class ZipFileIndexerProvider implements Indexer {
String[] getTypes() { ['*:file:*.zip', '*:file:*.jar'] }
String[] getTypes() { ['*:file:*.zip', '*:file:*.jar', '*:file:*.war'] }

Pattern getPathPattern() { null }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import jd.gui.util.JarContainerEntryUtil
import java.nio.file.Path

class PackageSourceSaverProvider extends DirectorySourceSaverProvider {
String[] getTypes() { ['jar:dir:*'] }
String[] getTypes() { ['jar:dir:*', 'war:dir:*'] }

void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path path, Container.Entry entry) {
save(api, controller, listener, path, JarContainerEntryUtil.removeInnerTypeEntries(entry.children))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import java.nio.file.Paths

class ZipFileSourceSaverProvider extends DirectorySourceSaverProvider {

String[] getTypes() { ['*:file:*.zip', '*:file:*.jar'] }
String[] getTypes() { ['*:file:*.zip', '*:file:*.jar', '*:file:*.war'] }

String getSourcePath(Container.Entry entry) {
def path = entry.path
return path.substring(0, path.length()-3) + 'src.zip'
return path + '.src.zip'
}

@CompileStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2008-2015 Emmanuel Dupuy
* This program is made available under the terms of the GPLv3 License.
*/

package jd.gui.service.treenode

import jd.gui.api.API
import jd.gui.api.feature.UriGettable
import jd.gui.api.model.Container
import jd.gui.view.data.TreeNodeBean
import org.fife.ui.rsyntaxtextarea.SyntaxConstants

import javax.swing.ImageIcon
import javax.swing.JComponent
import javax.swing.tree.DefaultMutableTreeNode

class CssFileTreeNodeFactoryProvider extends TextFileTreeNodeFactoryProvider {
static final ImageIcon icon = new ImageIcon(HtmlFileTreeNodeFactoryProvider.class.classLoader.getResource('images/css_obj.png'))

String[] getTypes() { ['*:file:*.css'] }

public <T extends DefaultMutableTreeNode & UriGettable> T make(API api, Container.Entry entry) {
int lastSlashIndex = entry.path.lastIndexOf('/')
def name = entry.path.substring(lastSlashIndex+1)
return new TreeNode(entry, new TreeNodeBean(label:name, icon:icon, tip:"Location: $entry.uri.path"))
}

static class TreeNode extends TextFileTreeNodeFactoryProvider.TreeNode {
TreeNode(Container.Entry entry, Object userObject) {
super(entry, userObject)
}

public <T extends JComponent & UriGettable> T createPage(API api) {
return new TextFileTreeNodeFactoryProvider.Page(entry) {
String getSyntaxStyle() {
SyntaxConstants.SYNTAX_STYLE_CSS
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import javax.swing.tree.DefaultMutableTreeNode
class HtmlFileTreeNodeFactoryProvider extends TextFileTreeNodeFactoryProvider {
static final ImageIcon icon = new ImageIcon(HtmlFileTreeNodeFactoryProvider.class.classLoader.getResource('images/html_obj.gif'))

String[] getTypes() { ['*:file:*.html'] }
String[] getTypes() { ['*:file:*.html', '*:file:*.xhtml'] }

public <T extends DefaultMutableTreeNode & UriGettable> T make(API api, Container.Entry entry) {
int lastSlashIndex = entry.path.lastIndexOf('/')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2008-2015 Emmanuel Dupuy
* This program is made available under the terms of the GPLv3 License.
*/

package jd.gui.service.treenode

import jd.gui.api.API
import jd.gui.api.feature.UriGettable
import jd.gui.api.model.Container
import jd.gui.view.data.TreeNodeBean
import org.fife.ui.rsyntaxtextarea.SyntaxConstants

import javax.swing.ImageIcon
import javax.swing.JComponent
import javax.swing.tree.DefaultMutableTreeNode

class JspFileTreeNodeFactoryProvider extends TextFileTreeNodeFactoryProvider {
static final ImageIcon icon = new ImageIcon(HtmlFileTreeNodeFactoryProvider.class.classLoader.getResource('images/html_obj.gif'))

String[] getTypes() { ['*:file:*.jsp', '*:file:*.jspf'] }

public <T extends DefaultMutableTreeNode & UriGettable> T make(API api, Container.Entry entry) {
int lastSlashIndex = entry.path.lastIndexOf('/')
def name = entry.path.substring(lastSlashIndex+1)
return new TreeNode(entry, new TreeNodeBean(label:name, icon:icon, tip:"Location: $entry.uri.path"))
}

static class TreeNode extends TextFileTreeNodeFactoryProvider.TreeNode {
TreeNode(Container.Entry entry, Object userObject) {
super(entry, userObject)
}

public <T extends JComponent & UriGettable> T createPage(API api) {
return new TextFileTreeNodeFactoryProvider.Page(entry) {
String getSyntaxStyle() {
SyntaxConstants.SYNTAX_STYLE_JSP
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import javax.swing.*
import javax.swing.tree.DefaultMutableTreeNode

class ManifestFileTreeNodeFactoryProvider extends FileTreeNodeFactoryProvider {
static
final ImageIcon icon = new ImageIcon(ManifestFileTreeNodeFactoryProvider.class.classLoader.getResource('images/manifest_obj.png'))
static final ImageIcon icon = new ImageIcon(ManifestFileTreeNodeFactoryProvider.class.classLoader.getResource('images/manifest_obj.png'))

String[] getTypes() { ['*:file:META-INF/MANIFEST.MF'] }

public <T extends DefaultMutableTreeNode & UriGettable> T make(API api, Container.Entry entry) {
return new TreeNode(entry, new TreeNodeBean(label: 'MANIFEST.MF', icon: icon, tip:"Location: $entry.uri.path"))
return new TreeNode(entry, new TreeNodeBean(label:'MANIFEST.MF', icon:icon, tip:"Location: $entry.uri.path"))
}

static class TreeNode extends FileTreeNodeFactoryProvider.TreeNode implements PageCreator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@

package jd.gui.service.treenode

import javax.swing.ImageIcon
import java.util.regex.Pattern

class MetainfDirectoryTreeNodeFactoryProvider extends DirectoryTreeNodeFactoryProvider {
Pattern pattern = ~/META-IN(F|F\/.*)/
static final ImageIcon icon = new ImageIcon(MetainfDirectoryTreeNodeFactoryProvider.class.classLoader.getResource('images/inf_obj.png'))

String[] getTypes() { ['jar:dir:*'] }
Pattern pattern = ~/(WEB-INF|(WEB-INF\/classes\/)?META-IN(F|F\/.*))/

String[] getTypes() { ['jar:dir:*', 'war:dir:*'] }

Pattern getPathPattern() { pattern }

ImageIcon getIcon() { icon }
ImageIcon getOpenIcon() { null }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TextFileTreeNodeFactoryProvider extends FileTreeNodeFactoryProvider {
Theme.load(TextFileTreeNodeFactoryProvider.class.classLoader.getResourceAsStream('rsyntaxtextarea/themes/eclipse.xml'))
}

String[] getTypes() { ['*:file:*.txt'] }
String[] getTypes() { ['*:file:*.txt', '*:file:*.md', '*:file:*.SF', '*:file:*.policy'] }

public <T extends DefaultMutableTreeNode & UriGettable> T make(API api, Container.Entry entry) {
int lastSlashIndex = entry.path.lastIndexOf('/')
Expand Down
Loading

0 comments on commit 5f8b151

Please sign in to comment.