DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
#use strict;
use File::Find;
use File::Compare;
use File::Basename;
use File::stat;
use File::Copy;

@excluded_sources = qw(
provider\.new/
org/mozilla/jss/provider/java/security/KeyFactorySpi1_4\.java
org/mozilla/jss/pkix/cert/X509Certificate\.java
samples/
);

@javah_classes = qw(
org.mozilla.jss.DatabaseCloser        
org.mozilla.jss.CryptoManager          
org.mozilla.jss.crypto.Algorithm        
org.mozilla.jss.crypto.EncryptionAlgorithm      
org.mozilla.jss.crypto.PQGParams     
org.mozilla.jss.crypto.SecretDecoderRing
org.mozilla.jss.pkcs11.CertProxy        
org.mozilla.jss.pkcs11.CipherContextProxy 
org.mozilla.jss.pkcs11.PK11Module 
org.mozilla.jss.pkcs11.ModuleProxy 
org.mozilla.jss.pkcs11.PK11Cert     
org.mozilla.jss.pkcs11.PK11Cipher     
org.mozilla.jss.pkcs11.PK11KeyWrapper  
org.mozilla.jss.pkcs11.PK11MessageDigest 
org.mozilla.jss.pkcs11.PK11PrivKey   
org.mozilla.jss.pkcs11.PK11PubKey     
org.mozilla.jss.pkcs11.PK11SymKey      
org.mozilla.jss.pkcs11.PK11KeyPairGenerator 
org.mozilla.jss.pkcs11.PK11KeyGenerator
org.mozilla.jss.pkcs11.PK11Token
org.mozilla.jss.pkcs11.PrivateKeyProxy  
org.mozilla.jss.pkcs11.PublicKeyProxy    
org.mozilla.jss.pkcs11.SymKeyProxy
org.mozilla.jss.pkcs11.KeyProxy    
org.mozilla.jss.pkcs11.PK11Token    
org.mozilla.jss.pkcs11.TokenProxy    
org.mozilla.jss.pkcs11.PK11Signature  
org.mozilla.jss.pkcs11.PK11Store       
org.mozilla.jss.pkcs11.PK11KeyPairGenerator 
org.mozilla.jss.pkcs11.SigContextProxy
org.mozilla.jss.pkcs11.PK11RSAPublicKey
org.mozilla.jss.pkcs11.PK11DSAPublicKey
org.mozilla.jss.pkcs11.PK11ECPublicKey
org.mozilla.jss.pkcs11.PK11SecureRandom 
org.mozilla.jss.provider.java.security.JSSKeyStoreSpi
org.mozilla.jss.SecretDecoderRing.KeyManager
org.mozilla.jss.ssl.SSLSocket 
org.mozilla.jss.ssl.SSLServerSocket 
org.mozilla.jss.ssl.SocketBase 
org.mozilla.jss.util.Debug
org.mozilla.jss.util.Password       
);

@packages = qw(
org.mozilla.jss
org.mozilla.jss.asn1
org.mozilla.jss.crypto
org.mozilla.jss.pkcs7
org.mozilla.jss.pkcs10
org.mozilla.jss.pkcs11
org.mozilla.jss.pkcs12
org.mozilla.jss.pkix.primitive
org.mozilla.jss.pkix.cert
org.mozilla.jss.pkix.cmc
org.mozilla.jss.pkix.cmmf
org.mozilla.jss.pkix.cms
org.mozilla.jss.pkix.crmf
org.mozilla.jss.provider.java.security
org.mozilla.jss.provider.javax.crypto
org.mozilla.jss.SecretDecoderRing
org.mozilla.jss.ssl
org.mozilla.jss.tests
org.mozilla.jss.util
);


# setup variables
setup_vars(\@ARGV);

# run the command with its arguments
my $cmd = (shift || "build");   # first argument is command
grep { s/(.*)/"$1"/ } @ARGV;    # enclose remaining arguments in quotes
my $args = join(",",@ARGV);     # and comma-separate them
eval "$cmd($args)";             # now run the command
if( $@ ) {
    die $@;                     # errors in eval will be put in $@
}

# END

sub grab_cmdline_vars {
    my $argv = shift;

    while( $$argv[0] =~ /(.+)=(.*)/ ) {
        $cmdline_vars{$1} = $2;
        shift @$argv;
    }
}

sub dump_cmdline_vars {
    print "Command variables:\n";
    for(keys %cmdline_vars) {
        print "$_=" . $cmdline_vars{$_} . "\n";
    }
}

sub setup_vars {
    my $argv = shift;

    grab_cmdline_vars($argv);
    dump_cmdline_vars();

    $ENV{JAVA_HOME} or die "Must specify JAVA_HOME environment variable";
    $jar = "$ENV{JAVA_HOME}/bin/jar";
    $javac = "$ENV{JAVA_HOME}/bin/javac";
    $javah = "$ENV{JAVA_HOME}/bin/javah";
    $javadoc = "$ENV{JAVA_HOME}/bin/javadoc";

    $dist_dir = $cmdline_vars{SOURCE_PREFIX};
    $jce_jar = $ENV{JCE_JAR};

    $class_release_dir = $cmdline_vars{SOURCE_RELEASE_PREFIX};
    if( $ENV{BUILD_OPT} ) {
        $class_dir = "$dist_dir/classes";
        $class_jar = "$dist_dir/$cmdline_vars{XPCLASS_JAR}";
        $class_release_dir .= "/$cmdline_vars{SOURCE_RELEASE_CLASSES_DIR}";
        $javac_opt_flag = "-O";
        $debug_source_file = "org/mozilla/jss/util/Debug_ship.jnot";
    } else {
        $class_dir = "$dist_dir/classes_DBG";
        $class_jar = "$dist_dir/$cmdline_vars{XPCLASS_DBG_JAR}";
        $class_release_dir .= "/$cmdline_vars{SOURCE_RELEASE_CLASSES_DBG_DIR}";
        $javac_opt_flag = "-g";
        $debug_source_file = "org/mozilla/jss/util/Debug_debug.jnot";
    }
    $jni_header_dir = "$dist_dir/private/jss/_jni";

    if( $jce_jar ) {
        $classpath = "-classpath $jce_jar";
    }
}

sub clean {
    print_do("rm -rf $class_dir");
    print_do("rm -f $class_jar");
    print_do("rm -rf $jni_header_dir");
}

sub build {

    #
    # copy the appropriate debug file
    #
    my $debug_target_file = "org/mozilla/jss/util/Debug.java";
    if( compare($debug_source_file, $debug_target_file) ) {
        copy($debug_source_file, $debug_target_file) or die "Copying file: $!";
    }

    #
    # generate manifest.mf file in lib dir
    #
    my $manifest_file   = "MANIFEST.MF";
    my $jss_revision   = `grep JSS_VERSION org/mozilla/jss/util/jssver.h`;
    chop($jss_revision);
    $jss_revision      = substr($jss_revision, 22, 3);
    my $build_revision = $jss_revision;
    $append = 0;

    if ($append) {
        open(MYOUTFILE, ">MANIFEST.MF");  #open for write, overwrite
    } else {
        open(MYOUTFILE, ">>MANIFEST.MF"); #open for write, append
    }

    #*** Print freeform text, semicolon required ***
print MYOUTFILE <<"MyLabel";
Manifest-Version: 1.0
    
Name: org/mozilla/jss/
Specification-Title: Network Security Services for Java (JSS)
Specification-Version: $jss_revision
Specification-Vendor: Mozilla Foundation
Implementation-Title: org.mozilla.jss
Implementation-Version: $build_revision
Implementation-Vendor: Mozilla Foundation
MyLabel

    #*** Close the file ***
    close(MYOUTFILE);

    #
    # recursively find *.java
    #
    my %source_list;
    find sub {
        my $name = $File::Find::name;
        if( $name =~ /\.java$/) { 
            $source_list{$File::Find::name} = 1;
        }
    }, ".";

    #
    # weed out files that are excluded or don't need to be updated
    #
    my $file;
    foreach $file (keys %source_list) {
        my $pattern;
        foreach $pattern (@excluded_sources) {
            if( $file =~ /$pattern/ ) {
                delete $source_list{$file};
            }
        }
        unless( java_source_needs_update( $file, $class_dir ) ){
            delete $source_list{$file};
        }
    }
    my @source_list = keys(%source_list);

    #
    # build the java sources
    #
    if( scalar(@source_list) > 0 ) {
        ensure_dir_exists($class_dir);
        print_do("$javac $javac_opt_flag -sourcepath . -d $class_dir " .
            "$classpath " . join(" ",@source_list));
        print_do("sh -c 'pwd && cd $class_dir && pwd && rm -f $class_jar && pwd && ls -al && ls -al ../../dist && $jar -cvmf ../../security/jss/$manifest_file $class_jar *'");
        print_do("rm -f $manifest_file");
        print "Exit status was " . ($?>>8) . "\n";
    }

    #
    # create the JNI header files
    #
    ensure_dir_exists($jni_header_dir);
    print_do("$javah -classpath $class_dir -d $jni_header_dir " .
        (join " ", @javah_classes) );
}

sub print_do {
    my $cmd = shift;
    print "$cmd\n";
    system($cmd);
    my $exit_status = $?>>8;
    $exit_status and die "Command failed ($exit_status)\n";
}

sub needs_update {
    my $target = shift;
    my @dependencies = @_;

    my $target_mtime = (stat($target))[9];
    my $dep;
    foreach $dep( @dependencies ) {
        my $dep_mtime = (stat($dep))[9];
        if( $dep_mtime > $target_mtime ) {
            return 1;
        }
    }
    return 0;
}

# A quick-and-dirty way to guess whether a .java file needs to be rebuilt.
# We merely look for a .class file of the same name. This won't work if
# the source file's directory is different from its package, and it
# doesn't know about nested or inner classes.
# source_file: the relative path to the source file ("org/mozilla/jss/...")
# dest_dir: the directory where classes are output ("../../dist/classes_DBG")
# Returns 1 if the source file is newer than the class file, or the class file
#   doesn't exist. Returns 0 if the class file is newer than the source file.
sub java_source_needs_update {
    my $source_file = shift;
    my $dest_dir = shift;

    my $class_dir = "$dest_dir/" . dirname($source_file);
    my $class_file = basename($source_file);
    $class_file =~ s/\.java/.class/;
    $class_file = $class_dir . "/" . $class_file;
    if( -f $class_file ) {
        my $class_stat = stat($class_file);
        my $source_stat = stat($source_file);

        if( $source_stat->mtime > $class_stat->mtime) {
            # class file exists and is out of date
            return 1;
        } else {
            #class file exists and is up to date
            return 0;
        }
    } else {
        # class file hasn't been generated yet.
        return 1;
    }
}

# Recursively makes the given directory. Dies at the first sign of trouble
sub ensure_dir_exists {
    my $dir = shift;
    my $parent = dirname($dir);
    if( $parent ne $dir ) {
        ensure_dir_exists($parent);
    }
    if( ! -d $dir ) {
        mkdir($dir, 0777) or die "Failed to mkdir $dir: $!";
    }
}

sub release {
    # copy all class files into release directory
    ensure_dir_exists("$class_release_dir");
    print_do("cp -r $class_dir/* $class_release_dir");
}

sub javadoc {
    my $html_header_opt;
    if( $ENV{HTML_HEADER} ) {
        $html_header_opt = "-header '$ENV{HTML_HEADER}'";
    }
    ensure_dir_exists("$dist_dir/jssdoc");
    my $targets = join(" ", @packages);
    print "$targets\n";
    print_do("$javadoc -breakiterator -sourcepath . -d $dist_dir/jssdoc $html_header_opt $targets");
    print_do("cp $dist_dir/jssdoc/index.html $dist_dir/jssdoc/index.html.bak");
    print_do("cp $dist_dir/jssdoc/overview-summary.html $dist_dir/jssdoc/index.html");
}