summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2007-09-06 08:19:03 +0300
committerPanu Matilainen <pmatilai@redhat.com>2007-09-06 08:19:03 +0300
commit2e9586ad93e717001e01ca9ad9477bf026bf3870 (patch)
tree5590a4c9c662a8c5bf0b6bc0629e7263e44746a5 /scripts
parent3448bd7328ad310f781f72c031dc1a92d0d8f31e (diff)
downloadlibrpm-tizen-2e9586ad93e717001e01ca9ad9477bf026bf3870.tar.gz
librpm-tizen-2e9586ad93e717001e01ca9ad9477bf026bf3870.tar.bz2
librpm-tizen-2e9586ad93e717001e01ca9ad9477bf026bf3870.zip
Add OSGi dependency extractor script from Kyu Lee
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.am4
-rw-r--r--scripts/osgideps.pl161
2 files changed, 163 insertions, 2 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 01dd54765..1e9d2a95d 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -14,7 +14,7 @@ EXTRA_DIST = \
check-files check-prereqs \
check-buildroot check-rpaths check-rpaths-worker \
find-debuginfo.sh find-lang.sh
- perldeps.pl perl.prov perl.req pythondeps.sh \
+ perldeps.pl perl.prov perl.req pythondeps.sh osgideps.pl \
rpmdb_loadcvt rpmdiff rpmdiff.cgi \
rpm.daily rpm.log rpm.xinetd rpm2cpio.sh \
tcl.req tgpg u_pkg.sh \
@@ -31,7 +31,7 @@ rpmconfig_SCRIPTS = \
check-files check-prereqs \
check-buildroot check-rpaths check-rpaths-worker \
find-lang.sh \
- perl.prov perl.req pythondeps.sh \
+ perl.prov perl.req pythondeps.sh osgideps.pl \
mono-find-requires mono-find-provides \
rpmdb_loadcvt rpmdiff rpmdiff.cgi \
rpm.daily rpm.log rpm.xinetd rpm2cpio.sh \
diff --git a/scripts/osgideps.pl b/scripts/osgideps.pl
new file mode 100644
index 000000000..428c9080c
--- /dev/null
+++ b/scripts/osgideps.pl
@@ -0,0 +1,161 @@
+#!/usr/bin/perl
+
+
+use Cwd;
+use Getopt::Long;
+
+
+$cdir = getcwd();
+$TEMPDIR="/tmp";
+$MANIFEST_NAME="META-INF/MANIFEST.MF";
+
+
+# prepare temporary directory
+if (! (-d $TEMPDIR)) {
+ if (($_ = `mkdir $TEMPDIR`) != 0) {exit 1;}
+ elsif (! (-w $TEMPDIR) && (-x $TEMPDIR)) {exit 1;}
+}
+
+# parse options
+my ($show_provides, $show_requires);
+
+my $result = GetOptions("provides" => \$show_provides,
+ "requires" => \$show_requires);
+
+exit(1) if (not $result);
+
+
+
+@allfiles = <STDIN>;
+
+if ($show_provides) {
+ do_provides(@allfiles);
+}
+
+if ($show_requires) {
+ do_requires(@allfiles);
+}
+
+
+exit(0);
+
+
+
+sub do_provides {
+
+
+foreach $jar (@_) {
+
+next if -f $jar && -r $jar;
+ $jar =~ s/[^[:print:]]//g;
+ # if this jar contains MANIFEST.MF file
+ if (`jar tf $jar | grep -e \^$MANIFEST_NAME` eq "$MANIFEST_NAME\n") {
+ # extract MANIFEST.MF file from jar to temporary directory
+ chdir $TEMPDIR;
+ `jar xf $cdir/$jar $MANIFEST_NAME`;
+ open(MANIFEST, "$MANIFEST_NAME");
+ my $bundleName = "";
+ my $bundleVersion = "";
+ # parse bundle name and version
+ while(<MANIFEST>) {
+ # get rid of non-print chars (some manifest files contain weird chars
+ s/[^[:print]]//g;
+ if (m/(^Bundle-SymbolicName: )((\w|\.)+)(\;*)(.*\n)/) {
+ $bundleName = $2;
+ }
+ if (m/(^Bundle-Version: )(.*)/) {
+ $bundleVersion = $2;
+ }
+ }
+ # skip this jar if no bundle name exists
+ if (! $bundleName eq "") {
+ if (! $bundleVersion eq "") {
+ print "osgi(".$bundleName.") = ".$bundleVersion."\n";
+ } else {
+ print "osgi(".$bundleName.")\n";
+ }
+ }
+ chdir $cdir;
+ }
+
+}
+
+}
+
+
+sub do_requires {
+
+foreach $jar (@_) {
+next if -f $jar && -r $jar;
+$jar =~ s/[^[:print:]]//g;
+ if (`jar tf $jar | grep -e \^$MANIFEST_NAME` eq "$MANIFEST_NAME\n") {
+ chdir $TEMPDIR;
+ `jar xf $cdir/$jar $MANIFEST_NAME`;
+ open(MANIFEST, "$MANIFEST_NAME") or die;
+ my %reqcomp = ();
+ while(<MANIFEST>) {
+ if (m/(^(Require-Bundle|Import-Package): )(.*)$/) {
+ my $reqlist = "$3"."\n";
+ while(<MANIFEST>) {
+ if (m/^[[:upper:]][[:alpha:]]+-[[:upper:]][[:alpha:]]+: .*/) {
+ $len = length $_;
+ seek MANIFEST, $len*-1 , 1;
+ last;
+ }
+ $reqlist.="$_";
+ }
+ push @requirelist, parseReqString($reqlist);
+ }
+
+ }
+ chdir $cdir;
+ }
+
+}
+
+$list = "";
+for $require (@requirelist) {
+ $list .= "osgi(".$require->{NAME}.")".$require->{VERSION}."\n";
+}
+#$abc = `echo \"$list\"|grep -e \^osgi\\(.*\\)| sort|uniq`;
+print $list;
+
+}
+
+sub parseReqString {
+ my $reqstr = $_[0];
+ my @return;
+ $reqstr =~ s/ //g;
+ $reqstr =~ s/\n//g;
+ $reqstr =~ s/[^[:print:]]//g;
+ $reqstr =~ s/("[[:alnum:]|\-|\_|\.|\(|\)|\[|\]]+)(,)([[:alnum:]|\-|\_|\.|\(|\)|\[|\]]+")/$1 $3/g;
+ @reqcomp = split /,/g, $reqstr;
+ foreach $reqelement (@reqcomp) {
+ @reqelementfrmnt = split /;/g, $reqelement;
+ $name="";
+ $version="";
+ $name = $reqelementfrmnt[0];
+ for $i (1 .. $#reqelementfrmnt) {
+ if ($reqelementfrmnt[$i] =~ m/(^(bundle-|)version=")(.*)(")/){
+ $version = $3;
+ last;
+ }
+ }
+ $version = parseVersion($version);
+ push @return, { NAME=>"$name", VERSION=>"$version"};
+ }
+
+ return @return;
+}
+
+sub parseVersion {
+ my $ver = $_[0];
+ if ($ver eq "") { return "";}
+ if ($ver =~ m/(^[\[|\(])(.+)\ (.+)([\]|\)]$)/) {
+ ($1 eq "\[") ? return " <= $2" : return " < $2";
+ } else {
+ return " = $ver";
+ }
+ return $ver;
+}
+