-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathbuildJdtlsExt.js
More file actions
99 lines (90 loc) · 3.77 KB
/
buildJdtlsExt.js
File metadata and controls
99 lines (90 loc) · 3.77 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
// 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');
const bundleList = [
'org.eclipse.jdt.junit4.runtime_',
'org.eclipse.jdt.junit5.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
const packageJsonData = require('../package.json');
const javaExtensions = packageJsonData.contributes.javaExtensions;
if (Array.isArray(javaExtensions)) {
packageJsonData.contributes.javaExtensions = javaExtensions.map((extensionString) => {
const ind = extensionString.indexOf('_');
const fileName = findNewRequiredJar(extensionString.substring(extensionString.lastIndexOf('/') + 1, ind));
if (ind >= 0) {
return extensionString.substring(0, extensionString.lastIndexOf('/') + 1) + fileName;
}
return extensionString;
});
fs.writeFileSync(path.resolve('package.json'), JSON.stringify(packageJsonData, null, 4));
fs.appendFileSync(path.resolve('package.json'), os.EOL);
}
}
// The plugin jar follows the name convention: <name>_<version>.jar
function findNewRequiredJar(fileName) {
fileName = fileName + "_";
const destFolder = path.resolve('./server');
const files = fs.readdirSync(destFolder);
const f = files.find((file) => {
return file.indexOf(fileName) >= 0;
});
return f;
}
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';
}