Skip to content

Commit 09e7a93

Browse files
Merge pull request #5677 from kwvanderlinde/refactor/3777-dependency-breaking
Factor common utilities into a separate subproject
2 parents ca81ab6 + 42aa31c commit 09e7a93

File tree

136 files changed

+1010
-827
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+1010
-827
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ def zipJpackageImage = tasks.register('zipJpackageImage', Zip) {
361361

362362
// In this section you declare the dependencies for your production and test code
363363
dependencies {
364+
implementation project(':common')
364365
implementation project(':clientserver')
365366

366367
implementation(libs.bundles.log4j)

common/build.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
plugins {
2+
id "base"
3+
id "java-library"
4+
}
5+
6+
apply from: rootProject.file('buildSrc/shared.gradle')
7+
8+
// In this section you declare the dependencies for your production and test code
9+
dependencies {
10+
implementation(libs.findbugs.jsr305)
11+
12+
implementation(libs.bundles.log4j)
13+
implementation(libs.slf4j.simple)
14+
implementation(libs.apache.commons.logging)
15+
16+
implementation(libs.gson)
17+
18+
implementation(libs.bundles.imageio)
19+
implementation(libs.batik)
20+
21+
implementation(libs.apache.commons.io)
22+
23+
implementation(libs.jts.core)
24+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This software Copyright by the RPTools.net development team, and
3+
* licensed under the Affero GPL Version 3 or, at your option, any later
4+
* version.
5+
*
6+
* MapTool Source Code is distributed in the hope that it will be
7+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
8+
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+
*
10+
* You should have received a copy of the GNU Affero General Public
11+
* License * along with this source Code. If not, please visit
12+
* <http://www.gnu.org/licenses/> and specifically the Affero license
13+
* text at <http://www.gnu.org/licenses/agpl.html>.
14+
*/
15+
package net.rptools.lib;
16+
17+
import java.awt.Dimension;
18+
19+
public final class AwtUtil {
20+
private AwtUtil() {
21+
throw new RuntimeException("AwtUtil is a static class");
22+
}
23+
24+
public static void constrainTo(Dimension dim, int size) {
25+
boolean widthBigger = dim.width > dim.height;
26+
27+
if (widthBigger) {
28+
dim.height = (int) ((dim.height / (double) dim.width) * size);
29+
dim.width = size;
30+
} else {
31+
dim.width = (int) ((dim.width / (double) dim.height) * size);
32+
dim.height = size;
33+
}
34+
}
35+
36+
public static void constrainTo(Dimension dim, int width, int height) {
37+
boolean widthBigger = dim.width > dim.height;
38+
39+
constrainTo(dim, widthBigger ? width : height);
40+
41+
if ((widthBigger && dim.height > height) || (!widthBigger && dim.width > width)) {
42+
int size =
43+
(int)
44+
Math.round(
45+
widthBigger
46+
? (height / (double) dim.height) * width
47+
: (width / (double) dim.width) * dim.height);
48+
constrainTo(dim, size);
49+
}
50+
}
51+
}

src/main/java/net/rptools/lib/BackupManager.java renamed to common/src/main/java/net/rptools/lib/BackupManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Arrays;
2020
import java.util.LinkedList;
2121
import java.util.List;
22+
import org.apache.commons.io.FileUtils;
2223

2324
public class BackupManager {
2425

@@ -70,7 +71,7 @@ public void backup(File file) throws IOException {
7071
}
7172

7273
// Save
73-
FileUtil.copyFile(file, newFile);
74+
FileUtils.copyFile(file, newFile, false);
7475
}
7576

7677
/** List of existing backup files, with the oldest at the front */

src/main/java/net/rptools/maptool/util/CollectionUtil.java renamed to common/src/main/java/net/rptools/lib/CollectionUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* <http://www.gnu.org/licenses/> and specifically the Affero license
1313
* text at <http://www.gnu.org/licenses/agpl.html>.
1414
*/
15-
package net.rptools.maptool.util;
15+
package net.rptools.lib;
1616

1717
import java.util.EnumMap;
1818
import java.util.function.Function;
File renamed without changes.

src/main/java/net/rptools/lib/FileUtil.java renamed to common/src/main/java/net/rptools/lib/FileUtil.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
package net.rptools.lib;
1616

17-
import com.thoughtworks.xstream.XStream;
1817
import java.io.BufferedInputStream;
1918
import java.io.BufferedOutputStream;
2019
import java.io.BufferedReader;
@@ -41,10 +40,6 @@
4140
import java.util.zip.ZipEntry;
4241
import java.util.zip.ZipFile;
4342
import java.util.zip.ZipInputStream;
44-
import net.rptools.maptool.client.ui.token.BarTokenOverlay;
45-
import net.rptools.maptool.model.AStarCellPointConverter;
46-
import net.rptools.maptool.model.ShapeType;
47-
import net.rptools.maptool.model.converters.WallTopologyConverter;
4843
import org.apache.commons.io.FileUtils;
4944
import org.apache.commons.io.IOUtils;
5045
import org.apache.logging.log4j.LogManager;
@@ -79,11 +74,8 @@ public static byte[] getBytes(File file) throws IOException {
7974
return FileUtils.readFileToByteArray(file);
8075
}
8176

82-
public static Object objFromResource(String res) throws IOException {
83-
XStream xs = getConfiguredXStream();
84-
try (InputStream is = FileUtil.class.getClassLoader().getResourceAsStream(res)) {
85-
return xs.fromXML(new InputStreamReader(is, StandardCharsets.UTF_8));
86-
}
77+
public static InputStream getResourceAsStream(String res) {
78+
return FileUtil.class.getClassLoader().getResourceAsStream(res);
8779
}
8880

8981
public static byte[] loadResource(String resource) throws IOException {
@@ -480,21 +472,4 @@ public static void delete(File file) {
480472
public static String stripInvalidCharacters(String fileName) {
481473
return fileName = fileName.replaceAll("[^\\w\\s.,-]", "_");
482474
}
483-
484-
/**
485-
* Return an XStream which allows net.rptools.**, java.awt.**, sun.awt.** May be too permissive,
486-
* but it Works For Me(tm)
487-
*
488-
* @return a configured XStream
489-
*/
490-
public static XStream getConfiguredXStream() {
491-
XStream xStream = new XStream();
492-
XStream.setupDefaultSecurity(xStream);
493-
xStream.allowTypesByWildcard(new String[] {"net.rptools.**", "java.awt.**", "sun.awt.**"});
494-
xStream.registerConverter(new AStarCellPointConverter());
495-
xStream.registerConverter(new WallTopologyConverter(xStream));
496-
xStream.addImmutableType(ShapeType.class, true);
497-
xStream.addImmutableType(BarTokenOverlay.Side.class, true);
498-
return xStream;
499-
}
500475
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)