Skip to content

Commit 57e71a7

Browse files
committed
test(java): compare JDT Windows library paths case insensitively
1 parent ae5b4ed commit 57e71a7

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎scripts/compiler/test-live.mjs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const eclipse=process.env.LITHE_JAVA_PROJECT_KIND==='eclipse';
1919
const sourceFile=join(root,eclipse?'src/Main.java':'Main.java');
2020
if(eclipse){mkdirSync(join(root,'src'));writeFileSync(join(root,'.project'),'<projectDescription><name>FixtureNative</name><buildSpec><buildCommand><name>org.eclipse.jdt.core.javabuilder</name></buildCommand></buildSpec><natures><nature>org.eclipse.jdt.core.javanature</nature></natures></projectDescription>');writeFileSync(join(root,'.classpath'),'<classpath><classpathentry kind="src" path="src"/><classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/><classpathentry kind="output" path="bin"/></classpath>');}
2121
const context={contextID:'ctx-1',generation:1};let op=0;
22+
const samePath=(left,right)=>process.platform==='win32'?resolve(left).toLowerCase()===resolve(right).toLowerCase():resolve(left)===resolve(right);
2223
const snapshot=root=>{const items=[];const visit=(path,label)=>{const stat=lstatSync(path);assert.equal(stat.isSymbolicLink(),false);items.push([label,stat.mode,stat.isFile()?createHash('sha256').update(readFileSync(path)).digest('hex'):null]);if(stat.isDirectory())for(const name of readdirSync(path).sort())visit(join(path,name),`${label}/${name}`);};visit(root,'');return items;};
2324
const baseline=snapshot(pkg);
2425
const folders=[{rootID:'root',name:'workspace',path:root,uri:pathToFileURL(root).href}];
@@ -48,7 +49,7 @@ try{
4849
const invoke=(functionID,params)=>backend.request('lithe/function/invoke',{functionID,operationID:`native-${++op}`,params,context},90000);
4950
let sources;
5051
await step('Discover the project from the real JDT server',async()=>{await until(()=>execute('java.project.getAll'),projects=>projects.some(uri=>(process.platform==='win32'?fileURLToPath(uri).replace(/[\\/]$/,'').toLowerCase()===root.toLowerCase():fileURLToPath(uri).replace(/\/$/,'')===root)),'JDT project import');sources=await invoke('libraries.settings',{context:{language:'zh-CN',builds:[]}});assert.equal(sources.sources[0].path,eclipse?'.classpath':'.vscode/settings.json');});
51-
await step('Save a referenced JAR and confirm JDT resolves the actual classpath',async()=>{const source=sources.sources[0],stageFile=join(stage,'libraries-stage.json');writeFileSync(stageFile,'');await invoke('compiler.prepareSettings',{operation:'editSource',sourceID:source.id,revision:source.revision,values:{libraries:[jar]},outputFile:stageFile});mkdirSync(join(root,'.vscode'),{recursive:true});renameSync(stageFile,join(root,source.path));await invoke('libraries.settings',{operation:'readAfterSave',context:{language:'zh-CN',builds:[]}});if(!eclipse)await until(()=>execute('java.project.getSettings',[pathToFileURL(root).href,['org.eclipse.jdt.ls.core.referencedLibraries']]),value=>value['org.eclipse.jdt.ls.core.referencedLibraries']?.includes(jar),'JDT classpath refresh');});
52+
await step('Save a referenced JAR and confirm JDT resolves the actual classpath',async()=>{const source=sources.sources[0],stageFile=join(stage,'libraries-stage.json');writeFileSync(stageFile,'');await invoke('compiler.prepareSettings',{operation:'editSource',sourceID:source.id,revision:source.revision,values:{libraries:[jar]},outputFile:stageFile});mkdirSync(join(root,'.vscode'),{recursive:true});renameSync(stageFile,join(root,source.path));await invoke('libraries.settings',{operation:'readAfterSave',context:{language:'zh-CN',builds:[]}});if(!eclipse)await until(()=>execute('java.project.getSettings',[pathToFileURL(root).href,['org.eclipse.jdt.ls.core.referencedLibraries']]),value=>value['org.eclipse.jdt.ls.core.referencedLibraries']?.some(path=>samePath(path,jar)),'JDT classpath refresh');});
5253
await step('Save native compiler target and verify real JDT effective settings',async()=>{sources=await invoke('compiler.settings',{context:{language:'zh-CN',builds:[]}});const source=sources.sources.find(s=>s.id==='defaults'),stageFile=join(stage,'compiler-stage.prefs');writeFileSync(stageFile,'');await invoke('compiler.prepareSettings',{operation:'editSource',sourceID:source.id,revision:source.revision,values:{target:'8'},outputFile:stageFile});mkdirSync(join(root,'.settings'),{recursive:true});renameSync(stageFile,join(root,source.path));await invoke('compiler.settings',{operation:'readAfterSave',context:{language:'zh-CN',builds:[]}});await until(()=>execute('java.project.getSettings',[pathToFileURL(root).href,['org.eclipse.jdt.core.compiler.codegen.targetPlatform']]),value=>value['org.eclipse.jdt.core.compiler.codegen.targetPlatform']==='1.8','JDT compiler refresh');});
5354
await step('Compile with JDT, inspect Java 8 bytecode and run with the external JAR',async()=>{
5455
const result=await execute('vscode.java.buildWorkspace',[JSON.stringify({mainClass:'Main',filePath:sourceFile,isFullBuild:true})]);assert.equal(result,1);

0 commit comments

Comments
 (0)