build.gradle 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import org.elasticsearch.gradle.VersionProperties
  2. apply plugin: 'distribution'
  3. ext.version = VersionProperties.elasticsearch
  4. // This project pulls a snapshot version of the ML cpp artifacts and sets that as the artifact
  5. // for this project so it can be used with dependency substitution.
  6. void getZip(File snapshotZip) {
  7. String zipUrl = "https://prelert-artifacts.s3.amazonaws.com/maven/org/elasticsearch/ml/ml-cpp/${version}/ml-cpp-${version}.zip"
  8. File snapshotMd5 = new File(snapshotZip.toString() + '.md5')
  9. HttpURLConnection conn = (HttpURLConnection) new URL(zipUrl).openConnection();
  10. // do a HEAD first to check the zip hash against the local file
  11. conn.setRequestMethod('HEAD');
  12. if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
  13. throw new GradleException('ML cpp snapshot does not exist')
  14. }
  15. String remoteMd5 = conn.getHeaderField('ETag')
  16. if (snapshotZip.exists()) {
  17. // do a HEAD first to check the zip hash against the local file
  18. String localMd5 = snapshotMd5.getText('UTF-8')
  19. if (remoteMd5.equals(localMd5)) {
  20. logger.info('Using cached ML snapshot')
  21. return
  22. }
  23. }
  24. snapshotZip.bytes = new URL(zipUrl).bytes
  25. snapshotMd5.setText(remoteMd5, 'UTF-8')
  26. }
  27. File snapshotZip = new File(projectDir, ".cache/ml-cpp-${version}.zip")
  28. task downloadMachineLearningSnapshot {
  29. onlyIf {
  30. // skip if ml-cpp is being built locally
  31. findProject(':ml-cpp') == null &&
  32. // skip for offline builds - just rely on the artifact already having been downloaded before here
  33. project.gradle.startParameter.isOffline() == false
  34. }
  35. doFirst {
  36. snapshotZip.parentFile.mkdirs()
  37. getZip(snapshotZip)
  38. }
  39. }
  40. task cleanCache(type: Delete) {
  41. delete "${projectDir}/.cache"
  42. }
  43. artifacts {
  44. 'default' file: snapshotZip, name: 'ml-cpp', type: 'zip', builtBy: downloadMachineLearningSnapshot
  45. }