Skip to content

Commit 9764e68

Browse files
dklilleyGitHub Enterprise
authored andcommitted
Merge pull request mathworks#36 from development/skondapa.feature.trigger-licensing-workflows
Feature:Integrate licensing workflows
2 parents 7f97392 + 77036f9 commit 9764e68

File tree

96 files changed

+50238
-4313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+50238
-4313
lines changed

package-lock-old.json

Lines changed: 9664 additions & 0 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 2005 additions & 4220 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
"bin": "./out/index.js",
77
"scripts": {
88
"vscode:prepublish": "npm run package",
9-
"compile": "webpack --mode development",
9+
"compile": "webpack --mode development && mkdir -p ./out/licensing/static && cd src/licensing/gui && npm run build && cd ../../.. && cp -R src/licensing/gui/build/* ./out/licensing/static",
1010
"watch": "webpack --watch",
1111
"package": "webpack --mode production --devtool hidden-source-map",
1212
"test-compile": "tsc -p ./",
1313
"test-watch": "tsc -watch -p ./",
1414
"pretest": "npm run test-compile",
1515
"lint": "eslint src --ext ts",
16+
"lint:fix": "eslint src --ext ts --fix",
1617
"test": "mocha"
1718
},
1819
"repository": {
@@ -21,10 +22,15 @@
2122
"author": "The MathWorks, Inc.",
2223
"license": "MIT",
2324
"devDependencies": {
25+
"@types/cookie-parser": "^1.4.7",
26+
"@types/express": "^4.17.21",
27+
"@types/express-session": "^1.18.0",
2428
"@types/mocha": "^10.0.6",
29+
"@types/node-fetch": "^2.6.11",
2530
"@types/node": "^18.7.18",
2631
"@types/sinon": "^17.0.3",
2732
"@types/which": "^2.0.1",
33+
"@types/xml2js": "^0.4.14",
2834
"@types/yargs": "^17.0.12",
2935
"@typescript-eslint/eslint-plugin": "^5.36.1",
3036
"@typescript-eslint/parser": "^5.36.1",
@@ -42,13 +48,18 @@
4248
"webpack": "^5.74.0",
4349
"webpack-cli": "^4.10.0"
4450
},
45-
"dependencies": {
51+
"dependencies": {
4652
"chokidar": "^3.5.3",
53+
"cookie-parser": "^1.4.6",
54+
"express": "^4.18.2",
55+
"express-session": "^1.18.0",
4756
"faye": "^1.4.0",
57+
"node-fetch": "^3.3.2",
4858
"vscode-languageserver": "^8.0.2",
4959
"vscode-languageserver-textdocument": "^1.0.7",
5060
"vscode-uri": "^3.0.6",
5161
"which": "^2.0.2",
62+
"xml2js": "^0.6.2",
5263
"yargs": "^17.5.1"
5364
},
5465
"mocha": {

src/ClientConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright 2024 The MathWorks, Inc.
2-
import { _Connection, createConnection, ProposedFeatures } from "vscode-languageserver/node"
2+
import { _Connection, createConnection, ProposedFeatures } from 'vscode-languageserver/node'
33

44
export type Connection = _Connection
55

src/licensing/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

src/licensing/config.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright 2024 The MathWorks, Inc.
2+
3+
import { promises as fs } from 'fs';
4+
import { findExecutableOnPath, resolveSymlink } from '../utils/FsUtils';
5+
import * as path from 'path';
6+
import * as xml2js from 'xml2js';
7+
import { VersionInfoXML } from './types';
8+
import Logger from '../logging/Logger';
9+
10+
const VERSION_INFO_FILENAME = 'VersionInfo.xml';
11+
12+
export const MWI_AUTH_TOKEN_NAME_FOR_HTTP = 'mwi-auth-token'
13+
14+
export const MWI_AUTH_TOKEN_LENGTH = 32
15+
16+
export const MWI_ENABLE_TOKEN_AUTH = true
17+
18+
export const MWI_LICENSING_SESSION_COOKIE_NAME = 'matlab-licensing-session'
19+
20+
let installPath: string | null = null;
21+
let matlabVersion: string | null = null;
22+
export const staticFolderPath: string = path.join(__dirname, 'licensing', 'static')
23+
24+
/**
25+
* Sets the MATLAB install path. Is called when:
26+
* 1) The LSP is initialzed
27+
* &
28+
* 2) The installPath setting changes by its config change handler
29+
* @param path - The MATLAB install path
30+
*/
31+
export function setInstallPath (path: string): void {
32+
installPath = path;
33+
34+
// When installPath changes, update MATLAB version
35+
getMatlabVersionFromInstallPath(installPath).then((version) => {
36+
matlabVersion = version;
37+
});
38+
}
39+
40+
/**
41+
* Sets the MATLAB version. This function is called to update the current
42+
* MATLAB version in the application state.
43+
*
44+
* @param version - The MATLAB version to be set
45+
*/
46+
export function setMatlabVersion (version: string): void {
47+
matlabVersion = version
48+
}
49+
50+
/**
51+
* Gets the MATLAB version
52+
* @returns {Promise<string | null>} The MATLAB version or null if it cannot be determined
53+
*/
54+
export async function getMatlabVersion (): Promise<string | null> {
55+
// If MATLAB version was already determined (either by this function or the setInstallPath function), return it directly.
56+
if (matlabVersion) {
57+
return matlabVersion
58+
} else {
59+
const matlabExecutableOnPath = await findExecutableOnPath('matlab')
60+
// If there's no matlab executable on system PATH return null
61+
if (!matlabExecutableOnPath) {
62+
return null;
63+
}
64+
65+
const absoluteMatlabPath = await resolveSymlink(matlabExecutableOnPath);
66+
const matlabRoot = path.resolve(absoluteMatlabPath, '..', '..')
67+
68+
// Update matlabVersion variable before returning to avoid recomputation.
69+
matlabVersion = await getMatlabVersionFromInstallPath(matlabRoot)
70+
return matlabVersion
71+
}
72+
}
73+
74+
/**
75+
* Retrieves the MATLAB version from the installation path.
76+
*
77+
* @param pathToMatlabRoot - The path to the MATLAB ROOT.
78+
* @returns {Promise<string|null>} A promise that resolves to the MATLAB version as a string, or null if an error occurs.
79+
*/
80+
async function getMatlabVersionFromInstallPath (pathToMatlabRoot: string) {
81+
const versionInfoPath = path.join(pathToMatlabRoot, VERSION_INFO_FILENAME);
82+
83+
try {
84+
const fileContent = await fs.readFile(versionInfoPath, { encoding: 'utf-8' })
85+
const xmlData = (await xml2js.parseStringPromise(fileContent)) as VersionInfoXML
86+
const versionInfo = xmlData.MathWorks_version_info.release[0]
87+
return versionInfo
88+
} catch (error) {
89+
Logger.error(`Failed to read version info file at path:${versionInfoPath} with error:${error}`)
90+
return null;
91+
}
92+
}

src/licensing/errors.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2024 The MathWorks, Inc.
2+
3+
export class AppError extends Error {
4+
/**
5+
* A Generic Parent class which inherits the Error class.
6+
* This class will be inherited by other classes representing specific exceptions.
7+
*
8+
* @param message - Error message.
9+
* @param logs - Logs associated with the error.
10+
* @param stacktrace - Stacktrace associated with the error.
11+
*/
12+
constructor(
13+
message: string,
14+
public readonly logs: string | null = null,
15+
public readonly stacktrace: string | null = null
16+
) {
17+
super(message);
18+
this.name = this.constructor.name;
19+
}
20+
}
21+
22+
/**
23+
* A Class which inherits the AppError class.
24+
* This class represents any Licensing Errors (MHLM and NLM Licensing)
25+
*/
26+
export class LicensingError extends AppError {}
27+
28+
/**
29+
* A Class which inherits the Licensing class.
30+
* This class represents any errors specific to MHLM Licensing.
31+
*/
32+
export class OnlineLicensingError extends LicensingError {}
33+
34+
/**
35+
* A Class which inherits the LicensingError class.
36+
* This class represents errors with Entitlements in MHLM Licensing.
37+
*/
38+
export class EntitlementError extends LicensingError {}
39+
40+
/**
41+
* A Class which inherits the AppError class.
42+
* This class represents token authentication errors.
43+
*/
44+
export class InvalidTokenError extends AppError {}

src/licensing/gui/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

src/licensing/gui/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Runs the app in the development mode.<br />
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.<br />
13+
You will also see any lint errors in the console.
14+
15+
### `npm test`
16+
17+
Launches the test runner in the interactive watch mode.<br />
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `npm run build`
21+
22+
Builds the app for production to the `build` folder.<br />
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.<br />
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `npm run eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35+
36+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37+
38+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39+
40+
## Learn More
41+
42+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43+
44+
To learn React, check out the [React documentation](https://reactjs.org/).
45+
46+
### Code Splitting
47+
48+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49+
50+
### Analyzing the Bundle Size
51+
52+
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53+
54+
### Making a Progressive Web App
55+
56+
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57+
58+
### Advanced Configuration
59+
60+
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61+
62+
### Deployment
63+
64+
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65+
66+
### `npm run build` fails to minify
67+
68+
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

0 commit comments

Comments
 (0)