kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/docs/schema/example-java.sh (about)

     1  #!/bin/bash -e
     2  set -o pipefail
     3  
     4  # Copyright 2014 The Kythe Authors. All rights reserved.
     5  #
     6  # Licensed under the Apache License, Version 2.0 (the "License");
     7  # you may not use this file except in compliance with the License.
     8  # You may obtain a copy of the License at
     9  #
    10  #   http://www.apache.org/licenses/LICENSE-2.0
    11  #
    12  # Unless required by applicable law or agreed to in writing, software
    13  # distributed under the License is distributed on an "AS IS" BASIS,
    14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  # See the License for the specific language governing permissions and
    16  # limitations under the License.
    17  
    18  # This script verifies and formats a single Kythe example, which is expected
    19  # to be piped in on standard input from example.sh.
    20  #
    21  # The script assumes its working directory is the schema output directory and
    22  # requires the following environment variables:
    23  #   TMP
    24  #   LANGUAGE
    25  #   LABEL
    26  #   JAVA_INDEXER_BIN
    27  #   VERIFIER_BIN
    28  #   VERIFIER_ARGS
    29  #   SHASUM_TOOL
    30  #   SHOWGRAPH
    31  #
    32  # TODO(zarko): Provide alternate templates to avoid unnecessary boilerplate
    33  # (eg, text within class scope, text within method scope, ...).
    34  
    35  # Save the Java source example
    36  TEST_FILE="$TMP/E.java"
    37  tee "$TEST_FILE.orig" > "$TEST_FILE"
    38  FILE_SHA=$($SHASUM_TOOL "${TEST_FILE}.orig" | cut -c 1-64)
    39  
    40  if ! env \
    41    KYTHE_OUTPUT_FILE="${TEST_FILE}.kzip" \
    42    KYTHE_ROOT_DIRECTORY="$PWD" \
    43    "$JAVA_EXTRACTOR_BIN" "$TEST_FILE"; then
    44    error EXTRACT
    45  fi
    46  
    47  # Index the file.
    48  if ! "$JAVA_INDEXER_BIN" "${TEST_FILE}.kzip" >"${TEST_FILE}.entries"; then
    49    error INDEX
    50  fi
    51  
    52  # Verify the index.
    53  if ! "$VERIFIER_BIN" "${VERIFIER_ARGS}" --ignore_dups "${TEST_FILE}.orig" <"${TEST_FILE}.entries"; then
    54    error VERIFY
    55  fi
    56  
    57  # Format the output.
    58  trap 'error FORMAT' ERR
    59  
    60  echo "<div><h5 id=\"_${LABEL}\">${LABEL}"
    61  
    62  if [[ "${SHOWGRAPH}" == 1 ]]; then
    63    "$VERIFIER_BIN" --ignore_dups --graphviz >"$TMP/${FILE_SHA}.dot" <"${TEST_FILE}.entries"
    64    dot -Tsvg -o "${FILE_SHA}.svg" "$TMP/${FILE_SHA}.dot"
    65    echo "(<a href=\"${FILE_SHA}.svg\" target=\"_blank\">${LANGUAGE}</a>)</h5>"
    66  else
    67    echo " (${LANGUAGE})</h5>"
    68  fi
    69  
    70  source-highlight --failsafe --output=STDOUT --src-lang java -i "${TEST_FILE}.orig"
    71  echo "</div>"