xref: /JGit/tools/version.sh (revision 792d27ece1c997d7364dded2dc8c2d2e45e4dc5b)
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
80764f1635SShawn 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/')
84764f1635SShawn O. Pearce	OSGI_V=$(perl -e '
858d88a842SShawn O. Pearce		die unless $ARGV[0] =~ /^(\d+)(?:\.(\d+)(?:\.(\d+))?(?:\.\d{12}-r)?)?-(\d+)-g(.*)$/;
86764f1635SShawn O. Pearce		my ($a, $b, $c, $p, $r) = ($1, $2, $3, $4, $5);
87764f1635SShawn O. Pearce		$b = '0' unless defined $b;
88764f1635SShawn O. Pearce		$c = '0' unless defined $c;
89764f1635SShawn O. Pearce
90764f1635SShawn O. Pearce		printf "%s.%s.%s.%6.6i_g%s\n", $a, $b, $c, $p, $r;
91764f1635SShawn O. Pearce		' "$V")
926f06be9bSShawn O. Pearce	;;
936f06be9bSShawn O. Pearce*)
946f06be9bSShawn O. Pearce	POM_V=$V
95764f1635SShawn O. Pearce	OSGI_V=$V
966f06be9bSShawn O. Pearce	;;
976f06be9bSShawn O. Pearceesac
986f06be9bSShawn O. Pearce
99764f1635SShawn O. PearceAPI_V=$(perl -e '
100764f1635SShawn O. Pearce	$ARGV[0] =~ /^(\d+(?:\.\d+(?:\.\d+)?)?)/;
101764f1635SShawn O. Pearce	print $1
102764f1635SShawn O. Pearce	' "$V")
103764f1635SShawn O. Pearce
104764f1635SShawn O. PearceAPI_N=$(perl -e '
105764f1635SShawn O. Pearce	$ARGV[0] =~ /^(\d+)(?:\.(\d+)(?:\.(\d+))?)?/;
106764f1635SShawn O. Pearce	my ($a, $b) = ($1, $2);
107764f1635SShawn O. Pearce	$b = 0 unless defined $b;
108764f1635SShawn O. Pearce	$b++;
109764f1635SShawn O. Pearce	print "$a.$b.0";
110764f1635SShawn O. Pearce	' "$API_V")
111764f1635SShawn O. Pearce
112200f3caeSShawn O. Pearceperl -pi~ -e '
113764f1635SShawn O. Pearce	s/^(Bundle-Version:\s*).*$/${1}'"$OSGI_V"'/;
114764f1635SShawn O. Pearce	s/(org.eclipse.jgit.*;version=")[^"[(]*(")/${1}'"$API_V"'${2}/;
115764f1635SShawn O. Pearce	s/(org.eclipse.jgit.*;version="\[)[^"]*(\)")/${1}'"$API_V,$API_N"'${2}/;
116764f1635SShawn O. Pearce	' $(git ls-files | grep META-INF/MANIFEST.MF)
117764f1635SShawn O. Pearce
118200f3caeSShawn O. Pearceperl -pi~ -e '
119e2a35242SMatthias Sohn	s/^(Bundle-Version:\s*).*$/${1}'"$OSGI_V"'/;
120e2a35242SMatthias Sohn	s/(org.eclipse.jgit.*;version=")[^"[(]*(")/${1}'"$API_V"'${2}/;
121e2a35242SMatthias Sohn	s/(org.eclipse.jgit.*;version="\[)[^"]*(\)")/${1}'"$API_V,$API_N"'${2}/;
122*792d27ecSMatthias Sohn	s/^(Eclipse-SourceBundle:\s*org.eclipse.jgit.*;version=\").*(\";roots=\"\.\")$/${1}'"$OSGI_V"'${2}/;
123e2a35242SMatthias Sohn	' $(git ls-files | grep META-INF/SOURCE-MANIFEST.MF)
124e2a35242SMatthias Sohn
125e2a35242SMatthias Sohnperl -pi~ -e '
126764f1635SShawn O. Pearce	if ($ARGV ne $old_argv) {
127764f1635SShawn O. Pearce		$seen_version = 0;
128764f1635SShawn O. Pearce		$old_argv = $ARGV;
129764f1635SShawn O. Pearce	}
130764f1635SShawn O. Pearce	if (!$seen_version) {
131764f1635SShawn O. Pearce		$seen_version = 1 if (!/<\?xml/ &&
132764f1635SShawn O. Pearce		s/(version=")[^"]*(")/${1}'"$OSGI_V"'${2}/);
133764f1635SShawn O. Pearce	}
1347804045cSShawn O. Pearce	' org.eclipse.jgit.packaging/org.*.feature/feature.xml
135764f1635SShawn O. Pearce
136200f3caeSShawn O. Pearceperl -pi~ -e '
13779a2e28aSMatthias Sohn	if ($ARGV ne $old_argv) {
13879a2e28aSMatthias Sohn		$seen_version = 0;
13979a2e28aSMatthias Sohn		$old_argv = $ARGV;
14079a2e28aSMatthias Sohn	}
14179a2e28aSMatthias Sohn	if (!$seen_version) {
14279a2e28aSMatthias Sohn		$seen_version = 1 if
143764f1635SShawn O. Pearce		s{<(version)>.*</\1>}{<${1}>'"$POM_V"'</${1}>};
14479a2e28aSMatthias Sohn	}
1457804045cSShawn O. Pearce	' org.eclipse.jgit.packaging/org.*.feature/pom.xml
146764f1635SShawn O. Pearce
147200f3caeSShawn O. Pearceperl -pi~ -e '
148764f1635SShawn O. Pearce	if ($ARGV ne $old_argv) {
149764f1635SShawn O. Pearce		$seen_version = 0;
150764f1635SShawn O. Pearce		$old_argv = $ARGV;
151764f1635SShawn O. Pearce	}
152c1f352c1SMatthias Sohn	if ($seen_version < 5) {
153764f1635SShawn O. Pearce		$seen_version++ if
154764f1635SShawn O. Pearce		s{<(version)>.*</\1>}{<${1}>'"$POM_V"'</${1}>};
155764f1635SShawn O. Pearce	}
156764f1635SShawn O. Pearce	' org.eclipse.jgit.packaging/org.eclipse.jgit.updatesite/pom.xml
157764f1635SShawn O. Pearce
158200f3caeSShawn O. Pearceperl -pi~ -e '
1596f06be9bSShawn O. Pearce	if ($ARGV ne $old_argv) {
1606f06be9bSShawn O. Pearce		$seen_version = 0;
1616f06be9bSShawn O. Pearce		$old_argv = $ARGV;
1626f06be9bSShawn O. Pearce	}
16379a2e28aSMatthias Sohn	if (!$seen_version) {
16479a2e28aSMatthias Sohn		$seen_version = 1 if
165e2a35242SMatthias Sohn		s{<(version)>.*</\1>}{<${1}>'"$POM_V"'</${1}>};
166e2a35242SMatthias Sohn	}
167e2a35242SMatthias Sohn	' org.eclipse.jgit.packaging/pom.xml
168e2a35242SMatthias Sohn
169e2a35242SMatthias Sohnperl -pi~ -e '
170e2a35242SMatthias Sohn	if ($ARGV ne $old_argv) {
171e2a35242SMatthias Sohn		$seen_version = 0;
172e2a35242SMatthias Sohn		$old_argv = $ARGV;
173e2a35242SMatthias Sohn	}
1746f06be9bSShawn O. Pearce	if (!$seen_version) {
1756f06be9bSShawn O. Pearce		$seen_version = 1 if
176fc5fc70eSShawn O. Pearce		s{<(version)>.*</\1>}{<${1}>'"$POM_V"'</${1}>};
1776f06be9bSShawn O. Pearce	}
1786f06be9bSShawn O. Pearce	' $(git ls-files | grep pom.xml)
1796f06be9bSShawn O. Pearce
180200f3caeSShawn O. Pearcefind . -name '*~' | xargs rm -f
1816f06be9bSShawn O. Pearcegit diff
182