21 changed files with 1128 additions and 283 deletions
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import org.gradle.api.Project; |
||||
|
||||
/** |
||||
* A contribution of aggregate content. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
class AggregateContentContribution extends ConsumableContentContribution { |
||||
|
||||
protected AggregateContentContribution(Project project, String name) { |
||||
super(project, "aggregate", name); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import javax.inject.Inject; |
||||
|
||||
import org.antora.gradle.AntoraPlugin; |
||||
import org.gradle.api.Action; |
||||
import org.gradle.api.NamedDomainObjectContainer; |
||||
import org.gradle.api.Plugin; |
||||
import org.gradle.api.Project; |
||||
import org.gradle.api.file.CopySpec; |
||||
|
||||
/** |
||||
* {@link Plugin} for a project that contributes to Antora-based documentation that is |
||||
* {@link AntoraDependenciesPlugin depended upon} by another project. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
public class AntoraContributorPlugin implements Plugin<Project> { |
||||
|
||||
@Override |
||||
public void apply(Project project) { |
||||
project.getPlugins().apply(AntoraPlugin.class); |
||||
NamedDomainObjectContainer<Contribution> antoraContributions = project.getObjects() |
||||
.domainObjectContainer(Contribution.class, |
||||
(name) -> project.getObjects().newInstance(Contribution.class, name, project)); |
||||
project.getExtensions().add("antoraContributions", antoraContributions); |
||||
} |
||||
|
||||
public static class Contribution { |
||||
|
||||
private final String name; |
||||
|
||||
private final Project project; |
||||
|
||||
@Inject |
||||
public Contribution(String name, Project project) { |
||||
this.name = name; |
||||
this.project = project; |
||||
} |
||||
|
||||
public String getName() { |
||||
return this.name; |
||||
} |
||||
|
||||
public void source() { |
||||
new SourceContribution(this.project, this.name).produce(); |
||||
} |
||||
|
||||
public void catalogContent(Action<CopySpec> action) { |
||||
CopySpec copySpec = this.project.copySpec(); |
||||
action.execute(copySpec); |
||||
new CatalogContentContribution(this.project, this.name).produceFrom(copySpec); |
||||
} |
||||
|
||||
public void aggregateContent(Action<CopySpec> action) { |
||||
CopySpec copySpec = this.project.copySpec(); |
||||
action.execute(copySpec); |
||||
new AggregateContentContribution(this.project, this.name).produceFrom(copySpec); |
||||
} |
||||
|
||||
public void localAggregateContent(Action<CopySpec> action) { |
||||
CopySpec copySpec = this.project.copySpec(); |
||||
action.execute(copySpec); |
||||
new LocalAggregateContentContribution(this.project, this.name).produceFrom(copySpec); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import javax.inject.Inject; |
||||
|
||||
import org.gradle.api.NamedDomainObjectContainer; |
||||
import org.gradle.api.Plugin; |
||||
import org.gradle.api.Project; |
||||
|
||||
/** |
||||
* {@link Plugin} for a project that depends on {@link AntoraContributorPlugin |
||||
* contributed} Antora-based documentation. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
public class AntoraDependenciesPlugin implements Plugin<Project> { |
||||
|
||||
@Override |
||||
public void apply(Project project) { |
||||
NamedDomainObjectContainer<AntoraDependency> antoraDependencies = project.getObjects() |
||||
.domainObjectContainer(AntoraDependency.class); |
||||
project.getExtensions().add("antoraDependencies", antoraDependencies); |
||||
} |
||||
|
||||
public static class AntoraDependency { |
||||
|
||||
private final String name; |
||||
|
||||
private final Project project; |
||||
|
||||
private String path; |
||||
|
||||
@Inject |
||||
public AntoraDependency(String name, Project project) { |
||||
this.name = name; |
||||
this.project = project; |
||||
} |
||||
|
||||
public String getName() { |
||||
return this.name; |
||||
} |
||||
|
||||
public String getPath() { |
||||
return this.path; |
||||
} |
||||
|
||||
public void setPath(String path) { |
||||
this.path = path; |
||||
} |
||||
|
||||
public void catalogContent() { |
||||
new CatalogContentContribution(this.project, this.name).consumeFrom(this.path); |
||||
} |
||||
|
||||
public void aggregateContent() { |
||||
new AggregateContentContribution(this.project, this.name).consumeFrom(this.path); |
||||
} |
||||
|
||||
public void source() { |
||||
new SourceContribution(this.project, this.name).consumeFrom(this.path); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import org.gradle.api.Project; |
||||
|
||||
/** |
||||
* A contribution of catalog content. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
class CatalogContentContribution extends ConsumableContentContribution { |
||||
|
||||
CatalogContentContribution(Project project, String name) { |
||||
super(project, "catalog", name); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,107 @@
@@ -0,0 +1,107 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import org.gradle.api.Project; |
||||
import org.gradle.api.Task; |
||||
import org.gradle.api.artifacts.Configuration; |
||||
import org.gradle.api.artifacts.dsl.DependencyHandler; |
||||
import org.gradle.api.file.CopySpec; |
||||
import org.gradle.api.file.Directory; |
||||
import org.gradle.api.file.RegularFile; |
||||
import org.gradle.api.provider.Provider; |
||||
import org.gradle.api.publish.PublishingExtension; |
||||
import org.gradle.api.publish.maven.MavenPublication; |
||||
import org.gradle.api.tasks.TaskContainer; |
||||
import org.gradle.api.tasks.TaskProvider; |
||||
|
||||
/** |
||||
* A contribution of content to Antora that can be consumed by other projects. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
class ConsumableContentContribution extends ContentContribution { |
||||
|
||||
protected ConsumableContentContribution(Project project, String type, String name) { |
||||
super(project, name, type); |
||||
} |
||||
|
||||
@Override |
||||
void produceFrom(CopySpec copySpec) { |
||||
TaskProvider<? extends Task> producer = super.configureProduction(copySpec); |
||||
Configuration configuration = createConfiguration(getName(), |
||||
"Configuration for %s Antora %s content artifacts."); |
||||
configuration.setCanBeConsumed(true); |
||||
configuration.setCanBeResolved(false); |
||||
getProject().getArtifacts().add(configuration.getName(), producer); |
||||
} |
||||
|
||||
void consumeFrom(String path) { |
||||
Configuration configuration = createConfiguration(getName(), "Configuration for %s Antora %s content."); |
||||
configuration.setCanBeConsumed(false); |
||||
configuration.setCanBeResolved(true); |
||||
DependencyHandler dependencies = getProject().getDependencies(); |
||||
dependencies.add(configuration.getName(), |
||||
getProject().provider(() -> projectDependency(path, configuration.getName()))); |
||||
Provider<Directory> outputDirectory = outputDirectory("content", getName()); |
||||
TaskContainer tasks = getProject().getTasks(); |
||||
TaskProvider<?> copyAntoraContent = tasks.register(taskName("copy", "%s", configuration.getName()), |
||||
CopyAntoraContent.class, (task) -> configureCopyContent(task, path, configuration, outputDirectory)); |
||||
configureAntora(addInputFrom(copyAntoraContent, configuration.getName())); |
||||
configurePlaybookGeneration(this::addToZipContentsCollectorDependencies); |
||||
getProject().getExtensions() |
||||
.getByType(PublishingExtension.class) |
||||
.getPublications() |
||||
.withType(MavenPublication.class) |
||||
.configureEach((mavenPublication) -> addPublishedMavenArtifact(mavenPublication, copyAntoraContent)); |
||||
} |
||||
|
||||
private void configureCopyContent(CopyAntoraContent task, String path, Configuration configuration, |
||||
Provider<Directory> outputDirectory) { |
||||
task.setDescription( |
||||
"Syncs the %s Antora %s content from %s.".formatted(getName(), toDescription(getType()), path)); |
||||
task.setSource(configuration); |
||||
task.getOutputFile().set(outputDirectory.map(this::getContentZipFile)); |
||||
} |
||||
|
||||
private void addToZipContentsCollectorDependencies(GenerateAntoraPlaybook task) { |
||||
task.getAntoraExtensions().getZipContentsCollector().getDependencies().add(getName()); |
||||
} |
||||
|
||||
private void addPublishedMavenArtifact(MavenPublication mavenPublication, TaskProvider<?> copyAntoraContent) { |
||||
if ("maven".equals(mavenPublication.getName())) { |
||||
String classifier = "%s-%s-content".formatted(getName(), getType()); |
||||
mavenPublication.artifact(copyAntoraContent, (mavenArtifact) -> mavenArtifact.setClassifier(classifier)); |
||||
} |
||||
} |
||||
|
||||
private RegularFile getContentZipFile(Directory dir) { |
||||
Object version = getProject().getVersion(); |
||||
return dir.file("spring-boot-docs-%s-%s-%s-content.zip".formatted(version, getName(), getType())); |
||||
} |
||||
|
||||
private static String toDescription(String input) { |
||||
return input.replace("-", " "); |
||||
} |
||||
|
||||
private Configuration createConfiguration(String name, String description) { |
||||
return getProject().getConfigurations() |
||||
.create(configurationName(name, "Antora%sContent", getType()), |
||||
(configuration) -> configuration.setDescription(description.formatted(getName(), getType()))); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import org.gradle.api.Project; |
||||
import org.gradle.api.Task; |
||||
import org.gradle.api.file.CopySpec; |
||||
import org.gradle.api.tasks.TaskContainer; |
||||
import org.gradle.api.tasks.TaskProvider; |
||||
import org.gradle.api.tasks.bundling.Zip; |
||||
|
||||
/** |
||||
* A contribution of content to Antora. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
abstract class ContentContribution extends Contribution { |
||||
|
||||
private final String type; |
||||
|
||||
protected ContentContribution(Project project, String name, String type) { |
||||
super(project, name); |
||||
this.type = type; |
||||
} |
||||
|
||||
protected String getType() { |
||||
return this.type; |
||||
} |
||||
|
||||
abstract void produceFrom(CopySpec copySpec); |
||||
|
||||
protected TaskProvider<? extends Task> configureProduction(CopySpec copySpec) { |
||||
TaskContainer tasks = getProject().getTasks(); |
||||
TaskProvider<Zip> zipContent = tasks.register(taskName("zip", "%sAntora%sContent", getName(), this.type), |
||||
Zip.class, (zip) -> { |
||||
zip.getDestinationDirectory() |
||||
.set(getProject().getLayout().getBuildDirectory().dir("generated/docs/antora-content")); |
||||
zip.getArchiveClassifier().set("%s-%s-content".formatted(getName(), this.type)); |
||||
zip.with(copySpec); |
||||
zip.setDescription("Creates a zip archive of the %s Antora %s content.".formatted(getName(), |
||||
toDescription(this.type))); |
||||
}); |
||||
configureAntora(addInputFrom(zipContent, zipContent.getName())); |
||||
return zipContent; |
||||
} |
||||
|
||||
private static String toDescription(String input) { |
||||
return input.replace("-", " "); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,115 @@
@@ -0,0 +1,115 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.Map; |
||||
|
||||
import org.antora.gradle.AntoraTask; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.gradle.api.Action; |
||||
import org.gradle.api.Project; |
||||
import org.gradle.api.artifacts.Dependency; |
||||
import org.gradle.api.file.Directory; |
||||
import org.gradle.api.provider.Provider; |
||||
import org.gradle.api.tasks.PathSensitivity; |
||||
import org.gradle.api.tasks.TaskProvider; |
||||
|
||||
import org.springframework.boot.build.AntoraConventions; |
||||
|
||||
/** |
||||
* A contribution to Antora. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
abstract class Contribution { |
||||
|
||||
private final Project project; |
||||
|
||||
private final String name; |
||||
|
||||
protected Contribution(Project project, String name) { |
||||
this.project = project; |
||||
this.name = name; |
||||
} |
||||
|
||||
protected Project getProject() { |
||||
return this.project; |
||||
} |
||||
|
||||
protected String getName() { |
||||
return this.name; |
||||
} |
||||
|
||||
protected Dependency projectDependency(String path, String configurationName) { |
||||
return getProject().getDependencies().project(Map.of("path", path, "configuration", configurationName)); |
||||
} |
||||
|
||||
protected Provider<Directory> outputDirectory(String dependencyType, String theName) { |
||||
return getProject().getLayout() |
||||
.getBuildDirectory() |
||||
.dir("generated/docs/antora-dependencies-" + dependencyType + "/" + theName); |
||||
} |
||||
|
||||
protected String taskName(String verb, String object, String... args) { |
||||
return name(verb, object, args); |
||||
} |
||||
|
||||
protected String configurationName(String name, String type, String... args) { |
||||
return name(toCamelCase(name), type, args); |
||||
} |
||||
|
||||
protected void configurePlaybookGeneration(Action<GenerateAntoraPlaybook> action) { |
||||
this.project.getTasks() |
||||
.named(AntoraConventions.GENERATE_ANTORA_PLAYBOOK_TASK_NAME, GenerateAntoraPlaybook.class, action); |
||||
} |
||||
|
||||
protected void configureAntora(Action<AntoraTask> action) { |
||||
this.project.getTasks().named("antora", AntoraTask.class, action); |
||||
} |
||||
|
||||
protected Action<AntoraTask> addInputFrom(TaskProvider<?> task, String propertyName) { |
||||
return (antora) -> antora.getInputs() |
||||
.files(task) |
||||
.withPathSensitivity(PathSensitivity.RELATIVE) |
||||
.withPropertyName(propertyName); |
||||
} |
||||
|
||||
private String name(String prefix, String format, String... args) { |
||||
return prefix + format.formatted(Arrays.stream(args).map(this::toPascalCase).toArray()); |
||||
} |
||||
|
||||
private String toPascalCase(String input) { |
||||
return StringUtils.capitalize(toCamelCase(input)); |
||||
} |
||||
|
||||
private String toCamelCase(String input) { |
||||
StringBuilder output = new StringBuilder(input.length()); |
||||
boolean capitalize = false; |
||||
for (char c : input.toCharArray()) { |
||||
if (c == '-') { |
||||
capitalize = true; |
||||
} |
||||
else { |
||||
output.append(capitalize ? Character.toUpperCase(c) : c); |
||||
capitalize = false; |
||||
} |
||||
} |
||||
return output.toString(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.StandardCopyOption; |
||||
|
||||
import javax.inject.Inject; |
||||
|
||||
import org.gradle.api.DefaultTask; |
||||
import org.gradle.api.file.FileCollection; |
||||
import org.gradle.api.file.RegularFileProperty; |
||||
import org.gradle.api.tasks.InputFiles; |
||||
import org.gradle.api.tasks.OutputFile; |
||||
import org.gradle.api.tasks.TaskAction; |
||||
|
||||
/** |
||||
* Tasks to copy Antora content. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
public abstract class CopyAntoraContent extends DefaultTask { |
||||
|
||||
private FileCollection source; |
||||
|
||||
@Inject |
||||
public CopyAntoraContent() { |
||||
} |
||||
|
||||
@InputFiles |
||||
public FileCollection getSource() { |
||||
return this.source; |
||||
} |
||||
|
||||
public void setSource(FileCollection source) { |
||||
this.source = source; |
||||
} |
||||
|
||||
@OutputFile |
||||
public abstract RegularFileProperty getOutputFile(); |
||||
|
||||
@TaskAction |
||||
void copyAntoraContent() throws IllegalStateException, IOException { |
||||
Path source = this.source.getSingleFile().toPath(); |
||||
Path target = getOutputFile().getAsFile().get().toPath(); |
||||
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import org.gradle.api.Project; |
||||
import org.gradle.api.file.CopySpec; |
||||
|
||||
import org.springframework.boot.build.antora.Extensions.AntoraExtensionsConfiguration.ZipContentsCollector.AlwaysInclude; |
||||
|
||||
/** |
||||
* A contribution of aggregate content that cannot be consumed by other projects. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
class LocalAggregateContentContribution extends ContentContribution { |
||||
|
||||
protected LocalAggregateContentContribution(Project project, String name) { |
||||
super(project, name, "local-aggregate"); |
||||
} |
||||
|
||||
@Override |
||||
void produceFrom(CopySpec copySpec) { |
||||
super.configureProduction(copySpec); |
||||
configurePlaybookGeneration(this::addToAlwaysInclude); |
||||
} |
||||
|
||||
private void addToAlwaysInclude(GenerateAntoraPlaybook task) { |
||||
task.getAntoraExtensions() |
||||
.getZipContentsCollector() |
||||
.getAlwaysInclude() |
||||
.add(new AlwaysInclude(getName(), "local-aggregate-content")); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import org.gradle.api.Project; |
||||
import org.gradle.api.artifacts.Configuration; |
||||
import org.gradle.api.artifacts.dsl.DependencyHandler; |
||||
import org.gradle.api.file.Directory; |
||||
import org.gradle.api.provider.Provider; |
||||
import org.gradle.api.tasks.TaskContainer; |
||||
import org.gradle.api.tasks.TaskProvider; |
||||
import org.gradle.api.tasks.bundling.Zip; |
||||
|
||||
import org.springframework.boot.build.AntoraConventions; |
||||
|
||||
/** |
||||
* A contribution of source to Antora. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
class SourceContribution extends Contribution { |
||||
|
||||
private static final String CONFIGURATION_NAME = "antoraSource"; |
||||
|
||||
SourceContribution(Project project, String name) { |
||||
super(project, name); |
||||
} |
||||
|
||||
void produce() { |
||||
Configuration antoraSource = getProject().getConfigurations().create(CONFIGURATION_NAME); |
||||
TaskProvider<Zip> antoraSourceZip = getProject().getTasks().register("antoraSourceZip", Zip.class, (zip) -> { |
||||
zip.getDestinationDirectory().set(getProject().getLayout().getBuildDirectory().dir("antora-source")); |
||||
zip.from(AntoraConventions.ANTORA_SOURCE_DIR); |
||||
zip.setDescription( |
||||
"Creates a zip archive of the Antora source in %s.".formatted(AntoraConventions.ANTORA_SOURCE_DIR)); |
||||
}); |
||||
getProject().getArtifacts().add(antoraSource.getName(), antoraSourceZip); |
||||
} |
||||
|
||||
void consumeFrom(String path) { |
||||
Configuration configuration = createConfiguration(getName()); |
||||
DependencyHandler dependencies = getProject().getDependencies(); |
||||
dependencies.add(configuration.getName(), |
||||
getProject().provider(() -> projectDependency(path, CONFIGURATION_NAME))); |
||||
Provider<Directory> outputDirectory = outputDirectory("source", getName()); |
||||
TaskContainer tasks = getProject().getTasks(); |
||||
TaskProvider<SyncAntoraSource> syncSource = tasks.register(taskName("sync", "%s", configuration.getName()), |
||||
SyncAntoraSource.class, (task) -> configureSyncSource(task, path, configuration, outputDirectory)); |
||||
configureAntora(addInputFrom(syncSource, configuration.getName())); |
||||
configurePlaybookGeneration( |
||||
(generatePlaybook) -> generatePlaybook.getContentSource().addStartPath(outputDirectory)); |
||||
} |
||||
|
||||
private void configureSyncSource(SyncAntoraSource task, String path, Configuration configuration, |
||||
Provider<Directory> outputDirectory) { |
||||
task.setDescription("Syncs the %s Antora source from %s.".formatted(getName(), path)); |
||||
task.setSource(configuration); |
||||
task.getOutputDirectory().set(outputDirectory); |
||||
} |
||||
|
||||
private Configuration createConfiguration(String name) { |
||||
return getProject().getConfigurations().create(configurationName(name, "AntoraSource")); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
/* |
||||
* Copyright 2012-2024 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://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.springframework.boot.build.antora; |
||||
|
||||
import javax.inject.Inject; |
||||
|
||||
import org.gradle.api.DefaultTask; |
||||
import org.gradle.api.file.ArchiveOperations; |
||||
import org.gradle.api.file.CopySpec; |
||||
import org.gradle.api.file.DirectoryProperty; |
||||
import org.gradle.api.file.FileCollection; |
||||
import org.gradle.api.file.FileSystemOperations; |
||||
import org.gradle.api.tasks.InputFiles; |
||||
import org.gradle.api.tasks.OutputDirectory; |
||||
import org.gradle.api.tasks.TaskAction; |
||||
|
||||
/** |
||||
* Task sync Antora source. |
||||
* |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
public abstract class SyncAntoraSource extends DefaultTask { |
||||
|
||||
private final FileSystemOperations fileSystemOperations; |
||||
|
||||
private final ArchiveOperations archiveOperations; |
||||
|
||||
private FileCollection source; |
||||
|
||||
@Inject |
||||
public SyncAntoraSource(FileSystemOperations fileSystemOperations, ArchiveOperations archiveOperations) { |
||||
this.fileSystemOperations = fileSystemOperations; |
||||
this.archiveOperations = archiveOperations; |
||||
} |
||||
|
||||
@OutputDirectory |
||||
public abstract DirectoryProperty getOutputDirectory(); |
||||
|
||||
@InputFiles |
||||
public FileCollection getSource() { |
||||
return this.source; |
||||
} |
||||
|
||||
public void setSource(FileCollection source) { |
||||
this.source = source; |
||||
} |
||||
|
||||
@TaskAction |
||||
void syncAntoraSource() { |
||||
this.fileSystemOperations.sync(this::syncAntoraSource); |
||||
} |
||||
|
||||
private void syncAntoraSource(CopySpec sync) { |
||||
sync.into(getOutputDirectory()); |
||||
this.source.getFiles().forEach((file) -> sync.from(this.archiveOperations.zipTree(file))); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue