mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-27 09:10:45 +00:00
Separated FFDec core library and the rest (GUI).
FFDec Library is now LGPLv3, others stay GPLv3. Version changed to 3.0.0 for FFDec, 1.0.0 for FFDec Library.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS, Miron Sadziak, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.␍ */
|
||||
package com.jpexs.helpers.plugin;
|
||||
|
||||
import java.net.URI;
|
||||
import javax.tools.JavaFileObject.Kind;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class CharSequenceJavaFileObject extends SimpleJavaFileObject {
|
||||
|
||||
/**
|
||||
* CharSequence representing the source code to be compiled
|
||||
*/
|
||||
private final CharSequence content;
|
||||
|
||||
/**
|
||||
* This constructor will store the source code in the internal "content"
|
||||
* variable and register it as a source code, using a URI containing the
|
||||
* class full name
|
||||
*
|
||||
* @param className name of the public class in the source code
|
||||
* @param content source code to compile
|
||||
*/
|
||||
public CharSequenceJavaFileObject(String className, CharSequence content) {
|
||||
super(URI.create("string:///" + className.replace('.', '/')
|
||||
+ Kind.SOURCE.extension), Kind.SOURCE);
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers the CharSequence to be compiled. It will give the source code
|
||||
* stored in variable "content"
|
||||
*
|
||||
* @param ignoreEncodingErrors
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS, Miron Sadziak, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.␍ */
|
||||
package com.jpexs.helpers.plugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.SecureClassLoader;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.ForwardingJavaFileManager;
|
||||
import javax.tools.JavaFileManager;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.JavaFileObject.Kind;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class ClassFileManager extends
|
||||
ForwardingJavaFileManager<JavaFileManager> {
|
||||
|
||||
/**
|
||||
* Instance of JavaClassObject that will store the compiled bytecode of our
|
||||
* class
|
||||
*/
|
||||
private JavaClassObject jclassObject;
|
||||
|
||||
/**
|
||||
* Will initialize the manager with the specified standard java file manager
|
||||
*
|
||||
* @param standardManager
|
||||
*/
|
||||
public ClassFileManager(StandardJavaFileManager standardManager) {
|
||||
super(standardManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be used by us to get the class loader for our compiled class. It
|
||||
* creates an anonymous class extending the SecureClassLoader which uses the
|
||||
* byte code created by the compiler and stored in the JavaClassObject, and
|
||||
* returns the Class for it
|
||||
*
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ClassLoader getClassLoader(Location location) {
|
||||
return new SecureClassLoader() {
|
||||
@Override
|
||||
protected Class<?> findClass(String name)
|
||||
throws ClassNotFoundException {
|
||||
byte[] b = jclassObject.getBytes();
|
||||
return super.defineClass(name, jclassObject
|
||||
.getBytes(), 0, b.length);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the compiler an instance of the JavaClassObject so that the
|
||||
* compiler can write the byte code into it.
|
||||
*
|
||||
* @param location
|
||||
* @param className
|
||||
* @param kind
|
||||
* @param sibling
|
||||
* @return
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public JavaFileObject getJavaFileForOutput(Location location,
|
||||
String className, Kind kind, FileObject sibling)
|
||||
throws IOException {
|
||||
jclassObject = new JavaClassObject(className, kind);
|
||||
return jclassObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 JPEXS, Miron Sadziak, All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.␍ */
|
||||
package com.jpexs.helpers.plugin;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import javax.tools.JavaFileObject.Kind;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class JavaClassObject extends SimpleJavaFileObject {
|
||||
|
||||
/**
|
||||
* Byte code created by the compiler will be stored in this
|
||||
* ByteArrayOutputStream so that we can later get the byte array out of it
|
||||
* and put it in the memory as an instance of our class.
|
||||
*/
|
||||
protected final ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
/**
|
||||
* Registers the compiled class object under URI containing the class full
|
||||
* name
|
||||
*
|
||||
* @param name Full name of the compiled class
|
||||
* @param kind Kind of the data. It will be CLASS in our case
|
||||
*/
|
||||
public JavaClassObject(String name, Kind kind) {
|
||||
super(URI.create("string:///" + name.replace('.', '/')
|
||||
+ kind.extension), kind);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be used by our file manager to get the byte code that can be put
|
||||
* into memory to instantiate our class
|
||||
*
|
||||
* @return compiled byte code
|
||||
*/
|
||||
public byte[] getBytes() {
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Will provide the compiler with an output stream that leads to our byte
|
||||
* array. This way the compiler will write everything into the byte array
|
||||
* that we will instantiate later
|
||||
*
|
||||
* @return
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
@Override
|
||||
public OutputStream openOutputStream() throws IOException {
|
||||
return bos;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user