Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default Java target to 6 #596

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions framework/core/Project/Cli.pm
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ sub _post_checkout {
print OUT $converted_file;
close(OUT);
}

# Set default Java target to 6.
# either these:
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
# or these:
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/build.xml");
}

#
Expand Down
23 changes: 23 additions & 0 deletions framework/core/Project/Closure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ sub determine_layout {
sub _post_checkout {
@_ == 3 or die $ARG_ERROR;
my ($self, $rev_id, $work_dir) = @_;
my $vid = $self->{_vcs}->lookup_vid($rev_id);

open FH, "$work_dir/build.xml" or die $!;
my $build_file = do { local $/; <FH> };
Expand All @@ -79,6 +80,28 @@ sub _post_checkout {
open FH, ">$work_dir/build.xml" or die $!;
print FH $build_file;
close FH;

# 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 ($vid >= $1 && $vid <= $2) {
$self->apply_patch($work_dir, "$compile_errors/$file")
or confess("Couldn't apply patch ($file): $!");
}
}
}

# 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");
# 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");
}

1;
21 changes: 7 additions & 14 deletions framework/core/Project/Codec.pm
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,10 @@ sub _post_checkout {

# Convert the file encoding of problematic files
my $result = determine_layout($self, $rev_id);
if (-e $work_dir."/".$result->{test}."/org/apache/commons/codec/language/DoubleMetaphoneTest.java"){
rename($work_dir."/".$result->{test}."/org/apache/commons/codec/language/DoubleMetaphoneTest.java", $work_dir."/".$result->{test}."/org/apache/commons/codec/language/DoubleMetaphoneTest.java".".bak");
open(OUT, '>'.$work_dir."/".$result->{test}."/org/apache/commons/codec/language/DoubleMetaphoneTest.java") or die $!;
my $converted_file = `iconv -f iso-8859-1 -t utf-8 $work_dir"/"$result->{test}"/org/apache/commons/codec/language/DoubleMetaphoneTest.java.bak"`;
print OUT $converted_file;
close(OUT);
}
if (-e $work_dir."/".$result->{test}."/org/apache/commons/codec/language/SoundexTest.java"){
rename($work_dir."/".$result->{test}."/org/apache/commons/codec/language/SoundexTest.java", $work_dir."/".$result->{test}."/org/apache/commons/codec/language/SoundexTest.java".".bak");
open(OUT, '>'.$work_dir."/".$result->{test}."/org/apache/commons/codec/language/SoundexTest.java") or die $!;
my $converted_file = `iconv -f iso-8859-1 -t utf-8 $work_dir"/"$result->{test}"/org/apache/commons/codec/language/SoundexTest.java.bak"`;
print OUT $converted_file;
close(OUT);
}
Utils::convert_file_encoding($work_dir."/".$result->{test}."/org/apache/commons/codec/binary/Base64Test.java");
Utils::convert_file_encoding($work_dir."/".$result->{test}."/org/apache/commons/codec/language/ColognePhoneticTest.java");
Utils::convert_file_encoding($work_dir."/".$result->{test}."/org/apache/commons/codec/language/DoubleMetaphoneTest.java");
Utils::convert_file_encoding($work_dir."/".$result->{test}."/org/apache/commons/codec/language/SoundexTest.java");

# Copy in a missing dependency
if (-d $work_dir."/src/main/resources"){
Expand All @@ -125,6 +115,9 @@ sub _post_checkout {
close(OUT);
}
}

# Set default Java target to 6.
Utils::sed_cmd("s/1\.[1-5]/1.6/", "$work_dir/default.properties");
}

#
Expand Down
4 changes: 4 additions & 0 deletions framework/core/Project/Compress.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ sub _post_checkout {
Utils::exec_cmd("cp -r $build_files_dir/* $work_dir", "Copy generated Ant build file") or die;
}
}

# Set default Java target to 6.
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
}

#
Expand Down
4 changes: 4 additions & 0 deletions framework/core/Project/Csv.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ sub _post_checkout {
Utils::exec_cmd("cp -r $build_files_dir/* $work_dir", "Copy generated Ant build file") or die;
}
}

# Set default Java target to 6.
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
}

#
Expand Down
4 changes: 4 additions & 0 deletions framework/core/Project/Gson.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ sub _post_checkout {
Utils::exec_cmd("cp -r $build_files_dir/* $work_dir", "Copy generated Ant build file") or die;
}
}

# Set default Java target to 6.
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
}

#
Expand Down
4 changes: 4 additions & 0 deletions framework/core/Project/Jsoup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ sub _post_checkout {
Utils::exec_cmd("cp -r $build_files_dir/* $work_dir", "Copy generated Ant build file") or die;
}
}

# Set default Java target to 6.
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
}

#
Expand Down
49 changes: 48 additions & 1 deletion framework/core/Project/Lang.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use warnings;

use Constants;
use Vcs::Git;
use File::Path 'rmtree';

our @ISA = qw(Project);
my $PID = "Lang";
Expand Down Expand Up @@ -107,11 +108,57 @@ 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/lang3/text/translate/EntityArrays.java");
Utils::convert_file_encoding($work_dir."/".$result->{src}."/org/apache/commons/lang/Entities.java");

# Some of the Lang tests were created pre Java 1.5 and contain an 'enum' package.
# The is now a reserved word in Java so we convert all references to 'oldenum'.
my $cmd = "grep -lR '\.enum;' $work_dir'/'$result->{src}'/org/apache/commons/lang/enum/'";
my $log = `$cmd`;
my $ret = $?;
if ($ret == 0 && length($log) > 0) {
Utils::exec_cmd("grep -lR '\\.enum;' $work_dir'/'$result->{src}'/org/apache/commons/lang/enum/' | xargs sed -i'.bak' 's/\\.enum;/\\.oldenum;/'", "Rename enum 1") or die;
}

$cmd = "grep -lR '\.enum;' $work_dir'/'$result->{test}'/org/apache/commons/lang/enum/'";
$log = `$cmd`;
$ret = $?;
if ($ret == 0 && length($log) > 0) {
Utils::exec_cmd("grep -lR '\\.enum;' $work_dir'/'$result->{test}'/org/apache/commons/lang/enum/' | xargs sed -i'.bak' 's/\\.enum;/\\.oldenum;/'", "Rename enum 2") or die;
}

# 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 ($vid >= $1 && $vid <= $2) {
$self->apply_patch($work_dir, "$compile_errors/$file")
or confess("Couldn't apply patch ($file): $!");
}
}
}

# Check whether ant build file exists
unless (-e "$work_dir/build.xml") {
system("cp $PROJECTS_DIR/$PID/build_files/$revision_id/* $work_dir");
my $build_files_dir = "$PROJECTS_DIR/$PID/build_files/$revision_id";
if (-d "$build_files_dir") {
Utils::exec_cmd("cp -r $build_files_dir/* $work_dir", "Copy generated Ant build file") or die;
}
}

# Set default Java target to 6.
# either these:
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
# or this
Utils::sed_cmd("s/1\.[1-5]/1.6/", "$work_dir/default.properties");
}

#
Expand Down
16 changes: 15 additions & 1 deletion framework/core/Project/Math.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ sub new {
my $name = "commons-math";
my $vcs = Vcs::Git->new($PID,
"$REPO_DIR/$name.git",
"$PROJECTS_DIR/$PID/$BUGS_CSV_ACTIVE");
"$PROJECTS_DIR/$PID/$BUGS_CSV_ACTIVE",
\&_post_checkout);

return $class->SUPER::new($PID, $name, $vcs);
}
Expand Down Expand Up @@ -101,6 +102,19 @@ sub _layout2 {
return {src=>$src, test=>$test};
}

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");
}

#
# Remove looping tests in addition to the broken ones
#
Expand Down
12 changes: 10 additions & 2 deletions framework/core/Project/Mockito.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ sub _post_checkout {
system("sed -i.bak s/org.gradle.daemon=true/org.gradle.daemon=false/g \"$work_dir/gradle.properties\"");
}

# Enable local repository
system("find $work_dir -type f -name \"build.gradle\" -exec sed -i.bak 's|jcenter()|maven { url \"$BUILD_SYSTEMS_LIB_DIR/gradle/deps\" }\\\n maven { url \"https://jcenter.bintray.com/\" }\\\n|g' {} \\;");
# Set default Java target to 6.
# some bids use gradle:
Utils::sed_cmd("s/sourceCompatibility = 1\.[1-5]/sourceCompatibility=1.6/", "$work_dir/build.gradle");
Utils::sed_cmd("s/targetCompatibility = 1\.[1-5]/targetCompatibility=1.6/", "$work_dir/build.gradle");
Utils::sed_cmd("s/gradle-1.12-bin/gradle-4.9-bin/", "$work_dir/gradle/wrapper/gradle-wrapper.properties");
Utils::sed_cmd("s/gradle-2.2.1-all/gradle-4.9-bin/", "$work_dir/gradle/wrapper/gradle-wrapper.properties");
Utils::sed_cmd("s/0.7-groovy-1.8/1.1-groovy-2.4/", "$work_dir/buildSrc/build.gradle");
# and some don't:
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/build.xml");
}

sub determine_layout {
Expand Down
8 changes: 8 additions & 0 deletions framework/core/Project/Time.pm
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ sub _post_checkout {
Utils::exec_cmd("cp $filename $work_dir/build.xml",
"Fix broken build") or die;
}

# Set default Java target to 6.
# either these:
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/maven-build.xml");
# or these:
Utils::sed_cmd("s/source=\\\"1\.[1-5]\\\"/source=\\\"1.6\\\"/", "$work_dir/build.xml");
Utils::sed_cmd("s/target=\\\"1\.[1-5]\\\"/target=\\\"1.6\\\"/", "$work_dir/build.xml");
}

sub determine_layout {
Expand Down
65 changes: 64 additions & 1 deletion framework/core/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,69 @@ sub print_env {

=pod

=item C<Utils::print_perl_call_stack>

Print the current Perl execution stack trace to F<stderr>.

=cut

sub print_perl_call_stack {
my ($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash);
my $i = 1;
my @r;
while (@r = caller($i)) {
($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash) = @r;
print(STDERR "$filename:$line $subroutine\n");
$i++;
}
}

=pod

=item C<Utils::convert_file_encoding(file_name)>

Copies the original file to <file_name>.bak then converts
the encoding of file_name from iso-8859-1 to utf-8.

=cut

sub convert_file_encoding {
@_ == 1 or die $ARG_ERROR;
my ($file_name) = @_;
if (-e $file_name){
rename($file_name, $file_name.".bak");
open(OUT, '>'.$file_name) or die $!;
my $converted_file = `iconv -f iso-8859-1 -t utf-8 $file_name.bak`;
print OUT $converted_file;
close(OUT);
}
}

=pod

=item C<Utils::sed_cmd(cmd_string, file_name)>

Uses sed with cmd_string to modify file_name.

=cut

sub sed_cmd {
@_ == 2 || die $ARG_ERROR;
my ($cmd_string, $file_name) = @_;

print(STDERR "About to execute command: sed -i $cmd_string $file_name\n") if $DEBUG;

# We ignore sed result as it is ok if command fails.
chomp(my $uname = `uname -s`);
if ($uname eq "Darwin" ) {
`sed -i '' -e '$cmd_string' $file_name`;
} else {
`sed -i "$cmd_string" "$file_name"`;
}
}

=pod

=item C<Utils::is_continuous_integration>

Returns true if this process is running under continuous integration.
Expand Down Expand Up @@ -342,7 +405,7 @@ sub fix_dependency_urls {
exec_cmd("cp $build_file $build_file.bak", "Backing up build file: $build_file");
$modified = 1;
}
print(STDERR "Pattern matches in build file ($build_file): $$_[0]\n");
print(STDERR "Pattern matches in build file ($build_file): $$_[0]\n") if $DEBUG;
$lines[$i] = $l;
last;
}
Expand Down
25 changes: 25 additions & 0 deletions framework/core/Vcs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,34 @@ sub _apply_cmd {
$log .= "* $cmd\n";
$log .= `$cmd`;
if ($? == 0) {
print(STDERR "patch applied: $patch_file\n") if $DEBUG;
return("cd $work_dir; git apply -p$n $patch_file 2>&1");
}
}
# The code above checks for an exact match before patching
# but if we're patching to fix compile errors, because of using
# newer versions of the JDK, we want to use a 'fuzzy' match.
# Also, if a 'compile-errors' patch doesn't apply, we skip
# it rather than report an error. This allows us to significantly
# reduce the number of unique patches in the compile-errors directory.
if (index($patch_file, "compile-errors") != -1) {
# We have a 'compile-errors' patch. Reset the log file.
$log = "";
my $cmd = "cd $work_dir; patch -p1 --dry-run -l < $patch_file 2>&1";
$log .= "* $cmd\n";
#print "\nlog: $log\n\n";
$log .= `$cmd`;
if ($? == 0) {
print(STDERR "patch applied: $patch_file\n") if $DEBUG;
return("cd $work_dir; patch -p1 -l < $patch_file 2>&1");
} else {
#print "\nlog: $log\n\n";
# Patch doesn't apply, just skip it.
print(STDERR "patch skipped: $patch_file\n") if $DEBUG;
return("echo patch skipped");
}
}

confess("Cannot determine how to apply patch!\n" .
"All attempts failed:\n$log" . "-" x 70 . "\n");
}
Expand Down
Loading
Loading