Skip to content

Commit

Permalink
When a JRuby version is explicitly named, force to that version.
Browse files Browse the repository at this point in the history
See: #709
  • Loading branch information
ysb33r committed Jan 26, 2024
1 parent 1e16f31 commit 82d2a2b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 4.0.1
version = 4.0.2
group = org.asciidoctor

copyrightYear = 2013-2024
Expand Down
2 changes: 1 addition & 1 deletion jvm-epub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ generateModuleVersions {
}

dependencies {
implementation project(':asciidoctor-gradle-jvm')
api project(':asciidoctor-gradle-jvm')

intTestOfflineRepo "org.asciidoctor:asciidoctorj:${compileOnlyAsciidoctorJVersion}"
intTestOfflineRepo "org.asciidoctor:asciidoctorj-epub3:${downloadOnlyEpubVersion}"
Expand Down
2 changes: 1 addition & 1 deletion jvm-pdf/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ agProject {
}

dependencies {
implementation project(':asciidoctor-gradle-jvm')
api project(':asciidoctor-gradle-jvm')
intTestOfflineRepo "org.asciidoctor:asciidoctorj:${compileOnlyAsciidoctorJVersion}"
intTestOfflineRepo "org.asciidoctor:asciidoctorj-pdf:${downloadOnlyPdfVersion}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import java.util.regex.Pattern
import static groovy.lang.Closure.DELEGATE_FIRST
import static org.ysb33r.grolifant.api.core.ClosureUtils.configureItem

/** Extension for configuring AsciidoctorJ.
/**
* Extension for configuring AsciidoctorJ.
*
* It can be used as both a project and a task extension.
*
Expand Down Expand Up @@ -85,7 +86,7 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension {
private final BiFunction<String, Closure, Dependency> dependencyCreator
private final Function<Project, Dependency> projectDependency
private Object version
private Optional<Object> jrubyVersion
private Optional<Object> jrubyVersionProvider
private boolean onlyTaskOptions = false
private boolean onlyTaskExtensions = false
private boolean onlyTaskWarnings = false
Expand Down Expand Up @@ -381,27 +382,29 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension {
*/
String getJrubyVersion() {
if (task) {
if (this.jrubyVersion != null && this.jrubyVersion.present) {
projectOperations.stringTools.stringize(this.jrubyVersion.get())
if (this.jrubyVersionProvider != null && this.jrubyVersionProvider.present) {
projectOperations.stringTools.stringize(this.jrubyVersionProvider.get())
} else {
extFromProject.getJrubyVersion()
extFromProject.jrubyVersion
}
} else {
this.jrubyVersion?.present ? projectOperations.stringTools.stringize(this.jrubyVersion.get()) : null
this.jrubyVersionProvider?.present ?
projectOperations.stringTools.stringize(this.jrubyVersionProvider.get()) : null
}
}

/** Set a version of JRuby to use.
*
* The version specified is not a guarantetd version, simply a minimum required version.
* The version specified is not a guaranteed version, simply a minimum required version.
* If the version of asciidoctorj is dependent on a version later than the one specified
* here, then that would be used instead. In such cases iif the exact version needs to be
* here, then that would be used instead. In such cases if the exact version needs to be
* forced then a resolution strategy needs to be provided via {@link #resolutionStrategy}.
*
* @param v JRuby version
*/
void setJrubyVersion(Object v) {
this.jrubyVersion = Optional.of(v)
this.jrubyVersionProvider = Optional.of(v)
updateConfiguration()
}

/* -------------------------
Expand Down Expand Up @@ -623,6 +626,7 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension {
*/
void setVersion(Object v) {
this.version = v
updateConfiguration()
}

/**
Expand All @@ -643,8 +647,13 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension {
*/
void loadJRubyResolutionStrategy(Configuration cfg) {
cfg.resolutionStrategy.eachDependency { DependencyResolveDetails dsr ->
if (dsr.target.name == 'jruby' && dsr.target.group == 'org.jruby') {
dsr.useTarget "${JRUBY_COMPLETE_DEPENDENCY}:${dsr.target.version}"
if (dsr.requested.name == 'jruby' && dsr.requested.group == 'org.jruby') {
dsr.useTarget "${JRUBY_COMPLETE_DEPENDENCY}:${dsr.requested.version}"
}

String req = "${dsr.requested.group}:${dsr.requested.name}"
if (JRUBY_COMPLETE_DEPENDENCY == req && jrubyVersion) {
dsr.useVersion jrubyVersion
}
}
}
Expand Down Expand Up @@ -699,11 +708,6 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension {
}
}

@SuppressWarnings(['UnusedPrivateMethodParameter', 'UnusedPrivateMethod'])
private String minimumSafeJRubyVersion(final String asciidoctorjVersion) {
'9.1.0.0'
}

@SuppressWarnings('Instanceof')
private List<Pattern> patternize(final List<Object> patterns) {
Transform.toList(patterns) {
Expand All @@ -728,8 +732,12 @@ class AsciidoctorJExtension extends AbstractImplementationEngineExtension {
final String diagramVer = finalDiagramVersion

loadDependencyRuleOnce(ASCIIDOCTORJ_CORE_DEPENDENCY) { -> owner.version }
loadDependencyRuleOnce(JRUBY_COMPLETE_DEPENDENCY) { ->
owner.getJrubyVersion() ?: owner.minimumSafeJRubyVersion(owner.getVersion())

if (jrubyVersionProvider?.present) {
loadDependencyRuleOnce(
JRUBY_COMPLETE_DEPENDENCY,
{ Optional x -> x.get() }.curry(jrubyVersionProvider) as Callable<String>
)
}

if (gDslVer != null) {
Expand Down

0 comments on commit 82d2a2b

Please sign in to comment.