-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite downgrading classloader to not use a URLClassLoader
- Loading branch information
1 parent
aa29707
commit 8d188fa
Showing
14 changed files
with
183 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
kotlin.code.style=official | ||
org.gradle.jvmargs=-Xmx4G | ||
org.gradle.parallel=true | ||
|
||
version=0.5.0 | ||
|
||
asm_version=9.7 | ||
|
||
mainVersion=7 | ||
testVersion=21 | ||
|
||
# because java 7 support is in beta* | ||
testTargetVersion=8 | ||
|
||
stubFromVersion=8 | ||
stubToVersion=22 | ||
|
||
maven_group=xyz.wagyourtail.jvmdowngrader | ||
archives_base_name=jvmdowngrader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/xyz/wagyourtail/jvmdg/classloader/FlatEnumeration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package xyz.wagyourtail.jvmdg.classloader; | ||
|
||
import xyz.wagyourtail.jvmdg.util.Function; | ||
|
||
import java.util.Enumeration; | ||
|
||
public class FlatEnumeration<T, E> implements Enumeration<E> { | ||
private final Enumeration<T> enumeration; | ||
private final Function<T, Enumeration<E>> mapper; | ||
|
||
private Enumeration<E> currentEnumeration = null; | ||
|
||
public FlatEnumeration(Enumeration<T> enumeration, Function<T, Enumeration<E>> mapper) { | ||
this.enumeration = enumeration; | ||
this.mapper = mapper; | ||
} | ||
|
||
@Override | ||
public boolean hasMoreElements() { | ||
while (currentEnumeration == null || !currentEnumeration.hasMoreElements()) { | ||
if (enumeration.hasMoreElements()) { | ||
currentEnumeration = mapper.apply(enumeration.nextElement()); | ||
} else { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public E nextElement() { | ||
if (!hasMoreElements()) { | ||
return null; | ||
} | ||
return currentEnumeration.nextElement(); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/xyz/wagyourtail/jvmdg/classloader/ResourceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package xyz.wagyourtail.jvmdg.classloader; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Enumeration; | ||
|
||
public interface ResourceProvider extends Closeable { | ||
|
||
Enumeration<URL> getResources(String name) throws IOException; | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/xyz/wagyourtail/jvmdg/classloader/providers/ClassLoaderResourceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package xyz.wagyourtail.jvmdg.classloader.providers; | ||
|
||
import xyz.wagyourtail.jvmdg.classloader.ResourceProvider; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Enumeration; | ||
|
||
public class ClassLoaderResourceProvider implements ResourceProvider { | ||
private final ClassLoader classLoader; | ||
|
||
public ClassLoaderResourceProvider(ClassLoader classLoader) { | ||
this.classLoader = classLoader; | ||
} | ||
|
||
@Override | ||
public Enumeration<URL> getResources(String name) throws IOException { | ||
return classLoader.getResources(name); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (classLoader instanceof Closeable) { | ||
((Closeable) classLoader).close(); | ||
} else if (classLoader instanceof AutoCloseable) { | ||
try { | ||
((AutoCloseable) classLoader).close(); | ||
} catch (Exception e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/xyz/wagyourtail/jvmdg/classloader/providers/FileSystemResourceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package xyz.wagyourtail.jvmdg.classloader.providers; | ||
|
||
import xyz.wagyourtail.jvmdg.classloader.ResourceProvider; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Enumeration; | ||
import java.util.List; | ||
|
||
public class FileSystemResourceProvider implements ResourceProvider { | ||
private final FileSystem jarFile; | ||
|
||
public FileSystemResourceProvider(FileSystem jarFile) { | ||
this.jarFile = jarFile; | ||
} | ||
|
||
|
||
@Override | ||
public Enumeration<URL> getResources(String name) throws IOException { | ||
List<URL> urls = new ArrayList<>(); | ||
for (Path rootDirectory : jarFile.getRootDirectories()) { | ||
Path resource = rootDirectory.resolve(name); | ||
if (Files.exists(resource)) { | ||
urls.add(resource.toUri().toURL()); | ||
} | ||
} | ||
return Collections.enumeration(urls); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
jarFile.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.