Skip to content

Commit

Permalink
Update AAR and JMOD files support
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanue1 committed May 31, 2019
1 parent db6ba80 commit b4b8ec8
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TreeNodeFactoryService {

public static TreeNodeFactoryService getInstance() { return TREE_NODE_FACTORY_SERVICE; }

protected HashMap<String, TreeNodeFactories> mapProviders = new HashMap<>();
protected HashMap<String, TreeNodeFactories> mapProviders = new HashMap<>();

protected TreeNodeFactoryService() {
Collection<TreeNodeFactory> providers = ExtensionService.getInstance().load(TreeNodeFactory.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,7 @@ protected Collection<Container.Entry> loadChildrenFromDirectoryEntry() throws IO

for (Path subPath : stream) {
if (subPath.getNameCount() > parentNameCount) {
ContainerFactory containerFactory = api.getContainerFactory(subPath);

if ((containerFactory == null) || "generic".equals(containerFactory.getType())) {
children.add(newChildEntry(subPath));
} else {
Entry childEntry = newChildEntry(subPath);
Container container = containerFactory.make(api, childEntry, subPath);

if (container != null) {
childEntry.children = container.getRoot().getChildren();
}

children.add(childEntry);
}
children.add(newChildEntry(subPath));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

import java.nio.file.Path;

public class JmodClassesDirectoryContainer extends GenericContainer {
public JmodClassesDirectoryContainer(API api, Container.Entry parentEntry, Path rootPath) {
public class JmodContainer extends GenericContainer {
public JmodContainer(API api, Container.Entry parentEntry, Path rootPath) {
super(api, parentEntry, rootPath);
}

public String getType() { return "jmodClassesDirectory"; }
public String getType() { return "jmod"; }
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2008-2019 Emmanuel Dupuy.
* This project is distributed under the GPLv3 license.
* This is a Copyleft license that gives the user the right to use,
* copy and modify the code freely for non-commercial purposes.
*/

package org.jd.gui.service.container;

import org.jd.gui.api.API;
import org.jd.gui.api.model.Container;
import org.jd.gui.model.container.JmodContainer;
import org.jd.gui.spi.ContainerFactory;
import org.jd.gui.util.exception.ExceptionUtil;

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

public class JmodContainerFactoryProvider implements ContainerFactory {
@Override
public String getType() { return "jmod"; }

@Override
public boolean accept(API api, Path rootPath) {
if (rootPath.toUri().toString().toLowerCase().endsWith(".jmod!/")) {
return true;
} else {
// Extension: accept uncompressed WAR file containing a folder 'WEB-INF'
try {
return rootPath.getFileSystem().provider().getScheme().equals("file") && Files.exists(rootPath.resolve("classes"));
} catch (InvalidPathException e) {
assert ExceptionUtil.printStackTrace(e);
return false;
}
}
}

@Override
public Container make(API api, Container.Entry parentEntry, Path rootPath) {
return new JmodContainer(api, parentEntry, rootPath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

import javax.swing.*;

public class WebinfClassesDirectoryTreeNodeFactoryProvider extends DirectoryTreeNodeFactoryProvider {
protected static final ImageIcon ICON = new ImageIcon(WebinfClassesDirectoryTreeNodeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/packagefolder_obj.png"));
public class ClassesDirectoryTreeNodeFactoryProvider extends DirectoryTreeNodeFactoryProvider {
protected static final ImageIcon ICON = new ImageIcon(ClassesDirectoryTreeNodeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/packagefolder_obj.png"));

@Override public String[] getSelectors() { return appendSelectors("war:dir:WEB-INF/classes"); }
@Override public String[] getSelectors() { return appendSelectors("war:dir:WEB-INF/classes", "jmod:dir:classes"); }
@Override public ImageIcon getIcon() { return ICON; }
@Override public ImageIcon getOpenIcon() { return null; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable>
int lastSlashIndex = entry.getPath().lastIndexOf("/");
String label = entry.getPath().substring(lastSlashIndex+1);
String location = new File(entry.getUri()).getPath();
T node = (T)new TreeNode(entry, "ear", new TreeNodeBean(label, "Location: " + location, ICON));
T node = (T)new TreeNode(entry, new TreeNodeBean(label, "Location: " + location, ICON));
// Add dummy node
node.add(new DefaultMutableTreeNode());
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable>
String label = entry.getPath().substring(lastSlashIndex+1);
String location = new File(entry.getUri()).getPath();
ImageIcon icon = isAEjbModule(entry) ? EJB_FILE_ICON : JAR_FILE_ICON;
T node = (T)new TreeNode(entry, "jar", new TreeNodeBean(label, "Location: " + location, icon));
T node = (T)new TreeNode(entry, new TreeNodeBean(label, "Location: " + location, icon));
// Add dummy node
node.add(new DefaultMutableTreeNode());
return node;
Expand Down Expand Up @@ -66,8 +66,8 @@ protected static boolean isAEjbModule(Container.Entry entry) {
}

protected static class TreeNode extends ZipFileTreeNodeFactoryProvider.TreeNode {
public TreeNode(Container.Entry entry, String containerType, Object userObject) {
super(entry, containerType, userObject);
public TreeNode(Container.Entry entry, Object userObject) {
super(entry, userObject);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable>
int lastSlashIndex = entry.getPath().lastIndexOf("/");
String label = entry.getPath().substring(lastSlashIndex+1);
String location = new File(entry.getUri()).getPath();
T node = (T)new TreeNode(entry, "generic", new TreeNodeBean(label, "Location: " + location, ICON));
T node = (T)new TreeNode(entry, new TreeNodeBean(label, "Location: " + location, ICON));
// Add dummy node
node.add(new DefaultMutableTreeNode());
return node;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2008-2019 Emmanuel Dupuy.
* This project is distributed under the GPLv3 license.
* This is a Copyleft license that gives the user the right to use,
* copy and modify the code freely for non-commercial purposes.
*/

package org.jd.gui.service.treenode;

import java.util.regex.Pattern;

public class JmodPackageTreeNodeFactoryProvider extends PackageTreeNodeFactoryProvider {

@Override public String[] getSelectors() { return appendSelectors("jmod:dir:*"); }

@Override
public Pattern getPathPattern() {
if (externalPathPattern == null) {
return Pattern.compile("classes\\/.*");
} else {
return externalPathPattern;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable>
int lastSlashIndex = entry.getPath().lastIndexOf("/");
String label = entry.getPath().substring(lastSlashIndex+1);
String location = new File(entry.getUri()).getPath();
T node = (T)new TreeNode(entry, "war", new TreeNodeBean(label, "Location: " + location, ICON));
T node = (T)new TreeNode(entry, new TreeNodeBean(label, "Location: " + location, ICON));
// Add dummy node
node.add(new DefaultMutableTreeNode());
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@ public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable>
int lastSlashIndex = entry.getPath().lastIndexOf("/");
String label = entry.getPath().substring(lastSlashIndex+1);
String location = new File(entry.getUri()).getPath();
T node = (T)new TreeNode(entry, "generic", new TreeNodeBean(label, "Location: " + location, ICON));
T node = (T)new TreeNode(entry, new TreeNodeBean(label, "Location: " + location, ICON));
// Add dummy node
node.add(new DefaultMutableTreeNode());
return node;
}

protected static class TreeNode extends DirectoryTreeNodeFactoryProvider.TreeNode {
protected String ct;

public TreeNode(Container.Entry entry, String containerType, Object userObject) {
public TreeNode(Container.Entry entry, Object userObject) {
super(entry, userObject);
ct = containerType;
}

// --- TreeNodeExpandable --- //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Order is important : 'GenericContainerFactoryProvider' must be the last
org.jd.gui.service.container.JmodClassesDirectoryContainerFactoryProvider
org.jd.gui.service.container.JmodContainerFactoryProvider
org.jd.gui.service.container.EarContainerFactoryProvider
org.jd.gui.service.container.WarContainerFactoryProvider
org.jd.gui.service.container.JarContainerFactoryProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.jd.gui.service.treenode.ClassesDirectoryTreeNodeFactoryProvider
org.jd.gui.service.treenode.ClassFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.CssFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.DirectoryTreeNodeFactoryProvider
Expand All @@ -10,6 +11,7 @@ org.jd.gui.service.treenode.JarFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.JavaFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.JavascriptFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.JmodFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.JmodPackageTreeNodeFactoryProvider
org.jd.gui.service.treenode.JsonFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.JspFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.ManifestFileTreeNodeFactoryProvider
Expand All @@ -21,7 +23,6 @@ org.jd.gui.service.treenode.SqlFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.TextFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.WarFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.WarPackageTreeNodeFactoryProvider
org.jd.gui.service.treenode.WebinfClassesDirectoryTreeNodeFactoryProvider
org.jd.gui.service.treenode.WebinfLibDirectoryTreeNodeFactoryProvider
org.jd.gui.service.treenode.WebXmlFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.XmlBasedFileTreeNodeFactoryProvider
Expand Down

0 comments on commit b4b8ec8

Please sign in to comment.