Skip to content

Commit

Permalink
improve lookup version in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauma109 committed Oct 23, 2022
2 parents beed648 + 94c5078 commit 19b4567
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 72 deletions.
4 changes: 2 additions & 2 deletions org.jd.ide.eclipse.plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Bundle-Activator: org.jd.ide.eclipse.JavaDecompilerPlugin
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: /lib/commons-io-2.11.0.jar,
/lib/bcel-6.6.0.jar,
/lib/jd-util-1.1.11.jar,
/lib/jd-core-1.2.17.jar,
/lib/jd-util-1.1.12.jar,
/lib/jd-core-1.2.18.jar,
.
Export-Package: jd.core,
jd.core.model.instruction.bytecode,
Expand Down
4 changes: 2 additions & 2 deletions org.jd.ide.eclipse.plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ configurations {
}

dependencies {
implementation 'com.github.nbauma109:jd-core:1.2.17'
implementation 'com.github.nbauma109:jd-core:1.2.18'

implementation 'com.github.nbauma109:jd-util:1.1.11'
implementation 'com.github.nbauma109:jd-util:1.1.12'

implementation 'org.apache.bcel:bcel:6.6.0'

Expand Down
4 changes: 2 additions & 2 deletions org.jd.ide.eclipse.plugin/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ bin.includes = META-INF/,\
plugin.xml,\
icons/,\
about.ini,\
lib/jd-util-1.1.11.jar,\
lib/jd-core-1.2.17.jar,\
lib/jd-util-1.1.12.jar,\
lib/jd-core-1.2.18.jar,\
.
source.. = src/
jars.compile.order = .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

package org.jd.ide.eclipse.editors;

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand All @@ -15,19 +20,12 @@
import org.jd.core.v1.ClassFileToJavaSourceDecompiler;
import org.jd.core.v1.api.loader.Loader;
import org.jd.core.v1.printer.LineNumberStringBuilderPrinter;
import org.jd.core.v1.util.StringConstants;
import org.jd.ide.eclipse.JavaDecompilerPlugin;
import org.jd.ide.eclipse.util.loader.DirectoryLoader;
import org.jd.ide.eclipse.util.loader.ZipLoader;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import jd.core.preferences.Preferences;


/**
Expand All @@ -38,7 +36,6 @@
* @see org.eclipse.jdt.internal.core.SourceMapper
*/
public class JDSourceMapper extends SourceMapper {
private static final String JAVA_CLASS_SUFFIX = ".class";
private static final String JAVA_SOURCE_SUFFIX = ".java";
private static final int JAVA_SOURCE_SUFFIX_LENGTH = 5;

Expand Down Expand Up @@ -102,8 +99,11 @@ protected char[] decompile(String basePath, String internalTypeName) throws Exce
boolean showLineNumbers = store.getBoolean(JavaDecompilerPlugin.PREF_SHOW_LINE_NUMBERS);
boolean showMetaData = store.getBoolean(JavaDecompilerPlugin.PREF_SHOW_METADATA);

Map<String, Object> configuration = new HashMap<>();
configuration.put("realignLineNumbers", realignmentLineNumber);
Map<String, String> configuration = new HashMap<>();
configuration.put(Preferences.REALIGN_LINE_NUMBERS, Boolean.toString(realignmentLineNumber));
configuration.put(Preferences.ESCAPE_UNICODE_CHARACTERS, Boolean.toString(unicodeEscape));
configuration.put(Preferences.WRITE_LINE_NUMBERS, Boolean.toString(showLineNumbers));
configuration.put(Preferences.WRITE_METADATA, Boolean.toString(showMetaData));

// Initialize loader
Loader loader;
Expand All @@ -122,59 +122,8 @@ protected char[] decompile(String basePath, String internalTypeName) throws Exce
loader = new DirectoryLoader(base);
}

// Initialize printer
printer.setRealignmentLineNumber(realignmentLineNumber);
printer.setUnicodeEscape(unicodeEscape);
printer.setShowLineNumbers(showLineNumbers);

// Decompile class file
DECOMPILER.decompile(loader, printer, internalTypeName, configuration);

StringBuilder stringBuffer = printer.getStringBuffer();

// Metadata
if (showMetaData) {
// Add location
stringBuffer.append("\n\n/* Location: ");
String classPath = internalTypeName + JAVA_CLASS_SUFFIX;
String location = base.isFile() ? base.getPath() + "!/" + classPath : new File(base, classPath).getPath();
// Escape "\ u" sequence to prevent "Invalid unicode" errors
stringBuffer.append(location.replaceAll("(^|[^\\\\])\\\\u", "\\\\\\\\u"));
// Add Java compiler version
int majorVersion = printer.getMajorVersion();
if (majorVersion >= 45) {
stringBuffer.append("\n * Java compiler version: ");

if (majorVersion >= 49) {
stringBuffer.append(majorVersion - (49 - 5));
} else {
stringBuffer.append(majorVersion - (45 - 1));
}

stringBuffer.append(" (");
stringBuffer.append(majorVersion);
stringBuffer.append('.');
stringBuffer.append(printer.getMinorVersion());
stringBuffer.append(')');
}
// Add JD-Core version
stringBuffer.append("\n * JD-Core Version: ");
Enumeration<URL> manifestURLs = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
while (manifestURLs.hasMoreElements()) {
URL manifestUrl = manifestURLs.nextElement();
try (InputStream inputStream = manifestUrl.openStream()) {
Manifest manifest = new Manifest(inputStream);
Attributes attributes = manifest.getMainAttributes();
String version = attributes.getValue("JD-Core-Version");
if (version != null) {
stringBuffer.append(version);
break;
}
}
}
stringBuffer.append("\n */");
}

return stringBuffer.toString().toCharArray();
String entryPath = internalTypeName + StringConstants.CLASS_FILE_SUFFIX;
String decompiledOutput = printer.buildDecompiledOutput(configuration, loader, entryPath, DECOMPILER);
return decompiledOutput .toCharArray();
}
}

0 comments on commit 19b4567

Please sign in to comment.