Skip to content

Commit

Permalink
Check whether repos and dependencies are up to date.
Browse files Browse the repository at this point in the history
  • Loading branch information
rjust committed Sep 10, 2024
1 parent 844b35c commit b4ed5bb
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 148 deletions.
15 changes: 11 additions & 4 deletions framework/core/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,29 @@ if ($java_version_output =~ 'version "?(?:1\.)?(\K\d+)') {
# - External libraries (test generation) available?
#
_repos_available()
or die("Couldn't find project repositories! Did you (re)run 'defects4j/init.sh'?\n\n");
or die("Couldn't find up-to-date project repositories! Did you (re)run 'defects4j/init.sh'?\n\n");

-e "$MAJOR_ROOT/bin/ant"
or die("Couldn't find Major mutation framework! Did you (re)run 'defects4j/init.sh'?\n\n");

-d "$TESTGEN_LIB_DIR"
or die("Couldn't find test generation tools! Did you (re)run 'defects4j/init.sh'?\n\n");

-d "$BUILD_SYSTEMS_LIB_DIR"
or die("Couldn't find build system tools! Did you (re)run 'defects4j/init.sh'?\n\n");

-d "$BUILD_SYSTEMS_LIB_DIR/gradle/dists"
or die("Couldn't find gradle distributions! Did you (re)run 'defects4j/init.sh'?\n\n");

-d "$BUILD_SYSTEMS_LIB_DIR/gradle/deps"
or die("Couldn't find gradle dependencies! Did you (re)run 'defects4j/init.sh'?\n\n");

sub _repos_available {
opendir(my $dh, "$REPO_DIR") or die "Cannot read $REPO_DIR: $!";
# The repos directory by default only contains a helper script
return scalar(grep { $_ ne "." && $_ ne ".." } readdir($dh)) > 1;
-e "$REPO_DIR/README" or return 0;
open(IN, "<$REPO_DIR/README") or return 0;
my $line = <IN>;
close(IN);
$line =~ /Defects4J version 3/ or return 0;
}

# Add script and core directory to @INC
Expand Down
247 changes: 131 additions & 116 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,143 @@
# immediately
set -e
#

################################################################################
# This script initializes Defects4J. In particular, it downloads and sets up:
# - the project's version control repositories
# - the Major mutation framework
# - the supported test generation tools
# - the supported code coverage tools (TODO)
################################################################################
main() {
############################################################################
#
# Download project repositories if necessary
#
echo "Setting up project repositories ... "
cd "$DIR_REPOS" && ./get_repos.sh

############################################################################
#
# Download Major
#
# Adapt Major's default wrapper scripts:
# - set headless to true to support Chart on machines without X.
# - do not mutate code unless an MML is specified (for historical reasons,
# major v1 was sometimes called without specifying an MML to simply act as
# javac; Major v2+'s default is to generate all mutants as opposed to none).
#
echo
echo "Setting up Major ... "
MAJOR_VERSION="3.0.1"
MAJOR_URL="https://mutation-testing.org/downloads"
MAJOR_ZIP="major-${MAJOR_VERSION}_jre11.zip"
cd "$BASE" && rm -rf major \
&& download_url_and_unzip "$MAJOR_URL/$MAJOR_ZIP" \
&& rm "$MAJOR_ZIP" \
&& perl -pi -e '$_ .= qq( -Djava.awt.headless=true \\\n -Djava.locale.providers=COMPAT \\\n) if /CodeCacheSize/' \
major/bin/ant \
&& perl -pi -e '$_ .= qq(\nif [ -z "\$MML" ]; then javac \$*; exit \$?; fi\n) if /REFACTOR=/' \
major/bin/major \

############################################################################
#
# Download EvoSuite
#
echo
echo "Setting up EvoSuite ... "
EVOSUITE_VERSION="1.1.0"
EVOSUITE_URL="https://github.com/EvoSuite/evosuite/releases/download/v${EVOSUITE_VERSION}"
EVOSUITE_JAR="evosuite-${EVOSUITE_VERSION}.jar"
EVOSUITE_RT_JAR="evosuite-standalone-runtime-${EVOSUITE_VERSION}.jar"
cd "$DIR_LIB_GEN" && download_url "$EVOSUITE_URL/$EVOSUITE_JAR"
cd "$DIR_LIB_RT" && download_url "$EVOSUITE_URL/$EVOSUITE_RT_JAR"
# Set symlinks for the supported version of EvoSuite
(cd "$DIR_LIB_GEN" && ln -sf "$EVOSUITE_JAR" "evosuite-current.jar")
(cd "$DIR_LIB_RT" && ln -sf "$EVOSUITE_RT_JAR" "evosuite-rt.jar")

############################################################################
#
# Download Randoop
#
echo
echo "Setting up Randoop ... "
RANDOOP_VERSION="4.3.3"
RANDOOP_URL="https://github.com/randoop/randoop/releases/download/v${RANDOOP_VERSION}"
RANDOOP_ZIP="randoop-${RANDOOP_VERSION}.zip"
RANDOOP_JAR="randoop-all-${RANDOOP_VERSION}.jar"
REPLACECALL_JAR="replacecall-${RANDOOP_VERSION}.jar"
COVEREDCLASS_JAR="covered-class-${RANDOOP_VERSION}.jar"
(cd "$DIR_LIB_GEN" && download_url_and_unzip "$RANDOOP_URL/$RANDOOP_ZIP")
# Set symlink for the supported version of Randoop
(cd "$DIR_LIB_GEN" && ln -sf "randoop-${RANDOOP_VERSION}/$RANDOOP_JAR" "randoop-current.jar")
(cd "$DIR_LIB_GEN" && ln -sf "randoop-${RANDOOP_VERSION}/$REPLACECALL_JAR" "replacecall-current.jar")
(cd "$DIR_LIB_GEN" && ln -sf "randoop-${RANDOOP_VERSION}/$COVEREDCLASS_JAR" "covered-class-current.jar")
(cd "$DIR_LIB_GEN" && ln -sf "randoop-${RANDOOP_VERSION}/jacocoagent.jar" "jacocoagent.jar")

############################################################################
#
# Download build system dependencies
#
echo
echo "Setting up Gradle dependencies ... "

cd "$DIR_LIB_GRADLE"

GRADLE_DISTS_ZIP=defects4j-gradle-dists-v3.zip
GRADLE_DEPS_ZIP=defects4j-gradle-deps-v3.zip

old_dists_ts=0
old_deps_ts=0

if [ -e $GRADLE_DISTS_ZIP ]; then
old_dists_ts=$(get_modification_timestamp $GRADLE_DISTS_ZIP)
fi
if [ -e $GRADLE_DEPS_ZIP ]; then
old_deps_ts=$(get_modification_timestamp $GRADLE_DEPS_ZIP)
fi

# Only download archive if the server has a newer file
download_url $HOST_URL/$GRADLE_DISTS_ZIP
download_url $HOST_URL/$GRADLE_DEPS_ZIP
new_dists_ts=$(get_modification_timestamp $GRADLE_DISTS_ZIP)
new_deps_ts=$(get_modification_timestamp $GRADLE_DEPS_ZIP)

# Update gradle distributions/dependencies if a newer archive was available
[ "$old_dists_ts" != "$new_dists_ts" ] && mkdir "dists" && unzip -q -u $GRADLE_DISTS_ZIP -d "dists"
[ "$old_deps_ts" != "$new_deps_ts" ] && unzip -q -u $GRADLE_DEPS_ZIP

cd "$BASE"

############################################################################
#
# Download utility programs
#
echo
echo "Setting up utility programs ... "

BUILD_ANALYZER_VERSION="0.0.1"
BUILD_ANALYZER_JAR=build-analyzer-$BUILD_ANALYZER_VERSION.jar
BUILD_ANALYZER_URL="https://github.com/jose/build-analyzer/releases/download/v$BUILD_ANALYZER_VERSION/$BUILD_ANALYZER_JAR"
BUILD_ANALYZER_JAR_LOCAL="analyzer.jar"
cd "$BASE/framework/lib" && download_url "$BUILD_ANALYZER_URL"
rm -f "$BUILD_ANALYZER_JAR_LOCAL"
ln -s "$BUILD_ANALYZER_JAR" "$BUILD_ANALYZER_JAR_LOCAL"

echo
echo "Defects4J successfully initialized."
echo
echo "|------------------------------------------------------------------------|"
echo "| Defects4J version 3 |"
echo "|------------------------------------------------------------------------|"
echo "| PLEASE READ: |"
echo "| https://github.com/rjust/defects4j/?tab=readme-ov-file#reproducibility |"
echo "|------------------------------------------------------------------------|"
echo "| Major changes: |"
echo "| * Java 11 is required |"
echo "| * |"
echo "|------------------------------------------------------------------------|"
}

# Print an error message and terminate the script.
# Takes one argument, a custom error message.
Expand Down Expand Up @@ -125,119 +255,4 @@ get_modification_timestamp() {
echo "$ts"
}

################################################################################
#
# Download project repositories if necessary
#
echo "Setting up project repositories ... "
cd "$DIR_REPOS" && ./get_repos.sh

################################################################################
#
# Download Major
#
# Adapt Major's default wrapper scripts:
# - set headless to true to support Chart on machines without X.
# - do not mutate code unless an MML is specified (for historical reasons,
# major v1 was sometimes called without specifying an MML to simply act as
# javac; Major v2+'s default is to generate all mutants as opposed to none).
#
echo
echo "Setting up Major ... "
MAJOR_VERSION="3.0.1"
MAJOR_URL="https://mutation-testing.org/downloads"
MAJOR_ZIP="major-${MAJOR_VERSION}_jre11.zip"
cd "$BASE" && rm -rf major \
&& download_url_and_unzip "$MAJOR_URL/$MAJOR_ZIP" \
&& rm "$MAJOR_ZIP" \
&& perl -pi -e '$_ .= qq( -Djava.awt.headless=true \\\n -Djava.locale.providers=COMPAT \\\n) if /CodeCacheSize/' \
major/bin/ant \
&& perl -pi -e '$_ .= qq(\nif [ -z "\$MML" ]; then javac \$*; exit \$?; fi\n) if /REFACTOR=/' \
major/bin/major \

################################################################################
#
# Download EvoSuite
#
echo
echo "Setting up EvoSuite ... "
EVOSUITE_VERSION="1.1.0"
EVOSUITE_URL="https://github.com/EvoSuite/evosuite/releases/download/v${EVOSUITE_VERSION}"
EVOSUITE_JAR="evosuite-${EVOSUITE_VERSION}.jar"
EVOSUITE_RT_JAR="evosuite-standalone-runtime-${EVOSUITE_VERSION}.jar"
cd "$DIR_LIB_GEN" && download_url "$EVOSUITE_URL/$EVOSUITE_JAR"
cd "$DIR_LIB_RT" && download_url "$EVOSUITE_URL/$EVOSUITE_RT_JAR"
# Set symlinks for the supported version of EvoSuite
(cd "$DIR_LIB_GEN" && ln -sf "$EVOSUITE_JAR" "evosuite-current.jar")
(cd "$DIR_LIB_RT" && ln -sf "$EVOSUITE_RT_JAR" "evosuite-rt.jar")

################################################################################
#
# Download Randoop
#
echo
echo "Setting up Randoop ... "
RANDOOP_VERSION="4.3.3"
RANDOOP_URL="https://github.com/randoop/randoop/releases/download/v${RANDOOP_VERSION}"
RANDOOP_ZIP="randoop-${RANDOOP_VERSION}.zip"
RANDOOP_JAR="randoop-all-${RANDOOP_VERSION}.jar"
REPLACECALL_JAR="replacecall-${RANDOOP_VERSION}.jar"
COVEREDCLASS_JAR="covered-class-${RANDOOP_VERSION}.jar"
(cd "$DIR_LIB_GEN" && download_url_and_unzip "$RANDOOP_URL/$RANDOOP_ZIP")
# Set symlink for the supported version of Randoop
(cd "$DIR_LIB_GEN" && ln -sf "randoop-${RANDOOP_VERSION}/$RANDOOP_JAR" "randoop-current.jar")
(cd "$DIR_LIB_GEN" && ln -sf "randoop-${RANDOOP_VERSION}/$REPLACECALL_JAR" "replacecall-current.jar")
(cd "$DIR_LIB_GEN" && ln -sf "randoop-${RANDOOP_VERSION}/$COVEREDCLASS_JAR" "covered-class-current.jar")
(cd "$DIR_LIB_GEN" && ln -sf "randoop-${RANDOOP_VERSION}/jacocoagent.jar" "jacocoagent.jar")

################################################################################
#
# Download build system dependencies
#
echo
echo "Setting up Gradle dependencies ... "

cd "$DIR_LIB_GRADLE"

GRADLE_DISTS_ZIP=defects4j-gradle-dists-v3.zip
GRADLE_DEPS_ZIP=defects4j-gradle-deps-v3.zip

old_dists_ts=0
old_deps_ts=0

if [ -e $GRADLE_DISTS_ZIP ]; then
old_dists_ts=$(get_modification_timestamp $GRADLE_DISTS_ZIP)
fi
if [ -e $GRADLE_DEPS_ZIP ]; then
old_deps_ts=$(get_modification_timestamp $GRADLE_DEPS_ZIP)
fi

# Only download archive if the server has a newer file
download_url $HOST_URL/$GRADLE_DISTS_ZIP
download_url $HOST_URL/$GRADLE_DEPS_ZIP
new_dists_ts=$(get_modification_timestamp $GRADLE_DISTS_ZIP)
new_deps_ts=$(get_modification_timestamp $GRADLE_DEPS_ZIP)

# Update gradle distributions/dependencies if a newer archive was available
[ "$old_dists_ts" != "$new_dists_ts" ] && mkdir "dists" && unzip -q -u $GRADLE_DISTS_ZIP -d "dists"
[ "$old_deps_ts" != "$new_deps_ts" ] && unzip -q -u $GRADLE_DEPS_ZIP

cd "$BASE"

################################################################################
#
# Download utility programs
#
echo
echo "Setting up utility programs ... "

BUILD_ANALYZER_VERSION="0.0.1"
BUILD_ANALYZER_JAR=build-analyzer-$BUILD_ANALYZER_VERSION.jar
BUILD_ANALYZER_URL="https://github.com/jose/build-analyzer/releases/download/v$BUILD_ANALYZER_VERSION/$BUILD_ANALYZER_JAR"
BUILD_ANALYZER_JAR_LOCAL="analyzer.jar"
cd "$BASE/framework/lib" && download_url "$BUILD_ANALYZER_URL"
rm -f "$BUILD_ANALYZER_JAR_LOCAL"
ln -s "$BUILD_ANALYZER_JAR" "$BUILD_ANALYZER_JAR_LOCAL"

echo
echo "Defects4J successfully initialized."
main
64 changes: 36 additions & 28 deletions project_repos/get_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ set -e
# The name of the archive that contains all project repos
ARCHIVE=defects4j-repos-v3.zip

main() {
# The BSD version of stat does not support --version or -c
if stat --version &> /dev/null; then
# GNU version
cmd="stat -c %Y $ARCHIVE"
else
# BSD version
cmd="stat -f %m $ARCHIVE"
fi

if [ -e $ARCHIVE ]; then
old=$($cmd)
else
old=0
fi
# Only download repos if the server has a newer file
download_url "https://defects4j.org/downloads/$ARCHIVE"

new=$($cmd)

# Exit if no newer file is available
[ "$old" == "$new" ] && exit 0

# Remove old files
clean

# Extract new repos
unzip -q -u $ARCHIVE && mv defects4j/project_repos/* . && rm -r defects4j
}

clean() {
rm -rf \
closure-compiler.git \
Expand All @@ -19,11 +49,15 @@ clean() {
gson.git \
jackson-core.git \
jackson-databind.git \
jackson-dataformat-xml \
jackson-dataformat-xml.git \
jfreechart \
jfreechart.git \
joda-time.git \
jsoup.git \
mockito.git \
defects4j-repos.zip \
repos.csv \
sync.sh \
README
}

Expand All @@ -44,30 +78,4 @@ download_url() {
fi
}

# The BSD version of stat does not support --version or -c
if stat --version &> /dev/null; then
# GNU version
cmd="stat -c %Y $ARCHIVE"
else
# BSD version
cmd="stat -f %m $ARCHIVE"
fi

if [ -e $ARCHIVE ]; then
old=$($cmd)
else
old=0
fi
# Only download repos if the server has a newer file
download_url "https://defects4j.org/downloads/$ARCHIVE"

new=$($cmd)

# Exit if no newer file is available
[ "$old" == "$new" ] && exit 0

# Remove old files
clean

# Extract new repos
unzip -q -u $ARCHIVE && mv defects4j/project_repos/* . && rm -r defects4j
main

0 comments on commit b4ed5bb

Please sign in to comment.