From 84f74af7510865dd489f12a158dcada3f664a552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Sun, 14 Apr 2019 19:53:29 +0200 Subject: [PATCH] Remove deprecated compatibility tasks (#343) --- asciidoctor-gradle-jvm/build.gradle | 5 - .../compat-plugin-still-works/build.gradle | 19 - .../src/docs/asciidoc/test.adoc | 3 - .../compat/AsciidoctorFunctionalSpec.groovy | 237 ------ ...mpatExtensionMultiuseFunctionalSpec.groovy | 88 -- .../compat/ExtensionsFunctionalSpec.groovy | 166 ---- .../asciidoctor/gradle/AsciidoctorTask.groovy | 39 - .../gradle/compat/AsciidoctorBackend.groovy | 57 -- .../AsciidoctorCompatibilityPlugin.groovy | 170 ---- .../AsciidoctorCompatibilityTask.groovy | 797 ------------------ .../gradle/compat/AsciidoctorExtension.groovy | 47 -- .../org.asciidoctor.convert.properties | 17 - .../compat/AsciidoctorExtensionSpec.groovy | 43 - .../compat/AsciidoctorPluginSpec.groovy | 127 --- .../gradle/compat/AsciidoctorTaskSpec.groovy | 515 ----------- 15 files changed, 2330 deletions(-) delete mode 100644 asciidoctor-gradle-jvm/src/gradleTest/compat-plugin-still-works/build.gradle delete mode 100644 asciidoctor-gradle-jvm/src/gradleTest/compat-plugin-still-works/src/docs/asciidoc/test.adoc delete mode 100755 asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/AsciidoctorFunctionalSpec.groovy delete mode 100644 asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/CompatExtensionMultiuseFunctionalSpec.groovy delete mode 100644 asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/ExtensionsFunctionalSpec.groovy delete mode 100755 asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/AsciidoctorTask.groovy delete mode 100755 asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorBackend.groovy delete mode 100755 asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityPlugin.groovy delete mode 100755 asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityTask.groovy delete mode 100644 asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorExtension.groovy delete mode 100644 asciidoctor-gradle-jvm/src/main/resources/META-INF/gradle-plugins/org.asciidoctor.convert.properties delete mode 100644 asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorExtensionSpec.groovy delete mode 100755 asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorPluginSpec.groovy delete mode 100755 asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorTaskSpec.groovy diff --git a/asciidoctor-gradle-jvm/build.gradle b/asciidoctor-gradle-jvm/build.gradle index c4d350ab3..6d4d6ba60 100644 --- a/asciidoctor-gradle-jvm/build.gradle +++ b/asciidoctor-gradle-jvm/build.gradle @@ -47,11 +47,6 @@ configurePlugin 'org.asciidoctor.jvm.base', 'Base plugin for all AsciidoctorJ tasks & extensions. Provides the asciidoctorj project extension.', ['asciidoctorj'] -configurePlugin 'org.asciidoctor.convert', - 'AsciidoctorJ Compatibility Plugin', - 'Compatibility AsciidoctorJ plugin for those upgrading from 1.5.x', - ['asciidoctorj', 'html5', 'docbook', 'pdf', 'epub3'] - configurePlugin 'org.asciidoctor.jvm.convert', 'AsciidoctorJ General Purpose Document Conversion Plugin', 'Provides asciidoctor task and conventions', diff --git a/asciidoctor-gradle-jvm/src/gradleTest/compat-plugin-still-works/build.gradle b/asciidoctor-gradle-jvm/src/gradleTest/compat-plugin-still-works/build.gradle deleted file mode 100644 index b9c6fa4d9..000000000 --- a/asciidoctor-gradle-jvm/src/gradleTest/compat-plugin-still-works/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id 'org.asciidoctor.convert' -} - -asciidoctor { - sources { - include 'test.adoc' - } - - legacyAttributes = true -} - -task runGradleTest { - dependsOn asciidoctor - - doLast { - assert file("${buildDir}/asciidoc/html5/test.html").exists() - } -} \ No newline at end of file diff --git a/asciidoctor-gradle-jvm/src/gradleTest/compat-plugin-still-works/src/docs/asciidoc/test.adoc b/asciidoctor-gradle-jvm/src/gradleTest/compat-plugin-still-works/src/docs/asciidoc/test.adoc deleted file mode 100644 index 0f8a39e2c..000000000 --- a/asciidoctor-gradle-jvm/src/gradleTest/compat-plugin-still-works/src/docs/asciidoc/test.adoc +++ /dev/null @@ -1,3 +0,0 @@ -= Test file - -Check that compatibility plugins still works \ No newline at end of file diff --git a/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/AsciidoctorFunctionalSpec.groovy b/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/AsciidoctorFunctionalSpec.groovy deleted file mode 100755 index 1a1ef63a9..000000000 --- a/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/AsciidoctorFunctionalSpec.groovy +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import org.asciidoctor.gradle.internal.FunctionalSpecification -import org.gradle.testkit.runner.BuildResult -import org.gradle.testkit.runner.TaskOutcome - -import java.util.regex.Pattern - -/** - * This was first functional specification. It is now the functional sepcification to ensure that - * the compatibility plugin and task in 2.x still functions correctly. - * - * @author Peter Ledbrook - * @author Schalk W. Cronjé - */ -class AsciidoctorFunctionalSpec extends FunctionalSpecification { - - static final String ASCIIDOCTOR_TASK = 'asciidoctor' - static final String ASCIIDOCTOR_PATH = ':asciidoctor' - static final String ASCIIDOC_SAMPLE_FILE = 'sample.asciidoc' - static final String ASCIIDOC_INVALID_FILE = 'subdir/_include.adoc' - static final Pattern DOCINFO_FILE_PATTERN = ~/^(.+\-)?docinfo(-footer)?\.[^.]+$/ - - File buildDir - - void setup() { - createTestProject('normal') - buildDir = new File(testProjectDir.root, 'build') - } - - void 'Should do nothing with an empty project'() { - given: 'A minimal build file' - getBuildFile(''' - asciidoctor { - sourceDir 'non-existing' - } -''') - - when: - BuildResult result = runGradle() - - then: - result.task(ASCIIDOCTOR_PATH).outcome == TaskOutcome.NO_SOURCE - } - - void 'Should build normally for a standard project'() { - given: 'A minimal build file' - getBuildFile('') - - when: - BuildResult result = runGradle() - - then: - result.task(ASCIIDOCTOR_PATH).outcome == TaskOutcome.SUCCESS - new File(buildDir, 'asciidoc/html5/sample.html').exists() - new File(buildDir, 'asciidoc/html5/subdir/sample2.html').exists() - } - - void 'Task should be up-to-date when executed a second time'() { - given: 'A minimal build file' - getBuildFile('') - - when: - runGradle() - BuildResult result = runGradle() - - then: - result.task(ASCIIDOCTOR_PATH).outcome == TaskOutcome.UP_TO_DATE - } - - void 'Task should not be up-to-date when classpath is changed'() { - given: 'A minimal build file' - getBuildFile(''' - if (project.hasProperty('modifyClasspath')) { - dependencies { - asciidoctor 'org.jsoup:jsoup:1.11.2' - } - } - ''') - - when: - runGradle() - BuildResult result = getGradleRunner([ASCIIDOCTOR_TASK, '-PmodifyClasspath']).build() - - then: - result.task(ASCIIDOCTOR_PATH).outcome == TaskOutcome.SUCCESS - } - - void 'Should build normally for a standard project with multiple backends'() { - given: 'A minimal build file' - getBuildFile(''' - asciidoctor { - backends 'html5', 'docbook' - } - ''') - - when: - BuildResult result = runGradle() - - then: - verifyAll { - result.task(ASCIIDOCTOR_PATH).outcome == TaskOutcome.SUCCESS - new File(buildDir, 'asciidoc/html5/sample.html').exists() - new File(buildDir, 'asciidoc/html5/subdir/sample2.html').exists() - new File(buildDir, 'asciidoc/docbook/sample.xml').exists() - new File(buildDir, 'asciidoc/docbook/subdir/sample2.xml').exists() - } - } - - void 'Processes a single document given a value for sourceDocumentName'() { - given: - getBuildFile(""" - asciidoctor { - sources { - include '${ASCIIDOC_SAMPLE_FILE}' - } - } - """) - - when: - runGradle() - - then: - new File(buildDir, 'asciidoc/html5/sample.html').exists() - !new File(buildDir, 'asciidoc/html5/subdir/sample2.html').exists() - } - - void 'Docinfo files are not copied to target directory'() { - given: - getBuildFile('') - - when: - runGradle(['asciidoctor', '-i']) - - then: - !new File(buildDir, 'asciidoctor/html5').listFiles({ - !it.directory && !(it.name =~ DOCINFO_FILE_PATTERN) - } as FileFilter) - } - - void 'When resources not specified, then copy all images to backend'() { - given: - getBuildFile(""" - asciidoctor { - sources { - include '${ASCIIDOC_SAMPLE_FILE}' - } - } - """) - - when: - runGradle() - - then: - new File(buildDir, 'asciidoc/html5/images/fake.txt').exists() - new File(buildDir, 'asciidoc/html5/images/fake2.txt').exists() - } - - void 'When resources are specified, then copy images according to patterns'() { - given: - getBuildFile(""" - asciidoctor { - sources { - include '${ASCIIDOC_SAMPLE_FILE}' - } - resources { - from sourceDir, { - include 'images/fake2.txt' - } - } - } - """) - - when: - runGradle() - - then: - verifyAll { - !new File(buildDir, 'asciidoc/html5/images/fake.txt').exists() - new File(buildDir, 'asciidoc/html5/images/fake2.txt').exists() - new File(buildDir, 'asciidoc/html5/sample.html').exists() - } - } - - void 'Will not process file if it starts with underscore'() { - given: - getBuildFile(""" - asciidoctor { - sources { - include '${ASCIIDOC_INVALID_FILE}' - } - } - """) - - when: - BuildResult result = runGradle() - - then: - verifyAll { - result.task(ASCIIDOCTOR_PATH).outcome == TaskOutcome.NO_SOURCE - !new File(buildDir, 'asciidoc/html5/subdir/_include.html').exists() - } - } - - File getBuildFile(final String extraContent = '') { - getJvmConvertGroovyBuildFile(""" - asciidoctorj.noDefaultRepositories = true - - ${extraContent} - """, - 'org.asciidoctor.convert' - ) - } - - BuildResult runGradle(List args = ['asciidoctor']) { - getGradleRunner(args).build() - } - - BuildResult failedGradle(List args = ['asciidoctor', '-i']) { - getGradleRunner(args).buildAndFail() - } -} diff --git a/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/CompatExtensionMultiuseFunctionalSpec.groovy b/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/CompatExtensionMultiuseFunctionalSpec.groovy deleted file mode 100644 index 446105044..000000000 --- a/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/CompatExtensionMultiuseFunctionalSpec.groovy +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import org.apache.commons.io.FileUtils -import org.asciidoctor.gradle.internal.FunctionalSpecification -import org.gradle.testkit.runner.BuildResult -import org.gradle.testkit.runner.GradleRunner -import org.gradle.testkit.runner.TaskOutcome - -/** - * @author Rene Groeschke - */ -class CompatExtensionMultiuseFunctionalSpec extends FunctionalSpecification { - - static final String TEST_PROJECTS_DIR = FunctionalSpecification.TEST_PROJECTS_DIR - - void setup() { - testProjectDir.root.mkdirs() - } - - void 'Postprocessor extensions are registered and preserved across multiple builds'() { - given: 'A build file that declares extensions' - def buildFile = testProjectDir.newFile('build.gradle') - buildFile << """ - plugins { - id 'org.asciidoctor.convert' - } - - asciidoctor { - extensions { - postprocessor { document, output -> - return 'Hi, Mom' + output - } - } - - sources { - include 'sample.adoc' - } - } - """ - - and: 'Some source files' - FileUtils.copyDirectory(new File(TEST_PROJECTS_DIR, 'extensions'), testProjectDir.root) - final File buildDir = new File(testProjectDir.root, 'build') - - when: - final BuildResult firstInvocationResult = GradleRunner.create() - .withProjectDir(testProjectDir.root) - .withArguments('asciidoctor') - .withPluginClasspath() - .withDebug(true) - .build() - - then: - firstInvocationResult.task(':asciidoctor').outcome == TaskOutcome.SUCCESS - File sampleHtmlOutput = new File(buildDir, 'asciidoc/html5/sample.html') - sampleHtmlOutput.exists() - sampleHtmlOutput.text.startsWith('Hi, Mom') - - when: - new File(testProjectDir.root, 'src/docs/asciidoc/sample.asciidoc') << 'changes' - final BuildResult secondInvocationResult = GradleRunner.create() - .withProjectDir(testProjectDir.root) - .withArguments('asciidoctor') - .withPluginClasspath() - .withDebug(true) - .build() - - then: - secondInvocationResult.task(':asciidoctor').outcome == TaskOutcome.SUCCESS - new File(buildDir, 'asciidoc/html5/sample.html').text.startsWith('Hi, Mom') - } - -} diff --git a/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/ExtensionsFunctionalSpec.groovy b/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/ExtensionsFunctionalSpec.groovy deleted file mode 100644 index 08b016ac1..000000000 --- a/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/ExtensionsFunctionalSpec.groovy +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import org.asciidoctor.gradle.internal.FunctionalSpecification -import org.gradle.testkit.runner.BuildResult -import spock.lang.Unroll - -/** - * Asciidoctor task inline extensionRegistry specification - * - * @author Robert Panzer - * @author Schalk W. Cronjé - */ -class ExtensionsFunctionalSpec extends FunctionalSpecification { - - private static final String ASCIIDOC_BUILD_DIR = 'build/asciidocextensions' - private static final String ASCIIDOC_MACRO_EXTENSION_SCRIPT = 'blockMacro.groovy' - private static final String ASCIIDOC_INLINE_EXTENSIONS_FILE = 'inlineextensions.asciidoc' - private static final String ASCIIDOC_INLINE_EXTENSIONS_RESULT_FILE = 'inlineextensions.html' - - File resultFile - - @SuppressWarnings('LineLength') - void setup() { - createTestProject('extensions') - resultFile = new File(testProjectDir.root, "${ASCIIDOC_BUILD_DIR}/html5/${ASCIIDOC_INLINE_EXTENSIONS_RESULT_FILE}") - } - - @Unroll - void 'Compat Task: Should apply #description'() { - given: - getBuildFile(script) - - when: - getGradleRunner(['asciidoctor', '-i']).build() - - then: - resultFile.exists() - resultFile.text.contains(content[0]) - content.size() == 1 || resultFile.text.contains(content[1]) - - where: - description << [ - 'inline BlockProcessor', - 'BlockProcessor from file', - 'inline PostProcessor', - 'inline IncludeProcessor' - ] - - and: - script << [ - """{ - block(name: 'BIG', contexts: [':paragraph']) { - parent, reader, attributes -> - def upperLines = reader.readLines()*.toUpperCase() - .inject('') {a, b -> a + '\\n' + b} - - createBlock(parent, 'paragraph', [upperLines], attributes, [:]) - } - block('small') { - parent, reader, attributes -> - def lowerLines = reader.readLines()*.toLowerCase() - .inject('') {a, b -> a + '\\n' + b} - - createBlock(parent, 'paragraph', [lowerLines], attributes, [:]) - } - - } - """, - "file('src/docs/asciidoc/${ASCIIDOC_MACRO_EXTENSION_SCRIPT}')", - '''{ - postprocessor { document, String output -> - if (document.basebackend("html")) { - output + '\' - } else { - throw new IllegalArgumentException("Expected html!") - } - } - } - ''', - '''{ - include_processor(filter: { it.startsWith('http') }) { - document, reader, target, attributes -> - reader.push_include('Content of URL', target, target, 1, attributes) - } - } - ''' - ] - - and: - content << [ - ['WRITE THIS IN UPPERCASE', 'and write this in lowercase'], - ['WRITE THIS IN UPPERCASE', 'and write this in lowercase'], - ['Copyright Acme, Inc.', 'Inline Extension Test document'], - ['Content of URL'] - ] - } - - void 'Compat Task: Should apply inline Preprocessor'() { - given: - getBuildFile('''{ - preprocessor { - document, reader -> - reader.advance() - reader - } - } - ''') - - when: - gradleRunner.build() - - then: - resultFile.exists() - !resultFile.text.contains('Inline Extension Test document') - } - - void 'Compat Task: Should fail if inline PostProcessor fails'() { - given: - getBuildFile('''{ - postprocessor { - document, output -> - if (output.contains("blacklisted")) { - throw new IllegalArgumentException("Document contains a blacklisted word") - } - } - } - ''') - - when: - BuildResult result = gradleRunner.buildAndFail() - - then: - result.output.contains('Document contains a blacklisted word') - } - - File getBuildFile(final String extension) { - getJvmConvertGroovyBuildFile( - """ - asciidoctor { - sourceDir = file('src/docs/asciidoc') - sources { - include '${ASCIIDOC_INLINE_EXTENSIONS_FILE}' - } - outputDir = file('${ASCIIDOC_BUILD_DIR}') - extensions ${extension} - } - """, - 'org.asciidoctor.convert' - ) - } -} diff --git a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/AsciidoctorTask.groovy b/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/AsciidoctorTask.groovy deleted file mode 100755 index 82f9dfb11..000000000 --- a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/AsciidoctorTask.groovy +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle - -import org.asciidoctor.gradle.compat.AsciidoctorCompatibilityTask - -/** This is just a wrapper class in a legacy package. All of the code has moved to AsciidoctorCompatibilityTask - * - * @author Noam Tenne - * @author Andres Almiray - * @author Tom Bujok - * @author Lukasz Pielak - * @author Dmitri Vyazelenko - * @author Benjamin Muschko - * @author Dan Allen - * @author Rob Winch - * @author Stefan Schlott - * @author Stephan Classen - * @author Marcus Fihlon - * @author Schalk W. Cronjé - * @author Robert Panzer - */ -@Deprecated -class AsciidoctorTask extends AsciidoctorCompatibilityTask { -} - diff --git a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorBackend.groovy b/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorBackend.groovy deleted file mode 100755 index 40c8033b8..000000000 --- a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorBackend.groovy +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import groovy.transform.CompileStatic - -/** - * Supported backends. - * - * @author Benjamin Muschko - * @author Dan Allen - */ -@Deprecated -@CompileStatic -enum AsciidoctorBackend { - HTML('html'), - DOCBOOK('docbook'), - HTML5('html5'), - DOCBOOK45('docbook45'), - DOCBOOK5('docbook5'), - EPUB3('epub3'), - PDF('pdf'), - XHTML('xhtml'), - XHTML5('xhtml5'), - - private final static Map ALL_BACKENDS - private final String id - - static boolean isBuiltIn(String name) { - ALL_BACKENDS.containsKey(name) - } - - String getId() { - id - } - - static { - ALL_BACKENDS = (values().collectEntries { [it.id, it] }.asImmutable()) as Map - } - - private AsciidoctorBackend(String id) { - this.id = id - } -} diff --git a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityPlugin.groovy b/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityPlugin.groovy deleted file mode 100755 index 09c59599c..000000000 --- a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityPlugin.groovy +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import groovy.transform.CompileDynamic -import groovy.transform.CompileStatic -import org.asciidoctor.gradle.AsciidoctorTask -import org.asciidoctor.gradle.jvm.AsciidoctorJBasePlugin -import org.gradle.api.Action -import org.gradle.api.GradleException -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.artifacts.Configuration -import org.gradle.api.artifacts.DependencyResolveDetails -import org.gradle.api.artifacts.DependencySet -import org.gradle.api.artifacts.ResolvableDependencies -import org.gradle.api.artifacts.dsl.DependencyHandler -import org.gradle.api.logging.LogLevel -import org.gradle.util.GradleVersion - -import static org.asciidoctor.gradle.jvm.AsciidoctorJExtension.JRUBY_COMPLETE_DEPENDENCY - -/** - * @author Noam Tenne - * @author Andres Almiray - * @author Patrick Reimers - * @author Markus Schlichting - * @author Schalk W. Cronjé - */ -@Deprecated -@CompileStatic -@SuppressWarnings('LineLength') -class AsciidoctorCompatibilityPlugin implements Plugin { - static final String ASCIIDOCTOR = 'asciidoctor' - static final String ASCIIDOCTORJ = 'asciidoctorj' - static final String ASCIIDOCTORJ_CORE_DEPENDENCY = 'org.asciidoctor:asciidoctorj:' - static final String ASCIIDOCTORJ_GROOVY_DSL_DEPENDENCY = 'org.asciidoctor:asciidoctorj-groovy-dsl:' - - static String createMigrationOutputMessage(final Set messages) { - StringWriter output = new StringWriter() - output.withCloseable { - output.println 'You are using one or more deprecated Asciidoctor task or plugins. These will be removed in a future release. To help you migrate we have compiled some tips for you based upon your current usage:' - output.println() - - messages.each { String msg -> - output.println " - ${msg}" - } - output.println() - output.toString() - } - } - - void apply(Project project) { - ['jvm.convert', 'js.base'].each { String s -> - String pluginName = "org.asciidoctor.${s}" - if (project.gradle.plugins.hasPlugin(pluginName)) { - throw new GradleException("'${pluginName}' and 'org.asciidoctor.convert' cannot be used within the same (sub)project") - } - } - - project.apply plugin: 'org.asciidoctor.base' - - AsciidoctorExtension extension = project.extensions.create(ASCIIDOCTORJ, AsciidoctorExtension, project) - - addDefaultRepositories(project) - Configuration configuration = project.configurations.maybeCreate(ASCIIDOCTOR) - project.logger.info("[Asciidoctor] asciidoctorj: ${extension.version}") - project.logger.info("[Asciidoctor] asciidoctorj-groovy-dsl: ${extension.groovyDslVersion}") - - configuration.incoming.beforeResolve(new Action() { - @SuppressWarnings('UnusedMethodParameter') - void execute(ResolvableDependencies resolvableDependencies) { - DependencyHandler dependencyHandler = project.dependencies - DependencySet dependencies = configuration.dependencies - dependencies.add(dependencyHandler.create(ASCIIDOCTORJ_CORE_DEPENDENCY + extension.version)) - dependencies.add( - dependencyHandler.create( - ASCIIDOCTORJ_GROOVY_DSL_DEPENDENCY + extension.groovyDslVersion, - excludeGroovy() - ) - ) - } - }) - - configuration.resolutionStrategy.eachDependency { DependencyResolveDetails dsr -> - dsr.with { - if (target.name == 'jruby' && target.group == 'org.jruby') { - useTarget "${JRUBY_COMPLETE_DEPENDENCY}:${target.version}" - } - } - } - - AsciidoctorTask asciidoctor = project.tasks.create(ASCIIDOCTOR, AsciidoctorTask) - asciidoctor.group = AsciidoctorJBasePlugin.TASK_GROUP - asciidoctor.description = 'Compatibility task to convert AsciiDoc files and copy related resources' - asciidoctor.classpath = configuration - - addMigrationSupport( - project, - "'org.asciidoctor.convert' is deprecated. When you have time please switch over to 'org.asciidoctor.jvm.convert'.", - 'jcenter() is no longer added by default. If you relied on this behaviour in the past, please add jcenter() to the repositories block.' - ) - } - - @CompileDynamic - Closure excludeGroovy() { - return { - exclude module: 'groovy-all' - } - } - - @CompileDynamic - private void addDefaultRepositories(Project project) { - project.afterEvaluate { - if (!project.extensions.asciidoctorj.noDefaultRepositories) { - project.repositories { - jcenter() - } - } - } - } - - @CompileDynamic - private void addMigrationSupport(Project project, String... pluginMessages) { - project.afterEvaluate { - Set messages = [] - messages.addAll(pluginMessages) - project.tasks.withType(AsciidoctorTask) { AsciidoctorTask task -> - messages.addAll(task.migrationMessages) - } - - if (messages.empty) { - return - } - - if (GradleVersion.current() >= GradleVersion.version('4.5')) { - switch (project.gradle.startParameter.warningMode.toString().toLowerCase()) { - case 'all': - project.logger.lifecycle(createMigrationOutputMessage(messages)) - break - case 'none': - break - default: - project.logger.lifecycle 'You are using one or more deprecated Asciidoctor task or plugins. To help with migration run with --warnings=all' - } - } else { - if (project.gradle.startParameter.logLevel != LogLevel.QUIET) { - if (project.gradle.startParameter.logLevel == LogLevel.LIFECYCLE) { - project.logger.lifecycle 'You are using one or more deprecated Asciidoctor task or plugins. To help with migration run with -i or --info' - } else { - project.logger.info(createMigrationOutputMessage(messages)) - } - } - } - } - } -} diff --git a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityTask.groovy b/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityTask.groovy deleted file mode 100755 index 2c16d87b0..000000000 --- a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityTask.groovy +++ /dev/null @@ -1,797 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import groovy.transform.CompileDynamic -import groovy.transform.CompileStatic -import org.asciidoctor.gradle.base.SafeMode -import org.asciidoctor.gradle.base.Transform -import org.asciidoctor.gradle.internal.ExecutorConfiguration -import org.asciidoctor.gradle.internal.ExecutorConfigurationContainer -import org.asciidoctor.gradle.internal.ExecutorLogLevel -import org.asciidoctor.gradle.internal.JavaExecUtils -import org.asciidoctor.gradle.remote.AsciidoctorJavaExec -import org.gradle.api.DefaultTask -import org.gradle.api.InvalidUserDataException -import org.gradle.api.artifacts.Configuration -import org.gradle.api.file.CopySpec -import org.gradle.api.file.FileCollection -import org.gradle.api.file.FileTree -import org.gradle.api.internal.file.copy.CopySpecInternal -import org.gradle.api.tasks.Console -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.InputFiles -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.OutputDirectories -import org.gradle.api.tasks.OutputDirectory -import org.gradle.api.tasks.SkipWhenEmpty -import org.gradle.api.tasks.TaskAction -import org.gradle.api.tasks.WorkResult -import org.gradle.api.tasks.util.PatternSet -import org.gradle.internal.FileUtils -import org.gradle.process.JavaExecSpec -import org.ysb33r.grolifant.api.OperatingSystem - -import java.util.stream.Collectors - -import static org.asciidoctor.gradle.base.AsciidoctorUtils.UNDERSCORE_LED_FILES -import static org.asciidoctor.gradle.base.AsciidoctorUtils.getClassLocation -import static org.asciidoctor.gradle.base.AsciidoctorUtils.getSourceFileTree -import static org.asciidoctor.gradle.internal.JavaExecUtils.getJavaExecClasspath -import static org.asciidoctor.gradle.jvm.AsciidoctorJExtension.GUAVA_REQUIRED_FOR_EXTERNALS -import static org.ysb33r.grolifant.api.StringUtils.stringize - -/** The core functionality of the Asciidoctor task type as it was in the 1.5.x series. - * - * @author Noam Tenne - * @author Andres Almiray - * @author Tom Bujok - * @author Lukasz Pielak - * @author Dmitri Vyazelenko - * @author Benjamin Muschko - * @author Dan Allen - * @author Rob Winch - * @author Stefan Schlott - * @author Stephan Classen - * @author Marcus Fihlon - * @author Schalk W. Cronjé - * @author Robert Panzer - */ -@Deprecated -@SuppressWarnings(['MethodCount', 'Instanceof', 'LineLength']) -@CompileStatic -class AsciidoctorCompatibilityTask extends DefaultTask { - private static final String PATH_SEPARATOR = OperatingSystem.current().pathSeparator - private static - final String MIGRATE_GEMS_MSG = 'When upgrading GEMs, \'requires\' will need to be set via the asciidoctorj project and task docExtensions. Use setGemPaths method in extension(s) to set GEM paths.' - - private static final String DEFAULT_BACKEND = AsciidoctorBackend.HTML5.id - private boolean baseDirSetToNull - private Object outDir - private Object srcDir - private final List gemPaths = [] - private final Set backends = [] - private final Set requires = [] - private final Set migrationMessages = [] - private final Map opts = [:] - private final Map attrs = [:] - private PatternSet sourceDocumentPattern - private CopySpec resourceCopy - private boolean separateOutputDirs = true - - @SuppressWarnings('CouldBeSwitchStatement') - static int resolveSafeModeLevel(Object safe, int defaultLevel = SafeMode.UNSAFE.level) { - if (safe == null) { - defaultLevel - } else if (safe instanceof SafeMode) { - safe.level - } else if (safe instanceof Number) { - SafeMode.safeMode(safe as Integer).level - } else if (safe instanceof CharSequence) { - SafeMode.valueOf(safe.toString().toUpperCase()).level - } else { - defaultLevel - } - } - - /** If set to true each backend will be output to a separate subfolder below {@code outputDir} - * @since 1.5.1 - */ - @Input - boolean getSeparateOutputDirs() { - migrationMessage('seperateOutputDirs', 'Separate output directories are now configured via outputOptions.separateOutputDirs') - this.separateOutputDirs - } - - void setSeparateOutputDirs(boolean v) { - this.separateOutputDirs = v - } - - @Optional - @InputDirectory - File baseDir - - /** Set to {@code true} in order to add legacy attributes - * {@code projectdir} and {@code rootdir}. - * - * This is for ease of upgrading. Documents should be converted to - * use {@code gradle-projectdir} amd {@code gradle-rootdir} instead. - */ - @Input - boolean legacyAttributes = false - - /** Logs documents as they are converted - * - */ - @Optional - @Console - boolean logDocuments = false - - /** - * Stores the extensionRegistry defined in the runConfiguration phase - * to register them in the execution phase. - */ - @Internal - final List asciidoctorExtensions = [] - - @Optional - @InputFiles - Configuration classpath - - /** Returns all of the Asciidoctor options - * - */ - @Optional - @Input - Map getOptions() { this.opts } - - /** Apply a new set of Asciidoctor options, clearing any options previously set. - * - * For backwards compatibility it is still possible to replace attributes via this call. However the - * use of {@link #setAttributes(java.util.Map)} and {@link #attributes(java.util.Map)} are the now - * correct way of working with attributes - * - * @param m Map with new options - */ - @SuppressWarnings('DuplicateStringLiteral') - void setOptions(Map m) { - if (!m) { - return - } // null check - if (m.containsKey('attributes')) { - migrationMessage( - 'setOptions', - """Pay attention to these attributes found in options. -Currently attributes will be replaced due to assignment. -Please use one of the following instead instead as current behaviour will no longer be available when upgrading: - - 'attributes' - - 'project.asciidoctorj.attributes' - - '${name}.asciidoctorj.attributes' -""") - attrs.clear() - attrs.putAll(coerceLegacyAttributeFormats(m.attributes)) - m.remove('attributes') - } - this.opts.clear() - this.opts.putAll(m) - } - - /** Appends a new set of Asciidoctor options. - * - * For backwards compatibility it is still possible to append attributes via this call. However the - * use of {@link #setAttributes(java.util.Map)} and {@link #attributes(java.util.Map)} are the now - * correct way of working with attributes - * - * @param m Map with new options - * @since 1.5.1 - */ - @SuppressWarnings('DuplicateStringLiteral') - void options(Map m) { - if (!m) { - return - } // null check - if (m.containsKey('attributes')) { - migrationMessage( - 'setOptions', - """Pay attention to these attributes found in options. -Currently these attributes are added to existing attributes. -Please use one of the following instead instead as current behaviour will no longer be available when upgrading: - - 'attributes' - - 'project.asciidoctorj.attributes' - - '${name}.asciidoctorj.attributes' -""") - attributes coerceLegacyAttributeFormats(m.attributes) - m.remove('attributes') - } - this.opts.putAll(m) - } - - /** Returns the current set of Asciidoctor attributes - * - * @since 1.5.1 - */ - @Optional - @Input - Map getAttributes() { this.attrs } - - /** Applies a new set of Asciidoctor attributes, clearing any previously set - * - * @param m New map of attributes - * @since 1.5.1 - */ - void setAttributes(Map m) { - migrationMessage('setAttributes', 'the behaviour of setAttributes will change when upgrading. You may decide to use the asciidoctorj.setAttributes that exists as a project or task extension instead') - this.attrs.clear() - if (m) { - this.attrs.putAll(m) - } - } - - /** Appends a set of Asciidoctor attributes. - * - * @param o a Map, List or a literal (String) definition - * @since 1.5.1 - */ - void attributes(Object... o) { - if (!o) { - this.attrs.clear() - return - } - for (input in o) { - this.attrs.putAll(coerceLegacyAttributeFormats(input)) - } - } - - /** Returns the set of Ruby modules to be included. - * - * @since 1.5.0 - */ - @Optional - @Input - Set getRequires() { this.requires } - - /** Applies a new set of Ruby modules to be included, clearing any previous set. - * - * @param b One or more ruby modules to be included - * @since 1.5.0 - */ - @Deprecated - void setRequires(Iterable b) { - migrationMessage('setRequires', MIGRATE_GEMS_MSG) - this.requires.clear() - this.requires.addAll(stringize(b)) - } - - /** Appends new set of Ruby modules to be included. - * - * @param b One or more ruby modules to be included - * @since 1.5.1 - */ - @Deprecated - void requires(Object... b) { - migrationMessage('requires', MIGRATE_GEMS_MSG) - this.requires.addAll(stringize(b as List)) - } - - /** Returns the current set of Asciidoctor backends that will be used for document generation - * - * @since 0.7.1* @deprecated - */ - @Optional - @Input - Set getBackends() { - migrationMessage('getBackends', 'Use outputOptions.getBackends') - this.backends - } - - /** Applies a new set of Asciidoctor backends that will be used for document generation clearing any - * previous backends - * - * @param b List of backends. Each item must be convertible to string. - * - * @since 0.7.1 - */ - void setBackends(Iterable b) { - migrationMessage('setBackends', 'Use outputOptions.setBackends') - this.backends.clear() - this.backends.addAll(stringize(b)) - } - - /** Appends additional Asciidoctor backends that will be used for document generation. - * - * @param b List of backends. Each item must be convertible to string. - * - * @since 1.5.1 - */ - void backends(Object... b) { - migrationMessage('backends', 'Use outputOptions.setbackends') - this.backends.addAll(stringize(b as List)) - } - - /** Defines extensionRegistry. The given parameters should - * either contain Asciidoctor Groovy DSL closures or files - * with content conforming to the Asciidoctor Groovy DSL. - */ - @Deprecated - void extensions(Object... exts) { - migrationMessage( - 'docExtensions', - 'Extensions will need to be set via the asciidoctorj project and task docExtensions' - ) - if (!exts) { - return - } // null check - asciidoctorExtensions.addAll(exts as List) - } - - /** Sets a new gemPath to be used - * - * @param f A path object can be be converted with {@code project.file}. - * @since 1.5.1 - */ - @Deprecated - void gemPath(Object... f) { - migrationMessage( - 'gemPath', - 'GEM paths will need to be set via the asciidoctorj project and task docExtensions using the gemPaths method' - ) - if (!f) { - return - } // null check - this.gemPaths.addAll(f as List) - } - - /** Sets a new list of GEM paths to be used. - * - * @param f A {@code File} object pointing to list of installed GEMs - * @since 1.5.0 - */ - @Deprecated - void setGemPath(Object... f) { - migrationMessage('setGemPath(Object...)', MIGRATE_GEMS_MSG) - this.gemPaths.clear() - if (!f) { - return - } // null check - this.gemPaths.addAll(f as List) - } - - /** Assigns a single string to a GEM path, scanning it for concatenated GEM Paths, separated by the platform - * separator. This utility is only for backwards compatibility - * - * @param s - */ - @SuppressWarnings('UnnecessarySetter') - @CompileDynamic - void setGemPath(Object path) { - migrationMessage('setGemPath(Object)', MIGRATE_GEMS_MSG) - this.gemPaths.clear() - if (path instanceof CharSequence) { - this.gemPaths.addAll(setGemPath(path.split(PATH_SEPARATOR))) - } else if (path) { - this.gemPaths.addAll(path) - } - } - - /** Returns the list of paths to be used for {@code GEM_HOME} - * - * @since 1.5.0 - */ - @Optional - @InputFiles - FileCollection getGemPath() { - project.files(this.gemPaths) - } - - /** Returns the list of paths to be used for GEM installations in a format that is suitable for assignment to {@code GEM_HOME} - * - * Calling this will cause gemPath to be resolved immediately. - * @since 1.5.1 - */ - @Optional - @InputDirectory - String asGemPath() { - gemPath.files*.toString().join(PATH_SEPARATOR) - } - - /** Sets the new Asciidoctor parent source directory. - * - * @param f An object convertible via {@code project.file} - * @since 1.5.1 - */ - void sourceDir(Object f) { - this.srcDir = f - } - - /** Sets the new Asciidoctor parent source directory. - * - * @param f A {@code File} object pointing to the parent source directory - */ - void setSourceDir(File f) { - this.srcDir = f - } - - /** Returns the parent directory for Asciidoctor source. Default is {@code src/asciidoc}. - */ - @Optional - @InputDirectory - File getSourceDir() { - project.file(srcDir) - } - - /** Sets the new Asciidoctor parent output directory. - * - * @param f An object convertible via {@code project.file} - * @since 1.5.1 - */ - void outputDir(Object f) { - this.outDir = f - } - - /** Sets the new Asciidoctor parent output directory. - * - * @param f A {@code File} object pointing to the parent output directory - */ - void setOutputDir(File f) { - this.outDir = f - } - - /** Returns the current toplevel output directory - * - */ - @OutputDirectory - File getOutputDir() { - if (this.outDir == null) { - this.outDir = new File(project.buildDir, 'asciidoc') - } - project.file(this.outDir) - } - - void setBaseDir(File baseDir) { - this.baseDir = baseDir - baseDirSetToNull = baseDir == null - } - - /** Returns a list of all output directories. - * @since 1.5.1 - */ - @OutputDirectories - Set getOutputDirectories() { - if (separateOutputDirs) { - backends.stream().map { - new File(outputDir, it) - }.collect(Collectors.toSet()) - } else { - [outputDir] as Set - } - } - - /** Returns a FileTree containing all of the source documents - * - * @return If{@code sources} was never called then all asciidoc source files below {@code sourceDir} will - * be included - * @since 1.5.1 - */ - @InputFiles - @SkipWhenEmpty - FileTree getSourceFileTree() { - getSourceFileTree(project, sourceDir, this.sourceDocumentPattern ?: defaultSourceDocumentPattern) - } - - /** Add patterns for source files or source files via a closure - * - * @param cfg PatternSet runConfiguration closure - * @since 1.5.1 - */ - void sources(Closure cfg) { - if (sourceDocumentPattern == null) { - sourceDocumentPattern = new PatternSet().exclude('**/_*') - } - Closure configuration = (Closure) (cfg.clone()) - configuration.delegate = sourceDocumentPattern - configuration() - } - - /** Add to the CopySpec for extra files. The destination of these files will always have a parent directory - * of {@code outputDir} or {@code outputDir + backend} - * - * @param cfg CopySpec runConfiguration closure - * @since 1.5.1 - */ - void resources(Closure cfg) { - if (this.resourceCopy == null) { - this.resourceCopy = project.copySpec(cfg) - } else { - Closure configuration = (Closure) (cfg.clone()) - configuration.delegate = this.resourceCopy - configuration() - } - } - - /** The default PatternSet that will be used if {@code sources} was never called - * - * By default all *.adoc,*.ad,*.asc,*.asciidoc is included. Files beginning with underscore are excluded - * - * @since 1.5.1 - */ - @Internal - PatternSet getDefaultSourceDocumentPattern() { - PatternSet ps = new PatternSet() - ps.include '**/*.adoc' - ps.include '**/*.ad' - ps.include '**/*.asc' - ps.include '**/*.asciidoc' - ps.exclude UNDERSCORE_LED_FILES - } - - /** The default CopySpec that will be used if {@code resources} was never called - * - * By default anything below {@code $sourceDir/images} will be included. - * - * @return A{@code CopySpec}, never null - * @since 1.5.1 - */ - @Internal - @CompileDynamic - CopySpec getDefaultResourceCopySpec() { - project.copySpec { - from(sourceDir) { - include 'images/**' - } - } - } - - /** Gets the CopySpec for additional resources - * If {@code resources} was never called, it will return a default CopySpec otherwise it will return the - * one built up via successive calls to {@code resources} - * - * @return A{@code CopySpec}, never null - * @since 1.5.1 - */ - @Internal - CopySpec getResourceCopySpec() { - this.resourceCopy ?: defaultResourceCopySpec - } - - /** Gets the additional resources as a FileCollection. - * If {@code resources} was never called, it will return the file collections as per default CopySpec otherwise it - * will return the collections as built up via successive calls to {@code resources} - * - * @return A{@code FileCollection}, never null - * @since 1.5.2 - */ - @InputFiles - @Optional - FileCollection getResourceFileCollection() { - (resourceCopySpec as CopySpecInternal).buildRootResolver().allSource - } - - @TaskAction - @CompileStatic - void processAsciidocSources() { - File output = outputDir - - final Map finalAttributes = [ - 'gradle-project-group': project.group, - 'gradle-project-name' : project.name, - 'revnumber' : project.version - ] - if (legacyAttributes) { - finalAttributes.putAll([ - 'project-version': project.version, - 'project-group' : project.group, - 'project-name' : project.name - ]) - } - finalAttributes.putAll(attributes) - - ExecutorConfigurationContainer ecc = new ExecutorConfigurationContainer(activeBackends().stream().map { backend -> - new ExecutorConfiguration( - sourceDir: sourceDir, - outputDir: outputBackendDir(output, backend), - projectDir: project.projectDir, - rootDir: project.rootProject.projectDir, - baseDir: getBaseDir(), - sourceTree: sourceFileTree.files, - fatalMessagePatterns: [], - backendName: backend, - gemPath: asGemPath(), - logDocuments: this.logDocuments, - copyResources: true, - safeModeLevel: resolveSafeModeLevel(options['safe'], 0), - requires: getRequires(), - options: options, - attributes: finalAttributes, - legacyAttributes: legacyAttributes, - asciidoctorExtensions: dehydrateExtensions(getAsciidoctorExtensions()), - executorLogLevel: ExecutorLogLevel.WARN - ) - }.collect(Collectors.toList())) - - Set closurePaths = getAsciidoctorExtensions().findAll { - it instanceof Closure - }.stream().map { - getClassLocation(it.class) - }.collect(Collectors.toSet()) - closurePaths.add(getClassLocation(org.gradle.internal.scripts.ScriptOrigin)) - - FileCollection javaExecClasspath = project.files( - getJavaExecClasspath( - project, - classpath ?: project.configurations.getByName(AsciidoctorCompatibilityPlugin.ASCIIDOCTOR), - GUAVA_REQUIRED_FOR_EXTERNALS - ), - closurePaths - ) - - if (legacyAttributes) { - migrationMessage 'legacyAttributes=true', '''Switch documents to use the following attributes instead: - - gradle-projectdir (old=projectdir) - - gradle-rootdir (old=rootdir) - - gradle-project-name (old=project-name) - - gradle-projetc-group (old=project-group) - - revnumber (old=project-version) - ''' - } - - File execConfigurationData = JavaExecUtils.writeExecConfigurationData(this, ecc.configurations) - logger.debug("Serialised AsciidoctorJ configuration to ${execConfigurationData}") - logger.info "Running AsciidoctorJ instance with classpath ${javaExecClasspath.files}" - - activeBackends().each { backend -> - copyResources(outputBackendDir(outputDir, backend), resourceCopySpec) - } - - runJavaExec(execConfigurationData, javaExecClasspath) - } - - // Helper method to be able to produce migration messages - @Internal - Set getMigrationMessages() { - this.migrationMessages - } - - @CompileDynamic - protected static void processCollectionAttributes(Map attributes, List rawAttributes) { - for (Object attr in rawAttributes) { - if (attr instanceof CharSequence) { - String[] tokens = attr.toString().split('=', 2) - attributes.put(tokens[0], tokens.size() > 1 ? tokens[1] : '') - } else { - throw new InvalidUserDataException("Unsupported type for attribute ${attr}: ${attr.getClass()}") - } - } - } - - protected AsciidoctorCompatibilityTask() { - srcDir = project.file('src/docs/asciidoc') - } - - protected Set activeBackends() { - this.backends.empty ? [DEFAULT_BACKEND].toSet() : this.backends - } - - @CompileDynamic - @SuppressWarnings(['DuplicateStringLiteral', 'DuplicateNumberLiteral']) - private static Map coerceLegacyAttributeFormats(Object attributes) { - Map transformedMap = [:] - switch (attributes) { - case Map: - transformedMap = attributes - break - case CharSequence: - Transform.toList(attributes.replaceAll('([^\\\\]) ', '$1\0').replaceAll('\\\\ ', ' ').split('\0') as List) { - String[] split = it.split('=') - if (split.size() < 2) { - throw new InvalidUserDataException("Unsupported format for attributes: ${attributes}") - } - transformedMap[split[0]] = split.drop(1).join('=') - } - break - case Collection: - processCollectionAttributes(transformedMap, attributes) - break - default: - if (attributes.class.isArray()) { - processCollectionAttributes(transformedMap, attributes) - } else { - throw new InvalidUserDataException("Unsupported type for attributes: ${attributes.class}") - } - } - - transformedMap - } - - @CompileDynamic - @SuppressWarnings('CouldBeSwitchStatement') - private static List stringifyList(List input) { - Transform.toList(input) { element -> - if (element instanceof CharSequence) { - element.toString() - } else if (element instanceof List) { - stringifyList(element) - } else if (element instanceof Map) { - stringifyMap(element) - } else if (element instanceof File) { - element.absolutePath - } else { - element - } - } - } - - @CompileDynamic - @SuppressWarnings('CouldBeSwitchStatement') - private static Map stringifyMap(Map input) { - Map output = [:] - input.each { key, value -> - if (value instanceof CharSequence) { - output[key] = value.toString() - } else if (value instanceof List) { - output[key] = stringifyList(value) - } else if (value instanceof Map) { - output[key] = stringifyMap(value) - } else if (value instanceof File) { - output[key] = value.absolutePath - } else { - output[key] = value - } - } - output - } - - private File outputBackendDir(final File outputDir, final String backend) { - separateOutputDirs ? new File(outputDir, FileUtils.toSafeFileName(backend)) : outputDir - } - - @CompileDynamic - private WorkResult copyResources(File outputDir, CopySpec spec) { - project.copy { - into outputDir - with spec - } - } - - private void migrationMessage(final String currentMethod, final String upgradeInstructions) { - this.migrationMessages.add( - "You have used '${currentMethod}'. When upgrading you will need to: ${upgradeInstructions}".toString() - ) - } - - private void runJavaExec(File execConfigurationData, FileCollection javaExecClasspath) { - project.javaexec { JavaExecSpec jes -> - logger.debug "Running AsciidoctorJ instance with environment: ${jes.environment}" - jes.main = AsciidoctorJavaExec.canonicalName - jes.classpath = javaExecClasspath - jes.args execConfigurationData.absolutePath - } - } - - private List dehydrateExtensions(final List exts) { - Transform.toList(exts) { - switch (it) { - case Closure: - ((Closure) it).dehydrate() - break - default: - it - } - } - } -} - diff --git a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorExtension.groovy b/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorExtension.groovy deleted file mode 100644 index fed520589..000000000 --- a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorExtension.groovy +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import groovy.transform.CompileStatic -import org.asciidoctor.gradle.jvm.AsciidoctorJExtension -import org.gradle.api.Project - -/** - * @author Andres Almiray - * @author Schalk W. Cronjé - */ -@Deprecated -@CompileStatic -class AsciidoctorExtension { - String version = AsciidoctorJExtension.DEFAULT_ASCIIDOCTORJ_VERSION - - String groovyDslVersion = AsciidoctorJExtension.DEFAULT_GROOVYDSL_VERSION - - /** - * By default the plugin will try to add a default repository to find AsciidoctorJ. - * For certain cases this approach is not acceptable, the behaviour can be turned off - * by setting this value to {@code true} - * - * @since 1.5.3 - */ - boolean noDefaultRepositories = false - - final Project project - - AsciidoctorExtension(Project project) { - this.project = project - } -} diff --git a/asciidoctor-gradle-jvm/src/main/resources/META-INF/gradle-plugins/org.asciidoctor.convert.properties b/asciidoctor-gradle-jvm/src/main/resources/META-INF/gradle-plugins/org.asciidoctor.convert.properties deleted file mode 100644 index 9f25edb4a..000000000 --- a/asciidoctor-gradle-jvm/src/main/resources/META-INF/gradle-plugins/org.asciidoctor.convert.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright 2013-2019 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. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -implementation-class=org.asciidoctor.gradle.compat.AsciidoctorCompatibilityPlugin \ No newline at end of file diff --git a/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorExtensionSpec.groovy b/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorExtensionSpec.groovy deleted file mode 100644 index 7f66f71fa..000000000 --- a/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorExtensionSpec.groovy +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import org.asciidoctor.gradle.testfixtures.jvm.AsciidoctorjTestVersions -import org.gradle.api.Project -import org.gradle.testfixtures.ProjectBuilder -import spock.lang.Specification - -class AsciidoctorExtensionSpec extends Specification { - - Project project = ProjectBuilder.builder().build() - - void setup() { - project.allprojects { - apply plugin : 'org.asciidoctor.convert' - } - } - - void 'Default version should be the same as AsciidoctorJExtension'() { - expect: - project.extensions.asciidoctorj.version == AsciidoctorjTestVersions.SERIES_20 - } - - void 'Default GroovyDSL version should be the same as AsciidoctorJExtension'() { - expect: - project.extensions.asciidoctorj.groovyDslVersion == AsciidoctorjTestVersions.GROOVYDSL_SERIES_20 - } - -} \ No newline at end of file diff --git a/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorPluginSpec.groovy b/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorPluginSpec.groovy deleted file mode 100755 index fbcf6d630..000000000 --- a/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorPluginSpec.groovy +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import org.asciidoctor.gradle.jvm.AsciidoctorJPlugin -import org.gradle.api.GradleException -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.artifacts.DependencyResolutionListener -import org.gradle.api.artifacts.ResolvableDependencies -import org.gradle.testfixtures.ProjectBuilder -import spock.lang.Ignore -import spock.lang.Specification - -/** - * Plugin specification. - * - * @author Benjamin Muschko - * @author Patrick Reimers - * @author Markus Schlichting - */ -// Suppressing a number of warnings rather than fixing as this -// test will be removed in 3.0.0 -@SuppressWarnings([ - 'LineLength', - 'MethodReturnTypeRequired' -]) -class AsciidoctorPluginSpec extends Specification { - private static final String ASCIIDOCTOR = 'asciidoctor' - private static final String BINTRAY = 'BintrayJCenter' - Project project - - def setup() { - project = ProjectBuilder.builder().build() - } - - @SuppressWarnings('MethodName') - def "Compatibility plugin applies with default setup"() { - expect: - project.tasks.findByName(ASCIIDOCTOR) == null - when: - project.apply plugin: AsciidoctorCompatibilityPlugin - then: - Task asciidoctorTask = project.tasks.findByName(ASCIIDOCTOR) - asciidoctorTask != null - asciidoctorTask.group == 'Documentation' - asciidoctorTask.sourceDir == project.file('src/docs/asciidoc') - asciidoctorTask.outputDir == new File(project.buildDir, 'asciidoc') - - project.tasks.findByName('clean') != null - } - - @Ignore("Method 'getDependencyResolutionBroadcast' is unknown") - @SuppressWarnings('MethodName') - def "Compatibility extension accepts alternative Asciidoctorj version"() { - expect: - project.tasks.findByName(ASCIIDOCTOR) == null - - when: - project.apply plugin: AsciidoctorCompatibilityPlugin - - def expectedVersion = 'my.expected.version-SNAPSHOT' - project.asciidoctorj.version = expectedVersion - - def expectedDslVersion = 'dsl.' + expectedVersion - project.asciidoctorj.groovyDslVersion = expectedDslVersion - - def config = project.project.configurations.getByName(ASCIIDOCTOR) - def dependencies = config.dependencies - assert dependencies.isEmpty() - - // mock-trigger beforeResolve() to avoid 'real' resolution of dependencies - DependencyResolutionListener broadcast = config.dependencyResolutionBroadcast - ResolvableDependencies incoming = config.incoming - broadcast.beforeResolve(incoming) - def dependencyHandler = project.dependencies - - then: - assert dependencies.contains(dependencyHandler.create(AsciidoctorCompatibilityPlugin.ASCIIDOCTORJ_GROOVY_DSL_DEPENDENCY + expectedDslVersion)) - assert dependencies.contains(dependencyHandler.create(AsciidoctorCompatibilityPlugin.ASCIIDOCTORJ_CORE_DEPENDENCY + expectedVersion)) - } - - @SuppressWarnings('MethodName') - def "Compatibility plugin adds JCenter repository by default"() { - when: - project.apply plugin: AsciidoctorCompatibilityPlugin - project.evaluate() - - then: - project.repositories.findByName(BINTRAY) - } - - @SuppressWarnings('MethodName') - def "Compatibility plugin does nto add JCenter repository when noDefaultRepositories is set"() { - when: - project.apply plugin: AsciidoctorCompatibilityPlugin - project.extensions.asciidoctorj.noDefaultRepositories = true - project.evaluate() - - then: - project.repositories.findByName(BINTRAY) == null - } - - @SuppressWarnings('MethodName') - def 'Cannot combine compatibility plugin with newer plugins'() { - when: - project.apply plugin: AsciidoctorJPlugin - project.apply plugin: AsciidoctorCompatibilityPlugin - - then: - thrown(GradleException) - } -} - diff --git a/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorTaskSpec.groovy b/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorTaskSpec.groovy deleted file mode 100755 index 11145aed3..000000000 --- a/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorTaskSpec.groovy +++ /dev/null @@ -1,515 +0,0 @@ -/* - * Copyright 2013-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.asciidoctor.gradle.compat - -import org.asciidoctor.gradle.AsciidoctorTask -import org.gradle.api.GradleException -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.testfixtures.ProjectBuilder -import spock.lang.Specification -import spock.lang.Unroll - -@java.lang.SuppressWarnings('NoWildcardImports') -import static org.asciidoctor.gradle.base.SafeMode.* -import static org.asciidoctor.gradle.compat.AsciidoctorCompatibilityTask.resolveSafeModeLevel - -/** - * Asciidoctor task specification - * - * @author Benjamin Muschko - * @author Stephan Classen - * @author Marcus Fihlon - * @author Schalk W. Cronjé - */ -// We suppress a lot of warnings as this test will be removed in 3.0. -@SuppressWarnings([ - 'MethodCount', - 'UnusedPrivateField', - 'LineLength', - 'MethodReturnTypeRequired', - 'StaticFieldsBeforeInstanceFields' -]) -class AsciidoctorTaskSpec extends Specification { - private static final String ASCIIDOCTOR = 'asciidoctor' - private static final String ASCIIDOC_RESOURCES_DIR = 'build/resources/test/src/asciidoc' - private static final String ASCIIDOC_BUILD_DIR = 'build/asciidoc' - private static final String ASCIIDOC_SAMPLE_FILE = 'sample.asciidoc' - private static final String ASCIIDOC_SAMPLE2_FILE = 'subdir/sample2.ad' - private static final String ASCIIDOC_INVALID_FILE = 'subdir/_include.adoc' - - Project project - File testRootDir - File srcDir - File outDir - ByteArrayOutputStream systemOut - - PrintStream originSystemOut - - def setup() { - project = ProjectBuilder.builder().withName('test').build() - project.configurations.create(ASCIIDOCTOR) - testRootDir = new File('.') - srcDir = new File(testRootDir, ASCIIDOC_RESOURCES_DIR).absoluteFile - outDir = new File(project.projectDir, ASCIIDOC_BUILD_DIR) - systemOut = new ByteArrayOutputStream() - originSystemOut = System.out - System.out = new PrintStream(systemOut) - } - - def cleanup() { - System.out = originSystemOut - } - - void 'Files starting with _ should not be included'() { - when: - AsciidoctorCompatibilityTask task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - sourceDir = srcDir - outputDir = outDir - } - - Set files = task.sourceFileTree.files - - then: - files.find { it.name == '_include.adoc' } == null - } - - def "Allow setting of options via method"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - options eruby: 'erb' - options eruby: 'erubis' - options doctype: 'book', toc: 'right' - } - - then: - !systemOut.toString().contains('deprecated') - task.options['eruby'] == 'erubis' - task.options['doctype'] == 'book' - task.options['toc'] == 'right' - } - - def "Allow setting of options via assignment"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - options = [eruby: 'erb', toc: 'right'] - options = [eruby: 'erubis', doctype: 'book'] - } - - then: - !systemOut.toString().contains('deprecated') - task.options['eruby'] == 'erubis' - task.options['doctype'] == 'book' - !task.options.containsKey('toc') - } - - def "Allow setting of attributes via method (Map variant)"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - attributes 'source-highlighter': 'foo' - attributes 'source-highlighter': 'coderay' - attributes idprefix: '$', idseparator: '-' - } - - then: - !systemOut.toString().contains('deprecated') - task.attributes['source-highlighter'] == 'coderay' - task.attributes['idprefix'] == '$' - task.attributes['idseparator'] == '-' - } - - def "Allow setting of attributes via method (List variant)"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - attributes(['source-highlighter=foo', 'source-highlighter=coderay', 'idprefix=$', 'idseparator=-']) - } - - then: - !systemOut.toString().contains('deprecated') - task.attributes['source-highlighter'] == 'coderay' - task.attributes['idprefix'] == '$' - task.attributes['idseparator'] == '-' - } - - def "Allow setting of attributes via method (String variant)"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - attributes 'source-highlighter=foo source-highlighter=coderay idprefix=$ idseparator=-' - } - - then: - !systemOut.toString().contains('deprecated') - task.attributes['source-highlighter'] == 'coderay' - task.attributes['idprefix'] == '$' - task.attributes['idseparator'] == '-' - } - - def "Allow setting of attributes via assignment"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - attributes = ['source-highlighter': 'foo', idprefix: '$'] - attributes = ['source-highlighter': 'coderay', idseparator: '-'] - } - - then: - !systemOut.toString().contains('deprecated') - task.attributes['source-highlighter'] == 'coderay' - task.attributes['idseparator'] == '-' - !task.attributes.containsKey('idprefix') - } - - def "Mixing attributes with options, should produce a warning, but updates should be appended"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - options eruby: 'erubis', attributes: ['source-highlighter': 'foo', idprefix: '$'] - options doctype: 'book', attributes: [idseparator: '-'] - } - - then: - !task.attributes.containsKey('attributes') - task.attributes['source-highlighter'] == 'foo' - task.attributes['idseparator'] == '-' - task.attributes['idprefix'] == '$' - task.options['eruby'] == 'erubis' - task.options['doctype'] == 'book' - } - - def "Mixing attributes with options with assignment, should produce a warning, and attributes will be replaced"() { - when: - Map tmpStore = [eruby: 'erubis', attributes: ['source-highlighter': 'foo', idprefix: '$']] - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - options = tmpStore - options = [doctype: 'book', attributes: [idseparator: '-']] - } - - then: - !task.attributes.containsKey('attributes') - task.attributes['idseparator'] == '-' - !task.attributes.containsKey('source-highlighter') - !task.attributes.containsKey('idprefix') - !task.options.containsKey('eruby') - task.options['doctype'] == 'book' - // @Ignore('Wrong sysout capture') - // systemOut.toString().contains('Attributes found in options.') - } - - def "Mixing string legacy form of attributes with options with assignment, should produce a warning, and attributes will be replaced"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - options = [doctype: 'book', attributes: 'toc=right source-highlighter=coderay toc-title=Table\\ of\\ Contents'] - } - - then: - task.options['doctype'] == 'book' - !task.attributes.containsKey('attributes') - task.attributes['toc'] == 'right' - task.attributes['source-highlighter'] == 'coderay' - task.attributes['toc-title'] == 'Table of Contents' - } - - def "Mixing list legacy form of attributes with options with assignment, should produce a warning, and attributes will be replaced"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - options = [doctype: 'book', attributes: [ - 'toc=right', - 'source-highlighter=coderay', - 'toc-title=Table of Contents' - ]] - } - - then: - task.options['doctype'] == 'book' - !task.attributes.containsKey('attributes') - task.attributes['toc'] == 'right' - task.attributes['source-highlighter'] == 'coderay' - task.attributes['toc-title'] == 'Table of Contents' - // @Ignore('Wrong sysout capture') - // systemOut.toString().contains('Attributes found in options.') - } - - def "Allow setting of backends via method"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - backends 'foo', 'bar' - backends 'pdf' - } - - then: - !systemOut.toString().contains('deprecated') - task.backends.contains('pdf') - task.backends.contains('foo') - task.backends.contains('bar') - } - - def "Allow setting of backends via assignment"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - backends = ['pdf'] - backends = ['foo', 'bar'] - } - - then: - !systemOut.toString().contains('deprecated') - !task.backends.contains('pdf') - task.backends.contains('foo') - task.backends.contains('bar') - } - - def "Allow setting of requires via method"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - requires 'slim', 'tilt' - requires 'asciidoctor-pdf' - } - - then: - !systemOut.toString().contains('deprecated') - task.requires.contains('asciidoctor-pdf') - task.requires.contains('tilt') - task.requires.contains('slim') - } - - def "Allow setting of requires via assignment"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - requires = ['asciidoctor-pdf'] - requires = ['slim', 'tilt'] - } - - then: - !systemOut.toString().contains('deprecated') - !task.requires.contains('asciidoctor-pdf') - task.requires.contains('tilt') - task.requires.contains('slim') - } - - def "Allow setting of sourceDir via method"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - sourceDir project.projectDir - } - - then: - !systemOut.toString().contains('deprecated') - task.sourceDir.absolutePath == project.projectDir.absolutePath - task.sourceDir.absolutePath == project.projectDir.absolutePath - } - - def "When setting sourceDir via assignment"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - sourceDir = project.projectDir - } - - then: - task.sourceDir.absolutePath == project.projectDir.absolutePath - task.sourceDir.absolutePath == project.projectDir.absolutePath - } - - def "When setting sourceDir via setSourceDir"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - sourceDir = project.projectDir - } - - then: - task.sourceDir.absolutePath == project.projectDir.absolutePath - task.sourceDir.absolutePath == project.projectDir.absolutePath - !systemOut.toString().contains('deprecated') - } - - def "Allow setting of gemPath via method"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - gemPath project.projectDir - } - - then: - !systemOut.toString().contains('deprecated') - task.gemPath.files[0].absolutePath == project.projectDir.absolutePath - } - - def "When setting gemPath via assignment"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - gemPath = project.projectDir - } - - then: - task.gemPath.files[0].absolutePath == project.projectDir.absolutePath - !systemOut.toString().contains('deprecated') - } - - def "When setting gemPath via setGemPath"() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - gemPath = project.projectDir - } - - then: - task.gemPath.files[0].absolutePath == project.projectDir.absolutePath - !systemOut.toString().contains('deprecated') - } - - void "Method `sourceDocumentNames` should resolve descendant files of `sourceDir` if supplied as relatives"() { - when: 'I specify two files relative to sourceDir,including one in a subfolder' - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - sourceDir srcDir - sources { - include ASCIIDOC_SAMPLE_FILE - include ASCIIDOC_SAMPLE2_FILE - } - } - def fileCollection = task.sourceFileTree - - then: 'both files should be in collection, but any other files found in folder should be excluded' - fileCollection.contains(new File(srcDir, ASCIIDOC_SAMPLE_FILE).canonicalFile) - fileCollection.contains(new File(srcDir, ASCIIDOC_SAMPLE2_FILE).canonicalFile) - !fileCollection.contains(new File(srcDir, 'sample-docinfo.xml').canonicalFile) - fileCollection.files.size() == 2 - } - - void 'sanity test for default configuration'() { - when: - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) - - then: - task.sourceDir.absolutePath.replace('\\', '/').endsWith('src/docs/asciidoc') - task.outputDir.absolutePath.replace('\\', '/').endsWith('build/asciidoc') - } - - void 'Files in the resources copyspec should be recognised as input files'() { - given: - File imagesDir = new File(outDir, 'images') - File imageFile = new File(imagesDir, 'fake.txt') - imagesDir.mkdirs() - imageFile.text = 'foo' - - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - sourceDir srcDir - outputDir "${outDir}/foo" - backends AsciidoctorBackend.HTML5.id - - sources { - include ASCIIDOC_SAMPLE_FILE - } - - resources { - from(outDir) { - include 'images/**' - } - } - } - - when: - project.evaluate() - - then: - task.inputs.files.contains(project.file("${srcDir}/sample.asciidoc")) - task.inputs.files.contains(project.file("${imagesDir}/fake.txt")) - } - - static final String ATTRS_AS_STRING = 'toc=right source-highlighter=coderay' - static final String HIGHLIGTHER = 'coderay' - - @Unroll - void 'Should support #type value for attributes embedded in options'() { - given: - AsciidoctorTask task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - options = [ - attributes: data - ] - } - - Map options = task.options - Map attrs = task.attributes - - expect: - verifyAll { - options.isEmpty() - attrs.containsKey('toc') - attrs.containsKey('source-highlighter') - } - verifyAll { - attrs.toc == 'right' - attrs.'source-highlighter' == HIGHLIGTHER - } - - where: - type | data - 'String' | 'toc=right source-highlighter=coderay' - 'GString' | "${ATTRS_AS_STRING}" - 'List' | ['toc=right', "source-highlighter=${HIGHLIGTHER}"] - } - - void "Throws exception when attributes embedded in options is an unsupported type"() { - when: - project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - options = [ - attributes: 23 - ] - } - - then: - thrown(GradleException) - } - - void 'GStrings in options and attributes are converted into Strings'() { - given: - String variable = 'bar' - Task task = project.tasks.create(name: ASCIIDOCTOR, type: AsciidoctorTask) { - options = [ - template_dirs: ["${project.projectDir}/templates/haml"] - ] - attributes = [ - foo: "${variable}" - ] - } - - Map options = task.options - Map attrs = task.attributes - - expect: - verifyAll { - options.containsKey('template_dirs') - attrs.containsKey('foo') - } - verifyAll { - options.template_dirs[0].endsWith('haml') - attrs.'foo' == variable - } - } - - void 'Safe mode option is equal to level of SafeMode.UNSAFE by default'() { - expect: - resolveSafeModeLevel(null) == UNSAFE.level - } - - void 'Safe mode configuration option as integer is honored'() { - expect: - resolveSafeModeLevel(10) == SERVER.level - } - - void 'Safe mode configuration option as string is honored'() { - expect: - resolveSafeModeLevel('safe') == SAFE.level - } - - void 'Safe mode configuration option as enum is honored'() { - expect: - resolveSafeModeLevel(SECURE) == SECURE.level - } -}