|
| 1 | +buildscript { |
| 2 | + // Add the "buildPlugins" ExtraProperty. It should be usable from the rest of this script as well. |
| 3 | + // See http://goo.gl/9bixNV |
| 4 | + apply from: "$rootDir/gradle/any/shared-mvn-coords.gradle" |
| 5 | + |
| 6 | + // The buildscript {} block is odd: even though we applied dependencies.gradle above, the repositories therein |
| 7 | + // do not get included here. Instead, we must explicitly define the repos again. Yay for duplication. |
| 8 | + repositories { |
| 9 | + gradlePluginPortal() |
| 10 | + exclusiveContent { |
| 11 | + forRepository { |
| 12 | + maven { |
| 13 | + url 'https://artifacts.unidata.ucar.edu/repository/unidata-all/' |
| 14 | + } |
| 15 | + } |
| 16 | + // only look for unidata plugin related artifacts from the unidata-all repo |
| 17 | + filter { |
| 18 | + includeModule 'edu.ucar.unidata', 'unidata-nexus-gradle' |
| 19 | + } |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + dependencies { |
| 24 | + classpath buildPlugins.nexus |
| 25 | + } |
| 26 | +} |
| 27 | + |
1 | 28 | if (!name.equals(rootProject.name)) { |
2 | 29 | throw new GradleException("This script plugin should only be applied to the root project, not '$name'.") |
3 | 30 | } |
4 | 31 |
|
5 | | -apply plugin: 'maven-publish' |
| 32 | +apply plugin: 'maven-publish' // gives us the publish task even though we are not going to publish anything to maven |
6 | 33 | apply plugin: 'com.github.johnrengelman.shadow' |
7 | 34 | apply from: "$rootDir/gradle/any/properties.gradle" // For Nexus credential properties. |
8 | 35 |
|
9 | | -import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact |
10 | | - |
11 | | -publishing { |
12 | | - // Publish all artifacts we've added to the "archives" configuration of the root project. See fatJars.gradle. |
13 | | - publications { |
14 | | - rootProject.configurations.archives.allArtifacts.each { |
15 | | - if (it instanceof ArchivePublishArtifact) { |
16 | | - AbstractArchiveTask task = (it as ArchivePublishArtifact).archiveTask |
17 | | - "$task.name"(MavenPublication) { |
18 | | - artifactId task.archiveBaseName.get() |
19 | | - artifact task |
| 36 | +import edu.ucar.build.publishing.tasks.PublishToRawRepoTask |
| 37 | + |
| 38 | +import java.nio.file.Files |
| 39 | +import java.nio.file.Paths |
| 40 | +import java.security.DigestInputStream |
| 41 | +import java.security.MessageDigest |
| 42 | + |
| 43 | +def createChecksumsTask = tasks.register('createChecksums') { |
| 44 | + group = 'publishing' |
| 45 | + description = 'Create .sha1, .sha256, and .md5 checksum files for the fatJars.' |
| 46 | + String sourceDir = "${rootProject.getBuildDir()}/libs" |
| 47 | + def files = fileTree(dir: "${sourceDir}", include: '**/*.jar') |
| 48 | + def algorithms = ["MD5", "SHA-1", "SHA-256"] |
| 49 | + algorithms.each {algorithm -> |
| 50 | + MessageDigest md = MessageDigest.getInstance(algorithm) |
| 51 | + files.each { File jarFile -> |
| 52 | + InputStream is = null |
| 53 | + DigestInputStream dis = null |
| 54 | + byte[] buffer = new byte[2048] |
| 55 | + try { |
| 56 | + is = Files.newInputStream(Paths.get(jarFile.absolutePath)) |
| 57 | + dis = new DigestInputStream(is, md) |
| 58 | + while (dis.read(buffer) != -1) { |
| 59 | + // just need to read through the file |
| 60 | + } |
| 61 | + dis.close() |
| 62 | + is.close() |
| 63 | + } finally { |
| 64 | + if (dis != null) { |
| 65 | + dis.close() |
| 66 | + } |
| 67 | + if (is != null) { |
| 68 | + is.close() |
20 | 69 | } |
21 | 70 | } |
| 71 | + |
| 72 | + byte[] digest = md.digest() |
| 73 | + StringBuilder sb = new StringBuilder() |
| 74 | + for (int b=0; b < digest.length; b++) { |
| 75 | + sb.append(Integer.toString((digest[b] & 0xff) + 0x100, 16).substring(1)) |
| 76 | + } |
| 77 | + String checksum = sb.toString() |
| 78 | + def ext = algorithm.toLowerCase().replace("-","") |
| 79 | + String outputFilename = "${buildDir}/libs/${jarFile.getName()}.${ext}" |
| 80 | + new File(outputFilename).withWriter { writer -> |
| 81 | + writer.write checksum |
| 82 | + } |
22 | 83 | } |
23 | 84 | } |
| 85 | + dependsOn buildDap4Lib, buildNcIdv, buildNetcdfAll, buildToolsUI |
24 | 86 | } |
25 | 87 |
|
26 | | -tasks.withType(GenerateModuleMetadata) { |
27 | | - enabled = false |
28 | | -} |
| 88 | +def publishFatJarsTask = tasks.register('publishFatJars', PublishToRawRepoTask) { |
| 89 | + group = 'publishing' |
| 90 | + description = 'Publish fatJars to Nexus downloads under /version/.' |
| 91 | + host = 'https://artifacts.unidata.ucar.edu/' |
| 92 | + repoName = 'downloads-netcdf-java' |
29 | 93 |
|
30 | | -// The "publish" tasks require credentials for our Nexus server, which they look for in Gradle properties. |
31 | | -// If those properties (i.e. NEXUS_USERNAME_KEY and NEXUS_PASSWORD_KEY) haven't been provided, the build will fail. |
32 | | -// Therefore, we only want to configure credentials when a "publish" task is part of the execution plan. Otherwise, |
33 | | -// unavailable credentials could cause a build to fail even if we aren't doing any publishing. The TaskExecutionGraph |
34 | | -// allows us to do that. |
35 | | -gradle.taskGraph.whenReady {TaskExecutionGraph taskGraph -> |
36 | | - // This won't find any publishToMavenLocal tasks. Those are of type PublishToMavenLocal |
37 | | - Collection<Task> mavenPublishTasks = taskGraph.allTasks.findAll { |
38 | | - it instanceof PublishToMavenRepository |
39 | | - } |
| 94 | + publishSrc = new File(rootProject.getBuildDir(), "libs") |
| 95 | + destPath = "$project.cleanVersion/" |
| 96 | + dependsOn createChecksumsTask |
40 | 97 |
|
41 | | - mavenPublishTasks.each { |
42 | | - it.repository.credentials.with { |
43 | | - username = getPropertyOrFailBuild NEXUS_USERNAME_KEY |
44 | | - password = getPropertyOrFailBuild NEXUS_PASSWORD_KEY |
45 | | - } |
| 98 | + onlyIf { |
| 99 | + // Will be evaluated at task execution time, not during configuration. |
| 100 | + // Fails the build if the specified properties haven't been provided. |
| 101 | + username = getPropertyOrFailBuild NEXUS_USERNAME_KEY |
| 102 | + password = getPropertyOrFailBuild NEXUS_PASSWORD_KEY |
| 103 | + return true |
46 | 104 | } |
47 | 105 | } |
| 106 | + |
| 107 | +publish.dependsOn publishFatJarsTask |
0 commit comments