Skip to content

Commit

Permalink
Merge pull request #28 from IntershopCommunicationsAG/createISMLResou…
Browse files Browse the repository at this point in the history
…rceList

Use ResourceListTask to create an index of ISML files, TLD support removed
  • Loading branch information
m-raab authored Jun 22, 2022
2 parents 7ef8a9f + 146da7e commit 826f85f
Show file tree
Hide file tree
Showing 27 changed files with 40 additions and 1,236 deletions.
2 changes: 0 additions & 2 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ The ISML Gradle plugin adds one task `isml` to the project. This task depends on
[cols="25%,30%,45%", width="90%, options="header"]
|===
|Task name |Type |Description
|prepareTagLibs | com.intershop.gradle.isml.tasks.PrepareTagLibs | This task prepares the environment for ISML compilation with TagLibs.
The output of this task is directly used by the isml2class* tasks.
|isml | Task | Overall ``isml`` code generation task of a project. This task depends on all ``isml2class`` tasks.
|isml2class<source set name> | com.intershop.gradle.isml.tasks.IsmlCompile | This task compiles ISML files to class files.
|===
Expand Down
9 changes: 2 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ val sonatypeUsername: String? by project
val sonatypePassword: String? by project

repositories {
gradlePluginPortal()
mavenCentral()
}

Expand All @@ -78,12 +79,6 @@ gradlePlugin {
displayName = project.name
description = project.description
}
create("ismltaglibPlugin") {
id = ismltaglibPluginId
implementationClass = "com.intershop.gradle.isml.IsmlTagLibPlugin"
displayName = project.name
description = project.description
}
}
}

Expand Down Expand Up @@ -281,8 +276,8 @@ dependencies {
compileOnly("org.apache.tomcat:tomcat-jasper:10.0.18")
compileOnly("org.apache.tomcat:tomcat-api:10.0.18")


compileOnly("com.intershop.icm:isml-parser:11.0.0")
implementation("com.intershop.gradle.resourcelist:resourcelist-gradle-plugin:4.3.3")

testImplementation("com.intershop.gradle.test:test-gradle-plugin:4.1.1")
testImplementation(gradleTestKit())
Expand Down
36 changes: 26 additions & 10 deletions src/main/kotlin/com/intershop/gradle/isml/IsmlPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ package com.intershop.gradle.isml
import com.intershop.gradle.isml.extension.IsmlExtension
import com.intershop.gradle.isml.tasks.Isml2Jsp
import com.intershop.gradle.isml.tasks.Jsp2Java
import com.intershop.gradle.isml.tasks.PrepareTagLibs
import com.intershop.gradle.resourcelist.extension.ResourceListExtension
import com.intershop.gradle.resourcelist.task.ResourceListFileTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskProvider
import java.util.*

/**
* Plugin Class implementation.
Expand Down Expand Up @@ -65,7 +68,8 @@ open class IsmlPlugin : Plugin<Project> {

if (extension.sourceSets.findByName(IsmlExtension.ISML_MAIN_SOURCESET) == null) {
val mainIsmlSourceSet = extension.sourceSets.create(IsmlExtension.ISML_MAIN_SOURCESET)
mainIsmlSourceSet.srcDir.set(layout.projectDirectory.dir(IsmlExtension.MAIN_TEMPLATE_PATH))
mainIsmlSourceSet.srcDir.set(
layout.projectDirectory.dir(IsmlExtension.MAIN_TEMPLATE_PATH + "/" + project.name))
mainIsmlSourceSet.ismlOutputDir.set(layout.buildDirectory.dir(
"${IsmlExtension.ISML_OUTPUTPATH}/${IsmlExtension.ISML_MAIN_SOURCESET}"
))
Expand Down Expand Up @@ -108,20 +112,12 @@ open class IsmlPlugin : Plugin<Project> {
jsptask.targetCompatibility.set(extension.targetCompatibility)
jsptask.encoding.set(extension.encoding)

jsptask.enableTldScan.set(extension.enableTldScan)
jsptask.encoding.set(extension.encoding)

jsptask.sourceCompatibility.set(extension.sourceCompatibility)
jsptask.targetCompatibility.set(extension.targetCompatibility)

jsptask.sourceSetName.set(extension.sourceSetName)


project.plugins.withType(IsmlTagLibPlugin::class.java) {
val ismlTagLib = tasks.named(IsmlTagLibPlugin.TASKNAME, PrepareTagLibs::class.java)
jsptask.tagLibsInputDir.set(project.provider { ismlTagLib.get().outputDir.get() })
jsptask.dependsOn(ismlTagLib)
}
jsptask.dependsOn(ismlTask)
}

Expand All @@ -131,6 +127,11 @@ open class IsmlPlugin : Plugin<Project> {
it.name == SourceSet.MAIN_SOURCE_SET_NAME
}.forEach {
it.java.srcDir(jspTask)

val ismlListTask = createISMLResourceTask(project).get()
it.java.srcDir(ismlTask.get().outputDir.get())
it.output.dir(ismlListTask.outputs)
ismlListTask.dependsOn(ismlTask)
}
}
}
Expand Down Expand Up @@ -177,4 +178,19 @@ open class IsmlPlugin : Plugin<Project> {
configuration.dependencies.add( dependencyHandler.create("org.apache.tomcat:tomcat-jasper") )
configuration.dependencies.add( dependencyHandler.create("org.slf4j:slf4j-api") )
}

private fun createISMLResourceTask(project: Project): TaskProvider<ResourceListFileTask> {
return project.tasks.register("resourceListISML", ResourceListFileTask::class.java) { task ->
task.description = "Creates a resource file with a list of ISML templates"
task.group = IsmlExtension.ISML_GROUP_NAME
task.fileExtension = "jsp"
task.resourceListFileName =
String.format(Locale.getDefault() ,"resources/%s/isml/isml.resource", project.name)
task.sourceSetName = "main"
task.include("**/**/*.jsp")
task.outputDir.set(
project.layout.buildDirectory.dir(
"${ResourceListExtension.RESOURCELIST_OUTPUTPATH}/isml").get())
}
}
}
55 changes: 0 additions & 55 deletions src/main/kotlin/com/intershop/gradle/isml/IsmlTagLibPlugin.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ open class IsmlExtension @Inject constructor(objectFactory: ObjectFactory, proje
/**
* Default path of ISML files.
*/
const val MAIN_TEMPLATE_PATH = "staticfiles/cartridge/templates"
const val MAIN_TEMPLATE_PATH = "src/main/isml"

/**
* Default target path of ISML compilation.
Expand Down
59 changes: 2 additions & 57 deletions src/main/kotlin/com/intershop/gradle/isml/tasks/Jsp2Java.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,6 @@ open class Jsp2Java @Inject constructor(
@get:Input
val encoding: Property<String> = objectFactory.property(String::class.java)

/**
* Input directory for TagLibs.
*
* @property tagLibsInputDir
*/
@get:Optional
@get:InputDirectory
val tagLibsInputDir: DirectoryProperty = objectFactory.directoryProperty()

/**
* Input directory for ISML files.
*
Expand Down Expand Up @@ -152,40 +143,6 @@ open class Jsp2Java @Inject constructor(
returnFiles
}

/**
* List of filenames, that should be excluded from the JspC file scan.
* The file name is check for the beginning of the name.
*
* @property tldScanExcludes
*/
@get:Input
val tldScanExcludes: ListProperty<String> = objectFactory.listProperty(String::class.java)

/**
* List of filenames, that should be included in the JspC file scan.
* The file name is check for the beginning of the name.
*
* The default value will be generated from the classpath if exclude list is empty.
*
* @property tldScanIncludes
*/
@get:Input
val tldScanIncludes: ListProperty<String> = objectFactory.listProperty(String::class.java)

/**
* This will enable the TLD file scan of Jsp Compiler. It is only necessary if
* TLDs are used and available.
* Default value is false.
*
* @property enableTldScan
*/
@get:Input
val enableTldScan: Property<Boolean> = objectFactory.property(Boolean::class.java)

init {
enableTldScan.convention(false)
}

/**
* This is the task action and processes ISML files.
*/
Expand All @@ -197,17 +154,8 @@ open class Jsp2Java @Inject constructor(

prepareFolder(outputFolder.parentFile)

if(tagLibsInputDir.isPresent) {
// copy taglib conf files with web-inf to the uriroot
fileSystemOperations.copy {
it.from(tagLibsInputDir)
it.into(outputFolder)
}
} else {
// create web-inf in uriroot
webinf.parentFile.mkdirs()
webinf.writeText(IsmlExtension.WEB_XML_CONTENT)
}
webinf.parentFile.mkdirs()
webinf.writeText(IsmlExtension.WEB_XML_CONTENT)

val classpathCollection = project.files(outputFolder, classpathfiles)

Expand All @@ -232,9 +180,6 @@ open class Jsp2Java @Inject constructor(
it.sourceCompatibility.set(sourceCompatibility)
it.targetCompatibility.set(targetCompatibility)

it.tldScanIncludes.set(tldScanIncludes)
it.tldScanExcludes.set(tldScanExcludes)
it.enableTldScan.set(enableTldScan)
it.logLevel.set(runLoggerLevel)
it.classpath.set(classpathCollection.asPath)
}
Expand Down
15 changes: 4 additions & 11 deletions src/main/kotlin/com/intershop/gradle/isml/tasks/Jsp2JavaRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.intershop.gradle.isml.tasks

import org.apache.jasper.JspC
import org.gradle.workers.WorkAction
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -43,29 +44,21 @@ abstract class Jsp2JavaRunner : WorkAction<Jsp2JavaRunnerParameters> {

override fun execute() {
val fileList = mutableListOf<String>()
// disable scanning of jar files during jsp to java
System.setProperty( org.apache.tomcat.util.scan.Constants.SKIP_JARS_PROPERTY, "*.jar");

if (parameters.enableTldScan.get() == true &&
parameters.tldScanIncludes.get().size >= 0 &&
parameters.tldScanExcludes.get().size == 0 &&
parameters.classpath.get().isNotEmpty()) {
if (parameters.classpath.get().isNotEmpty()) {
val cpList = parameters.classpath.get().split(":")
cpList.forEach {
if (!it.endsWith(File.pathSeparator)) {
fileList.add(File(it).name)
log.debug("Add file name {} to list", File(it).name)
}
}

fileList.addAll(parameters.tldScanIncludes.get())
}

// run JSP compiler
val jspc = JspC()
jspc.setLogging(parameters.logLevel.get())

jspc.enableTldScan = parameters.enableTldScan.get()
jspc.tldScanIncludes = fileList
jspc.tldScanExcludes = parameters.tldScanExcludes.get()

jspc.classPath = parameters.classpath.get()
jspc.setUriroot(parameters.inputDir.get().asFile.absolutePath)
Expand Down
Loading

0 comments on commit 826f85f

Please sign in to comment.