forked from dcarter/Google-Data-APIs-Mavenized
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pomgen.rb
executable file
·242 lines (199 loc) · 10.2 KB
/
pomgen.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/ruby -w
require 'pp';
require 'set';
require 'tmpdir'
# maven command lines
$Mvn_deploy_snapshot = 'mvn -e deploy:deploy-file'
$Mvn_deploy_release = 'mvn -e deploy:deploy-file'
# maven coordinates
$Group = 'com.google.gdata.gdata-java-client'
$Release_repo = 'sonatype-nexus-staging'
$Release_repo_url = 'file:///tmp/maven/'
$Snapshot_repo = 'sonatype-nexus-snapshots'
$Snapshot_repo_url = 'http://oss.sonatype.org/content/repositories/snapshots'
def get_tattletale(dest=Dir.tmpdir, version='1.1.0.Final')
tattletale_basename = "jboss-tattletale-#{version}"
tattletale_archive = "#{tattletale_basename}.tar.gz"
tattletale_url = "http://sourceforge.net/projects/jboss/files/JBoss%20Tattletale/#{version}/#{tattletale_archive}/download"
tattletale_destfile = File.join(dest,tattletale_archive)
tattletale_destdir = File.join(dest,tattletale_basename)
tattletale = File.join(tattletale_destdir,'tattletale.jar')
# tattletale is cached; if you want to re-download a given version, you must delete prev files
if !File.exists?(tattletale) then
puts "Downloading tattletale"
`wget -nc #{tattletale_url} -O #{tattletale_destfile}`
`cd #{dest} && tar -xzf #{tattletale_destfile}`
FileUtils.rm(tattletale_destfile)
end
return tattletale
end
def get_gdata_jars(version, dest=Dir.tmpdir)
basename = "gdata-src.java-#{version}"
archive = "#{basename}.zip"
destfile = File.join(dest,archive)
destdir = File.join(dest,basename)
uri = "http://gdata-java-client.googlecode.com/files/#{archive}"
libs = File.join(destdir,"gdata","java","lib")
deps = File.join(destdir,"gdata","java","deps",".")
srcs = File.join(destdir,"gdata","java","src")
srcjar = File.join(destdir,"gdata","java","gdata-#{version}-sources.jar")
docs = File.join(destdir,"gdata","java","doc")
docjar = File.join(destdir,"gdata","java","gdata-#{version}-javadoc.jar")
# gdata jars are cached; if you want to re-download a given version, you must delete prev files
if !(File.exists?(libs) && File.directory?(libs)) then
puts "Downloading #{archive}"
`wget -nc #{uri} -O #{destfile}`
`unzip #{destfile} -d #{destdir}`
puts "Generating sources & javadoc packages"
`cd #{srcs}; jar -cf #{srcjar} . ; cd #{docs}; jar -cf #{docjar} .`
FileUtils.rm(destfile)
FileUtils.cp_r(deps,libs)
end
return libs, srcjar, docjar
end
def find_dependencies(version, jarpath, dest=Dir.tmpdir)
# run the jboss tattletale dependency analyzer, output into temp dir, pluck out the .dot file of dependencies
outdir = File.join(dest, "tattletale_out", "gdata-#{version}")
dotfile = File.join(outdir,"graphviz","dependencies.dot")
# tattletale results are cached; if you want to rebuild, you must delete prev files
if !File.exists?(dotfile) then
puts "Running tattletale. . ."
`java -Xmx256m -jar #{$Tattletale} #{jarpath} #{outdir}`
end
# parse dependencies .dot file & output pom.xml files for each jar
# and a script file to do the mvn deploy:deploy-file for each jar/pom combo
# the gdata distribution version becomes the <version></version> value in the pom
# the artifact id is the jar basename including version, as shipped from google, e.g. 'gdata-calendar-2.0'
# group id will use our own groupId, since we can't release under com.google groupId
depends_txt = File.read(dotfile)
depends = depends_txt.gsub(/;/,'').gsub(/_/,'-').gsub(/(\D+-\d+)-(\d+)/,'\1.\2').scan(/(\S+)\s+->\s+(\S+)/);
# build hash of dependencies - content of each hash entry is an array of the depended-upon jars
depends_hash = Hash.new();
depends.inject(depends_hash) { |hash, dependency|
if hash[dependency[0]] then
hash[dependency[0]].push(dependency[1])
else
hash[dependency[0]] = Array.new([dependency[1]])
end
hash;
}
# determine which dependencies are terminal dependencies
terminal_deps = depends_hash.inject(Set.new) { |set, a| set.merge([*a.flatten()] ) } # gives set of all artifacts that are depended on
terminal_deps.subtract(depends_hash.keys) # remove those that have dependencies
# tattletale can't tell us which jars rely on the jsr305 jar that is shipped in deps, so we will assume they all do
terminal_deps.each {|dep|
# add an "empty" dependency entry for each terminal dependency
# unless it is the google collections jar, which already exist on maven central, so we don't want to upload another
depends_hash[dep] = nil unless dep =~ /^google-collect-/
}
return depends_hash
end
def generate_poms(version, dependencies, jarpath, srcpath, docpath, dest=Dir.tmpdir, snapshot=FALSE)
outdir = File.join(dest, snapshot ? "snapshot" : "release", "v#{version}")
FileUtils.rm_r(outdir) if File.exists?(outdir) # start clean each time, so we have no orphan pom if a jar is deleted
FileUtils.mkdir(outdir)
pom_version = version + (snapshot ? '-SNAPSHOT' : '')
puts "Generating poms to #{outdir}"
script_file_name = File.join(outdir,"mvn_deploy_gdata")
script_file = File.new(script_file_name, "w")
script_file.puts "#!/bin/bash\n\n"
script_file.puts "MVN='#{snapshot ? $Mvn_deploy_snapshot : $Mvn_deploy_release}'"
script_file.puts "JARS='#{File.join(jarpath,'/')}'"
script_file.puts "POMS='#{File.join('.','/')}'"
script_file.puts "REPO='#{snapshot ? $Snapshot_repo : $Release_repo}'"
script_file.puts "SRCPATH='#{srcpath}'"
script_file.puts "DOCPATH='#{docpath}'"
script_file.puts "URL='#{snapshot ? $Snapshot_repo_url : $Release_repo_url}'\n\n"
dependencies.keys.sort.each { |key|
pom_file_name = key + "-pom.xml"
pom_file = File.new(File.join(outdir,pom_file_name), "w")
pom_file.puts '<?xml version="1.0" encoding="UTF-8"?>'
pom_file.puts '<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">'
pom_file.puts " <modelVersion>4.0.0</modelVersion>"
pom_file.puts " <groupId>#{$Group}</groupId>"
pom_file.puts " <artifactId>#{key}</artifactId>"
pom_file.puts " <version>#{pom_version}</version>"
pom_file.puts " <name>#{key}</name>"
pom_file.puts " <description>3rd-party jar #{key} from gdata-java-client project repackaged to meet requirements of Maven central repo</description>"
pom_file.puts " <url>http://code.google.com/p/gdata-java-client/</url>"
pom_file.puts " <licenses>"
pom_file.puts " <license>"
pom_file.puts " <name>Apache 2</name>"
pom_file.puts " <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>"
pom_file.puts " </license>"
pom_file.puts " </licenses>"
pom_file.puts " <scm>"
pom_file.puts " <url>http://code.google.com/p/gdata-java-client/source/browse/</url>"
pom_file.puts " </scm>"
pom_file.puts " <developers>"
pom_file.puts " <developer>"
pom_file.puts " <id>gdata-team</id>"
pom_file.puts " <name>The Google GData Team</name>"
pom_file.puts " <url>http://code.google.com/p/gdata-java-client/people/list</url>"
pom_file.puts " <organization>Google</organization>"
pom_file.puts " </developer>"
pom_file.puts " </developers>"
if dependencies[key] then
pom_file.puts " <dependencies>"
dependencies[key].uniq.sort.each { |dep|
# if the dependency is on google collections, need to use the proper group/artifact/version
# TODO: move this to find_dependencies phase. will require expanding the dependencies data structure to include group & version
# in addition to artifactId
if dep =~ /google-collect-(\S+)/ then # e.g. - google-collect-1.0-rc1
dep_group = 'com.google.collections'
dep_artifact = 'google-collections'
dep_version = $1
else
if dep =~ /guava-(\S+)/ then # e.g. - google-collect-1.0-rc1
dep_group = 'com.google.guava'
dep_artifact = 'guava'
dep_version = $1.sub( %r{-}, ".")
else
dep_group = $Group
dep_artifact = dep
dep_version = pom_version
end
end
pom_file.puts " <dependency>"
pom_file.puts " <groupId>#{dep_group}</groupId>"
pom_file.puts " <artifactId>#{dep_artifact}</artifactId>"
pom_file.puts " <version>#{dep_version}</version>"
pom_file.puts " </dependency>"
}
pom_file.puts " </dependencies>"
end
pom_file.puts "</project>"
pom_file.close;
script_file.puts "${MVN} -Dfile=${JARS}#{key}.jar -DpomFile=${POMS}#{pom_file_name} -DrepositoryId=${REPO} -Durl=${URL}"
if not key =~ /meta-/
script_file.puts "${MVN} -Dfile=${SRCPATH} -DpomFile=${POMS}#{pom_file_name} -Dpackaging=java-source -DrepositoryId=${REPO} -Durl=${URL}"
script_file.puts "${MVN} -Dfile=${DOCPATH} -DpomFile=${POMS}#{pom_file_name} -Dpackaging=javadoc -DrepositoryId=${REPO} -Durl=${URL}"
end
}
script_file.close
FileUtils.chmod(0744,script_file_name)
return outdir
end
# execution begins here
tempdir = File.join(Dir.tmpdir,"gdata-mvn")
FileUtils.mkdir(tempdir) unless File.exists?(tempdir) && File.directory?(tempdir)
outdir = File.join(FileUtils.pwd(),"target")
FileUtils.mkdir(outdir) unless File.exists?(outdir) && File.directory?(outdir)
$Tattletale = get_tattletale(tempdir)
['1.40.0', '1.40.1', '1.40.2', '1.40.3', '1.41.0', '1.41.1', '1.41.2', '1.42.0', '1.43.0', '1.44.0', '1.45.0', '1.46.0', '1.47.0', '1.47.1'].each { |version|
jarpath, srcpath, docpath = get_gdata_jars(version, tempdir)
puts "!!!! #{srcpath} - #{docpath}"
deps = find_dependencies(version, jarpath, tempdir)
deps_with_meta = Hash.new()
deps.each { |artifact, dep|
meta = artifact.sub( %r{(\w*)-(\d.\d)}, '\1-meta-\2' )
deps_with_meta[meta] = [artifact]
deps_with_meta[artifact] = dep
}
# generate snapshot poms
snaps_location = generate_poms(version, deps_with_meta, jarpath, srcpath, docpath, outdir, TRUE)
# generate release poms
rel_location = generate_poms(version, deps_with_meta, jarpath, srcpath, docpath, outdir, FALSE)
puts "Snapshot poms & deployment script created in #{snaps_location}\n\n"
puts " Release poms & deployment script created in #{rel_location}\n\n"
}