OSGi dep extractor update (rhbz#466111):
- From Alphonse Van Assche: "This patch fix some parsing bugs and add some new functionality (disable for now)"
This commit is contained in:
parent
6ce7def270
commit
5e71c9bd76
|
@ -43,93 +43,121 @@ exit(0);
|
|||
|
||||
sub do_provides {
|
||||
|
||||
foreach $file (@_) {
|
||||
|
||||
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;
|
||||
}
|
||||
next if -f $file && -r $file && !-l $file;
|
||||
$file =~ s/[^[:print:]]//g;
|
||||
if ($file =~ m/$MANIFEST_NAME$/ || $file =~ m/\.jar$/ ) {
|
||||
if ($file =~ m/\.jar$/) {
|
||||
# if this jar contains MANIFEST.MF file
|
||||
if (`jar tf $file | grep -e \^$MANIFEST_NAME` eq "$MANIFEST_NAME\n") {
|
||||
# extract MANIFEST.MF file from jar to temporary directory
|
||||
chdir $TEMPDIR;
|
||||
`jar xf $file $MANIFEST_NAME`;
|
||||
open(MANIFEST, "$MANIFEST_NAME");
|
||||
chdir $cdir;
|
||||
}
|
||||
} else {
|
||||
open(MANIFEST, "$file");
|
||||
}
|
||||
my $bundleName = "";
|
||||
my $version = "";
|
||||
# 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: )(.*)/) {
|
||||
$version = $2;
|
||||
$version = fixVersion($version);
|
||||
}
|
||||
if (m/(^(Export-Package): )(.*)$/) {
|
||||
my $bunlist = "$3"."\n";
|
||||
while(<MANIFEST>) {
|
||||
if (m/^[[:upper:]][[:alpha:]]+-[[:upper:]][[:alpha:]]+: .*/) {
|
||||
$len = length $_;
|
||||
seek MANIFEST, $len*-1 , 1;
|
||||
last;
|
||||
}
|
||||
$bunlist.="$_";
|
||||
}
|
||||
push @bundlelist, parsePkgString($bunlist);
|
||||
}
|
||||
}
|
||||
# skip this jar if no bundle name exists
|
||||
if (! $bundleName eq "") {
|
||||
if (! $bundleVersion eq "") {
|
||||
print "osgi(".$bundleName.") = ".$bundleVersion."\n";
|
||||
} else {
|
||||
if (! $version eq "") {
|
||||
print "osgi(".$bundleName.") = ".$version."\n";
|
||||
} else {
|
||||
print "osgi(".$bundleName.")\n";
|
||||
}
|
||||
}
|
||||
chdir $cdir;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$list = "";
|
||||
for $bundle (@bundlelist) {
|
||||
$list .= "osgi(".$bundle->{NAME}.")".$bundle->{VERSION}."\n";
|
||||
}
|
||||
# For now we dont take Require-Bundle AND Import-Package in account
|
||||
#print $list;
|
||||
}
|
||||
|
||||
|
||||
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";
|
||||
foreach $file (@_) {
|
||||
|
||||
next if -f $file && -r $file;
|
||||
$file =~ s/[^[:print:]]//g;
|
||||
if ($file =~ m/$MANIFEST_NAME$/ || $file =~ m/\.jar$/ ) {
|
||||
if ($file =~ m/\.jar$/) {
|
||||
# if this jar contains MANIFEST.MF file
|
||||
if (`jar tf $file | grep -e \^$MANIFEST_NAME` eq "$MANIFEST_NAME\n") {
|
||||
# extract MANIFEST.MF file from jar to temporary directory
|
||||
chdir $TEMPDIR;
|
||||
`jar xf $file $MANIFEST_NAME`;
|
||||
open(MANIFEST, "$MANIFEST_NAME");
|
||||
chdir $cdir;
|
||||
}
|
||||
} else {
|
||||
open(MANIFEST, "$file");
|
||||
}
|
||||
my %reqcomp = ();
|
||||
while(<MANIFEST>) {
|
||||
if (m/(^(Require-Bundle|Import-Package): )(.*)$/) {
|
||||
my $bunlist = "$3"."\n";
|
||||
while(<MANIFEST>) {
|
||||
if (m/^[[:upper:]][[:alpha:]]+-[[:upper:]][[:alpha:]]+: .*/) {
|
||||
$len = length $_;
|
||||
seek MANIFEST, $len*-1 , 1;
|
||||
last;
|
||||
}
|
||||
$reqlist.="$_";
|
||||
$bunlist.="$_";
|
||||
}
|
||||
push @requirelist, parseReqString($reqlist);
|
||||
push @bundlelist, parsePkgString($bunlist);
|
||||
}
|
||||
|
||||
}
|
||||
chdir $cdir;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$list = "";
|
||||
for $require (@requirelist) {
|
||||
$list .= "osgi(".$require->{NAME}.")".$require->{VERSION}."\n";
|
||||
for $bundle (@bundlelist) {
|
||||
$list .= "osgi(".$bundle->{NAME}.")".$bundle->{VERSION}."\n";
|
||||
}
|
||||
#$abc = `echo \"$list\"|grep -e \^osgi\\(.*\\)| sort|uniq`;
|
||||
print $list;
|
||||
|
||||
# For now we dont take Require-Bundle AND Import-Package in account
|
||||
#print $list;
|
||||
}
|
||||
|
||||
sub parseReqString {
|
||||
my $reqstr = $_[0];
|
||||
sub parsePkgString {
|
||||
my $bunstr = $_[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;
|
||||
$bunstr =~ s/ //g;
|
||||
$bunstr =~ s/\n//g;
|
||||
$bunstr =~ s/[^[:print:]]//g;
|
||||
$bunstr =~ s/("[[:alnum:]|\-|\_|\.|\(|\)|\[|\]]+)(,)([[:alnum:]|\-|\_|\.|\(|\)|\[|\]]+")/$1 $3/g;
|
||||
@reqcomp = split /,/g, $bunstr;
|
||||
foreach $reqelement (@reqcomp) {
|
||||
@reqelementfrmnt = split /;/g, $reqelement;
|
||||
$name="";
|
||||
|
@ -142,6 +170,9 @@ sub parseReqString {
|
|||
}
|
||||
}
|
||||
$version = parseVersion($version);
|
||||
$version = fixVersion($version);
|
||||
# dirty fix for provides that contain " char
|
||||
$name =~ s/\"//g;
|
||||
push @return, { NAME=>"$name", VERSION=>"$version"};
|
||||
}
|
||||
|
||||
|
@ -152,10 +183,21 @@ sub parseVersion {
|
|||
my $ver = $_[0];
|
||||
if ($ver eq "") { return "";}
|
||||
if ($ver =~ m/(^[\[|\(])(.+)\ (.+)([\]|\)]$)/) {
|
||||
($1 eq "\[") ? return " <= $2" : return " < $2";
|
||||
# FIXME: The right rpm match of osgi version [1,2) seems to be <= 2
|
||||
# but when you look at the requires >= look more permssive/correct?
|
||||
($1 eq "\[") ? return " >= $2" : return " > $2";
|
||||
} else {
|
||||
return " = $ver";
|
||||
}
|
||||
return $ver;
|
||||
}
|
||||
|
||||
sub fixVersion {
|
||||
my $version = $_[0];
|
||||
# remove version qualifier.
|
||||
$version =~ s/\.v.[0-9]*.*//g;
|
||||
# We try to match RPM version, so remove last .0
|
||||
$version =~ s/\.0$//g;
|
||||
return $version;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue