Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Perl-Sensitive Sunglasses
 
PerlMonks  

jdiff - jar/java diff

by vladb (Vicar)
on Mar 04, 2004 at 21:51 UTC ( #334045=sourcecode: print w/ replies, xml ) Need Help??

Category: Utility Scripts
Author/Contact Info Vladimir Bogdanov (contact at vladb.com)
Description: Compares java classes in a set of jar files and prints out a straightforward inconsistency report. The report shows missing and modified files for each jar file.
#!/usr/bin/perl
# author: Vladimir Bogdanov (vladb)
# date:   2004-03
# Compares java classes in a set of jar files and
# prints out a straightforward inconsistency report.

use Getopt::Long;
use Data::Dumper;
use strict;

##---------------------------------------------
## CONFIG
##---------------------------------------------
@cfg::options = ("help|h","m");
$cfg::unzip = "/usr/5bin/unzip";

##---------------------------------------------
## MAIN
##---------------------------------------------
my %opts;
GetOptions(\%opts, @cfg::options);
help() if ($opts{help});

my @jars = @ARGV;
my (%jar_files, %jar_classes, $cmd, $out);

for my $jar (@jars) {
  $cmd = "$cfg::unzip -l $jar";

  my $pid = open(CMD, "-|");
  unless ($pid) {
    exec($cmd) || die "can't exec program: $!";
  }

  while (<CMD>) {
    if (/(\d+)[\t\s]+([\d-]+)[\t\s]+([\d:]+)[\t\s+]+((.*?)\.class)/) {
      my $d = [$1, $2, $3];
      $jar_files{$jar}{$4} = $d;
      $jar_classes{$4}{$jar} = $d;
    }
  }
  close(CMD) || warn "failed to close CMD: $?";  
}

for my $c (keys %jar_classes) {
  my ($info, $size, $osize, $mod);  
  for my $j (@jars) {
    if (exists $jar_classes{$c}{$j}) {
      $size = $jar_classes{$c}{$j}->[0];  
      $osize = $size unless (defined $osize); 
      $mod = 1 if ($size != $osize);
        
      $info .= "   $j    \t" . join("\t", @{$jar_classes{$c}{$j}}) . "
+\n";      
    } else {
      $mod = 1;
      $info .= "   $j    \tMISSING\n";
    }
  }

  
  if ($opts{m}) {
    next unless $mod;
    $mod = "";
  } else {
    $mod = "***  " if ($mod);
  }

  print "$mod$c:\n";
  print "$info\n";
}


##---------------------------------------------
## SUBROUTINES
##---------------------------------------------
sub help 
{
  print qq~
jardiff [help] <jarfile1> <jarfile2>

  Compares contents of two jar files.    

EXAMPLES:

  Show modified files only 

  jardiff -m j.jar j1.jar

~;
  exit;
}

Comment on jdiff - jar/java diff
Download Code
Re: jdiff - jar/java diff
by esskar (Deacon) on Mar 04, 2004 at 21:54 UTC

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://334045]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-04-19 18:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls