Skip to content

Commit

Permalink
fix: migrate jakarta deps to comply with lithium 3.6.x (pt1) (#119)
Browse files Browse the repository at this point in the history
* Lithium 3.6.0

* WebsocketBundle

* chore: cleanup depedencies

* chore: cleanup depedencies to jakarta

* chore: fixing tests

* chore: fixing tests

* chore: comments - [skip-ci]

* feat: fixing tests and dependencies

* feat: fixing tests and dependencies

* chore: fixing ws config to jakarta

* chore: removing local fix docker image platform

---------

Co-authored-by: Dejan <dejankov@gmail.com>
  • Loading branch information
yamilmedina and dkovacevic committed Dec 5, 2023
1 parent 4ee39cd commit 122e6d2
Show file tree
Hide file tree
Showing 54 changed files with 1,656 additions and 1,362 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR ./frontend
RUN npm i
RUN npm run build

FROM maven:3-openjdk-11 AS build
FROM maven:3-openjdk-17 AS build
WORKDIR /app

COPY backend/pom.xml ./
Expand All @@ -18,7 +18,7 @@ COPY backend/ ./

RUN mvn -Dmaven.test.skip=true package

FROM wirebot/runtime:1.3.0 AS runtime
FROM wirebot/runtime:1.4.0 AS runtime
LABEL description="Wire Roman"
LABEL project="wire-bots:roman"

Expand Down
136 changes: 85 additions & 51 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,72 @@
</licenses>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.test.skip>true</maven.test.skip>

<lithium.version>3.6.0</lithium.version>
<dropwizard.version>2.1.5</dropwizard.version>
<dropwizard.version>4.0.0</dropwizard.version>
<jwt.version>0.11.5</jwt.version>
<junit5.version>5.8.2</junit5.version>
<jetty.version>11.0.18</jetty.version>
<jakarta.version>2.1.1</jakarta.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-bom</artifactId>
<version>${dropwizard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-auth</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-assets</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-servlets</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard-bundles</groupId>
<artifactId>dropwizard-configurable-assets-bundle</artifactId>
<version>1.3.5</version>
</dependency>
<!-- MIGRATION TO JAKARTA JETTY 11 -->
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta.version}</version>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<version>${jakarta.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-jakarta-server</artifactId>
<version>${jetty.version}</version>
</dependency>

<dependency>
<groupId>com.wire</groupId>
<artifactId>lithium</artifactId>
Expand All @@ -49,6 +102,11 @@
<artifactId>jackson-databind</artifactId>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
Expand All @@ -67,64 +125,34 @@
<scope>runtime</scope>
</dependency>

<!-- test dependencies-->
<dependency>
<groupId>io.dropwizard-bundles</groupId>
<artifactId>dropwizard-configurable-assets-bundle</artifactId>
<version>1.3.5</version>
<exclusions>
<exclusion>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-servlets</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.dropwizard-bundles</groupId>
<artifactId>dropwizard-redirect-bundle</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>9.4.49.v20220914</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.liveperson</groupId>
<artifactId>dropwizard-websockets</artifactId>
<version>1.3.14</version>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-testing</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-servlets</artifactId>
<version>${dropwizard.version}</version>
</dependency>

<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-testing</artifactId>
<version>${dropwizard.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -133,6 +161,12 @@
<version>3.24.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -141,8 +175,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 0 additions & 2 deletions backend/roman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ server:
requestLog:
appenders:
- type: ${APPENDER_TYPE:-console}
filterFactories:
- type: status-filter-factory

logging:
level: INFO
Expand Down
11 changes: 4 additions & 7 deletions backend/src/main/java/com/wire/bots/roman/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
import com.wire.xenon.MessageHandlerBase;
import com.wire.xenon.factories.CryptoFactory;
import com.wire.xenon.factories.StorageFactory;
import io.dropwizard.bundles.assets.ConfiguredAssetsBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.websockets.WebsocketBundle;
import io.dropwizard.core.setup.Bootstrap;
import io.dropwizard.core.setup.Environment;
import io.jsonwebtoken.security.Keys;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.FilterRegistration;
import org.eclipse.jetty.servlets.CrossOriginFilter;

import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import java.security.Key;
import java.util.EnumSet;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -72,7 +70,6 @@ public void initialize(Bootstrap<Config> bootstrap) {
instance = (Application) bootstrap.getApplication();
bootstrap.addBundle(new WebsocketBundle(WebSocket.class));
bootstrap.addCommand(new UpdateCertCommand());
bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/", "index.html"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import com.wire.xenon.models.otr.Missing;
import com.wire.xenon.models.otr.Recipients;
import com.wire.xenon.tools.Logger;
import jakarta.ws.rs.client.Client;
import org.checkerframework.checker.nullness.qual.Nullable;

import javax.ws.rs.client.Client;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.wire.bots.roman.DAO;

import com.wire.bots.roman.DAO.mappers.UUIDMapper;
import jakarta.annotation.Nullable;
import org.jdbi.v3.core.mapper.ColumnMapper;
import org.jdbi.v3.core.statement.StatementContext;
import org.jdbi.v3.sqlobject.config.RegisterColumnMapper;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;

import javax.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.wire.bots.roman.DAO.mappers;

import com.wire.xenon.tools.Logger;
import jakarta.annotation.Nullable;
import org.jdbi.v3.core.mapper.ColumnMapper;
import org.jdbi.v3.core.statement.StatementContext;

import javax.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
Expand Down
80 changes: 35 additions & 45 deletions backend/src/main/java/com/wire/bots/roman/ImageProcessor.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package com.wire.bots.roman;

import com.wire.xenon.assets.Picture;
import com.wire.bots.roman.resources.Picture;
import com.wire.xenon.assets.ImagePreview;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

public class ImageProcessor {

private static final int MEDIUM_DIMENSION = 2896;
private static final int SMALL_DIMENSION = 2896;

public static Picture getMediumImage(Picture original) throws Exception {
return getScaledImage(original, MEDIUM_DIMENSION);
}

public static Picture getSmallImage(Picture original) throws Exception {
return getScaledImage(original, SMALL_DIMENSION);
public static Picture getMediumImage(Picture picture) throws Exception {
return getScaledImage(picture, MEDIUM_DIMENSION);
}

private static Boolean shouldScaleOriginalSize(double width, double height, double dimension) {
Expand Down Expand Up @@ -59,40 +52,37 @@ private static BufferedImage resizeImage(BufferedImage originalImage,
return resizedImage;
}

private static Picture getScaledImage(Picture image, double dimension) throws Exception {
String resultImageType;
switch (image.getMimeType()) {
case "image/gif":
resultImageType = "gif";
break;
case "image/jpeg":
resultImageType = "jpg";
break;
case "image/png":
resultImageType = "png";
break;
default:
throw new Exception("Unsupported mime type: " + image.getMimeType());
}

int origWidth = image.getWidth();
int origHeight = image.getHeight();

BufferedImage resultImage = ImageIO.read(new ByteArrayInputStream(image.getImageData()));

if (shouldScaleOriginalSize(origWidth, origHeight, dimension)) {
Size scaledSize = getScaledSize(origWidth, origHeight, dimension);
resultImage = resizeImage(resultImage, (int) scaledSize.width,
(int) scaledSize.height);
}

try (ByteArrayOutputStream resultStream = new ByteArrayOutputStream()) {
ImageIO.write(resultImage, resultImageType, resultStream);
resultStream.flush();
Picture picture = new Picture(resultStream.toByteArray(), image.getMimeType());
picture.setRetention(image.getRetention());
return picture;
}
// todo. fixme, xenon to expose getMimeType type and getImageData
private static Picture getScaledImage(ImagePreview image, int dimension) throws Exception {
// String resultImageType;
// switch ("image/jpeg") {
// case "image/jpeg":
// resultImageType = "jpg";
// break;
// case "image/png":
// resultImageType = "png";
// break;
// default:
// throw new IllegalArgumentException("Unsupported mime type");
// }
//
// int origWidth = image.getWidth();
// int origHeight = image.getHeight();
//
// BufferedImage resultImage = ImageIO.read(new ByteArrayInputStream(image.getImageData()));
//
// if (shouldScaleOriginalSize(origWidth, origHeight, dimension)) {
// Size scaledSize = getScaledSize(origWidth, origHeight, dimension);
// resultImage = resizeImage(resultImage, (int) scaledSize.width,
// (int) scaledSize.height);
// }
//
// try (ByteArrayOutputStream resultStream = new ByteArrayOutputStream()) {
// ImageIO.write(resultImage, resultImageType, resultStream);
// resultStream.flush();
// return new Picture(resultStream.toByteArray(), image.getMimeType());
// }
return null;
}

private static class Size {
Expand Down
Loading

0 comments on commit 122e6d2

Please sign in to comment.