Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Allow to configure location of UI5 home directory #635

Merged
merged 11 commits into from
Aug 8, 2023
17 changes: 16 additions & 1 deletion lib/config/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import os from "node:os";
*/
class Configuration {
#mavenSnapshotEndpointUrl;
#ui5DataDir;

/**
* @param {object} configuration
* @param {string} [configuration.mavenSnapshotEndpointUrl]
* @param {string} [configuration.ui5DataDir]
*/
constructor({mavenSnapshotEndpointUrl}) {
constructor({mavenSnapshotEndpointUrl, ui5DataDir}) {
d3xter666 marked this conversation as resolved.
Show resolved Hide resolved
this.#mavenSnapshotEndpointUrl = mavenSnapshotEndpointUrl;
this.#ui5DataDir = ui5DataDir;
}

/**
Expand All @@ -31,13 +34,24 @@ class Configuration {
return this.#mavenSnapshotEndpointUrl;
}

/**
* Configurable directory where the framework artefacts are stored.
*
* @public
* @returns {string}
*/
getUi5DataDir() {
return this.#ui5DataDir;
}

/**
* @public
* @returns {object} The configuration in a JSON format
*/
toJson() {
return {
mavenSnapshotEndpointUrl: this.#mavenSnapshotEndpointUrl,
ui5DataDir: this.#ui5DataDir,
};
}

Expand Down Expand Up @@ -74,6 +88,7 @@ class Configuration {
});
}
}

return new Configuration(config);
}

Expand Down
11 changes: 10 additions & 1 deletion lib/graph/helpers/ui5Framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Module from "../Module.js";
import ProjectGraph from "../ProjectGraph.js";
import {getLogger} from "@ui5/logger";
const log = getLogger("graph:helpers:ui5Framework");
import Configuration from "../../config/Configuration.js";
import path from "node:path";

class ProjectProcessor {
constructor({libraryMetadata, graph, workspace}) {
Expand Down Expand Up @@ -363,13 +365,20 @@ export default {
});
}

const config = await Configuration.fromFile();
// ENV var should take precedence over the dataDir from the configuration.
const ui5HomeDir = process.env.UI5_DATA_DIR ?
path.resolve(path.join(process.env.UI5_DATA_DIR, ".ui5")) :
d3xter666 marked this conversation as resolved.
Show resolved Hide resolved
config.getUi5DataDir();

// Note: version might be undefined here and the Resolver will throw an error when calling
// #install and it can't be resolved via the provided library metadata
const resolver = new Resolver({
cwd: rootProject.getRootPath(),
version,
providedLibraryMetadata,
cacheMode
cacheMode,
ui5HomeDir
});

let startTime;
Expand Down
15 changes: 11 additions & 4 deletions test/lib/config/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ test.serial("Build configuration with defaults", (t) => {
const config = new Configuration({});

t.deepEqual(config.toJson(), {
mavenSnapshotEndpointUrl: undefined
mavenSnapshotEndpointUrl: undefined,
ui5DataDir: undefined,
});
});

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

const params = {
mavenSnapshotEndpointUrl: "https://snapshot.url"
mavenSnapshotEndpointUrl: "https://snapshot.url",
ui5DataDir: "/custom/data/dir"
};

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

const params = {
mavenSnapshotEndpointUrl: "https://snapshot.url"
mavenSnapshotEndpointUrl: "https://snapshot.url",
ui5DataDir: "/custom/data/dir"
};

const config = new Configuration(params);

t.is(config.getMavenSnapshotEndpointUrl(), params.mavenSnapshotEndpointUrl);
t.is(config.getUi5DataDir(), params.ui5DataDir);
});


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

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

t.is(config instanceof Configuration, true, "Created a default configuration");
t.is(config.getMavenSnapshotEndpointUrl(), undefined, "Default settings");
t.is(config.getUi5DataDir(), undefined, "Default settings");
});


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

t.is(config instanceof Configuration, true, "Created a default configuration");
t.is(config.getMavenSnapshotEndpointUrl(), undefined, "Default settings");
t.is(config.getUi5DataDir(), undefined, "Default settings");
});

test.serial("fromFile: throws", async (t) => {
Expand Down
8 changes: 8 additions & 0 deletions test/lib/graph/helpers/ui5Framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ test.serial("enrichProjectGraph", async (t) => {
cacheMode: undefined,
cwd: dependencyTree.path,
version: dependencyTree.configuration.framework.version,
ui5HomeDir: undefined,
providedLibraryMetadata: undefined
}], "Sapui5Resolver#constructor should be called with expected args");

Expand Down Expand Up @@ -319,6 +320,7 @@ test.serial("enrichProjectGraph: With versionOverride", async (t) => {
cacheMode: undefined,
cwd: dependencyTree.path,
version: "1.99.9",
ui5HomeDir: undefined,
providedLibraryMetadata: undefined
}], "Sapui5Resolver#constructor should be called with expected args");
});
Expand Down Expand Up @@ -375,6 +377,7 @@ test.serial("enrichProjectGraph: With versionOverride containing snapshot versio
cacheMode: undefined,
cwd: dependencyTree.path,
version: "1.99.9-SNAPSHOT",
ui5HomeDir: undefined,
providedLibraryMetadata: undefined
}], "Sapui5Resolver#constructor should be called with expected args");
});
Expand Down Expand Up @@ -431,6 +434,7 @@ test.serial("enrichProjectGraph: With versionOverride containing latest-snapshot
cacheMode: undefined,
cwd: dependencyTree.path,
version: "1.99.9-SNAPSHOT",
ui5HomeDir: undefined,
providedLibraryMetadata: undefined
}], "Sapui5Resolver#constructor should be called with expected args");
});
Expand Down Expand Up @@ -587,6 +591,7 @@ test.serial("enrichProjectGraph should resolve framework project with version an
cacheMode: undefined,
cwd: dependencyTree.path,
version: "1.2.3",
ui5HomeDir: undefined,
providedLibraryMetadata: undefined
}], "Sapui5Resolver#constructor should be called with expected args");
});
Expand Down Expand Up @@ -685,6 +690,7 @@ test.serial("enrichProjectGraph should resolve framework project " +
cacheMode: undefined,
cwd: dependencyTree.path,
version: "1.99.9",
ui5HomeDir: undefined,
providedLibraryMetadata: undefined
}], "Sapui5Resolver#constructor should be called with expected args");
});
Expand Down Expand Up @@ -949,6 +955,7 @@ test.serial("enrichProjectGraph should use framework library metadata from works
cacheMode: undefined,
cwd: dependencyTree.path,
version: "1.111.1",
ui5HomeDir: undefined,
providedLibraryMetadata: workspaceFrameworkLibraryMetadata
}], "Sapui5Resolver#constructor should be called with expected args");
t.is(Sapui5ResolverStub.getCall(0).args[0].providedLibraryMetadata, workspaceFrameworkLibraryMetadata);
Expand Down Expand Up @@ -1006,6 +1013,7 @@ test.serial("enrichProjectGraph should allow omitting framework version in case
t.deepEqual(Sapui5ResolverStub.getCall(0).args, [{
cacheMode: undefined,
cwd: dependencyTree.path,
ui5HomeDir: undefined,
version: undefined,
providedLibraryMetadata: workspaceFrameworkLibraryMetadata
}], "Sapui5Resolver#constructor should be called with expected args");
Expand Down
3 changes: 2 additions & 1 deletion test/lib/ui5framework/Sapui5MavenSnapshotResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ test.serial("_resolveSnapshotEndpointUrl: Maven fallback with config update", as
t.is(configFromFile.callCount, 1, "Configuration has been read once");
t.is(configToFile.callCount, 1, "Configuration has been written once");
t.deepEqual(configToFile.firstCall.firstArg.toJson(), {
mavenSnapshotEndpointUrl: "maven-url"
mavenSnapshotEndpointUrl: "maven-url",
ui5DataDir: undefined
}, "Correct configuration has been written");
});

Expand Down