Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c7dfe86 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Make dump-jar filtering faster

Filtering was too slow on a big jar file.

Flag: EXEMPT host side test change only
Bug: 292141694
Test: manual
Change-Id: I5ff56f158976fe6661151e2a0aa80e837c840d59
parent 9302f849
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ shift $(($OPTIND - 1))


# Build the dump files, which are the input of this test.
run m tiny-framework-dump-test
run m  dump-jar tiny-framework-dump-test


# Get the path to the generate text files. (not the golden files.)
+12 −20
Original line number Diff line number Diff line
@@ -26,12 +26,12 @@ help() {

        Dump a *.class file

      dump-jar [-v] [-s] [-o OUTPUT-FILENAME] JAR-FILE[: filename regex] [...]
      dump-jar [-v] [-s] [-o OUTPUT-FILENAME] JAR-FILE[: class internal name regex] [...]

        Dump a jar file.

        If a filename contains a ':', then the following part
        will be used to filter files in the jar file.
        will be used to filter files in the jar file that matches against class internal names.

        For example, "file.jar:/MyClass$" will only dump "MyClass" in file.jar.

@@ -78,16 +78,6 @@ if (( $simple )) ; then
  JAVAP_OPTS="-p -c -v"
fi


# Normalize a java class name.
# Convert '.' to '/'
# Remove the *.class suffix.
normalize() {
  local name="$1"
  name="${name%.class}" # Remove the .class suffix.
  echo "$name" | tr '.' '/'
}

# Convert the output for `-s` as needed.
filter_output() {
  if (( $simple )) ; then
@@ -124,6 +114,12 @@ write_to_out() {
  fi
}

# Read jar file names and remove the .class suffix.
# Also remove non-class files.
to_internal_names() {
    sed -ne 's/\.class$//p'
}

for file in "${@}"; do

    # *.class?
@@ -136,7 +132,7 @@ for file in "${@}"; do
        # Take the regex. Remove everything up to : in $file
        regex=""
        if [[ "$file" =~ : ]] ; then
            regex="$(normalize "${file##*:}")"
            regex="${file##*:}"
        fi

        # Remove everything after ':', inclusively, in $file.
@@ -151,13 +147,9 @@ for file in "${@}"; do
          echo
        fi

        jar tf "$file" | grep '\.class$' | sort | while read -r class ; do
            if normalize "$class" | grep -q -- "$regex" ; then
                echo "## Class: $class"
                javap $dump_code_opt $JAVAP_OPTS -cp $file ${class%.class}
            else
                (( $verbose )) && echo "## Skipping class: $class"
            fi
        jar tf "$file" | sort | to_internal_names | grep -- "$regex" | while read -r class ; do
            echo "## Class: $class.class"
            javap $dump_code_opt $JAVAP_OPTS -cp "$file" "${class}"
        done

    else