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
4 changes: 2 additions & 2 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 8.0.312
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '8.0.312+7'
java-version: '11'
distribution: 'adopt'
- name: NBM
run: mvn clean install
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Java Decompiler for Apache Netbeans, it is based on [jd-core](https://github.com
## Description
This a very simple plugin, with only basic features, if you have some tips or want to help, make a fork and open a pull-request.

- Apache Netbeans 9+
- JDK 8+
- Apache Netbeans 13
- JDK 11+

## Screenshots

Expand Down
48 changes: 33 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mrf.javadecompiler</groupId>
<artifactId>nb-java-decompiler</artifactId>
<version>0.0.1-beta</version>
<version>0.0.2-beta</version>
<packaging>nbm</packaging>
<build>
<plugins>
Expand All @@ -12,20 +12,27 @@
<artifactId>nbm-maven-plugin</artifactId>
<version>4.5</version>
<extensions>true</extensions>
<configuration>
<publicPackages>
<publicPackage>com.mrf.javadecompiler</publicPackage>
</publicPackages>
<netbeansInstallation>/home/PROGRAMAS/instalados/ides/netbeans/</netbeansInstallation>
<!-- <netbeansInstallation>${netbeansInstalationPath}</netbeansInstallation>-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
Expand All @@ -46,70 +53,81 @@
<dependency>
<groupId>com.machinezoo.noexception</groupId>
<artifactId>noexception</artifactId>
<version>1.6.2</version>
<version>1.8.0</version>
</dependency>

<!-- Netbeans modules -->
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-api-annotations-common</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-filesystems</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-awt</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-loaders</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-windows</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-ui</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util-lookup</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-settings</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-text</artifactId>
<version>RELEASE90</version>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-explorer</artifactId>
<version>RELEASE130</version>
</dependency>

<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-java-source</artifactId>
<version>RELEASE130</version>
</dependency>
</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.mrf.javadecompiler.constants.Constants.CLASS_EXT;
import static com.mrf.javadecompiler.constants.Constants.EXCLAM;
import static com.mrf.javadecompiler.constants.Constants.FILE;
import static com.mrf.javadecompiler.constants.Constants.HEADER_COMMENT;
import static com.mrf.javadecompiler.constants.Constants.JAR;
import static com.mrf.javadecompiler.exception.ExceptionHandler.handleException;
import static java.io.File.separator;
Expand All @@ -37,16 +38,11 @@
*/
public final class SourceWindowBuilder {

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

public static SourceWindowTopComponent build(FileObject file, String decompiledSource) {
SourceWindowTopComponent window = new SourceWindowTopComponent();
window.setName(getName(file));
window.setToolTipText(getTooltip(file));
window.setDecompiledSource(COMMENT + decompiledSource);
window.setDecompiledSource(HEADER_COMMENT + decompiledSource);
return window;
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/mrf/javadecompiler/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
*/
package com.mrf.javadecompiler.constants;

import static java.lang.System.getProperty;

/**
*
* @author Moacir da Roza Flores <moacirrf@gmail.com>
*/
public final class Constants {

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";

public static final String TEMP_DIR_PLUGIN = getProperty("java.io.tmpdir") + "/nb_java_decompiler";
public static final String CLASSFILE_BINARY_NAME = "classfile-binaryName";
public static final String CLASSFILE_ROOT = "classfile-root";
public static final String CLASS_EXT = ".class";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 moacirrf
* Copyright (C) 2021 Moacir da Roza Flores <moacirrf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -16,28 +16,36 @@
*/
package com.mrf.javadecompiler.openapi.action;

import static com.machinezoo.noexception.Exceptions.wrap;
import static com.mrf.javadecompiler.constants.Constants.HEADER_COMMENT;
import static java.util.Objects.nonNull;
import com.mrf.javadecompiler.builder.SourceWindowBuilder;
import static com.mrf.javadecompiler.constants.Constants.TEMP_DIR_PLUGIN;
import com.mrf.javadecompiler.decompiler.Decompiler;
import static com.mrf.javadecompiler.exception.ExceptionHandler.handleException;
import com.mrf.javadecompiler.factory.DecompilerFactory;
import com.mrf.javadecompiler.validator.FileValidator;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.netbeans.api.java.source.UiUtils;
import org.openide.loaders.DataObject;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.NbBundle.Messages;

@ActionID(
category = "Tools",
id = "com.mrf.javadecompiler.openapi.DecompileAction"
category = "Tools",
id = "com.mrf.javadecompiler.openapi.DecompileAction"
)
@ActionRegistration(
iconBase = "com/mrf/javadecompiler/openapi/jd_icon_16.png",
displayName = "#CTL_DecompileAction"
iconBase = "com/mrf/javadecompiler/openapi/jd_icon_16.png",
displayName = "#CTL_DecompileAction"
)
@ActionReferences(value = {
@ActionReference(path = "Editors/Popup", position = 1425),
Expand All @@ -47,21 +55,38 @@
public final class DecompileAction implements ActionListener {

private final DataObject context;
private final Path decompilerDir;

public DecompileAction(DataObject context) {
this.context = context;
this.decompilerDir = Paths.get(TEMP_DIR_PLUGIN);
if (!Files.exists(decompilerDir)) {
wrap(e -> handleException(e))
.run(() -> Files.createDirectory(decompilerDir));
}
}

@Override
public void actionPerformed(ActionEvent ev) {
FileObject file = context.getPrimaryFile();
if (FileValidator.validate(file)) {
Decompiler<String> decompiler = DecompilerFactory.create();
String decompiled = decompiler.decompile(file);
writeToNewClass(file, decompiler.decompile(file));
}
}

if (nonNull(decompiled) && !decompiled.isEmpty()) {
SourceWindowBuilder.build(file, decompiled).open();
}
private void writeToNewClass(FileObject file, String decompiled) {
if (nonNull(decompiled) && !decompiled.isEmpty()) {
wrap(e -> handleException(e)).run(() -> {
Path newFile = Path.of(decompilerDir.toString(), file.getName().concat(".java"));
if (Files.exists(newFile)) {
Files.delete(newFile);
}
Files.write(newFile, HEADER_COMMENT.concat(decompiled).getBytes());
newFile.toFile().setReadOnly();
FileObject newFileObject = FileUtil.createData(newFile.toFile());
UiUtils.open(newFileObject, 1);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 moacirrf
* Copyright (C) 2021 Moacir da Roza Flores <moacirrf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -46,11 +46,17 @@
@Messages({
"CTL_SourceWindowAction=Java Decompiler"
})
@Deprecated
/**
* Actualy not used, maybe will be used again on the future.
*
*/
public final class SourceWindowTopComponent extends TopComponent {

public SourceWindowTopComponent() {
initComponents();
initEditorPane();

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
import org.openide.awt.StatusDisplayer;
import org.openide.filesystems.FileObject;

/**
*
* @author Moacir da Roza Flores <moacirrf@gmail.com>
*/
public final class FileValidator {

private static final String INVALID_FILE = "Invalid file.";
Expand Down