Skip to content

Commit

Permalink
Bundle plugins into shadow jar
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Apr 11, 2023
1 parent 03df216 commit 9f7cb6d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
37 changes: 30 additions & 7 deletions core/src/main/java/org/polypheny/db/plugins/PolyPluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.function.Supplier;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -86,16 +89,36 @@ public class PolyPluginManager extends DefaultPluginManager {


static {
pluginManager = new PolyPluginManager(
PolyphenyHomeDirManager.getInstance().registerNewFolder( "plugins" ).getPath(),
"../build/plugins",
"./build/plugins",
"../../build/plugins" );
final File jarFile = new File( PolyPluginManager.class.getProtectionDomain().getCodeSource().getLocation().getPath() );
if ( jarFile.isFile() ) { // Run with JAR file
File pluginsFolder = PolyphenyHomeDirManager.getInstance().registerNewFolder( "plugins" );
try {
final JarFile jar = new JarFile( jarFile );
final Enumeration<JarEntry> entries = jar.entries();
while ( entries.hasMoreElements() ) {
final String name = entries.nextElement().getName();
if ( name.startsWith( "plugins/" ) && name.endsWith( ".zip" ) ) {
System.out.println( name );
FileUtils.copyURLToFile( PolyPluginManager.class.getResource( "/" + name ), new File( pluginsFolder, name.split( "/" )[1] ) );
}
}
jar.close();
} catch ( Exception e ) {
// Ignore
}
pluginManager = new PolyPluginManager( Path.of( pluginsFolder.getPath() ) );
} else {
pluginManager = new PolyPluginManager(
Path.of( PolyphenyHomeDirManager.getInstance().registerNewFolder( "plugins" ).getPath() ),
Path.of( "../build/plugins" ),
Path.of( "./build/plugins" ),
Path.of( "../../build/plugins" ) );
}
}


public PolyPluginManager( String... paths ) {
super( Arrays.stream( paths ).map( Path::of ).collect( Collectors.toList() ) );
public PolyPluginManager( Path... paths ) {
super( List.of( paths ) );
}


Expand Down
12 changes: 12 additions & 0 deletions dbms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ shadowJar {
}
}

task deletePlugins(type: Delete) {
delete 'src/main/resources/plugins'
}
task copyPlugins(type: Copy, dependsOn: deletePlugins) {
from('../build/plugins')
into('src/main/resources/plugins')
include('*.zip')
}
shadowJar.dependsOn(copyPlugins)
copyPlugins.dependsOn(":plugins:assemblePlugins")


// due to gradle 7.6+
configurations {
test {
Expand Down

0 comments on commit 9f7cb6d

Please sign in to comment.