@@ -19,6 +19,20 @@ import org.apache.tools.ant.taskdefs.condition.Os
1919
2020description = ' Ballerina - Regex Ballerina Generator'
2121
22+ def packageName = " regex"
23+ def packageOrg = " ballerina"
24+ def snapshotVersion = " -SNAPSHOT"
25+ def tomlVersion = project. version. replace(" ${ snapshotVersion} " , " " )
26+ def ballerinaConfigFile = new File (" $project . projectDir /Ballerina.toml" )
27+ def artifactBallerinaDocs = file(" $project . projectDir /build/docs_parent/" )
28+ def artifactCacheParent = file(" $project . projectDir /build/cache_parent/" )
29+ def artifactLibParent = file(" $project . projectDir /build/lib_parent/" )
30+ def artifactCodeCoverageReport = file(" $project . projectDir /target/cache/tests_cache/coverage/ballerina.exec" )
31+ def artifactTestableJar = file(" $project . projectDir /target/cache/${ packageOrg} /${ packageName} /${ tomlVersion} /java11/" )
32+ def ballerinaCentralAccessToken = System . getenv(' BALLERINA_CENTRAL_ACCESS_TOKEN' )
33+ def originalConfig = ballerinaConfigFile. text
34+ def distributionBinPath = project. projectDir. absolutePath + " /build/target/extracted-distributions/jballerina-tools-zip/jballerina-tools-${ ballerinaLangVersion} /bin"
35+
2236configurations {
2337 jbalTools
2438}
@@ -47,18 +61,6 @@ task unpackJballerinaTools(type: Copy) {
4761 }
4862}
4963
50- def packageName = " regex"
51- def packageOrg = " ballerina"
52- def ballerinaConfigFile = new File (" $project . projectDir /Ballerina.toml" )
53- def artifactBallerinaDocs = file(" $project . projectDir /build/docs_parent/" )
54- def artifactCacheParent = file(" $project . projectDir /build/cache_parent/" )
55- def artifactLibParent = file(" $project . projectDir /build/lib_parent/" )
56- def artifactCodeCoverageReport = file(" $project . projectDir /target/cache/tests_cache/coverage/ballerina.exec" )
57- def tomlVersion = project. version. split(" -" )[0 ]
58- def ballerinaCentralAccessToken = System . getenv(' BALLERINA_CENTRAL_ACCESS_TOKEN' )
59- def originalConfig = ballerinaConfigFile. text
60- def distributionBinPath = project. projectDir. absolutePath + " /build/target/extracted-distributions/jballerina-tools-zip/jballerina-tools-${ ballerinaLangVersion} /bin"
61-
6264task updateTomlVersions {
6365 doLast {
6466 def newConfig = ballerinaConfigFile. text. replace(" @project.version@" , project. version)
@@ -75,6 +77,7 @@ task revertTomlFile {
7577
7678def debugParams = " "
7779def balJavaDebugParam = " "
80+ def testParams = " "
7881
7982task initializeVariables {
8083 if (project. hasProperty(" debug" )) {
@@ -83,6 +86,24 @@ task initializeVariables {
8386 if (project. hasProperty(" balJavaDebug" )) {
8487 balJavaDebugParam = " BAL_JAVA_DEBUG=${ project.findProperty("balJavaDebug")} "
8588 }
89+
90+ gradle. taskGraph. whenReady { graph ->
91+ if (graph. hasTask(" :${ packageName} -ballerina:build" ) || graph. hasTask(" :${ packageName} -ballerina:publish" )) {
92+ ballerinaTest. enabled = false
93+ }
94+
95+ if (graph. hasTask(" :${ packageName} -ballerina:test" )) {
96+ testParams = " --code-coverage --includes=*"
97+ } else {
98+ testParams = " --skip-tests"
99+ }
100+
101+ if (graph. hasTask(" :${ packageName} -ballerina:publish" )) {
102+ ballerinaPublish. enabled = true
103+ } else {
104+ ballerinaPublish. enabled = false
105+ }
106+ }
86107}
87108
88109task ballerinaTest {
@@ -114,16 +135,6 @@ task ballerinaBuild {
114135 dependsOn(initializeVariables)
115136 finalizedBy(revertTomlFile)
116137
117- def testParams = " --skip-tests"
118- gradle. taskGraph. whenReady { graph ->
119- if (graph. hasTask(' :regex-ballerina:build' ) || graph. hasTask(' :regex-ballerina:publish' )) {
120- ballerinaTest. enabled = false
121- }
122- if (graph. hasTask(' :regex-ballerina:test' )) {
123- testParams = " --code-coverage --includes=*"
124- }
125- }
126-
127138 doLast {
128139 // Build and populate caches
129140 exec {
@@ -146,20 +157,6 @@ task ballerinaBuild {
146157 into file(" $artifactCacheParent /cache/" )
147158 }
148159
149- // Publish to central
150- if (! project. version. endsWith(' -SNAPSHOT' ) && ballerinaCentralAccessToken != null && project. hasProperty(" publishToCentral" )) {
151- println (" Publishing to the ballerina central.." )
152- exec {
153- workingDir project. projectDir
154- environment " JAVA_OPTS" , " -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true"
155- if (Os . isFamily(Os . FAMILY_WINDOWS )) {
156- commandLine ' cmd' , ' /c' , " $distributionBinPath /bal.bat push && exit %%ERRORLEVEL%%"
157- } else {
158- commandLine ' sh' , ' -c' , " $distributionBinPath /bal push"
159- }
160- }
161-
162- }
163160 // Doc creation and packing
164161 exec {
165162 workingDir project. projectDir
@@ -181,6 +178,23 @@ task ballerinaBuild {
181178 outputs. dir artifactLibParent
182179}
183180
181+ task ballerinaPublish {
182+ doLast {
183+ if (ballerinaCentralAccessToken != null ) {
184+ println (" Publishing to the ballerina central..." )
185+ exec {
186+ workingDir project. projectDir
187+ environment " JAVA_OPTS" , " -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true"
188+ if (Os . isFamily(Os . FAMILY_WINDOWS )) {
189+ commandLine ' cmd' , ' /c' , " $distributionBinPath /bal.bat push ${ packageName} && exit %%ERRORLEVEL%%"
190+ } else {
191+ commandLine ' sh' , ' -c' , " $distributionBinPath /bal push ${ packageName} "
192+ }
193+ }
194+ }
195+ }
196+ }
197+
184198task createArtifactZip (type : Zip ) {
185199 destinationDirectory = file(" $buildDir /distributions" )
186200 from ballerinaBuild
@@ -201,7 +215,7 @@ publishing {
201215 repositories {
202216 maven {
203217 name = " GitHubPackages"
204- url = uri(" https://maven.pkg.github.com/ballerina-platform/module-ballerina-regex " )
218+ url = uri(" https://maven.pkg.github.com/ballerina-platform/module-${ packageOrg } - ${ packageName } " )
205219 credentials {
206220 username = System . getenv(" packageUser" )
207221 password = System . getenv(" packagePAT" )
@@ -212,3 +226,6 @@ publishing {
212226
213227updateTomlVersions. dependsOn unpackJballerinaTools
214228build. dependsOn ballerinaBuild
229+
230+ ballerinaPublish. dependsOn ballerinaBuild
231+ publish. dependsOn ballerinaPublish
0 commit comments