diff --git a/.changeset/clean-forks-love.md b/.changeset/clean-forks-love.md new file mode 100644 index 0000000000..f81fe3066b --- /dev/null +++ b/.changeset/clean-forks-love.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-sonarqube-backend': patch +--- + +Added support for the [new backend system](https://backstage.io/docs/backend-system/) diff --git a/packages/backend-next/package.json b/packages/backend-next/package.json index edda247a5a..0e8ed62fbb 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -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:^" }, diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 4e99732a11..e61e303e9c 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -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(); diff --git a/plugins/sonarqube-backend/README.md b/plugins/sonarqube-backend/README.md index b417fea7c4..1a1e2ae2dd 100644 --- a/plugins/sonarqube-backend/README.md +++ b/plugins/sonarqube-backend/README.md @@ -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. diff --git a/plugins/sonarqube-backend/api-report.md b/plugins/sonarqube-backend/api-report.md index 535db37185..c3c684f9d4 100644 --- a/plugins/sonarqube-backend/api-report.md +++ b/plugins/sonarqube-backend/api-report.md @@ -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) ``` diff --git a/plugins/sonarqube-backend/package.json b/plugins/sonarqube-backend/package.json index ec5a2ed887..2cb0fd9636 100644 --- a/plugins/sonarqube-backend/package.json +++ b/plugins/sonarqube-backend/package.json @@ -29,6 +29,7 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/config": "workspace:^", "@backstage/errors": "workspace:^", "@types/express": "*", diff --git a/plugins/sonarqube-backend/src/index.ts b/plugins/sonarqube-backend/src/index.ts index c91aef09f8..4bb82df34e 100644 --- a/plugins/sonarqube-backend/src/index.ts +++ b/plugins/sonarqube-backend/src/index.ts @@ -16,3 +16,4 @@ export * from './service/router'; export * from './service/sonarqubeInfoProvider'; +export { sonarqubePlugin as default } from './plugin'; diff --git a/plugins/sonarqube-backend/src/plugin.test.tsx b/plugins/sonarqube-backend/src/plugin.test.tsx new file mode 100644 index 0000000000..9b26a88862 --- /dev/null +++ b/plugins/sonarqube-backend/src/plugin.test.tsx @@ -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(); + }); +}); diff --git a/plugins/sonarqube-backend/src/plugin.ts b/plugins/sonarqube-backend/src/plugin.ts new file mode 100644 index 0000000000..fd4fb77fb4 --- /dev/null +++ b/plugins/sonarqube-backend/src/plugin.ts @@ -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), + }), + ); + }, + }); + }, +}); diff --git a/yarn.lock b/yarn.lock index c0a75005bf..cf41441920 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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