forked from java-decompiler/jd-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates of service-providers loading
- Loading branch information
Showing
14 changed files
with
112 additions
and
44 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
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
51 changes: 51 additions & 0 deletions
51
app/src/main/groovy/org/jd/gui/service/extension/ExtensionService.groovy
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,51 @@ | ||
/* | ||
* Copyright (c) 2008-2015 Emmanuel Dupuy | ||
* This program is made available under the terms of the GPLv3 License. | ||
*/ | ||
|
||
package org.jd.gui.service.extension | ||
|
||
import groovy.transform.CompileStatic | ||
|
||
@Singleton | ||
@CompileStatic | ||
class ExtensionService { | ||
protected ClassLoader extensionClassLoader = initClassLoader() | ||
|
||
protected ClassLoader initClassLoader() { | ||
def extDirectory = new File("ext"); | ||
|
||
if (extDirectory.exists() && extDirectory.isDirectory()) { | ||
List<URL> urls = [] | ||
|
||
searchJarAndMetaInf(urls, extDirectory) | ||
|
||
if (! urls.isEmpty()) { | ||
URL[] array = urls.sort { u1, u2 -> u1.path.compareTo(u2.path) } | ||
return new URLClassLoader(array, ExtensionService.class.classLoader) | ||
} | ||
} | ||
|
||
return ExtensionService.class.classLoader | ||
} | ||
|
||
protected void searchJarAndMetaInf(List<URL> urls, File directory) { | ||
def metaInf = new File(directory, 'META-INF') | ||
|
||
if (metaInf.exists() && metaInf.isDirectory()) { | ||
urls.add(directory.toURI().toURL()) | ||
} else { | ||
directory.eachFile { File child -> | ||
if (child.isDirectory()) { | ||
searchJarAndMetaInf(urls, child) | ||
} else if (child.name.toLowerCase().endsWith('.jar')) { | ||
urls.add(new URL('jar', '', child.toURI().toURL().toString() + '!/')) | ||
} | ||
} | ||
} | ||
} | ||
|
||
public <T> Collection<T> load(Class<T> service) { | ||
return ServiceLoader.load(service, extensionClassLoader).toList() | ||
} | ||
} |
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
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
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