Skip to content

Commit 7a6ad02

Browse files
committed
Align Module and ThemeLibrary with resource access changes, cleanup
1 parent 799a9a1 commit 7a6ad02

File tree

7 files changed

+163
-209
lines changed

7 files changed

+163
-209
lines changed

lib/specifications/ComponentProject.js

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class ComponentProject extends Project {
1414
}
1515

1616
this._pPom = null;
17-
1817
this._namespace = null;
18+
this._isRuntimeNamespaced = true;
1919
}
2020

2121
/* === Attributes === */
@@ -60,10 +60,6 @@ class ComponentProject extends Project {
6060
return this._config.builder && this._config.builder.bundles || [];
6161
}
6262

63-
_isRuntimeNamespaced() {
64-
return true;
65-
}
66-
6763
/* === Resource Access === */
6864

6965
/**
@@ -84,9 +80,9 @@ class ComponentProject extends Project {
8480
let reader;
8581
switch (style) {
8682
case "buildtime":
87-
reader = this._getSourceReaderFlat(`/resources/${this._namespace}/`);
83+
reader = this._getFlatSourceReader(`/resources/${this._namespace}/`);
8884
if (includeTestResources) {
89-
const testReader = this._getTestReaderFlat(`/test-resources/${this._namespace}/`);
85+
const testReader = this._getFlatTestReader(`/test-resources/${this._namespace}/`);
9086
if (testReader) {
9187
reader = resourceFactory.createReaderCollection({
9288
name: `Reader collection for project ${this.getName()}`,
@@ -99,17 +95,17 @@ class ComponentProject extends Project {
9995
if (includeTestResources) {
10096
throw new Error(`Readers of style "runtime" can't include test resources`);
10197
}
102-
if (this._isRuntimeNamespaced()) {
98+
if (this._isRuntimeNamespaced) {
10399
// Same as buildtime
104100
return this.getReader({style: "buildtime", includeTestResources: false});
105101
}
106-
reader = this._getSourceReaderFlat("/");
102+
reader = this._getFlatSourceReader("/");
107103
break;
108104
case "flat":
109105
if (includeTestResources) {
110106
throw new Error(`Readers of style "flat" can't include test resources`);
111107
}
112-
reader = this._getSourceReaderFlat("/");
108+
reader = this._getFlatSourceReader("/");
113109
break;
114110
default:
115111
throw new Error(`Unknown path mapping style ${style}`);
@@ -124,6 +120,49 @@ class ComponentProject extends Project {
124120
});
125121
}
126122

123+
/**
124+
* Get a resource reader for the sources of the project (not including any test resources)
125+
*
126+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
127+
*/
128+
_getFullSourceReader() {
129+
throw new Error(`_getFullSourceReader must be implemented by subclass ${this.constructor.name}`);
130+
}
131+
132+
/**
133+
* TODO
134+
*
135+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
136+
*/
137+
_getFlatSourceReader() {
138+
throw new Error(`_getFlatSourceReader must be implemented by subclass ${this.constructor.name}`);
139+
}
140+
141+
/**
142+
* Get a resource reader for the test-sources of the project
143+
*
144+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
145+
*/
146+
_getFullTestReader() {
147+
throw new Error(`_getFullTestReader must be implemented by subclass ${this.constructor.name}`);
148+
}
149+
/**
150+
* TODO
151+
*
152+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
153+
*/
154+
_getFlatTestReader() {
155+
throw new Error(`_getFlatTestReader must be implemented by subclass ${this.constructor.name}`);
156+
}
157+
158+
/**
159+
* Get a resource reader/writer for accessing and modifying a project's resources
160+
*
161+
* @public
162+
* @param {object} [options]
163+
* @param {boolean} [options.includeTestResources=false] Whether test resources should be included in the result set
164+
* @returns {module:@ui5/fs.ReaderCollection} A reader collection instance
165+
*/
127166
getWorkspace({includeTestResources = false} = {}) {
128167
// Workspace is always of style "buildtime"
129168
const reader = this.getReader({
@@ -153,7 +192,7 @@ class ComponentProject extends Project {
153192
if (!includeTestResources) {
154193
// If no test-resources are requested, filter them out
155194
writer = writer.filter((resource) => {
156-
return !this._isTestResource(resource);
195+
return !resource.getPath().startsWith("/test-resources/");
157196
});
158197
}
159198

@@ -166,7 +205,7 @@ class ComponentProject extends Project {
166205
if (includeTestResources) {
167206
throw new Error(`Readers of style "runtime" can't include test resources`);
168207
}
169-
if (this._isRuntimeNamespaced()) {
208+
if (this._isRuntimeNamespaced) {
170209
// Same as buildtime
171210
return this._getWriter({style: "buildtime", includeTestResources});
172211
}
@@ -193,10 +232,6 @@ class ComponentProject extends Project {
193232
}
194233
}
195234

196-
_isTestResource(resource) {
197-
throw new Error(`_isTestResource must be implemented by subclass ${this.constructor.name}`);
198-
}
199-
200235
/* === Internals === */
201236
/**
202237
* @private

lib/specifications/Project.js

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -71,48 +71,21 @@ class Project extends Specification {
7171

7272
/* === Resource Access === */
7373
/**
74-
* Get a resource reader for the sources of the project (excluding any test resources)
75-
*
76-
* @public
74+
* TODO
75+
*
76+
* @public
77+
* @param {object} [options]
78+
* @param {string} [options.style=buildtime] Path style to access resources. Can be "buildtime", "runtime" or "flat"
79+
* TODO: describe styles
80+
* This parameter might be ignored by some specifications
81+
* @param {boolean} [options.includeTestResources=false] Whether test resources should be included in the result set
82+
* This parameter might be ignored by some specifications
7783
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
78-
*/
79-
_getSourceReader() {
80-
throw new Error(`_getSourceReader must be implemented by subclass ${this.constructor.name}`);
81-
}
82-
83-
/**
84-
* TODO
85-
*
86-
* @public
87-
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
88-
*/
89-
_getSourceReaderFlat() {
90-
throw new Error(`_getSourceReaderFlat must be implemented by subclass ${this.constructor.name}`);
91-
}
92-
93-
/**
94-
* TODO
95-
*
96-
* @public
97-
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
98-
*/
99-
_getTestReaderFlat() {
100-
throw new Error(`_getTestReaderFlat must be implemented by subclass ${this.constructor.name}`);
101-
}
102-
103-
_getDesignatedPath({namespace, isFlattable, isTestResources, isFramework}) {
104-
105-
}
106-
107-
/**
108-
* TODO
109-
*
110-
* @public
111-
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
112-
*/
113-
getReader() {
84+
*/
85+
getReader(options) {
11486
throw new Error(`getReader must be implemented by subclass ${this.constructor.name}`);
11587
}
88+
11689
/**
11790
* TODO
11891
*

lib/specifications/types/Application.js

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ class Application extends ComponentProject {
99
this._pManifests = {};
1010

1111
this._webappPath = "webapp";
12+
13+
this._isRuntimeNamespaced = false;
1214
}
1315

16+
1417
/* === Attributes === */
1518
/**
1619
* @public
@@ -32,22 +35,16 @@ class Application extends ComponentProject {
3235
* @param {string} virBasePath
3336
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
3437
*/
35-
_getSourceReaderFlat(virBasePath = "/") {
38+
_getFlatSourceReader(virBasePath = "/") {
3639
return resourceFactory.createReader({
3740
fsBasePath: fsPath.join(this.getPath(), this._webappPath),
3841
virBasePath,
3942
name: `Source reader for application project ${this.getName()}`
4043
});
4144
}
4245

43-
_getTestReaderFlat(virBasePath = "/") {
44-
return null;
45-
// TODO allow test path for applications
46-
// return resourceFactory.createReader({
47-
// fsBasePath: fsPath.join(this.getPath(), this._testPath),
48-
// virBasePath,
49-
// name: `Source reader for application project ${this.getName()}`
50-
// });
46+
_getFlatTestReader() {
47+
return null; // Applications do not have a dedicated test directory
5148
}
5249

5350
_getSourceReader() {
@@ -58,35 +55,6 @@ class Application extends ComponentProject {
5855
});
5956
}
6057

61-
62-
/**
63-
* Get a resource reader for accessing the project resources the same way the UI5 runtime would do
64-
*
65-
* @public
66-
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
67-
*/
68-
// getRuntimeReader() {
69-
// return resourceFactory.createReader({
70-
// fsBasePath: fsPath.join(this.getPath(), this._webappPath),
71-
// virBasePath: "/", // Applications are served at "/"
72-
// name: `Runtime reader for application project ${this.getName()}`
73-
// });
74-
// }
75-
76-
// *
77-
// * Get a resource reader for accessing the project resources during the build process
78-
// *
79-
// * @public
80-
// * @returns {module:@ui5/fs.ReaderCollection} Reader collection
81-
82-
// getBuildtimeReader() {
83-
// return resourceFactory.createReader({
84-
// fsBasePath: fsPath.join(this.getPath(), this._webappPath),
85-
// virBasePath: `/resources/${this.getNamespace()}/`,
86-
// name: `Buildtime reader for application project ${this.getName()}`
87-
// });
88-
// }
89-
9058
/* === Internals === */
9159
/**
9260
* @private

lib/specifications/types/Library.js

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,6 @@ class Library extends ComponentProject {
3737
}
3838

3939
/* === Resource Access === */
40-
41-
// getReader({style = "namespaced", includeTestResources = false} = {}) {
42-
// // if source is namespaced, create fs reader not for src/ but for src/name/space/
43-
// // If there are other files or directories on the top level (like in sap.ui.core):
44-
// // libraries: map to src/ but throw if flat is requested. Same for test/
45-
// // applications: throw on creation. This should not be allowed. Same for test/
46-
47-
// return resourceFactory.createReader({
48-
// fsBasePath: fsPath.join(this.getPath(), this._srcPath),
49-
// virBasePath: "/",
50-
// name: `Source reader for library project ${this.getName()}`
51-
// });
52-
// }
53-
54-
// getWorkspace(readerOptions) {
55-
56-
// }
57-
5840
/*
5941
*
6042
* Get a resource reader for the sources of the project (excluding any test resources)
@@ -71,7 +53,7 @@ class Library extends ComponentProject {
7153
});
7254
}
7355

74-
_getSourceReaderFlat(virBasePath = "/") {
56+
_getFlatSourceReader(virBasePath = "/") {
7557
// TODO: Throw for libraries with additional namespaces like sap.ui.core?
7658
return resourceFactory.createReader({
7759
fsBasePath: fsPath.join(this.getPath(), this._srcPath, ...this._namespace.split("/")),
@@ -80,7 +62,7 @@ class Library extends ComponentProject {
8062
});
8163
}
8264

83-
_getTestReaderFlat(virBasePath = "/") {
65+
_getFlatTestReader(virBasePath = "/") {
8466
if (!this._testPathExists) {
8567
return null;
8668
}
@@ -92,47 +74,6 @@ class Library extends ComponentProject {
9274
return testReader;
9375
}
9476

95-
_isTestResource(resource) {
96-
return resource.getPath().startsWith("/test-resources/");
97-
}
98-
99-
// /**
100-
// * Get a resource reader for accessing the project resources the same way the UI5 runtime would do
101-
// *
102-
// * @public
103-
// * @returns {module:@ui5/fs.ReaderCollection} Reader collection
104-
// */
105-
// getRuntimeReader() {
106-
// let reader = resourceFactory.createReader({
107-
// fsBasePath: fsPath.join(this.getPath(), this._srcPath),
108-
// virBasePath: "/resources/",
109-
// name: `Runtime resources reader for library project ${this.getName()}`
110-
// });
111-
// if (this._testPathExists) {
112-
// const testReader = resourceFactory.createReader({
113-
// fsBasePath: fsPath.join(this.getPath(), this._testPath),
114-
// virBasePath: "/test-resources/",
115-
// name: `Runtime test-resources reader for library project ${this.getName()}`
116-
// });
117-
// reader = resourceFactory.createReaderCollection({
118-
// name: `Reader collection for library project ${this.getName()}`,
119-
// readers: [reader, testReader]
120-
// });
121-
// }
122-
// return reader;
123-
// }
124-
125-
// /**
126-
// * Get a resource reader for accessing the project resources during the build process
127-
// *
128-
// * @public
129-
// * @returns {module:@ui5/fs.ReaderCollection} Reader collection
130-
// */
131-
// getBuildtimeReader() {
132-
// // Same as runtime
133-
// return this.getRuntimeReader();
134-
// }
135-
13677
/* === Internals === */
13778
/**
13879
* @private

0 commit comments

Comments
 (0)