Skip to content

Commit

Permalink
Merge pull request #675 from asciidoctor/schalk/grolifant-2
Browse files Browse the repository at this point in the history
Remove most deprecated Grolifant 2.0 APIs
  • Loading branch information
ysb33r authored Jan 4, 2024
2 parents b061409 + 6157479 commit a0892a7
Show file tree
Hide file tree
Showing 232 changed files with 6,537 additions and 3,886 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ jobs:
with:
arguments: --console=plain --warning-mode=all -s clean assemble
# Test
# TODO: Resolve the gem integration test issue. See https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/694
- name: Test
uses: gradle/gradle-build-action@v2
with:
arguments: --console=plain --warning-mode=all -s check --no-parallel -Djava.net.preferIPv4Stack=true -x gradleTest --scan
arguments: --console=plain --warning-mode=all -s check --no-parallel -Djava.net.preferIPv4Stack=true -x gradleTest -x :asciidoctor-gradle-jvm-gems:IntTest --scan
# Stop gradlew to avoid locking issues
- name: Cleanup
uses: gradle/gradle-build-action@v2
Expand Down Expand Up @@ -88,13 +89,16 @@ jobs:
- name: Integration tests (without slides)
uses: gradle/gradle-build-action@v2
with:
arguments: -i -s --console=plain --no-build-cache test intTest remoteTest -x asciidoctor-gradle-slides-export:intTest -x asciidoctor-gradle-jvm-slides:intTest
arguments: -i -s --console=plain --no-build-cache test intTest remoteTest --scan
# arguments: -i -s --console=plain --no-build-cache test intTest remoteTest -x asciidoctor-gradle-jvm-slides:intTest
# arguments: -i -s --console=plain --no-build-cache test intTest remoteTest -x asciidoctor-gradle-slides-export:intTest -x asciidoctor-gradle-jvm-slides:intTest
# TODO: See https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/695
# - name: Integration tests (slides only)
# uses: eskatos/gradle-command-action@v1
# uses: eskatos/gradle-command-action@v2
# with:
# arguments: -i -s --console=plain --no-build-cache test asciidoctor-gradle-jvm-slides:intTest asciidoctor-gradle-slides-export:intTest
# Gradle tests
- name: Gradle tests
uses: gradle/gradle-build-action@v2
with:
arguments: -i -s --console=plain --no-build-cache gradleTest
arguments: -i -s --console=plain --no-build-cache gradleTest --scan
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ out
buildSrc/gradle/wrapper
buildSrc/gradlew*
.asciidoctor-module-versions.generated

.generated-src/
# Because we auto-generate this from the main project
# and it is only needed for IntelliJ
docs/gradle/wrapper
Expand Down
3 changes: 3 additions & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=8.0.302-open
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= Asciidoctor Gradle Plugin
Andres Almiray <https://github.com/aalmiray[@aalmiray]>
:version: 3.3.2
:version-published: 3.3.2
:version: 4.0.0
:version-published: 4.0.0-alpha.1
:asciidoc-url: http://asciidoc.org
:asciidoctor-url: http://asciidoctor.org
:issues: https://github.com/asciidoctor/asciidoctor-maven-plugin/issues
Expand All @@ -20,7 +20,7 @@ Andres Almiray <https://github.com/aalmiray[@aalmiray]>
:plugin-name: Asciidoctor Gradle plugin
:project-name: asciidoctor-gradle-plugin
:project-full-path: asciidoctor/asciidoctor-gradle-plugin
:github-branch: development-3.x
:github-branch: development-4.x
:linkattrs:
ifndef::env-github[:icons: font]
ifdef::env-github,env-browser[]
Expand Down
19 changes: 10 additions & 9 deletions asciidoctoreditorconfig/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
configurations {
additionalPluginClasspath
agProject {
withAdditionalPluginClasspath()

configurePlugin(
'org.asciidoctor.editorconfig',
'Asciidoctor Editor Config Plugin',
'Generate .asciidoctorconfig files for use by supported IDEs',
'org.asciidoctor.gradle.editorconfig.AsciidoctorEditorConfigPlugin',
['intellij', 'idea']
)
}

dependencies {
implementation project(':asciidoctor-gradle-base')
additionalPluginClasspath project(':asciidoctor-gradle-jvm')
}

pluginUnderTestMetadata {
pluginClasspath.from configurations.additionalPluginClasspath
}

configurePlugin 'org.asciidoctor.editorconfig',
'Asciidoctor Editor Config Plugin',
'Generate .asciidoctorconfig files for use by supported IDEs',
['asciidoctor', 'intellij', 'idea']

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2023 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@ class AsciidoctorEditorConfigIntegrationSpec extends FunctionalSpecification {
String groupName = 'the.group'
String projVer = '1.0.0'

File attrFile = new File(testProjectDir.root, 'inputs.adoc')
File attrFile = new File(projectDir, 'inputs.adoc')
attrFile.text = ":${key3}: ${value3}\n"

getGroovyBuildFile("""
Expand All @@ -51,23 +51,23 @@ class AsciidoctorEditorConfigIntegrationSpec extends FunctionalSpecification {
}
""")

File outputFile = new File(testProjectDir.root, '.asciidoctorconfig')
new File(testProjectDir.root, 'settings.gradle').text = "rootProject.name='${projName}'"
File outputFile = new File(projectDir, '.asciidoctorconfig')
settingsFile.text = "rootProject.name='${projName}'"

when:
getGradleRunner(['asciidoctorEditorConfig']).build()

then:
normalisedLineEndings(outputFile.text) == """:${key1}: ${value1}
:gradle-project-name: ${projName}
:gradle-project-group: ${groupName}
:gradle-project-version: ${projVer}
:gradle-project-name: ${projName}
:${key2}: ${value2}
:gradle-project-group: ${groupName}
:${key3}: ${value3}
"""
}

String normalisedLineEndings(String text) {
text.replaceAll('\\r', '')
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2023 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,56 +17,50 @@ package org.asciidoctor.gradle.editorconfig.internal

import groovy.transform.CompileStatic
import org.apache.commons.io.FileUtils
import org.asciidoctor.gradle.testfixtures.DslType
import org.asciidoctor.gradle.testfixtures.FunctionalTestFixture
import org.asciidoctor.gradle.testfixtures.FunctionalTestSetup
import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
import spock.lang.TempDir

import static org.asciidoctor.gradle.testfixtures.DslType.GROOVY_DSL
import static org.asciidoctor.gradle.testfixtures.DslType.KOTLIN_DSL
import static org.asciidoctor.gradle.testfixtures.FunctionalTestSetup.getOfflineRepositoriesGroovyDsl
import static org.asciidoctor.gradle.testfixtures.FunctionalTestSetup.getOfflineRepositoriesKotlinDsl

class FunctionalSpecification extends Specification {
class FunctionalSpecification extends Specification implements FunctionalTestFixture {

public static final String TEST_PROJECTS_DIR = System.getProperty(
'TEST_PROJECTS_DIR',
'./asciidoctoreditorconfig/src/intTest/projects'
'TEST_PROJECTS_DIR',
'./asciidoctoreditorconfig/src/intTest/projects'
)

public static final String TEST_REPO_DIR = System.getProperty(
'OFFLINE_REPO',
'./testfixtures/offline-repo/build/repo'
'OFFLINE_REPO',
'./testfixtures/offline-repo/build/repo'
)

@Rule
TemporaryFolder testProjectDir
@TempDir
File testProjectDir

void setup() {
projectDir.mkdirs()
}

@CompileStatic
GradleRunner getGradleRunner(List<String> taskNames = ['tasks']) {
FunctionalTestSetup.getGradleRunner(GROOVY_DSL, testProjectDir.root, taskNames)
FunctionalTestSetup.getGradleRunner(GROOVY_DSL, projectDir, taskNames)
}

@CompileStatic
GradleRunner getGradleRunnerForKotlin(List<String> taskNames = ['tasks']) {
FunctionalTestSetup.getGradleRunner(KOTLIN_DSL, testProjectDir.root, taskNames)
FunctionalTestSetup.getGradleRunner(KOTLIN_DSL, projectDir, taskNames)
}

@SuppressWarnings(['BuilderMethodWithSideEffects'])
void createTestProject(String docGroup = 'normal') {
FileUtils.copyDirectory(new File(TEST_PROJECTS_DIR, docGroup), testProjectDir.root)
}

@CompileStatic
String getOfflineRepositories(DslType dslType = GROOVY_DSL) {
dslType == GROOVY_DSL ? getOfflineRepositoriesGroovyDsl(new File(TEST_REPO_DIR)) :
getOfflineRepositoriesKotlinDsl(new File(TEST_REPO_DIR))
FileUtils.copyDirectory(new File(TEST_PROJECTS_DIR, docGroup), projectDir)
}

File getGroovyBuildFile(String extraContent, String plugin = 'org.asciidoctor.editorconfig') {
File buildFile = testProjectDir.newFile('build.gradle')
buildFile << """
plugins {
id '${plugin}'
Expand All @@ -80,8 +74,7 @@ class FunctionalSpecification extends Specification {
}

File getKotlinBuildFile(String extraContent, String plugin = 'org.asciidoctor.editorconfig') {
File buildFile = testProjectDir.newFile('build.gradle.kts')
buildFile << """
buildFileKts << """
plugins {
id("${plugin}")
}
Expand All @@ -90,7 +83,7 @@ class FunctionalSpecification extends Specification {
${extraContent}
"""
buildFile
buildFileKts
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2023 the original author or authors.
* Copyright 2013-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,12 +26,12 @@ import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
import org.ysb33r.grolifant.api.core.ProjectOperations

import java.util.concurrent.Callable

import static org.ysb33r.grolifant.api.v4.MapUtils.stringizeValues

/** Generates {@code .asciidoctorconfig} file.
/**
* Generates {@code .asciidoctorconfig} file.
*
* When the file is generated attributes are applied in the following order.
* <ol>
Expand All @@ -51,16 +51,19 @@ class AsciidoctorEditorConfigGenerator extends DefaultTask {
private final List<Provider<File>> fileProviders = []
private final List<Provider<Map<String, String>>> attributeProviders = []
private final Provider<File> outputFile
private final ProjectOperations projectOperations
private Object outputDir

AsciidoctorEditorConfigGenerator() {
this.projectOperations = ProjectOperations.find(project)
this.outputDir = project.projectDir
this.outputFile = project.provider({
new File(destinationDir, '.asciidoctorconfig')
} as Callable<File>)
}

/** Replace existing attributes with a new set.
/**
* Replace existing attributes with a new set.
*
* @param attrs Replacement attributes
*/
Expand All @@ -69,7 +72,8 @@ class AsciidoctorEditorConfigGenerator extends DefaultTask {
this.attributes.putAll(attrs)
}

/** Add more attributes to the existing set
/**
* Add more attributes to the existing set
*
* @param attrs Additional attributes.
*/
Expand All @@ -83,23 +87,23 @@ class AsciidoctorEditorConfigGenerator extends DefaultTask {
*/
@Input
Map<String, String> getAttributes() {
stringizeValues(this.attributes)
projectOperations.stringTools.stringizeValues(this.attributes)
}

/** Add an additional attribute provider.
/**
* Add an additional attribute provider.
*
* A provider can be a file of something that implements {@link AsciidoctorAttributeProvider} (such as
* an {@code asciidoctorj} or {@code asciidoctorjs extension}).
*
*
* @param attrs Anything convertible to a file using {@code project.file} or that implements
* {@link AsciidoctorAttributeProvider}.
*/
void additionalAttributes(Object attrs) {
switch (attrs) {
case AsciidoctorAttributeProvider:
this.attributeProviders.add(project.provider({
stringizeValues(((AsciidoctorAttributeProvider) attrs).attributes)
this.attributeProviders.add(projectOperations.provider({
projectOperations.stringTools.stringizeValues(((AsciidoctorAttributeProvider) attrs).attributes)
} as Callable<Map<String, String>>))
break
default:
Expand All @@ -109,7 +113,8 @@ class AsciidoctorEditorConfigGenerator extends DefaultTask {
}
}

/** Returns list of file providers.
/**
* Returns list of file providers.
*
* Content of these files will simply be appended to the genrated content.
*
Expand All @@ -121,7 +126,8 @@ class AsciidoctorEditorConfigGenerator extends DefaultTask {
this.fileProviders
}

/** Returns list of attribute providers. THese providers will return attributes as key-value pairs.
/**
* Returns list of attribute providers. THese providers will return attributes as key-value pairs.
*
* @return List of attribute providers
*/
Expand All @@ -130,24 +136,27 @@ class AsciidoctorEditorConfigGenerator extends DefaultTask {
this.attributeProviders
}

/** Destination directory. Defaults to the project directory.
/**
* Destination directory. Defaults to the project directory.
*
* @return Directory
*/
@Internal
File getDestinationDir() {
project.file(this.outputDir)
projectOperations.fsOperations.file(this.outputDir)
}

/** Sets destination directory.
/**
* Sets destination directory.
*
* @param dir Anything convertible to a directory using {@code project.file}.
*/
void setDestinationDir(Object dir) {
this.outputDir = dir
}

/** Location of generated {@code .asciidoctorconfig} file.
/**
* Location of generated {@code .asciidoctorconfig} file.
*
* @return File location.
*/
Expand All @@ -159,8 +168,9 @@ class AsciidoctorEditorConfigGenerator extends DefaultTask {
@TaskAction
void exec() {
outputFile.get().withWriter { w ->
getAttributes().each { k, v ->
w.println ":${k}: ${v}"
Map<String,String> attrs = getAttributes()
attrs.keySet().sort().each { String k ->
w.println ":${k}: ${attrs[k]}"
}

additionalAttributeProviders.each { prov ->
Expand Down
Loading

0 comments on commit a0892a7

Please sign in to comment.