kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/release/maven_extractor.sh (about)

     1  #!/bin/bash -e
     2  
     3  # Copyright 2014 The Kythe Authors. All rights reserved.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #   http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  # kzip compilation extractor for Maven builds. For exclusive use within the
    18  # google/kythe Docker container. The assumed repository root is /repo and
    19  # /compilations/java will be used as the .kzip file output directory.
    20  #
    21  # usage: maven_extractor.sh
    22  
    23  export KYTHE_ROOT_DIRECTORY=/repo
    24  cd "$KYTHE_ROOT_DIRECTORY"
    25  
    26  export KYTHE_OUTPUT_DIRECTORY=/compilations/java
    27  mkdir -p "$KYTHE_OUTPUT_DIRECTORY"
    28  
    29  mvn_print() {
    30    mvn help:evaluate -Dexpression="$1" | grep -Ev '^(\[|Download)' | xargs echo -n
    31  }
    32  mvn help:evaluate </dev/null # ensure plugin is loaded
    33  
    34  group="$(mvn_print project.groupId)"
    35  artifact="$(mvn_print project.artifactId)"
    36  export KYTHE_CORPUS="$group-$artifact"
    37  if [[ "$KYTHE_CORPUS" = "-" ]]; then
    38    export KYTHE_CORPUS=maven
    39  fi
    40  
    41  echo "Extracting $KYTHE_CORPUS" >&2
    42  
    43  CP="$(mktemp)"
    44  trap 'rm -f "$CP"' EXIT
    45  
    46  mvn process-sources dependency:build-classpath -Dmdep.outputFile="$CP"
    47  if [[ ! -s "$CP" ]]; then
    48    # Empty Maven classpath; fix up for the javac @ argument below
    49    echo > "$CP"
    50  fi
    51  
    52  readarray -t SRCS < <(find . -name '*.java')
    53  
    54  java -jar /kythe/bin/javac_extractor_deploy.jar -cp "@$CP" "${SRCS[@]}"