Compare commits

...

3 Commits

Author SHA1 Message Date
Schalk W. Cronjé 8320341dd5
Merge pull request #413 from ysb33r/alpha-2
Upgrade to grolifant 1.0.0-alpha.4
2020-11-15 21:23:35 +01:00
Schalk Cronje 102e880c3e Upgradle to grolifant 1.0.0-alpha.4 2020-11-15 18:01:39 +01:00
Schalk Cronje 8fd5b396e8 Upgrade to grolifant 1.0.0-alpha.2 2020-11-13 16:54:40 +01:00
12 changed files with 115 additions and 71 deletions

View File

@ -24,7 +24,7 @@
package com.github.jrubygradle package com.github.jrubygradle
import com.github.jrubygradle.testhelper.IntegrationSpecification import com.github.jrubygradle.testhelper.IntegrationSpecification
import org.ysb33r.grolifant.api.OperatingSystem import org.ysb33r.grolifant.api.core.OperatingSystem
import spock.lang.IgnoreIf import spock.lang.IgnoreIf
/** /**

View File

@ -256,7 +256,7 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
registerPrepareTask(((Configuration) c).name) registerPrepareTask(((Configuration) c).name)
break break
case CharSequence: case CharSequence:
this.gemConfiguration = project.provider( this.gemConfiguration = projectOperations.provider(
{ -> configurations.getByName(c.toString()) } as Callable<Configuration> { -> configurations.getByName(c.toString()) } as Callable<Configuration>
) )
registerPrepareTask(c.toString()) registerPrepareTask(c.toString())

View File

@ -28,7 +28,7 @@ import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic import groovy.transform.CompileStatic
import org.gradle.api.InvalidUserDataException import org.gradle.api.InvalidUserDataException
import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Configuration
import org.ysb33r.grolifant.api.OperatingSystem import org.ysb33r.grolifant.api.core.OperatingSystem
import org.ysb33r.grolifant.api.core.ProjectOperations import org.ysb33r.grolifant.api.core.ProjectOperations
import org.ysb33r.grolifant.api.v4.StringUtils import org.ysb33r.grolifant.api.v4.StringUtils

View File

@ -24,7 +24,7 @@
package com.github.jrubygradle.internal package com.github.jrubygradle.internal
import org.gradle.api.InvalidUserDataException import org.gradle.api.InvalidUserDataException
import org.ysb33r.grolifant.api.OperatingSystem import org.ysb33r.grolifant.api.core.OperatingSystem
import spock.lang.Issue import spock.lang.Issue
import spock.lang.Specification import spock.lang.Specification

View File

@ -54,8 +54,8 @@ subprojects {
dependencies { dependencies {
compile localGroovy() compile localGroovy()
compile gradleApi() compile gradleApi()
compile "org.ysb33r.gradle:grolifant50:${grolifantVersion}" compile "org.ysb33r.gradle:grolifant60:${grolifantVersion}"
gradleTestRuntime "org.ysb33r.gradle:grolifant50:${grolifantVersion}" gradleTestRuntime "org.ysb33r.gradle:grolifant60:${grolifantVersion}"
} }
codenarc { codenarc {

View File

@ -136,7 +136,7 @@ abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTas
void exec() { void exec() {
File out = getOutputDir() File out = getOutputDir()
File jrubyJar = jrubyJarLocation.get() File jrubyJar = jrubyJarLocation.get()
extractGems(project, jrubyJar, gemsAsFileCollection(), out, SKIP) extractGems(projectOperations, jrubyJar, gemsAsFileCollection(), out, SKIP)
dependencies.findAll { dependencies.findAll {
it instanceof Configuration it instanceof Configuration

View File

@ -34,7 +34,7 @@ import groovy.transform.CompileStatic
import groovy.transform.InheritConstructors import groovy.transform.InheritConstructors
import groovy.transform.Synchronized import groovy.transform.Synchronized
import groovy.util.logging.Slf4j import groovy.util.logging.Slf4j
import org.ysb33r.grolifant.api.ExclusiveFileAccess import org.ysb33r.grolifant.api.core.ExclusiveFileAccess
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path

View File

@ -24,7 +24,7 @@
package com.github.jrubygradle.api.core package com.github.jrubygradle.api.core
import com.github.jrubygradle.internal.core.DefaultRubyGemRestApi import com.github.jrubygradle.internal.core.DefaultRubyGemRestApi
import org.ysb33r.grolifant.api.Version import org.ysb33r.grolifant.api.core.Version
import spock.lang.Specification import spock.lang.Specification
class RubyGemQueryRestApiSpec extends Specification { class RubyGemQueryRestApiSpec extends Specification {

View File

@ -25,9 +25,8 @@ task printSomePrettyOutputPlease(type: JRubyExec) {
script "${projectDir}/print-script.rb" script "${projectDir}/print-script.rb"
} }
/* /*
* This task is only here for the execution fo the gradleTest * This task is only here for the execution of the gradleTest
*/ */
task runGradleTest { task runGradleTest {
dependsOn printSomePrettyOutputPlease dependsOn printSomePrettyOutputPlease

View File

@ -1,4 +1,4 @@
version=2.1.0-alpha.1 version=2.1.0-alpha.2
group=com.github.jruby-gradle group=com.github.jruby-gradle
copyrightYear=2014-2020 copyrightYear=2014-2020
@ -14,7 +14,7 @@ releaseBuild=false
targetCompatibility=1.8 targetCompatibility=1.8
sourceCompatibility=1.8 sourceCompatibility=1.8
grolifantVersion=1.0.0-alpha.1 grolifantVersion=1.0.0-alpha.4
jrubyVersion=9.2.9.0 jrubyVersion=9.2.9.0
jettyVersion=9.2.12.v20150709 jettyVersion=9.2.12.v20150709
bcprovVersion=1.46 bcprovVersion=1.46

View File

@ -23,28 +23,34 @@
*/ */
package com.github.jrubygradle.jar package com.github.jrubygradle.jar
import com.github.jengelman.gradle.plugins.shadow.internal.DefaultZipCompressor
import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor
import com.github.jrubygradle.JRubyPrepare
/* /*
* These two internal imports from the Shadow plugin are unavoidable because of * These two internal imports from the Shadow plugin are unavoidable because of
* the expected internals of ShadowCopyAction * the expected internals of ShadowCopyAction
*/ */
import com.github.jengelman.gradle.plugins.shadow.internal.DefaultZipCompressor
import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor
import com.github.jrubygradle.JRubyPrepare
import com.github.jrubygradle.jar.internal.JRubyDirInfoTransformer import com.github.jrubygradle.jar.internal.JRubyDirInfoTransformer
import com.github.jrubygradle.jar.internal.JRubyJarCopyAction import com.github.jrubygradle.jar.internal.JRubyJarCopyAction
import groovy.transform.CompileDynamic
import groovy.transform.PackageScope import groovy.transform.PackageScope
import org.apache.tools.zip.ZipOutputStream import org.apache.tools.zip.ZipOutputStream
import org.gradle.api.InvalidUserDataException import org.gradle.api.InvalidUserDataException
import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.RegularFile
import org.gradle.api.internal.file.copy.CopyAction import org.gradle.api.internal.file.copy.CopyAction
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.StopExecutionException import org.gradle.api.tasks.StopExecutionException
import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.bundling.ZipEntryCompression import org.gradle.api.tasks.bundling.ZipEntryCompression
import org.ysb33r.grolifant.api.core.LegacyLevel
import org.ysb33r.grolifant.api.core.ProjectOperations
import static com.github.jrubygradle.JRubyPlugin.TASK_GROUP_NAME import static com.github.jrubygradle.JRubyPlugin.TASK_GROUP_NAME
@ -63,10 +69,31 @@ class JRubyJar extends Jar {
RUNNABLE, LIBRARY RUNNABLE, LIBRARY
} }
static final String DEFAULT_JRUBYJAR_CONFIG = 'jrubyJar' public static final String DEFAULT_JRUBYJAR_CONFIG = 'jrubyJar'
static final String DEFAULT_MAIN_CLASS = 'org.jruby.mains.JarMain' public static final String DEFAULT_MAIN_CLASS = 'org.jruby.mains.JarMain'
static final String EXTRACTING_MAIN_CLASS = 'org.jruby.mains.ExtractingMain' public static final String EXTRACTING_MAIN_CLASS = 'org.jruby.mains.ExtractingMain'
static final String DEFAULT_JRUBY_MAINS = '0.6.1' public static final String DEFAULT_JRUBY_MAINS = '0.6.1'
JRubyJar() {
projectOperations = ProjectOperations.create(project)
addJrubyAppendix()
/* Make sure our default configuration is present regardless of whether we use it or not */
prepareTask = project.task("prepare${prepareNameForSuffix(name)}", type: JRubyPrepare)
prepareTask.group TASK_GROUP_NAME
dependsOn prepareTask
group TASK_GROUP_NAME
// TODO get rid of this and try to adjust the CopySpec for the gems
// to exclude '.jrubydir'
// there are other duplicates as well :(
setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE)
customConfigName = "jrubyJarEmbeds-${hashCode()}"
project.afterEvaluate {
addJRubyDependency()
applyConfig()
}
}
/** /**
* @return Directory that the dependencies for this project will be staged into * @return Directory that the dependencies for this project will be staged into
@ -187,7 +214,7 @@ class JRubyJar extends Jar {
* Unrecognised values are silently discarded * Unrecognised values are silently discarded
* *
* @param defs A list of defaults. Currently {@code gems} and {@code mainClass} are the only recognised values. * @param defs A list of defaults. Currently {@code gems} and {@code mainClass} are the only recognised values.
* @deprecated This method is no longer very useful, just use {@link defaultMainClass} instead * @deprecated This method is no longer very useful, just use {@code defaultMainClass} instead
*/ */
@Deprecated @Deprecated
void defaults(final String... defs) { void defaults(final String... defs) {
@ -231,7 +258,7 @@ class JRubyJar extends Jar {
if (mainClass != null && scriptName != Type.LIBRARY) { if (mainClass != null && scriptName != Type.LIBRARY) {
Configuration embeds = project.configurations.findByName(customConfigName) Configuration embeds = project.configurations.findByName(customConfigName)
with project.copySpec { with projectOperations.copySpec {
embeds.each { File embed -> embeds.each { File embed ->
logger.info("unzipping ${embed} in the jar") logger.info("unzipping ${embed} in the jar")
/* We nede to extract the class files from jruby-mains in order to properly run */ /* We nede to extract the class files from jruby-mains in order to properly run */
@ -248,11 +275,11 @@ class JRubyJar extends Jar {
} }
if (scriptName != Type.RUNNABLE && scriptName != Type.LIBRARY) { if (scriptName != Type.RUNNABLE && scriptName != Type.LIBRARY) {
File script = project.file(scriptName) File script = projectOperations.file(scriptName)
if (!script.exists()) { if (!script.exists()) {
throw new InvalidUserDataException("initScript ${script} does not exists") throw new InvalidUserDataException("initScript ${script} does not exists")
} }
with project.copySpec { with projectOperations.copySpec {
from script.parent from script.parent
include script.name include script.name
rename(script.name, 'jar-bootstrap.rb') rename(script.name, 'jar-bootstrap.rb')
@ -270,26 +297,6 @@ class JRubyJar extends Jar {
Type.RUNNABLE Type.RUNNABLE
} }
JRubyJar() {
appendix = 'jruby'
/* Make sure our default configuration is present regardless of whether we use it or not */
prepareTask = project.task("prepare${prepareNameForSuffix(name)}", type: JRubyPrepare)
prepareTask.group TASK_GROUP_NAME
dependsOn prepareTask
group TASK_GROUP_NAME
// TODO get rid of this and try to adjust the CopySpec for the gems
// to exclude '.jrubydir'
// there are other duplicates as well :(
setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE)
customConfigName = "jrubyJarEmbeds-${hashCode()}"
project.afterEvaluate {
addJRubyDependency()
applyConfig()
}
}
/** /**
* Adds our jruby-complete to a custom configuration only so it can be * Adds our jruby-complete to a custom configuration only so it can be
* safely unzipped later when we build the jar * safely unzipped later when we build the jar
@ -304,10 +311,10 @@ class JRubyJar extends Jar {
/** Update the staging directory and tasks responsible for setting it up */ /** Update the staging directory and tasks responsible for setting it up */
void updateStageDirectory() { void updateStageDirectory() {
File dir = project.file("${project.buildDir}/dirinfo/${configuration}") File dir = projectOperations.file("${project.buildDir}/dirinfo/${configuration}")
prepareTask.dependencies project.configurations.maybeCreate(configuration) prepareTask.dependencies project.configurations.maybeCreate(configuration)
prepareTask.outputDir dir prepareTask.outputDir(dir)
logger.info("${this} including files in ${dir}") logger.info("${this} including files in ${dir}")
from(dir) { from(dir) {
@ -315,6 +322,30 @@ class JRubyJar extends Jar {
} }
} }
@Internal
protected Object scriptName
@Internal
protected JRubyPrepare prepareTask
@Internal
protected String customConfigName
@Internal
protected String embeddedJRubyVersion
@Internal
protected String embeddedJRubyMainsVersion = DEFAULT_JRUBY_MAINS
@Internal
protected String jarConfiguration = DEFAULT_JRUBYJAR_CONFIG
@Internal
protected String jarMainClass
@Internal
protected final ProjectOperations projectOperations
/** /**
* Provide a custom {@link CopyAction} to insert .jrubydir files into the archive. * Provide a custom {@link CopyAction} to insert .jrubydir files into the archive.
* *
@ -325,17 +356,18 @@ class JRubyJar extends Jar {
*/ */
@Override @Override
protected CopyAction createCopyAction() { protected CopyAction createCopyAction() {
return new JRubyJarCopyAction(getArchivePath(), new JRubyJarCopyAction(
getInternalCompressor(), getArchiveProviderSafely(),
null, /* DocumentationRegistry */ getInternalCompressor(),
'utf-8', /* encoding */ null, /* DocumentationRegistry */
[new JRubyDirInfoTransformer()], /* transformers */ 'utf-8', /* encoding */
[], /* relocators */ [new JRubyDirInfoTransformer()], /* transformers */
mainSpec.buildRootResolver().getPatternSet(), /* patternSet */ [], /* relocators */
false, /* preserveFileTimestamps */ mainSpec.buildRootResolver().getPatternSet(), /* patternSet */
false, /* minimizeJar */ false, /* preserveFileTimestamps */
null /* unusedTracker */ false, /* minimizeJar */
) null /* unusedTracker */
)
} }
@ -363,11 +395,22 @@ class JRubyJar extends Jar {
return baseName.replaceAll('(?i)jruby', 'JRuby').capitalize() return baseName.replaceAll('(?i)jruby', 'JRuby').capitalize()
} }
protected Object scriptName @CompileDynamic
protected JRubyPrepare prepareTask private Provider<File> getArchiveProviderSafely() {
protected String customConfigName if (LegacyLevel.PRE_5_1) {
protected String embeddedJRubyVersion projectOperations.provider { -> archivePath }
protected String embeddedJRubyMainsVersion = DEFAULT_JRUBY_MAINS } else {
protected String jarConfiguration = DEFAULT_JRUBYJAR_CONFIG archiveFile.map { RegularFile it -> it.asFile }
protected String jarMainClass }
}
@CompileDynamic
@SuppressWarnings('DuplicateStringLiteral')
private void addJrubyAppendix() {
if (LegacyLevel.PRE_5_1) {
appendix = 'jruby'
} else {
archiveAppendix.set('jruby')
}
}
} }

View File

@ -24,6 +24,7 @@
package com.github.jrubygradle.jar.internal package com.github.jrubygradle.jar.internal
import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper
import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker
/* /*
* This source code is derived from Apache 2.0 licensed software copyright John * This source code is derived from Apache 2.0 licensed software copyright John
@ -31,7 +32,6 @@ import com.github.jengelman.gradle.plugins.shadow.impl.RelocatorRemapper
* repository: https://github.com/johnrengelman/shadow * repository: https://github.com/johnrengelman/shadow
*/ */
import com.github.jengelman.gradle.plugins.shadow.internal.UnusedTracker
import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor import com.github.jengelman.gradle.plugins.shadow.internal.ZipCompressor
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
@ -50,6 +50,7 @@ import org.gradle.api.internal.file.DefaultFileTreeElement
import org.gradle.api.internal.file.copy.CopyAction import org.gradle.api.internal.file.copy.CopyAction
import org.gradle.api.internal.file.copy.CopyActionProcessingStream import org.gradle.api.internal.file.copy.CopyActionProcessingStream
import org.gradle.api.internal.file.copy.FileCopyDetailsInternal import org.gradle.api.internal.file.copy.FileCopyDetailsInternal
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.WorkResult import org.gradle.api.tasks.WorkResult
import org.gradle.api.tasks.WorkResults import org.gradle.api.tasks.WorkResults
import org.gradle.api.tasks.bundling.Zip import org.gradle.api.tasks.bundling.Zip
@ -86,7 +87,7 @@ import java.util.zip.ZipException
class JRubyJarCopyAction implements CopyAction { class JRubyJarCopyAction implements CopyAction {
static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = (new GregorianCalendar(1980, 1, 1, 0, 0, 0)).timeInMillis static final long CONSTANT_TIME_FOR_ZIP_ENTRIES = (new GregorianCalendar(1980, 1, 1, 0, 0, 0)).timeInMillis
private final File zipFile private final Provider<File> zipFile
private final ZipCompressor compressor private final ZipCompressor compressor
private final DocumentationRegistry documentationRegistry private final DocumentationRegistry documentationRegistry
private final List<Transformer> transformers private final List<Transformer> transformers
@ -97,7 +98,7 @@ class JRubyJarCopyAction implements CopyAction {
private final boolean minimizeJar private final boolean minimizeJar
private final UnusedTracker unusedTracker private final UnusedTracker unusedTracker
JRubyJarCopyAction(File zipFile, ZipCompressor compressor, DocumentationRegistry documentationRegistry, JRubyJarCopyAction(Provider<File> zipFile, ZipCompressor compressor, DocumentationRegistry documentationRegistry,
String encoding, List<Transformer> transformers, List<Relocator> relocators, String encoding, List<Transformer> transformers, List<Relocator> relocators,
PatternSet patternSet, PatternSet patternSet,
boolean preserveFileTimestamps, boolean minimizeJar, UnusedTracker unusedTracker) { boolean preserveFileTimestamps, boolean minimizeJar, UnusedTracker unusedTracker) {
@ -133,8 +134,9 @@ class JRubyJarCopyAction implements CopyAction {
unusedClasses = Collections.emptySet() unusedClasses = Collections.emptySet()
} }
File zipFileResolved = zipFile.get()
try { try {
final ZipOutputStream zipOutStr = compressor.createArchiveOutputStream(zipFile) final ZipOutputStream zipOutStr = compressor.createArchiveOutputStream(zipFileResolved)
withResource(zipOutStr, new Action<ZipOutputStream>() { withResource(zipOutStr, new Action<ZipOutputStream>() {
void execute(ZipOutputStream outputStream) { void execute(ZipOutputStream outputStream) {
try { try {
@ -156,7 +158,7 @@ class JRubyJarCopyAction implements CopyAction {
) )
} }
} catch (Exception e) { } catch (Exception e) {
throw new GradleException("Could not create ZIP '${zipFile.toString()}'", e) throw new GradleException("Could not create ZIP '${zipFileResolved}'", e)
} }
return WorkResults.didWork(true) return WorkResults.didWork(true)
} }
@ -273,7 +275,7 @@ class JRubyJarCopyAction implements CopyAction {
} }
recordVisit(fileDetails.relativePath) recordVisit(fileDetails.relativePath)
} catch (Exception e) { } catch (Exception e) {
throw new GradleException(String.format("Could not add %s to ZIP '%s'.", fileDetails, zipFile), e) throw new GradleException(String.format("Could not add %s to ZIP '%s'.", fileDetails, zipFile.get()), e)
} }
} }
@ -357,7 +359,7 @@ class JRubyJarCopyAction implements CopyAction {
zipOutStr.closeEntry() zipOutStr.closeEntry()
recordVisit(dirDetails.relativePath) recordVisit(dirDetails.relativePath)
} catch (Exception e) { } catch (Exception e) {
throw new GradleException(String.format("Could not add %s to ZIP '%s'.", dirDetails, zipFile), e) throw new GradleException(String.format("Could not add %s to ZIP '%s'.", dirDetails, zipFile.get()), e)
} }
} }