-
Notifications
You must be signed in to change notification settings - Fork 5
WIP create executable jar using jruby-main artifact #38
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,12 @@ import com.github.jrubygradle.GemUtils | |
/** Helper class to add extra methods to {@code Jar} tasks in order to add JRuby specifics. | ||
* | ||
* @author Schalk W. Cronjé | ||
* @author Christian Meier | ||
*/ | ||
class JRubyJarConfigurator { | ||
|
||
static final String DEFAULT_BOOTSTRAP_CLASS = 'com.github.jrubygradle.jar.bootstrap.JarMain' | ||
static final String SHADOW_JAR_TASK_CLASS = 'com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar' | ||
static final String DEFAULT_MAIN_CLASS = 'de.saumya.mojo.mains.JarMain' | ||
static final String DEFAULT_EXTRACTING_MAIN_CLASS = 'de.saumya.mojo.mains.ExtractingMain' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you read my comment in the meanwhile. sometimes running from inside the jar fails like "rake spec" using RSpec rake task does spawn ruby and this spawning will fail. will see to JRuby itself to fix it on the JRuby if possible. but for the time being we need to offer both cases to cover more applications (hopefully all applications) |
||
|
||
// This is used by JRubyJarPlugin to configure Jar classes | ||
@PackageScope | ||
|
@@ -24,15 +25,6 @@ class JRubyJarConfigurator { | |
configure() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure whether I am happy with dropping shadowJar support completely. What I do think is to definitely remove it from a fixed dependency in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, sounds fair to treat There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on second thought: I moved back the shadowJar option for jruby-gradle-jar-plugin BUT things will not really work when you use it since all those embedded jars are gone and jruby-main will look for them and not find them. |
||
@PackageScope | ||
static void afterEvaluateAction( Project project ) { | ||
project.tasks.withType(Jar) { t -> | ||
if(t.class.superclass.name == SHADOW_JAR_TASK_CLASS && t.name=='shadowJar') { | ||
t.configurations.add(project.configurations.getByName('jrubyJar')) | ||
} | ||
} | ||
} | ||
|
||
/** Adds a GEM installation directory | ||
*/ | ||
void gemDir(def properties=[:],File f) { | ||
|
@@ -45,7 +37,20 @@ class JRubyJarConfigurator { | |
* @param dir Source folder. Will be handled by {@code project.files(dir)} | ||
*/ | ||
void gemDir(def properties=[:],Object dir) { | ||
archive.with GemUtils.gemCopySpec(properties,archive.project,dir) | ||
jar().with GemUtils.gemCopySpec(properties,archive.project,dir) | ||
} | ||
|
||
/** Adds a GEM installation directory | ||
*/ | ||
void jarDir(File f) { | ||
jarDir(f.absolutePath) | ||
} | ||
|
||
/** Adds a JAR installation directory | ||
* @param dir Source folder. Will be handled by {@code project.files(dir)} | ||
*/ | ||
void jarDir(Object dir) { | ||
jar().with GemUtils.jarCopySpec(archive.project, dir) | ||
} | ||
|
||
/** Makes the JAR executable by setting a custom main class | ||
|
@@ -54,11 +59,33 @@ class JRubyJarConfigurator { | |
*/ | ||
@Incubating | ||
void mainClass(final String className) { | ||
archive.with { | ||
jar().with { | ||
manifest { | ||
attributes 'Main-Class': className | ||
} | ||
} | ||
jar().with archive.project.copySpec { | ||
from { | ||
archive.project.configurations.jrubyJar.collect { | ||
archive.project.zipTree( it ) | ||
} | ||
} | ||
include '**' | ||
exclude 'META-INF/MANIFEST.MF' | ||
// some pom.xml are readonly which creates problems | ||
// with zipTree on second run | ||
exclude 'META-INF/maven/**/pom.xml' | ||
} | ||
} | ||
|
||
@Incubating | ||
void initScript(final String scriptName) { | ||
def script = archive.project.file(scriptName) | ||
jar().with archive.project.copySpec { | ||
from(script.parent) | ||
include script.name | ||
rename { 'jar-bootstrap.rb' } | ||
} | ||
} | ||
|
||
/** Sets the defaults | ||
|
@@ -71,37 +98,46 @@ class JRubyJarConfigurator { | |
switch(it) { | ||
case 'gems': | ||
case 'mainClass': | ||
case 'extractingMainClass': | ||
"default${it.capitalize()}"() | ||
} | ||
} | ||
} | ||
|
||
/** Loads the default GEM installation directory | ||
/** Loads the default GEM installation directory and | ||
* JAR installation directory | ||
* | ||
*/ | ||
void defaultGems() { | ||
gemDir({archive.project.jruby.gemInstallDir}) | ||
// gems depend on jars so we need to add meaningful default | ||
jarDir({archive.project.jruby.jarInstallDir}) | ||
} | ||
|
||
/** Makes the executable by adding a default main class | ||
* | ||
*/ | ||
@Incubating | ||
void defaultMainClass() { | ||
mainClass(DEFAULT_BOOTSTRAP_CLASS) | ||
mainClass(DEFAULT_MAIN_CLASS) | ||
} | ||
|
||
boolean isShadowJar() { | ||
shadowJar | ||
/** Makes the executable by adding a default main class | ||
* which extracts the jar to temporary directory | ||
* | ||
*/ | ||
@Incubating | ||
void defaultExtractingMainClass() { | ||
mainClass(DEFAULT_EXTRACTING_MAIN_CLASS) | ||
} | ||
|
||
private JRubyJarConfigurator(Jar a) { | ||
archive = a | ||
if (a.class.name == SHADOW_JAR_TASK_CLASS || a.class.superclass.name == SHADOW_JAR_TASK_CLASS) { | ||
shadowJar = true | ||
} | ||
} | ||
|
||
private Jar jar() { | ||
return archive.project.tasks.getByName('jrubyJar') | ||
} | ||
|
||
private Jar archive | ||
private boolean shadowJar = false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the removal of this final closing
}
ius causing the build to fail in Travis