Skip to content
Snippets Groups Projects
osx-setup 3.16 KiB
Newer Older
  • Learn to ignore specific revisions
  • #! /usr/bin/env perl -I./bin
    
    
    use strict;
    use warnings;
    
    use Cwd 'getcwd';
    use File::Copy 'copy';
    use File::Copy::Recursive 'rcopy';
    use File::Find 'find';
    use File::Path 'remove_tree';
    use String::Util 'trim';
    
    use Metabase::Util;
    
    use constant JRE_DEST => getcwd() . '/OSX/Metabase/jre';
    use constant JRE_HOME => trim(`/usr/libexec/java_home`) . '/jre';
    
    
    use constant UBERJAR_SRC => getcwd() . '/target/uberjar/metabase.jar';
    
    use constant UBERJAR_DEST => getcwd() . '/OSX/Resources/metabase.jar';
    
    
    use constant RESET_PW_SRC => getcwd() . '/reset-password-artifacts/reset-password/reset-password.jar';
    use constant RESET_PW_DEST => getcwd() . '/OSX/Resources/reset-password.jar';
    
    
    use constant ENABLE_JAR_PACKING => 0;
    
    use constant ENABLE_JAR_OPTIONAL_FILE_STRIPPING => 0;
    
    
    sub remove_jre_optional_files {
        my @optional_files = ('bin/keytool',
                              'bin/orbd',
                              'bin/policytool',
                              'bin/rmid',
                              'bin/rmiregistry',
                              'bin/servertool',
                              'bin/tnameserv',
                              'lib/cmm/PYCC.pf',
                              'lib/deploy.jar',
                              'lib/ext',
                              'lib/fonts',
                              'lib/javaws.jar',
                              'lib/jfr',
                              'lib/jfr.jar',
                              'lib/libglass.dylib',
                              'lib/libglib-lite.dylib',
                              'lib/libgstreamer-lite.dylib',
                              'lib/libjavafx_font_t2k.dylib',
                              'lib/libjfxmedia.dylib',
                              'lib/libjfxwebkit.dylib',
                              'lib/libprism_common.dylib',
                              'lib/libprism_sw.dylib',
                              'lib/plugin.jar',
                              'lib/javafx.properties',
                              'lib/jfxswt.jar'
            );
        for my $file (@optional_files) {
            $file = JRE_DEST . '/' . $file;
            remove_tree($file) if -e $file;
        }
    }
    
    # Finds all the .jar files in JRE_DEST and replaces them with packed .pack.gz files.
    sub pack_jre_jars {
        sub pack_jar {
            if (/\.jar$/) {
                s/(^.*)\.jar$/$1/; # stip off extension
                print "Packing $_.jar...\n";
                system('pack200', '--gzip', '--strip-debug', '--effort=9', $_ . '.pack.gz', $_ . '.jar') == 0 or die $!;
                remove_tree($_ . '.jar');
            }
        }
        find(\&pack_jar, JRE_DEST . '/lib');
    }
    
    # Copy the JRE if needed
    (rcopy(JRE_HOME, JRE_DEST) or die $!) unless -d JRE_DEST;
    
    # Remove optional files from JRE dest
    
    remove_jre_optional_files() if ENABLE_JAR_OPTIONAL_FILE_STRIPPING;
    
    
    # Pack JARs in JRE if applicable
    pack_jar() if ENABLE_JAR_PACKING;
    
    
    # Build jars if needed
    
    (system('./bin/build') or die $!) unless -f UBERJAR_SRC;
    
    (system('lein', 'with-profile', 'reset-password', 'jar') or die $!) unless -f RESET_PW_SRC;
    
    # Copy jars over
    sub copy_jar {
      my ($src, $dest) = @_;
      announce 'Copying jar ' . $src . ' -> ' . $dest;
      copy(get_file_or_die($src), $dest) or die $!;
    }
    copy_jar(UBERJAR_SRC, UBERJAR_DEST);
    copy_jar(RESET_PW_SRC, RESET_PW_DEST);
    
    
    print_giant_success_banner();