Migrate sonarqube-backend plugin to the new backend system #18320

Signed-off-by: Andy Muldoon <andy.muldoon@ericsson.com>
This commit is contained in:
Andy Muldoon
2023-09-14 12:34:47 +01:00
parent 3d3ddfb2c9
commit a5d592d0ad
10 changed files with 110 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-sonarqube-backend': patch
---
Added support for the [new backend system](https://backstage.io/docs/backend-system/)
+1
View File
@@ -52,6 +52,7 @@
"@backstage/plugin-search-backend-module-explore": "workspace:^",
"@backstage/plugin-search-backend-module-techdocs": "workspace:^",
"@backstage/plugin-search-backend-node": "workspace:^",
"@backstage/plugin-sonarqube-backend": "workspace:^",
"@backstage/plugin-techdocs-backend": "workspace:^",
"@backstage/plugin-todo-backend": "workspace:^"
},
+1
View File
@@ -44,5 +44,6 @@ backend.add(import('@backstage/plugin-search-backend-module-techdocs/alpha'));
backend.add(import('@backstage/plugin-search-backend/alpha'));
backend.add(import('@backstage/plugin-techdocs-backend/alpha'));
backend.add(import('@backstage/plugin-todo-backend'));
backend.add(import('@backstage/plugin-sonarqube-backend'));
backend.start();
+14
View File
@@ -2,6 +2,20 @@
Welcome to the sonarqube-backend backend plugin!
## New Backend System
The Sonarqube backend plugin has support for the [new backend system](https://backstage.io/docs/backend-system/), here's how you can set that up:
In your `packages/backend/src/index.ts` make the following changes:
```diff
import { createBackend } from '@backstage/backend-defaults';
const backend = createBackend();
// ... other feature additions
+ backend.add(import('@backstage/plugin-sonarqube-backend');
backend.start();
```
## Integrating into a backstage instance
This plugin needs to be added to an existing backstage instance.
+5
View File
@@ -3,6 +3,7 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import express from 'express';
import { Logger } from 'winston';
@@ -72,5 +73,9 @@ export interface SonarqubeMeasure {
value: string;
}
// @public
const sonarqubePlugin: () => BackendFeature;
export default sonarqubePlugin;
// (No @packageDocumentation comment for this package)
```
+1
View File
@@ -29,6 +29,7 @@
},
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/errors": "workspace:^",
"@types/express": "*",
+1
View File
@@ -16,3 +16,4 @@
export * from './service/router';
export * from './service/sonarqubeInfoProvider';
export { sonarqubePlugin as default } from './plugin';
@@ -0,0 +1,22 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { sonarqubePlugin } from './plugin';
describe('sonarqube', () => {
it('should export the sonarqube plugin', () => {
expect(sonarqubePlugin).toBeDefined();
});
});
+57
View File
@@ -0,0 +1,57 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { loggerToWinstonLogger } from '@backstage/backend-common';
import {
createBackendPlugin,
coreServices,
} from '@backstage/backend-plugin-api';
import { DefaultSonarqubeInfoProvider } from './service/sonarqubeInfoProvider';
import { createRouter } from './service/router';
/**
* Sonarqube backend plugin
*
* @public
*/
export const sonarqubePlugin = createBackendPlugin({
pluginId: 'sonarqube',
register(env) {
env.registerInit({
deps: {
logger: coreServices.logger,
config: coreServices.rootConfig,
httpRouter: coreServices.httpRouter,
},
async init({ logger, config, httpRouter }) {
const winstonLogger = loggerToWinstonLogger(logger);
httpRouter.use(
await createRouter({
/**
* Logger for logging purposes
*/
logger: winstonLogger,
/**
* Info provider to be able to get all necessary information for the APIs
*/
sonarqubeInfoProvider:
DefaultSonarqubeInfoProvider.fromConfig(config),
}),
);
},
});
},
});
+3 -1
View File
@@ -9219,11 +9219,12 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/plugin-sonarqube-backend@workspace:plugins/sonarqube-backend":
"@backstage/plugin-sonarqube-backend@workspace:^, @backstage/plugin-sonarqube-backend@workspace:plugins/sonarqube-backend":
version: 0.0.0-use.local
resolution: "@backstage/plugin-sonarqube-backend@workspace:plugins/sonarqube-backend"
dependencies:
"@backstage/backend-common": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/backend-test-utils": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/config": "workspace:^"
@@ -25973,6 +25974,7 @@ __metadata:
"@backstage/plugin-search-backend-module-explore": "workspace:^"
"@backstage/plugin-search-backend-module-techdocs": "workspace:^"
"@backstage/plugin-search-backend-node": "workspace:^"
"@backstage/plugin-sonarqube-backend": "workspace:^"
"@backstage/plugin-techdocs-backend": "workspace:^"
"@backstage/plugin-todo-backend": "workspace:^"
languageName: unknown