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

Making the correct Parsing #890

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
34 changes: 33 additions & 1 deletion TestResultSummaryService/parsers/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,50 @@ class Parser {
const sdkResourceRegex = /.*?SDK_RESOURCE\=(.*)[\r\n]+/;
let curRegexResult = null;
let javaVersion, jdkDate, sdkResource;

if ((curRegexResult = javaVersionRegex.exec(output)) !== null) {
javaVersion = removeTimestamp(curRegexResult[1]);
} else {
return null; // Return null if markers are missing
}

curRegexResult = null;
if ((curRegexResult = sdkResourceRegex.exec(output)) != null) {
sdkResource = curRegexResult[1];
}
curRegexResult = null;
// parse jdk date from javaVersion

// parse jdk date from javaVersion or output
if ((curRegexResult = javaBuildDateRegex.exec(javaVersion)) !== null) {
jdkDate = curRegexResult[0];
} else if ((curRegexResult = javaBuildDateRegex.exec(output)) !== null) {
jdkDate = curRegexResult[0];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be removed


// Refine jdkDate extraction to match specific lines for HotSpot, OpenJ9, and Java 8 implementations
if (!jdkDate) {
// Try to extract date from specific lines for HotSpot
const hotspotBuildDateRegex =
/OpenJDK Runtime Environment [^ ]+ \([^)]+ (\d{4})(\d{2})(\d{2})/; // e.g., 20240626
const openj9BuildDateRegex =
/Eclipse OpenJ9 VM \([^)]+ (\d{4})(\d{2})(\d{2})/; // e.g., 20240627
const java8BuildDateRegex =
/OpenJDK Runtime Environment.*\(build [^\d]*(\d{4})(\d{2})(\d{2})/; // e.g., 1.8.0_412-b08

if ((curRegexResult = hotspotBuildDateRegex.exec(output)) !== null) {
jdkDate = `${curRegexResult[1]}-${curRegexResult[2]}-${curRegexResult[3]}`;
} else if ((curRegexResult = openj9BuildDateRegex.exec(output)) !== null) {
jdkDate = `${curRegexResult[1]}-${curRegexResult[2]}-${curRegexResult[3]}`;
} else if ((curRegexResult = java8BuildDateRegex.exec(output)) !== null) {
jdkDate = `${curRegexResult[1]}-${curRegexResult[2]}-${curRegexResult[3]}`;
}
}

// Return null if no jdkDate is found
if (!jdkDate) {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, add else at line 56

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean line 59?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, at line 56 add eles block


return { javaVersion, jdkDate, sdkResource };
}

Expand Down
125 changes: 125 additions & 0 deletions TestResultSummaryService/parsers/Parser.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
const Parser = require('./Parser'); // Adjust the path if necessary

describe('Parser', () => {
let parser;

beforeEach(() => {
parser = new Parser('TestBuild');
});

test('should extract Java version and build date for HotSpot implementation', () => {
const hotspotOutput = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "21.0.4-beta" 2024-07-16
16:38:54 OpenJDK Runtime Environment Temurin-21.0.4+6-202406261902 (build 21.0.4-beta+6-ea)
16:38:54 OpenJDK 64-Bit Server VM Temurin-21.0.4+6-202406261902 (build 21.0.4-beta+6-ea, mixed mode, sharing)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(hotspotOutput);
expect(result.jdkDate).toBe('2024-06-26');
});

test('should extract Java version and build date for OpenJ9 implementation', () => {
const openj9Output = `
11:53:15 =JAVA VERSION OUTPUT BEGIN=
11:53:19 openjdk version "11.0.24-internal" 2024-07-16
11:53:19 OpenJDK Runtime Environment (build 11.0.24-internal+0-adhoc.jenkins.BuildJDK11aarch64macPersonal)
11:53:19 Eclipse OpenJ9 VM (build master-2a2df9f1117, JRE 11 Mac OS X aarch64-64-Bit 20240627_514 (JIT enabled, AOT enabled)
11:53:19 OpenJ9 - 2a2df9f1117
11:53:19 OMR - 47a9d248db0
11:53:19 JCL - c535515f053 based on jdk-11.0.24+6)
11:53:19 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(openj9Output);
expect(result.jdkDate).toBe('2024-06-27');
});

test('should extract Java version and build date for Java 8 implementation', () => {
const java8Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "1.8.0_412"
16:38:54 OpenJDK Runtime Environment (Temurin)(build 1.8.0_412-b08)
16:38:54 OpenJDK 64-Bit Server VM (Temurin)(build 25.412-b08, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java8Output);
expect(result).toBeNull();
});

test('should extract Java version and build date for Java 8u152-b01 implementation', () => {
const java8u152Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "1.8.0_152"
16:38:54 OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_152-b01)
16:38:54 OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.152-b01, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java8u152Output);
expect(result).toBeNull();
});

test('should extract Java version and build date for Java 9.0.4+11 implementation', () => {
const java904Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "9.0.4"
16:38:54 OpenJDK Runtime Environment (build 9.0.4+11)
16:38:54 OpenJDK 64-Bit Server VM (build 9.0.4+11, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java904Output);
expect(result).toBeNull();
});

test('should extract Java version and build date for Java 10.0.2+13.1 implementation', () => {
const java1002Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "10.0.2"
16:38:54 OpenJDK Runtime Environment (build 10.0.2+13.1)
16:38:54 OpenJDK 64-Bit Server VM (build 10.0.2+13.1, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java1002Output);
expect(result).toBeNull();
});

test('should extract Java version and build date for Java 11.0.4+11.4 implementation', () => {
const java1104Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "11.0.4"
16:38:54 OpenJDK Runtime Environment (build 11.0.4+11.4)
16:38:54 OpenJDK 64-Bit Server VM (build 11.0.4+11.4, mixed mode)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java1104Output);
expect(result).toBeNull();
});

test('should extract Java version and build date for Java 13+33_openj9-0.16.0 implementation', () => {
const java1333Output = `
16:38:54 =JAVA VERSION OUTPUT BEGIN=
16:38:54 openjdk version "13"
16:38:54 OpenJDK Runtime Environment (build 13+33)
16:38:54 Eclipse OpenJ9 VM (build 13+33_openj9-0.16.0, JRE 13 Mac OS X aarch64-64-Bit)
16:38:54 =JAVA VERSION OUTPUT END=
`;

const result = parser.exactJavaVersion(java1333Output);
expect(result).toBeNull();
});

test('should return null if no Java version regex match', () => {
const invalidOutput = `
16:38:54 Some invalid output that does not contain Java version information
`;

const result = parser.exactJavaVersion(invalidOutput);
expect(result).toBeNull();
});
});
Loading