From a5a6c618eea5ad1e60ace1b12a0355a03bc34c99 Mon Sep 17 00:00:00 2001
From: Zoe Wang <33073555+zoewangg@users.noreply.github.com>
Date: Fri, 16 May 2025 13:52:39 -0700
Subject: [PATCH 1/3] Add a script to set up new module
---
scripts/setup-new-module | 352 +++++++++++++++++++++++++++++++++++++++
1 file changed, 352 insertions(+)
create mode 100755 scripts/setup-new-module
diff --git a/scripts/setup-new-module b/scripts/setup-new-module
new file mode 100755
index 000000000000..b767d9ff6330
--- /dev/null
+++ b/scripts/setup-new-module
@@ -0,0 +1,352 @@
+#!/bin/bash
+
+# setup-new-module - Script to set up a new module in the AWS SDK for Java v2
+# Usage: ./scripts/setup-new-module -n module-name [-t] [-p parent-dir]
+# Options:
+# -n module-name: Name of the new module (required)
+# -t: Set up as a test module (optional, default: false)
+# -p parent-dir: Parent directory for the module (optional, default: root project directory for regular modules, test directory for test modules)
+# -h: Show help
+
+set -e
+
+# Get the root project directory
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
+
+# Default values
+IS_TEST_MODULE=false
+PARENT_DIR=""
+MODULE_NAME=""
+
+# Parse command line arguments
+while getopts "n:tp:h" opt; do
+ case ${opt} in
+ n)
+ MODULE_NAME=$OPTARG
+ ;;
+ t)
+ IS_TEST_MODULE=true
+ ;;
+ p)
+ PARENT_DIR=$OPTARG
+ ;;
+ h)
+ echo "Usage: $0 -n module-name [-t] [-p parent-dir]"
+ echo "Options:"
+ echo " -n module-name: Name of the new module (required)"
+ echo " -t: Set up as a test module (optional, default: false)"
+ echo " -p parent-dir: Parent directory for the module (optional, default: root project directory for regular modules, test directory for test modules)"
+ echo " -h: Show help"
+ exit 0
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG" >&2
+ exit 1
+ ;;
+ esac
+done
+
+# Check if module name is provided
+if [ -z "$MODULE_NAME" ]; then
+ echo "Error: Module name is required. Use -n option to specify the module name."
+ exit 1
+fi
+
+# Set default parent directory based on module type
+if [ -z "$PARENT_DIR" ]; then
+ if [ "$IS_TEST_MODULE" = true ]; then
+ PARENT_DIR="$ROOT_DIR/test"
+ echo "Setting default parent directory for test module to: $PARENT_DIR"
+ else
+ PARENT_DIR="$ROOT_DIR"
+ fi
+fi
+
+# Create module directory
+MODULE_DIR="$PARENT_DIR/$MODULE_NAME"
+echo "Creating module directory: $MODULE_DIR"
+mkdir -p "$MODULE_DIR"
+mkdir -p "$MODULE_DIR/src/main/java"
+mkdir -p "$MODULE_DIR/src/main/resources"
+mkdir -p "$MODULE_DIR/src/test/java"
+mkdir -p "$MODULE_DIR/src/test/resources"
+
+# Create basic pom.xml
+# Get the current SDK version from the root pom.xml
+SDK_VERSION=$(grep -o "[^<]*" "$ROOT_DIR/pom.xml" | head -1 | sed 's/\(.*\)<\/version>/\1/')
+
+echo "Using SDK version: $SDK_VERSION"
+
+cat > "$MODULE_DIR/pom.xml" << EOF
+
+
+ 4.0.0
+
+ software.amazon.awssdk
+ aws-sdk-java-pom
+ ${SDK_VERSION}
+
+
+ ${MODULE_NAME}
+ AWS Java SDK :: ${MODULE_NAME}
+ AWS SDK for Java - ${MODULE_NAME}
+ https://aws.amazon.com/sdkforjava
+EOF
+
+# Add Automatic-Module-Name for non-test modules
+if [ "$IS_TEST_MODULE" = false ]; then
+ cat >> "$MODULE_DIR/pom.xml" << EOF
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+
+ software.amazon.awssdk.TODO
+
+
+
+
+
+
+EOF
+fi
+
+# Close pom.xml
+cat >> "$MODULE_DIR/pom.xml" << EOF
+
+
+
+
+
+
+EOF
+
+echo "Basic module structure created at $MODULE_DIR"
+
+# Function to add dependency to a pom.xml file
+add_dependency_to_pom() {
+ local pom_file=$1
+ local module_name=$2
+
+ # Check if the file exists
+ if [ ! -f "$pom_file" ]; then
+ echo "Warning: $pom_file does not exist. Skipping."
+ return
+ fi
+
+ # Check if dependency already exists
+ if grep -q "$module_name" "$pom_file"; then
+ echo "Dependency already exists in $pom_file. Skipping."
+ return
+ fi
+
+ # Find the dependencies section and add the new dependency
+ sed -i.bak "//a\\
+ \\
+ software.amazon.awssdk\\
+ $module_name\\
+ \${awsjavasdk.version}\\
+ \\
+" "$pom_file"
+
+ # Remove backup file
+ rm -f "${pom_file}.bak"
+
+ echo "Added dependency to $pom_file"
+}
+
+# Function to update the root pom.xml to include the new module
+update_root_pom() {
+ local root_pom="$ROOT_DIR/pom.xml"
+ local module_name=$1
+
+ # Check if the file exists
+ if [ ! -f "$root_pom" ]; then
+ echo "Warning: $root_pom does not exist. Skipping."
+ return
+ fi
+
+ # Determine the module path based on whether it's a test module
+ local module_path="$module_name"
+ if [ "$IS_TEST_MODULE" = true ]; then
+ module_path="test/$module_name"
+ fi
+
+ # Check if module already exists
+ if grep -q "$module_path" "$root_pom"; then
+ echo "Module already exists in root pom.xml. Skipping."
+ return
+ fi
+
+ # Find the modules section and add the new module
+ sed -i.bak "//a\\
+ $module_path\\
+" "$root_pom"
+
+ # Remove backup file
+ rm -f "${root_pom}.bak"
+
+ echo "Added module to root pom.xml"
+}
+
+# Function to update japicmp plugin config
+update_japicmp_config() {
+ local root_pom="$ROOT_DIR/pom.xml"
+ local module_name=$1
+
+ # Check if the file exists
+ if [ ! -f "$root_pom" ]; then
+ echo "Warning: $root_pom does not exist. Skipping japicmp update."
+ return
+ fi
+
+ # Check if module already exists in japicmp config
+ if grep -q "$module_name" "$root_pom"; then
+ echo "Module already exists in japicmp config. Skipping."
+ return
+ fi
+
+ # Add the module to the includeModules section
+ # Find the last includeModule line and add the new module after it
+ sed -i.bak "/<\/includeModules>/i\\
+ $module_name\\
+" "$root_pom"
+
+ # Remove backup file
+ rm -f "${root_pom}.bak"
+
+ echo "Added $module_name to japicmp plugin configuration in $root_pom"
+}
+
+# Function to update .brazil.json
+update_brazil_json() {
+ local brazil_json="$ROOT_DIR/.brazil.json"
+ local module_name=$1
+ local is_test=$2
+
+ # Check if the file exists
+ if [ ! -f "$brazil_json" ]; then
+ echo "Warning: $brazil_json does not exist. Skipping."
+ return
+ fi
+
+ # Check if module already exists in .brazil.json
+ if grep -q "\"$module_name\":" "$brazil_json"; then
+ echo "Module already exists in .brazil.json. Skipping."
+ return
+ fi
+
+ if [ "$is_test" = true ]; then
+ # Find a specific test module entry to anchor our insertion
+ # Using a specific entry (s3-tests) as an anchor point to avoid multiple insertions
+ sed -i.bak "/\"s3-tests\": {\"skipImport\": true}/i\\
+ \"$module_name\": { \"skipImport\": true },\\
+" "$brazil_json"
+
+ echo "Added $module_name to .brazil.json with skipImport: true"
+ else
+ # Find a specific non-test module entry to anchor our insertion
+ # Using the first module entry as an anchor point
+ sed -i.bak "/\"annotations\": { \"packageName\": /i\\
+ \"$module_name\": { \"packageName\": \"TODO\" },\\
+" "$brazil_json"
+
+ echo "Added $module_name to .brazil.json with packageName: TODO"
+ fi
+
+ # Remove backup file
+ rm -f "${brazil_json}.bak"
+}
+
+# Function to update buildspec files for test modules
+update_buildspecs() {
+ local module_name=$1
+ local release_maven="$ROOT_DIR/buildspecs/release-to-maven.yml"
+ local release_javadoc="$ROOT_DIR/buildspecs/release-javadoc.yml"
+
+ # Check if files exist
+ if [ ! -f "$release_maven" ]; then
+ echo "Warning: $release_maven does not exist. Skipping."
+ else
+ # Update MODULES_TO_SKIP in release-to-maven.yml
+ if grep -q "MODULES_TO_SKIP=" "$release_maven"; then
+ # Extract current value
+ current_modules=$(grep "MODULES_TO_SKIP=" "$release_maven" | cut -d'"' -f2)
+ # Add new module to skip
+ new_modules="$current_modules,$module_name"
+ # Update the file
+ sed -i.bak "s/MODULES_TO_SKIP=\"$current_modules\"/MODULES_TO_SKIP=\"$new_modules\"/" "$release_maven"
+ rm -f "${release_maven}.bak"
+ echo "Updated MODULES_TO_SKIP in $release_maven to include $module_name"
+ else
+ echo "MODULES_TO_SKIP variable not found in $release_maven. Please manually update."
+ fi
+ fi
+
+ if [ ! -f "$release_javadoc" ]; then
+ echo "Warning: $release_javadoc does not exist. Skipping."
+ else
+ # Update MODULES_TO_SKIP in release-javadoc.yml
+ if grep -q "MODULES_TO_SKIP=" "$release_javadoc"; then
+ # Extract current value
+ current_modules=$(grep "MODULES_TO_SKIP=" "$release_javadoc" | cut -d'"' -f2)
+ # Add new module to skip
+ new_modules="$current_modules,$module_name"
+ # Update the file
+ sed -i.bak "s/MODULES_TO_SKIP=\"$current_modules\"/MODULES_TO_SKIP=\"$new_modules\"/" "$release_javadoc"
+ rm -f "${release_javadoc}.bak"
+ echo "Updated MODULES_TO_SKIP in $release_javadoc to include $module_name"
+ else
+ echo "MODULES_TO_SKIP variable not found in $release_javadoc. Please manually update."
+ fi
+ fi
+}
+
+# Perform updates based on module type
+if [ "$IS_TEST_MODULE" = false ]; then
+ echo "Performing non-test module updates..."
+
+ # Add to tests-coverage-reporting pom.xml
+ add_dependency_to_pom "$ROOT_DIR/test/tests-coverage-reporting/pom.xml" "$MODULE_NAME"
+
+ # Add to aws-sdk-java pom.xml
+ add_dependency_to_pom "$ROOT_DIR/aws-sdk-java/pom.xml" "$MODULE_NAME"
+
+ # Add to architecture-tests pom.xml
+ add_dependency_to_pom "$ROOT_DIR/test/architecture-tests/pom.xml" "$MODULE_NAME"
+
+ # Add to bom pom.xml
+ add_dependency_to_pom "$ROOT_DIR/bom/pom.xml" "$MODULE_NAME"
+
+ # Update japicmp plugin config
+ update_japicmp_config "$MODULE_NAME"
+
+ # Update .brazil.json
+ update_brazil_json "$MODULE_NAME" false
+
+ # Update root pom.xml
+ update_root_pom "$MODULE_NAME"
+
+else
+ echo "Performing test module updates..."
+
+ # Update buildspecs
+ update_buildspecs "$MODULE_NAME"
+
+ # Update .brazil.json
+ update_brazil_json "$MODULE_NAME" true
+
+ # Update root pom.xml
+ update_root_pom "$MODULE_NAME"
+fi
+
+echo ""
+echo "Module setup complete! Please review the changes and complete any manual steps mentioned above."
From 1cdfc8a94ead7a5e2acc1731008ab1a0b5cd79a8 Mon Sep 17 00:00:00 2001
From: Zoe Wang <33073555+zoewangg@users.noreply.github.com>
Date: Fri, 16 May 2025 15:48:26 -0700
Subject: [PATCH 2/3] Convert to python
---
scripts/setup-new-module | 580 +++++++++++++++++++++------------------
1 file changed, 317 insertions(+), 263 deletions(-)
diff --git a/scripts/setup-new-module b/scripts/setup-new-module
index b767d9ff6330..f1bf3554d8be 100755
--- a/scripts/setup-new-module
+++ b/scripts/setup-new-module
@@ -1,85 +1,65 @@
-#!/bin/bash
+#!/usr/bin/env python
-# setup-new-module - Script to set up a new module in the AWS SDK for Java v2
-# Usage: ./scripts/setup-new-module -n module-name [-t] [-p parent-dir]
-# Options:
-# -n module-name: Name of the new module (required)
-# -t: Set up as a test module (optional, default: false)
-# -p parent-dir: Parent directory for the module (optional, default: root project directory for regular modules, test directory for test modules)
-# -h: Show help
+"""
+setup-new-module - Script to set up a new module in the AWS SDK for Java v2
+Usage: ./scripts/setup-new-module -n module-name [-t] [-p parent-dir]
+Options:
+ -n module-name: Name of the new module (required)
+ -t: Set up as a test module (optional, default: false)
+ -p parent-dir: Parent directory for the module (optional, default: root project directory for regular modules, test directory for test modules)
+ -h: Show help
+"""
-set -e
+import os
+import sys
+import argparse
+import re
+import shutil
+from pathlib import Path
-# Get the root project directory
-SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
-# Default values
-IS_TEST_MODULE=false
-PARENT_DIR=""
-MODULE_NAME=""
+def parse_arguments():
+ """Parse command line arguments."""
+ parser = argparse.ArgumentParser(description='Set up a new module in the AWS SDK for Java v2')
+ parser.add_argument('-n', '--name', required=True, help='Name of the new module (required)')
+ parser.add_argument('-t', '--test', action='store_true', help='Set up as a test module (optional, default: false)')
+ parser.add_argument('-p', '--parent-dir', help='Parent directory for the module (optional)')
+ return parser.parse_args()
-# Parse command line arguments
-while getopts "n:tp:h" opt; do
- case ${opt} in
- n)
- MODULE_NAME=$OPTARG
- ;;
- t)
- IS_TEST_MODULE=true
- ;;
- p)
- PARENT_DIR=$OPTARG
- ;;
- h)
- echo "Usage: $0 -n module-name [-t] [-p parent-dir]"
- echo "Options:"
- echo " -n module-name: Name of the new module (required)"
- echo " -t: Set up as a test module (optional, default: false)"
- echo " -p parent-dir: Parent directory for the module (optional, default: root project directory for regular modules, test directory for test modules)"
- echo " -h: Show help"
- exit 0
- ;;
- \?)
- echo "Invalid option: -$OPTARG" >&2
- exit 1
- ;;
- esac
-done
-# Check if module name is provided
-if [ -z "$MODULE_NAME" ]; then
- echo "Error: Module name is required. Use -n option to specify the module name."
- exit 1
-fi
-
-# Set default parent directory based on module type
-if [ -z "$PARENT_DIR" ]; then
- if [ "$IS_TEST_MODULE" = true ]; then
- PARENT_DIR="$ROOT_DIR/test"
- echo "Setting default parent directory for test module to: $PARENT_DIR"
- else
- PARENT_DIR="$ROOT_DIR"
- fi
-fi
+def get_sdk_version(root_dir):
+ """Get the current SDK version from the root pom.xml."""
+ pom_path = os.path.join(root_dir, 'pom.xml')
+ with open(pom_path, 'r') as f:
+ content = f.read()
+
+ # Find the first version tag
+ match = re.search(r'([^<]+)', content)
+ if match:
+ return match.group(1)
+ else:
+ print("Warning: Could not find SDK version in pom.xml")
+ return "UNKNOWN"
-# Create module directory
-MODULE_DIR="$PARENT_DIR/$MODULE_NAME"
-echo "Creating module directory: $MODULE_DIR"
-mkdir -p "$MODULE_DIR"
-mkdir -p "$MODULE_DIR/src/main/java"
-mkdir -p "$MODULE_DIR/src/main/resources"
-mkdir -p "$MODULE_DIR/src/test/java"
-mkdir -p "$MODULE_DIR/src/test/resources"
-# Create basic pom.xml
-# Get the current SDK version from the root pom.xml
-SDK_VERSION=$(grep -o "[^<]*" "$ROOT_DIR/pom.xml" | head -1 | sed 's/\(.*\)<\/version>/\1/')
+def create_module_directory(module_dir):
+ """Create the module directory structure."""
+ print(f"Creating module directory: {module_dir}")
+ os.makedirs(module_dir, exist_ok=True)
+ os.makedirs(os.path.join(module_dir, 'src/main/java'), exist_ok=True)
+ os.makedirs(os.path.join(module_dir, 'src/main/resources'), exist_ok=True)
+ os.makedirs(os.path.join(module_dir, 'src/test/java'), exist_ok=True)
+ os.makedirs(os.path.join(module_dir, 'src/test/resources'), exist_ok=True)
-echo "Using SDK version: $SDK_VERSION"
-cat > "$MODULE_DIR/pom.xml" << EOF
-
+def create_pom_xml(module_dir, module_name, sdk_version, is_test_module):
+ """Create a basic pom.xml file for the module."""
+ pom_path = os.path.join(module_dir, 'pom.xml')
+
+ print(f"Using SDK version: {sdk_version}")
+
+ with open(pom_path, 'w') as f:
+ f.write(f'''
@@ -87,19 +67,18 @@ cat > "$MODULE_DIR/pom.xml" << EOF
software.amazon.awssdk
aws-sdk-java-pom
- ${SDK_VERSION}
+ {sdk_version}
- ${MODULE_NAME}
- AWS Java SDK :: ${MODULE_NAME}
- AWS SDK for Java - ${MODULE_NAME}
+ {module_name}
+ AWS Java SDK :: {module_name}
+ AWS SDK for Java - {module_name}
https://aws.amazon.com/sdkforjava
-EOF
-
-# Add Automatic-Module-Name for non-test modules
-if [ "$IS_TEST_MODULE" = false ]; then
- cat >> "$MODULE_DIR/pom.xml" << EOF
-
+''')
+
+ # Add Automatic-Module-Name for non-test modules
+ if not is_test_module:
+ f.write('''
@@ -116,237 +95,312 @@ if [ "$IS_TEST_MODULE" = false ]; then
-EOF
-fi
-
-# Close pom.xml
-cat >> "$MODULE_DIR/pom.xml" << EOF
-
+''')
+
+ # Close pom.xml
+ f.write('''
-EOF
-
-echo "Basic module structure created at $MODULE_DIR"
-
-# Function to add dependency to a pom.xml file
-add_dependency_to_pom() {
- local pom_file=$1
- local module_name=$2
+''')
+ print(f"Created pom.xml at {pom_path}")
+def add_dependency_to_pom(pom_file, module_name):
+ """Add dependency to a pom.xml file."""
# Check if the file exists
- if [ ! -f "$pom_file" ]; then
- echo "Warning: $pom_file does not exist. Skipping."
+ if not os.path.isfile(pom_file):
+ print(f"Warning: {pom_file} does not exist. Skipping.")
return
- fi
+
+ # Read the file content
+ with open(pom_file, 'r') as f:
+ content = f.read()
# Check if dependency already exists
- if grep -q "$module_name" "$pom_file"; then
- echo "Dependency already exists in $pom_file. Skipping."
+ dependency_pattern = f"{module_name}"
+ if dependency_pattern in content:
+ print(f"Dependency already exists in {pom_file}. Skipping.")
return
- fi
# Find the dependencies section and add the new dependency
- sed -i.bak "//a\\
- \\
- software.amazon.awssdk\\
- $module_name\\
- \${awsjavasdk.version}\\
- \\
-" "$pom_file"
-
- # Remove backup file
- rm -f "${pom_file}.bak"
-
- echo "Added dependency to $pom_file"
-}
+ dependencies_pattern = r""
+ new_dependency = f'''
+ software.amazon.awssdk
+ {module_name}
+ ${{awsjavasdk.version}}
+
+'''
+
+ # Insert the new dependency after the dependencies tag
+ modified_content = re.sub(
+ dependencies_pattern,
+ f"{dependencies_pattern}\n{new_dependency}",
+ content
+ )
+
+ # Write the modified content back to the file
+ with open(pom_file, 'w') as f:
+ f.write(modified_content)
+
+ print(f"Added dependency to {pom_file}")
-# Function to update the root pom.xml to include the new module
-update_root_pom() {
- local root_pom="$ROOT_DIR/pom.xml"
- local module_name=$1
+def update_root_pom(root_dir, module_name, is_test_module):
+ """Update the root pom.xml to include the new module."""
+ root_pom = os.path.join(root_dir, 'pom.xml')
+
# Check if the file exists
- if [ ! -f "$root_pom" ]; then
- echo "Warning: $root_pom does not exist. Skipping."
+ if not os.path.isfile(root_pom):
+ print(f"Warning: {root_pom} does not exist. Skipping.")
return
- fi
-
+
# Determine the module path based on whether it's a test module
- local module_path="$module_name"
- if [ "$IS_TEST_MODULE" = true ]; then
- module_path="test/$module_name"
- fi
-
+ module_path = module_name
+ if is_test_module:
+ module_path = f"test/{module_name}"
+
+ # Read the file content
+ with open(root_pom, 'r') as f:
+ content = f.read()
+
# Check if module already exists
- if grep -q "$module_path" "$root_pom"; then
- echo "Module already exists in root pom.xml. Skipping."
+ module_pattern = f"{module_path}"
+ if module_pattern in content:
+ print("Module already exists in root pom.xml. Skipping.")
return
- fi
-
+
# Find the modules section and add the new module
- sed -i.bak "//a\\
- $module_path\\
-" "$root_pom"
-
- # Remove backup file
- rm -f "${root_pom}.bak"
-
- echo "Added module to root pom.xml"
-}
-
-# Function to update japicmp plugin config
-update_japicmp_config() {
- local root_pom="$ROOT_DIR/pom.xml"
- local module_name=$1
+ modules_pattern = r""
+ new_module = f" {module_path}"
+
+ # Insert the new module after the modules tag
+ modified_content = re.sub(
+ modules_pattern,
+ f"{modules_pattern}\n{new_module}",
+ content
+ )
+
+ # Write the modified content back to the file
+ with open(root_pom, 'w') as f:
+ f.write(modified_content)
+
+ print("Added module to root pom.xml")
+def update_japicmp_config(root_dir, module_name):
+ """Update japicmp plugin config in root pom.xml."""
+ root_pom = os.path.join(root_dir, 'pom.xml')
# Check if the file exists
- if [ ! -f "$root_pom" ]; then
- echo "Warning: $root_pom does not exist. Skipping japicmp update."
+ if not os.path.isfile(root_pom):
+ print(f"Warning: {root_pom} does not exist. Skipping japicmp update.")
return
- fi
+
+ # Read the file content
+ with open(root_pom, 'r') as f:
+ content = f.read()
# Check if module already exists in japicmp config
- if grep -q "$module_name" "$root_pom"; then
- echo "Module already exists in japicmp config. Skipping."
+ include_module_pattern = f" {module_name}"
+ if include_module_pattern in content:
+ print("Module already exists in japicmp config. Skipping.")
return
- fi
- # Add the module to the includeModules section
- # Find the last includeModule line and add the new module after it
- sed -i.bak "/<\/includeModules>/i\\
- $module_name\\
-" "$root_pom"
+ # Find the includeModules section and add the new module
+ include_modules_end_pattern = r""
+ new_include_module = f"{module_name}\n"
+
+ # Insert the new module before the includeModules end tag
+ modified_content = re.sub(
+ include_modules_end_pattern,
+ f"{new_include_module} {include_modules_end_pattern}",
+ content
+ )
- # Remove backup file
- rm -f "${root_pom}.bak"
+ # Write the modified content back to the file
+ with open(root_pom, 'w') as f:
+ f.write(modified_content)
- echo "Added $module_name to japicmp plugin configuration in $root_pom"
-}
+ print(f"Added {module_name} to japicmp plugin configuration in {root_pom}")
-# Function to update .brazil.json
-update_brazil_json() {
- local brazil_json="$ROOT_DIR/.brazil.json"
- local module_name=$1
- local is_test=$2
+
+def update_brazil_json(root_dir, module_name, is_test):
+ """Update .brazil.json file."""
+ brazil_json = os.path.join(root_dir, '.brazil.json')
# Check if the file exists
- if [ ! -f "$brazil_json" ]; then
- echo "Warning: $brazil_json does not exist. Skipping."
+ if not os.path.isfile(brazil_json):
+ print(f"Warning: {brazil_json} does not exist. Skipping.")
return
- fi
+
+ # Read the file content
+ with open(brazil_json, 'r') as f:
+ content = f.read()
# Check if module already exists in .brazil.json
- if grep -q "\"$module_name\":" "$brazil_json"; then
- echo "Module already exists in .brazil.json. Skipping."
+ module_pattern = f'"{module_name}":'
+ if module_pattern in content:
+ print("Module already exists in .brazil.json. Skipping.")
return
- fi
- if [ "$is_test" = true ]; then
+ if is_test:
# Find a specific test module entry to anchor our insertion
- # Using a specific entry (s3-tests) as an anchor point to avoid multiple insertions
- sed -i.bak "/\"s3-tests\": {\"skipImport\": true}/i\\
- \"$module_name\": { \"skipImport\": true },\\
-" "$brazil_json"
+ anchor_pattern = r'"s3-tests": {"skipImport": true}'
+ new_module_entry = f'"{module_name}": {{ "skipImport": true }},\n'
- echo "Added $module_name to .brazil.json with skipImport: true"
- else
+ # Insert the new module before the anchor
+ modified_content = re.sub(
+ anchor_pattern,
+ f"{new_module_entry} {anchor_pattern}",
+ content
+ )
+
+ print(f"Added {module_name} to .brazil.json with skipImport: true")
+ else:
# Find a specific non-test module entry to anchor our insertion
- # Using the first module entry as an anchor point
- sed -i.bak "/\"annotations\": { \"packageName\": /i\\
- \"$module_name\": { \"packageName\": \"TODO\" },\\
-" "$brazil_json"
+ anchor_pattern = r'"annotations": { "packageName": '
+ new_module_entry = f'"{module_name}": {{ "packageName": "TODO" }},\n'
- echo "Added $module_name to .brazil.json with packageName: TODO"
- fi
-
- # Remove backup file
- rm -f "${brazil_json}.bak"
-}
-
-# Function to update buildspec files for test modules
-update_buildspecs() {
- local module_name=$1
- local release_maven="$ROOT_DIR/buildspecs/release-to-maven.yml"
- local release_javadoc="$ROOT_DIR/buildspecs/release-javadoc.yml"
-
- # Check if files exist
- if [ ! -f "$release_maven" ]; then
- echo "Warning: $release_maven does not exist. Skipping."
- else
- # Update MODULES_TO_SKIP in release-to-maven.yml
- if grep -q "MODULES_TO_SKIP=" "$release_maven"; then
- # Extract current value
- current_modules=$(grep "MODULES_TO_SKIP=" "$release_maven" | cut -d'"' -f2)
- # Add new module to skip
- new_modules="$current_modules,$module_name"
- # Update the file
- sed -i.bak "s/MODULES_TO_SKIP=\"$current_modules\"/MODULES_TO_SKIP=\"$new_modules\"/" "$release_maven"
- rm -f "${release_maven}.bak"
- echo "Updated MODULES_TO_SKIP in $release_maven to include $module_name"
- else
- echo "MODULES_TO_SKIP variable not found in $release_maven. Please manually update."
- fi
- fi
-
- if [ ! -f "$release_javadoc" ]; then
- echo "Warning: $release_javadoc does not exist. Skipping."
- else
- # Update MODULES_TO_SKIP in release-javadoc.yml
- if grep -q "MODULES_TO_SKIP=" "$release_javadoc"; then
- # Extract current value
- current_modules=$(grep "MODULES_TO_SKIP=" "$release_javadoc" | cut -d'"' -f2)
- # Add new module to skip
- new_modules="$current_modules,$module_name"
- # Update the file
- sed -i.bak "s/MODULES_TO_SKIP=\"$current_modules\"/MODULES_TO_SKIP=\"$new_modules\"/" "$release_javadoc"
- rm -f "${release_javadoc}.bak"
- echo "Updated MODULES_TO_SKIP in $release_javadoc to include $module_name"
- else
- echo "MODULES_TO_SKIP variable not found in $release_javadoc. Please manually update."
- fi
- fi
-}
-
-# Perform updates based on module type
-if [ "$IS_TEST_MODULE" = false ]; then
- echo "Performing non-test module updates..."
-
- # Add to tests-coverage-reporting pom.xml
- add_dependency_to_pom "$ROOT_DIR/test/tests-coverage-reporting/pom.xml" "$MODULE_NAME"
+ # Insert the new module before the anchor
+ modified_content = re.sub(
+ anchor_pattern,
+ f"{new_module_entry} {anchor_pattern}",
+ content
+ )
+
+ print(f"Added {module_name} to .brazil.json with packageName: TODO")
- # Add to aws-sdk-java pom.xml
- add_dependency_to_pom "$ROOT_DIR/aws-sdk-java/pom.xml" "$MODULE_NAME"
+ # Write the modified content back to the file
+ with open(brazil_json, 'w') as f:
+ f.write(modified_content)
+def update_buildspecs(root_dir, module_name):
+ """Update buildspec files for test modules."""
+ release_maven = os.path.join(root_dir, 'buildspecs/release-to-maven.yml')
+ release_javadoc = os.path.join(root_dir, 'buildspecs/release-javadoc.yml')
- # Add to architecture-tests pom.xml
- add_dependency_to_pom "$ROOT_DIR/test/architecture-tests/pom.xml" "$MODULE_NAME"
+ # Update release-to-maven.yml
+ if os.path.isfile(release_maven):
+ with open(release_maven, 'r') as f:
+ content = f.read()
+
+ # Look for MODULES_TO_SKIP variable
+ modules_pattern = r'MODULES_TO_SKIP="([^"]*)"'
+ match = re.search(modules_pattern, content)
+
+ if match:
+ current_modules = match.group(1)
+ new_modules = f"{current_modules},{module_name}" if current_modules else module_name
+
+ # Update the file
+ modified_content = re.sub(
+ modules_pattern,
+ f'MODULES_TO_SKIP="{new_modules}"',
+ content
+ )
+
+ with open(release_maven, 'w') as f:
+ f.write(modified_content)
+
+ print(f"Updated MODULES_TO_SKIP in {release_maven} to include {module_name}")
+ else:
+ print(f"MODULES_TO_SKIP variable not found in {release_maven}. Please manually update.")
+ else:
+ print(f"Warning: {release_maven} does not exist. Skipping.")
- # Add to bom pom.xml
- add_dependency_to_pom "$ROOT_DIR/bom/pom.xml" "$MODULE_NAME"
+ # Update release-javadoc.yml
+ if os.path.isfile(release_javadoc):
+ with open(release_javadoc, 'r') as f:
+ content = f.read()
+
+ # Look for MODULES_TO_SKIP variable
+ modules_pattern = r'MODULES_TO_SKIP="([^"]*)"'
+ match = re.search(modules_pattern, content)
+
+ if match:
+ current_modules = match.group(1)
+ new_modules = f"{current_modules},{module_name}" if current_modules else module_name
+
+ # Update the file
+ modified_content = re.sub(
+ modules_pattern,
+ f'MODULES_TO_SKIP="{new_modules}"',
+ content
+ )
+
+ with open(release_javadoc, 'w') as f:
+ f.write(modified_content)
+
+ print(f"Updated MODULES_TO_SKIP in {release_javadoc} to include {module_name}")
+ else:
+ print(f"MODULES_TO_SKIP variable not found in {release_javadoc}. Please manually update.")
+ else:
+ print(f"Warning: {release_javadoc} does not exist. Skipping.")
+def main():
+ """Main function to set up a new module."""
+ args = parse_arguments()
- # Update japicmp plugin config
- update_japicmp_config "$MODULE_NAME"
+ # Get the root project directory
+ script_dir = os.path.dirname(os.path.abspath(__file__))
+ root_dir = os.path.dirname(script_dir)
- # Update .brazil.json
- update_brazil_json "$MODULE_NAME" false
+ # Set default parent directory based on module type
+ parent_dir = args.parent_dir
+ if not parent_dir:
+ if args.test:
+ parent_dir = os.path.join(root_dir, 'test')
+ print(f"Setting default parent directory for test module to: {parent_dir}")
+ else:
+ parent_dir = root_dir
- # Update root pom.xml
- update_root_pom "$MODULE_NAME"
+ # Create module directory
+ module_dir = os.path.join(parent_dir, args.name)
+ create_module_directory(module_dir)
-else
- echo "Performing test module updates..."
+ # Get SDK version
+ sdk_version = get_sdk_version(root_dir)
- # Update buildspecs
- update_buildspecs "$MODULE_NAME"
+ # Create pom.xml
+ create_pom_xml(module_dir, args.name, sdk_version, args.test)
- # Update .brazil.json
- update_brazil_json "$MODULE_NAME" true
+ # Perform updates based on module type
+ if not args.test:
+ print("Performing non-test module updates...")
+
+ # Add to tests-coverage-reporting pom.xml
+ add_dependency_to_pom(os.path.join(root_dir, 'test/tests-coverage-reporting/pom.xml'), args.name)
+
+ # Add to aws-sdk-java pom.xml
+ add_dependency_to_pom(os.path.join(root_dir, 'aws-sdk-java/pom.xml'), args.name)
+
+ # Add to architecture-tests pom.xml
+ add_dependency_to_pom(os.path.join(root_dir, 'test/architecture-tests/pom.xml'), args.name)
+
+ # Add to bom pom.xml
+ add_dependency_to_pom(os.path.join(root_dir, 'bom/pom.xml'), args.name)
+
+ # Update japicmp plugin config
+ update_japicmp_config(root_dir, args.name)
+
+ # Update .brazil.json
+ update_brazil_json(root_dir, args.name, False)
+
+ # Update root pom.xml
+ update_root_pom(root_dir, args.name, False)
+ else:
+ print("Performing test module updates...")
+
+ # Update buildspecs
+ update_buildspecs(root_dir, args.name)
+
+ # Update .brazil.json
+ update_brazil_json(root_dir, args.name, True)
+
+ # Update root pom.xml
+ update_root_pom(root_dir, args.name, True)
- # Update root pom.xml
- update_root_pom "$MODULE_NAME"
-fi
+ print("")
+ print("Module setup complete! Please review the changes and complete any manual steps mentioned above.")
+
-echo ""
-echo "Module setup complete! Please review the changes and complete any manual steps mentioned above."
+if __name__ == "__main__":
+ main()
From fe3588ee4777646359eb168a6f33e69c83907c0d Mon Sep 17 00:00:00 2001
From: Zoe Wang <33073555+zoewangg@users.noreply.github.com>
Date: Fri, 16 May 2025 16:04:38 -0700
Subject: [PATCH 3/3] Update log
---
scripts/setup-new-module | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/setup-new-module b/scripts/setup-new-module
index f1bf3554d8be..fff112a75ce9 100755
--- a/scripts/setup-new-module
+++ b/scripts/setup-new-module
@@ -399,7 +399,7 @@ def main():
update_root_pom(root_dir, args.name, True)
print("")
- print("Module setup complete! Please review the changes and complete any manual steps mentioned above.")
+ print("Module setup complete! Please review the changes.")
if __name__ == "__main__":