mirror of
https://github.com/ethauvin/rife2-hello.git
synced 2025-04-25 23:37:12 -07:00
commit
a54ab9b23e
6 changed files with 100 additions and 22 deletions
|
@ -2,19 +2,15 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||||
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
application
|
|
||||||
id("com.uwyn.rife2")
|
id("com.uwyn.rife2")
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
}
|
}
|
||||||
|
|
||||||
base {
|
|
||||||
archivesName.set("hello")
|
|
||||||
version = 1.0
|
version = 1.0
|
||||||
group = "com.example"
|
group = "com.example"
|
||||||
}
|
|
||||||
|
|
||||||
application {
|
base {
|
||||||
mainClass.set("hello.App")
|
archivesName.set("hello")
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
@ -30,6 +26,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
rife2 {
|
rife2 {
|
||||||
|
mainClass.set("hello.App")
|
||||||
version.set("1.3.0")
|
version.set("1.3.0")
|
||||||
useAgent.set(true)
|
useAgent.set(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,13 @@ dependencies {
|
||||||
gradleApi()
|
gradleApi()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
withType<JavaCompile> {
|
||||||
|
options.isDeprecation = true
|
||||||
|
options.compilerArgs.add("-Xlint:unchecked")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gradlePlugin {
|
gradlePlugin {
|
||||||
plugins {
|
plugins {
|
||||||
create("rife2") {
|
create("rife2") {
|
||||||
|
|
|
@ -17,7 +17,10 @@ package com.uwyn.rife2.gradle;
|
||||||
|
|
||||||
import org.gradle.api.provider.Property;
|
import org.gradle.api.provider.Property;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public abstract class Rife2Extension {
|
public abstract class Rife2Extension {
|
||||||
|
public abstract Property<String> getMainClass();
|
||||||
|
|
||||||
public abstract Property<String> getVersion();
|
public abstract Property<String> getVersion();
|
||||||
|
|
||||||
public abstract Property<Boolean> getUseAgent();
|
public abstract Property<Boolean> getUseAgent();
|
||||||
|
|
|
@ -27,14 +27,10 @@ import org.gradle.api.component.AdhocComponentWithVariants;
|
||||||
import org.gradle.api.component.ConfigurationVariantDetails;
|
import org.gradle.api.component.ConfigurationVariantDetails;
|
||||||
import org.gradle.api.file.DuplicatesStrategy;
|
import org.gradle.api.file.DuplicatesStrategy;
|
||||||
import org.gradle.api.plugins.BasePluginExtension;
|
import org.gradle.api.plugins.BasePluginExtension;
|
||||||
import org.gradle.api.plugins.JavaApplication;
|
|
||||||
import org.gradle.api.plugins.JavaPlugin;
|
import org.gradle.api.plugins.JavaPlugin;
|
||||||
import org.gradle.api.plugins.JavaPluginExtension;
|
import org.gradle.api.plugins.JavaPluginExtension;
|
||||||
import org.gradle.api.plugins.PluginContainer;
|
import org.gradle.api.plugins.PluginContainer;
|
||||||
import org.gradle.api.tasks.JavaExec;
|
import org.gradle.api.tasks.*;
|
||||||
import org.gradle.api.tasks.SourceSet;
|
|
||||||
import org.gradle.api.tasks.TaskContainer;
|
|
||||||
import org.gradle.api.tasks.TaskProvider;
|
|
||||||
import org.gradle.api.tasks.bundling.Jar;
|
import org.gradle.api.tasks.bundling.Jar;
|
||||||
import org.gradle.api.tasks.testing.Test;
|
import org.gradle.api.tasks.testing.Test;
|
||||||
import org.gradle.process.CommandLineArgumentProvider;
|
import org.gradle.process.CommandLineArgumentProvider;
|
||||||
|
@ -42,10 +38,11 @@ import org.gradle.process.CommandLineArgumentProvider;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@SuppressWarnings({"ALL", "unused"})
|
||||||
public class Rife2Plugin implements Plugin<Project> {
|
public class Rife2Plugin implements Plugin<Project> {
|
||||||
|
|
||||||
public static final String DEFAULT_TEMPLATES_DIR = "src/main/templates";
|
public static final String DEFAULT_TEMPLATES_DIR = "src/main/templates";
|
||||||
public static final String DEFAULT_GENERATED_RIFE2_CLASSES_DIR = "generated/classes/rife2";
|
public static final String DEFAULT_GENERATED_RIFE2_CLASSES_DIR = "generated/classes/rife2";
|
||||||
|
public static final String RIFE2_GROUP = "rife2";
|
||||||
public static final String WEBAPP_SRCDIR = "src/main/webapp";
|
public static final String WEBAPP_SRCDIR = "src/main/webapp";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,6 +62,7 @@ public class Rife2Plugin implements Plugin<Project> {
|
||||||
createRife2DevelopmentOnlyConfiguration(project, configurations, dependencyHandler, precompileTemplates);
|
createRife2DevelopmentOnlyConfiguration(project, configurations, dependencyHandler, precompileTemplates);
|
||||||
exposePrecompiledTemplatesToTestTask(project, configurations, dependencyHandler, precompileTemplates);
|
exposePrecompiledTemplatesToTestTask(project, configurations, dependencyHandler, precompileTemplates);
|
||||||
configureAgent(project, plugins, rife2Extension, rife2AgentClasspath);
|
configureAgent(project, plugins, rife2Extension, rife2AgentClasspath);
|
||||||
|
registerRunTask(project, rife2Extension, rife2AgentClasspath);
|
||||||
TaskProvider<Jar> uberJarTask = registerUberJarTask(project, plugins, javaPluginExtension, rife2Extension, tasks, precompileTemplates);
|
TaskProvider<Jar> uberJarTask = registerUberJarTask(project, plugins, javaPluginExtension, rife2Extension, tasks, precompileTemplates);
|
||||||
bundlePrecompiledTemplatesIntoJarFile(tasks, precompileTemplates);
|
bundlePrecompiledTemplatesIntoJarFile(tasks, precompileTemplates);
|
||||||
configureMavenPublishing(project, plugins, configurations, uberJarTask);
|
configureMavenPublishing(project, plugins, configurations, uberJarTask);
|
||||||
|
@ -81,13 +79,15 @@ public class Rife2Plugin implements Plugin<Project> {
|
||||||
conf.attributes(attrs -> {
|
conf.attributes(attrs -> {
|
||||||
for (Attribute<?> attribute : runtimeAttributes.keySet()) {
|
for (Attribute<?> attribute : runtimeAttributes.keySet()) {
|
||||||
Object value = runtimeAttributes.getAttribute(attribute);
|
Object value = runtimeAttributes.getAttribute(attribute);
|
||||||
//noinspection unchecked
|
if (value != null) {
|
||||||
if (Bundling.class.equals(attribute.getType())) {
|
if (Bundling.class.equals(attribute.getType())) {
|
||||||
attrs.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.SHADOWED));
|
attrs.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.SHADOWED));
|
||||||
} else {
|
} else {
|
||||||
|
//noinspection unchecked
|
||||||
attrs.attribute((Attribute<Object>) attribute, value);
|
attrs.attribute((Attribute<Object>) attribute, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
AdhocComponentWithVariants component = (AdhocComponentWithVariants) project.getComponents().getByName("java");
|
AdhocComponentWithVariants component = (AdhocComponentWithVariants) project.getComponents().getByName("java");
|
||||||
|
@ -125,6 +125,8 @@ public class Rife2Plugin implements Plugin<Project> {
|
||||||
TaskContainer tasks,
|
TaskContainer tasks,
|
||||||
TaskProvider<PrecompileTemplates> precompileTemplatesTask) {
|
TaskProvider<PrecompileTemplates> precompileTemplatesTask) {
|
||||||
return tasks.register("uberJar", Jar.class, jar -> {
|
return tasks.register("uberJar", Jar.class, jar -> {
|
||||||
|
jar.setGroup(RIFE2_GROUP);
|
||||||
|
jar.setDescription("Assembles the web application and all dependencies into a single jar archive.");
|
||||||
var base = project.getExtensions().getByType(BasePluginExtension.class);
|
var base = project.getExtensions().getByType(BasePluginExtension.class);
|
||||||
jar.getArchiveBaseName().convention(project.provider(() -> base.getArchivesName().get() + "-uber"));
|
jar.getArchiveBaseName().convention(project.provider(() -> base.getArchivesName().get() + "-uber"));
|
||||||
jar.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE);
|
jar.setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE);
|
||||||
|
@ -156,8 +158,7 @@ public class Rife2Plugin implements Plugin<Project> {
|
||||||
private static Rife2Extension createRife2Extension(Project project) {
|
private static Rife2Extension createRife2Extension(Project project) {
|
||||||
var rife2 = project.getExtensions().create("rife2", Rife2Extension.class);
|
var rife2 = project.getExtensions().create("rife2", Rife2Extension.class);
|
||||||
rife2.getUseAgent().convention(false);
|
rife2.getUseAgent().convention(false);
|
||||||
rife2.getUberMainClass().convention(project.getExtensions().getByType(JavaApplication.class).getMainClass()
|
rife2.getUberMainClass().set(rife2.getMainClass() + "Uber");
|
||||||
.map(mainClass -> mainClass + "Uber"));
|
|
||||||
return rife2;
|
return rife2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +200,8 @@ public class Rife2Plugin implements Plugin<Project> {
|
||||||
private static TaskProvider<PrecompileTemplates> registerPrecompileTemplateTask(Project project,
|
private static TaskProvider<PrecompileTemplates> registerPrecompileTemplateTask(Project project,
|
||||||
Configuration rife2CompilerClasspath) {
|
Configuration rife2CompilerClasspath) {
|
||||||
return project.getTasks().register("precompileTemplates", PrecompileTemplates.class, task -> {
|
return project.getTasks().register("precompileTemplates", PrecompileTemplates.class, task -> {
|
||||||
|
task.setGroup(RIFE2_GROUP);
|
||||||
|
task.setDescription("Pre-compiles the templates.");
|
||||||
task.getVerbose().convention(true);
|
task.getVerbose().convention(true);
|
||||||
task.getClasspath().from(rife2CompilerClasspath);
|
task.getClasspath().from(rife2CompilerClasspath);
|
||||||
task.getType().convention("html");
|
task.getType().convention("html");
|
||||||
|
@ -206,4 +209,17 @@ public class Rife2Plugin implements Plugin<Project> {
|
||||||
task.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir(DEFAULT_GENERATED_RIFE2_CLASSES_DIR));
|
task.getOutputDirectory().set(project.getLayout().getBuildDirectory().dir(DEFAULT_GENERATED_RIFE2_CLASSES_DIR));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void registerRunTask(Project project, Rife2Extension rife2Extension,
|
||||||
|
Configuration rife2CompilerClasspath) {
|
||||||
|
project.getTasks().register("run", RunTask.class, task -> {
|
||||||
|
task.setGroup(RIFE2_GROUP);
|
||||||
|
task.setDescription("Runs this project as a web application.");
|
||||||
|
task.getAgentClassPath().set(rife2CompilerClasspath.getAsPath());
|
||||||
|
task.getClasspath().from(project.getExtensions().getByType(SourceSetContainer.class)
|
||||||
|
.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
|
||||||
|
task.getMainClass().set(rife2Extension.getMainClass());
|
||||||
|
task.getTemplatesDirectory().set(project.getLayout().getProjectDirectory().dir(DEFAULT_TEMPLATES_DIR));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
54
build-logic/src/main/java/com/uwyn/rife2/gradle/RunTask.java
Normal file
54
build-logic/src/main/java/com/uwyn/rife2/gradle/RunTask.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2003-2021 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 com.uwyn.rife2.gradle;
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask;
|
||||||
|
import org.gradle.api.file.ConfigurableFileCollection;
|
||||||
|
import org.gradle.api.file.DirectoryProperty;
|
||||||
|
import org.gradle.api.provider.Property;
|
||||||
|
import org.gradle.api.tasks.*;
|
||||||
|
import org.gradle.process.ExecOperations;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CacheableTask
|
||||||
|
public abstract class RunTask extends DefaultTask {
|
||||||
|
@Input
|
||||||
|
public abstract Property<String> getAgentClassPath();
|
||||||
|
|
||||||
|
@Classpath
|
||||||
|
public abstract ConfigurableFileCollection getClasspath();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected abstract ExecOperations getExecOperations();
|
||||||
|
|
||||||
|
@Input
|
||||||
|
public abstract Property<String> getMainClass();
|
||||||
|
|
||||||
|
@InputDirectory
|
||||||
|
@PathSensitive(PathSensitivity.RELATIVE)
|
||||||
|
public abstract DirectoryProperty getTemplatesDirectory();
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
public void run() {
|
||||||
|
getExecOperations().javaexec(run -> {
|
||||||
|
run.setClasspath(getProject().getObjects().fileCollection().from(getTemplatesDirectory()).plus(getClasspath()));
|
||||||
|
run.getMainClass().set(getMainClass());
|
||||||
|
run.args(List.of("-javaagent:" + getAgentClassPath().get()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,9 +2,10 @@ plugins {
|
||||||
war
|
war
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version = 1.0
|
||||||
|
|
||||||
base {
|
base {
|
||||||
archivesName.set("hello")
|
archivesName.set("hello")
|
||||||
version = 1.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue