Skip to content

Commit b4b8ec8

Browse files
author
emmanue1
committed
Update AAR and JMOD files support
1 parent db6ba80 commit b4b8ec8

14 files changed

+86
-74
lines changed

app/src/main/java/org/jd/gui/service/treenode/TreeNodeFactoryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class TreeNodeFactoryService {
1919

2020
public static TreeNodeFactoryService getInstance() { return TREE_NODE_FACTORY_SERVICE; }
2121

22-
protected HashMap<String, TreeNodeFactories> mapProviders = new HashMap<>();
22+
protected HashMap<String, TreeNodeFactories> mapProviders = new HashMap<>();
2323

2424
protected TreeNodeFactoryService() {
2525
Collection<TreeNodeFactory> providers = ExtensionService.getInstance().load(TreeNodeFactory.class);

services/src/main/java/org/jd/gui/model/container/GenericContainer.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,7 @@ protected Collection<Container.Entry> loadChildrenFromDirectoryEntry() throws IO
152152

153153
for (Path subPath : stream) {
154154
if (subPath.getNameCount() > parentNameCount) {
155-
ContainerFactory containerFactory = api.getContainerFactory(subPath);
156-
157-
if ((containerFactory == null) || "generic".equals(containerFactory.getType())) {
158-
children.add(newChildEntry(subPath));
159-
} else {
160-
Entry childEntry = newChildEntry(subPath);
161-
Container container = containerFactory.make(api, childEntry, subPath);
162-
163-
if (container != null) {
164-
childEntry.children = container.getRoot().getChildren();
165-
}
166-
167-
children.add(childEntry);
168-
}
155+
children.add(newChildEntry(subPath));
169156
}
170157
}
171158

services/src/main/java/org/jd/gui/model/container/JmodClassesDirectoryContainer.java renamed to services/src/main/java/org/jd/gui/model/container/JmodContainer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
import java.nio.file.Path;
1414

15-
public class JmodClassesDirectoryContainer extends GenericContainer {
16-
public JmodClassesDirectoryContainer(API api, Container.Entry parentEntry, Path rootPath) {
15+
public class JmodContainer extends GenericContainer {
16+
public JmodContainer(API api, Container.Entry parentEntry, Path rootPath) {
1717
super(api, parentEntry, rootPath);
1818
}
1919

20-
public String getType() { return "jmodClassesDirectory"; }
20+
public String getType() { return "jmod"; }
2121
}

services/src/main/java/org/jd/gui/service/container/JmodClassesDirectoryContainerFactoryProvider.java

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2008-2019 Emmanuel Dupuy.
3+
* This project is distributed under the GPLv3 license.
4+
* This is a Copyleft license that gives the user the right to use,
5+
* copy and modify the code freely for non-commercial purposes.
6+
*/
7+
8+
package org.jd.gui.service.container;
9+
10+
import org.jd.gui.api.API;
11+
import org.jd.gui.api.model.Container;
12+
import org.jd.gui.model.container.JmodContainer;
13+
import org.jd.gui.spi.ContainerFactory;
14+
import org.jd.gui.util.exception.ExceptionUtil;
15+
16+
import java.nio.file.Files;
17+
import java.nio.file.InvalidPathException;
18+
import java.nio.file.Path;
19+
20+
public class JmodContainerFactoryProvider implements ContainerFactory {
21+
@Override
22+
public String getType() { return "jmod"; }
23+
24+
@Override
25+
public boolean accept(API api, Path rootPath) {
26+
if (rootPath.toUri().toString().toLowerCase().endsWith(".jmod!/")) {
27+
return true;
28+
} else {
29+
// Extension: accept uncompressed WAR file containing a folder 'WEB-INF'
30+
try {
31+
return rootPath.getFileSystem().provider().getScheme().equals("file") && Files.exists(rootPath.resolve("classes"));
32+
} catch (InvalidPathException e) {
33+
assert ExceptionUtil.printStackTrace(e);
34+
return false;
35+
}
36+
}
37+
}
38+
39+
@Override
40+
public Container make(API api, Container.Entry parentEntry, Path rootPath) {
41+
return new JmodContainer(api, parentEntry, rootPath);
42+
}
43+
}

services/src/main/java/org/jd/gui/service/treenode/WebinfClassesDirectoryTreeNodeFactoryProvider.java renamed to services/src/main/java/org/jd/gui/service/treenode/ClassesDirectoryTreeNodeFactoryProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
import javax.swing.*;
1111

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

15-
@Override public String[] getSelectors() { return appendSelectors("war:dir:WEB-INF/classes"); }
15+
@Override public String[] getSelectors() { return appendSelectors("war:dir:WEB-INF/classes", "jmod:dir:classes"); }
1616
@Override public ImageIcon getIcon() { return ICON; }
1717
@Override public ImageIcon getOpenIcon() { return null; }
1818
}

services/src/main/java/org/jd/gui/service/treenode/EarFileTreeNodeFactoryProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable>
2828
int lastSlashIndex = entry.getPath().lastIndexOf("/");
2929
String label = entry.getPath().substring(lastSlashIndex+1);
3030
String location = new File(entry.getUri()).getPath();
31-
T node = (T)new TreeNode(entry, "ear", new TreeNodeBean(label, "Location: " + location, ICON));
31+
T node = (T)new TreeNode(entry, new TreeNodeBean(label, "Location: " + location, ICON));
3232
// Add dummy node
3333
node.add(new DefaultMutableTreeNode());
3434
return node;

services/src/main/java/org/jd/gui/service/treenode/JarFileTreeNodeFactoryProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable>
3232
String label = entry.getPath().substring(lastSlashIndex+1);
3333
String location = new File(entry.getUri()).getPath();
3434
ImageIcon icon = isAEjbModule(entry) ? EJB_FILE_ICON : JAR_FILE_ICON;
35-
T node = (T)new TreeNode(entry, "jar", new TreeNodeBean(label, "Location: " + location, icon));
35+
T node = (T)new TreeNode(entry, new TreeNodeBean(label, "Location: " + location, icon));
3636
// Add dummy node
3737
node.add(new DefaultMutableTreeNode());
3838
return node;
@@ -66,8 +66,8 @@ protected static boolean isAEjbModule(Container.Entry entry) {
6666
}
6767

6868
protected static class TreeNode extends ZipFileTreeNodeFactoryProvider.TreeNode {
69-
public TreeNode(Container.Entry entry, String containerType, Object userObject) {
70-
super(entry, containerType, userObject);
69+
public TreeNode(Container.Entry entry, Object userObject) {
70+
super(entry, userObject);
7171
}
7272

7373
@Override

services/src/main/java/org/jd/gui/service/treenode/JmodFileTreeNodeFactoryProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable>
2525
int lastSlashIndex = entry.getPath().lastIndexOf("/");
2626
String label = entry.getPath().substring(lastSlashIndex+1);
2727
String location = new File(entry.getUri()).getPath();
28-
T node = (T)new TreeNode(entry, "generic", new TreeNodeBean(label, "Location: " + location, ICON));
28+
T node = (T)new TreeNode(entry, new TreeNodeBean(label, "Location: " + location, ICON));
2929
// Add dummy node
3030
node.add(new DefaultMutableTreeNode());
3131
return node;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2008-2019 Emmanuel Dupuy.
3+
* This project is distributed under the GPLv3 license.
4+
* This is a Copyleft license that gives the user the right to use,
5+
* copy and modify the code freely for non-commercial purposes.
6+
*/
7+
8+
package org.jd.gui.service.treenode;
9+
10+
import java.util.regex.Pattern;
11+
12+
public class JmodPackageTreeNodeFactoryProvider extends PackageTreeNodeFactoryProvider {
13+
14+
@Override public String[] getSelectors() { return appendSelectors("jmod:dir:*"); }
15+
16+
@Override
17+
public Pattern getPathPattern() {
18+
if (externalPathPattern == null) {
19+
return Pattern.compile("classes\\/.*");
20+
} else {
21+
return externalPathPattern;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)