github.com/apache/beam/sdks/v2@v2.48.2/java/container/license_scripts/license_script.sh (about)

     1   # Licensed to the Apache Software Foundation (ASF) under one
     2   # or more contributor license agreements.  See the NOTICE file
     3   # distributed with this work for additional information
     4   # regarding copyright ownership.  The ASF licenses this file
     5   # to you under the Apache License, Version 2.0 (the
     6   # License); you may not use this file except in compliance
     7   # with the License.  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  set -e
    18  
    19  # Get currently used Python version from Gradle or assume a default.
    20  PYTHON=${1:-python3}
    21  SCRIPT_DIR="${PWD}/license_scripts"
    22  ENV_DIR="${PWD}/build/virtualenv"
    23  
    24  # This file must already exist before this helper script is run.
    25  # It is created by :sdks:java:container:generateLicenseReport
    26  INDEX_FILE="${PWD}/build/reports/dependency-license/index.json"
    27  
    28  # The licenses already pulled by generateDependencyReport are alongside index.json.
    29  # The script first copies those over.
    30  EXISTING_LICENSE_DIR="${PWD}/build/reports/dependency-license"
    31  
    32  # The python will download Java licenses here
    33  DOWNLOAD_DIR="${PWD}/build/target/java_third_party_licenses"
    34  
    35  # All licenses will be put here by this script
    36  DEST_DIR="${PWD}/build/target/third_party_licenses"
    37  
    38  echo "Copying already-fetched licenses from ${EXISTING_LICENSE_DIR} to ${DOWNLOAD_DIR}"
    39  if [ -d "$DOWNLOAD_DIR" ]; then rm -rf "$DOWNLOAD_DIR" ; fi
    40  mkdir -p "$DOWNLOAD_DIR"
    41  cp -r "${EXISTING_LICENSE_DIR}"/*.jar "${DOWNLOAD_DIR}"
    42  
    43  $PYTHON -m venv --clear ${ENV_DIR} && . ${ENV_DIR}/bin/activate
    44  pip install --retries 10 --upgrade pip setuptools wheel
    45  
    46  # install packages
    47  pip install --retries 10 -r ${SCRIPT_DIR}/requirement.txt
    48  
    49  # pull licenses, notices and source code
    50  FLAGS="--license_index=${INDEX_FILE} \
    51         --output_dir=${DOWNLOAD_DIR} \
    52         --dep_url_yaml=${SCRIPT_DIR}/dep_urls_java.yaml \
    53         --manual_license_path=${SCRIPT_DIR}/manual_licenses"
    54  
    55  echo "Executing python ${SCRIPT_DIR}/pull_licenses_java.py $FLAGS"
    56  python "${SCRIPT_DIR}/pull_licenses_java.py" $FLAGS
    57  
    58  # If this script is running, it is assumed that outputs are out of date and should be cleared and rewritten
    59  if [ -d "$DEST_DIR" ]; then rm -rf "$DEST_DIR"; fi
    60  mkdir -p "$DEST_DIR"
    61  
    62  echo "Copying licenses from ${DOWNLOAD_DIR} to ${DEST_DIR}."
    63  cp -r "$DOWNLOAD_DIR"/*.jar "$DEST_DIR"/
    64  cp -r "$DOWNLOAD_DIR"/*.csv "$DEST_DIR"/
    65  gzip -r "$DEST_DIR"/*
    66  
    67  echo "Finished license_scripts.sh"