Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<licenseName>GNU GENERAL PUBLIC LICENSE 3.0</licenseName>
<licenseFile>LICENSE</licenseFile>
<!-- Path of Netbeans instalation.
<netbeansInstallation>${netbeansInstalationPath}</netbeansInstallation>
-->
<netbeansInstallation>${netbeansInstalationPath}</netbeansInstallation>
-->
</configuration>
</plugin>
<plugin>
Expand All @@ -40,6 +40,11 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
<dependencies>
Expand All @@ -57,6 +62,28 @@
<version>1.8.0</version>
</dependency>

<!-- Junit -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>

<!-- Netbeans modules -->
<dependency>
<groupId>org.netbeans.api</groupId>
Expand Down

This file was deleted.

This file was deleted.

42 changes: 0 additions & 42 deletions src/main/java/com/mrf/javadecompiler/constants/Constants.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
*/
package com.mrf.javadecompiler.decompiler;

import org.openide.filesystems.FileObject;

/**
*
* @author Moacir da Roza Flores <moacirrf@gmail.com>
*/
public interface Decompiler<T> {
public interface Decompiler<T,P> {

public T decompile(FileObject input);
public T decompile(P input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,36 @@
*/
package com.mrf.javadecompiler.decompiler;

import com.mrf.javadecompiler.decompiler.jdcore.PrinterImpl;
import com.mrf.javadecompiler.decompiler.jdcore.LoaderImpl;
import static com.machinezoo.noexception.Exceptions.wrap;
import static com.mrf.javadecompiler.constants.Constants.CLASSFILE_BINARY_NAME;
import static com.mrf.javadecompiler.constants.Constants.CLASS_EXT;
import static com.mrf.javadecompiler.exception.ExceptionHandler.handleException;
import static java.io.File.separatorChar;
import static java.util.Objects.nonNull;
import com.mrf.javadecompiler.builder.FileSystemBuilder;
import com.mrf.javadecompiler.exception.ExceptionHandler;
import com.mrf.javadecompiler.filesystems.FileSystemHelper;
import org.jd.core.v1.ClassFileToJavaSourceDecompiler;
import org.openide.filesystems.FileObject;

/**
*
* @author Moacir da Roza Flores <moacirrf@gmail.com>
*/
public class DecompilerClassImpl implements Decompiler<String> {
public final class DecompilerClassImpl implements Decompiler<String, FileObject> {

public static final String HEADER_COMMENT = "//\n"
+ "// Source code recreated by Apache Netbeans\n"
+ "// (powered by Java Decompiler http://java-decompiler.github.io )\n"
+ "//\n";

@Override
public String decompile(FileObject file) {
return wrap(e -> handleException(e)).get(() -> {
LoaderImpl loader = new LoaderImpl(FileSystemBuilder.build(file));
return wrap(ExceptionHandler::handleException).get(() -> {
LoaderImpl loader = new LoaderImpl(FileSystemHelper.of(file));
PrinterImpl printer = new PrinterImpl();

ClassFileToJavaSourceDecompiler decompiler = new ClassFileToJavaSourceDecompiler();
decompiler.decompile(loader, printer, getFileName(file));
return printer.toString();
decompiler.decompile(loader, printer, FileSystemHelper.extractName(file));

return HEADER_COMMENT + printer.toString();
});
}

private String getFileName(FileObject file) {
Object fileName = file.getAttribute(CLASSFILE_BINARY_NAME);
if (nonNull(fileName)) {
return String.valueOf(fileName) + CLASS_EXT;
}
return file.getParent().getPath() + separatorChar + file.getName() + CLASS_EXT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.mrf.javadecompiler.factory;

import com.mrf.javadecompiler.decompiler.Decompiler;
import com.mrf.javadecompiler.decompiler.DecompilerClassImpl;
package com.mrf.javadecompiler.decompiler;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,44 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.mrf.javadecompiler.decompiler;
package com.mrf.javadecompiler.decompiler.jdcore;

import com.mrf.javadecompiler.filesystems.FileSystemHelper;
import java.io.IOException;
import static java.util.Objects.nonNull;
import org.jd.core.v1.api.loader.Loader;
import org.jd.core.v1.api.loader.LoaderException;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;

/**
*
* @author Moacir da Roza Flores <moacirrf@gmail.com>
*/
public class LoaderImpl implements Loader {

private final FileSystem fileSystem;

public LoaderImpl(FileSystem fileSystem) {
this.fileSystem = fileSystem;
private final FileSystemHelper input;
public LoaderImpl(FileSystemHelper input) {
this.input = input;
}

@Override
public boolean canLoad(String internalName) {
FileObject fileObject = fileSystem.findResource(internalName);
if (fileObject == null) {
return false;
}
return fileObject.canRead();
FileObject file = input.findResource(internalName);
if (nonNull(file)) {
return file.canRead();
}
return false;
}

@Override
public byte[] load(String internalName) throws LoaderException {
try {
return fileSystem.findResource(internalName).asBytes();
FileObject file = input.findResource(internalName);
if (nonNull(file)) {
return file.asBytes();
}
return null;
} catch (IOException ex) {
throw new LoaderException(ex);
}
Expand Down
Loading