Successfully building a dist from a simple page.
This commit is contained in:
parent
e34bb38350
commit
30e463f1cf
@ -12,8 +12,12 @@ import com.jessebrault.ssg.page.PageSpec
|
||||
import com.jessebrault.ssg.text.Text
|
||||
import com.jessebrault.ssg.util.Diagnostic
|
||||
import com.jessebrault.ssg.view.PageView
|
||||
import com.jessebrault.ssg.view.WvcPageView
|
||||
import groovy.transform.TupleConstructor
|
||||
import groowt.util.di.RegistryObjectFactory
|
||||
import groowt.view.component.ViewComponent
|
||||
import groowt.view.component.context.DefaultComponentContext
|
||||
import groowt.view.web.DefaultWebViewComponentContext
|
||||
import io.github.classgraph.ClassGraph
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
@ -128,7 +132,6 @@ class DefaultStaticSiteGenerator implements StaticSiteGenerator {
|
||||
.addClassLoader(groovyClassLoader)
|
||||
basePackages.each { classgraph.acceptPackages(it) }
|
||||
|
||||
|
||||
def pages = [] as Set<Page>
|
||||
|
||||
try (def scanResult = classgraph.scan()) {
|
||||
@ -187,6 +190,13 @@ class DefaultStaticSiteGenerator implements StaticSiteGenerator {
|
||||
return
|
||||
}
|
||||
|
||||
// Prepare for rendering
|
||||
pageView.pageTitle = it.name
|
||||
pageView.url = buildSpec.baseUrl.get() + it.path
|
||||
if (pageView instanceof WvcPageView) {
|
||||
pageView.context = new DefaultWebViewComponentContext()
|
||||
}
|
||||
|
||||
// Render the page
|
||||
def sw = new StringWriter()
|
||||
try {
|
||||
|
@ -4,5 +4,8 @@ import groowt.view.View
|
||||
|
||||
interface PageView extends View {
|
||||
String getPageTitle()
|
||||
void setPageTitle(String pageTitle)
|
||||
|
||||
String getUrl()
|
||||
void setUrl(String url)
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ trait WithHtmlHelpers {
|
||||
String prettyFormat(String html) {
|
||||
Jsoup.parse(html).with {
|
||||
outputSettings().prettyPrint(true)
|
||||
toString()
|
||||
it.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,9 @@ abstract class AbstractBuildCommand extends AbstractSubCommand {
|
||||
groovyClassLoader.addURL(URLUtil.ofJarFile(classpathElement))
|
||||
}
|
||||
}
|
||||
|
||||
projectConnection.newBuild().forTasks('ssgJars').run()
|
||||
projectConnection.close()
|
||||
}
|
||||
|
||||
this.libDirs.each { libDir ->
|
||||
|
@ -5,7 +5,7 @@ import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class DeafultSsgBuildModel implements SsgBuildModel, Serializable {
|
||||
public class DefaultSsgBuildModel implements SsgBuildModel, Serializable {
|
||||
|
||||
private final Set<File> buildOutputLibs = new HashSet<>();
|
||||
private final Set<File> runtimeClasspath = new HashSet<>();
|
@ -3,10 +3,13 @@ package com.jessebrault.ssg.gradle;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.TaskCollection;
|
||||
import org.gradle.jvm.tasks.Jar;
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SsgBuildModelBuilder implements ToolingModelBuilder {
|
||||
|
||||
@Override
|
||||
@ -16,7 +19,7 @@ public class SsgBuildModelBuilder implements ToolingModelBuilder {
|
||||
|
||||
@Override
|
||||
public @NotNull Object buildAll(@NotNull String modelName, @NotNull Project project) {
|
||||
final SsgBuildModel ssgBuildModel = new DeafultSsgBuildModel();
|
||||
final SsgBuildModel ssgBuildModel = new DefaultSsgBuildModel();
|
||||
|
||||
final JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
|
||||
final SourceSet mainSourceSet = javaPluginExtension.getSourceSets().getByName("main");
|
||||
@ -25,6 +28,13 @@ public class SsgBuildModelBuilder implements ToolingModelBuilder {
|
||||
.get();
|
||||
ssgBuildModel.getBuildOutputLibs().addAll(jarTask.getOutputs().getFiles().getFiles());
|
||||
|
||||
final TaskCollection<Jar> allJarTasks = project.getTasks().withType(Jar.class);
|
||||
ssgBuildModel.getBuildOutputLibs().addAll(
|
||||
allJarTasks.stream()
|
||||
.flatMap(jar -> jar.getOutputs().getFiles().getFiles().stream())
|
||||
.collect(Collectors.toSet())
|
||||
);
|
||||
|
||||
ssgBuildModel.getRuntimeClasspath().addAll(mainSourceSet.getRuntimeClasspath().getFiles());
|
||||
|
||||
return ssgBuildModel;
|
||||
|
@ -9,6 +9,7 @@ import org.gradle.api.plugins.GroovyPlugin;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.tasks.*;
|
||||
import org.gradle.api.tasks.bundling.Jar;
|
||||
import org.gradle.api.tasks.compile.GroovyCompile;
|
||||
import org.gradle.api.tasks.compile.JavaCompile;
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry;
|
||||
@ -67,16 +68,39 @@ public class SsgGradlePlugin implements Plugin<Project> {
|
||||
sourceSets.create(name, sourceSet -> {
|
||||
// first, register the dirs
|
||||
// java
|
||||
sourceSet.getJava().setSrcDirs(List.of(name + File.separator + "java"));
|
||||
final var javaSourceDirectorySet = sourceSet.getJava();
|
||||
javaSourceDirectorySet.setSrcDirs(List.of(name + File.separator + "java"));
|
||||
|
||||
// groovy
|
||||
final var groovySourceDirectorySet = sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class);
|
||||
groovySourceDirectorySet.setSrcDirs(List.of(name + File.separator + "groovy"));
|
||||
|
||||
// resources
|
||||
sourceSet.getResources().setSrcDirs(List.of(name + File.separator + "resources"));
|
||||
|
||||
project.getTasks().withType(GroovyCompile.class).configureEach(groovyCompile -> {
|
||||
// second, configure the relevant compile tasks
|
||||
project.getTasks().named(sourceSet.getCompileJavaTaskName(), JavaCompile.class, javaCompile -> {
|
||||
javaCompile.source(name + File.separator + "java");
|
||||
});
|
||||
project.getTasks().named(sourceSet.getCompileTaskName("groovy"), GroovyCompile.class, groovyCompile -> {
|
||||
groovyCompile.source(name + File.separator + "groovy");
|
||||
});
|
||||
|
||||
// third, we need a jar task which knows where stuff is
|
||||
final TaskProvider<Jar> jarTaskProvider = project.getTasks().register(
|
||||
sourceSet.getJarTaskName(),
|
||||
Jar.class,
|
||||
jarTask -> {
|
||||
// jarTask.from(javaSourceDirectorySet.getClassesDirectory());
|
||||
jarTask.from(groovySourceDirectorySet.getClassesDirectory());
|
||||
jarTask.from(sourceSet.getResources());
|
||||
jarTask.getArchiveBaseName().set(project.getName() + "-" + name);
|
||||
}
|
||||
);
|
||||
|
||||
project.getTasks().named("ssgJars", ssgJarsTask -> {
|
||||
ssgJarsTask.dependsOn(jarTaskProvider);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -153,6 +177,10 @@ public class SsgGradlePlugin implements Plugin<Project> {
|
||||
project.getPlugins().apply(JavaPlugin.class);
|
||||
project.getPlugins().apply(GroovyPlugin.class);
|
||||
|
||||
// create our ssgJars task, which is just a holder for source set jar tasks
|
||||
project.getTasks().register("ssgJars");
|
||||
|
||||
// configure the repositories, tooling models, and source sets
|
||||
this.configureRepositories(project);
|
||||
this.configureToolingModelBuilders();
|
||||
this.configureSourceSets(project);
|
||||
|
2
test-ssg-project/.gitignore
vendored
2
test-ssg-project/.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
bin
|
||||
.ssg
|
||||
testBuild
|
||||
dist
|
||||
|
@ -1,19 +0,0 @@
|
||||
package com.jessebrault
|
||||
|
||||
import com.jessebrault.ssg.view.WvcPageView
|
||||
import jakarta.inject.Inject
|
||||
import jakarta.inject.Named
|
||||
|
||||
class Biography extends WvcPageView {
|
||||
|
||||
final String pageTitle
|
||||
final String url
|
||||
|
||||
@Inject
|
||||
Biography(@Named('siteTitle') String siteTitle, @Named('baseUrl') String baseUrl) {
|
||||
super(Biography.getResource('BiographyTemplate.wvc'))
|
||||
this.pageTitle = siteTitle + ': Biography'
|
||||
this.url = baseUrl + '/biography'
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.jessebrault.site
|
||||
|
||||
import com.jessebrault.ssg.page.PageSpec
|
||||
import com.jessebrault.ssg.view.WvcPageView
|
||||
import jakarta.inject.Inject
|
||||
|
||||
@PageSpec(name = 'Biography', path = '/biography')
|
||||
class Biography extends WvcPageView {
|
||||
|
||||
@Inject
|
||||
Biography() {
|
||||
super(Biography.getResource('BiographyTemplate.wvc'))
|
||||
println 'Hello from Biography!'
|
||||
}
|
||||
|
||||
@Override
|
||||
void renderTo(Writer out) throws IOException {
|
||||
println "Rendering: $pageTitle..."
|
||||
super.renderTo(out)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
package com.jessebrault.site
|
||||
---
|
||||
Hello, World!
|
@ -1,5 +0,0 @@
|
||||
$pageTitle
|
||||
|
||||
Hello, World!
|
||||
|
||||
$url
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
package com.jessebrault.site
|
||||
---
|
||||
$pageTitle
|
||||
$url
|
||||
|
||||
Hello, World!
|
Loading…
Reference in New Issue
Block a user