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

Update Lang project for Java 11 #541

Merged
merged 5 commits into from
Nov 29, 2023
Merged
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
81 changes: 42 additions & 39 deletions 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 All @@ -61,56 +62,58 @@ sub new {
#
sub determine_layout {
@_ == 2 or die $ARG_ERROR;
my ($self, $rev_id) = @_;
my $dir = $self->{prog_root};
my $result = _layout1($dir) // _layout2($dir);
die "Unknown layout for revision: ${rev_id}" unless defined $result;
return $result;
}

#
# Existing Ant build.xml and default.properties
#
sub _layout1 {
@_ == 1 or die $ARG_ERROR;
my ($dir) = @_;
my $src = `grep "source.home" $dir/default.properties 2>/dev/null`;
my $test = `grep "test.home" $dir/default.properties 2>/dev/null`;
my ($self, $revision_id) = @_;
my $work_dir = $self->{prog_root};

return undef if ($src eq "" || $test eq "");

$src =~ s/\s*source.home\s*=\s*(\S+)\s*/$1/;
$test=~ s/\s*test.home\s*=\s*(\S+)\s*/$1/;

return {src=>$src, test=>$test};
}

#
# Generated build.xml (from mvn ant:ant) with maven-build.properties
#
sub _layout2 {
@_ == 1 or die $ARG_ERROR;
my ($dir) = @_;
my $src = `grep "maven.build.srcDir.0" $dir/maven-build.properties 2>/dev/null`;
my $test = `grep "maven.build.testDir.0" $dir/maven-build.properties 2>/dev/null`;

return undef if ($src eq "" || $test eq "");

$src =~ s/\s*maven\.build\.srcDir\.0\s*=\s*(\S+)\s*/$1/;
$test=~ s/\s*maven\.build\.testDir\.0\s*=\s*(\S+)\s*/$1/;

return {src=>$src, test=>$test};
# Only two sets of layouts in this case
my $result;
if (-e "$work_dir/src/main"){
$result = {src=>"src/main/java", test=>"src/test/java"};
}
if (-e "$work_dir/src/java"){
$result = {src=>"src/java", test=>"src/test"};
}
die "Unknown layout for revision: ${revision_id}" unless defined $result;
return $result;
}

#
# Copy the generated build.xml, if necessary.
#
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");

# remove old pre Java 1.5 code
print($work_dir."/".$result->{src}."/org/apache/commons/lang/enum\n");
rmtree($work_dir."/".$result->{src}."/org/apache/commons/lang/enum");
rmtree($work_dir."/".$result->{test}."/org/apache/commons/lang/enum");

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

Expand Down
2 changes: 0 additions & 2 deletions framework/projects/Lang/active-bugs.csv
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ bug.id,revision.id.buggy,revision.id.fixed,report.id,report.url
22,7e8d044b7b8c6d2786a88f416d17eed2f472445c,2270d830fda743de1ce8a61e33b9542cb39a0f4b,LANG-662,https://issues.apache.org/jira/browse/LANG-662
23,66e42dc8b43d37ff011de69586f8e6764c4b3164,249788d799ca1c3964062bdc5c19a51ecc05c2f7,LANG-636,https://issues.apache.org/jira/browse/LANG-636
24,7df70a8c6b14452767ac932a14640e32a1dc16da,8e2f4ddb9a1ecd7a1bf7d752c2c891d630287036,LANG-664,https://issues.apache.org/jira/browse/LANG-664
25,44dbf85b6a7156d550ba62210412015058336281,dd5f8ea30755268dc43bbf2cd5024412674eb1b0,LANG-658,https://issues.apache.org/jira/browse/LANG-658
26,f7f19a3d2f98f48924d38fec2308dc3db83445d8,14a0cc2a9baf84a97348263975082ef3857daf97,LANG-645,https://issues.apache.org/jira/browse/LANG-645
27,bbcba273ad4322e76a90bcb867cbea108134717c,50c1fdecb4ed33ec1bb0d449f294c299d5369701,LANG-638,https://issues.apache.org/jira/browse/LANG-638
28,c0041cafc2fda3fb437009d5417ba5ebeb32ad35,bef3eb6ed060d5ae14da6ce5a1909675b8cf5650,LANG-617,https://issues.apache.org/jira/browse/LANG-617
Expand All @@ -45,7 +44,6 @@ bug.id,revision.id.buggy,revision.id.fixed,report.id,report.url
45,04f767b393b5849185f4ddf8f7ae8fc0b255e9bf,4342bd5d69d122a16c735416039b4b2ca27897ad,LANG-419,https://issues.apache.org/jira/browse/LANG-419
46,65b5dc69db3bfd08b4392dcee16fa0542b097812,dd0deed066e728d7b09e5fd69855c5ad7bf6bdb4,LANG-421,https://issues.apache.org/jira/browse/LANG-421
47,2e8e3f46ba0a41d95c38875cf6a7153816262123,1fe5439baf32af2114958e3cfc3512bd72c84773,LANG-412,https://issues.apache.org/jira/browse/LANG-412
48,97f1c120c092916f2f95439b6440a8977c66ee0a,e199d381f8c199801fee2d40a7f3ea1380700631,LANG-393,https://issues.apache.org/jira/browse/LANG-393
49,dab1bdfc0fec1d45def7d4e4870dc207bd954686,673385b43d0d5783039242460ba1c12b3f1f4e92,LANG-380,https://issues.apache.org/jira/browse/LANG-380
50,43cf3f491e7b9b42dc4a5fa4d7bc00cef1d38f7e,127e6e338f088b82eea1967d31c1abf8d51a364f,LANG-368,https://issues.apache.org/jira/browse/LANG-368
51,9da40ba6b5bcc7b6071fa7fe11eaeb1b97e53d81,796b898281af571a510d96487dcd95699ac1e435,LANG-365,https://issues.apache.org/jira/browse/LANG-365
Expand Down
71 changes: 71 additions & 0 deletions framework/projects/Lang/compile-errors/test-1-10.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java
index 0a34fea8f..40f8830c9 100644
--- a/src/main/java/org/apache/commons/lang3/JavaVersion.java
+++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java
@@ -69,7 +69,17 @@ public enum JavaVersion {
/**
* Java 1.8.
*/
- JAVA_1_8(1.8f, "1.8");
+ JAVA_1_8(1.8f, "1.8"),
+
+ /**
+ * Java 1.9.
+ */
+ JAVA_1_9(1.9f, "1.9"),
+
+ /**
+ * Java 1.x, x > 9. Mainly introduced to avoid to break when a new version of Java is used.
+ */
+ JAVA_RECENT(maxVersion(), Float.toString(maxVersion()));

/**
* The float value.
@@ -147,9 +157,21 @@ static JavaVersion get(final String nom) {
return JAVA_1_7;
} else if ("1.8".equals(nom)) {
return JAVA_1_8;
- } else {
+ } else if ("1.9".equals(nom)) {
+ return JAVA_1_9;
+ }
+ if (nom == null) {
return null;
}
+ final float v = toFloatVersion(nom);
+ if ((v - 1.) < 1.) { // then we need to check decimals > .9
+ final int firstComma = Math.max(nom.indexOf('.'), nom.indexOf(','));
+ final int end = Math.max(nom.length(), nom.indexOf(',', firstComma));
+ if (Float.parseFloat(nom.substring(firstComma + 1, end)) > .9f) {
+ return JAVA_RECENT;
+ }
+ }
+ return null;
}

//-----------------------------------------------------------------------
@@ -165,4 +187,24 @@ public String toString() {
return name;
}

+ // upper bound of java version considering 2. or current is the higher
+ private static float maxVersion() {
+ final float v = toFloatVersion(System.getProperty("java.version", "2.0"));
+ if (v > 0) {
+ return v;
+ }
+ return 2f;
+ }
+
+ private static float toFloatVersion(final String name) {
+ final String[] toParse = name.split("\\.");
+ if (toParse.length >= 2) {
+ try {
+ return Float.parseFloat(toParse[0] + '.' + toParse[1]);
+ } catch (final NumberFormatException nfe) {
+ // no-op, let use default
+ }
+ }
+ return -1;
+ }
}
12 changes: 12 additions & 0 deletions framework/projects/Lang/compile-errors/test-1-4.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
index e65ba73f4..df52fc50f 100644
--- a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java
@@ -521,7 +521,7 @@ public class TypeUtilsTest<B> {
public void testTypesSatisfyVariables() throws SecurityException, NoSuchFieldException,
NoSuchMethodException {
final Map<TypeVariable<?>, Type> typeVarAssigns = new HashMap<TypeVariable<?>, Type>();
- final Integer max = TypeUtilsTest.stub();
+ final Integer max = TypeUtilsTest.<Integer> stub();
typeVarAssigns.put(getClass().getMethod("stub").getTypeParameters()[0], Integer.class);
Assert.assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns));
typeVarAssigns.clear();
71 changes: 71 additions & 0 deletions framework/projects/Lang/compile-errors/test-14-16.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java
index 0a34fea8f..40f8830c9 100644
--- a/src/main/java/org/apache/commons/lang3/JavaVersion.java
+++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java
@@ -69,7 +69,17 @@ public enum JavaVersion {
/**
* Java 1.8.
*/
- JAVA_1_8(1.8f, "1.8");
+ JAVA_1_8(1.8f, "1.8"),
+
+ /**
+ * Java 1.9.
+ */
+ JAVA_1_9(1.9f, "1.9"),
+
+ /**
+ * Java 1.x, x > 9. Mainly introduced to avoid to break when a new version of Java is used.
+ */
+ JAVA_RECENT(maxVersion(), Float.toString(maxVersion()));

/**
* The float value.
@@ -147,9 +157,21 @@ static JavaVersion get(final String nom) {
return JAVA_1_7;
} else if ("1.8".equals(nom)) {
return JAVA_1_8;
- } else {
+ } else if ("1.9".equals(nom)) {
+ return JAVA_1_9;
+ }
+ if (nom == null) {
return null;
}
+ final float v = toFloatVersion(nom);
+ if ((v - 1.) < 1.) { // then we need to check decimals > .9
+ final int firstComma = Math.max(nom.indexOf('.'), nom.indexOf(','));
+ final int end = Math.max(nom.length(), nom.indexOf(',', firstComma));
+ if (Float.parseFloat(nom.substring(firstComma + 1, end)) > .9f) {
+ return JAVA_RECENT;
+ }
+ }
+ return null;
}

//-----------------------------------------------------------------------
@@ -165,4 +187,24 @@ public String toString() {
return name;
}

+ // upper bound of java version considering 2. or current is the higher
+ private static float maxVersion() {
+ final float v = toFloatVersion(System.getProperty("java.version", "2.0"));
+ if (v > 0) {
+ return v;
+ }
+ return 2f;
+ }
+
+ private static float toFloatVersion(final String name) {
+ final String[] toParse = name.split("\\.");
+ if (toParse.length >= 2) {
+ try {
+ return Float.parseFloat(toParse[0] + '.' + toParse[1]);
+ } catch (final NumberFormatException nfe) {
+ // no-op, let use default
+ }
+ }
+ return -1;
+ }
}
73 changes: 73 additions & 0 deletions framework/projects/Lang/compile-errors/test-17-20.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
index 477495a4e..93e5bc142 100644
--- a/src/main/java/org/apache/commons/lang3/JavaVersion.java
+++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java
@@ -36,7 +36,17 @@ public enum JavaVersion {
JAVA_1_5(1.5f, "1.5"),
JAVA_1_6(1.6f, "1.6"),
JAVA_1_7(1.7f, "1.7"),
- JAVA_1_8(1.8f, "1.8");
+ JAVA_1_8(1.8f, "1.8"),
+
+ /**
+ * Java 1.9.
+ */
+ JAVA_1_9(1.9f, "1.9"),
+
+ /**
+ * Java 1.x, x > 9. Mainly introduced to avoid to break when a new version of Java is used.
+ */
+ JAVA_RECENT(maxVersion(), Float.toString(maxVersion()));

/**
* The float value.
@@ -114,10 +124,22 @@ public enum JavaVersion {
return JAVA_1_7;
} else if ("1.8".equals(nom)) {
return JAVA_1_8;
- } else {
+ } else if ("1.9".equals(nom)) {
+ return JAVA_1_9;
+ }
+ if (nom == null) {
return null;
}
- }
+ final float v = toFloatVersion(nom);
+ if ((v - 1.) < 1.) { // then we need to check decimals > .9
+ final int firstComma = Math.max(nom.indexOf('.'), nom.indexOf(','));
+ final int end = Math.max(nom.length(), nom.indexOf(',', firstComma));
+ if (Float.parseFloat(nom.substring(firstComma + 1, end)) > .9f) {
+ return JAVA_RECENT;
+ }
+ }
+ return null;
+ }

//-----------------------------------------------------------------------
/**
@@ -132,4 +154,25 @@ public enum JavaVersion {
return name;
}

+ // upper bound of java version considering 2. or current is the higher
+ private static float maxVersion() {
+ final float v = toFloatVersion(System.getProperty("java.version", "2.0"));
+ if (v > 0) {
+ return v;
+ }
+ return 2f;
+ }
+
+ private static float toFloatVersion(final String name) {
+ final String[] toParse = name.split("\\.");
+ if (toParse.length >= 2) {
+ try {
+ return Float.parseFloat(toParse[0] + '.' + toParse[1]);
+ } catch (final NumberFormatException nfe) {
+ // no-op, let use default
+ }
+ }
+ return -1;
+ }
+
}
Loading
Loading