Skip to content

Commit afad186

Browse files
committed
add missing file
1 parent 3182296 commit afad186

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

copy-parent-poms.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
DEPENDENCY_DIR="$1"
4+
M2_REPO="${HOME}/.m2/repository"
5+
COPIED_TRACKER="${DEPENDENCY_DIR}/.parent_poms_copied"
6+
7+
echo "========================================"
8+
echo "Copying parent POMs from local Maven repository"
9+
echo "========================================"
10+
11+
# Create tracker file
12+
mkdir -p "$DEPENDENCY_DIR"
13+
> "$COPIED_TRACKER"
14+
15+
# Function to check if we've already copied this POM
16+
is_already_copied() {
17+
grep -qx "$1" "$COPIED_TRACKER" 2>/dev/null
18+
}
19+
20+
# Function to mark POM as copied
21+
mark_as_copied() {
22+
echo "$1" >> "$COPIED_TRACKER"
23+
}
24+
25+
# Function to recursively copy parent chain
26+
copy_parent_chain() {
27+
pom_file="$1"
28+
29+
# Check if POM exists
30+
if [ ! -f "$pom_file" ]; then
31+
return
32+
fi
33+
34+
# Extract parent info (handles multi-line XML)
35+
parent_block=$(sed -n '/<parent>/,/<\/parent>/p' "$pom_file" | tr '\n' ' ')
36+
37+
if [ -z "$parent_block" ]; then
38+
return # No parent, stop recursion
39+
fi
40+
41+
parent_group=$(echo "$parent_block" | sed -n 's/.*<groupId>\([^<]*\)<\/groupId>.*/\1/p' | head -1)
42+
parent_artifact=$(echo "$parent_block" | sed -n 's/.*<artifactId>\([^<]*\)<\/artifactId>.*/\1/p' | head -1)
43+
parent_version=$(echo "$parent_block" | sed -n 's/.*<version>\([^<]*\)<\/version>.*/\1/p' | head -1)
44+
45+
# Validate we got all three values
46+
if [ -z "$parent_group" ] || [ -z "$parent_artifact" ] || [ -z "$parent_version" ]; then
47+
return
48+
fi
49+
50+
# Create unique key for this POM (safe for file storage)
51+
pom_key="${parent_group}__${parent_artifact}__${parent_version}"
52+
53+
# Skip if already copied
54+
if is_already_copied "$pom_key"; then
55+
return
56+
fi
57+
58+
# Convert group ID to path
59+
parent_path=$(echo "$parent_group" | tr '.' '/')
60+
61+
# Source location in local Maven repo
62+
parent_pom="$M2_REPO/$parent_path/$parent_artifact/$parent_version/$parent_artifact-$parent_version.pom"
63+
64+
# Target location in dependency directory
65+
target_dir="$DEPENDENCY_DIR/$parent_path/$parent_artifact/$parent_version"
66+
67+
if [ -f "$parent_pom" ]; then
68+
mkdir -p "$target_dir"
69+
cp "$parent_pom" "$target_dir/"
70+
echo "✓ Copied: $parent_artifact:$parent_version"
71+
72+
# Mark as copied
73+
mark_as_copied "$pom_key"
74+
75+
# Recursively copy this parent's parent
76+
copy_parent_chain "$parent_pom"
77+
else
78+
echo "✗ NOT FOUND in local repo: $parent_artifact:$parent_version"
79+
echo " Expected at: $parent_pom"
80+
fi
81+
}
82+
83+
# Find all POM files and process each
84+
find "$DEPENDENCY_DIR" -name "*.pom" -type f | while read pom; do
85+
copy_parent_chain "$pom"
86+
done
87+
88+
# Clean up tracker file
89+
rm -f "$COPIED_TRACKER"
90+
91+
echo "========================================"
92+
echo "Parent POM copy complete"
93+
echo "========================================"

0 commit comments

Comments
 (0)