Skip to content

Commit 1562109

Browse files
author
David Hasani
committed
script updates
1 parent cbdf1db commit 1562109

File tree

2 files changed

+63
-39
lines changed

2 files changed

+63
-39
lines changed

packages/amazonq/scripts/build/transformByQ/gradle_copy_deps.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -536,35 +536,46 @@ def modify_script(self, script_path):
536536
def add_maven_repos(self, content, local_path):
537537
new_maven_repo = f"""
538538
maven {{
539-
url '{local_path}'
539+
url "{local_path}"
540540
metadataSources {{
541541
mavenPom()
542542
artifact()
543543
}}
544544
}}
545545
"""
546546

547-
# Find the repositories block manually and modify it
548-
start_idx = content.find('repositories {')
549-
if start_idx == -1:
550-
# If no repositories block is found, return the content as is
551-
return content
547+
modified_content = ''
548+
start_idx = 0
549+
while True:
550+
# Find the repositories block manually and modify it
551+
start_idx_of_repo = content.find('repositories {', start_idx)
552+
if start_idx_of_repo == -1:
553+
# No more repositories blocks found
554+
break
552555

553-
# Find the matching closing brace for the repositories block
554-
open_braces = 1
555-
end_idx = start_idx + len('repositories {')
556-
while open_braces > 0 and end_idx < len(content):
557-
if content[end_idx] == '{':
558-
open_braces += 1
559-
elif content[end_idx] == '}':
560-
open_braces -= 1
561-
end_idx += 1
556+
# Find the matching closing brace for the repositories block
557+
open_braces = 1
558+
end_idx = start_idx_of_repo + len('repositories {')
559+
while open_braces > 0 and end_idx < len(content):
560+
if content[end_idx] == '{':
561+
open_braces += 1
562+
elif content[end_idx] == '}':
563+
open_braces -= 1
564+
end_idx += 1
562565

563-
# Insert the new maven repository before the closing brace
564-
modified_repositories_block = content[start_idx:end_idx-1].strip() + f"\n{new_maven_repo.strip()}\n" + content[end_idx-1:end_idx]
566+
# Insert the new maven repository before the closing brace
567+
modified_repositories_block = content[start_idx_of_repo:end_idx-1].strip() + f"\n{new_maven_repo.strip()}\n" + content[end_idx-1:end_idx]
565568

566-
# Replace the old block with the modified one
567-
return content[:start_idx] + modified_repositories_block + content[end_idx:]
569+
# Append the modified block to the modified_content string
570+
modified_content += content[start_idx:start_idx_of_repo] + modified_repositories_block
571+
572+
# Move the start_idx to the end of the current block
573+
start_idx = end_idx
574+
575+
# Append any remaining content after the last repositoroies block
576+
modified_content += content[start_idx:]
577+
578+
return modified_content
568579

569580
def create_init_script(directory, init_name, content):
570581
qct_gradle_dir = os.path.join(directory, 'qct-gradle')
@@ -657,6 +668,7 @@ def run_properties(dir,action_1, distBase, distPath, zip_name):
657668
manager.set_custom_distribution(distributionBase, distributionPath)
658669

659670
#do a gradlew to pull the artifacts to the specified destination
671+
# TODO: do a gradlew subprocess here before modifying the content of the distribution to pull the zip
660672
run_gradlew(project_directory)
661673

662674
#modify the initialization scripts under init.d

packages/amazonq/scripts/build/transformByQ/windows_gradle_copy_deps.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -536,35 +536,46 @@ def modify_script(self, script_path):
536536
def add_maven_repos(self, content, local_path):
537537
new_maven_repo = f"""
538538
maven {{
539-
url '{local_path}'
539+
url "{local_path}"
540540
metadataSources {{
541541
mavenPom()
542542
artifact()
543543
}}
544544
}}
545545
"""
546546

547-
# Find the repositories block manually and modify it
548-
start_idx = content.find('repositories {')
549-
if start_idx == -1:
550-
# If no repositories block is found, return the content as is
551-
return content
547+
modified_content = ''
548+
start_idx = 0
549+
while True:
550+
# Find the repositories block manually and modify it
551+
start_idx_of_repo = content.find('repositories {', start_idx)
552+
if start_idx_of_repo == -1:
553+
# No more repositories blocks found
554+
break
552555

553-
# Find the matching closing brace for the repositories block
554-
open_braces = 1
555-
end_idx = start_idx + len('repositories {')
556-
while open_braces > 0 and end_idx < len(content):
557-
if content[end_idx] == '{':
558-
open_braces += 1
559-
elif content[end_idx] == '}':
560-
open_braces -= 1
561-
end_idx += 1
556+
# Find the matching closing brace for the repositories block
557+
open_braces = 1
558+
end_idx = start_idx_of_repo + len('repositories {')
559+
while open_braces > 0 and end_idx < len(content):
560+
if content[end_idx] == '{':
561+
open_braces += 1
562+
elif content[end_idx] == '}':
563+
open_braces -= 1
564+
end_idx += 1
562565

563-
# Insert the new maven repository before the closing brace
564-
modified_repositories_block = content[start_idx:end_idx-1].strip() + f"\n{new_maven_repo.strip()}\n" + content[end_idx-1:end_idx]
566+
# Insert the new maven repository before the closing brace
567+
modified_repositories_block = content[start_idx_of_repo:end_idx-1].strip() + f"\n{new_maven_repo.strip()}\n" + content[end_idx-1:end_idx]
565568

566-
# Replace the old block with the modified one
567-
return content[:start_idx] + modified_repositories_block + content[end_idx:]
569+
# Append the modified block to the modified_content string
570+
modified_content += content[start_idx:start_idx_of_repo] + modified_repositories_block
571+
572+
# Move the start_idx to the end of the current block
573+
start_idx = end_idx
574+
575+
# Append any remaining content after the last repositoroies block
576+
modified_content += content[start_idx:]
577+
578+
return modified_content
568579

569580
def create_init_script(directory, init_name, content):
570581
qct_gradle_dir = os.path.join(directory, 'qct-gradle')
@@ -636,7 +647,7 @@ def run(directory_path):
636647
create_run_task(directory_path, 'custom-init.gradle', custom_init_script_content, 'cacheToMavenLocal')
637648
create_run_task(directory_path,'buildEnv-copy-init.gradle', run_build_env_copy_content, 'runAndParseBuildEnvironment')
638649
build_offline_dependencies = create_init_script(directory_path, 'use-downloaded-dependencies.gradle', use_offline_dependency)
639-
#run_offline_build(build_offline_dependencies, directory_path)
650+
# run_offline_build(build_offline_dependencies, directory_path)
640651
except Exception as e:
641652
print(f"An error occurred: {e}")
642653
sys.exit(1)
@@ -657,6 +668,7 @@ def run_properties(dir,action_1, distBase, distPath, zip_name):
657668
manager.set_custom_distribution(distributionBase, distributionPath)
658669

659670
#do a gradlew to pull the artifacts to the specified destination
671+
# TODO: do a gradlew subprocess here before modifying the content of the distribution to pull the zip
660672
run_gradlew(project_directory)
661673

662674
#modify the initialization scripts under init.d

0 commit comments

Comments
 (0)