@@ -407,163 +407,168 @@ subprojects {
407407 ' default' buildDist
408408 }
409409
410- // sanity checks if packages can be extracted
411- final File extractionDir = new File (buildDir, ' extracted' )
412- File packageExtractionDir
413- if (project. name. contains(' deb' )) {
414- packageExtractionDir = new File (extractionDir, ' deb-extracted' )
415- } else {
416- assert project. name. contains(' rpm' )
417- packageExtractionDir = new File (extractionDir, ' rpm-extracted' )
418- }
419- task checkExtraction(type : LoggedExec ) {
420- dependsOn buildDist
421- doFirst {
422- project. delete(extractionDir)
423- extractionDir. mkdirs()
410+ if (dpkgExists() || rpmExists()) {
411+
412+ // sanity checks if packages can be extracted
413+ final File extractionDir = new File (buildDir, ' extracted' )
414+ File packageExtractionDir
415+ if (project. name. contains(' deb' )) {
416+ packageExtractionDir = new File (extractionDir, ' deb-extracted' )
417+ } else {
418+ assert project. name. contains(' rpm' )
419+ packageExtractionDir = new File (extractionDir, ' rpm-extracted' )
424420 }
425- }
426- check . dependsOn checkExtraction
427- if (project . name . contains( ' deb ' )) {
428- checkExtraction {
429- onlyIf dpkgExists
430- commandLine ' dpkg-deb ' , ' -x ' , " ${ -> buildDist.outputs.files.filter(debFilter).singleFile } " , packageExtractionDir
421+ task checkExtraction( type : LoggedExec ) {
422+ dependsOn buildDist
423+ doFirst {
424+ project . delete(extractionDir)
425+ extractionDir . mkdirs()
426+ }
431427 }
432- } else {
433- assert project. name. contains(' rpm' )
434- checkExtraction {
435- onlyIf rpmExists
436- final File rpmDatabase = new File (extractionDir, ' rpm-database' )
437- commandLine ' rpm' ,
438- ' --badreloc' ,
439- ' --nodeps' ,
440- ' --noscripts' ,
441- ' --notriggers' ,
442- ' --dbpath' ,
443- rpmDatabase,
444- ' --relocate' ,
445- " /=${ packageExtractionDir} " ,
446- ' -i' ,
447- " ${ -> buildDist.outputs.files.singleFile} "
428+
429+ check. dependsOn checkExtraction
430+ if (project. name. contains(' deb' )) {
431+ checkExtraction {
432+ onlyIf dpkgExists
433+ commandLine ' dpkg-deb' , ' -x' , " ${ -> buildDist.outputs.files.filter(debFilter).singleFile} " , packageExtractionDir
434+ }
435+ } else {
436+ assert project. name. contains(' rpm' )
437+ checkExtraction {
438+ onlyIf rpmExists
439+ final File rpmDatabase = new File (extractionDir, ' rpm-database' )
440+ commandLine ' rpm' ,
441+ ' --badreloc' ,
442+ ' --nodeps' ,
443+ ' --noscripts' ,
444+ ' --notriggers' ,
445+ ' --dbpath' ,
446+ rpmDatabase,
447+ ' --relocate' ,
448+ " /=${ packageExtractionDir} " ,
449+ ' -i' ,
450+ " ${ -> buildDist.outputs.files.singleFile} "
451+ }
448452 }
449- }
450453
451- task checkLicense {
452- dependsOn buildDist, checkExtraction
453- }
454- check. dependsOn checkLicense
455- if (project. name. contains(' deb' )) {
456- checkLicense {
457- onlyIf dpkgExists
458- doLast {
459- Path copyrightPath
460- String expectedLicense
461- String licenseFilename
462- if (project. name. contains(' oss-' )) {
463- copyrightPath = packageExtractionDir. toPath(). resolve(" usr/share/doc/elasticsearch-oss/copyright" )
464- expectedLicense = " ASL-2.0"
465- licenseFilename = " APACHE-LICENSE-2.0.txt"
466- } else {
467- copyrightPath = packageExtractionDir. toPath(). resolve(" usr/share/doc/elasticsearch/copyright" )
468- expectedLicense = " Elastic-License"
469- licenseFilename = " ELASTIC-LICENSE.txt"
454+ task checkLicense {
455+ dependsOn buildDist, checkExtraction
456+ }
457+ check. dependsOn checkLicense
458+ if (project. name. contains(' deb' )) {
459+ checkLicense {
460+ onlyIf dpkgExists
461+ doLast {
462+ Path copyrightPath
463+ String expectedLicense
464+ String licenseFilename
465+ if (project. name. contains(' oss-' )) {
466+ copyrightPath = packageExtractionDir. toPath(). resolve(" usr/share/doc/elasticsearch-oss/copyright" )
467+ expectedLicense = " ASL-2.0"
468+ licenseFilename = " APACHE-LICENSE-2.0.txt"
469+ } else {
470+ copyrightPath = packageExtractionDir. toPath(). resolve(" usr/share/doc/elasticsearch/copyright" )
471+ expectedLicense = " Elastic-License"
472+ licenseFilename = " ELASTIC-LICENSE.txt"
473+ }
474+ final List<String > header = Arrays . asList(" Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/" ,
475+ " Copyright: Elasticsearch B.V. <info@elastic.co>" ,
476+ " License: " + expectedLicense)
477+ final List<String > licenseLines = Files . readAllLines(rootDir. toPath(). resolve(" licenses/" + licenseFilename))
478+ final List<String > expectedLines = header + licenseLines. collect { " " + it }
479+ assertLinesInFile(copyrightPath, expectedLines)
470480 }
471- final List<String > header = Arrays . asList(" Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/" ,
472- " Copyright: Elasticsearch B.V. <info@elastic.co>" ,
473- " License: " + expectedLicense)
474- final List<String > licenseLines = Files . readAllLines(rootDir. toPath(). resolve(" licenses/" + licenseFilename))
475- final List<String > expectedLines = header + licenseLines. collect { " " + it }
476- assertLinesInFile(copyrightPath, expectedLines)
477481 }
478- }
479- } else {
480- assert project. name. contains(' rpm' )
481- checkLicense {
482- onlyIf rpmExists
483- doLast {
484- String licenseFilename
485- if (project. name. contains(' oss-' )) {
486- licenseFilename = " APACHE-LICENSE-2.0.txt"
487- } else {
488- licenseFilename = " ELASTIC-LICENSE.txt"
482+ } else {
483+ assert project. name. contains(' rpm' )
484+ checkLicense {
485+ onlyIf rpmExists
486+ doLast {
487+ String licenseFilename
488+ if (project. name. contains(' oss-' )) {
489+ licenseFilename = " APACHE-LICENSE-2.0.txt"
490+ } else {
491+ licenseFilename = " ELASTIC-LICENSE.txt"
492+ }
493+ final List<String > licenseLines = Files . readAllLines(rootDir. toPath(). resolve(" licenses/" + licenseFilename))
494+ final Path licensePath = packageExtractionDir. toPath(). resolve(" usr/share/elasticsearch/LICENSE.txt" )
495+ assertLinesInFile(licensePath, licenseLines)
489496 }
490- final List<String > licenseLines = Files . readAllLines(rootDir. toPath(). resolve(" licenses/" + licenseFilename))
491- final Path licensePath = packageExtractionDir. toPath(). resolve(" usr/share/elasticsearch/LICENSE.txt" )
492- assertLinesInFile(licensePath, licenseLines)
493497 }
494498 }
495- }
496499
497- task checkNotice {
498- dependsOn buildDist, checkExtraction
499- onlyIf { (project. name. contains(' deb' ) && dpkgExists. call(it)) || (project. name. contains(' rpm' ) && rpmExists. call(it)) }
500- doLast {
501- final List<String > noticeLines = Arrays . asList(" Elasticsearch" , " Copyright 2009-2018 Elasticsearch" )
502- final Path noticePath = packageExtractionDir. toPath(). resolve(" usr/share/elasticsearch/NOTICE.txt" )
503- assertLinesInFile(noticePath, noticeLines)
500+ task checkNotice {
501+ dependsOn buildDist, checkExtraction
502+ onlyIf {
503+ (project. name. contains(' deb' ) && dpkgExists. call(it)) || (project. name. contains(' rpm' ) && rpmExists. call(it))
504+ }
505+ doLast {
506+ final List<String > noticeLines = Arrays . asList(" Elasticsearch" , " Copyright 2009-2018 Elasticsearch" )
507+ final Path noticePath = packageExtractionDir. toPath(). resolve(" usr/share/elasticsearch/NOTICE.txt" )
508+ assertLinesInFile(noticePath, noticeLines)
509+ }
504510 }
505- }
506- check. dependsOn checkNotice
511+ check. dependsOn checkNotice
507512
508- task checkLicenseMetadata(type : LoggedExec ) {
509- dependsOn buildDist, checkExtraction
510- }
511- check. dependsOn checkLicenseMetadata
512- if (project. name. contains(' deb' )) {
513- checkLicenseMetadata { LoggedExec exec ->
514- onlyIf dpkgExists
515- final ByteArrayOutputStream output = new ByteArrayOutputStream ()
516- exec. commandLine ' dpkg-deb' , ' --info' , " ${ -> buildDist.outputs.files.filter(debFilter).singleFile} "
517- exec. standardOutput = output
518- doLast {
519- String expectedLicense
520- if (project. name. contains(' oss-' )) {
521- expectedLicense = " ASL-2.0"
522- } else {
523- expectedLicense = " Elastic-License"
524- }
525- final Pattern pattern = Pattern . compile(" \\ s*License: (.+)" )
526- final String info = output. toString(' UTF-8' )
527- final String [] actualLines = info. split(" \n " )
528- int count = 0
529- for (final String actualLine : actualLines) {
530- final Matcher matcher = pattern. matcher(actualLine)
531- if (matcher. matches()) {
532- count++
533- final String actualLicense = matcher. group(1 )
534- if (expectedLicense != actualLicense) {
535- throw new GradleException (" expected license [${ expectedLicense} for package info but found [${ actualLicense} ]" )
513+ task checkLicenseMetadata(type : LoggedExec ) {
514+ dependsOn buildDist, checkExtraction
515+ }
516+ check. dependsOn checkLicenseMetadata
517+ if (project. name. contains(' deb' )) {
518+ checkLicenseMetadata { LoggedExec exec ->
519+ onlyIf dpkgExists
520+ final ByteArrayOutputStream output = new ByteArrayOutputStream ()
521+ exec. commandLine ' dpkg-deb' , ' --info' , " ${ -> buildDist.outputs.files.filter(debFilter).singleFile} "
522+ exec. standardOutput = output
523+ doLast {
524+ String expectedLicense
525+ if (project. name. contains(' oss-' )) {
526+ expectedLicense = " ASL-2.0"
527+ } else {
528+ expectedLicense = " Elastic-License"
529+ }
530+ final Pattern pattern = Pattern . compile(" \\ s*License: (.+)" )
531+ final String info = output. toString(' UTF-8' )
532+ final String [] actualLines = info. split(" \n " )
533+ int count = 0
534+ for (final String actualLine : actualLines) {
535+ final Matcher matcher = pattern. matcher(actualLine)
536+ if (matcher. matches()) {
537+ count++
538+ final String actualLicense = matcher. group(1 )
539+ if (expectedLicense != actualLicense) {
540+ throw new GradleException (" expected license [${ expectedLicense} for package info but found [${ actualLicense} ]" )
541+ }
536542 }
537543 }
538- }
539- if (count == 0 ) {
540- throw new GradleException ( " expected license [ ${ expectedLicense } ] for package info but found none in: \n ${ info } " )
541- }
542- if (count > 1 ) {
543- throw new GradleException ( " expected a single license for package info but found [ ${ count } ] in: \n ${ info } " )
544+ if (count == 0 ) {
545+ throw new GradleException ( " expected license [ ${ expectedLicense } ] for package info but found none in: \n ${ info } " )
546+ }
547+ if (count > 1 ) {
548+ throw new GradleException ( " expected a single license for package info but found [ ${ count } ] in: \n ${ info } " )
549+ }
544550 }
545551 }
546- }
547- } else {
548- assert project . name . contains( ' rpm ' )
549- checkLicenseMetadata { LoggedExec exec ->
550- onlyIf rpmExists
551- final ByteArrayOutputStream output = new ByteArrayOutputStream ()
552- exec. commandLine ' rpm ' , ' -qp ' , ' --queryformat ' , ' %{License} ' , " ${ -> buildDist.outputs.files.singleFile } "
553- exec . standardOutput = output
554- doLast {
555- String license = output . toString( ' UTF-8 ' )
556- String expectedLicense
557- if (project . name . contains( ' oss- ' )) {
558- expectedLicense = " ASL 2.0 "
559- } else {
560- expectedLicense = " Elastic License "
561- }
562- if ( license != expectedLicense) {
563- throw new GradleException ( " expected license [ ${ expectedLicense } ] for [ ${ -> buildDist.outputs.files.singleFile } ] but was [ ${ license } ] " )
552+ } else {
553+ assert project . name . contains( ' rpm ' )
554+ checkLicenseMetadata { LoggedExec exec ->
555+ onlyIf rpmExists
556+ final ByteArrayOutputStream output = new ByteArrayOutputStream ()
557+ exec . commandLine ' rpm ' , ' -qp ' , ' --queryformat ' , ' %{License} ' , " ${ -> buildDist.outputs.files.singleFile } "
558+ exec. standardOutput = output
559+ doLast {
560+ String license = output . toString( ' UTF-8 ' )
561+ String expectedLicense
562+ if (project . name . contains( ' oss- ' )) {
563+ expectedLicense = " ASL 2.0 "
564+ } else {
565+ expectedLicense = " Elastic License "
566+ }
567+ if (license != expectedLicense) {
568+ throw new GradleException ( " expected license [ ${ expectedLicense} ] for [ ${ -> buildDist.outputs.files.singleFile } ] but was [ ${ license } ] " )
569+ }
564570 }
565571 }
566572 }
567573 }
568-
569574}
0 commit comments