fix: use perl script to localize maven

This commit is contained in:
Akash Yadav
2025-03-05 12:07:24 +05:30
parent 83f290698c
commit 0571b573ce
2 changed files with 44 additions and 2 deletions

38
scripts/localize_maven.pl Executable file
View File

@@ -0,0 +1,38 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Slurp;
sub localize_maven {
my ($file) = @_;
die "File does not exist: $file\n" unless -f $file;
die "Not a Gradle file (must end in .gradle or .gradle.kts): $file\n"
unless $file =~ /\.(gradle|gradle\.kts)$/;
my $content = read_file($file);
my $modified_content = $content;
$modified_content =~ s{
(maven\s*\{) # Start of maven block
((?:[^{}]*|\{[^{}]*\})*?) # Content of the block (non-greedy)
(\}) # Closing brace
}{
# Check if the block contains plugins.gradle.org
my $block = $1 . $2 . $3;
$block =~ /plugins\.gradle\.org/ ? $block : "mavenLocal()"
}gexs;
if ($modified_content ne $content) {
# Write the modified content back to the file
open(my $out, '>', $file) or die "Can't open $file: $!";
print $out $modified_content;
close $out;
print "Processed file: $file\n";
}
}
localize_maven($ARGV[0]) if @ARGV;
1;

View File

@@ -22,8 +22,8 @@ set -e
function localize_maven {
# Replace custom Maven repositories with mavenLocal()
find ./* -name '*.gradle' -type f -print0 | xargs -0 \
sed -n -i \
-e '/maven {/{:loop;N;/}$/!b loop;/plugins.gradle.org/!s/maven .*/mavenLocal()/};p'
perl "$rootdir/scripts/localize_maven.pl"
# Make gradlew scripts call our Gradle wrapper
find ./* -name gradlew -type f | while read -r gradlew; do
echo -e '#!/bin/sh\ngradle "$@"' >"$gradlew"
@@ -116,6 +116,10 @@ rustup target add aarch64-linux-android
rustup target add x86_64-linux-android
cargo install --vers 0.26.0 cbindgen
## Install perl modules
echo 'Installing File::Slurp perl module...'
sudo perl -MCPAN -e 'install File::Slurp'
# Fenix
# shellcheck disable=SC2154
pushd "$fenix"