Skip to content

Commit 0aab3e3

Browse files
committed
[PoC] ZipArchive Adapter: Either skip validations or use adapter provided by projectPreprocessor to access project resources
1 parent d3614d2 commit 0aab3e3

File tree

2 files changed

+87
-58
lines changed

2 files changed

+87
-58
lines changed

lib/types/library/LibraryFormatter.js

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class LibraryFormatter extends AbstractUi5Formatter {
168168
namespace = libraryNs.replace(/\./g, "/");
169169

170170
const namespacePath = this.getNamespaceFromFsPath(fsNamespacePath);
171-
if (namespacePath !== namespace) {
171+
if (false && namespacePath !== namespace) {
172172
throw new Error(
173173
`Detected namespace "${namespace}" does not match detected directory ` +
174174
`structure "${namespacePath}" for project ${this._project.metadata.name}`);
@@ -337,32 +337,61 @@ class LibraryFormatter extends AbstractUi5Formatter {
337337
if (this._pDotLibrary) {
338338
return this._pDotLibrary;
339339
}
340-
const basePath = this.getSourceBasePath();
341-
return this._pDotLibrary = glob("**/.library", {
342-
cwd: basePath,
343-
followSymbolicLinks: false
344-
}).then(async (dotLibraryResources) => {
345-
if (!dotLibraryResources.length) {
346-
throw new Error(`Could not find .library file for project ${this._project.metadata.name}`);
347-
}
348-
if (dotLibraryResources.length > 1) {
349-
throw new Error(`Found multiple (${dotLibraryResources.length}) .library files ` +
350-
`for project ${this._project.metadata.name}`);
351-
}
352-
const fsPath = path.join(basePath, dotLibraryResources[0]);
353-
const content = await readFile(fsPath);
354-
const xml2js = require("xml2js");
355-
const parser = new xml2js.Parser({
356-
explicitArray: false,
357-
ignoreAttrs: true
340+
if (this._project._zipAdapter) {
341+
const basePath = this.getSourceBasePath();
342+
console.log("/" + this._project.resources.pathMappings["/resources/"] + "/**/.library");
343+
return this._pDotLibrary = this._project._zipAdapter.byGlob(
344+
"/" + this._project.resources.pathMappings["/resources/"] + "/**/.library")
345+
.then(async (dotLibraryResources) => {
346+
if (!dotLibraryResources.length) {
347+
throw new Error(`Could not find .library file for project ${this._project.metadata.name}`);
348+
}
349+
if (dotLibraryResources.length > 1) {
350+
throw new Error(`Found multiple (${dotLibraryResources.length}) .library files ` +
351+
`for project ${this._project.metadata.name}`);
352+
}
353+
const fsPath = path.join(basePath, dotLibraryResources[0].getPath());
354+
const content = await dotLibraryResources[0].getBuffer();
355+
const xml2js = require("xml2js");
356+
const parser = new xml2js.Parser({
357+
explicitArray: false,
358+
ignoreAttrs: true
359+
});
360+
const readXML = promisify(parser.parseString);
361+
const contentJson = await readXML(content);
362+
return {
363+
content: contentJson,
364+
fsPath
365+
};
366+
});
367+
} else {
368+
const basePath = this.getSourceBasePath();
369+
return this._pDotLibrary = glob("**/.library", {
370+
cwd: basePath,
371+
followSymbolicLinks: false
372+
}).then(async (dotLibraryResources) => {
373+
if (!dotLibraryResources.length) {
374+
throw new Error(`Could not find .library file for project ${this._project.metadata.name}`);
375+
}
376+
if (dotLibraryResources.length > 1) {
377+
throw new Error(`Found multiple (${dotLibraryResources.length}) .library files ` +
378+
`for project ${this._project.metadata.name}`);
379+
}
380+
const fsPath = path.join(basePath, dotLibraryResources[0]);
381+
const content = await readFile(fsPath);
382+
const xml2js = require("xml2js");
383+
const parser = new xml2js.Parser({
384+
explicitArray: false,
385+
ignoreAttrs: true
386+
});
387+
const readXML = promisify(parser.parseString);
388+
const contentJson = await readXML(content);
389+
return {
390+
content: contentJson,
391+
fsPath
392+
};
358393
});
359-
const readXML = promisify(parser.parseString);
360-
const contentJson = await readXML(content);
361-
return {
362-
content: contentJson,
363-
fsPath
364-
};
365-
});
394+
}
366395
}
367396

368397
/**
@@ -445,22 +474,22 @@ class LibraryFormatter extends AbstractUi5Formatter {
445474

446475
const absoluteSrcPath = path.join(project.path, project.resources.configuration.paths.src);
447476
const absoluteTestPath = path.join(project.path, project.resources.configuration.paths.test);
448-
return Promise.all([
449-
this.dirExists(absoluteSrcPath).then(function(bExists) {
450-
if (!bExists) {
451-
throw new Error(`Could not find source directory of project ${project.id}: ` +
452-
`${absoluteSrcPath}`);
453-
}
454-
}),
455-
this.dirExists(absoluteTestPath).then(function(bExists) {
456-
if (!bExists) {
457-
log.verbose(`Could not find (optional) test directory of project ${project.id}: ` +
458-
`${absoluteTestPath}`);
459-
// Current signal to following consumers that "test" is not available is null
460-
project.resources.configuration.paths.test = null;
461-
}
462-
})
463-
]);
477+
// return Promise.all([
478+
// this.dirExists(absoluteSrcPath).then(function(bExists) {
479+
// if (!bExists) {
480+
// throw new Error(`Could not find source directory of project ${project.id}: ` +
481+
// `${absoluteSrcPath}`);
482+
// }
483+
// }),
484+
// this.dirExists(absoluteTestPath).then(function(bExists) {
485+
// if (!bExists) {
486+
// log.verbose(`Could not find (optional) test directory of project ${project.id}: ` +
487+
// `${absoluteTestPath}`);
488+
// // Current signal to following consumers that "test" is not available is null
489+
// project.resources.configuration.paths.test = null;
490+
// }
491+
// })
492+
// ]);
464493
});
465494
}
466495
}

lib/types/themeLibrary/ThemeLibraryFormatter.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ class ThemeLibraryFormatter extends AbstractUi5Formatter {
6565

6666
const absoluteSrcPath = path.join(project.path, project.resources.configuration.paths.src);
6767
const absoluteTestPath = path.join(project.path, project.resources.configuration.paths.test);
68-
return Promise.all([
69-
this.dirExists(absoluteSrcPath).then(function(bExists) {
70-
if (!bExists) {
71-
throw new Error(`Could not find source directory of project ${project.id}: ` +
72-
`${absoluteSrcPath}`);
73-
}
74-
}),
75-
this.dirExists(absoluteTestPath).then(function(bExists) {
76-
if (!bExists) {
77-
log.verbose(`Could not find (optional) test directory of project ${project.id}: ` +
78-
`${absoluteTestPath}`);
79-
// Current signal to following consumers that "test" is not available is null
80-
project.resources.configuration.paths.test = null;
81-
}
82-
})
83-
]);
68+
// return Promise.all([
69+
// this.dirExists(absoluteSrcPath).then(function(bExists) {
70+
// if (!bExists) {
71+
// throw new Error(`Could not find source directory of project ${project.id}: ` +
72+
// `${absoluteSrcPath}`);
73+
// }
74+
// }),
75+
// this.dirExists(absoluteTestPath).then(function(bExists) {
76+
// if (!bExists) {
77+
// log.verbose(`Could not find (optional) test directory of project ${project.id}: ` +
78+
// `${absoluteTestPath}`);
79+
// // Current signal to following consumers that "test" is not available is null
80+
// project.resources.configuration.paths.test = null;
81+
// }
82+
// })
83+
// ]);
8484
});
8585
}
8686
}

0 commit comments

Comments
 (0)