Skip to content

Commit cb8de55

Browse files
author
emmanue1
committed
Add AAR and JMOD files support
1 parent 6ac9549 commit cb8de55

30 files changed

+264
-79
lines changed

api/src/main/java/org/jd/gui/spi/ContainerFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import java.nio.file.Path;
1414

1515
public interface ContainerFactory {
16-
String getType();
17-
18-
boolean accept(API api, Path rootPath);
19-
20-
Container make(API api, Container.Entry parentEntry, Path rootPath);
16+
String getType();
17+
18+
boolean accept(API api, Path rootPath);
19+
20+
Container make(API api, Container.Entry parentEntry, Path rootPath);
2121
}

app/src/main/java/org/jd/gui/service/fileloader/FileLoaderService.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class FileLoaderService {
2121
public static FileLoaderService getInstance() { return FILE_LOADER_SERVICE; }
2222

2323
protected final Collection<FileLoader> providers = ExtensionService.getInstance().load(FileLoader.class);
24-
25-
protected HashMap<String, FileLoader> mapProviders = new HashMap<>();
2624

27-
protected FileLoaderService() {
28-
for (FileLoader provider : providers) {
29-
for (String extension : provider.getExtensions()) {
25+
protected HashMap<String, FileLoader> mapProviders = new HashMap<>();
26+
27+
protected FileLoaderService() {
28+
for (FileLoader provider : providers) {
29+
for (String extension : provider.getExtensions()) {
3030
mapProviders.put(extension, provider);
3131
}
3232
}
@@ -37,12 +37,7 @@ public FileLoader get(API api, File file) {
3737
int lastDot = name.lastIndexOf('.');
3838
String extension = name.substring(lastDot+1);
3939
FileLoader provider = mapProviders.get(extension);
40-
41-
if ((provider != null) && provider.accept(api, file)) {
42-
return provider;
43-
}
44-
45-
return null;
40+
return provider;
4641
}
4742

4843
public HashMap<String, FileLoader> getMapProviders() {

app/src/main/java/org/jd/gui/service/uriloader/UriLoaderService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class UriLoaderService {
2020

2121
public static UriLoaderService getInstance() { return URI_LOADER_SERVICE; }
2222

23-
protected HashMap<String, UriLoader> mapProviders = new HashMap<>();
23+
protected HashMap<String, UriLoader> mapProviders = new HashMap<>();
2424

25-
protected UriLoaderService() {
25+
protected UriLoaderService() {
2626
Collection<UriLoader> providers = ExtensionService.getInstance().load(UriLoader.class);
2727

2828
for (UriLoader provider : providers) {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,20 @@ protected Collection<Container.Entry> loadChildrenFromDirectoryEntry() throws IO
147147

148148
for (Path subPath : stream) {
149149
if (subPath.getNameCount() > parentNameCount) {
150-
children.add(newChildEntry(subPath));
150+
ContainerFactory containerFactory = api.getContainerFactory(subPath);
151+
152+
if ((containerFactory == null) || "generic".equals(containerFactory.getType())) {
153+
children.add(newChildEntry(subPath));
154+
} else {
155+
Entry childEntry = newChildEntry(subPath);
156+
Container container = containerFactory.make(api, childEntry, subPath);
157+
158+
if (container != null) {
159+
childEntry.children = container.getRoot().getChildren();
160+
}
161+
162+
children.add(childEntry);
163+
}
151164
}
152165
}
153166

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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.model.container;
9+
10+
import org.jd.gui.api.API;
11+
import org.jd.gui.api.model.Container;
12+
13+
import java.nio.file.Path;
14+
15+
public class JmodClassesDirectoryContainer extends GenericContainer {
16+
public JmodClassesDirectoryContainer(API api, Container.Entry parentEntry, Path rootPath) {
17+
super(api, parentEntry, rootPath);
18+
}
19+
20+
public String getType() { return "jmodClassesDirectory"; }
21+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
import java.nio.file.Path;
1919

2020
public class EarContainerFactoryProvider implements ContainerFactory {
21-
21+
@Override
2222
public String getType() { return "ear"; }
2323

24+
@Override
2425
public boolean accept(API api, Path rootPath) {
2526
if (rootPath.toUri().toString().toLowerCase().endsWith(".ear!/")) {
2627
return true;
@@ -35,6 +36,7 @@ public boolean accept(API api, Path rootPath) {
3536
}
3637
}
3738

39+
@Override
3840
public Container make(API api, Container.Entry parentEntry, Path rootPath) {
3941
return new EarContainer(api, parentEntry, rootPath);
4042
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
import java.nio.file.Path;
1616

1717
public class GenericContainerFactoryProvider implements ContainerFactory {
18+
@Override
19+
public String getType() { return "generic"; }
1820

19-
public String getType() { return "generic"; }
21+
@Override
22+
public boolean accept(API api, Path rootPath) { return true; }
2023

21-
public boolean accept(API api, Path rootPath) { return true; }
22-
23-
public Container make(API api, Container.Entry parentEntry, Path rootPath) {
24-
return new GenericContainer(api, parentEntry, rootPath);
25-
}
24+
@Override
25+
public Container make(API api, Container.Entry parentEntry, Path rootPath) {
26+
return new GenericContainer(api, parentEntry, rootPath);
27+
}
2628
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
import java.nio.file.Path;
1919

2020
public class JarContainerFactoryProvider implements ContainerFactory {
21-
21+
@Override
2222
public String getType() { return "jar"; }
2323

24+
@Override
2425
public boolean accept(API api, Path rootPath) {
2526
if (rootPath.toUri().toString().toLowerCase().endsWith(".jar!/")) {
2627
// Specification: http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html
@@ -36,7 +37,8 @@ public boolean accept(API api, Path rootPath) {
3637
}
3738
}
3839

40+
@Override
3941
public Container make(API api, Container.Entry parentEntry, Path rootPath) {
40-
return new JarContainer(api, parentEntry, rootPath);
41-
}
42+
return new JarContainer(api, parentEntry, rootPath);
43+
}
4244
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.JmodClassesDirectoryContainer;
13+
import org.jd.gui.spi.ContainerFactory;
14+
15+
import java.nio.file.Files;
16+
import java.nio.file.Path;
17+
18+
public class JmodClassesDirectoryContainerFactoryProvider implements ContainerFactory {
19+
@Override
20+
public String getType() { return "jmodClassesDirectory"; }
21+
22+
@Override
23+
public boolean accept(API api, Path rootPath) {
24+
if (Files.isDirectory(rootPath)) {
25+
Path fileName = rootPath.getFileName();
26+
27+
if ((fileName != null) && "classes".equals(rootPath.getFileName().toString())) {
28+
String fileStoreName = rootPath.getFileSystem().getFileStores().iterator().next().name();
29+
return fileStoreName.endsWith(".jmod/");
30+
}
31+
}
32+
33+
return false;
34+
}
35+
36+
@Override
37+
public Container make(API api, Container.Entry parentEntry, Path rootPath) {
38+
return new JmodClassesDirectoryContainer(api, parentEntry, rootPath);
39+
}
40+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
import java.nio.file.Path;
1919

2020
public class WarContainerFactoryProvider implements ContainerFactory {
21-
21+
@Override
2222
public String getType() { return "war"; }
2323

24+
@Override
2425
public boolean accept(API api, Path rootPath) {
2526
if (rootPath.toUri().toString().toLowerCase().endsWith(".war!/")) {
2627
return true;
@@ -35,6 +36,7 @@ public boolean accept(API api, Path rootPath) {
3536
}
3637
}
3738

39+
@Override
3840
public Container make(API api, Container.Entry parentEntry, Path rootPath) {
3941
return new WarContainer(api, parentEntry, rootPath);
4042
}

0 commit comments

Comments
 (0)