diff --git a/app/src/main/java/org/jd/gui/service/treenode/TreeNodeFactoryService.java b/app/src/main/java/org/jd/gui/service/treenode/TreeNodeFactoryService.java index ffde27b7..49c3514d 100644 --- a/app/src/main/java/org/jd/gui/service/treenode/TreeNodeFactoryService.java +++ b/app/src/main/java/org/jd/gui/service/treenode/TreeNodeFactoryService.java @@ -19,7 +19,7 @@ public class TreeNodeFactoryService { public static TreeNodeFactoryService getInstance() { return TREE_NODE_FACTORY_SERVICE; } - protected HashMap mapProviders = new HashMap<>(); + protected HashMap mapProviders = new HashMap<>(); protected TreeNodeFactoryService() { Collection providers = ExtensionService.getInstance().load(TreeNodeFactory.class); diff --git a/services/src/main/java/org/jd/gui/model/container/GenericContainer.java b/services/src/main/java/org/jd/gui/model/container/GenericContainer.java index ecad83d7..3477eabb 100644 --- a/services/src/main/java/org/jd/gui/model/container/GenericContainer.java +++ b/services/src/main/java/org/jd/gui/model/container/GenericContainer.java @@ -152,20 +152,7 @@ protected Collection 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)); } } diff --git a/services/src/main/java/org/jd/gui/model/container/JmodClassesDirectoryContainer.java b/services/src/main/java/org/jd/gui/model/container/JmodContainer.java similarity index 64% rename from services/src/main/java/org/jd/gui/model/container/JmodClassesDirectoryContainer.java rename to services/src/main/java/org/jd/gui/model/container/JmodContainer.java index 22d7f74e..4d274979 100644 --- a/services/src/main/java/org/jd/gui/model/container/JmodClassesDirectoryContainer.java +++ b/services/src/main/java/org/jd/gui/model/container/JmodContainer.java @@ -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"; } } diff --git a/services/src/main/java/org/jd/gui/service/container/JmodClassesDirectoryContainerFactoryProvider.java b/services/src/main/java/org/jd/gui/service/container/JmodClassesDirectoryContainerFactoryProvider.java deleted file mode 100644 index 5ccf8589..00000000 --- a/services/src/main/java/org/jd/gui/service/container/JmodClassesDirectoryContainerFactoryProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.JmodClassesDirectoryContainer; -import org.jd.gui.spi.ContainerFactory; - -import java.nio.file.Files; -import java.nio.file.Path; - -public class JmodClassesDirectoryContainerFactoryProvider implements ContainerFactory { - @Override - public String getType() { return "jmodClassesDirectory"; } - - @Override - public boolean accept(API api, Path rootPath) { - if (Files.isDirectory(rootPath)) { - Path fileName = rootPath.getFileName(); - - if ((fileName != null) && "classes".equals(rootPath.getFileName().toString())) { - String fileStoreName = rootPath.getFileSystem().getFileStores().iterator().next().name(); - return fileStoreName.endsWith(".jmod/"); - } - } - - return false; - } - - @Override - public Container make(API api, Container.Entry parentEntry, Path rootPath) { - return new JmodClassesDirectoryContainer(api, parentEntry, rootPath); - } -} diff --git a/services/src/main/java/org/jd/gui/service/container/JmodContainerFactoryProvider.java b/services/src/main/java/org/jd/gui/service/container/JmodContainerFactoryProvider.java new file mode 100644 index 00000000..544a3e30 --- /dev/null +++ b/services/src/main/java/org/jd/gui/service/container/JmodContainerFactoryProvider.java @@ -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); + } +} diff --git a/services/src/main/java/org/jd/gui/service/treenode/WebinfClassesDirectoryTreeNodeFactoryProvider.java b/services/src/main/java/org/jd/gui/service/treenode/ClassesDirectoryTreeNodeFactoryProvider.java similarity index 59% rename from services/src/main/java/org/jd/gui/service/treenode/WebinfClassesDirectoryTreeNodeFactoryProvider.java rename to services/src/main/java/org/jd/gui/service/treenode/ClassesDirectoryTreeNodeFactoryProvider.java index ee635dad..f5d91511 100644 --- a/services/src/main/java/org/jd/gui/service/treenode/WebinfClassesDirectoryTreeNodeFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/treenode/ClassesDirectoryTreeNodeFactoryProvider.java @@ -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; } } diff --git a/services/src/main/java/org/jd/gui/service/treenode/EarFileTreeNodeFactoryProvider.java b/services/src/main/java/org/jd/gui/service/treenode/EarFileTreeNodeFactoryProvider.java index c1f06134..a1c0f90f 100644 --- a/services/src/main/java/org/jd/gui/service/treenode/EarFileTreeNodeFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/treenode/EarFileTreeNodeFactoryProvider.java @@ -28,7 +28,7 @@ public 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; diff --git a/services/src/main/java/org/jd/gui/service/treenode/JarFileTreeNodeFactoryProvider.java b/services/src/main/java/org/jd/gui/service/treenode/JarFileTreeNodeFactoryProvider.java index 6f5c1f72..027810d5 100644 --- a/services/src/main/java/org/jd/gui/service/treenode/JarFileTreeNodeFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/treenode/JarFileTreeNodeFactoryProvider.java @@ -32,7 +32,7 @@ public 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; @@ -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 diff --git a/services/src/main/java/org/jd/gui/service/treenode/JmodFileTreeNodeFactoryProvider.java b/services/src/main/java/org/jd/gui/service/treenode/JmodFileTreeNodeFactoryProvider.java index 66e1283b..c51cb461 100644 --- a/services/src/main/java/org/jd/gui/service/treenode/JmodFileTreeNodeFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/treenode/JmodFileTreeNodeFactoryProvider.java @@ -25,7 +25,7 @@ public 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; diff --git a/services/src/main/java/org/jd/gui/service/treenode/JmodPackageTreeNodeFactoryProvider.java b/services/src/main/java/org/jd/gui/service/treenode/JmodPackageTreeNodeFactoryProvider.java new file mode 100644 index 00000000..4456cdf8 --- /dev/null +++ b/services/src/main/java/org/jd/gui/service/treenode/JmodPackageTreeNodeFactoryProvider.java @@ -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; + } + } +} diff --git a/services/src/main/java/org/jd/gui/service/treenode/WarFileTreeNodeFactoryProvider.java b/services/src/main/java/org/jd/gui/service/treenode/WarFileTreeNodeFactoryProvider.java index 0af36376..57e80945 100644 --- a/services/src/main/java/org/jd/gui/service/treenode/WarFileTreeNodeFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/treenode/WarFileTreeNodeFactoryProvider.java @@ -28,7 +28,7 @@ public 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; diff --git a/services/src/main/java/org/jd/gui/service/treenode/ZipFileTreeNodeFactoryProvider.java b/services/src/main/java/org/jd/gui/service/treenode/ZipFileTreeNodeFactoryProvider.java index ee1917f2..204e79c1 100644 --- a/services/src/main/java/org/jd/gui/service/treenode/ZipFileTreeNodeFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/treenode/ZipFileTreeNodeFactoryProvider.java @@ -29,18 +29,15 @@ public 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 --- // diff --git a/services/src/main/resources/META-INF/services/org.jd.gui.spi.ContainerFactory b/services/src/main/resources/META-INF/services/org.jd.gui.spi.ContainerFactory index c8d094e5..f8a5ecc5 100644 --- a/services/src/main/resources/META-INF/services/org.jd.gui.spi.ContainerFactory +++ b/services/src/main/resources/META-INF/services/org.jd.gui.spi.ContainerFactory @@ -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 diff --git a/services/src/main/resources/META-INF/services/org.jd.gui.spi.TreeNodeFactory b/services/src/main/resources/META-INF/services/org.jd.gui.spi.TreeNodeFactory index d15d20dd..2c641d42 100644 --- a/services/src/main/resources/META-INF/services/org.jd.gui.spi.TreeNodeFactory +++ b/services/src/main/resources/META-INF/services/org.jd.gui.spi.TreeNodeFactory @@ -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 @@ -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 @@ -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