Skip to content

Commit d9e717e

Browse files
Merge pull request #1878 from BorderTech/feature/replace-tika-lib
Replace tika lib and update project dependencies
2 parents c51c592 + d6b53ca commit d9e717e

36 files changed

Lines changed: 450 additions & 455 deletions

File tree

.github/workflows/github-actions-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
echo "Sonar secure variables NOT available"
4949
else
5050
echo "Sonar secure variables ARE available"
51-
mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey="bordertech-wcomponents" -Dsonar.organization="bordertech-github" -Dsonar.host.url="https://sonarcloud.io"
51+
mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey="bordertech-wcomponents" -Dsonar.organization="bordertech-github" -Dsonar.host.url="https://sonarcloud.io" -Dsonar.qualitygate.wait=true
5252
fi
5353
env:
5454
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44

55
### API Changes
66
### Enhancements
7+
* Consistent use of try-with-resources when handling streams
8+
* Updated AbstractRequest to remove deprecated methods uploadFileItems and readBytes (were protected static). Use StreamUtils instead.
9+
* Replaced org.apache.tika:tika library with org.overviewproject:mime-types in FileUtil to validate uploaded file mime types.
10+
* Updated FileUtil to make file extension and mime type validation case insensitive.
11+
* Updated the following dependencies:
12+
* wcomponents-core:
13+
* com.google.code.gson:gson from 2.13.1 to 2.13.2
14+
* org.apache.commons:commons-lang3 from 3.18.0 to 3.20.0
15+
* commons-io:commons-io from 2.19.0 to 2.21.0
16+
* com.google.errorprone:error_prone_annotations from 2.39.0 to 2.46.0
17+
* org.apache.httpcomponents.client5:httpclient5 from 5.5 to 5.6
18+
* org.apache.httpcomponents.core5:httpcore5 from 5.3.4 to 5.4
19+
* wcomponents-test-lib:
20+
* io.github.bonigarcia:webdrivermanager from 6.1.0 to 6.3.3
21+
* org.apache.commons:commons-compress from 1.27.1 to 1.28.0
22+
* commons-codec:commons-codec from 1.18.0 to 1.20.0
23+
* com.google.guava:guava from 33.4.8-jre to 33.5.0-jre
24+
* net.java.dev.jna:jna from 5.17.0 to 5.18.1
25+
* wcomponents-bundle:
26+
* org.ehcache:ehcahce from 3.10.8 to 3.11.1
27+
* org.glassfish.jaxb:jaxb-runtime from 4.0.5 to 4.0.6
28+
729
### Bug Fixes
830

931
## 1.5.38

code-coverage/pom.xml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>com.github.bordertech.wcomponents</groupId>
7+
<artifactId>wcomponents-parent</artifactId>
8+
<version>1.5.39-SNAPSHOT</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
12+
<name>code-coverage</name>
13+
<artifactId>code-coverage</artifactId>
14+
15+
<packaging>jar</packaging>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.github.bordertech.wcomponents</groupId>
20+
<artifactId>wcomponents-core</artifactId>
21+
<version>${project.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.github.bordertech.wcomponents</groupId>
25+
<artifactId>wcomponents-examples</artifactId>
26+
<version>${project.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.github.bordertech.wcomponents</groupId>
30+
<artifactId>wcomponents-test-lib</artifactId>
31+
<version>${project.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.github.bordertech.wcomponents</groupId>
35+
<artifactId>wcomponents-lde</artifactId>
36+
<version>${project.version}</version>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
42+
<plugins>
43+
<!-- Generate aggreated coverage report -->
44+
<plugin>
45+
<groupId>org.jacoco</groupId>
46+
<artifactId>jacoco-maven-plugin</artifactId>
47+
<executions>
48+
<execution>
49+
<id>report-aggregate</id>
50+
<phase>test</phase>
51+
<goals>
52+
<goal>report-aggregate</goal>
53+
</goals>
54+
</execution>
55+
</executions>
56+
</plugin>
57+
<!-- This coverage module should never de deployed -->
58+
<plugin>
59+
<groupId>org.apache.maven.plugins</groupId>
60+
<artifactId>maven-deploy-plugin</artifactId>
61+
<version>3.1.4</version>
62+
<configuration>
63+
<skip>true</skip>
64+
</configuration>
65+
</plugin>
66+
</plugins>
67+
68+
</build>
69+
70+
</project>

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<dependency>
8686
<groupId>org.ehcache</groupId>
8787
<artifactId>ehcache</artifactId>
88-
<version>3.10.8</version>
88+
<version>3.11.1</version>
8989
<exclusions>
9090
<!-- Exclude jaxb runtime as ehcache has a wildcard dependency that breaks the build -->
9191
<exclusion>
@@ -107,7 +107,7 @@
107107
<dependency>
108108
<groupId>org.glassfish.jaxb</groupId>
109109
<artifactId>jaxb-runtime</artifactId>
110-
<version>4.0.5</version>
110+
<version>4.0.6</version>
111111
</dependency>
112112

113113
<!-- Servlet Interface -->
@@ -217,6 +217,7 @@
217217
<module>wcomponents-theme</module>
218218
<module>wcomponents-xslt</module>
219219
<module>wcomponents-bundle</module>
220+
<module>code-coverage</module>
220221
</modules>
221222

222223
</project>

wcomponents-core/pom.xml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
<dependency>
219219
<groupId>com.google.code.gson</groupId>
220220
<artifactId>gson</artifactId>
221-
<version>2.13.1</version>
221+
<version>2.13.2</version>
222222
<exclusions>
223223
<exclusion>
224224
<groupId>com.google.errorprone</groupId>
@@ -248,6 +248,14 @@
248248
<groupId>xerces</groupId>
249249
<artifactId>xercesImpl</artifactId>
250250
</exclusion>
251+
<exclusion>
252+
<groupId>commons-io</groupId>
253+
<artifactId>commons-io</artifactId>
254+
</exclusion>
255+
<exclusion>
256+
<groupId>org.apache.httpcomponents.core5</groupId>
257+
<artifactId>httpcore5</artifactId>
258+
</exclusion>
251259
</exclusions>
252260
</dependency>
253261
<dependency>
@@ -289,20 +297,9 @@
289297
</dependency>
290298

291299
<dependency>
292-
<groupId>org.apache.tika</groupId>
293-
<artifactId>tika-core</artifactId>
294-
<version>2.9.4</version>
295-
<!-- Fix convergence -->
296-
<exclusions>
297-
<exclusion>
298-
<groupId>org.slf4j</groupId>
299-
<artifactId>slf4j-api</artifactId>
300-
</exclusion>
301-
<exclusion>
302-
<groupId>commons-io</groupId>
303-
<artifactId>commons-io</artifactId>
304-
</exclusion>
305-
</exclusions>
300+
<groupId>org.overviewproject</groupId>
301+
<artifactId>mime-types</artifactId>
302+
<version>2.0.0</version>
306303
</dependency>
307304

308305
<!-- Force versions to fix convergence -->
@@ -319,22 +316,22 @@
319316
<dependency>
320317
<groupId>org.apache.commons</groupId>
321318
<artifactId>commons-lang3</artifactId>
322-
<version>3.18.0</version>
319+
<version>3.20.0</version>
323320
</dependency>
324321
<dependency>
325322
<groupId>commons-io</groupId>
326323
<artifactId>commons-io</artifactId>
327-
<version>2.19.0</version>
324+
<version>2.21.0</version>
328325
</dependency>
329326
<dependency>
330327
<groupId>com.google.errorprone</groupId>
331328
<artifactId>error_prone_annotations</artifactId>
332-
<version>2.39.0</version>
329+
<version>2.46.0</version>
333330
</dependency>
334331
<dependency>
335332
<groupId>org.apache.httpcomponents.client5</groupId>
336333
<artifactId>httpclient5</artifactId>
337-
<version>5.5</version>
334+
<version>5.6</version>
338335
<exclusions>
339336
<exclusion>
340337
<groupId>org.slf4j</groupId>
@@ -345,7 +342,7 @@
345342
<dependency>
346343
<groupId>org.apache.httpcomponents.core5</groupId>
347344
<artifactId>httpcore5</artifactId>
348-
<version>5.3.4</version>
345+
<version>5.4</version>
349346
</dependency>
350347

351348
<!-- Test dependencies -->

wcomponents-core/src/main/java/com/github/bordertech/wcomponents/AbstractRequest.java

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package com.github.bordertech.wcomponents;
22

3-
import com.github.bordertech.wcomponents.servlet.ServletUtil;
43
import com.github.bordertech.wcomponents.util.Config;
54
import com.github.bordertech.wcomponents.util.Enumerator;
6-
import com.github.bordertech.wcomponents.util.StreamUtil;
75
import com.github.bordertech.wcomponents.util.Util;
8-
import java.io.IOException;
9-
import java.io.InputStream;
106
import java.io.Serializable;
117
import java.util.Enumeration;
128
import java.util.HashMap;
13-
import java.util.List;
149
import java.util.Map;
1510
import org.apache.commons.fileupload.FileItem;
1611

@@ -69,7 +64,7 @@ public FileItem[] getFileItems(final String key) {
6964
result = deserialized.toArray(new FileItem[]{});
7065
}
7166
}
72-
*/
67+
*/
7368
return result;
7469
}
7570

@@ -128,41 +123,6 @@ public boolean isLogout() {
128123
return logout;
129124
}
130125

131-
/**
132-
* <p>
133-
* {@link FileItem} classes (if attachements) will be kept as part of the request. The default behaviour of the file
134-
* item is to store the upload in memory until it reaches a certain size, after which the content is streamed to a
135-
* temp file.</p>
136-
*
137-
* <p>
138-
* If, in the future, performance of uploads becomes a focus we can instead look into using the Jakarta Commons
139-
* Streaming API. In this case, the content of the upload isn't stored anywhere. It will be up to the user to
140-
* read/store the content of the stream.</p>
141-
*
142-
* @param fileItems a list of {@link FileItem}s corresponding to POSTed form data.
143-
* @param parameters the map to store non-file request parameters in.
144-
* @param files the map to store the uploaded file parameters in.
145-
* @deprecated Use {@link ServletUtil#uploadFileItems(java.util.List, java.util.Map, java.util.Map)} instead.
146-
*/
147-
@Deprecated
148-
protected static void uploadFileItems(final List fileItems, final Map<String, String[]> parameters,
149-
final Map<String, FileItem[]> files) {
150-
ServletUtil.uploadFileItems(fileItems, parameters, files);
151-
}
152-
153-
/**
154-
* Returns a byte array containing all the information contained in the given input stream.
155-
*
156-
* @param stream the input stream to read from.
157-
* @return the stream contents as a byte array.
158-
* @throws IOException if there is an error reading from the stream.
159-
* @deprecated Use {@link StreamUtil#getBytes(java.io.InputStream)} instead.
160-
*/
161-
@Deprecated
162-
protected static byte[] readBytes(final InputStream stream) throws IOException {
163-
return StreamUtil.getBytes(stream);
164-
}
165-
166126
/**
167127
* This method contains no logic. Subclasses which need to perform event handling logic (eg.
168128
* <code>WPortletRequest</code>) should override this method.

wcomponents-core/src/main/java/com/github/bordertech/wcomponents/ContentEscape.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import org.apache.commons.logging.LogFactory;
1010

1111
/**
12-
* An Escape subclass that bypasses the usual request -&gt; paint flow by directly producing the binary document
13-
* content.
12+
* An Escape subclass that bypasses the usual request -&gt; paint flow by directly producing the binary document content.
1413
*
1514
* @author Martin Shevchenko
1615
* @since 1.0.0
@@ -81,28 +80,19 @@ public void escape() throws IOException {
8180
}
8281

8382
if (contentAccess instanceof ContentStreamAccess) {
84-
InputStream stream = null;
85-
86-
try {
87-
stream = ((ContentStreamAccess) contentAccess).getStream();
88-
83+
try (InputStream stream = ((ContentStreamAccess) contentAccess).getStream()) {
8984
if (stream == null) {
9085
throw new SystemException(
9186
"ContentAccess returned null stream, access=" + contentAccess);
9287
}
93-
9488
StreamUtil.copy(stream, response.getOutputStream());
95-
} finally {
96-
StreamUtil.safeClose(stream);
9789
}
9890
} else {
9991
byte[] bytes = contentAccess.getBytes();
100-
10192
if (bytes == null) {
10293
throw new SystemException(
10394
"ContentAccess returned null data, access=" + contentAccess);
10495
}
105-
10696
response.getOutputStream().write(bytes);
10797
}
10898
}

wcomponents-core/src/main/java/com/github/bordertech/wcomponents/InternalResource.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,11 @@ public InternalResource(final String resourceName, final String description) {
5656
*/
5757
@Override
5858
public byte[] getBytes() {
59-
InputStream stream = null;
60-
61-
try {
62-
stream = getClass().getResourceAsStream(resourceName);
59+
try (InputStream stream = getClass().getResourceAsStream(resourceName)) {
6360
return StreamUtil.getBytes(stream);
6461
} catch (Exception e) {
6562
LOG.error("Failed to read resource: " + resourceName, e);
66-
} finally {
67-
StreamUtil.safeClose(stream);
6863
}
69-
7064
return EMPTY;
7165
}
7266

0 commit comments

Comments
 (0)