Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
64 changes: 48 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<okhttp.version>4.12.0</okhttp.version>
<gson.version>2.9.0</gson.version>
<gson.version>2.13.1</gson.version>
</properties>
<licenses>
<license>
Expand Down Expand Up @@ -59,7 +59,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -72,7 +72,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<version>3.12.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -85,7 +85,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.8</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down Expand Up @@ -113,7 +113,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<version>3.5.5</version>
<configuration>
<skip>true</skip>
</configuration>
Expand Down Expand Up @@ -153,13 +153,13 @@
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>3.7.0</version>
<version>3.12.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
<version>${gson.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -189,7 +189,7 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
<version>1.21.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -198,7 +198,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<version>3.10.0</version>
<executions>
<execution>
<id>copy-agent</id>
Expand All @@ -223,15 +223,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<version>3.5.5</version>
<configuration>
<argLine>-javaagent:"${project.build.directory}/agents/jmockit-1.49.jar"</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.15.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -243,7 +243,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<version>3.5.0</version>
<configuration>
<archive>
<manifest>
Expand All @@ -256,7 +256,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -267,11 +267,24 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.5.1</version>
<version>5.1.9</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>!com.tinify.*,!org.bouncycastle.jsse.*,!com.experian.b2b.global.mvdam-project.*,!android.*,!javax.annotation.meta.*,!org.conscrypt.*;resolution:=optional,*
<Import-Package>
!com.tinify.*,
!org.bouncycastle.jsse.*,
!com.experian.b2b.global.mvdam-project.*,
!android.*,
!dalvik.*,
!javax.annotation.meta.*,
!javax.lang.model.*,
!kotlin.reflect.jvm.internal.*,
!org.conscrypt.*,
!org.openjsse.*,
sun.misc;resolution:=optional,
sun.security.ssl;resolution:=optional,
*
</Import-Package>
<Embed-Dependency>
*;scope=compile|runtime
Expand All @@ -283,7 +296,26 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.1</version>
<version>3.10.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.5</version>
<configuration>
<systemPropertyVariables>
<project.build.directory>${project.build.directory}</project.build.directory>
<project.build.finalName>${project.build.finalName}</project.build.finalName>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
77 changes: 77 additions & 0 deletions src/test/java/com/tinify/BundleManifestIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.tinify;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.jar.Attributes;

import static org.junit.Assert.*;

public class BundleManifestIT {

private static final List<String> FORBIDDEN_IMPORTS = Arrays.asList(
"org.openjsse.",
"dalvik.",
"android.",
"kotlin.reflect.jvm.internal"
);

private Manifest loadBundleManifest() throws IOException {
String buildDir = System.getProperty("project.build.directory", "target");
String finalName = System.getProperty("project.build.finalName", "tinify-1.8.8");
File jar = new File(buildDir, finalName + ".jar");
assertTrue("Bundle JAR not found: " + jar.getAbsolutePath(), jar.exists());
try (JarFile jarFile = new JarFile(jar)) {
return jarFile.getManifest();
}
}

@Test
public void bundleHasRequiredOsgiHeaders() throws IOException {
Attributes attrs = loadBundleManifest().getMainAttributes();

assertEquals("2", attrs.getValue("Bundle-ManifestVersion"));
assertNotNull("Missing Bundle-SymbolicName", attrs.getValue("Bundle-SymbolicName"));
assertNotNull("Missing Bundle-Version", attrs.getValue("Bundle-Version"));
assertNotNull("Missing Export-Package", attrs.getValue("Export-Package"));
}

@Test
public void importPackageDoesNotContainUnresolvablePackages() throws IOException {
Attributes attrs = loadBundleManifest().getMainAttributes();
String importPackage = attrs.getValue("Import-Package");
assertNotNull("Missing Import-Package header", importPackage);

for (String forbidden : FORBIDDEN_IMPORTS) {
assertFalse(
"Import-Package must not contain " + forbidden + " but was: " + importPackage,
importPackage.contains(forbidden)
);
}
}

@Test
public void exportPackageContainsTinify() throws IOException {
Attributes attrs = loadBundleManifest().getMainAttributes();
String exportPackage = attrs.getValue("Export-Package");
assertTrue(
"Export-Package must contain com.tinify",
exportPackage.contains("com.tinify")
);
}

@Test
public void bundleEmbedsDependencies() throws IOException {
Attributes attrs = loadBundleManifest().getMainAttributes();
String bundleClassPath = attrs.getValue("Bundle-ClassPath");
assertNotNull("Missing Bundle-ClassPath", bundleClassPath);
assertTrue("Bundle-ClassPath must contain okhttp", bundleClassPath.contains("okhttp"));
assertTrue("Bundle-ClassPath must contain gson", bundleClassPath.contains("gson"));
assertTrue("Bundle-ClassPath must contain okio", bundleClassPath.contains("okio"));
}
}
4 changes: 3 additions & 1 deletion src/test/java/com/tinify/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.logging.Logger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class ClientTest {
Expand Down Expand Up @@ -424,7 +425,8 @@ public void requestWithBadServerResponseRepeatedlyShouldThrowExceptionWithMessag
new Client(key).request(Client.Method.POST, "/shrink");
fail("Expected an Exception to be thrown");
} catch (Exception e) {
assertEquals("Error while parsing response: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ (HTTP 543/ParseError)", e.getMessage());
assertTrue(e.getMessage().startsWith("Error while parsing response: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"));
assertTrue(e.getMessage().endsWith("(HTTP 543/ParseError)"));
}
}

Expand Down
Loading