forked from jflex-de/jflex
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost-release.pl
executable file
·176 lines (147 loc) · 6.61 KB
/
post-release.pl
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
#! /usr/bin/perl -w
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
#
# post-release.pl
#
# Performs the following:
#
# - switches working copy to git master branch
# - Changes the JFlex version in all POMs to the supplied
# snapshot version (X.Y.Z-SNAPSHOT)
# - Changes the bootstrap JFlex version in the de.jflex:jflex
# POM to the latest release version.
# - Updates the JFlex version comments and @version tags
# - Commits the changes to master
#
# For more information, see HOWTO_release.txt.
#
use strict;
use warnings;
use File::Find ();
use XML::LibXML;
use XML::LibXSLT;
use Getopt::Long;
my $snapshot;
my $usage = "Usage: $0 --snapshot <new-snapshot-version>\n e.g.: $0 --snapshot 1.6.0-SNAPSHOT\n";
GetOptions("snapshot=s" => \$snapshot) or die($usage);
die $usage unless (defined($snapshot) && $snapshot =~ /-SNAPSHOT$/);
my $sheet =<<'__STYLESHEET__';
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pom="http://maven.apache.org/POM/4.0.0"
xmlns="http://maven.apache.org/POM/4.0.0"
exclude-result-prefixes="pom">
<xsl:param name="snapshot"/>
<xsl:param name="latest-release"/>
<!-- Replace all JFlex versions with the new JFlex snapshot version, -->
<!-- except for the bootstrap version in the de.jflex:jflex POM. -->
<xsl:template
match=" /pom:project[pom:groupId='de.jflex' or (not(pom:groupId) and pom:parent/pom:groupId='de.jflex')]/pom:version
|/pom:project/pom:parent[pom:groupId='de.jflex' and pom:artifactId='jflex-parent']/pom:version
|/pom:project/pom:dependencies/pom:dependency[pom:groupId='de.jflex' and pom:artifactId='jflex']/pom:version
|/pom:project/pom:build/pom:plugins/pom:plugin
[ (pom:groupId='de.jflex' and pom:artifactId='jflex-maven-plugin')
and not(/pom:project/pom:parent/pom:groupId='de.jflex' and /pom:project/pom:artifactId='jflex')]/pom:version">
<version><xsl:value-of select="$snapshot"/></version>
</xsl:template>
<!-- Replace the bootstrap version with the latest release version -->
<!-- in the de.jflex:jflex POM. -->
<xsl:template
match="/pom:project/pom:build/pom:plugins/pom:plugin
[ /pom:project/pom:parent/pom:groupId='de.jflex'
and /pom:project/pom:artifactId='jflex'
and pom:artifactId='jflex-maven-plugin']
/pom:version">
<version><xsl:value-of select="$latest-release"/></version>
</xsl:template>
<xsl:template match="@*|*|processing-instruction()|comment()">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()|processing-instruction()|comment()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
__STYLESHEET__
select STDOUT;
$| = 1; # Turn on auto-flush
print "Clean checkout? ";
my $stat_results=`git status -s`;
if ($stat_results) {
print "NO!\n\n$stat_results\nAborting.\n";
exit 1;
}
print "Yes.\n\n";
print "Switching to master branch..\n";
system ("git checkout master");
if ($?) {
print "FAILED.\n";
exit 1;
}
print "OK.\n\n";
# read versions after branch switch!
my $previous_snapshot = get_latest_version();
(my $latest_release = $previous_snapshot) =~ s/-SNAPSHOT//;
print "Switching JFlex version -> $snapshot\n";
print " and boostrap JFlex version -> $previous_snapshot in the de.jflex:jflex POM ...\n";
File::Find::find({wanted => \&wanted, follow => 1}, '.');
print "Updating version in build.xml\n";
system (qq!perl -pi -e "s/\Q$previous_snapshot\E/$snapshot/" jflex/build.xml !);
print "Updating version in Main.java\n";
system (qq!perl -pi -e "s/\Q$previous_snapshot\E/$snapshot/" jflex/src/main/java/jflex/Main.java !);
print "Updating version in the testsuite's Exec.java\n";
system (qq!perl -pi -e "s/\Q$previous_snapshot\E/$snapshot/"!
. q! testsuite/jflex-testsuite-maven-plugin/src/main/java/jflextest/Exec.java !);
print " updating version in bin/jflex*";
system (qq!perl -pi -e "s/\Q$previous_snapshot\E/$snapshot/" jflex/bin/jflex !);
system (qq!perl -pi -e "s/\Q$previous_snapshot\E/$snapshot/" jflex/bin/jflex.bat !);
print "\ndone.\n\n";
# <property name="bootstrap.version" value="1.5.0" />
# <property name="version" value="1.5.1-SNAPSHOT" />
print "Updating version -> $snapshot and",
" bootstrap JFlex version -> $latest_release\n",
" in jflex/build.xml\n";
system(qq!perl -pi -e "s/(property\\s+name\\s*=\\s*[\\"']version[\\"']\\s+value\\s*=\\s*[\\"'])[^\\"]+/\\\${1}$snapshot/;!
.qq! s/(property\\s+name\\s*=\\s*[\\"']bootstrap\\.version[\\"']\\s+value\\s*=\\s*[\\"'])[^\\"']+/\\\${1}$latest_release/;"!
. q! jflex/build.xml !);
print "\ndone.\n\n";
print " updating version in tex/manual.tex";
system (qq!perl -pi -e "s/\Q$previous_snapshot\E/$snapshot/" tex/manual.tex!);
print "\ndone.\n\n";
print " updating version in jflex/README.md";
system (qq!perl -pi -e "s/\Q$previous_snapshot\E/$snapshot/" jflex/README.md!);
print "\ndone.\n\n";
print " updating version in comments and version tags in jflex/**.java";
system (qq!find jflex -name "*.java" | xargs perl -pi -e "s/\Q$previous_snapshot\E/$snapshot/"!);
system (qq!find jflex -name "LexScan.flex" | xargs perl -pi -e "s/\Q$previous_snapshot\E/$snapshot/"!);
print "\ndone.\n\n";
print "Committing version update ...\n";
my $ret_val = system
(qq!git commit -a -m "bump version: JFlex $previous_snapshot -> $snapshot"!);
if ($ret_val) {
print STDERR "ERROR - Aborting.\n";
exit $ret_val >> 8; # Exit with git's return value
}
print "\ndone.\n\n";
print "Now on branch master. 'git push' to publish.\n\n";
exit;
sub get_latest_version {
# Get the previous snapshot version from the parent POM
# (assumes master is on previous snapshot)
my $parent_pom = XML::LibXML->load_xml(location => 'pom.xml');
my $xpath_context = XML::LibXML::XPathContext->new($parent_pom);
$xpath_context->registerNs('pom', 'http://maven.apache.org/POM/4.0.0');
return $xpath_context->findvalue('/pom:project/pom:version');
}
sub wanted {
transform($File::Find::fullname) if (/^pom\.xml\z/);
}
sub transform {
my $pom = shift;
my $xslt = XML::LibXSLT->new();
my $style_doc = XML::LibXML->load_xml('string' => $sheet);
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform_file
($pom, 'snapshot' => "'$snapshot'",
'latest-release' => "'$latest_release'");
$stylesheet->output_file($results, $pom); # replace existing file
}