mirror of
https://github.com/ethauvin/rife2-hello.git
synced 2025-04-25 07:27:12 -07:00
Revert RunTask
This commit is contained in:
parent
86b7ec21d9
commit
65e579966c
7 changed files with 23 additions and 99 deletions
|
@ -3,15 +3,19 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent
|
|||
import com.uwyn.rife2.gradle.TemplateType.*
|
||||
|
||||
plugins {
|
||||
application
|
||||
id("com.uwyn.rife2")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
version = 1.0
|
||||
group = "com.example"
|
||||
|
||||
base {
|
||||
archivesName.set("hello")
|
||||
version = 1.0
|
||||
group = "com.example"
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set("hello.App")
|
||||
}
|
||||
|
||||
java {
|
||||
|
@ -27,7 +31,6 @@ repositories {
|
|||
}
|
||||
|
||||
rife2 {
|
||||
mainClass.set("hello.App")
|
||||
version.set("1.4.0")
|
||||
useAgent.set(true)
|
||||
precompiledTemplateTypes.addAll(HTML)
|
||||
|
|
|
@ -8,4 +8,4 @@
|
|||
<body>
|
||||
<p>Hello World</p>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -10,13 +10,6 @@ dependencies {
|
|||
gradleApi()
|
||||
}
|
||||
|
||||
tasks {
|
||||
withType<JavaCompile> {
|
||||
options.isDeprecation = true
|
||||
options.compilerArgs.add("-Xlint:unchecked")
|
||||
}
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("rife2") {
|
||||
|
|
|
@ -18,10 +18,7 @@ package com.uwyn.rife2.gradle;
|
|||
import org.gradle.api.provider.ListProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class Rife2Extension {
|
||||
public abstract Property<String> getMainClass();
|
||||
|
||||
public abstract Property<String> getVersion();
|
||||
|
||||
public abstract Property<Boolean> getUseAgent();
|
||||
|
|
|
@ -25,10 +25,14 @@ import org.gradle.api.component.AdhocComponentWithVariants;
|
|||
import org.gradle.api.component.ConfigurationVariantDetails;
|
||||
import org.gradle.api.file.DuplicatesStrategy;
|
||||
import org.gradle.api.plugins.BasePluginExtension;
|
||||
import org.gradle.api.plugins.JavaApplication;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.plugins.PluginContainer;
|
||||
import org.gradle.api.tasks.*;
|
||||
import org.gradle.api.tasks.JavaExec;
|
||||
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.testing.Test;
|
||||
import org.gradle.process.CommandLineArgumentProvider;
|
||||
|
@ -36,7 +40,6 @@ import org.gradle.process.CommandLineArgumentProvider;
|
|||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
@SuppressWarnings({"ALL", "unused"})
|
||||
public class Rife2Plugin implements Plugin<Project> {
|
||||
public static final String DEFAULT_TEMPLATES_DIR = "src/main/templates";
|
||||
public static final String DEFAULT_GENERATED_RIFE2_CLASSES_DIR = "generated/classes/rife2";
|
||||
|
@ -62,9 +65,7 @@ public class Rife2Plugin implements Plugin<Project> {
|
|||
createRife2DevelopmentOnlyConfiguration(project, configurations, dependencyHandler, precompileTemplates);
|
||||
exposePrecompiledTemplatesToTestTask(project, configurations, dependencyHandler, precompileTemplates);
|
||||
configureAgent(project, plugins, rife2Extension, rife2AgentClasspath);
|
||||
registerRunTask(project, rife2Extension, rife2AgentClasspath);
|
||||
var uberJarTask = registerUberJarTask(project, plugins, javaPluginExtension, rife2Extension, tasks, precompileTemplates);
|
||||
|
||||
TaskProvider<Jar> uberJarTask = registerUberJarTask(project, plugins, javaPluginExtension, rife2Extension, tasks, precompileTemplates);
|
||||
bundlePrecompiledTemplatesIntoJarFile(tasks, precompileTemplates);
|
||||
|
||||
configureMavenPublishing(project, plugins, configurations, uberJarTask);
|
||||
|
@ -86,13 +87,11 @@ public class Rife2Plugin implements Plugin<Project> {
|
|||
conf.attributes(attrs -> {
|
||||
for (Attribute<?> attribute : runtimeAttributes.keySet()) {
|
||||
Object value = runtimeAttributes.getAttribute(attribute);
|
||||
if (value != null) {
|
||||
if (Bundling.class.equals(attribute.getType())) {
|
||||
attrs.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.SHADOWED));
|
||||
} else {
|
||||
//noinspection unchecked
|
||||
attrs.attribute((Attribute<Object>) attribute, value);
|
||||
}
|
||||
//noinspection unchecked
|
||||
if (Bundling.class.equals(attribute.getType())) {
|
||||
attrs.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.SHADOWED));
|
||||
} else {
|
||||
attrs.attribute((Attribute<Object>) attribute, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -173,7 +172,8 @@ public class Rife2Plugin implements Plugin<Project> {
|
|||
private static Rife2Extension createRife2Extension(Project project) {
|
||||
var rife2 = project.getExtensions().create("rife2", Rife2Extension.class);
|
||||
rife2.getUseAgent().convention(false);
|
||||
rife2.getUberMainClass().set(rife2.getMainClass() + "Uber");
|
||||
rife2.getUberMainClass().convention(project.getExtensions().getByType(JavaApplication.class).getMainClass()
|
||||
.map(mainClass -> mainClass + "Uber"));
|
||||
return rife2;
|
||||
}
|
||||
|
||||
|
@ -226,18 +226,4 @@ public class Rife2Plugin implements Plugin<Project> {
|
|||
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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* 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,10 +2,9 @@ plugins {
|
|||
war
|
||||
}
|
||||
|
||||
version = 1.0
|
||||
|
||||
base {
|
||||
archivesName.set("hello")
|
||||
version = 1.0
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
@ -21,4 +20,4 @@ tasks.war {
|
|||
webAppDirectory.set(file("../app/src/main/webapp"))
|
||||
webXml = file("src/web.xml")
|
||||
rootSpec.exclude("**/jetty*.jar", "**/slf4j*.jar", "**/rife2*-agent.jar")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue