1- const AbstractSpecification = require ( "./AbstractSpecification " ) ;
1+ const Specification = require ( "./Specification " ) ;
22
3- class Project extends AbstractSpecification {
3+ class Project extends Specification {
44 constructor ( parameters ) {
55 super ( parameters ) ;
66 if ( new . target === Project ) {
7- throw new TypeError ( "Class 'Project' is abstract" ) ;
7+ throw new TypeError ( "Class 'Project' is abstract. Please use one of the 'types' subclasses " ) ;
88 }
9- this . _frameworkName = null ;
10- this . _frameworkVersion = null ;
11- this . _frameworkDependencies = null ;
129 }
1310
1411 /* === Attributes === */
1512 /**
1613 * @public
1714 */
1815 getFrameworkName ( ) {
19- return this . _frameworkName ;
16+ return this . _config . framework && this . _config . framework . name ;
2017 }
2118 /**
2219 * @public
2320 */
2421 getFrameworkVersion ( ) {
25- return this . _frameworkVersion ;
22+ return this . _config . framework && this . _config . framework . version ;
2623 }
2724 /**
2825 * @public
2926 */
3027 getFrameworkDependencies ( ) {
3128 // TODO: Clone or freeze object before exposing?
32- return this . _frameworkDependencies || [ ] ;
29+ return this . _config . framework && this . _config . framework . libraries || [ ] ;
3330 }
3431
3532 isFrameworkProject ( ) {
3633 return this . __id . startsWith ( "@openui5/" ) || this . __id . startsWith ( "@sapui5/" ) ;
3734 }
3835
36+ getCustomConfiguration ( ) {
37+ return this . _config . customConfiguration ;
38+ }
39+
40+ getBuilderResourceExcludes ( ) {
41+ return this . _config . builder && this . _config . builder . resources && this . _config . builder . resources . excludes || [ ] ;
42+ }
43+
44+ getCustomTasks ( ) {
45+ return this . _config . builder && this . _config . builder . customTasks || [ ] ;
46+ }
47+
48+ getServerSettings ( ) {
49+ return this . _config . server && this . _config . server . settings ;
50+ }
51+
52+ /* === Resource Access === */
53+ /**
54+ * @public
55+ */
56+ getSourceReader ( ) {
57+ throw new Error ( `getSourceReader must be implemented by subclass ${ this . constructor . name } ` ) ;
58+ }
59+
60+ /**
61+ * @public
62+ */
63+ getRuntimeReader ( ) {
64+ throw new Error ( `getRuntimeReader must be implemented by subclass ${ this . constructor . name } ` ) ;
65+ }
66+
67+ /**
68+ * @public
69+ */
70+ getBuildtimeReader ( ) {
71+ throw new Error ( `getBuildtimeReader must be implemented by subclass ${ this . constructor . name } ` ) ;
72+ }
73+
3974 /* === Internals === */
4075 /**
4176 * @private
4277 * @param {object } config Configuration object
4378 */
4479 async _parseConfiguration ( config ) {
4580 await super . _parseConfiguration ( config ) ;
46-
47- if ( config . framework ) {
48- if ( config . framework . name ) {
49- this . _frameworkName = config . framework . name ;
50- }
51- if ( config . framework . version ) {
52- this . _frameworkVersion = config . framework . version ;
53- }
54- if ( config . framework . libraries ) {
55- this . _frameworkDependencies = JSON . parse ( JSON . stringify ( config . framework . libraries ) ) ;
56- }
57- }
5881 }
5982
6083 async _validate ( ) {
@@ -65,74 +88,6 @@ class Project extends AbstractSpecification {
6588 `is of kind '${ this . getKind ( ) } '` ) ;
6689 }
6790 }
68-
69- /* === Helper === */
70- /**
71- * Checks whether a given string contains a maven placeholder.
72- * E.g. <code>${appId}</code>.
73- *
74- * @param {string } value String to check
75- * @returns {boolean } True if given string contains a maven placeholder
76- */
77- _hasMavenPlaceholder ( value ) {
78- return ! ! value . match ( / ^ \$ \{ ( .* ) \} $ / ) ;
79- }
80-
81- /**
82- * Resolves a maven placeholder in a given string using the projects pom.xml
83- *
84- * @param {string } value String containing a maven placeholder
85- * @returns {Promise<string> } Resolved string
86- */
87- async _resolveMavenPlaceholder ( value ) {
88- const parts = value && value . match ( / ^ \$ \{ ( .* ) \} $ / ) ;
89- if ( parts ) {
90- this . _log . verbose (
91- `"${ value } contains a maven placeholder "${ parts [ 1 ] } ". Resolving from projects pom.xml...` ) ;
92- const pom = await this . getPom ( ) ;
93- let mvnValue ;
94- if ( pom . project && pom . project . properties && pom . project . properties [ parts [ 1 ] ] ) {
95- mvnValue = pom . project . properties [ parts [ 1 ] ] ;
96- } else {
97- let obj = pom ;
98- parts [ 1 ] . split ( "." ) . forEach ( ( part ) => {
99- obj = obj && obj [ part ] ;
100- } ) ;
101- mvnValue = obj ;
102- }
103- if ( ! mvnValue ) {
104- throw new Error ( `"${ value } " couldn't be resolved from maven property ` +
105- `"${ parts [ 1 ] } " of pom.xml of project ${ this . _project . metadata . name } ` ) ;
106- }
107- return mvnValue ;
108- } else {
109- throw new Error ( `"${ value } " is not a maven placeholder` ) ;
110- }
111- }
112-
113- /**
114- * Reads the projects pom.xml file
115- *
116- * @returns {Promise<object> } Resolves with a JSON representation of the content
117- */
118- async _getPom ( ) {
119- if ( this . _pPom ) {
120- return this . _pPom ;
121- }
122- const fsPath = path . join ( this . _project . path , "pom.xml" ) ;
123- return this . _pPom = readFile ( fsPath ) . then ( async ( content ) => {
124- const xml2js = require ( "xml2js" ) ;
125- const parser = new xml2js . Parser ( {
126- explicitArray : false ,
127- ignoreAttrs : true
128- } ) ;
129- const readXML = promisify ( parser . parseString ) ;
130- return readXML ( content ) ;
131- } ) . catch ( ( err ) => {
132- throw new Error (
133- `Failed to read pom.xml for project ${ this . _project . metadata . name } : ${ err . message } ` ) ;
134- } ) ;
135- }
13691}
13792
13893module . exports = Project ;
0 commit comments