Skip to content

Commit 8c86083

Browse files
d3xter666flovogt
andauthored
[FEATURE] Allow to configure location of UI5 home directory (#635)
JIRA: CPOUI5FOUNDATION-703 --------- Co-authored-by: Florian Vogt <[email protected]>
1 parent 14c4d35 commit 8c86083

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

lib/config/Configuration.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import os from "node:os";
1111
*/
1212
class Configuration {
1313
#mavenSnapshotEndpointUrl;
14+
#ui5DataDir;
1415

1516
/**
1617
* @param {object} configuration
1718
* @param {string} [configuration.mavenSnapshotEndpointUrl]
19+
* @param {string} [configuration.ui5DataDir]
1820
*/
19-
constructor({mavenSnapshotEndpointUrl}) {
21+
constructor({mavenSnapshotEndpointUrl, ui5DataDir}) {
2022
this.#mavenSnapshotEndpointUrl = mavenSnapshotEndpointUrl;
23+
this.#ui5DataDir = ui5DataDir;
2124
}
2225

2326
/**
@@ -31,13 +34,24 @@ class Configuration {
3134
return this.#mavenSnapshotEndpointUrl;
3235
}
3336

37+
/**
38+
* Configurable directory where the framework artefacts are stored.
39+
*
40+
* @public
41+
* @returns {string}
42+
*/
43+
getUi5DataDir() {
44+
return this.#ui5DataDir;
45+
}
46+
3447
/**
3548
* @public
3649
* @returns {object} The configuration in a JSON format
3750
*/
3851
toJson() {
3952
return {
4053
mavenSnapshotEndpointUrl: this.#mavenSnapshotEndpointUrl,
54+
ui5DataDir: this.#ui5DataDir,
4155
};
4256
}
4357

@@ -74,6 +88,7 @@ class Configuration {
7488
});
7589
}
7690
}
91+
7792
return new Configuration(config);
7893
}
7994

lib/graph/helpers/ui5Framework.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Module from "../Module.js";
22
import ProjectGraph from "../ProjectGraph.js";
33
import {getLogger} from "@ui5/logger";
44
const log = getLogger("graph:helpers:ui5Framework");
5+
import Configuration from "../../config/Configuration.js";
6+
import path from "node:path";
57

68
class ProjectProcessor {
79
constructor({libraryMetadata, graph, workspace}) {
@@ -363,13 +365,20 @@ export default {
363365
});
364366
}
365367

368+
const config = await Configuration.fromFile();
369+
// ENV var should take precedence over the dataDir from the configuration.
370+
const ui5HomeDir = process.env.UI5_DATA_DIR ?
371+
path.resolve(process.env.UI5_DATA_DIR) :
372+
config.getUi5DataDir();
373+
366374
// Note: version might be undefined here and the Resolver will throw an error when calling
367375
// #install and it can't be resolved via the provided library metadata
368376
const resolver = new Resolver({
369377
cwd: rootProject.getRootPath(),
370378
version,
371379
providedLibraryMetadata,
372-
cacheMode
380+
cacheMode,
381+
ui5HomeDir
373382
});
374383

375384
let startTime;

test/lib/config/Configuration.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ test.serial("Build configuration with defaults", (t) => {
3434
const config = new Configuration({});
3535

3636
t.deepEqual(config.toJson(), {
37-
mavenSnapshotEndpointUrl: undefined
37+
mavenSnapshotEndpointUrl: undefined,
38+
ui5DataDir: undefined,
3839
});
3940
});
4041

@@ -43,7 +44,8 @@ test.serial("Overwrite defaults defaults", (t) => {
4344
const {Configuration} = t.context;
4445

4546
const params = {
46-
mavenSnapshotEndpointUrl: "https://snapshot.url"
47+
mavenSnapshotEndpointUrl: "https://snapshot.url",
48+
ui5DataDir: "/custom/data/dir"
4749
};
4850

4951
const config = new Configuration(params);
@@ -55,12 +57,14 @@ test.serial("Check getters", (t) => {
5557
const {Configuration} = t.context;
5658

5759
const params = {
58-
mavenSnapshotEndpointUrl: "https://snapshot.url"
60+
mavenSnapshotEndpointUrl: "https://snapshot.url",
61+
ui5DataDir: "/custom/data/dir"
5962
};
6063

6164
const config = new Configuration(params);
6265

6366
t.is(config.getMavenSnapshotEndpointUrl(), params.mavenSnapshotEndpointUrl);
67+
t.is(config.getUi5DataDir(), params.ui5DataDir);
6468
});
6569

6670

@@ -69,7 +73,8 @@ test.serial("fromFile", async (t) => {
6973
const {promisifyStub, sinon} = t.context;
7074

7175
const ui5rcContents = {
72-
mavenSnapshotEndpointUrl: "https://snapshot.url"
76+
mavenSnapshotEndpointUrl: "https://snapshot.url",
77+
ui5DataDir: "/custom/data/dir"
7378
};
7479
const responseStub = sinon.stub().resolves(JSON.stringify(ui5rcContents));
7580
promisifyStub.callsFake(() => responseStub);
@@ -90,6 +95,7 @@ test.serial("fromFile: configuration file not found - fallback to default config
9095

9196
t.is(config instanceof Configuration, true, "Created a default configuration");
9297
t.is(config.getMavenSnapshotEndpointUrl(), undefined, "Default settings");
98+
t.is(config.getUi5DataDir(), undefined, "Default settings");
9399
});
94100

95101

@@ -104,6 +110,7 @@ test.serial("fromFile: empty configuration file - fallback to default config", a
104110

105111
t.is(config instanceof Configuration, true, "Created a default configuration");
106112
t.is(config.getMavenSnapshotEndpointUrl(), undefined, "Default settings");
113+
t.is(config.getUi5DataDir(), undefined, "Default settings");
107114
});
108115

109116
test.serial("fromFile: throws", async (t) => {

test/lib/graph/helpers/ui5Framework.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ test.serial("enrichProjectGraph", async (t) => {
113113
cacheMode: undefined,
114114
cwd: dependencyTree.path,
115115
version: dependencyTree.configuration.framework.version,
116+
ui5HomeDir: undefined,
116117
providedLibraryMetadata: undefined
117118
}], "Sapui5Resolver#constructor should be called with expected args");
118119

@@ -319,6 +320,7 @@ test.serial("enrichProjectGraph: With versionOverride", async (t) => {
319320
cacheMode: undefined,
320321
cwd: dependencyTree.path,
321322
version: "1.99.9",
323+
ui5HomeDir: undefined,
322324
providedLibraryMetadata: undefined
323325
}], "Sapui5Resolver#constructor should be called with expected args");
324326
});
@@ -375,6 +377,7 @@ test.serial("enrichProjectGraph: With versionOverride containing snapshot versio
375377
cacheMode: undefined,
376378
cwd: dependencyTree.path,
377379
version: "1.99.9-SNAPSHOT",
380+
ui5HomeDir: undefined,
378381
providedLibraryMetadata: undefined
379382
}], "Sapui5Resolver#constructor should be called with expected args");
380383
});
@@ -431,6 +434,7 @@ test.serial("enrichProjectGraph: With versionOverride containing latest-snapshot
431434
cacheMode: undefined,
432435
cwd: dependencyTree.path,
433436
version: "1.99.9-SNAPSHOT",
437+
ui5HomeDir: undefined,
434438
providedLibraryMetadata: undefined
435439
}], "Sapui5Resolver#constructor should be called with expected args");
436440
});
@@ -587,6 +591,7 @@ test.serial("enrichProjectGraph should resolve framework project with version an
587591
cacheMode: undefined,
588592
cwd: dependencyTree.path,
589593
version: "1.2.3",
594+
ui5HomeDir: undefined,
590595
providedLibraryMetadata: undefined
591596
}], "Sapui5Resolver#constructor should be called with expected args");
592597
});
@@ -685,6 +690,7 @@ test.serial("enrichProjectGraph should resolve framework project " +
685690
cacheMode: undefined,
686691
cwd: dependencyTree.path,
687692
version: "1.99.9",
693+
ui5HomeDir: undefined,
688694
providedLibraryMetadata: undefined
689695
}], "Sapui5Resolver#constructor should be called with expected args");
690696
});
@@ -949,6 +955,7 @@ test.serial("enrichProjectGraph should use framework library metadata from works
949955
cacheMode: undefined,
950956
cwd: dependencyTree.path,
951957
version: "1.111.1",
958+
ui5HomeDir: undefined,
952959
providedLibraryMetadata: workspaceFrameworkLibraryMetadata
953960
}], "Sapui5Resolver#constructor should be called with expected args");
954961
t.is(Sapui5ResolverStub.getCall(0).args[0].providedLibraryMetadata, workspaceFrameworkLibraryMetadata);
@@ -1006,6 +1013,7 @@ test.serial("enrichProjectGraph should allow omitting framework version in case
10061013
t.deepEqual(Sapui5ResolverStub.getCall(0).args, [{
10071014
cacheMode: undefined,
10081015
cwd: dependencyTree.path,
1016+
ui5HomeDir: undefined,
10091017
version: undefined,
10101018
providedLibraryMetadata: workspaceFrameworkLibraryMetadata
10111019
}], "Sapui5Resolver#constructor should be called with expected args");

test/lib/ui5framework/Sapui5MavenSnapshotResolver.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ test.serial("_resolveSnapshotEndpointUrl: Maven fallback with config update", as
480480
t.is(configFromFile.callCount, 1, "Configuration has been read once");
481481
t.is(configToFile.callCount, 1, "Configuration has been written once");
482482
t.deepEqual(configToFile.firstCall.firstArg.toJson(), {
483-
mavenSnapshotEndpointUrl: "maven-url"
483+
mavenSnapshotEndpointUrl: "maven-url",
484+
ui5DataDir: undefined
484485
}, "Correct configuration has been written");
485486
});
486487

0 commit comments

Comments
 (0)