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 40129aef6..000000000 --- a/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/AsciidoctorFunctionalSpec.groovy +++ /dev/null @@ -1,238 +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 - -/** - * 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é - */ -@SuppressWarnings(['DuplicateStringLiteral', 'MethodName']) -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 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 cc91da9f6..000000000 --- a/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/CompatExtensionMultiuseFunctionalSpec.groovy +++ /dev/null @@ -1,89 +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 - */ -@SuppressWarnings(['MethodName', 'DuplicateStringLiteral']) -class CompatExtensionMultiuseFunctionalSpec extends FunctionalSpecification { - - static final String TEST_PROJECTS_DIR = FunctionalSpecification.TEST_PROJECTS_DIR - - void setup() { - testProjectDir.root.mkdirs() - } - - def '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 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 97603ac64..000000000 --- a/asciidoctor-gradle-jvm/src/intTest/groovy/org/asciidoctor/gradle/compat/ExtensionsFunctionalSpec.groovy +++ /dev/null @@ -1,167 +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é - */ -@SuppressWarnings(['DuplicateStringLiteral', 'MethodName', 'Println']) -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 - - void setup() { - createTestProject('extensions') - resultFile = new File(testProjectDir.root, "${ASCIIDOC_BUILD_DIR}/html5/${ASCIIDOC_INLINE_EXTENSIONS_RESULT_FILE}") - } - - @Unroll - @SuppressWarnings('DuplicateListLiteral') - 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 a0817cdc6..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 { - ALL_BACKENDS = (values().collectEntries { [it.id, it] }.asImmutable()) as Map - } - - private AsciidoctorBackend(String id) { - this.id = id - } - - String getId() { - id - } - - static boolean isBuiltIn(String name) { - ALL_BACKENDS.containsKey(name) - } -} 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 2e87eee75..000000000 --- a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityPlugin.groovy +++ /dev/null @@ -1,171 +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 -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:' - - 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 - 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)) - } - } - } - } - } - - @SuppressWarnings('FactoryMethodName') - 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() - } - } - - @CompileDynamic - Closure excludeGroovy() { - return { - exclude module: 'groovy-all' - } - } -} 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 b985751cf..000000000 --- a/asciidoctor-gradle-jvm/src/main/groovy/org/asciidoctor/gradle/compat/AsciidoctorCompatibilityTask.groovy +++ /dev/null @@ -1,765 +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.internal.ExecutorConfiguration -import org.asciidoctor.gradle.internal.ExecutorConfigurationContainer -import org.asciidoctor.gradle.internal.ExecutorLogLevel -import org.asciidoctor.gradle.internal.JavaExecUtils -import org.asciidoctor.gradle.base.Transform -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 -@java.lang.SuppressWarnings('NoWildcardImports') -import org.gradle.api.tasks.* -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.* -import static org.asciidoctor.gradle.jvm.AsciidoctorJExtension.GUAVA_REQUIRED_FOR_EXTERNALS -import static org.asciidoctor.gradle.internal.JavaExecUtils.getJavaExecClasspath -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']) -@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 extensions. 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 - - /** 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 added to exustign 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 - */ - @SuppressWarnings('ConfusingMethodName') - @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 - */ - @SuppressWarnings('ConfusingMethodName') - 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('extensions', 'Extensions will need to be set via the asciidoctorj project and task extensions') - 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 - */ - @SuppressWarnings('ConfusingMethodName') - @Deprecated - void gemPath(Object... f) { - migrationMessage('gemPath', 'GEM paths will need to be set via the asciidoctorj project and task extensions 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 - } - - protected AsciidoctorCompatibilityTask() { - srcDir = project.file('src/docs/asciidoc') - } - - protected Set activeBackends() { - this.backends.empty ? [DEFAULT_BACKEND].toSet() : this.backends - } - - 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 -> -// configureForkOptions(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 - } - } - } - - @CompileDynamic - 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 - 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 - } - - @CompileDynamic - protected static void processCollectionAttributes(Map attributes, rawAttributes) { - for (attr in rawAttributes) { - if (attr instanceof CharSequence) { - def (k, v) = attr.toString().split('=', 2) as List - attributes.put(k, v != null ? v : '') - } else { - // QUESTION should we just coerce it to a String? - throw new InvalidUserDataException("Unsupported type for attribute ${attr}: ${attr.getClass()}") - } - } - } - - @SuppressWarnings(['DuplicateStringLiteral', 'DuplicateNumberLiteral']) - @CompileDynamic - 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) { - def 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 - } - - @SuppressWarnings('Instanceof') - 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 - } - } -} - 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 9743d1f4a..000000000 --- a/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorExtensionSpec.groovy +++ /dev/null @@ -1,44 +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 - -@SuppressWarnings(['MethodName']) -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 a67085eb6..000000000 --- a/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorPluginSpec.groovy +++ /dev/null @@ -1,121 +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 - */ -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 491f8b8d1..000000000 --- a/asciidoctor-gradle-jvm/src/test/groovy/org/asciidoctor/gradle/compat/AsciidoctorTaskSpec.groovy +++ /dev/null @@ -1,531 +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 at some stage. -@SuppressWarnings(['DuplicateStringLiteral', 'MethodName', 'MethodCount', 'DuplicateNumberLiteral', 'DuplicateMapLiteral', 'UnusedPrivateField']) -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' - } - - @SuppressWarnings('MethodName') - 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') - } - - @SuppressWarnings('MethodName') - 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'] == '-' - } - - @SuppressWarnings('MethodName') - 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'] == '-' - } - - @SuppressWarnings('MethodName') - 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'] == '-' - } - - @SuppressWarnings('MethodName') - 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') - } - - @SuppressWarnings('MethodName') - 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' - } - - @SuppressWarnings('MethodName') - 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.') - } - - @SuppressWarnings('MethodName') - 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' - } - - @SuppressWarnings('MethodName') - 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.') - } - - @SuppressWarnings('MethodName') - 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') - } - - @SuppressWarnings('MethodName') - 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') - } - - @SuppressWarnings('MethodName') - 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') - } - - @SuppressWarnings('MethodName') - 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') - } - - @SuppressWarnings('MethodName') - 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 - } - - - @SuppressWarnings('MethodName') - 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 - - } - - @SuppressWarnings('MethodName') - 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') - } - - @SuppressWarnings('MethodName') - 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 - } - - @SuppressWarnings('MethodName') - 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') - } - - @SuppressWarnings('MethodName') - 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 - } -}