Skip to content

Commit

Permalink
Fix Vue frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
fvclaus authored and Frederik Claus committed Jun 25, 2023
1 parent b333782 commit d546eea
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node/
.idea/
*.iml
.vscode/
docker/plugins/*.jar
31 changes: 31 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "3"

services:
sonarqube:
image: sonarqube:10.1.0-community
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- sonarqube_data:/opt/sonarqube/data
- ./plugins:/opt/sonarqube/extensions/plugins
- sonarqube_logs:/opt/sonarqube/logs
ports:
- "9000:9000"
db:
image: postgres:12
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data

volumes:
sonarqube_data:
sonarqube_logs:
postgresql:
postgresql_data:
Empty file added docker/plugins/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions jsonconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"include": [
"./src/main/web/**/*"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"build": "webpack --mode=production",
"watch": "concurrently --kill-others \"webpack -w\" \"node test-server.js\"",
"watch": "concurrently --kill-others \"webpack --watch --mode development --devtool inline-source-map\" \"node test-server.js\"",
"generate-icons": "vsvg -s ./svg-icons -t ./src/compiled-icons"
},
"author": "Christian Köberl",
Expand Down
51 changes: 24 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,33 +117,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>unpack</id>
<phase>clean</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-application</artifactId>
<version>${sonarqube.version}</version>
<type>zip</type>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<includes>sonarqube-*/lib/sonar-application*</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
Expand Down Expand Up @@ -232,6 +205,30 @@
<npmVersion>8.11.0</npmVersion>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/docker/plugins</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void execute(SensorContext context)
AGGREGATED_DEPENDENCIES.addAll(validatedDependencies);

// root module?
if (context.project().key().equals(context.project().key()))
if (context.project().key().equals(context.module().key()))
{
saveDependencies(context, AGGREGATED_DEPENDENCIES);
saveLicenses(context, AGGREGATED_LICENSES);
Expand Down
66 changes: 9 additions & 57 deletions src/main/web/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,18 @@
import Vue from 'vue';
import Licenses from './dashboard/licenses.vue';
import Dependencies from './dashboard/dependencies.vue';
import saveAs from 'file-saverjs';
import buildExcel from './dashboard/excel-builder';
import Dashboard from './dashboard/dashboard.vue';

window.registerExtension('licensecheck/dashboard', function (options) {

const app = new Vue({
el: options.el,
data: () => {
return {
licenses: [],
dependencies: [],
component: options.component
}
},
created() {
let params = new URLSearchParams(window.location.search);
let request = {
component : options.component.key,
metricKeys : "licensecheck.license,licensecheck.dependency"
};
if (params.has("branch")) {
request.branch = params.get("branch");
} else if (params.has("pullRequest")) {
request.pullRequest = params.get("pullRequest");
}
window.SonarRequest
.getJSON("/api/measures/component", request)
.then(response => {
response.component.measures.forEach(measure => {
if (measure.metric === 'licensecheck.license') {
this.licenses = JSON.parse(measure.value);
} else if (measure.metric === 'licensecheck.dependency') {
this.dependencies = JSON.parse(measure.value);
}
});
this.dependencies.forEach(dependency => {
dependency.status = 'Unknown';
this.licenses.forEach(license => {
if (dependency.license === license.identifier) {
dependency.status = license.status === 'true' ? 'Allowed' : 'Forbidden';
}
});
});
});
},
methods: {
exportExcel() {
const blob = new Blob([buildExcel(this.dependencies, this.licenses)], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
saveAs(blob, `license-check-${this.component.key}.xls`);
}
},
template: `<div class="page page-limited">
<h1>License Check</h1>
<div><a href="#" v-on:click="exportExcel()">Export to Excel</a></div>
<p>&nbsp;</p>
<licenses :licenses="licenses"></licenses>
<p>&nbsp;</p>
<dependencies :dependencies="dependencies"></dependencies>
</div>`,
components: { Licenses, Dependencies },
// Cannot use `template`. Eval is blocked by CSP
render(createElement) {
return createElement(Dashboard, {
props: {
options
}
})
}
});

return function () {
Expand Down
67 changes: 67 additions & 0 deletions src/main/web/dashboard/dashboard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<template>
<div class="page page-limited">
<h1>License Check</h1>
<div><a href="#" v-on:click="exportExcel()">Export to Excel</a></div>
<p>&nbsp;</p>
<licenses :licenses="licenses"></licenses>
<p>&nbsp;</p>
<dependencies :dependencies="dependencies"></dependencies>
</div>
</template>

<script>
import Licenses from './licenses.vue';
import Dependencies from './dependencies.vue';
import saveAs from 'file-saverjs';
import buildExcel from './excel-builder';
export default {
props: ["options"],
data() {
return {
licenses: [],
dependencies: [],
component: this.options.component
}
},
created() {
let params = new URLSearchParams(window.location.search);
let request = {
component : this.component.key,
metricKeys : "licensecheck.license,licensecheck.dependency"
};
if (params.has("branch")) {
request.branch = params.get("branch");
} else if (params.has("pullRequest")) {
request.pullRequest = params.get("pullRequest");
}
window.SonarRequest
.getJSON("/api/measures/component", request)
.then(response => {
response.component.measures.forEach(measure => {
if (measure.metric === 'licensecheck.license') {
this.licenses = JSON.parse(measure.value);
} else if (measure.metric === 'licensecheck.dependency') {
this.dependencies = JSON.parse(measure.value);
}
});
this.dependencies.forEach(dependency => {
dependency.status = 'Unknown';
this.licenses.forEach(license => {
if (dependency.license === license.identifier) {
dependency.status = license.status === 'true' ? 'Allowed' : 'Forbidden';
}
});
});
});
},
methods: {
exportExcel() {
const blob = new Blob([buildExcel(this.dependencies, this.licenses)], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
saveAs(blob, `license-check-${this.component.key}.xls`);
}
},
components: { Licenses, Dependencies },
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.Test;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.batch.sensor.measure.NewMeasure;
Expand Down Expand Up @@ -58,6 +59,9 @@ public void execute() throws IllegalAccessException
FieldUtils.writeField(sensor, "scanners", scanners, true);
SensorContext context = mock(SensorContext.class);
InputProject project = mock(InputProject.class);
InputModule module = mock(InputModule.class);
when(module.key()).thenReturn("my-project");
when(context.module()).thenReturn(module);
when(project.key()).thenReturn("my-project");
when(context.project()).thenReturn(project);
NewMeasure measure = mock(NewMeasure.class);
Expand Down

0 comments on commit d546eea

Please sign in to comment.