-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathbuildJdtlsExt.js
More file actions
104 lines (91 loc) · 4.02 KB
/
buildJdtlsExt.js
File metadata and controls
104 lines (91 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
const cp = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');
const fse = require('fs-extra');
fse.removeSync('server');
const serverDir = path.resolve('java-extension');
// Bundle prefixes to copy from the p2 repository.
// Each prefix may match multiple versions (e.g., junit-jupiter-api_5.x and junit-jupiter-api_6.x)
// to support both JUnit 5 and JUnit 6.
const bundleList = [
'org.eclipse.jdt.junit4.runtime_',
'org.eclipse.jdt.junit5.runtime_',
'org.eclipse.jdt.junit6.runtime_',
'junit-jupiter-api_',
'junit-jupiter-engine_',
'junit-jupiter-migrationsupport_',
'junit-jupiter-params_',
'junit-vintage-engine_',
'org.opentest4j_',
'junit-platform-commons_',
'junit-platform-engine_',
'junit-platform-launcher_',
'junit-platform-runner_',
'junit-platform-suite-api_',
'junit-platform-suite-commons_',
'junit-platform-suite-engine_',
'org.apiguardian.api_',
'org.jacoco.core_'
];
// Set MAVEN_OPTS to disable XML entity size limits for JDK XML parser
const env = { ...process.env };
env.MAVEN_OPTS = (env.MAVEN_OPTS || '') + ' -Djdk.xml.maxGeneralEntitySizeLimit=0 -Djdk.xml.totalEntitySizeLimit=0 -DentityExpansionLimit=0';
cp.execSync(`${mvnw()} clean verify`, { cwd: serverDir, stdio: [0, 1, 2], env });
copy(path.join(serverDir, 'com.microsoft.java.test.plugin/target'), path.resolve('server'), (file) => path.extname(file) === '.jar');
copy(path.join(serverDir, 'com.microsoft.java.test.runner/target'), path.resolve('server'), (file) => file.endsWith('jar-with-dependencies.jar'));
copy(path.join(serverDir, 'com.microsoft.java.test.plugin.site/target/repository/plugins'), path.resolve('server'), (file) => {
return bundleList.some(bundleName => file.startsWith(bundleName));
});
updateVersion();
downloadJacocoAgent();
function copy(sourceFolder, targetFolder, fileFilter) {
const jars = fse.readdirSync(sourceFolder).filter(file => fileFilter(file));
fse.ensureDirSync(targetFolder);
for (const jar of jars) {
fse.copyFileSync(path.join(sourceFolder, jar), path.join(targetFolder, path.basename(jar)));
}
}
function updateVersion() {
// Update the version - rebuild javaExtensions from actual server folder contents
const packageJsonData = require('../package.json');
const destFolder = path.resolve('./server');
const files = fs.readdirSync(destFolder);
// Build new javaExtensions list from all jar files in server folder
// that match our bundleList prefixes, plus the plugin jar
const newJavaExtensions = [];
for (const file of files) {
if (file.endsWith('.jar')) {
// Check if this file matches any bundle prefix or is the plugin jar
const isBundle = bundleList.some(prefix => file.startsWith(prefix));
const isPlugin = file.startsWith('com.microsoft.java.test.plugin');
if (isBundle || isPlugin) {
newJavaExtensions.push('./server/' + file);
}
}
}
// Sort for consistent ordering
newJavaExtensions.sort();
packageJsonData.contributes.javaExtensions = newJavaExtensions;
fs.writeFileSync(path.resolve('package.json'), JSON.stringify(packageJsonData, null, 4));
fs.appendFileSync(path.resolve('package.json'), os.EOL);
}
function downloadJacocoAgent() {
const version = "0.8.14";
const jacocoAgentUrl = `https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/${version}/org.jacoco.agent-${version}-runtime.jar`;
const jacocoAgentPath = path.resolve('server', 'jacocoagent.jar');
if (!fs.existsSync(jacocoAgentPath)) {
cp.execSync(`curl -L ${jacocoAgentUrl} -o ${jacocoAgentPath}`);
}
if (!fs.existsSync(jacocoAgentPath)) {
throw new Error('Failed to download jacoco agent.');
}
}
function isWin() {
return /^win/.test(process.platform);
}
function mvnw() {
return isWin() ? 'mvnw.cmd' : './mvnw';
}