|
| 1 | +apply from: "$rootDir/gradle/java.gradle" |
| 2 | + |
| 3 | +// Configuration for downloading CICS SDK from IBM |
| 4 | +ext { |
| 5 | + cicsVersion = '9.1' |
| 6 | + cicsSdkName = 'CICS_TG_SDK_91_Unix' |
| 7 | +} |
| 8 | + |
| 9 | +repositories { |
| 10 | + ivy { |
| 11 | + url = 'https://public.dhe.ibm.com/software/htp/cics/support/supportpacs/individual/' |
| 12 | + patternLayout { |
| 13 | + artifact '[module].[ext]' |
| 14 | + } |
| 15 | + metadataSources { |
| 16 | + it.artifact() |
| 17 | + } |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +configurations { |
| 22 | + register('cicsSdk') { |
| 23 | + canBeResolved = true |
| 24 | + canBeConsumed = false |
| 25 | + } |
| 26 | + register('cicsJars') { |
| 27 | + canBeResolved = true |
| 28 | + canBeConsumed = false |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +// Task to extract the CICS SDK and get the required JARs |
| 33 | +abstract class ExtractCicsJars extends DefaultTask { |
| 34 | + @InputFiles |
| 35 | + final ConfigurableFileCollection sdkArchive = project.objects.fileCollection() |
| 36 | + |
| 37 | + @OutputDirectory |
| 38 | + final DirectoryProperty outputDir = project.objects.directoryProperty() |
| 39 | + |
| 40 | + ExtractCicsJars() { |
| 41 | + outputDir.convention(project.layout.buildDirectory.dir('cics-jars')) |
| 42 | + } |
| 43 | + |
| 44 | + @TaskAction |
| 45 | + def extract() { |
| 46 | + def sdkFile = sdkArchive.singleFile |
| 47 | + def buildDir = outputDir.get().asFile |
| 48 | + buildDir.mkdirs() |
| 49 | + |
| 50 | + // Extract outer tar.gz to get the inner tar.gz |
| 51 | + def tempDir = new File(buildDir, 'temp') |
| 52 | + tempDir.mkdirs() |
| 53 | + |
| 54 | + project.copy { |
| 55 | + from project.tarTree(sdkFile) |
| 56 | + into tempDir |
| 57 | + } |
| 58 | + |
| 59 | + // Find and extract the multiplatforms SDK |
| 60 | + def multiplatformsSdk = new File(tempDir, 'CICS_TG_SDK_91_Multiplatforms.tar.gz') |
| 61 | + if (!multiplatformsSdk.exists()) { |
| 62 | + throw new GradleException("Could not find CICS_TG_SDK_91_Multiplatforms.tar.gz in extracted archive") |
| 63 | + } |
| 64 | + |
| 65 | + def sdkDir = new File(tempDir, 'sdk') |
| 66 | + sdkDir.mkdirs() |
| 67 | + |
| 68 | + project.copy { |
| 69 | + from project.tarTree(multiplatformsSdk) |
| 70 | + into sdkDir |
| 71 | + } |
| 72 | + |
| 73 | + // Extract cicseci.rar to get cicseci.jar, ctgclient.jar, and ctgserver.jar |
| 74 | + def cicsEciRar = new File(sdkDir, 'cicstgsdk/api/jee/runtime/managed/cicseci.rar') |
| 75 | + if (!cicsEciRar.exists()) { |
| 76 | + throw new GradleException("Could not find cicseci.rar at expected location") |
| 77 | + } |
| 78 | + |
| 79 | + project.copy { |
| 80 | + from project.zipTree(cicsEciRar) |
| 81 | + into buildDir |
| 82 | + include 'cicseci.jar' |
| 83 | + include 'ctgclient.jar' |
| 84 | + include 'ctgserver.jar' |
| 85 | + } |
| 86 | + |
| 87 | + // Copy cicsjee.jar |
| 88 | + def cicsJeeJar = new File(sdkDir, 'cicstgsdk/api/jee/runtime/nonmanaged/cicsjee.jar') |
| 89 | + if (!cicsJeeJar.exists()) { |
| 90 | + throw new GradleException("Could not find cicsjee.jar at expected location") |
| 91 | + } |
| 92 | + |
| 93 | + project.copy { |
| 94 | + from cicsJeeJar |
| 95 | + into buildDir |
| 96 | + } |
| 97 | + |
| 98 | + // Clean up temp directory |
| 99 | + tempDir.deleteDir() |
| 100 | + |
| 101 | + logger.lifecycle("Extracted CICS JARs to: ${buildDir.absolutePath}") |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +tasks.register('extractCicsJars', ExtractCicsJars) { |
| 106 | + sdkArchive.from(configurations.named('cicsSdk')) |
| 107 | + |
| 108 | + // Only extract if the output directory doesn't exist or SDK configuration changed |
| 109 | + outputs.upToDateWhen { |
| 110 | + def outputDir = it.outputDir.get().asFile |
| 111 | + outputDir.exists() && |
| 112 | + new File(outputDir, 'cicseci.jar').exists() && |
| 113 | + new File(outputDir, 'ctgclient.jar').exists() && |
| 114 | + new File(outputDir, 'ctgserver.jar').exists() && |
| 115 | + new File(outputDir, 'cicsjee.jar').exists() |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +dependencies { |
| 120 | + // Download the CICS SDK from IBM |
| 121 | + cicsSdk "${cicsSdkName}:${cicsSdkName}:@tar.gz" |
| 122 | + |
| 123 | + // Compile-time dependencies (eliminates reflection) |
| 124 | + compileOnly group: 'javax.resource', name: 'javax.resource-api', version: '1.7.1' |
| 125 | + compileOnly files(tasks.named('extractCicsJars').map { task -> |
| 126 | + project.fileTree(task.outputDir) { |
| 127 | + include 'cicseci.jar' |
| 128 | + } |
| 129 | + }) |
| 130 | + |
| 131 | + // Test dependencies |
| 132 | + testImplementation group: 'javax.resource', name: 'javax.resource-api', version: '1.7.1' |
| 133 | + testImplementation libs.bundles.mockito |
| 134 | + testImplementation files(tasks.named('extractCicsJars').map { task -> |
| 135 | + project.fileTree(task.outputDir) { |
| 136 | + include '*.jar' |
| 137 | + } |
| 138 | + }) |
| 139 | +} |
| 140 | + |
| 141 | +// Ensure extraction happens before compilation |
| 142 | +tasks.named('compileJava') { |
| 143 | + dependsOn 'extractCicsJars' |
| 144 | +} |
| 145 | + |
| 146 | +tasks.named('compileTestGroovy') { |
| 147 | + dependsOn 'extractCicsJars' |
| 148 | +} |
| 149 | + |
| 150 | +tasks.named('forbiddenApisMain').configure { |
| 151 | + failOnMissingClasses = false |
| 152 | +} |
0 commit comments