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

Integration as a sonar page #12

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 238 additions & 0 deletions sonar-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<name>Ecocode-sonarqube-dashboard</name>
<groupId>io.ecocode</groupId>
<artifactId>ecocode-sonarqube-dashboard</artifactId>
<packaging>sonar-plugin</packaging>
<version>0.0.1</version>
<description>Provides Dashboard for ecocode plugin</description>
<inceptionYear>2024</inceptionYear>
<url>https://github.com/green-code-initiative/ecoCode-dashboard.git</url>
<organization>
<name>green-code-initiative</name>
<url>https://github.com/green-code-initiative</url>
</organization>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gson.version>2.9.1</gson.version>
<jdk.min.version>11</jdk.min.version>
<sonar.sources>src/main/java,src/main/js</sonar.sources>
<sonarjava.version>7.2.0.26923</sonarjava.version>
<sonarphp.version>3.23.1.8766</sonarphp.version>
<sonarpython.version>3.4.1.8066</sonarpython.version>
<sonar.apiVersion>8.9.9.56886</sonar.apiVersion>
</properties>

<dependencies>
<!-- Common -->
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonar.apiVersion}</version>
<scope>provided</scope>
</dependency>
<!--<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-java-plugin</artifactId>
<version>${sonarjava.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.php</groupId>
<artifactId>sonar-php-plugin</artifactId>
<type>sonar-plugin</type>
<version>${sonarphp.version}</version>
<scope>provided</scope>
</dependency>-->
<!-- Needed by sonar php plugin, shouldn't be needed, need digging -->
<!-- Notice there is no <scope>provided</scope>, this because otherwise scans fail
on Sonarqube -->
<dependency>
<groupId>org.sonarsource.sslr</groupId>
<artifactId>sslr-core</artifactId>
<version>1.24.0.633</version>
</dependency>

<!-- There is no <scope>provided</scope> because scan fail otherwise with class not found exception -->
<!--<dependency>
<groupId>org.sonarsource.python</groupId>
<artifactId>sonar-python-plugin</artifactId>
<type>sonar-plugin</type>
<version>${sonarpython.version}</version>
</dependency>-->

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>

<!-- Tests deps (there is no php testkit because such package doesn't exist for some reason ) -->
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>java-checks-testkit</artifactId>
<version>${sonarjava.version}</version>
<scope>test</scope>
</dependency>
<!--<dependency>
<groupId>org.sonarsource.python</groupId>
<artifactId>python-checks-testkit</artifactId>
<version>${sonarpython.version}</version>
<scope>test</scope>
</dependency>-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<!--<resources>
<resource>
<directory>../dist</directory>
</resource>
</resources>-->
<plugins>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.21.0.505</version>
<extensions>true</extensions>
<configuration>
<pluginKey>ecocode</pluginKey>
<pluginClass>io.ecocode.plugin.EcocodeDashboardPlugin</pluginClass>
<sonarQubeMinVersion>${sonar.apiVersion}</sonarQubeMinVersion>
<!-- <requirePlugins>java:${sonarjava.version}</requirePlugins>
<requirePlugins>php:${sonarphp.version}</requirePlugins>
<requirePlugins>python:${sonarpython.version}</requirePlugins> -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${jdk.min.version}</source>
<target>${jdk.min.version}</target>
</configuration>
</plugin>

<!-- This plugin execute in order npm install and npm run build -->
<!-- This allow maven to create a production build of the front app -->
<!-- Maven will look for files in target/classes/static folder -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>

<executions>
<execution>

<!-- this line is to make linting happy, it has no effect on the build -->
<?m2e execute onConfiguration,onIncremental?>

<id>npm install</id>
<phase>initialize</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
<execution>

<!-- this line is to make linting happy, it has no effect on the build -->
<?m2e execute onConfiguration,onIncremental?>

<id>npm run build</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>7.1.1</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- maven-resources-plugin to copy the website -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>../dist/assets</directory>
<targetPath>${project.build.outputDirectory}/static</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<!-- maven-jar-plugin to include the website in the jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<includes>
<include>**/*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Package

package io.ecocode.plugin;

import org.sonar.api.Plugin;

import io.ecocode.plugin.web.EcocodeDashboardPageDefinition;

/**
* Main plugin class
*/
public class EcocodeDashboardPlugin implements Plugin {
@Override
public void define(Context context) {
context.addExtension(EcocodeDashboardPageDefinition.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Example Plugin for SonarQube
* Copyright (C) 2009-2020 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.ecocode.plugin.web;

import org.sonar.api.web.page.Context;
import org.sonar.api.web.page.Page;
import org.sonar.api.web.page.PageDefinition;

import static org.sonar.api.web.page.Page.Scope.COMPONENT;

/**
* Define EcoCode Dashboard additional page
*/
public class EcocodeDashboardPageDefinition implements PageDefinition {

@Override
public void define(Context context) {
context
.addPage(Page.builder("ecocode-sonarqube-dashboard/view")
.setName("EcoCode Dashboard")
.setScope(COMPONENT)
.build());
}
}
13 changes: 10 additions & 3 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueDevTools from 'vite-plugin-vue-devtools'
import { defineConfig } from 'vite'
import { fileURLToPath } from 'url'

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -14,5 +13,13 @@ export default defineConfig({
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
build: {
rollupOptions: {
output: {
entryFileNames: `assets/view.js`,
assetFileNames: `assets/view.css`
}
}
}
})
Loading