Skip to content

Commit

Permalink
Merge pull request #267 from romary22/master
Browse files Browse the repository at this point in the history
Add kar file support (KAraf aRchive)
  • Loading branch information
emmanue1 authored Nov 17, 2019
2 parents 0b9d892 + a82460b commit 683b861
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 2 deletions.
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"; }
}
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);
}
}
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class ZipFileIndexerProvider extends AbstractIndexerProvider {

@Override public String[] getSelectors() { return appendSelectors("*:file:*.zip", "*:file:*.jar", "*:file:*.war", "*:file:*.ear", "*:file:*.aar"); }
@Override public String[] getSelectors() { return appendSelectors("*:file:*.zip", "*:file:*.jar", "*:file:*.war", "*:file:*.ear", "*:file:*.aar", "*:file:*.kar"); }

@Override
public void index(API api, Container.Entry entry, Indexes indexes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class ZipFileSourceSaverProvider extends DirectorySourceSaverProvider {

@Override public String[] getSelectors() { return appendSelectors("*:file:*.zip", "*:file:*.jar", "*:file:*.war", "*:file:*.ear", "*:file:*.aar", "*:file:*.jmod"); }
@Override public String[] getSelectors() { return appendSelectors("*:file:*.zip", "*:file:*.jar", "*:file:*.war", "*:file:*.ear", "*:file:*.aar", "*:file:*.jmod", "*:file:*.kar"); }

@Override
public void save(API api, SourceSaver.Controller controller, SourceSaver.Listener listener, Path rootPath, Container.Entry entry) {
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Order is important : 'GenericContainerFactoryProvider' must be the last
org.jd.gui.service.container.KarContainerFactoryProvider
org.jd.gui.service.container.JavaModuleContainerFactoryProvider
org.jd.gui.service.container.EarContainerFactoryProvider
org.jd.gui.service.container.WarContainerFactoryProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ org.jd.gui.service.fileloader.EarFileLoaderProvider
org.jd.gui.service.fileloader.JarFileLoaderProvider
org.jd.gui.service.fileloader.JavaFileLoaderProvider
org.jd.gui.service.fileloader.JavaModuleFileLoaderProvider
org.jd.gui.service.fileloader.KarFileLoaderProvider
org.jd.gui.service.fileloader.LogFileLoaderProvider
org.jd.gui.service.fileloader.WarFileLoaderProvider
org.jd.gui.service.fileloader.ZipFileLoaderProvider
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ org.jd.gui.service.treenode.JavaModuleFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.JavaModulePackageTreeNodeFactoryProvider
org.jd.gui.service.treenode.JsonFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.JspFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.KarFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.ManifestFileTreeNodeFactoryProvider
org.jd.gui.service.treenode.MetainfDirectoryTreeNodeFactoryProvider
org.jd.gui.service.treenode.MetainfServiceFileTreeNodeFactoryProvider
Expand Down

0 comments on commit 683b861

Please sign in to comment.