Skip to content

Commit

Permalink
Remove feature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
jprinet committed Mar 30, 2023
1 parent 480e2c6 commit d7d6b85
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 104 deletions.
9 changes: 8 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ plugins {
org.gradle.playframework.`github-pages`
org.gradle.playframework.`documentation-test`
id("com.gradle.plugin-publish") version "0.12.0"
id("maven-publish")
}

group = "org.gradle.playframework"
version = "0.13"
version = "0.14"

repositories {
mavenCentral()
Expand Down Expand Up @@ -109,3 +110,9 @@ pluginBundle {
artifactId = base.archivesBaseName
}
}

publishing {
repositories {
mavenLocal()
}
}
4 changes: 3 additions & 1 deletion src/docs/asciidoc/10-plugin-conventions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ include::13-tasks.adoc[]

include::14-source-sets.adoc[]

include::15-dependency-configurations.adoc[]
include::15-dependency-configurations.adoc[]

include::16-routes-comments.adoc[]
4 changes: 4 additions & 0 deletions src/docs/asciidoc/16-routes-comments.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== Generated routes files comments

Routes files generated by the compiler contain comments which are changing across builds (absolute path and date depending on the framework version), this prevents tasks using those files as inputs to benefit from build cache.
The plugin is post-processing those files to remove timestamp and convert absolute paths to relative paths.
2 changes: 0 additions & 2 deletions src/docs/asciidoc/30-plugin-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ include::33-add-source-directories.adoc[]
include::34-compiler-options.adoc[]

include::35-add-distribution-files.adoc[]

include::36-strip-routes-comments.adoc[]
10 changes: 0 additions & 10 deletions src/docs/asciidoc/36-strip-routes-comments.adoc

This file was deleted.

2 changes: 1 addition & 1 deletion src/docs/asciidoc/50-changes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[discrete]
=== v0.14 (TBD)
* Add configuration to strip routes comments ({uri-github-issues}/109[issue #109]).
* Add configuration to post-process routes comments ({uri-github-issues}/109[issue #109]).

[discrete]
=== v0.13 (2023-01-24)
Expand Down
8 changes: 1 addition & 7 deletions src/docs/samples/play-2.4/groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,4 @@ play {
play {
injectedRoutesGenerator = true
}
// end::injected-routes-compiler[]

// tag::strip-routes-comments[]
play {
stripRoutesComments = true
}
// end::strip-routes-comments[]
// end::injected-routes-compiler[]
Original file line number Diff line number Diff line change
Expand Up @@ -262,31 +262,12 @@ $ROUTES_COMPILE_TASK_NAME {
new File(destinationDir, getScalaRoutesFileName('', '')).text.contains("extra.package")
}

def "do not strip generated comments by default"() {
when:
def "post-process generated comments"() {
given:
withRoutesTemplate()
then:
build(ROUTES_COMPILE_TASK_NAME)
and:
createRouteFileList().each {
def generatedFile = new File(destinationDir, it)
assert generatedFile.isFile()
assert generatedFile.getText(StandardCharsets.UTF_8.toString()).contains("// @SOURCE")
assert generatedFile.getText(StandardCharsets.UTF_8.toString()).contains("// @DATE")
}
}

def "can strip generated comments"() {
when:
buildFile << """
play {
stripRoutesComments = true
}
"""
withRoutesTemplate()
then:
build(ROUTES_COMPILE_TASK_NAME)
and:
expect:
createRouteFileList().each {
def generatedFile = new File(destinationDir, it)
assert generatedFile.isFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class PlayExtension {

private final PlayPlatform platform;
private final Property<Boolean> injectedRoutesGenerator;
private final Property<Boolean> stripRoutesComments;

public PlayExtension(ObjectFactory objectFactory) {
this.platform = objectFactory.newInstance(PlayPlatform.class, objectFactory);
Expand All @@ -38,8 +37,6 @@ public PlayExtension(ObjectFactory objectFactory) {
this.platform.getScalaVersion().convention(platform.getPlayVersion().map(playVersion -> PlayMajorVersion.forPlayVersion(playVersion).getDefaultScalaPlatform()));
this.injectedRoutesGenerator = objectFactory.property(Boolean.class);
injectedRoutesGenerator.convention(platform.getPlayVersion().map(playVersion -> !PlayMajorVersion.forPlayVersion(playVersion).hasSupportForStaticRoutesGenerator()));
this.stripRoutesComments = objectFactory.property(Boolean.class);
stripRoutesComments.convention(Boolean.FALSE);
}

/**
Expand Down Expand Up @@ -69,13 +66,4 @@ public PlayPlatform getPlatform() {
public Property<Boolean> getInjectedRoutesGenerator() {
return injectedRoutesGenerator;
}

/**
* Returns the property configuring if build dependent comments should be stripped from the generated routes files.
*
* @return Property configuring whether build dependent comments should be stripped
*/
public Property<Boolean> getStripRoutesComments() {
return stripRoutesComments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void apply(Project project) {
Configuration routesCompilerConfiguration = createRoutesCompilerConfiguration(project);
declareDefaultDependencies(project, routesCompilerConfiguration, playExtension);
RoutesSourceSet routesSourceSet = createCustomSourceSet(project, DefaultRoutesSourceSet.class, "routes");
createDefaultRoutesCompileTask(project, routesSourceSet.getRoutes(), routesCompilerConfiguration, playExtension, playExtension.getInjectedRoutesGenerator(), playExtension.getStripRoutesComments());
createDefaultRoutesCompileTask(project, routesSourceSet.getRoutes(), routesCompilerConfiguration, playExtension, playExtension.getInjectedRoutesGenerator());
}

private Configuration createRoutesCompilerConfiguration(Project project) {
Expand All @@ -44,12 +44,12 @@ private Configuration createRoutesCompilerConfiguration(Project project) {

private void declareDefaultDependencies(Project project, Configuration configuration, PlayExtension playExtension) {
configuration.defaultDependencies(dependencies -> {
String dependencyNotation = RoutesCompilerFactory.createAdapter(playExtension.getPlatform()).getDependencyNotation();
String dependencyNotation = RoutesCompilerFactory.createAdapter(playExtension.getPlatform(), project.getProjectDir().getAbsolutePath()).getDependencyNotation();
dependencies.add(project.getDependencies().create(dependencyNotation));
});
}

private void createDefaultRoutesCompileTask(Project project, SourceDirectorySet sourceDirectory, Configuration compilerConfiguration, PlayExtension playExtension, Provider<Boolean> injectedRoutesGenerator, Property<Boolean> stripRoutesComments) {
private void createDefaultRoutesCompileTask(Project project, SourceDirectorySet sourceDirectory, Configuration compilerConfiguration, PlayExtension playExtension, Provider<Boolean> injectedRoutesGenerator) {
project.getTasks().register(ROUTES_COMPILE_TASK_NAME, RoutesCompile.class, routesCompile -> {
routesCompile.setDescription("Generates routes for the '" + sourceDirectory.getDisplayName() + "' source set.");
routesCompile.getPlatform().set(project.provider(() -> playExtension.getPlatform()));
Expand All @@ -58,7 +58,6 @@ private void createDefaultRoutesCompileTask(Project project, SourceDirectorySet
routesCompile.getOutputDirectory().set(getOutputDir(project, sourceDirectory));
routesCompile.getInjectedRoutesGenerator().set(injectedRoutesGenerator);
routesCompile.getRoutesCompilerClasspath().setFrom(compilerConfiguration);
routesCompile.getStripRoutesComments().set(stripRoutesComments);
});
}
}
21 changes: 4 additions & 17 deletions src/main/java/org/gradle/playframework/tasks/RoutesCompile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.gradle.api.Action;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.Directory;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileTree;
import org.gradle.api.provider.ListProperty;
Expand Down Expand Up @@ -52,7 +51,7 @@ public class RoutesCompile extends SourceTask {
private final Property<PlayPlatform> platform;
private final Property<Boolean> injectedRoutesGenerator;
private final ConfigurableFileCollection routesCompilerClasspath;
private final Property<Boolean> stripRoutesComments;
private final String projectDir;

@Inject
public RoutesCompile(WorkerExecutor workerExecutor) {
Expand All @@ -67,8 +66,7 @@ public RoutesCompile(WorkerExecutor workerExecutor) {
this.injectedRoutesGenerator = getProject().getObjects().property(Boolean.class);
this.injectedRoutesGenerator.set(false);
this.routesCompilerClasspath = getProject().files();
this.stripRoutesComments = getProject().getObjects().property(Boolean.class);
this.stripRoutesComments.set(false);
this.projectDir = getProject().getProjectDir().getAbsolutePath();
}

/**
Expand Down Expand Up @@ -108,7 +106,7 @@ public ConfigurableFileCollection getRoutesCompilerClasspath() {
@TaskAction
@SuppressWarnings("Convert2Lambda")
void compile() {
RoutesCompileSpec spec = new DefaultRoutesCompileSpec(getSource().getFiles(), getOutputDirectory().get().getAsFile(), isJavaProject(), getNamespaceReverseRouter().get(), getGenerateReverseRoutes().get(), getInjectedRoutesGenerator().get(), getAdditionalImports().get(), getStripRoutesComments().get());
RoutesCompileSpec spec = new DefaultRoutesCompileSpec(getSource().getFiles(), getOutputDirectory().get().getAsFile(), isJavaProject(), getNamespaceReverseRouter().get(), getGenerateReverseRoutes().get(), getInjectedRoutesGenerator().get(), getAdditionalImports().get(), projectDir);

if (GradleVersion.current().compareTo(GradleVersion.version("5.6")) < 0) {
workerExecutor.submit(RoutesCompileRunnable.class, workerConfiguration -> {
Expand Down Expand Up @@ -136,7 +134,7 @@ public void execute(RoutesCompileParameters parameters) {
}

private Compiler<RoutesCompileSpec> getCompiler() {
return RoutesCompilerFactory.create(getPlatform().get());
return RoutesCompilerFactory.create(getPlatform().get(), projectDir);
}

@Internal
Expand Down Expand Up @@ -180,15 +178,4 @@ public Property<Boolean> getGenerateReverseRoutes() {
public Property<Boolean> getInjectedRoutesGenerator() {
return injectedRoutesGenerator;
}

/**
* Should build dependent comments in generated routes files be stripped? Default is false.
*
* @return false if build dependent comments in generated route files should not be stripped,
* true otherwise.
*/
@Input
public Property<Boolean> getStripRoutesComments() {
return stripRoutesComments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ public class DefaultRoutesCompileSpec implements RoutesCompileSpec {
private final boolean generateReverseRoutes;
private final boolean injectedRoutesGenerator;
private final Collection<String> additionalImports;
private final boolean stripRoutesComments;
private final String projectDir;

public DefaultRoutesCompileSpec(Iterable<File> sourceFiles, File outputDirectory, boolean javaProject, boolean namespaceReverseRouter, boolean generateReverseRoutes, boolean injectedRoutesGenerator, Collection<String> additionalImports, boolean stripRoutesComments) {
public DefaultRoutesCompileSpec(Iterable<File> sourceFiles, File outputDirectory, boolean javaProject, boolean namespaceReverseRouter, boolean generateReverseRoutes, boolean injectedRoutesGenerator, Collection<String> additionalImports, String projectDir) {
this.sourceFiles = sourceFiles;
this.outputDirectory = outputDirectory;
this.javaProject = javaProject;
this.namespaceReverseRouter = namespaceReverseRouter;
this.generateReverseRoutes = generateReverseRoutes;
this.injectedRoutesGenerator = injectedRoutesGenerator;
this.additionalImports = additionalImports;
this.stripRoutesComments = stripRoutesComments;
this.projectDir = projectDir;
}

@Override
Expand Down Expand Up @@ -60,7 +60,7 @@ public Collection<String> getAdditionalImports() {
}

@Override
public boolean isStripRoutesComments() {
return stripRoutesComments;
public String getProjectDir() {
return projectDir;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ class DefaultRoutesPostProcessor implements Serializable {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRoutesPostProcessor.class);

void execute(RoutesCompileSpec spec) {
if(spec.isStripRoutesComments()) {
try (Stream<Path> stream = Files.find(spec.getDestinationDir().toPath(), Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile())) {
stream.forEach(this::process);
} catch (IOException e) {
LOGGER.warn("Unable to post-process routes", e);
}
try (Stream<Path> stream = Files.find(spec.getDestinationDir().toPath(), Integer.MAX_VALUE, (filePath, fileAttr) -> fileAttr.isRegularFile())) {
stream.forEach(this::process);
} catch (IOException e) {
LOGGER.warn("Unable to post-process routes", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public interface RoutesCompileSpec extends PlayCompileSpec, Serializable {

Collection<String> getAdditionalImports();

boolean isStripRoutesComments();
String getProjectDir();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ private Boolean compile(File sourceFile, RoutesCompileSpec spec) {
try {
ClassLoader cl = getClass().getClassLoader();
ScalaMethod compile = adapter.getCompileMethod(cl);
return adapter.interpretResult(compile.invoke(adapter.createCompileParameters(cl, sourceFile, spec.getDestinationDir(), spec.isJavaProject(), spec.isNamespaceReverseRouter(), spec.isGenerateReverseRoutes(), spec.isInjectedRoutesGenerator(), spec.getAdditionalImports())));
System.setProperty("custompath", spec.getProjectDir());
return adapter.interpretResult(compile.invoke(adapter.createCompileParameters(cl, sourceFile, spec.getDestinationDir(), spec.isJavaProject(), spec.isNamespaceReverseRouter(), spec.isGenerateReverseRoutes(), spec.isInjectedRoutesGenerator(), spec.getAdditionalImports(), "barbar1")));
} catch (Exception e) {
throw new RuntimeException("Error invoking the Play routes compiler.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RoutesCompilerAdapterV23X extends DefaultVersionedRoutesCompilerAdapter {
private final List<String> defaultScalaImports = Arrays.asList("controllers.Assets.Asset");
private final List<String> defaultJavaImports = Arrays.asList("controllers.Assets.Asset", "play.libs.F");

public RoutesCompilerAdapterV23X(String playVersion) {
public RoutesCompilerAdapterV23X(String playVersion, String projectDir) {
// No 2.11 version of routes compiler published
super(playVersion, "2.10");
}
Expand All @@ -36,7 +36,7 @@ public ScalaMethod getCompileMethod(ClassLoader cl) throws ClassNotFoundExceptio
}

@Override
public Object[] createCompileParameters(ClassLoader cl, File file, File destinationDir, boolean javaProject, boolean namespaceReverseRouter, boolean generateReverseRoutes, boolean injectedRoutesGenerator, Collection<String> additionalImports) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
public Object[] createCompileParameters(ClassLoader cl, File file, File destinationDir, boolean javaProject, boolean namespaceReverseRouter, boolean generateReverseRoutes, boolean injectedRoutesGenerator, Collection<String> additionalImports, String projectDir) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
List<String> defaultImports = javaProject ? defaultJavaImports : defaultScalaImports;
defaultImports.addAll(additionalImports);
return new Object[] {
Expand All @@ -45,7 +45,8 @@ public Object[] createCompileParameters(ClassLoader cl, File file, File destinat
ScalaListBuffer.fromList(cl, defaultImports),
generateReverseRoutes,
isGenerateRefReverseRouter(),
namespaceReverseRouter
namespaceReverseRouter,
"barbar2"
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ScalaMethod getCompileMethod(ClassLoader cl) throws ClassNotFoundExceptio
}

@Override
public Object[] createCompileParameters(ClassLoader cl, File file, File destinationDir, boolean javaProject, boolean namespaceReverseRouter, boolean generateReverseRoutes, boolean injectedRoutesGenerator, Collection<String> additionalImports) throws ClassNotFoundException {
public Object[] createCompileParameters(ClassLoader cl, File file, File destinationDir, boolean javaProject, boolean namespaceReverseRouter, boolean generateReverseRoutes, boolean injectedRoutesGenerator, Collection<String> additionalImports, String projectDir) throws ClassNotFoundException {
List<String> defaultImports = getDefaultImports(javaProject);
defaultImports.addAll(additionalImports);

Expand All @@ -53,7 +53,8 @@ public Object[] createCompileParameters(ClassLoader cl, File file, File destinat
ScalaListBuffer.fromList(cl, defaultImports),
isGenerateForwardsRouter(),
generateReverseRoutes,
namespaceReverseRouter
namespaceReverseRouter,
"fuufuu"
);

String routeGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import java.util.List;

public class RoutesCompilerAdapterV27X extends RoutesCompilerAdapterV24X {
public RoutesCompilerAdapterV27X(String playVersion, String scalaVersion) {
private final String projectDir;

public RoutesCompilerAdapterV27X(String playVersion, String scalaVersion, String projectDir) {
super(playVersion, scalaVersion);
this.projectDir = projectDir;
}

@Override
public Object[] createCompileParameters(ClassLoader cl, File file, File destinationDir, boolean javaProject, boolean namespaceReverseRouter, boolean generateReverseRoutes, boolean injectedRoutesGenerator, Collection<String> additionalImports) throws ClassNotFoundException {
public Object[] createCompileParameters(ClassLoader cl, File file, File destinationDir, boolean javaProject, boolean namespaceReverseRouter, boolean generateReverseRoutes, boolean injectedRoutesGenerator, Collection<String> additionalImports, String projectDirFoo) throws ClassNotFoundException {
List<String> defaultImports = getDefaultImports(javaProject);
defaultImports.addAll(additionalImports);

Expand All @@ -24,7 +27,8 @@ public Object[] createCompileParameters(ClassLoader cl, File file, File destinat
ScalaSeq.fromList(cl, defaultImports),
isGenerateForwardsRouter(),
generateReverseRoutes,
namespaceReverseRouter
namespaceReverseRouter,
projectDir
);

String routeGenerator = PLAY_ROUTES_COMPILER_INJECTED_ROUTES_GENERATOR;
Expand Down
Loading

0 comments on commit d7d6b85

Please sign in to comment.