-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from ysb33r/dep-report-393
Report dependencies for any Asciidoctor task (#393)
- Loading branch information
Showing
8 changed files
with
209 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...radle-base/src/main/groovy/org/asciidoctor/gradle/base/internal/ConfigurationUtils.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.base.internal | ||
|
||
import groovy.transform.CompileStatic | ||
import org.asciidoctor.gradle.base.Transform | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.Configuration | ||
import org.gradle.api.provider.Provider | ||
import org.ysb33r.grolifant.api.StringUtils | ||
|
||
/** Utilities for dealing with Configurations | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
@CompileStatic | ||
class ConfigurationUtils { | ||
|
||
/** Extracts a {@link Configuration} if possible. | ||
* | ||
* @param project Associated project | ||
* @param sourceConfig Item that could be a source of a configuration | ||
* @return {@link Configuration} instance | ||
* | ||
* @throw {@code UnknownConfigurationException} | ||
*/ | ||
static Configuration asConfiguration(Project project, Object sourceConfig) { | ||
switch (sourceConfig) { | ||
case Configuration: | ||
return (Configuration) sourceConfig | ||
case Provider: | ||
return asConfiguration(project, ((Provider) sourceConfig).get()) | ||
default: | ||
project.configurations.getByName(StringUtils.stringize(sourceConfig)) | ||
} | ||
} | ||
|
||
/** Extracts a list of {@link Configuration} instances. | ||
* | ||
* @param project Associated project. | ||
* @param sourceConfigs Collection of items that could be sources of configurations. | ||
* @return List of {@link Configuration} instances. | ||
* | ||
* @throw {@code UnknownConfigurationException} | ||
*/ | ||
static List<Configuration> asConfigurations(Project project, Collection<Object> sourceConfigs) { | ||
Transform.toList(sourceConfigs) { | ||
asConfiguration(project, it) | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...-gradle-base/src/test/groovy/org/asciidoctor/gradle/base/AsciidoctorBasePluginSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.base | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.Configuration | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import spock.lang.Specification | ||
|
||
class AsciidoctorBasePluginSpec extends Specification { | ||
Project project = ProjectBuilder.builder().build() | ||
|
||
void 'Applying the plugin will add a report task rule'() { | ||
given: | ||
project.allprojects { | ||
apply plugin: 'org.asciidoctor.base' | ||
tasks.create 'foo', TestTask | ||
} | ||
|
||
when: | ||
project.tasks.getByName('fooDependencies') | ||
|
||
then: | ||
noExceptionThrown() | ||
} | ||
|
||
static class TestTask extends AbstractAsciidoctorBaseTask { | ||
Map<String, Object> attributes | ||
List<AsciidoctorAttributeProvider> attributeProviders | ||
Set<Configuration> reportableConfigurations = [] | ||
|
||
@Override | ||
void attributes(Map<String, Object> m) { | ||
} | ||
|
||
@Override | ||
protected String getEngineName() { | ||
null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters