Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Versions #30

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CCv2 Template Repository

- Best-practice setup
- Based on SAP Commerce 2011
- Based on SAP Commerce 2211
- Generates B2C accelerator modules, OCC extension and OCC tests extension
- Includes Spartacus storefront
- Fully automated setup for local development
Expand Down
2 changes: 1 addition & 1 deletion core-customize/.java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11.0
17.0
1 change: 1 addition & 0 deletions core-customize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
> -PprojectName=<name, e.g. coolshop> \
> -ProotPackage=<package, e.g. com.cool.shop> \
> -PintExtPackVersion=2102.1 # (optional) enable "SAP Commerce Cloud, Integration Extension Pack"
> -PsolrVersion=9.2 # (optional) set the solr version for the manifest - o
> ```
>
> Read the output!
Expand Down
12 changes: 7 additions & 5 deletions core-customize/bootstrap-demo.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
plugins {
id("sap.commerce.build") version("3.6.0")
id("sap.commerce.build.ccv2") version("3.6.0")
id("de.undercouch.download") version("4.1.2")
id("sap.commerce.build") version("4.0.0")
id("sap.commerce.build.ccv2") version("4.0.0")
id("de.undercouch.download") version("5.5.0")
}

buildscript {
repositories {
mavenCentral()
Expand All @@ -12,6 +13,7 @@ buildscript {
classpath("io.github.java-diff-utils:java-diff-utils:4.10")
}
}

import mpern.sap.commerce.build.tasks.HybrisAntTask
import com.github.difflib.UnifiedDiffUtils
import com.github.difflib.DiffUtils
Expand Down Expand Up @@ -42,15 +44,15 @@ tasks.register("fixcmsflexcomponent") {
}
}
tasks.register<de.undercouch.gradle.tasks.download.Download>("downloadSpartacusSampleData") {
src("https://github.com/SAP/spartacus/releases/download/storefront-3.4.1/spartacussampledata.2011.zip")
src("https://github.com/SAP-samples/cloud-commerce-sample-setup/releases/download/sampledata/spartacussampledata-version-2211-x.zip")
dest("dependencies")
onlyIfModified(true)
useETag(true)
}

tasks.register<Copy>("unpackSpartacus") {
dependsOn("downloadSpartacusSampleData", "bootstrapDefaultProject")
from(zipTree("dependencies/spartacussampledata.2011.zip"))
from(zipTree("dependencies/spartacussampledata.2211.zip"))
into("hybris/bin/custom/spartacussampledata")
// eachFile {
// val newPath = relativePath.segments.drop(1).toMutableList()
Expand Down
2 changes: 1 addition & 1 deletion core-customize/bootstrap-extras.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
}
}
dependencies {
classpath("de.undercouch:gradle-download-task:4.1.2")
classpath("de.undercouch:gradle-download-task:5.5.0")
}
}

Expand Down
143 changes: 85 additions & 58 deletions core-customize/bootstrap.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("sap.commerce.build") version("3.5.0")
id("sap.commerce.build.ccv2") version("3.5.0")
id("sap.commerce.build") version("4.0.0")
id("sap.commerce.build.ccv2") version("4.0.0")
}

buildscript {
Expand All @@ -19,15 +19,15 @@ repositories {
mavenCentral()
}


fun inputName(): String {
if (!(project.hasProperty("projectName") && project.hasProperty("rootPackage"))) {
logger.error("Please provide the projectName and rootPacakge")
logger.error("e.g. ./gradlew -b bootstrap.gradle.kts -PprojectName=coolshop -ProotPackage=com.shop.cool")
throw InvalidUserDataException("Please provide projectName / rootPackage!")
}
}
return (project.property("projectName") as String)
}

fun inputPackage(): String {
if (!(project.hasProperty("projectName") && project.hasProperty("rootPackage"))) {
logger.error("Please provide the projectName and rootPacakge")
Expand All @@ -38,13 +38,15 @@ fun inputPackage(): String {
}

apply(from = "bootstrap-extras.gradle.kts")

tasks.named("createDefaultConfig") {
dependsOn("bootstrapExtras")
}


//** generate code
// ant modulegen -Dinput.module=accelerator -Dinput.name=demoshop -Dinput.package=com.demo.shop
tasks.register<HybrisAntTask>("generateNewStorefront") {
tasks.register<HybrisAntTask>("generateAcceleratorModule") {
dependsOn("bootstrapPlatform", "createDefaultConfig")

args("modulegen")
Expand All @@ -53,11 +55,20 @@ tasks.register<HybrisAntTask>("generateNewStorefront") {
antProperty("input.package", inputPackage())
}

tasks.register<Copy>("copyConfigImpex") {
mustRunAfter("generateNewStorefront")
from("bootstrap/")
include("*.impex")
into("hybris/bin/custom/${inputName()}/${inputName()}storefront/resources/impex/")
val accStorefrontEnabled = project.hasProperty("accStorefrontEnabled") && (project.property("accStorefrontEnabled") == "true")

if (accStorefrontEnabled) {
tasks.register<Copy>("copyConfigImpex") {
dependsOn("generateAcceleratorModule", "copyJsonnet")
from("bootstrap/")
include("*.impex")
into("hybris/bin/custom/${inputName()}/${inputName()}storefront/resources/impex/")
}
} else {
tasks.register<Delete>("deleteAcceleratorStorefrontExtension") {
dependsOn("generateAcceleratorModule")
delete("hybris/bin/custom/${inputName()}/${inputName()}storefront/")
}
}

tasks.register<HybrisAntTask>("generateOcc") {
Expand All @@ -79,65 +90,69 @@ tasks.register<HybrisAntTask>("generateOccTests") {
}

tasks.register("generateCode") {
dependsOn("generateNewStorefront", "copyConfigImpex", "generateOcc", "generateOccTests")
dependsOn("generateOcc", "generateOccTests")
doLast {
ant.withGroovyBuilder {
ant.withGroovyBuilder {
"move"("file" to "hybris/bin/custom/${inputName()}occ", "todir" to "hybris/bin/custom/${inputName()}")
"move"("file" to "hybris/bin/custom/${inputName()}occtests", "todir" to "hybris/bin/custom/${inputName()}")
}
}
}

if (accStorefrontEnabled) {
tasks.named("generateCode") {
dependsOn("copyConfigImpex")
}
} else {
tasks.named("generateCode") {
dependsOn("deleteAcceleratorStorefrontExtension")
}
}

//** setup hybris/config folder
tasks.register<Copy>("mergeConfigFolder") {
mustRunAfter("generateCode")
dependsOn("generateCode")
mustRunAfter("copyJsonnet")
from("bootstrap/config-template")
into("hybris/config")
filter(org.apache.tools.ant.filters.ReplaceTokens::class, "tokens" to mapOf("projectName" to inputName()))
}
tasks.register<Copy>("filterJsonnet") {
from("bootstrap/manifest.jsonnet")
into("bootstrap")
rename(".*", "manifest.jsonnet.filtered")
filter(org.apache.tools.ant.filters.ReplaceTokens::class, "tokens" to mapOf("projectName" to inputName()))
}
tasks.register("moveJsonnet") {
dependsOn("filterJsonnet")
doLast {
ant.withGroovyBuilder {
"move"("file" to "bootstrap/manifest.jsonnet.filtered", "tofile" to file("manifest.jsonnet"))
}
if (!accStorefrontEnabled) {
filter { line -> line.replace(Regex("^.*${inputName()}storefront.*$"), "") }
}
}
tasks.register("enableIntExtPack") {
mustRunAfter("moveJsonnet")
onlyIf {
project.hasProperty("intExtPackVersion")
}
doLast {
ant.withGroovyBuilder {
"replace"(
"file" to "manifest.jsonnet",
"token" to "intExtPackVersion=null",
"value" to "intExtPackVersion='${project.property("intExtPackVersion")}'"
)
}
}

tasks.register<Copy>("copyJsonnet") {
from("bootstrap/manifest.jsonnet")
into(".")
}

fun generateManifest() {
val intExtJsonnetParams = if (project.hasProperty("intExtPackVersion")) {
arrayOf("--ext-str", "intExtPackVersion='${project.property("intExtPackVersion")}'")
} else arrayOf()

val accStorefrontParams = if (accStorefrontEnabled) {
arrayOf("--ext-str", "storefrontExtension=${inputName()}storefront", "--ext-code", "accStorefrontEnabled=true")
} else arrayOf()

val solrVersionParams = if (project.hasProperty("solrVersion")) {
arrayOf("--ext-str", "solrVersion='${project.property("solrVersion")}'")
} else arrayOf()

sjsonnet.SjsonnetMain.main0(
arrayOf("--output-file", "manifest.json", "manifest.jsonnet"),
accStorefrontParams + intExtJsonnetParams + solrVersionParams + arrayOf("--output-file", "manifest.json", "manifest.jsonnet"),
sjsonnet.SjsonnetMain.createParseCache(),
java.lang.System.`in`,
java.lang.System.`out`,
java.lang.System.err,
os.Path(project.rootDir.toPath()),
scala.`None$`.empty(),
scala.`None$`.empty()
)
)
}

tasks.register("generateManifest") {
dependsOn("moveJsonnet", "enableIntExtPack")
dependsOn("copyJsonnet")
doLast {
generateManifest()
}
Expand All @@ -150,16 +165,16 @@ val localDev = mapOf(
)
val localConfig = file("hybris/config/local-config")
val symlink = tasks.register("symlinkConfig")
localDev.forEach{
localDev.forEach {
val singleLink = tasks.register<Exec>("symlink${it.key}") {
dependsOn("mergeConfigFolder")
val path = it.value.relativeTo(localConfig)
if (Os.isFamily(Os.FAMILY_UNIX)) {
commandLine("sh", "-c", "ln -sfn ${path} ${it.key}")
commandLine("sh", "-c", "ln -sfn $path ${it.key}")
} else {
// https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
val windowsPath = path.toString().replace("[/]".toRegex(), "\\")
commandLine("cmd", "/c", """mklink /d "${it.key}" "${windowsPath}" """)
commandLine("cmd", "/c", """mklink /d "${it.key}" "$windowsPath" """)
}
workingDir(localConfig)
}
Expand All @@ -171,7 +186,7 @@ localDev.forEach{
tasks.register<WriteProperties>("generateLocalProperties") {
mustRunAfter("mergeConfigFolder")
comment = "GENEREATED AT " + java.time.Instant.now()
outputFile = project.file("hybris/config/local.properties")
destinationFile = project.file("hybris/config/local.properties")

property("hybris.optional.config.dir", project.file("hybris/config/local-config"))
}
Expand All @@ -182,7 +197,7 @@ tasks.register("setupConfigFolder") {

tasks.register<GradleBuild>("setupLocalDev") {
mustRunAfter("generateCode", "setupConfigFolder")
buildFile = file("build.gradle.kts")
dir = rootDir
tasks = listOf("setupLocalDevelopment")
}

Expand All @@ -195,14 +210,20 @@ tasks.register("bootstrapNewProject") {
println("")
println("==== Project generation finished! ====")
println("- Generated extensions:")
file("hybris/bin/custom/${inputName()}").listFiles().sortedBy{ it.name }.forEach {
file("hybris/bin/custom/${inputName()}").listFiles().sortedBy { it.name }.forEach {
println("\t${it.name}")
}
if (project.hasProperty("intExtPackVersion")) {
println("- Configured Integration Extension Pack ${project.property("intExtPackVersion")}")
}
println("- Generated new manifest.json (using manifest.jsonnet)")
println("")
if (!accStorefrontEnabled) {
println("! Deprecated accelerator storefront has not been included in the generated code.")
println("! If you want to use the JSP based deprecated accelerator storefront,")
println("! provide the flag -DaccStorefrontEnabled=true to the bootstrap command.")
println("")
}
println("? (optional)")
println("? If you plan to customize the Solr configuration of your project, please execute:")
println("? ./gradlew -b bootstrap.gradle.kts enableSolrCustomization")
Expand All @@ -217,16 +238,20 @@ tasks.register("enableSolrCustomization") {
group = "Bootstrap"
description = "Prepare Solr configuration for both local development and customization"
}

tasks.register<HybrisAntTask>("startSolr") {
args("startSolrServers")
}

tasks.register<HybrisAntTask>("stopSolr") {
args("stopSolrServers")
mustRunAfter("startSolr")
}

tasks.register("startStopSolr") {
dependsOn("startSolr", "stopSolr")
}

tasks.register("moveSolrConfig") {
dependsOn("startStopSolr")
doLast {
Expand All @@ -236,9 +261,10 @@ tasks.register("moveSolrConfig") {
}
}
}

tasks.register<Exec>("symlinkSolrConfig") {
dependsOn("moveSolrConfig")
if (Os.isFamily(Os.FAMILY_UNIX)) {
if (Os.isFamily(Os.FAMILY_UNIX)) {
commandLine("sh", "-c", "ln -sfn ../../../../../solr/server/solr/configsets configsets")
} else {
// https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
Expand All @@ -253,28 +279,29 @@ tasks.register("findSolrVersion") {
dependsOn("bootstrapPlatform")
doLast {
val solrDir = file("hybris/bin/modules/search-and-navigation/solrserver/resources/solr")
.listFiles()
.filter{ it.isDirectory() }
.sortedBy{ it.name }.last()
.listFiles()
.filter { it.isDirectory() }
.sortedBy { it.name }.last()
val props = java.util.Properties();
props.load(solrDir.resolve("server/meta.properties").inputStream())
extra.set("bundledSolrVersion", props.get("version"))
}
}

tasks.register("manifestWithSolr") {
mustRunAfter("symlinkSolrConfig")
dependsOn("findSolrVersion")
doLast {
println("Regenerating manifest.json...")
val solrVersion = tasks.named("findSolrVersion").get().extra.get("bundledSolrVersion") as String
val majorMinor = solrVersion.split(".").take(2).joinToString(".")
println("Detected Solr version ${solrVersion} bundled with the platform.")
println("Pinning Solr version to ${majorMinor} in manifest.json")
println("Detected Solr version $solrVersion bundled with the platform.")
println("Pinning Solr version to $majorMinor in manifest.json")
ant.withGroovyBuilder {
"replace"(
"file" to "manifest.jsonnet",
"token" to "solrVersion=null",
"value" to "solrVersion='${majorMinor}'"
"file" to "manifest.jsonnet",
"token" to "solrVersion=null",
"value" to "solrVersion='${majorMinor}'"
)
}
generateManifest()
Expand Down
Loading