Skip to content

Commit

Permalink
Merge pull request #33 from swisspost/develop
Browse files Browse the repository at this point in the history
PR for release
  • Loading branch information
mcweba authored Jan 17, 2024
2 parents 5b45d90 + 95e7164 commit 987ea14
Show file tree
Hide file tree
Showing 7 changed files with 840 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:

- name: Install, unit test, integration test
run: mvn install -Dmaven.javadoc.skip=true -B -V

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3

- name: Release to maven central
if: github.ref_name == 'master' && github.event_name != 'pull_request' && github.repository == 'swisspost/vertx-rest-mirror'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ vertx-mirror
=============

[![Build Status](https://travis-ci.com/swisspush/vertx-rest-mirror.svg?branch=master)](https://travis-ci.com/swisspush/vertx-rest-mirror)
[![codecov](https://codecov.io/gh/swisspush/vertx-rest-mirror/branch/master/graph/badge.svg)](https://codecov.io/gh/swisspush/vertx-rest-mirror)
[![codecov](https://codecov.io/gh/swisspost/vertx-rest-mirror/branch/master/graph/badge.svg?token=14IWfjaJYm)](https://codecov.io/gh/swisspost/vertx-rest-mirror)
[![Maven Central](https://img.shields.io/maven-central/v/org.swisspush/rest-mirror.svg)]()

A verticle that mirrors resources, which are provided as zip into a rest storage.
Expand Down
77 changes: 57 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.swisspush</groupId>
<artifactId>rest-mirror</artifactId>
<version>3.0.4-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<name>rest-mirror</name>
<description>
A verticle that mirrors resources, which are provided as zip into a rest storage.
Expand Down Expand Up @@ -37,14 +37,6 @@
<url>https://github.com/swisspush/vertx-rest-mirror.git</url>
</scm>
<dependencies>
<!-- swisspush dependencies -->
<dependency>
<groupId>org.swisspush</groupId>
<artifactId>rest-storage</artifactId>
<version>3.0.0</version>
</dependency>

<!-- other deps -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
Expand All @@ -60,25 +52,25 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<version>2.15.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
<version>2.0.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.6</version>
<artifactId>slf4j-reload4j</artifactId>
<version>2.0.10</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -91,7 +83,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -101,9 +93,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.1</version>
<version>5.4.0</version>
<scope>test</scope>
</dependency>

Expand All @@ -113,12 +105,12 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<version>0.8.9</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -172,6 +164,51 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for unit tests is created after
unit tests have been run.
-->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>external.atlassian.jgitflow</groupId>
<artifactId>jgitflow-maven-plugin</artifactId>
Expand Down Expand Up @@ -336,7 +373,7 @@
</profile>
</profiles>
<properties>
<vertx.version>4.2.1</vertx.version>
<vertx.version>4.5.1</vertx.version>
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
<sonatypeOssDistMgmtSnapshotsUrl>
https://oss.sonatype.org/content/repositories/snapshots/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/swisspush/mirror/ZipEntryPutter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swisspush.reststorage.MimeTypeResolver;
import org.swisspush.mirror.util.MimeTypeResolver;

import java.util.Map;

Expand Down
61 changes: 61 additions & 0 deletions src/main/java/org/swisspush/mirror/util/MimeTypeResolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.swisspush.mirror.util;

import org.slf4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import static org.slf4j.LoggerFactory.getLogger;

public class MimeTypeResolver {

private static final Logger log = getLogger(MimeTypeResolver.class);
private Map<String, String> mimeTypes = new HashMap<>();

private final String defaultMimeType;

public MimeTypeResolver(String defaultMimeType) {
this.defaultMimeType = defaultMimeType;
Properties props = new Properties();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("mime-types.properties");
try {
props.load(in);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
if(in != null) {
in.close();
}
} catch (IOException ex) {
log.debug("close() failed", ex);
}
}

for( Map.Entry<Object, Object> entry : props.entrySet()) {
mimeTypes.put(((String)entry.getKey()).toLowerCase(), (String)entry.getValue());
}
}

public String resolveMimeType(String path) {
int lastSlash = path.lastIndexOf("/");
String part = path;
if(lastSlash >= 0 && !path.endsWith("/")) {
part = part.substring(lastSlash+1);
}
int dot = part.lastIndexOf(".");
if(dot == -1 || part.endsWith(".")) {
return defaultMimeType;
} else {
String extension = part.substring(dot+1);
String type = mimeTypes.get(extension.toLowerCase());
if(type==null) {
type = "text/plain";
}
return type;
}
}
}
Loading

0 comments on commit 987ea14

Please sign in to comment.