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

Refactor packages #226

Open
wants to merge 6 commits into
base: webrepl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
20 changes: 12 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<modelVersion>4.0.0</modelVersion>

<artifactId>jsh4jpv3</artifactId>
<artifactId>jpv3-webrepl</artifactId>
<packaging>jar</packaging>
<version>${revision}</version>

<name>jsh4jpv3</name>
<name>jpv3-webrepl</name>
<description>A JShell service to evaluate JPv3 scripts</description>
<url>http://projects.freelibrary.info/jiiify-presentation</url>

Expand Down Expand Up @@ -54,7 +54,8 @@
<!-- Plugin related versions -->
<docker.plugin.version>0.45.0</docker.plugin.version>
<deploy.plugin.version>3.1.3</deploy.plugin.version>
<maven.shade.version>3.6.0</maven.shade.version>
<shade.plugin.version>3.6.0</shade.plugin.version>
<freelib.utils.version>5.0.5</freelib.utils.version>

<!-- Test dependency versions -->
<junit.version>5.11.0</junit.version>
Expand Down Expand Up @@ -85,6 +86,11 @@
<artifactId>jiiify-presentation-v3</artifactId>
<version>${jpv3.version}</version>
</dependency>
<dependency>
<groupId>info.freelibrary</groupId>
<artifactId>freelib-utils</artifactId>
<version>${freelib.utils.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down Expand Up @@ -113,7 +119,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.version}</version>
<version>${shade.plugin.version}</version>
<executions>
<execution>
<id>uber-jar</id>
Expand Down Expand Up @@ -149,7 +155,7 @@
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>info.freelibrary.jsh4jvp3.Server</mainClass>
<mainClass>info.freelibrary.iiif.webrepl.Server</mainClass>
</transformer>
</transformers>
</configuration>
Expand Down Expand Up @@ -257,8 +263,6 @@
<platform>linux/amd64</platform>
<platform>linux/arm64/v8</platform>
</platforms>
<!-- Multi-arch builds don't work on GA because containerd isn't supported (cf. reason number two on
https://github.com/fabric8io/docker-maven-plugin/issues/1557#issuecomment-1325203489) -->
<attestations>
<sbom>${docker.sbom}</sbom>
<provenance>${docker.provenance}</provenance>
Expand Down Expand Up @@ -330,7 +334,7 @@
</execution>

<!-- Deploys the application's Docker image -->

<execution>
<id>docker-deploy</id>
<phase>deploy</phase>
Expand Down
4 changes: 2 additions & 2 deletions src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ RUN apk add --no-cache nano curl && \
addgroup -S jpv3 && \
adduser -S jpv3 -G jpv3 -s bash

COPY --chown=jpv3:jpv3 --chmod=0400 "maven/jsh4jpv3-${project.version}-uber.jar" "/opt/jpv3.jar"
COPY --chown=jpv3:jpv3 --chmod=0400 "maven/${project.name}-${project.version}-uber.jar" "/opt/${project.name}.jar"
COPY --chown=jpv3:jpv3 --chmod=0400 "imports.jsh" "/etc/jshell/imports.jsh"

EXPOSE 8888

USER jpv3

CMD ["sh", "-c", "exec java ${JAVA_OPTS} -jar /opt/jpv3.jar"]
CMD ["sh", "-c", "exec java ${JAVA_OPTS} -jar /opt/${project.name}.jar"]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package info.freelibrary.jsh4jvp3;
package info.freelibrary.iiif.webrepl;

/**
* The application's configuration variables.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package info.freelibrary.jsh4jvp3;
package info.freelibrary.iiif.webrepl;

import static info.freelibrary.util.Constants.EOL;

Expand Down Expand Up @@ -55,19 +55,28 @@ public void accept(final Diag aDiagnostic) {
int start = (int) aDiagnostic.getStartPosition();
int end = (int) aDiagnostic.getEndPosition();

// Isolate and highlight the problem (with brackets)
if (start == end) {
myBuffer.insert(start, START).insert(start + START.length(), END);
} else {
myBuffer.insert(start, START).insert(end, END);
myBuffer.insert(start, START).insert(end + START.length(), END);
}

end = myBuffer.indexOf(TEMPLATE_START) + TEMPLATE_START.length() + 2;
start = myBuffer.length() - 4;
// If the code snippet includes the multi-line template, remove it
if (myBuffer.toString().contains(TEMPLATE_START)) {
end = myBuffer.indexOf(TEMPLATE_START) + TEMPLATE_START.length() + 2;
start = myBuffer.length() - 4;

myBuffer.delete(start, myBuffer.length()).delete(0, end);
myBuffer.delete(start, myBuffer.length()).delete(0, end);
}

// Add line numbers to what's returned
code = StringUtils.addLineNumbers(myBuffer.toString());

// Zero out the output buffer
myBuffer.setLength(0);

// Format the output and prepare to return it
myBuffer.append(INTRO).append(EOLX2).append(code).append(EOLX2).append(HEADER).append(message).append(EOL);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

package info.freelibrary.jsh4jvp3;
package info.freelibrary.iiif.webrepl;

import static info.freelibrary.jsh4jvp3.Status.METHOD_NOT_ALLOWED;
import static info.freelibrary.jsh4jvp3.Status.NOT_FOUND;
import static info.freelibrary.jsh4jvp3.Status.OK;
import static info.freelibrary.iiif.webrepl.Status.METHOD_NOT_ALLOWED;
import static info.freelibrary.iiif.webrepl.Status.NOT_FOUND;
import static info.freelibrary.iiif.webrepl.Status.OK;
import static info.freelibrary.util.Constants.EMPTY;
import static info.freelibrary.util.Constants.EOL;
import static info.freelibrary.util.Constants.INADDR_ANY;
Expand Down Expand Up @@ -34,6 +34,7 @@
import info.freelibrary.util.Env;
import info.freelibrary.util.StringUtils;
import info.freelibrary.util.warnings.PMD;
import info.freelibrary.util.warnings.Sonar;

import info.freelibrary.iiif.presentation.v3.Manifest;

Expand Down Expand Up @@ -140,6 +141,7 @@ private static class JPv3Handler implements Handler {
* @throws ClassNotFoundException If the JPv3 classes cannot be found
* @throws URISyntaxException If the Jar file's path couldn't be converted into a URI
*/
@SuppressWarnings({ Sonar.SYSTEM_OUT_ERR })
JPv3Handler() throws IOException, ClassNotFoundException, URISyntaxException {
myOutputStream = new ByteArrayOutputStream();
myShell = JShell.builder().compilerOptions("--enable-preview", "--source", "21")
Expand All @@ -150,15 +152,15 @@ private static class JPv3Handler implements Handler {

// Check that all the imports can be loaded successfully
myShell.eval(getImports()).stream().filter(event -> !Snippet.Status.VALID.equals(event.status()))
.map((Function<? super SnippetEvent, ? extends Status>) SnippetEvent::status)
.forEach(System.err::println);
.map((Function<? super SnippetEvent, Status>) SnippetEvent::status).forEach(System.err::println);

// Load the JPv3 classes so the imports have something to load
myShell.addToClasspath(getJarClasspath());
}

@Override
@SuppressWarnings({ PMD.COGNITIVE_COMPLEXITY, "PMD.SystemPrintln" })
@SuppressWarnings({ PMD.COGNITIVE_COMPLEXITY, PMD.SYSTEM_PRINTLN, PMD.COGNITIVE_COMPLEXITY,
Sonar.SYSTEM_OUT_ERR })
public void handle(final Request aRequest, final Consumer<Response> aCallback) {
final String uri = aRequest.uri();
final Response response;
Expand Down Expand Up @@ -188,11 +190,9 @@ public void handle(final Request aRequest, final Consumer<Response> aCallback) {
final StringBuilder buffer = new StringBuilder(snippet.source());

// Just check one at a time, and let the editor iterate
myShell.diagnostics(snippet).findFirst()
.ifPresentOrElse(new DiagConsumer(buffer), () -> {
buffer.delete(0, buffer.length())
.append("Parsing error, but diagnostics were not found");
});
myShell.diagnostics(snippet).findFirst().ifPresentOrElse(
new DiagConsumer(buffer), () -> buffer.delete(0, buffer.length())
.append("Parsing error, but diagnostics were not found"));

try {
myOutputStream.write(buffer.toString().getBytes(UTF_8));
Expand Down Expand Up @@ -338,7 +338,7 @@ private String getJarClasspath() throws ClassNotFoundException, URISyntaxExcepti
* @param aBody A response body
* @return The newly constructed response
*/
private Response getResponse(final info.freelibrary.jsh4jvp3.Status aEnum, final List<Header> aHeaderList,
private Response getResponse(final info.freelibrary.iiif.webrepl.Status aEnum, final List<Header> aHeaderList,
final byte[] aBody) {
return new Response(aEnum.getCode(), aEnum.getMessage(), aHeaderList, aBody);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package info.freelibrary.jsh4jvp3;
package info.freelibrary.iiif.webrepl;

/**
* An encapsulation of HTTP response information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package info.freelibrary.jsh4jvp3;
package info.freelibrary.iiif.webrepl;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package info.freelibrary.jsh4jpv3;
package info.freelibrary.iiif.webrepl;

import static info.freelibrary.util.Constants.INADDR_ANY;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand All @@ -25,8 +25,6 @@
import info.freelibrary.util.StringUtils;
import info.freelibrary.util.ThrowingConsumer;

import info.freelibrary.jsh4jvp3.Status;

/**
* A test of the server's endpoints.
*/
Expand Down
Loading