Skip to content

Commit

Permalink
Merge pull request mvnpm#1471 from phillip-kruger/col_size
Browse files Browse the repository at this point in the history
Col size
  • Loading branch information
phillip-kruger authored Oct 30, 2023
2 parents 039967e + 0fcf4f5 commit 92c6e71
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 15 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.mvnpm</groupId>
<artifactId>mvnpm</artifactId>
<version>2.0.26-SNAPSHOT</version>
<version>2.0.27-SNAPSHOT</version>

<name>mvnpm</name>
<description>Maven on NPM</description>
Expand Down Expand Up @@ -146,6 +146,12 @@
<artifactId>quarkus-mailer</artifactId>
</dependency>

<!-- To retry -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
</dependency>

<!-- To save to the db -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/io/mvnpm/log/EventLogApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;

import io.mvnpm.mavencentral.sync.*;
Expand All @@ -32,7 +33,7 @@
@ApplicationScoped
public class EventLogApi {

private Set<Session> sessions = new ConcurrentHashSet<>();
private final Set<Session> sessions = new ConcurrentHashSet<>();

@OnOpen
public void onOpen(Session session) {
Expand Down Expand Up @@ -93,4 +94,10 @@ public List<EventLogEntry> getTop(@QueryParam("limit") @DefaultValue("2000") int
return EventLogEntry.findAll(Sort.by("time")).range(0, limit).list();
}

@GET
@Path("/gav/{groupId}/{artifactId}/{version}")
public List<EventLogEntry> getGavLog(@PathParam("groupId") String groupId, @PathParam("artifactId") String artifactId,
@PathParam("version") String version) {
return EventLogEntry.findByGav(groupId, artifactId, version);
}
}
11 changes: 11 additions & 0 deletions src/main/java/io/mvnpm/log/EventLogEntry.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package io.mvnpm.log;

import java.time.LocalDateTime;
import java.util.List;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.NamedQueries;
import jakarta.persistence.NamedQuery;

import io.mvnpm.mavencentral.sync.Stage;
import io.quarkus.hibernate.orm.panache.PanacheEntity;
Expand All @@ -13,13 +17,20 @@
* @author Phillip Kruger ([email protected])
*/
@Entity
@NamedQueries({
@NamedQuery(name = "EventLogEntry.getByGav", query = "from EventLogEntry where groupId = ?1 and artifactId = ?2 and version = ?3 order by time")
})
public class EventLogEntry extends PanacheEntity {
public String groupId;
public String artifactId;
public String version;
public LocalDateTime time;
public Stage stage;
@Column(columnDefinition = "text", length = 10485760)
public String message;
public String color;

public static List<EventLogEntry> findByGav(String groupId, String artifactId, String version) {
return find("#EventLogEntry.getByGav", groupId, artifactId, version).list();
}
}
2 changes: 2 additions & 0 deletions src/main/java/io/mvnpm/mavencentral/SearchMavenClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Response;

import org.eclipse.microprofile.faulttolerance.Retry;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

/**
Expand All @@ -17,6 +18,7 @@ public interface SearchMavenClient {

@GET
@Path("/solrsearch/select")
@Retry(maxRetries = 3)
public Response search(@QueryParam("q") String q,
@QueryParam("core") String core,
@QueryParam("rows") String rows,
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/mvnpm/mavencentral/SonatypeFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import io.mvnpm.Constants;
import io.mvnpm.error.ErrorHandlingService;
import io.mvnpm.npm.model.Name;
import io.quarkus.cache.CacheResult;
import io.quarkus.logging.Log;
import io.smallrye.common.annotation.Blocking;
import io.vertx.core.json.JsonObject;

/**
* Facade on the OSS Sonatype server
* TODO: Add caching for search (5 mins or so)
*
* @author Phillip Kruger ([email protected])
*/
Expand Down Expand Up @@ -56,6 +56,7 @@ public class SonatypeFacade {
String searchMavenUrl;

@Blocking
@CacheResult(cacheName = "maven-search-cache")
public JsonObject search(String groupId, String artifactId, String version) {
String q = String.format(Q_FORMAT, groupId, artifactId, version);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public SyncInfo syncInfo(@PathParam("groupId") String groupId, @PathParam("artif
if (version.equalsIgnoreCase("latest")) {
version = getLatestVersion(name);
}
return centralSyncService.getSyncInfo(groupId, artifactId, version);
return centralSyncService.getSyncInfo(name, version);
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public class CentralSyncService {
@ConfigProperty(name = "mvnpm.local-m2-directory", defaultValue = ".m2")
String localM2Dir;

public SyncInfo getSyncInfo(String groupId, String artifactId, String version) {
boolean checkCentral = isAvailable(groupId, artifactId, version);
boolean checkStaging = isStaged(groupId, artifactId, version);
return new SyncInfo(checkCentral, checkStaging);
public SyncInfo getSyncInfo(Name name, String version) {
boolean checkCentral = isAvailable(name.mvnGroupId(), name.mvnArtifactId(), version);
boolean checkStaging = isStaged(name.mvnGroupId(), name.mvnArtifactId(), version);
return new SyncInfo(name, version, checkCentral, checkStaging);
}

public boolean isAvailable(String groupId, String artifactId, String version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void update(Name name) {
public boolean initializeSync(Name name, String version) {

CentralSyncItem itemInQ = new CentralSyncItem(name, version);
SyncInfo syncInfo = centralSyncService.getSyncInfo(name.mvnGroupId(), name.mvnArtifactId(), version);
SyncInfo syncInfo = centralSyncService.getSyncInfo(name, version);
if (syncInfo.canSync()) { // Check if this is already synced
if (!inProgressQueue.contains(itemInQ)) { // Already somewhere in the process
inProgressQueue.add(itemInQ);
Expand Down Expand Up @@ -152,8 +152,8 @@ void processInitQueue() {
}

private String processUpload(CentralSyncItem centralSyncItem) {
SyncInfo syncInfo = centralSyncService.getSyncInfo(centralSyncItem.getNameVersionType().name().mvnGroupId(),
centralSyncItem.getNameVersionType().name().mvnArtifactId(), centralSyncItem.getNameVersionType().version());
SyncInfo syncInfo = centralSyncService.getSyncInfo(centralSyncItem.getNameVersionType().name(),
centralSyncItem.getNameVersionType().version());
if (syncInfo.canSync()) {
// Kick off an update
Log.debug("Version [" + centralSyncItem.getNameVersionType().version() + "] of "
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/io/mvnpm/mavencentral/sync/SyncInfo.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package io.mvnpm.mavencentral.sync;

import io.mvnpm.npm.model.Name;

public class SyncInfo {
public Name name;
public String version;
public boolean inCentral;
public boolean inStaging;

public SyncInfo() {
}

public SyncInfo(boolean inCentral, boolean inStaging) {
public SyncInfo(Name name, String version, boolean inCentral, boolean inStaging) {
this.name = name;
this.version = version;
this.inCentral = inCentral;
this.inStaging = inStaging;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ quarkus.cache.caffeine."npm-package-cache".expire-after-write=3600S
%test.quarkus.cache.caffeine."npm-package-cache".expire-after-write=1S
%dev.quarkus.cache.caffeine."npm-package-cache".expire-after-write=1S

quarkus.cache.caffeine."maven-search-cache".initial-capacity=100
quarkus.cache.caffeine."maven-search-cache".maximum-size=100000
quarkus.cache.caffeine."maven-search-cache".expire-after-write=180S
%test.quarkus.cache.caffeine."maven-search-cache".expire-after-write=1S
%dev.quarkus.cache.caffeine."maven-search-cache".expire-after-write=1S

quarkus.native.resources.includes=importmap.json,**/importmap.json

%dev.mvnpm.cron.expr=0 0/1 * * * ?
mvnpm.cron.expr=0 0 0/4 * * ?

quarkus.http.read-timeout=5M
quarkus.rest-client.read-timeout=500000
quarkus.rest-client.connect-timeout=500000
quarkus.vertx.max-worker-execute-time=5M

quarkus.mailer.auth-methods=DIGEST-MD5 CRAM-SHA256 CRAM-SHA1 CRAM-MD5 PLAIN LOGIN
Expand Down
79 changes: 77 additions & 2 deletions src/main/resources/web/app/mvnpm-home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ export class MvnpmHome extends LitElement {
.copy:hover {
color:var(--lumo-success-color);
}
.gaveventlogconsole {
display: flex;
flex-direction: column;
height: 100%;
padding-left: 20px;
padding-right: 20px;
background: black;
font-family: 'Courier New', monospace;
font-size: small;
filter: brightness(0.85);
}
.gaveventlogline {
display: flex;
flex-direction: row;
gap: 10px;
}
`;

@state()
Expand Down Expand Up @@ -214,13 +231,17 @@ export class MvnpmHome extends LitElement {
private _loadingIcon = "hidden";
@state()
private _syncInfo?: object;
@state()
private _gavEventLog?: object;


constructor() {
super();
this._clearCoordinates();
this._disabled = "disabled";
this._codeViewSelection = ".pom";
this._syncInfo = null;
this._gavEventLog = null;
}

render() {
Expand Down Expand Up @@ -270,6 +291,7 @@ export class MvnpmHome extends LitElement {
<vaadin-tabs slot="tabs">
<vaadin-tab id="info-tab">info</vaadin-tab>
<vaadin-tab id="files-tab">files</vaadin-tab>
<vaadin-tab id="event-log-tab">event log</vaadin-tab>
</vaadin-tabs>
<div tab="info-tab">
Expand All @@ -279,11 +301,25 @@ export class MvnpmHome extends LitElement {
<div tab="files-tab">
${this._loadFilesTab()}
</div>
<div tab="event-log-tab">
${this._loadEventLogTab()}
</div>
</vaadin-tabsheet>`;
}
}

_showNpmjsLink(){
if(this._syncInfo){
var npmUrl = "https://www.npmjs.com/package/" + this._syncInfo.name.npmFullName + "/v/" + this._syncInfo.version;

return html`<a href="${npmUrl}" target="_blank">
<vaadin-icon title="${this._syncInfo.name.npmFullName}" icon="vaadin:tag"></vaadin-icon> npm registry
</a>`;
}
}

_loadSyncIcon(){
if(this._syncInfo){
if(this._syncInfo.inCentral){
Expand All @@ -304,6 +340,7 @@ export class MvnpmHome extends LitElement {
<h1>${this._coordinates.name} ${this._coordinates.version}</h1>
<div class="info-buttons">
${this._loadSyncIcon()}
${this._showNpmjsLink()}
<a href="${this._info.scmUrl}" target="_blank"><vaadin-icon icon="vaadin:code"></vaadin-icon> code</a>
<a href="${this._info.issueUrl}" target="_blank"><vaadin-icon icon="vaadin:bug-o"></vaadin-icon> issues</a>
<a href="${this._info.url}" target="_blank"><vaadin-icon icon="vaadin:external-link"></vaadin-icon> page</a>
Expand Down Expand Up @@ -373,6 +410,40 @@ export class MvnpmHome extends LitElement {
}
}

_loadEventLogTab(){
if(this._gavEventLog){
return html`<div class="gaveventlogconsole">
${this._renderGavEventLog()}
</div>`;
}
}

private _renderGavEventLog() {
if (this._gavEventLog && this._gavEventLog.length > 0) {
return html`
${this._gavEventLog.map((entry) => {
return html`${this._renderGavEventLogLine(entry)}`
})}
`;
} else {
return html`<p>Nothing in the event log</p>`;
}
}

private _renderGavEventLogLine(entry){
let formattedTime = entry.time.substring(0, entry.time.indexOf(".")).replace('T',' ');

return html`<div class="gaveventlogline">
<span style="color: grey">${formattedTime}</span>
<span style="color: lightblue">${entry.groupId}</span>
<span style="color: lightyellow">${entry.artifactId}</span>
<span style="color: lightpink">${entry.version}</span>
<span style="color: lightgrey">[${entry.stage}]</span>
<span style="color: ${entry.color}">${entry.message}</span>
</div>`;
}


_renderFileGroup(heading,fileExt, icon){
return html`
<span class="heading">${heading}</span>
Expand Down Expand Up @@ -640,7 +711,11 @@ export class MvnpmHome extends LitElement {
groupId = groupId.replaceAll('/', '.');
this._usePom = "<dependency>\n\t<groupId>" + groupId + "</groupId>\n\t<artifactId>" + artifactId + "</artifactId>\n\t<version>" + version + "</version>\n\t<scope>runtime</scope>\n</dependency>";
var syncInfoUrl = "/api/sync/info/" + groupId + "/" + artifactId + "?version=" + version;

var eventLogUrl = `/api/eventlog/gav/${groupId}/${artifactId}/${version}`;
fetch(eventLogUrl)
.then(response => response.json())
.then(response => this._gavEventLog = response);

groupId = groupId.replaceAll('.', '/');
var importMapUrl = "/maven2/" + groupId + "/" + artifactId + "/" + version + "/importmap.json";

Expand Down

0 comments on commit 92c6e71

Please sign in to comment.