Skip to content

Commit c5e02af

Browse files
authored
Merge pull request #160 from mendix/run/4592-4126-3917-4337-4308-backport-improvements-9.18
[RUN-4592][RUN-4126][RUN-3917][RUN-4308] Backport improvements (lts/9.18)
2 parents 9962696 + 6fedced commit c5e02af

9 files changed

Lines changed: 406 additions & 17 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mxMarketplace {
2626
appDirectory = "src/CommunityCommons"
2727
versionPathPrefix = "_Version " // the path prefix within the module to the version folder
2828
createMigrationFile = true
29-
includeFiles = ["$mprDir/License.txt", "$mprDir/SiemensMendixCommunityCommons__10.1.3__READMEOSS.html"]
29+
includeFiles = ["$mprDir/License.txt", "$mprDir/SiemensMendixCommunityCommons__10.2.0__READMEOSS.html"]
3030
}
3131

3232
def userLibDir = "$mprDir/userlib"
@@ -58,7 +58,7 @@ dependencies {
5858
compileOnly([group: 'com.mendix', name: 'public-api', version: "$mendixPublicApiVersion"])
5959

6060
implementation(
61-
[group: 'com.google.guava', name: 'guava', version: '32.0.1-jre'],
61+
[group: 'com.google.guava', name: 'guava', version: '33.4.7-jre'],
6262
[group: 'com.googlecode.owasp-java-html-sanitizer', name: 'owasp-java-html-sanitizer', version: '20211018.2'],
6363
[group: 'commons-io', name: 'commons-io', version: '2.17.0'],
6464
[group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.30'],

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=10.1.4-SNAPSHOT
1+
version=10.2.0-SNAPSHOT
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- The StringFromFile Java action now removes BOM from strings. (Ticket #242904)
2+
- We have upgraded the Guava dependency to 33.4.7. This also removes the dependency on the jsr305 version 3.0.2 dependency, which causes some code quality scanning tools to report issues.
3+
- We have added a warning about possible deadlocks to the commitInSeparateDatabaseTransaction Java action.
4+
- We added the ORM.cloneObject(IContext, IMendixObject, IMendixObject, Boolean, Boolean) method. This is an overload for the ORM.cloneObject with an extra Boolean parameter 'skipIsBoth' that can be used to skip 1-on-1 associations.
0 Bytes
Binary file not shown.

src/CommunityCommons/SiemensMendixCommunityCommons__10.1.3__READMEOSS.html renamed to src/CommunityCommons/SiemensMendixCommunityCommons__10.2.0__READMEOSS.html

Lines changed: 350 additions & 13 deletions
Large diffs are not rendered by default.

src/CommunityCommons/javasource/communitycommons/ORM.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ private static boolean isFileDocument(IMendixObject object) {
265265

266266
public static Boolean cloneObject(IContext c, IMendixObject source,
267267
IMendixObject target, Boolean withAssociations) {
268+
return cloneObject(c, source, target, withAssociations, false);
269+
}
270+
271+
public static Boolean cloneObject(IContext c, IMendixObject source,
272+
IMendixObject target, Boolean withAssociations, Boolean skipIsBoth) {
268273
Map<String, ? extends IMendixObjectMember<?>> members = source.getMembers(c);
269274

270275
for (var entry : members.entrySet()) {
@@ -279,6 +284,10 @@ public static Boolean cloneObject(IContext c, IMendixObject source,
279284
continue;
280285
}
281286
if (withAssociations || ((!(m instanceof MendixObjectReference) && !(m instanceof MendixObjectReferenceSet) && !(m instanceof MendixAutoNumber)))) {
287+
if (skipIsBoth && (
288+
(m instanceof MendixObjectReference && ((MendixObjectReference) m).isBoth()) ||
289+
(m instanceof MendixObjectReferenceSet && ((MendixObjectReferenceSet) m).isBoth())))
290+
continue;
282291
target.setValue(c, entry.getKey(), m.getValue(c));
283292
}
284293
}

src/CommunityCommons/javasource/communitycommons/StringUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import javax.swing.text.html.parser.ParserDelegator;
3737

3838
import org.apache.commons.io.IOUtils;
39+
import org.apache.commons.io.input.BOMInputStream;
3940
import org.apache.commons.text.StringEscapeUtils;
4041
import org.owasp.html.PolicyFactory;
4142
import org.owasp.html.Sanitizers;
@@ -222,10 +223,14 @@ public static String stringFromFile(IContext context, FileDocument source, Chars
222223
return null;
223224
}
224225
try (InputStream f = Core.getFileDocumentContent(context, source.getMendixObject())) {
225-
return IOUtils.toString(f, charset);
226+
return stringFromInputStream(f, charset);
226227
}
227228
}
228229

230+
public static String stringFromInputStream(InputStream inputStream, Charset charset) throws IOException {
231+
return IOUtils.toString(BOMInputStream.builder().setInputStream(inputStream).get(), charset);
232+
}
233+
229234
public static void stringToFile(IContext context, String value, FileDocument destination) throws IOException {
230235
stringToFile(context, value, destination, StandardCharsets.UTF_8);
231236
}

src/CommunityCommons/javasource/communitycommons/actions/commitInSeparateDatabaseTransaction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
/**
1919
* This function commits an object in a seperate context and transaction, making sure it gets persisted in the database (regarding which exception happens after invocation).
20+
*
21+
* Please note that this action is prone to deadlock. For example if you commit an object in one transaction and then use this action to commit the same object in a separate transaction. We do not recommend the use of this action.
2022
*/
2123
public class commitInSeparateDatabaseTransaction extends CustomJavaAction<java.lang.Boolean>
2224
{

src/test/communitycommons/StringUtilsTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import org.owasp.html.PolicyFactory;
1515
import org.owasp.html.Sanitizers;
1616

17+
import java.io.ByteArrayInputStream;
18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.nio.charset.Charset;
1721
import java.security.DigestException;
1822
import java.security.NoSuchAlgorithmException;
1923

@@ -170,4 +174,32 @@ public void testHash() throws DigestException, NoSuchAlgorithmException {
170174
assertEquals(StringUtils.hash(originalString), StringUtils.hash(originalString, length));
171175
assertEquals(StringUtils.hash(originalString), hashedString);
172176
}
177+
178+
@Test
179+
public void testStringFromInputStream() throws IOException {
180+
Charset utf8 = Charset.forName("UTF-8");
181+
Charset utf16 = Charset.forName("UTF-16");
182+
Charset utf16be = Charset.forName("UTF-16BE");
183+
Charset utf16le = Charset.forName("UTF-16LE");
184+
185+
String text = "hello";
186+
187+
assertEquals(text, testStringFromInputStream(text, utf8));
188+
assertEquals(text, testStringFromInputStream(text, utf16));
189+
assertEquals(text, testStringFromInputStream(text, utf16be));
190+
assertEquals(text, testStringFromInputStream(text, utf16le));
191+
192+
// BOM should be removed (UTF-8)
193+
byte[] UTF8BOM = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
194+
String textUTF8BOM = new String(UTF8BOM) + text;
195+
assertEquals(text, testStringFromInputStream(textUTF8BOM, utf8));
196+
}
197+
198+
private String testStringFromInputStream(String text, Charset charset) throws IOException {
199+
return StringUtils.stringFromInputStream(stringToInputStream(text, charset), charset);
200+
}
201+
202+
private InputStream stringToInputStream(String str, Charset charset) {
203+
return new ByteArrayInputStream(str.getBytes(charset));
204+
}
173205
}

0 commit comments

Comments
 (0)