|
| 1 | +class ArtifactProvider |
| 2 | + |
| 3 | + def initialize(bundle_name, base_dir) |
| 4 | + @base_bundle_name = bundle_name |
| 5 | + @module_dir = base_dir |
| 6 | + @target_dir = @module_dir + "/target" |
| 7 | + @release_version = getPomVersion() |
| 8 | + @sourceForgeArtifacts = prepareSourceForgeArtifacts() |
| 9 | + @docs_directory = prepareDocsDirectory() |
| 10 | + |
| 11 | + puts "" |
| 12 | + puts "Releasing " + @base_bundle_name + " version " + @release_version |
| 13 | + puts "" |
| 14 | + puts " The following SourceForge artifacts will be uploaded:" |
| 15 | + @sourceForgeArtifacts.each { |x| puts " * " + x } |
| 16 | + puts "" |
| 17 | + puts " The following directory will be synced to JBoss Docs server:" |
| 18 | + puts " * " + @docs_directory |
| 19 | + puts "" |
| 20 | + puts " Continue [y/N]" |
| 21 | + continueRelease = $stdin.gets |
| 22 | + continueRelease.chomp! |
| 23 | + abort("Aborting release process") unless continueRelease == "y" |
| 24 | + end |
| 25 | + |
| 26 | + def getReleaseVersion |
| 27 | + return @release_version |
| 28 | + end |
| 29 | + |
| 30 | + def getSourceForgeArtifacts() |
| 31 | + return @sourceForgeArtifacts |
| 32 | + end |
| 33 | + |
| 34 | + def getDocsDirectory() |
| 35 | + return @docs_directory |
| 36 | + end |
| 37 | + |
| 38 | + private |
| 39 | + |
| 40 | + def prepareDocsDirectory() |
| 41 | + docs_dir = getBundlePath(@target_dir, @base_bundle_name, @release_version, :dir) |
| 42 | + docs_dir << "/"<< @base_bundle_name << "-" << @release_version << "/docs" |
| 43 | + |
| 44 | + abort("Docs directory " + docs_dir + " cannot be found.") unless File.exist?(docs_dir) |
| 45 | + return docs_dir |
| 46 | + end |
| 47 | + |
| 48 | + def prepareSourceForgeArtifacts() |
| 49 | + readme = @module_dir + "/../README.md" |
| 50 | + abort(readme + " cannot be found. List of SourceForge artifacts not complete.") unless File.exist?(readme) |
| 51 | + |
| 52 | + changelog = @module_dir + "/../changelog.txt" |
| 53 | + abort(changelog + " cannot be found. List of SourceForge artifacts not complete.") unless File.exist?(changelog) |
| 54 | + |
| 55 | + tar_bundle = getBundlePath(@target_dir, @base_bundle_name, @release_version, :tar) |
| 56 | + abort("tar bundle '" + tar_bundle + "' cannot be found. List of SourceForge artifacts not complete.") unless File.exist?(tar_bundle) |
| 57 | + |
| 58 | + zip_bundle = getBundlePath(@target_dir, @base_bundle_name, @release_version, :zip) |
| 59 | + abort("zip bundle '" + zip_bundle + "' cannot be found. List of SourceForge artifacts not complete.") unless File.exist?(zip_bundle) |
| 60 | + |
| 61 | + return [readme, changelog, tar_bundle, zip_bundle] |
| 62 | + end |
| 63 | + |
| 64 | + def getPomVersion() |
| 65 | + pom = @module_dir + "/pom.xml" |
| 66 | + if(!File.file?( pom )) |
| 67 | + abort("Unable to locate pom file") |
| 68 | + end |
| 69 | + |
| 70 | + f = File.open(pom) |
| 71 | + doc = Nokogiri::XML(f) |
| 72 | + f.close |
| 73 | + doc.remove_namespaces! |
| 74 | + |
| 75 | + if(!(/hibernate-validator-distribution/ =~ doc.xpath('//artifactId').text)) |
| 76 | + abort("Script is not run from the distribution directory") |
| 77 | + end |
| 78 | + |
| 79 | + return doc.xpath('//parent/version').text |
| 80 | + end |
| 81 | + |
| 82 | + def getBundlePath(target_dir, project, version, type) |
| 83 | + bundle_name = target_dir + "/" + project + "-" + version + "-dist" |
| 84 | + if(type == :tar) |
| 85 | + bundle_name << ".tar.gz" |
| 86 | + elsif (type == :zip) |
| 87 | + bundle_name << ".zip" |
| 88 | + elsif (type == :dir) |
| 89 | + else |
| 90 | + abort("Wrong bundle type: '" + type + "'") |
| 91 | + end |
| 92 | + return bundle_name |
| 93 | + end |
| 94 | +end |
0 commit comments