xref: /JGit/tools/version.sh (revision 764f1635d4fec81e178bd98a08400eee2f633de0)
16f06be9bSShawn O. Pearce#!/bin/sh
26f06be9bSShawn O. Pearce# Copyright (C) 2009, Google Inc.
36f06be9bSShawn O. Pearce# and other copyright owners as documented in the project's IP log.
46f06be9bSShawn O. Pearce#
56f06be9bSShawn O. Pearce# This program and the accompanying materials are made available
66f06be9bSShawn O. Pearce# under the terms of the Eclipse Distribution License v1.0 which
76f06be9bSShawn O. Pearce# accompanies this distribution, is reproduced below, and is
86f06be9bSShawn O. Pearce# available at http://www.eclipse.org/org/documents/edl-v10.php
96f06be9bSShawn O. Pearce#
106f06be9bSShawn O. Pearce# All rights reserved.
116f06be9bSShawn O. Pearce#
126f06be9bSShawn O. Pearce# Redistribution and use in source and binary forms, with or
136f06be9bSShawn O. Pearce# without modification, are permitted provided that the following
146f06be9bSShawn O. Pearce# conditions are met:
156f06be9bSShawn O. Pearce#
166f06be9bSShawn O. Pearce# - Redistributions of source code must retain the above copyright
176f06be9bSShawn O. Pearce#   notice, this list of conditions and the following disclaimer.
186f06be9bSShawn O. Pearce#
196f06be9bSShawn O. Pearce# - Redistributions in binary form must reproduce the above
206f06be9bSShawn O. Pearce#   copyright notice, this list of conditions and the following
216f06be9bSShawn O. Pearce#   disclaimer in the documentation and/or other materials provided
226f06be9bSShawn O. Pearce#   with the distribution.
236f06be9bSShawn O. Pearce#
246f06be9bSShawn O. Pearce# - Neither the name of the Eclipse Foundation, Inc. nor the
256f06be9bSShawn O. Pearce#   names of its contributors may be used to endorse or promote
266f06be9bSShawn O. Pearce#   products derived from this software without specific prior
276f06be9bSShawn O. Pearce#   written permission.
286f06be9bSShawn O. Pearce#
296f06be9bSShawn O. Pearce# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
306f06be9bSShawn O. Pearce# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
316f06be9bSShawn O. Pearce# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
326f06be9bSShawn O. Pearce# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
336f06be9bSShawn O. Pearce# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
346f06be9bSShawn O. Pearce# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
356f06be9bSShawn O. Pearce# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
366f06be9bSShawn O. Pearce# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
376f06be9bSShawn O. Pearce# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
386f06be9bSShawn O. Pearce# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
396f06be9bSShawn O. Pearce# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
406f06be9bSShawn O. Pearce# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
416f06be9bSShawn O. Pearce# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
426f06be9bSShawn O. Pearce
436f06be9bSShawn O. Pearce
44fc5fc70eSShawn O. Pearce# Update all pom.xml with new build number
456f06be9bSShawn O. Pearce#
466f06be9bSShawn O. Pearce# TODO(spearce) This should be converted to some sort of
476f06be9bSShawn O. Pearce# Java based Maven plugin so its fully portable.
486f06be9bSShawn O. Pearce#
496f06be9bSShawn O. Pearce
506f06be9bSShawn O. Pearcecase "$1" in
516f06be9bSShawn O. Pearce--snapshot=*)
526f06be9bSShawn O. Pearce	V=$(echo "$1" | perl -pe 's/^--snapshot=//')
536f06be9bSShawn O. Pearce	if [ -z "$V" ]
546f06be9bSShawn O. Pearce	then
556f06be9bSShawn O. Pearce		echo >&2 "usage: $0 --snapshot=0.n.0"
566f06be9bSShawn O. Pearce		exit 1
576f06be9bSShawn O. Pearce	fi
586f06be9bSShawn O. Pearce	case "$V" in
596f06be9bSShawn O. Pearce	*-SNAPSHOT) : ;;
606f06be9bSShawn O. Pearce	*) V=$V-SNAPSHOT ;;
616f06be9bSShawn O. Pearce	esac
626f06be9bSShawn O. Pearce	;;
636f06be9bSShawn O. Pearce
646f06be9bSShawn O. Pearce--release)
656f06be9bSShawn O. Pearce	V=$(git describe HEAD) || exit
666f06be9bSShawn O. Pearce	;;
676f06be9bSShawn O. Pearce
686f06be9bSShawn O. Pearce*)
696f06be9bSShawn O. Pearce	echo >&2 "usage: $0 {--snapshot=0.n.0 | --release}"
706f06be9bSShawn O. Pearce	exit 1
716f06be9bSShawn O. Pearceesac
726f06be9bSShawn O. Pearce
736f06be9bSShawn O. Pearcecase "$V" in
746f06be9bSShawn O. Pearcev*) V=$(echo "$V" | perl -pe s/^v//) ;;
756f06be9bSShawn O. Pearceesac
766f06be9bSShawn O. Pearce
776f06be9bSShawn O. Pearcecase "$V" in
786f06be9bSShawn O. Pearce*-SNAPSHOT)
796f06be9bSShawn O. Pearce	POM_V=$V
80*764f1635SShawn O. Pearce	OSGI_V="${V%%-SNAPSHOT}.qualifier"
816f06be9bSShawn O. Pearce	;;
826f06be9bSShawn O. Pearce*-[1-9]*-g[0-9a-f]*)
836f06be9bSShawn O. Pearce	POM_V=$(echo "$V" | perl -pe 's/-(\d+-g.*)$/.$1/')
84*764f1635SShawn O. Pearce	OSGI_V=$(perl -e '
85*764f1635SShawn O. Pearce		$ARGV[0] =~ /^(\d+)(?:\.(\d+)(?:\.(\d+))?)?-(\d+)-g(.*)$/;
86*764f1635SShawn O. Pearce		my ($a, $b, $c, $p, $r) = ($1, $2, $3, $4, $5);
87*764f1635SShawn O. Pearce		$b = '0' unless defined $b;
88*764f1635SShawn O. Pearce		$c = '0' unless defined $c;
89*764f1635SShawn O. Pearce
90*764f1635SShawn O. Pearce		printf "%s.%s.%s.%6.6i_g%s\n", $a, $b, $c, $p, $r;
91*764f1635SShawn O. Pearce		' "$V")
926f06be9bSShawn O. Pearce	;;
936f06be9bSShawn O. Pearce*)
946f06be9bSShawn O. Pearce	POM_V=$V
95*764f1635SShawn O. Pearce	OSGI_V=$V
966f06be9bSShawn O. Pearce	;;
976f06be9bSShawn O. Pearceesac
986f06be9bSShawn O. Pearce
99*764f1635SShawn O. PearceAPI_V=$(perl -e '
100*764f1635SShawn O. Pearce	$ARGV[0] =~ /^(\d+(?:\.\d+(?:\.\d+)?)?)/;
101*764f1635SShawn O. Pearce	print $1
102*764f1635SShawn O. Pearce	' "$V")
103*764f1635SShawn O. Pearce
104*764f1635SShawn O. PearceAPI_N=$(perl -e '
105*764f1635SShawn O. Pearce	$ARGV[0] =~ /^(\d+)(?:\.(\d+)(?:\.(\d+))?)?/;
106*764f1635SShawn O. Pearce	my ($a, $b) = ($1, $2);
107*764f1635SShawn O. Pearce	$b = 0 unless defined $b;
108*764f1635SShawn O. Pearce	$b++;
109*764f1635SShawn O. Pearce	print "$a.$b.0";
110*764f1635SShawn O. Pearce	' "$API_V")
111*764f1635SShawn O. Pearce
112*764f1635SShawn O. Pearceperl -pi -e '
113*764f1635SShawn O. Pearce	s/^(Bundle-Version:\s*).*$/${1}'"$OSGI_V"'/;
114*764f1635SShawn O. Pearce	s/(org.eclipse.jgit.*;version=")[^"[(]*(")/${1}'"$API_V"'${2}/;
115*764f1635SShawn O. Pearce	s/(org.eclipse.jgit.*;version="\[)[^"]*(\)")/${1}'"$API_V,$API_N"'${2}/;
116*764f1635SShawn O. Pearce	' $(git ls-files | grep META-INF/MANIFEST.MF)
117*764f1635SShawn O. Pearce
118*764f1635SShawn O. Pearceperl -pi -e '
119*764f1635SShawn O. Pearce	if ($ARGV ne $old_argv) {
120*764f1635SShawn O. Pearce		$seen_version = 0;
121*764f1635SShawn O. Pearce		$old_argv = $ARGV;
122*764f1635SShawn O. Pearce	}
123*764f1635SShawn O. Pearce	if (!$seen_version) {
124*764f1635SShawn O. Pearce		$seen_version = 1 if (!/<\?xml/ &&
125*764f1635SShawn O. Pearce		s/(version=")[^"]*(")/${1}'"$OSGI_V"'${2}/);
126*764f1635SShawn O. Pearce	}
127*764f1635SShawn O. Pearce	' org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml
128*764f1635SShawn O. Pearce
129*764f1635SShawn O. Pearceperl -pi -e '
130*764f1635SShawn O. Pearce	s{<(version)>.*</\1>}{<${1}>'"$POM_V"'</${1}>};
131*764f1635SShawn O. Pearce	' org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml
132*764f1635SShawn O. Pearce
133*764f1635SShawn O. Pearceperl -pi -e '
134*764f1635SShawn O. Pearce	if ($ARGV ne $old_argv) {
135*764f1635SShawn O. Pearce		$seen_version = 0;
136*764f1635SShawn O. Pearce		$old_argv = $ARGV;
137*764f1635SShawn O. Pearce	}
138*764f1635SShawn O. Pearce	if ($seen_version < 3) {
139*764f1635SShawn O. Pearce		$seen_version++ if
140*764f1635SShawn O. Pearce		s{<(version)>.*</\1>}{<${1}>'"$POM_V"'</${1}>};
141*764f1635SShawn O. Pearce	}
142*764f1635SShawn O. Pearce	' org.eclipse.jgit.packaging/org.eclipse.jgit.updatesite/pom.xml
143*764f1635SShawn O. Pearce
1446f06be9bSShawn O. Pearceperl -pi -e '
1456f06be9bSShawn O. Pearce	if ($ARGV ne $old_argv) {
1466f06be9bSShawn O. Pearce		$seen_version = 0;
1476f06be9bSShawn O. Pearce		$old_argv = $ARGV;
1486f06be9bSShawn O. Pearce	}
1496f06be9bSShawn O. Pearce	if (!$seen_version) {
1506f06be9bSShawn O. Pearce		$seen_version = 1 if
151fc5fc70eSShawn O. Pearce		s{<(version)>.*</\1>}{<${1}>'"$POM_V"'</${1}>};
1526f06be9bSShawn O. Pearce	}
1536f06be9bSShawn O. Pearce	' $(git ls-files | grep pom.xml)
1546f06be9bSShawn O. Pearce
1556f06be9bSShawn O. Pearcegit diff
156