Skip to content

Commit 1abd2c0

Browse files
committed
restructure build script and use local maven repo instead of dependencies folder
1 parent 365e755 commit 1abd2c0

4 files changed

Lines changed: 209 additions & 227 deletions

File tree

core-customize/build.gradle.kts

Lines changed: 6 additions & 227 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import org.apache.tools.ant.taskdefs.condition.Os
2-
3-
import de.undercouch.gradle.tasks.download.Download
4-
import de.undercouch.gradle.tasks.download.VerifyAction
5-
6-
import java.time.Instant
71
import java.util.Base64
82

93
plugins {
@@ -13,233 +7,18 @@ plugins {
137
`maven-publish`
148
}
159

16-
val solrVersionMap = mapOf(
17-
/*
18-
* version 8 unfortunately has a different download URL and is currently not working. But it is the version that is
19-
* supplied with the standard zip, so we're fine unless the solr version is changed and then changed back in
20-
* manifest.json
21-
*/
22-
"8.11" to "8.11.2",
23-
"9.2" to "9.2.1",
24-
"9.5" to "9.5.0"
25-
)
26-
27-
val dependencyDir = "../dependencies"
28-
val workingDir = project.projectDir
29-
val binDir = "${workingDir}/hybris/bin"
30-
3110
repositories {
32-
flatDir { dirs(dependencyDir) }
11+
mavenLocal()
3312
mavenCentral()
3413
}
3514

36-
val solrVersion = solrVersionMap[CCV2.manifest.solrVersion] ?: "9.2.1"
37-
val solrServer: Configuration by configurations.creating
38-
39-
dependencies {
40-
solrServer("org.apache.solr:solr:${solrVersion}")
41-
}
42-
43-
hybris {
44-
// what files should be deleted when cleaning up the platform?
45-
// (cloudhofolders will be downloaded by custom configuration)
46-
cleanGlob.set("glob:**hybris/bin/{modules**,platform**,cloudhotfolders**}")
47-
48-
// what should be unpacked from the platform zip files?
49-
bootstrapInclude.set(
50-
listOf(
51-
"hybris/**", //
52-
"azurecloudhotfolder/**", //
53-
"cloudcommons/**", //
54-
"cloudhotfolder/**" //
55-
)
56-
)
57-
58-
// what should excluded when unpacking?
59-
// the default value is a npm package folder that includes UTF-8 filenames, which lead to problems on linux
60-
bootstrapExclude.set(
61-
listOf(
62-
"hybris/bin/ext-content/npmancillary/resources/npm/node_modules/http-server/node_modules/ecstatic/test/**"
63-
)
64-
)
65-
66-
// Control the sparse platform bootstrap.
67-
// When enabled, the commerce extensions are extracted from the distribution zip on a as-needed basis.
68-
// Only extensions that are actually used in the project (either directly listed in the localextensions.xml or
69-
// required by other extensions) are extracted.
70-
// The platform itself is always extracted.
71-
// When this mode is enabled, the bootstrapInclude configuration property is ignored.
72-
sparseBootstrap {
73-
enabled = true
74-
alwaysIncluded = listOf<String>("solrserver")
75-
}
76-
}
77-
78-
tasks.register<Download>("fetchSolr") {
79-
src(uri("https://archive.apache.org/dist/solr/solr/${solrVersion}/solr-${solrVersion}.tgz"))
80-
dest("${dependencyDir}/solr-${solrVersion}.tgz")
81-
overwrite(false)
82-
}
83-
84-
val repackSolr = tasks.register<Zip>("repackSolr") {
85-
dependsOn("fetchSolr")
86-
from(tarTree("${dependencyDir}/solr-${solrVersion}.tgz"))
87-
archiveFileName = "solr-${solrVersion}.zip"
88-
destinationDirectory = file(dependencyDir)
89-
}
90-
91-
publishing {
92-
publications {
93-
create<MavenPublication>("solr") {
94-
groupId = "org.apache.solr"
95-
artifactId = "solr"
96-
version = solrVersion
97-
98-
artifact(repackSolr.get().archiveFile)
99-
}
100-
}
101-
}
102-
103-
tasks.named("yinstallSolr") {
104-
// this task is available because of the solr-publication above.
105-
dependsOn("publishSolrPublicationToMavenLocal")
106-
}
107-
108-
tasks.ybuild {
109-
dependsOn("publishSolrPublicationToMavenLocal")
110-
group = "build"
111-
}
112-
113-
if (project.hasProperty("CXDEV_ARTEFACT_BASEURL") && project.hasProperty("CXDEV_ARTEFACT_USER") && project.hasProperty("CXDEV_ARTEFACT_PASSWORD")) {
114-
val BASEURL = project.property("CXDEV_ARTEFACT_BASEURL") as String
115-
val USER = project.property("CXDEV_ARTEFACT_USER") as String
116-
val PASSWORD = project.property("CXDEV_ARTEFACT_PASSWORD") as String
117-
val AUTHORIZATION = Base64.getEncoder().encodeToString((USER + ":" + PASSWORD).toByteArray())
118-
119-
val COMMERCE_VERSION = CCV2.manifest.effectiveVersion
120-
tasks.register<Download>("downloadPlatform") {
121-
val targetFile = file("${dependencyDir}/hybris-commerce-suite-${COMMERCE_VERSION}.zip")
122-
123-
src("$BASEURL/commerce/hybris-commerce-suite-${COMMERCE_VERSION}.zip")
124-
dest(targetFile)
125-
126-
header("Authorization", "Basic $AUTHORIZATION")
127-
128-
overwrite(false)
129-
tempAndMove(true)
130-
onlyIfModified(true)
131-
useETag(true)
132-
133-
doFirst {
134-
logger.lifecycle("=== Download Platform Debug ===")
135-
logger.lifecycle("Source URL: $BASEURL/commerce/hybris-commerce-suite-${COMMERCE_VERSION}.zip")
136-
logger.lifecycle("Destination: ${targetFile.absolutePath}")
137-
logger.lifecycle("Destination exists: ${targetFile.exists()}")
138-
logger.lifecycle("Dependency dir: ${file(dependencyDir).absolutePath}")
139-
140-
if (file(dependencyDir).exists()) {
141-
logger.lifecycle("Directory content:")
142-
file(dependencyDir).listFiles()?.forEach {
143-
logger.lifecycle(" - ${it.name}")
144-
}
145-
}
146-
}
147-
148-
doLast {
149-
logger.lifecycle("=== Download completed ===")
150-
logger.lifecycle("File exists after download: ${targetFile.exists()}")
151-
logger.lifecycle("File size: ${targetFile.length()}")
152-
153-
logger.lifecycle("Dependency dir: ${file(dependencyDir).absolutePath}")
154-
155-
if (file(dependencyDir).exists()) {
156-
logger.lifecycle("Directory content:")
157-
file(dependencyDir).listFiles()?.forEach {
158-
logger.lifecycle(" - ${it.name}")
159-
}
160-
}
161-
}
162-
}
163-
164-
tasks.named("bootstrapPlatform") {
165-
dependsOn("downloadPlatform")
166-
}
167-
168-
//check if Integration Extension Pack is configured and download it too
169-
if (CCV2.manifest.extensionPacks.any{"hybris-commerce-integrations".equals(it.name)}) {
170-
val INTEXTPACK_VERSION = CCV2.manifest.extensionPacks.first{"hybris-commerce-integrations".equals(it.name)}.version
171-
tasks.register<Download>("downloadIntExtPack") {
172-
src(BASEURL + "/integration/hybris-commerce-integrations-${INTEXTPACK_VERSION}.zip")
173-
dest(file("${dependencyDir}/hybris-commerce-integrations-${INTEXTPACK_VERSION}.zip"))
174-
header("Authorization", "Basic ${AUTHORIZATION}")
175-
overwrite(false)
176-
tempAndMove(true)
177-
onlyIfModified(true)
178-
useETag(true)
179-
}
180-
181-
tasks.named("bootstrapPlatform") {
182-
dependsOn("downloadIntExtPack")
183-
}
184-
}
185-
}
186-
187-
tasks.register<WriteProperties>("generateLocalProperties") {
188-
comment = "GENERATED AT " + Instant.now()
189-
destinationFile = project.file("hybris/config/local.properties")
190-
property("hybris.optional.config.dir", project.file("hybris/config/local-config").absolutePath)
191-
doLast {
192-
mkdir(project.file("hybris/config/local-config/"))
193-
}
194-
}
195-
196-
val symlinkConfigTask: TaskProvider<Task> = tasks.register("symlinkConfig")
197-
val localConfig = file("hybris/config/local-config")
198-
mapOf(
199-
"10-local.properties" to file("hybris/config/cloud/common.properties"),
200-
"20-local.properties" to file("hybris/config/cloud/persona/development.properties"),
201-
"50-local.properties" to file("hybris/config/cloud/local-dev.properties")
202-
).forEach{
203-
val symlinkTask = tasks.register<Exec>("symlink${it.key}") {
204-
val path = it.value.relativeTo(localConfig)
205-
if (Os.isFamily(Os.FAMILY_UNIX)) {
206-
commandLine("sh", "-c", "ln -sfn $path ${it.key}")
207-
} else {
208-
// https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
209-
val windowsPath = path.toString().replace("[/]".toRegex(), "\\")
210-
commandLine("cmd", "/c", """mklink "${it.key}" "$windowsPath" """)
211-
}
212-
workingDir(localConfig)
213-
dependsOn("generateLocalProperties")
214-
}
215-
symlinkConfigTask.configure {
216-
dependsOn(symlinkTask)
217-
}
218-
}
219-
220-
tasks.register<WriteProperties>("generateLocalDeveloperProperties") {
221-
dependsOn(symlinkConfigTask)
222-
comment = "my.properties - add your own local development configuration parameters here"
223-
destinationFile = project.file("hybris/config/local-config/99-local.properties")
224-
onlyIf {
225-
!project.file("hybris/config/local-config/99-local.properties").exists()
226-
}
227-
}
228-
229-
// https://help.sap.com/viewer/b2f400d4c0414461a4bb7e115dccd779/LATEST/en-US/784f9480cf064d3b81af9cad5739fecc.html
230-
tasks.register<Copy>("enableModeltMock") {
231-
from("hybris/bin/custom/extras/modelt/extensioninfo.disabled")
232-
into("hybris/bin/custom/extras/modelt/")
233-
rename { "extensioninfo.xml" }
234-
}
235-
236-
tasks.named("installManifestAddons") {
237-
mustRunAfter("generateLocalProperties")
238-
}
15+
apply(from = "gradle/commerce-artifacts.gradle.kts")
16+
apply(from = "gradle/solr.gradle.kts")
17+
apply(from = "gradle/localdev.gradle.kts")
23918

24019
tasks.register("setupLocalDevelopment") {
241-
group = "SAP Commerce"
242-
description = "Setup local development"
20+
group = "SAP Commerce Cloud"
21+
24322
dependsOn(
24423
"bootstrapPlatform",
24524
"yinstallSolr",
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import de.undercouch.gradle.tasks.download.Download
2+
import java.util.Base64
3+
4+
val artifactsDir = layout.buildDirectory.dir("artifacts")
5+
val commerceVersion = CCV2.manifest.effectiveVersion
6+
val artefactBaseUrl = findProperty("CXDEV_ARTEFACT_BASEURL") as String?
7+
val artefactUser = findProperty("CXDEV_ARTEFACT_USER") as String?
8+
val artefactPassword = findProperty("CXDEV_ARTEFACT_PASSWORD") as String?
9+
val artefactAuth = if (artefactUser != null && artefactPassword != null) {
10+
"Basic " + Base64.getEncoder().encodeToString("$artefactUser:$artefactPassword".toByteArray())
11+
} else null
12+
13+
fun registerDownloadTask(
14+
name: String,
15+
url: String,
16+
fileName: String
17+
) = tasks.register<Download>(name) {
18+
val targetFile = artifactsDir.get().file(fileName).asFile
19+
20+
src(url)
21+
dest(targetFile)
22+
23+
if (artefactAuth != null) {
24+
header("Authorization", artefactAuth)
25+
}
26+
27+
overwrite(false)
28+
tempAndMove(true)
29+
onlyIfModified(true)
30+
useETag(true)
31+
32+
doFirst {
33+
logger.lifecycle("=== Download $fileName ===")
34+
logger.lifecycle("Source: $url")
35+
logger.lifecycle("Target: ${targetFile.absolutePath}")
36+
}
37+
38+
doLast {
39+
logger.lifecycle("Download completed")
40+
logger.lifecycle("File exists: ${targetFile.exists()}")
41+
logger.lifecycle("Size: ${targetFile.length()}")
42+
43+
if (artifactsDir.exists()) {
44+
logger.lifecycle("Directory content:")
45+
artifactsDir.listFiles()?.forEach {
46+
logger.lifecycle(" - ${it.name}")
47+
}
48+
}
49+
}
50+
}
51+
52+
val downloadPlatform = artefactBaseUrl?.let {
53+
registerDownloadTask(
54+
"downloadPlatform",
55+
"$it/commerce/hybris-commerce-suite-$commerceVersion.zip",
56+
"hybris-commerce-suite-$commerceVersion.zip"
57+
)
58+
}
59+
60+
val integrationPackVersion = CCV2.manifest.extensionPacks.firstOrNull{ it.name == "hybris-commerce-integrations" }?.version
61+
val downloadIntegrationPack =
62+
if (artefactBaseUrl != null && integrationPackVersion != null) {
63+
registerDownloadTask(
64+
"downloadIntegrationPack",
65+
"$artefactBaseUrl/integration/hybris-commerce-integrations-$integrationPackVersion.zip",
66+
"hybris-commerce-integrations-$integrationPackVersion.zip"
67+
)
68+
} else null
69+
70+
publishing {
71+
publications {
72+
create<MavenPublication>("commerceSuite") {
73+
groupId = "de.hybris.platform"
74+
artifactId = "hybris-commerce-suite"
75+
version = commerceVersion
76+
artifact(artifactsDir.map {
77+
it.file("hybris-commerce-suite-$commerceVersion.zip")
78+
}) {
79+
extension = "zip"
80+
}
81+
}
82+
83+
if (integrationPackVersion != null) {
84+
create<MavenPublication>("commerceIntegrationPack") {
85+
groupId = "de.hybris.platform"
86+
artifactId = "hybris-commerce-integrations"
87+
version = integrationPackVersion
88+
artifact(artifactsDir.map {
89+
it.file("hybris-commerce-integrations-$integrationPackVersion.zip")
90+
}) {
91+
extension = "zip"
92+
}
93+
}
94+
}
95+
}
96+
}
97+
98+
val prepareCommerceArtifacts = tasks.register("prepareCommerceArtifacts") {
99+
group = "SAP Commerce"
100+
description = "Download and publish Commerce artifacts locally"
101+
102+
downloadPlatform?.let { dependsOn(it) }
103+
downloadIntegrationPack?.let { dependsOn(it) }
104+
105+
dependsOn("publishToMavenLocal")
106+
}
107+
108+
tasks.named("bootstrapPlatform") {
109+
dependsOn(prepareCommerceArtifacts)
110+
}

0 commit comments

Comments
 (0)