Skip to content

Commit

Permalink
Consistent target JVM version for all defect builds (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjust authored Nov 27, 2024
1 parent d062ed6 commit 8bb959b
Show file tree
Hide file tree
Showing 88 changed files with 502 additions and 5,637 deletions.
40 changes: 23 additions & 17 deletions framework/core/Project/Cli.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,24 @@ sub determine_layout {
#
sub _post_checkout {
my ($self, $rev_id, $work_dir) = @_;
my $vid = $self->{_vcs}->lookup_vid($rev_id);

my $bid = Utils::get_bid($work_dir);

# Fix compilation errors if necessary.
# Run this as the first step to ensure that patches are applicable to
# unmodified source files.
my $compile_errors = "$PROJECTS_DIR/$self->{pid}/compile-errors/";
opendir(DIR, $compile_errors) or die "Could not find compile-errors directory.";
my @entries = readdir(DIR);
closedir(DIR);
foreach my $file (@entries) {
if ($file =~ /-(\d+)-(\d+).diff/) {
if ($bid >= $1 && $bid <= $2) {
$self->apply_patch($work_dir, "$compile_errors/$file")
or confess("Couldn't apply patch ($file): $!");
}
}
}

my $project_dir = "$PROJECTS_DIR/$self->{pid}";
# Check whether ant build file exists
Expand All @@ -94,6 +111,9 @@ sub _post_checkout {
}
}

# Set source and target version in javac targets.
my $jvm_version="1.6";

# CommonsCLI uses "compile-tests" instead of "compile.test" as a target name.
# Replace all instances of "compile-tests" with "compile.test".
# They also use "build.classpath" instead of "compile.classpath".
Expand All @@ -104,6 +124,8 @@ sub _post_checkout {
open(IN, '<'."$work_dir/build.xml".'.bak') or die $!;
open(OUT, '>'."$work_dir/build.xml") or die $!;
while(<IN>) {
$_ =~ s/javac destdir="\$\{classesdir\}" deprecation="true"/javac destdir="\$\{classesdir\}" target="${jvm_version}" source="${jvm_version}" deprecation="true"/g;
$_ =~ s/javac destdir="\$\{testclassesdir\}" deprecation="true"/javac destdir="\$\{testclassesdir\}" target="${jvm_version}" source="${jvm_version}" deprecation="true"/g;
$_ =~ s/compile-tests/compile\.tests/g;
$_ =~ s/build\.classpath/compile\.classpath/g;
$_ =~ s/classesdir/classes\.dir/g;
Expand Down Expand Up @@ -146,22 +168,6 @@ sub _post_checkout {
print OUT $converted_file;
close(OUT);
}

# Fix compilation errors if necessary.
# Run this as the first step to ensure that patches are applicable to
# unmodified source files.
my $compile_errors = "$PROJECTS_DIR/$self->{pid}/compile-errors/";
opendir(DIR, $compile_errors) or die "Could not find compile-errors directory.";
my @entries = readdir(DIR);
closedir(DIR);
foreach my $file (@entries) {
if ($file =~ /-(\d+)-(\d+).diff/) {
if ($vid >= $1 && $vid <= $2) {
$self->apply_patch($work_dir, "$compile_errors/$file")
or confess("Couldn't apply patch ($file): $!");
}
}
}
}

#
Expand Down
47 changes: 23 additions & 24 deletions framework/core/Project/Closure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,15 @@ sub determine_layout {
sub _post_checkout {
@_ == 3 or die $ARG_ERROR;
my ($self, $rev_id, $work_dir) = @_;
# get original bid
my $bid;
if (-e "$work_dir/$CONFIG") {
my $config = Utils::read_config_file("$work_dir/$CONFIG");
if (defined $config) {
$bid = $config->{$CONFIG_VID};
} else { die "no .config file"; }
} else { die "no .config file"; }
chop($bid);

open FH, "$work_dir/build.xml" or die $!;
my $build_file = do { local $/; <FH> };
close FH;

$build_file =~ s/debug=".*"//g;
$build_file =~ s/<javac (.*)/<javac debug="true" $1/g;

open FH, ">$work_dir/build.xml" or die $!;
print FH $build_file;
close FH;
my $bid = Utils::get_bid($work_dir);

# Fix compilation errors if necessary
my $compile_errors = "$PROJECTS_DIR/$self->{pid}/compile-errors/";
opendir(DIR, $compile_errors) or die "Could not find compile-errors directory.";
my @entries = readdir(DIR);
closedir(DIR);
foreach my $file (@entries) {

if ($file =~ /-(\d+)-(\d+).diff/) {
if ($bid >= $1 && $bid <= $2) {
$self->apply_patch($work_dir, "$compile_errors/$file")
Expand All @@ -104,13 +85,31 @@ sub _post_checkout {
}
}

open FH, "$work_dir/build.xml" or die $!;
my $build_file = do { local $/; <FH> };
close FH;

$build_file =~ s/debug=".*"//g;
$build_file =~ s/<javac (.*)/<javac debug="true" $1/g;

# Set source and target version in javac targets.
my $jvm_version = "1.6";

unless ($build_file =~ m/<property name="ant.build.javac.source"/) {
$build_file =~ s/(<project name="compiler"[^>]+>)/$1\n<property name="ant.build.javac.target" value="${jvm_version}"\/>\n<property name="ant.build.javac.source" value="${jvm_version}"\/>/s;
}

open FH, ">$work_dir/build.xml" or die $!;
print FH $build_file;
close FH;

# Set default Java target to 6.
# either these:
Utils::sed_cmd("s/source-level: 1\.[1-5]/source-level 1.6/", "$work_dir/lib/rhino/build.properties");
Utils::sed_cmd("s/target-jvm: 1\.[1-5]/target-jvm 1.6/", "$work_dir/lib/rhino/build.properties");
Utils::sed_cmd("s/source-level: 1\.[1-5]/source-level ${jvm_version}/", "$work_dir/lib/rhino/build.properties");
Utils::sed_cmd("s/target-jvm: 1\.[1-5]/target-jvm ${jvm_version}/", "$work_dir/lib/rhino/build.properties");
# or these:
Utils::sed_cmd("s/source-level: 1\.[1-5]/source-level 1.6/", "$work_dir/lib/rhino/src/mozilla/js/rhino/build.properties");
Utils::sed_cmd("s/target-jvm: 1\.[1-5]/target-jvm 1.6/", "$work_dir/lib/rhino/src/mozilla/js/rhino/build.properties");
Utils::sed_cmd("s/source-level: 1\.[1-5]/source-level ${jvm_version}/", "$work_dir/lib/rhino/src/mozilla/js/rhino/build.properties");
Utils::sed_cmd("s/target-jvm: 1\.[1-5]/target-jvm ${jvm_version}/", "$work_dir/lib/rhino/src/mozilla/js/rhino/build.properties");
}

1;
21 changes: 18 additions & 3 deletions framework/core/Project/Codec.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,23 @@ sub determine_layout {
sub _post_checkout {
my ($self, $rev_id, $work_dir) = @_;

my $project_dir = "$PROJECTS_DIR/$self->{pid}";
# Check whether ant build file exists
unless (-e "$work_dir/build.xml") {
# Set source and target version in javac targets.
my $jvm_version="1.6";

if (-e "$work_dir/build.xml") {
rename("$work_dir/build.xml", "$work_dir/build.xml.bak");
open(IN, "<$work_dir/build.xml.bak") or die $!;
open(OUT, ">$work_dir/build.xml") or die $!;
while(<IN>) {
my $l = $_;
$l =~ s/(<javac srcdir="\$\{source.home\}" destdir="\$\{build.home\}\/classes" debug="\$\{compile.debug\}")/$1 target="${jvm_version}" source="${jvm_version}"/g;
$l =~ s/(<javac srcdir="\$\{test.home\}" destdir="\$\{build.home\}\/classes" debug="\$\{compile.debug\}")/$1 target="${jvm_version}" source="${jvm_version}"/g;

print OUT $l;
}
close(IN);
close(OUT);
} else {
my $build_files_dir = "$PROJECTS_DIR/$PID/build_files/$rev_id";
if (-d "$build_files_dir") {
Utils::exec_cmd("cp -r $build_files_dir/* $work_dir", "Copy generated Ant build file") or die;
Expand All @@ -101,6 +115,7 @@ sub _post_checkout {
Utils::convert_file_encoding($work_dir."/".$result->{test}."/org/apache/commons/codec/language/SoundexTest.java");

# Copy in a missing dependency
my $project_dir = "$PROJECTS_DIR/$self->{pid}";
if (-d $work_dir."/src/main/resources"){
copy("$project_dir/lib/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar", $work_dir."/src/main/resources/commons-lang3-3.8.1.jar");
if (-e $work_dir."/build.xml"){
Expand Down
24 changes: 20 additions & 4 deletions framework/core/Project/Collections.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ sub determine_layout {
#
sub _post_checkout {
my ($self, $rev_id, $work_dir) = @_;
my $vid = $self->{_vcs}->lookup_vid($rev_id);

my $bid = Utils::get_bid($work_dir);

# Fix compilation errors if necessary.
# Run this as the first step to ensure that patches are applicable to
Expand All @@ -94,15 +95,30 @@ sub _post_checkout {
closedir(DIR);
foreach my $file (@entries) {
if ($file =~ /-(\d+)-(\d+).diff/) {
if ($vid >= $1 && $vid <= $2) {
if ($bid >= $1 && $bid <= $2) {
$self->apply_patch($work_dir, "$compile_errors/$file")
or die("Couldn't apply patch ($file): $!");
}
}
}

# Check whether ant build file exists
unless (-e "$work_dir/build.xml") {
# Set source and target version in javac targets.
my $jvm_version="1.6";

if (-e "$work_dir/build.xml") {
rename("$work_dir/build.xml", "$work_dir/build.xml.bak");
open(IN, "<$work_dir/build.xml.bak") or die $!;
open(OUT, ">$work_dir/build.xml") or die $!;
while(<IN>) {
my $l = $_;
$l =~ s/(<javac srcdir="\$\{source.test\}")/$1 target="${jvm_version}" source="${jvm_version}"/g;
$l =~ s/(<javac srcdir="\$\{source.java\}")/$1 target="${jvm_version}" source="${jvm_version}"/g;

print OUT $l;
}
close(IN);
close(OUT);
} else {
my $build_files_dir = "$PROJECTS_DIR/$PID/build_files/$rev_id";
if (-d "$build_files_dir") {
Utils::exec_cmd("cp -r $build_files_dir/* $work_dir", "Copy generated Ant build file") or die;
Expand Down
12 changes: 2 additions & 10 deletions framework/core/Project/Gson.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,11 @@ sub new {
sub _post_checkout {
my ($self, $rev_id, $work_dir) = @_;

my $bid = Utils::get_bid($work_dir);

# All relevant files live in the gson subdirectory
$work_dir .= "/gson/";

# get original bid
my $bid;
if (-e "$work_dir/../$CONFIG") {
my $config = Utils::read_config_file("$work_dir/../$CONFIG");
if (defined $config) {
$bid = $config->{$CONFIG_VID};
} else { die "no .config file"; }
} else { die "no .config file"; }
chop($bid);

# Fix compilation errors if necessary.
# Run this as the first step to ensure that patches are applicable to
# unmodified source files.
Expand Down
5 changes: 3 additions & 2 deletions framework/core/Project/JacksonDatabind.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ sub new {
#
sub _post_checkout {
my ($self, $rev_id, $work_dir) = @_;
my $vid = $self->{_vcs}->lookup_vid($rev_id);

my $bid = Utils::get_bid($work_dir);

# Fix compilation errors if necessary
my $compile_errors = "$PROJECTS_DIR/$self->{pid}/compile-errors/";
Expand All @@ -73,7 +74,7 @@ sub _post_checkout {
foreach my $file (@entries) {
if ($file =~ /-(\d+)-(\d+)(.optional)?.diff/) {
my $opt = $3;
if ($vid >= $1 && $vid <= $2) {
if ($bid >= $1 && $bid <= $2) {
my $ret = $self->apply_patch($work_dir, "$compile_errors/$file", $opt);
if (!$ret && !$opt) {
confess("Couldn't apply patch ($file): $!");
Expand Down
12 changes: 9 additions & 3 deletions framework/core/Project/JxPath.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ sub determine_layout {
#
sub _post_checkout {
my ($self, $rev_id, $work_dir) = @_;
my $vid = $self->{_vcs}->lookup_vid($rev_id);
my $project_dir = "$PROJECTS_DIR/$self->{pid}";

my $bid = Utils::get_bid($work_dir);

# Fix compilation errors if necessary.
# Run this as the first step to ensure that patches are applicable to
Expand All @@ -95,7 +95,7 @@ sub _post_checkout {
closedir(DIR);
foreach my $file (@entries) {
if ($file =~ /-(\d+)-(\d+).diff/) {
if ($vid >= $1 && $vid <= $2) {
if ($bid >= $1 && $bid <= $2) {
$self->apply_patch($work_dir, "$compile_errors/$file")
or die("Couldn't apply patch ($file): $!");
}
Expand All @@ -111,10 +111,14 @@ sub _post_checkout {
}

# Copy in a missing dependency
my $project_dir = "$PROJECTS_DIR/$self->{pid}";
mkdir $work_dir."/target";
mkdir $work_dir."/target/lib";
copy($project_dir."/lib/mockrunner-0.4.1.jar", $work_dir."/target/lib/mockrunner-0.4.1.jar") or die "Copy failed: $!";

# Set source and target version in javac targets.
my $jvm_version="1.6";

# JxPath uses "compile-tests" instead of "compile.test" as a target name.
# Replace all instances of "compile-tests" with "compile.test".
# They also use "build.classpath" instead of "compile.classpath".
Expand All @@ -125,6 +129,8 @@ sub _post_checkout {
open(IN, '<'."$work_dir/build.xml".'.bak') or die $!;
open(OUT, '>'."$work_dir/build.xml") or die $!;
while(<IN>) {
$_ =~ s/javac destdir="\$\{classesdir\}" deprecation="true"/javac destdir="\$\{classesdir\}" target="${jvm_version}" source="${jvm_version}" deprecation="true"/g;
$_ =~ s/javac destdir="\$\{testclassesdir\}" deprecation="true"/javac destdir="\$\{testclassesdir\}" target="${jvm_version}" source="${jvm_version}" deprecation="true"/g;
$_ =~ s/compile-tests/compile\.tests/g;
$_ =~ s/classesdir/classes\.dir/g;
$_ =~ s/testclasses\.dir/test\.classes\.dir/g;
Expand Down
10 changes: 1 addition & 9 deletions framework/core/Project/Lang.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,7 @@ sub determine_layout {
sub _post_checkout {
my ($self, $revision_id, $work_dir) = @_;

# get original bid
my $bid;
if (-e "$work_dir/$CONFIG") {
my $config = Utils::read_config_file("$work_dir/$CONFIG");
if (defined $config) {
$bid = $config->{$CONFIG_VID};
} else { die "no .config file"; }
} else { die "no .config file"; }
chop($bid);
my $bid = Utils::get_bid($work_dir);

# Fix compilation errors if necessary.
# Run this as the first step to ensure that patches are applicable to
Expand Down
21 changes: 18 additions & 3 deletions framework/core/Project/Math.pm
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,30 @@ sub _layout2 {

sub _post_checkout {
my ($self, $revision_id, $work_dir) = @_;
my $vid = $self->{_vcs}->lookup_vid($revision_id);

# Convert the file encoding of problematic files
my $result = determine_layout($self, $revision_id);
Utils::convert_file_encoding($work_dir."/".$result->{src}."/org/apache/commons/math3/stat/correlation/StorelessBivariateCovariance.java");
Utils::convert_file_encoding($work_dir."/".$result->{src}."/org/apache/commons/math3/stat/correlation/StorelessCovariance.java");

# Set default Java target to 6.
Utils::sed_cmd("s/value=\\\"1\.[1-5]\\\"/value=\\\"1.6\\\"/", "$work_dir/build.xml");
# Set source and target version in javac targets.
my $jvm_version="1.6";

if (-e "$work_dir/build.xml") {
rename("$work_dir/build.xml", "$work_dir/build.xml.bak");
open(IN, "<$work_dir/build.xml.bak") or die $!;
open(OUT, ">$work_dir/build.xml") or die $!;
while(<IN>) {
my $l = $_;
$l =~ s/(javac destdir="\$\{classesdir\}" deprecation="true")/$1 target="${jvm_version}" source="${jvm_version}"/g;
$l =~ s/(javac destdir="\$\{testclassesdir\}" deprecation="true")/$1 target="${jvm_version}" source="${jvm_version}"/g;
$l =~ s/value="1\.[1-5]"/value="${jvm_version}"/g;

print OUT $l;
}
close(IN);
close(OUT);
}
}

#
Expand Down
10 changes: 6 additions & 4 deletions framework/core/Project/Mockito.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,20 @@ sub _post_checkout {
my ($self, $rev_id, $work_dir) = @_;

# Fix Mockito's test runners
my $vid = $self->{_vcs}->lookup_vid($rev_id);
# TODO: Testing for vids is super brittle! Find a better way to determine

my $bid = Utils::get_bid($work_dir);

# TODO: Testing for bids/vids is super brittle! Find a better way to determine
# whether a test class needs to be patched, or provide a patch for each
# affected revision id.
my $mockito_junit_runner_patch_file = "$PROJECTS_DIR/$PID/mockito_test_runners.patch";
if ($vid == 16 || $vid == 17 || ($vid >= 34 && $vid <= 38)) {
if ($bid == 16 || $bid == 17 || ($bid >= 34 && $bid <= 38)) {
$self->apply_patch($work_dir, "$mockito_junit_runner_patch_file")
or confess("Couldn't apply patch ($mockito_junit_runner_patch_file): $!");
}

# only bid with release notes and doesn't compile with newer Gradle
if ($vid == 21) {
if ($bid == 21) {
system("rm -rf $work_dir/buildSrc/src/main/groovy/org/mockito/release/notes");
system("rm -rf $work_dir/buildSrc/src/test/groovy/org/mockito/release/notes");
Utils::sed_cmd("/apply.from:..gradle.release.gradle./d", "$work_dir/build.gradle");
Expand Down
11 changes: 2 additions & 9 deletions framework/core/Project/Time.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,8 @@ sub new {
sub _post_checkout {
@_ == 3 or die $ARG_ERROR;
my ($self, $rev_id, $work_dir) = @_;
# get original bid
my $bid;
if (-e "$work_dir/$CONFIG") {
my $config = Utils::read_config_file("$work_dir/$CONFIG");
if (defined $config) {
$bid = $config->{$CONFIG_VID};
} else { die "no .config file"; }
} else { die "no .config file"; }
chop($bid);

my $bid = Utils::get_bid($work_dir);

# remove the JodaTime super directory (move things one dir up)
if (-e "$work_dir/JodaTime") {
Expand Down
Loading

0 comments on commit 8bb959b

Please sign in to comment.