-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from romary22/master
Add kar file support (KAraf aRchive)
- Loading branch information
Showing
9 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
services/src/main/java/org/jd/gui/model/container/KarContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 KarContainer extends GenericContainer { | ||
public KarContainer(API api, Container.Entry parentEntry, Path rootPath) { | ||
super(api, parentEntry, rootPath); | ||
} | ||
|
||
public String getType() { return "kar"; } | ||
} |
43 changes: 43 additions & 0 deletions
43
services/src/main/java/org/jd/gui/service/container/KarContainerFactoryProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.KarContainer; | ||
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 KarContainerFactoryProvider implements ContainerFactory { | ||
@Override | ||
public String getType() { return "kar"; } | ||
|
||
@Override | ||
public boolean accept(API api, Path rootPath) { | ||
if (rootPath.toUri().toString().toLowerCase().endsWith(".kar!/")) { | ||
return true; | ||
} else { | ||
// Extension: accept uncompressed KAR file containing a folder 'repository' | ||
try { | ||
return rootPath.getFileSystem().provider().getScheme().equals("file") && Files.exists(rootPath.resolve("repository")); | ||
} catch (InvalidPathException e) { | ||
assert ExceptionUtil.printStackTrace(e); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Container make(API api, Container.Entry parentEntry, Path rootPath) { | ||
return new KarContainer(api, parentEntry, rootPath); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
services/src/main/java/org/jd/gui/service/fileloader/KarFileLoaderProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.fileloader; | ||
|
||
import org.jd.gui.api.API; | ||
|
||
import java.io.File; | ||
|
||
public class KarFileLoaderProvider extends ZipFileLoaderProvider { | ||
protected static final String[] EXTENSIONS = { "kar" }; | ||
|
||
@Override public String[] getExtensions() { return EXTENSIONS; } | ||
@Override public String getDescription() { return "Karaf archive files (*.kar)"; } | ||
|
||
@Override | ||
public boolean accept(API api, File file) { | ||
return file.exists() && file.isFile() && file.canRead() && file.getName().toLowerCase().endsWith(".kar"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
services/src/main/java/org/jd/gui/service/treenode/KarFileTreeNodeFactoryProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.view.data.TreeNodeBean; | ||
|
||
import javax.swing.tree.DefaultMutableTreeNode; | ||
import java.io.File; | ||
|
||
public class KarFileTreeNodeFactoryProvider extends ZipFileTreeNodeFactoryProvider { | ||
@Override public String[] getSelectors() { return appendSelectors("*:file:*.kar"); } | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <T extends DefaultMutableTreeNode & ContainerEntryGettable & UriGettable> T make(API api, Container.Entry entry) { | ||
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, new TreeNodeBean(label, "Location: " + location, ICON)); | ||
// Add dummy node | ||
node.add(new DefaultMutableTreeNode()); | ||
return node; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
services/src/main/resources/META-INF/services/org.jd.gui.spi.ContainerFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters