From cb8de5579ddc1dad1d0d6420736266818a160338 Mon Sep 17 00:00:00 2001 From: emmanue1 Date: Thu, 30 May 2019 22:18:49 +0200 Subject: [PATCH] Add AAR and JMOD files support --- .../java/org/jd/gui/spi/ContainerFactory.java | 10 ++--- .../service/fileloader/FileLoaderService.java | 17 +++----- .../service/uriloader/UriLoaderService.java | 4 +- .../gui/model/container/GenericContainer.java | 15 ++++++- .../JmodClassesDirectoryContainer.java | 21 ++++++++++ .../EarContainerFactoryProvider.java | 4 +- .../GenericContainerFactoryProvider.java | 14 ++++--- .../JarContainerFactoryProvider.java | 8 ++-- ...ssesDirectoryContainerFactoryProvider.java | 40 ++++++++++++++++++ .../WarContainerFactoryProvider.java | 4 +- .../fileloader/AarFileLoaderProvider.java | 24 +++++++++++ .../AbstractFileLoaderProvider.java | 19 +++++---- .../fileloader/ClassFileLoaderProvider.java | 10 +++-- .../fileloader/EarFileLoaderProvider.java | 7 ++-- .../fileloader/JarFileLoaderProvider.java | 13 +++--- .../fileloader/JavaFileLoaderProvider.java | 8 ++-- .../fileloader/JmodFileLoaderProvider.java | 24 +++++++++++ .../fileloader/LogFileLoaderProvider.java | 8 ++-- .../fileloader/WarFileLoaderProvider.java | 7 ++-- .../fileloader/ZipFileLoaderProvider.java | 10 +++-- .../indexer/ZipFileIndexerProvider.java | 2 +- .../ZipFileSourceSaverProvider.java | 2 +- .../JmodFileTreeNodeFactoryProvider.java | 42 +++++++++++++++++++ .../PackageTreeNodeFactoryProvider.java | 2 +- .../TextFileTreeNodeFactoryProvider.java | 4 +- .../ZipFileTreeNodeFactoryProvider.java | 6 +-- .../uriloader/FileUriLoaderProvider.java | 12 +++--- .../services/org.jd.gui.spi.ContainerFactory | 3 +- .../services/org.jd.gui.spi.FileLoader | 2 + .../services/org.jd.gui.spi.TreeNodeFactory | 1 + 30 files changed, 264 insertions(+), 79 deletions(-) create mode 100644 services/src/main/java/org/jd/gui/model/container/JmodClassesDirectoryContainer.java create mode 100644 services/src/main/java/org/jd/gui/service/container/JmodClassesDirectoryContainerFactoryProvider.java create mode 100644 services/src/main/java/org/jd/gui/service/fileloader/AarFileLoaderProvider.java create mode 100644 services/src/main/java/org/jd/gui/service/fileloader/JmodFileLoaderProvider.java create mode 100644 services/src/main/java/org/jd/gui/service/treenode/JmodFileTreeNodeFactoryProvider.java diff --git a/api/src/main/java/org/jd/gui/spi/ContainerFactory.java b/api/src/main/java/org/jd/gui/spi/ContainerFactory.java index d1e8bc5..bb5f227 100644 --- a/api/src/main/java/org/jd/gui/spi/ContainerFactory.java +++ b/api/src/main/java/org/jd/gui/spi/ContainerFactory.java @@ -13,9 +13,9 @@ import org.jd.gui.api.model.Container; import java.nio.file.Path; public interface ContainerFactory { - String getType(); - - boolean accept(API api, Path rootPath); - - Container make(API api, Container.Entry parentEntry, Path rootPath); + String getType(); + + boolean accept(API api, Path rootPath); + + Container make(API api, Container.Entry parentEntry, Path rootPath); } diff --git a/app/src/main/java/org/jd/gui/service/fileloader/FileLoaderService.java b/app/src/main/java/org/jd/gui/service/fileloader/FileLoaderService.java index 148d30c..dc2e401 100644 --- a/app/src/main/java/org/jd/gui/service/fileloader/FileLoaderService.java +++ b/app/src/main/java/org/jd/gui/service/fileloader/FileLoaderService.java @@ -21,12 +21,12 @@ public class FileLoaderService { public static FileLoaderService getInstance() { return FILE_LOADER_SERVICE; } protected final Collection providers = ExtensionService.getInstance().load(FileLoader.class); - - protected HashMap mapProviders = new HashMap<>(); - protected FileLoaderService() { - for (FileLoader provider : providers) { - for (String extension : provider.getExtensions()) { + protected HashMap mapProviders = new HashMap<>(); + + protected FileLoaderService() { + for (FileLoader provider : providers) { + for (String extension : provider.getExtensions()) { mapProviders.put(extension, provider); } } @@ -37,12 +37,7 @@ public class FileLoaderService { int lastDot = name.lastIndexOf('.'); String extension = name.substring(lastDot+1); FileLoader provider = mapProviders.get(extension); - - if ((provider != null) && provider.accept(api, file)) { - return provider; - } - - return null; + return provider; } public HashMap getMapProviders() { diff --git a/app/src/main/java/org/jd/gui/service/uriloader/UriLoaderService.java b/app/src/main/java/org/jd/gui/service/uriloader/UriLoaderService.java index 980e862..115536d 100644 --- a/app/src/main/java/org/jd/gui/service/uriloader/UriLoaderService.java +++ b/app/src/main/java/org/jd/gui/service/uriloader/UriLoaderService.java @@ -20,9 +20,9 @@ public class UriLoaderService { public static UriLoaderService getInstance() { return URI_LOADER_SERVICE; } - protected HashMap mapProviders = new HashMap<>(); + protected HashMap mapProviders = new HashMap<>(); - protected UriLoaderService() { + protected UriLoaderService() { Collection providers = ExtensionService.getInstance().load(UriLoader.class); for (UriLoader provider : providers) { 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 dfaa24f..d327b84 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 @@ -147,7 +147,20 @@ public class GenericContainer implements Container { for (Path subPath : stream) { if (subPath.getNameCount() > parentNameCount) { - children.add(newChildEntry(subPath)); + 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); + } } } diff --git a/services/src/main/java/org/jd/gui/model/container/JmodClassesDirectoryContainer.java b/services/src/main/java/org/jd/gui/model/container/JmodClassesDirectoryContainer.java new file mode 100644 index 0000000..22d7f74 --- /dev/null +++ b/services/src/main/java/org/jd/gui/model/container/JmodClassesDirectoryContainer.java @@ -0,0 +1,21 @@ +/* + * 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.model.container; + +import org.jd.gui.api.API; +import org.jd.gui.api.model.Container; + +import java.nio.file.Path; + +public class JmodClassesDirectoryContainer extends GenericContainer { + public JmodClassesDirectoryContainer(API api, Container.Entry parentEntry, Path rootPath) { + super(api, parentEntry, rootPath); + } + + public String getType() { return "jmodClassesDirectory"; } +} diff --git a/services/src/main/java/org/jd/gui/service/container/EarContainerFactoryProvider.java b/services/src/main/java/org/jd/gui/service/container/EarContainerFactoryProvider.java index aee610c..f7bc3ae 100644 --- a/services/src/main/java/org/jd/gui/service/container/EarContainerFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/container/EarContainerFactoryProvider.java @@ -18,9 +18,10 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; public class EarContainerFactoryProvider implements ContainerFactory { - + @Override public String getType() { return "ear"; } + @Override public boolean accept(API api, Path rootPath) { if (rootPath.toUri().toString().toLowerCase().endsWith(".ear!/")) { return true; @@ -35,6 +36,7 @@ public class EarContainerFactoryProvider implements ContainerFactory { } } + @Override public Container make(API api, Container.Entry parentEntry, Path rootPath) { return new EarContainer(api, parentEntry, rootPath); } diff --git a/services/src/main/java/org/jd/gui/service/container/GenericContainerFactoryProvider.java b/services/src/main/java/org/jd/gui/service/container/GenericContainerFactoryProvider.java index 45e3ecd..bb3faec 100644 --- a/services/src/main/java/org/jd/gui/service/container/GenericContainerFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/container/GenericContainerFactoryProvider.java @@ -15,12 +15,14 @@ import org.jd.gui.spi.ContainerFactory; import java.nio.file.Path; public class GenericContainerFactoryProvider implements ContainerFactory { + @Override + public String getType() { return "generic"; } - public String getType() { return "generic"; } + @Override + public boolean accept(API api, Path rootPath) { return true; } - public boolean accept(API api, Path rootPath) { return true; } - - public Container make(API api, Container.Entry parentEntry, Path rootPath) { - return new GenericContainer(api, parentEntry, rootPath); - } + @Override + public Container make(API api, Container.Entry parentEntry, Path rootPath) { + return new GenericContainer(api, parentEntry, rootPath); + } } diff --git a/services/src/main/java/org/jd/gui/service/container/JarContainerFactoryProvider.java b/services/src/main/java/org/jd/gui/service/container/JarContainerFactoryProvider.java index fb9eb2a..d078403 100644 --- a/services/src/main/java/org/jd/gui/service/container/JarContainerFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/container/JarContainerFactoryProvider.java @@ -18,9 +18,10 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; public class JarContainerFactoryProvider implements ContainerFactory { - + @Override public String getType() { return "jar"; } + @Override public 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 @@ -36,7 +37,8 @@ public class JarContainerFactoryProvider implements ContainerFactory { } } + @Override public Container make(API api, Container.Entry parentEntry, Path rootPath) { - return new JarContainer(api, parentEntry, rootPath); - } + return new JarContainer(api, parentEntry, rootPath); + } } 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 new file mode 100644 index 0000000..5ccf858 --- /dev/null +++ b/services/src/main/java/org/jd/gui/service/container/JmodClassesDirectoryContainerFactoryProvider.java @@ -0,0 +1,40 @@ +/* + * 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/WarContainerFactoryProvider.java b/services/src/main/java/org/jd/gui/service/container/WarContainerFactoryProvider.java index e57cced..5b5bec2 100644 --- a/services/src/main/java/org/jd/gui/service/container/WarContainerFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/container/WarContainerFactoryProvider.java @@ -18,9 +18,10 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; public class WarContainerFactoryProvider implements ContainerFactory { - + @Override public String getType() { return "war"; } + @Override public boolean accept(API api, Path rootPath) { if (rootPath.toUri().toString().toLowerCase().endsWith(".war!/")) { return true; @@ -35,6 +36,7 @@ public class WarContainerFactoryProvider implements ContainerFactory { } } + @Override public Container make(API api, Container.Entry parentEntry, Path rootPath) { return new WarContainer(api, parentEntry, rootPath); } diff --git a/services/src/main/java/org/jd/gui/service/fileloader/AarFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/AarFileLoaderProvider.java new file mode 100644 index 0000000..cce4ea1 --- /dev/null +++ b/services/src/main/java/org/jd/gui/service/fileloader/AarFileLoaderProvider.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.fileloader; + +import org.jd.gui.api.API; + +import java.io.File; + +public class AarFileLoaderProvider extends ZipFileLoaderProvider { + protected static final String[] EXTENSIONS = { "aar" }; + + @Override public String[] getExtensions() { return EXTENSIONS; } + @Override public String getDescription() { return "Android archive files (*.aar)"; } + + @Override + public boolean accept(API api, File file) { + return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".aar"); + } +} diff --git a/services/src/main/java/org/jd/gui/service/fileloader/AbstractFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/AbstractFileLoaderProvider.java index 43fdc09..5c71870 100644 --- a/services/src/main/java/org/jd/gui/service/fileloader/AbstractFileLoaderProvider.java +++ b/services/src/main/java/org/jd/gui/service/fileloader/AbstractFileLoaderProvider.java @@ -57,8 +57,8 @@ public abstract class AbstractFileLoaderProvider implements FileLoader { protected static class ContainerEntry implements Container.Entry { protected static final Container PARENT_CONTAINER = new Container() { - public String getType() { return "generic"; } - public Container.Entry getRoot() { return null; } + @Override public String getType() { return "generic"; } + @Override public Container.Entry getRoot() { return null; } }; protected Collection children = Collections.emptyList(); @@ -76,14 +76,15 @@ public abstract class AbstractFileLoaderProvider implements FileLoader { } } - public Container getContainer() { return PARENT_CONTAINER; } - public Container.Entry getParent() { return null; } - public URI getUri() { return uri; } - public String getPath() { return path; } - public boolean isDirectory() { return file.isDirectory(); } - public long length() { return file.length(); } - public Collection getChildren() { return children; } + @Override public Container getContainer() { return PARENT_CONTAINER; } + @Override public Container.Entry getParent() { return null; } + @Override public URI getUri() { return uri; } + @Override public String getPath() { return path; } + @Override public boolean isDirectory() { return file.isDirectory(); } + @Override public long length() { return file.length(); } + @Override public Collection getChildren() { return children; } + @Override public InputStream getInputStream() { try { return new BufferedInputStream(new FileInputStream(file)); diff --git a/services/src/main/java/org/jd/gui/service/fileloader/ClassFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/ClassFileLoaderProvider.java index 08b44e2..68ffdee 100644 --- a/services/src/main/java/org/jd/gui/service/fileloader/ClassFileLoaderProvider.java +++ b/services/src/main/java/org/jd/gui/service/fileloader/ClassFileLoaderProvider.java @@ -18,14 +18,16 @@ import java.io.IOException; public class ClassFileLoaderProvider extends AbstractTypeFileLoaderProvider { protected static final String[] EXTENSIONS = { "class" }; - - public String[] getExtensions() { return EXTENSIONS; } - public String getDescription() { return "Class files (*.class)"; } + @Override public String[] getExtensions() { return EXTENSIONS; } + @Override public String getDescription() { return "Class files (*.class)"; } + + @Override public boolean accept(API api, File file) { - return file.exists() && file.canRead() && file.getName().toLowerCase().endsWith(".class"); + return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".class"); } + @Override public boolean load(API api, File file) { try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) { ClassReader classReader = new ClassReader(bis); diff --git a/services/src/main/java/org/jd/gui/service/fileloader/EarFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/EarFileLoaderProvider.java index 7468614..58bfcf3 100644 --- a/services/src/main/java/org/jd/gui/service/fileloader/EarFileLoaderProvider.java +++ b/services/src/main/java/org/jd/gui/service/fileloader/EarFileLoaderProvider.java @@ -14,10 +14,11 @@ import java.io.File; public class EarFileLoaderProvider extends ZipFileLoaderProvider { protected static final String[] EXTENSIONS = { "ear" }; - public String[] getExtensions() { return EXTENSIONS; } - public String getDescription() { return "Ear files (*.ear)"; } + @Override public String[] getExtensions() { return EXTENSIONS; } + @Override public String getDescription() { return "Enterprise application archive files (*.ear)"; } + @Override public boolean accept(API api, File file) { - return file.exists() && file.canRead() && file.getName().toLowerCase().endsWith(".ear"); + return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".ear"); } } diff --git a/services/src/main/java/org/jd/gui/service/fileloader/JarFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/JarFileLoaderProvider.java index fa4f592..bf51960 100644 --- a/services/src/main/java/org/jd/gui/service/fileloader/JarFileLoaderProvider.java +++ b/services/src/main/java/org/jd/gui/service/fileloader/JarFileLoaderProvider.java @@ -12,12 +12,13 @@ import org.jd.gui.api.API; import java.io.File; public class JarFileLoaderProvider extends ZipFileLoaderProvider { - protected static final String[] EXTENSIONS = { "jar" }; + protected static final String[] EXTENSIONS = { "jar" }; - public String[] getExtensions() { return EXTENSIONS; } - public String getDescription() { return "Jar files (*.jar)"; } + @Override public String[] getExtensions() { return EXTENSIONS; } + @Override public String getDescription() { return "Java archive files (*.jar)"; } - public boolean accept(API api, File file) { - return file.exists() && file.canRead() && file.getName().toLowerCase().endsWith(".jar"); - } + @Override + public boolean accept(API api, File file) { + return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".jar"); + } } diff --git a/services/src/main/java/org/jd/gui/service/fileloader/JavaFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/JavaFileLoaderProvider.java index a83b0d4..a6411ab 100644 --- a/services/src/main/java/org/jd/gui/service/fileloader/JavaFileLoaderProvider.java +++ b/services/src/main/java/org/jd/gui/service/fileloader/JavaFileLoaderProvider.java @@ -17,13 +17,15 @@ import java.util.regex.Pattern; public class JavaFileLoaderProvider extends AbstractTypeFileLoaderProvider { protected static final String[] EXTENSIONS = { "java" }; - public String[] getExtensions() { return EXTENSIONS; } - public String getDescription() { return "Java files (*.java)"; } + @Override public String[] getExtensions() { return EXTENSIONS; } + @Override public String getDescription() { return "Java files (*.java)"; } + @Override public boolean accept(API api, File file) { - return file.exists() && file.canRead() && file.getName().toLowerCase().endsWith(".java"); + return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".java"); } + @Override public boolean load(API api, File file) { String text = TextReader.getText(file); Pattern pattern = Pattern.compile("(?s)(.*\\s)?package\\s+(\\S+)\\s*;.*"); diff --git a/services/src/main/java/org/jd/gui/service/fileloader/JmodFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/JmodFileLoaderProvider.java new file mode 100644 index 0000000..0b02c60 --- /dev/null +++ b/services/src/main/java/org/jd/gui/service/fileloader/JmodFileLoaderProvider.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.fileloader; + +import org.jd.gui.api.API; + +import java.io.File; + +public class JmodFileLoaderProvider extends ZipFileLoaderProvider { + protected static final String[] EXTENSIONS = { "jmod" }; + + @Override public String[] getExtensions() { return EXTENSIONS; } + @Override public String getDescription() { return "Java module files (*.jmod)"; } + + @Override + public boolean accept(API api, File file) { + return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".jmod"); + } +} diff --git a/services/src/main/java/org/jd/gui/service/fileloader/LogFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/LogFileLoaderProvider.java index 8f3c759..01cd233 100644 --- a/services/src/main/java/org/jd/gui/service/fileloader/LogFileLoaderProvider.java +++ b/services/src/main/java/org/jd/gui/service/fileloader/LogFileLoaderProvider.java @@ -16,13 +16,15 @@ import java.io.File; public class LogFileLoaderProvider extends ZipFileLoaderProvider { protected static final String[] EXTENSIONS = { "log" }; - public String[] getExtensions() { return EXTENSIONS; } - public String getDescription() { return "Log files (*.log)"; } + @Override public String[] getExtensions() { return EXTENSIONS; } + @Override public String getDescription() { return "Log files (*.log)"; } + @Override public boolean accept(API api, File file) { - return file.exists() && file.canRead() && file.getName().toLowerCase().endsWith(".log"); + return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".log"); } + @Override public boolean load(API api, File file) { api.addPanel(file.getName(), null, "Location: " + file.getAbsolutePath(), new LogPage(api, file.toURI(), TextReader.getText(file))); return true; diff --git a/services/src/main/java/org/jd/gui/service/fileloader/WarFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/WarFileLoaderProvider.java index e869543..7784a7c 100644 --- a/services/src/main/java/org/jd/gui/service/fileloader/WarFileLoaderProvider.java +++ b/services/src/main/java/org/jd/gui/service/fileloader/WarFileLoaderProvider.java @@ -14,10 +14,11 @@ import java.io.File; public class WarFileLoaderProvider extends ZipFileLoaderProvider { protected static final String[] EXTENSIONS = { "war" }; - public String[] getExtensions() { return EXTENSIONS; } - public String getDescription() { return "War files (*.war)"; } + @Override public String[] getExtensions() { return EXTENSIONS; } + @Override public String getDescription() { return "Web application archive files (*.war)"; } + @Override public boolean accept(API api, File file) { - return file.exists() && file.canRead() && file.getName().toLowerCase().endsWith(".war"); + return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".war"); } } diff --git a/services/src/main/java/org/jd/gui/service/fileloader/ZipFileLoaderProvider.java b/services/src/main/java/org/jd/gui/service/fileloader/ZipFileLoaderProvider.java index 4ee6b85..4594c7d 100644 --- a/services/src/main/java/org/jd/gui/service/fileloader/ZipFileLoaderProvider.java +++ b/services/src/main/java/org/jd/gui/service/fileloader/ZipFileLoaderProvider.java @@ -24,13 +24,15 @@ import java.util.Iterator; public class ZipFileLoaderProvider extends AbstractFileLoaderProvider { protected static final String[] EXTENSIONS = { "zip" }; - public String[] getExtensions() { return EXTENSIONS; } - public String getDescription() { return "Zip files (*.zip)"; } + @Override public String[] getExtensions() { return EXTENSIONS; } + @Override public String getDescription() { return "Zip files (*.zip)"; } + @Override public boolean accept(API api, File file) { - return file.exists() && file.canRead() && file.getName().toLowerCase().endsWith(".zip"); + return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".zip"); } + @Override public boolean load(API api, File file) { try { URI fileUri = file.toURI(); @@ -55,5 +57,5 @@ public class ZipFileLoaderProvider extends AbstractFileLoaderProvider { } return false; - } + } } diff --git a/services/src/main/java/org/jd/gui/service/indexer/ZipFileIndexerProvider.java b/services/src/main/java/org/jd/gui/service/indexer/ZipFileIndexerProvider.java index 0ab195b..d544bfa 100644 --- a/services/src/main/java/org/jd/gui/service/indexer/ZipFileIndexerProvider.java +++ b/services/src/main/java/org/jd/gui/service/indexer/ZipFileIndexerProvider.java @@ -14,7 +14,7 @@ import org.jd.gui.spi.Indexer; public class ZipFileIndexerProvider extends AbstractIndexerProvider { - @Override public String[] getSelectors() { return appendSelectors("*:file:*.zip", "*:file:*.jar", "*:file:*.war", "*:file:*.ear"); } + @Override public String[] getSelectors() { return appendSelectors("*:file:*.zip", "*:file:*.jar", "*:file:*.war", "*:file:*.ear", "*:file:*.aar", "*:file:*.jmod"); } @Override public void index(API api, Container.Entry entry, Indexes indexes) { diff --git a/services/src/main/java/org/jd/gui/service/sourcesaver/ZipFileSourceSaverProvider.java b/services/src/main/java/org/jd/gui/service/sourcesaver/ZipFileSourceSaverProvider.java index 3828cf8..9015cc9 100644 --- a/services/src/main/java/org/jd/gui/service/sourcesaver/ZipFileSourceSaverProvider.java +++ b/services/src/main/java/org/jd/gui/service/sourcesaver/ZipFileSourceSaverProvider.java @@ -22,7 +22,7 @@ import java.util.HashMap; public class ZipFileSourceSaverProvider extends DirectorySourceSaverProvider { - @Override public String[] getSelectors() { return appendSelectors("*:file:*.zip", "*:file:*.jar", "*:file:*.war", "*:file:*.ear"); } + @Override public String[] getSelectors() { return appendSelectors("*:file:*.zip", "*:file:*.jar", "*:file:*.war", "*:file:*.ear", "*:file:*.aar", "*:file:*.jmod"); } @Override public void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path rootPath, Container.Entry entry) { 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 new file mode 100644 index 0000000..44296c4 --- /dev/null +++ b/services/src/main/java/org/jd/gui/service/treenode/JmodFileTreeNodeFactoryProvider.java @@ -0,0 +1,42 @@ +/* + * 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 org.jd.gui.api.API; +import org.jd.gui.api.feature.ContainerEntryGettable; +import org.jd.gui.api.feature.UriGettable; +import org.jd.gui.api.model.Container; +import org.jd.gui.spi.TreeNodeFactory; +import org.jd.gui.view.data.TreeNodeBean; + +import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; + +public class JmodFileTreeNodeFactoryProvider extends ZipFileTreeNodeFactoryProvider { + @Override public String[] getSelectors() { return appendSelectors("*:file:*.jmod"); } + + @Override + @SuppressWarnings("unchecked") + public T make(API api, Container.Entry entry) { + int lastSlashIndex = entry.getPath().lastIndexOf("/"); + String name = entry.getPath().substring(lastSlashIndex+1); + + + + T node = (T)new TreeNode(entry, "generic", new TreeNodeBean(name, ICON)); + + + + // Add dummy node + node.add(new DefaultMutableTreeNode()); + + + + return node; + } +} diff --git a/services/src/main/java/org/jd/gui/service/treenode/PackageTreeNodeFactoryProvider.java b/services/src/main/java/org/jd/gui/service/treenode/PackageTreeNodeFactoryProvider.java index 97790e9..ec2bfb3 100644 --- a/services/src/main/java/org/jd/gui/service/treenode/PackageTreeNodeFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/treenode/PackageTreeNodeFactoryProvider.java @@ -21,7 +21,7 @@ import java.util.Collection; public class PackageTreeNodeFactoryProvider extends DirectoryTreeNodeFactoryProvider { protected static final ImageIcon ICON = new ImageIcon(PackageTreeNodeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/package_obj.png")); - @Override public String[] getSelectors() { return appendSelectors("jar:dir:*"); } + @Override public String[] getSelectors() { return appendSelectors("jar:dir:*", "jmodClassesDirectory:dir:*"); } @Override @SuppressWarnings("unchecked") diff --git a/services/src/main/java/org/jd/gui/service/treenode/TextFileTreeNodeFactoryProvider.java b/services/src/main/java/org/jd/gui/service/treenode/TextFileTreeNodeFactoryProvider.java index 21b0aab..2550430 100644 --- a/services/src/main/java/org/jd/gui/service/treenode/TextFileTreeNodeFactoryProvider.java +++ b/services/src/main/java/org/jd/gui/service/treenode/TextFileTreeNodeFactoryProvider.java @@ -38,7 +38,9 @@ public class TextFileTreeNodeFactoryProvider extends FileTreeNodeFactoryProvider } } - @Override public String[] getSelectors() { return appendSelectors("*:file:*.txt", "*:file:*.md", "*:file:*.SF", "*:file:*.policy", "*:file:*.yaml", "*:file:*.yml"); } + @Override public String[] getSelectors() { + return appendSelectors("*:file:*.txt", "*:file:*.md", "*:file:*.SF", "*:file:*.policy", "*:file:*.yaml", "*:file:*.yml", "*:file:*/COPYRIGHT", "*:file:*/LICENSE"); + } @Override @SuppressWarnings("unchecked") 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 66e7afd..6bd96ad 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 @@ -18,9 +18,9 @@ import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; public class ZipFileTreeNodeFactoryProvider extends DirectoryTreeNodeFactoryProvider { - protected static final ImageIcon ICON = new ImageIcon(ZipFileTreeNodeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/zip_obj.png")); + protected static final ImageIcon ICON = new ImageIcon(ZipFileTreeNodeFactoryProvider.class.getClassLoader().getResource("org/jd/gui/images/zip_obj.png")); - @Override public String[] getSelectors() { return appendSelectors("*:file:*.zip"); } + @Override public String[] getSelectors() { return appendSelectors("*:file:*.zip", "*:file:*.aar"); } @Override @SuppressWarnings("unchecked") @@ -31,7 +31,7 @@ public class ZipFileTreeNodeFactoryProvider extends DirectoryTreeNodeFactoryProv // Add dummy node node.add(new DefaultMutableTreeNode()); return node; - } + } protected static class TreeNode extends DirectoryTreeNodeFactoryProvider.TreeNode { protected String ct; diff --git a/services/src/main/java/org/jd/gui/service/uriloader/FileUriLoaderProvider.java b/services/src/main/java/org/jd/gui/service/uriloader/FileUriLoaderProvider.java index 15bac3c..211972a 100644 --- a/services/src/main/java/org/jd/gui/service/uriloader/FileUriLoaderProvider.java +++ b/services/src/main/java/org/jd/gui/service/uriloader/FileUriLoaderProvider.java @@ -15,16 +15,16 @@ import java.io.File; import java.net.URI; public class FileUriLoaderProvider implements UriLoader { - protected static final String[] SCHEMES = { "file" }; + protected static final String[] SCHEMES = { "file" }; - public String[] getSchemes() { return SCHEMES; } + public String[] getSchemes() { return SCHEMES; } - public boolean accept(API api, URI uri) { return "file".equals(uri.getScheme()); } + public boolean accept(API api, URI uri) { return "file".equals(uri.getScheme()); } - public boolean load(API api, URI uri) { + public boolean load(API api, URI uri) { File file = new File(uri.getPath()); - FileLoader fileLoader = api.getFileLoader(file); + FileLoader fileLoader = api.getFileLoader(file); return (fileLoader != null) && fileLoader.load(api, file); - } + } } 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 5a46f43..c8d094e 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,4 +1,5 @@ -# Order is important +# Order is important : 'GenericContainerFactoryProvider' must be the last +org.jd.gui.service.container.JmodClassesDirectoryContainerFactoryProvider 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.FileLoader b/services/src/main/resources/META-INF/services/org.jd.gui.spi.FileLoader index a239d39..2875824 100644 --- a/services/src/main/resources/META-INF/services/org.jd.gui.spi.FileLoader +++ b/services/src/main/resources/META-INF/services/org.jd.gui.spi.FileLoader @@ -1,7 +1,9 @@ +org.jd.gui.service.fileloader.AarFileLoaderProvider org.jd.gui.service.fileloader.ClassFileLoaderProvider org.jd.gui.service.fileloader.EarFileLoaderProvider org.jd.gui.service.fileloader.JarFileLoaderProvider org.jd.gui.service.fileloader.JavaFileLoaderProvider +org.jd.gui.service.fileloader.JmodFileLoaderProvider org.jd.gui.service.fileloader.LogFileLoaderProvider org.jd.gui.service.fileloader.WarFileLoaderProvider org.jd.gui.service.fileloader.ZipFileLoaderProvider 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 28653f7..d15d20d 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 @@ -9,6 +9,7 @@ org.jd.gui.service.treenode.HtmlFileTreeNodeFactoryProvider 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.JsonFileTreeNodeFactoryProvider org.jd.gui.service.treenode.JspFileTreeNodeFactoryProvider org.jd.gui.service.treenode.ManifestFileTreeNodeFactoryProvider