Skip to content

Commit a899f49

Browse files
authored
experiment: add CI config for classport-experiments (#93)
1 parent 0ae51ad commit a899f49

File tree

5 files changed

+228
-0
lines changed

5 files changed

+228
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build Overhead Experiment
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
measure-overhead:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
12+
with:
13+
submodules: true
14+
fetch-depth: 0
15+
16+
- name: Setup JDK 17
17+
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5
18+
with:
19+
distribution: 'temurin'
20+
java-version: '17'
21+
22+
- name: Install dependencies
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y xmlstarlet bc
26+
27+
- name: Build classport project
28+
run: mvn install -DskipTests
29+
30+
- name: Run build overhead measurement
31+
run: |
32+
cd .github/workflows/experiments
33+
./compute_build_overhead.sh pdfbox
34+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
3+
# Script to add classport-maven-plugin to pom.xml
4+
# Usage: ./add_classport_plugin.sh [pom_file_path]
5+
# If pom_file_path is not provided, defaults to "pom.xml" in current directory
6+
7+
POM_FILE="${1:-pom.xml}"
8+
9+
# Check if xmlstarlet is available
10+
if ! command -v xmlstarlet &> /dev/null; then
11+
echo "Error: xmlstarlet is not installed. Please install it first."
12+
exit 1
13+
fi
14+
15+
# Check if pom.xml exists
16+
if [ ! -f "$POM_FILE" ]; then
17+
echo "Error: pom.xml not found at $POM_FILE"
18+
exit 1
19+
fi
20+
21+
# Determine if the document uses namespaces
22+
HAS_NAMESPACE=false
23+
if xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -c "/x:project" "$POM_FILE" &>/dev/null; then
24+
HAS_NAMESPACE=true
25+
fi
26+
27+
# Check if build/plugins already exists, if not create it
28+
# Try with namespace first, then without (only match /project/build/plugins, not pluginManagement)
29+
if [ "$HAS_NAMESPACE" = true ]; then
30+
BUILD_PLUGINS_EXISTS=$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -c "/x:project/x:build/x:plugins" "$POM_FILE" 2>/dev/null)
31+
else
32+
BUILD_PLUGINS_EXISTS=$(xmlstarlet sel -t -c "/project/build/plugins" "$POM_FILE" 2>/dev/null)
33+
fi
34+
35+
if [ -z "$BUILD_PLUGINS_EXISTS" ]; then
36+
# Check if build exists, if not create it
37+
if [ "$HAS_NAMESPACE" = true ]; then
38+
BUILD_EXISTS=$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -c "/x:project/x:build" "$POM_FILE" 2>/dev/null)
39+
else
40+
BUILD_EXISTS=$(xmlstarlet sel -t -c "/project/build" "$POM_FILE" 2>/dev/null)
41+
fi
42+
43+
if [ -z "$BUILD_EXISTS" ]; then
44+
# Create build element
45+
if [ "$HAS_NAMESPACE" = true ]; then
46+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project" -t elem -n "build" "$POM_FILE"
47+
else
48+
xmlstarlet ed -L -s "/project" -t elem -n "build" "$POM_FILE"
49+
fi
50+
fi
51+
# Create plugins element (only if it doesn't exist directly under build)
52+
if [ "$HAS_NAMESPACE" = true ]; then
53+
if ! xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -c "/x:project/x:build/x:plugins" "$POM_FILE" 2>/dev/null; then
54+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project/x:build" -t elem -n "plugins" "$POM_FILE"
55+
fi
56+
else
57+
if ! xmlstarlet sel -t -c "/project/build/plugins" "$POM_FILE" 2>/dev/null; then
58+
xmlstarlet ed -L -s "/project/build" -t elem -n "plugins" "$POM_FILE"
59+
fi
60+
fi
61+
fi
62+
63+
# Check if the plugin already exists (to avoid duplicates)
64+
# Try with namespace first, then without
65+
PLUGIN_EXISTS=$(xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -v "count(//x:plugin[x:groupId='io.github.project' and x:artifactId='classport-maven-plugin'])" "$POM_FILE" 2>/dev/null)
66+
if [ -z "$PLUGIN_EXISTS" ] || [ "$PLUGIN_EXISTS" = "" ]; then
67+
PLUGIN_EXISTS=$(xmlstarlet sel -t -v "count(//plugin[groupId='io.github.project' and artifactId='classport-maven-plugin'])" "$POM_FILE" 2>/dev/null || echo "0")
68+
fi
69+
70+
if [ "$PLUGIN_EXISTS" -eq 0 ]; then
71+
# Use the same namespace context as determined earlier
72+
if [ "$HAS_NAMESPACE" = true ]; then
73+
# Use namespace-aware XPath for editing - only match /project/build/plugins (not pluginManagement)
74+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project/x:build/x:plugins" -t elem -n "plugin" -v "" "$POM_FILE"
75+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project/x:build/x:plugins/x:plugin[last()]" -t elem -n "groupId" -v "io.github.project" "$POM_FILE"
76+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project/x:build/x:plugins/x:plugin[last()]" -t elem -n "artifactId" -v "classport-maven-plugin" "$POM_FILE"
77+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project/x:build/x:plugins/x:plugin[last()]" -t elem -n "version" -v "0.1.0-SNAPSHOT" "$POM_FILE"
78+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project/x:build/x:plugins/x:plugin[last()]" -t elem -n "executions" -v "" "$POM_FILE"
79+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:executions" -t elem -n "execution" -v "" "$POM_FILE"
80+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:executions/x:execution" -t elem -n "goals" -v "" "$POM_FILE"
81+
xmlstarlet ed -L -N x=http://maven.apache.org/POM/4.0.0 -s "/x:project/x:build/x:plugins/x:plugin[last()]/x:executions/x:execution/x:goals" -t elem -n "goal" -v "embed" "$POM_FILE"
82+
else
83+
# Use non-namespace XPath
84+
xmlstarlet ed -L -s "/project/build/plugins" -t elem -n "plugin" -v "" "$POM_FILE"
85+
xmlstarlet ed -L -s "/project/build/plugins/plugin[last()]" -t elem -n "groupId" -v "io.github.project" "$POM_FILE"
86+
xmlstarlet ed -L -s "/project/build/plugins/plugin[last()]" -t elem -n "artifactId" -v "classport-maven-plugin" "$POM_FILE"
87+
xmlstarlet ed -L -s "/project/build/plugins/plugin[last()]" -t elem -n "version" -v "0.1.0-SNAPSHOT" "$POM_FILE"
88+
xmlstarlet ed -L -s "/project/build/plugins/plugin[last()]" -t elem -n "executions" -v "" "$POM_FILE"
89+
xmlstarlet ed -L -s "/project/build/plugins/plugin[last()]/executions" -t elem -n "execution" -v "" "$POM_FILE"
90+
xmlstarlet ed -L -s "/project/build/plugins/plugin[last()]/executions/execution" -t elem -n "goals" -v "" "$POM_FILE"
91+
xmlstarlet ed -L -s "/project/build/plugins/plugin[last()]/executions/execution/goals" -t elem -n "goal" -v "embed" "$POM_FILE"
92+
fi
93+
echo "Plugin configuration added to pom.xml"
94+
else
95+
echo "Plugin already exists in pom.xml, skipping addition"
96+
fi
97+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
# Usage: ./compute_build_overhead.sh <program_name>
4+
# Ensure required argument is provided
5+
if [ $# -lt 1 ]; then
6+
echo "Usage: $0 <program_name> "
7+
echo "Supported programs: pdfbox, mcs, ripper, batik, checkstyle, zxing"
8+
exit 1
9+
fi
10+
11+
# Program name passed as an argument
12+
PROGRAM=$1
13+
14+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15+
16+
case $PROGRAM in
17+
pdfbox)
18+
PROJECT_DIR="$SCRIPT_DIR/../projects/pdfbox-3.0.4"
19+
;;
20+
ripper)
21+
PROJECT_DIR="$SCRIPT_DIR/../projects/certificate-ripper-2.4.1"
22+
;;
23+
mcs)
24+
PROJECT_DIR="$SCRIPT_DIR/../projects/mcs-0.7.3"
25+
;;
26+
batik)
27+
PROJECT_DIR="$SCRIPT_DIR/../projects/batikwrapper"
28+
;;
29+
checkstyle)
30+
PROJECT_DIR="$SCRIPT_DIR/../projects/checkstyle-checkstyle-10.23.0"
31+
;;
32+
zxing)
33+
PROJECT_DIR="$SCRIPT_DIR/../projects/zxing-wrapper"
34+
;;
35+
# jacop)
36+
# PROJECT_DIR="$SCRIPT_DIR/../projects/jacop-4.10.0/target/jacop-4.10.0.jar"
37+
# ;;
38+
39+
# ttorrent)
40+
# PROJECT_DIR="$SCRIPT_DIR/../projects/ttorrent-ttorrent-1.5/cli/target/ttorrent-cli-1.5-shaded.jar"
41+
# ;;
42+
# graph)
43+
# PROJECT_DIR="$SCRIPT_DIR/../projects/graphhopper/graphhopper/web/target/graphhopper-web-9.1.jar"
44+
# ;;
45+
# commons)
46+
# PROJECT_DIR="$SCRIPT_DIR/../projects/commons-validator-1.9.0-src/target/commons-validator-1.9.0.jar"
47+
# ;;
48+
*)
49+
echo "Error: Unsupported program '$PROGRAM'"
50+
echo "Supported programs: pdfbox, checkstyle"
51+
exit 1
52+
;;
53+
esac
54+
55+
case $PROGRAM in
56+
pdfbox)
57+
POM_FILE="app/pom.xml"
58+
;;
59+
*)
60+
POM_FILE="pom.xml"
61+
;;
62+
esac
63+
64+
cd "$PROJECT_DIR" || exit 1
65+
# Measure baseline build time
66+
echo "Measuring baseline build time..."
67+
BASELINE_TIME=$( { time mvn clean package -DskipTests; } 2>&1 | grep real | awk '{print $2}' )
68+
69+
cp $PROJECT_DIR/$POM_FILE $PROJECT_DIR/$POM_FILE.bak
70+
71+
echo "Adding classport-maven-plugin to pom.xml..."
72+
"$SCRIPT_DIR/add_classport_plugin.sh" $PROJECT_DIR/$POM_FILE
73+
74+
# Measure plugin execution time
75+
echo "Measuring plugin execution time..."
76+
PLUGIN_TIME=$( { time mvn clean package -DskipTests; } 2>&1 | grep real | awk '{print $2}' )
77+
78+
mv $PROJECT_DIR/$POM_FILE.bak $PROJECT_DIR/$POM_FILE
79+
80+
81+
# Convert times to seconds
82+
BASELINE_SECONDS=$(echo $BASELINE_TIME | awk -Fm '{print $1 * 60 + $2}')
83+
PLUGIN_SECONDS=$(echo $PLUGIN_TIME | awk -Fm '{print $1 * 60 + $2}')
84+
85+
# Compute overhead
86+
OVERHEAD=$(echo "$PLUGIN_SECONDS - $BASELINE_SECONDS" | bc)
87+
PERCENTAGE_OVERHEAD=$(echo "scale=2; ($OVERHEAD / $BASELINE_SECONDS) * 100" | bc)
88+
89+
echo "Baseline build time: $BASELINE_TIME"
90+
echo "Plugin execution time: $PLUGIN_TIME"
91+
echo "Overhead introduced by the plugin: ${OVERHEAD}s"
92+
echo "Percentage overhead: ${PERCENTAGE_OVERHEAD}%"
93+
Submodule pdfbox-3.0.4 added at 332d161

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "classport-experiments"]
22
path = classport-experiments
33
url = [email protected]:chains-project/classport-experiments.git
4+
[submodule ".github/workflows/projects/pdfbox-3.0.4"]
5+
path = .github/workflows/projects/pdfbox-3.0.4
6+
url = https://github.com/apache/pdfbox.git

0 commit comments

Comments
 (0)