Migrate sonarqube-backend plugin to the new backend system #18320
Signed-off-by: Andy Muldoon <andy.muldoon@ericsson.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
```
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-common": "workspace:^",
|
||||
"@backstage/backend-plugin-api": "workspace:^",
|
||||
"@backstage/config": "workspace:^",
|
||||
"@backstage/errors": "workspace:^",
|
||||
"@types/express": "*",
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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),
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user