Skip to content

Commit

Permalink
License list moved to the main plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gquerret committed Mar 23, 2020
1 parent f55cc0d commit 4ac2c94
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 1 deletion.
10 changes: 10 additions & 0 deletions openedge-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-ws</artifactId>
<version>7.9</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.sonar.plugins.openedge.sensor.OpenEdgeProparseSensor;
import org.sonar.plugins.openedge.sensor.OpenEdgeSensor;
import org.sonar.plugins.openedge.sensor.OpenEdgeWarningsSensor;
import org.sonar.plugins.openedge.web.OpenEdgeWebService;
import org.sonar.plugins.openedge.web.UiPageDefinition;

public class OpenEdgePlugin implements Plugin {
private static final String CATEGORY_OPENEDGE = "OpenEdge";
Expand Down Expand Up @@ -73,6 +75,11 @@ public void define(Context context) {
// Decorators
context.addExtensions(CommonMetricsDecorator.class, CommonDBMetricsDecorator.class);

// Web page + Web service handler
if (context.getRuntime().getProduct() == SonarProduct.SONARQUBE) {
context.addExtensions(UiPageDefinition.class, OpenEdgeWebService.class);
}

// Properties
context.addExtension(PropertyDefinition.builder(Constants.SKIP_RCODE) //
.name("Skip rcode parsing") //
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* OpenEdge plugin for SonarQube
* Copyright (C) 2013-2020 Riverside Software
* contact AT riverside DASH software DOT fr
*
* 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 02
*/
package org.sonar.plugins.openedge.web;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Base64;

import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.plugins.openedge.api.LicenseRegistration.License;
import org.sonar.plugins.openedge.foundation.OpenEdgeComponents;

public class OpenEdgeWebService implements WebService {
private final OpenEdgeComponents components;

public OpenEdgeWebService(OpenEdgeComponents components) {
this.components = components;
}

@Override
public void define(Context context) {
NewController controller = context.createController("api/openedge").setDescription("OpenEdge plugin web service");
controller.createAction("licenses").setDescription("Licenses list").setHandler(
new LicenseRequestHandler()).setSince("2.0.3").setResponseExample(
getClass().getResource("/org/sonar/openedge-licenses-response-example.json"));
controller.done();
}

private class LicenseRequestHandler implements RequestHandler {

@Override
public void handle(Request request, Response response) throws Exception {
try (JsonWriter writer = response.newJsonWriter()) {
writer.beginObject().name("licenses").beginArray();
for (License lic : components.getLicenses()) {
writer.beginObject() //
.prop("permanentId", lic.getPermanentId()) //
.prop("product", lic.getProduct().toString()) //
.prop("customer", lic.getCustomerName()) //
.prop("repository", lic.getRepositoryName()) //
.prop("type", lic.getType().name()) //
.prop("signature", Base64.getEncoder().encodeToString(lic.getSig())) //
.prop("expiration", LocalDateTime.ofEpochSecond(lic.getExpirationDate() / 1000, 0, ZoneOffset.UTC).format(
DateTimeFormatter.ISO_LOCAL_DATE_TIME)) //
.endObject();
}
writer.endArray().endObject();
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* OpenEdge plugin for SonarQube
* Copyright (C) 2013-2020 Riverside Software
* contact AT riverside DASH software DOT fr
*
* 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 02
*/
package org.sonar.plugins.openedge.web;

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

public class UiPageDefinition implements PageDefinition {
@Override
public void define(Context context) {
context.addPage(Page.builder("openedge/license_recap").setName("OpenEdge rules licenses").setAdmin(true).build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"licenses": [
{
"permanentId": "123456789",
"customer": "Riverside Software",
"repository": "rssw-oe-main",
"type": "COMMERCIAL",
"signature": "Base64SignatureHere",
"expiration": "2039-12-31T23:00:00"
},
{
"permanentId": "sonarlint-123456789",
"customer": "Riverside Software",
"repository": "rssw-oe-main",
"type": "COMMERCIAL",
"signature": "Base64SignatureHere",
"expiration": "2039-12-31T23:00:00"
}
]
}
127 changes: 127 additions & 0 deletions openedge-plugin/src/main/resources/static/license_recap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
window.registerExtension('openedge/license_recap', function (options) {
var isDisplayed = true;
window.SonarRequest.getJSON('/api/openedge/licenses', { }).then(function (response) {
if (isDisplayed) {
options.el.className = 'page page-limited';

var header = document.createElement('h1');
header.textContent = 'CABL rules • Licenses';
options.el.appendChild(header);

var tbl = document.createElement('table');
tbl.className = 'data zebra zebra-hover';
tbl.style.cssText = 'table-layout: fixed;';
options.el.appendChild(tbl);

var thead = document.createElement('thead');
tbl.appendChild(thead);
var theadLine = document.createElement('tr');
thead.appendChild(theadLine);

var theadCol = document.createElement('th');
theadCol.textContent = 'Company name';
theadLine.appendChild(theadCol);

theadCol = document.createElement('th');
theadCol.textContent = 'Server ID';
theadCol.width = 200
theadLine.appendChild(theadCol);

theadCol = document.createElement('th');
theadCol.textContent = 'Product';
theadCol.width = 150
theadLine.appendChild(theadCol);

theadCol = document.createElement('th');
theadCol.textContent = 'Repository';
theadCol.width = 130
theadLine.appendChild(theadCol);

theadCol = document.createElement('th');
theadCol.textContent = 'Expiration';
theadCol.width = 200
theadLine.appendChild(theadCol);

var bdy = document.createElement('tbody');
tbl.appendChild(bdy);

for (var i = 0; i < response.licenses.length ; i++) {
var ln = document.createElement('tr');
bdy.appendChild(ln);

var fld1 = document.createElement('td');
fld1.textContent = response.licenses[i].customer;
ln.appendChild(fld1);

var fld2 = document.createElement('td');
fld2.textContent = response.licenses[i].permanentId;
ln.appendChild(fld2);

var fld3 = document.createElement('td');
fld3.textContent = response.licenses[i].product;
ln.appendChild(fld3);

var fld4 = document.createElement('td');
fld4.textContent = response.licenses[i].repository;
ln.appendChild(fld4);

var fld5 = document.createElement('td');
fld5.textContent = response.licenses[i].expiration;
ln.appendChild(fld5);
}

var hr1 = document.createElement('hr');
hr1.style.cssText = 'height: 8px; margin-top: 10px; margin-bottom: 10px;';
options.el.appendChild(hr1);
var header2 = document.createElement('h1');
header2.textContent = 'CABL rules • Request new license';
options.el.appendChild(header2);

var tbl2 = document.createElement('table');
options.el.appendChild(tbl2);
var bdy2 = document.createElement('tbody');
tbl2.appendChild(bdy2);

var ln4 = document.createElement('tr');
bdy2.appendChild(ln4);
var col3 = document.createElement('td');
col3.style.cssText = 'padding: 10px;';
ln4.appendChild(col3);

var ln2 = document.createElement('tr');
bdy2.appendChild(ln2);
var col1 = document.createElement('td');
col1.style.cssText = 'padding: 10px;';
col1.innerHTML = 'Your CABL licenses can be managed at <a href="https://cabl.riverside-software.fr">https://cabl.riverside-software.fr</a>. ';
ln2.appendChild(col1);
var ln3 = document.createElement('tr');
bdy2.appendChild(ln3);
var col2 = document.createElement('td');
col2.style.cssText = 'padding: 10px;';
ln3.appendChild(col2);
var pre2 = document.createElement('pre');
pre2.id = 'cabl-input';
pre2.style.cssText = 'width: 600px; overflow: auto; background-color: #bbbbbb; border: 1px solid #898989; padding: 5px; white-space: pre-wrap; ';
col2.appendChild(pre2);
var code2 = document.createElement('code');
pre2.appendChild(code2);

window.SonarRequest.getJSON('/api/riverside/oeinfo', { }).then(function (response) {
code2.textContent = JSON.stringify(response);

var cablLink = document.createElement('a');
cablLink.href = 'https://cabl.riverside-software.fr/#/licenses?licenseRequest=' + encodeURI(JSON.stringify(response));
cablLink.textContent = 'Acquire or renew license for this server';
cablLink.rel = 'noopener noreferrer';
cablLink.target = '_blank';
col3.appendChild(cablLink);
}).catch(function (error) {
code2.textContent = "Riverside Rules plugin is not installed...";
});
}
});

return function () {
isDisplayed = false;
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testExtensionsSonarQube() {
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.2"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
Plugin.Context context = new Plugin.Context(runtime);
new OpenEdgePlugin().define(context);
assertThat(context.getExtensions()).hasSize(30);
assertThat(context.getExtensions()).hasSize(32);
}

}

0 comments on commit 4ac2c94

Please sign in to comment.