This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-api.git
The following commit(s) were added to refs/heads/main by this push:
new 00f6973 NIFI-16022 Fixed StandardResourceReferenceFactory
disambiguation for File path and block comments (#96)
00f6973 is described below
commit 00f69736ecdf45212fffb8c167bf0439853998d5
Author: dan-s1 <[email protected]>
AuthorDate: Mon Jul 6 11:05:36 2026 -0400
NIFI-16022 Fixed StandardResourceReferenceFactory disambiguation for File
path and block comments (#96)
Signed-off-by: David Handermann <[email protected]>
---
.../resource/StandardResourceReferenceFactory.java | 2 +-
.../TestStandardResourceReferenceFactory.java | 40 ++++++++++++++++++----
2 files changed, 34 insertions(+), 8 deletions(-)
diff --git
a/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
b/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
index d1aec57..95a6838 100644
---
a/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
+++
b/src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java
@@ -92,7 +92,7 @@ public class StandardResourceReferenceFactory implements
ResourceReferenceFactor
if (fileAllowed && textAllowed) {
// We have to make a determination whether this is a file or text.
Eventually, it will be best if the user tells us explicitly.
// For now, we will make a determination based on a couple of
simple rules.
- if (!trimmed.startsWith("//")) {
+ if (!trimmed.startsWith("//") && !trimmed.startsWith("/*")) {
final File file = new File(trimmed);
if (file.isAbsolute() || file.exists()) {
return new FileResourceReference(file);
diff --git
a/src/test/java/org/apache/nifi/components/resource/TestStandardResourceReferenceFactory.java
b/src/test/java/org/apache/nifi/components/resource/TestStandardResourceReferenceFactory.java
index 605ff9a..10e81e5 100644
---
a/src/test/java/org/apache/nifi/components/resource/TestStandardResourceReferenceFactory.java
+++
b/src/test/java/org/apache/nifi/components/resource/TestStandardResourceReferenceFactory.java
@@ -18,11 +18,15 @@
package org.apache.nifi.components.resource;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Set;
+import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -80,8 +84,17 @@ public class TestStandardResourceReferenceFactory {
assertEmptyResourceReferences(resourceReferences);
}
- @Test
- public void testDisambiguationBetweenTextAndFile() {
+ @ParameterizedTest
+ @MethodSource("disambiguationBetweenTextAndFileArgs")
+ public void testDisambiguationBetweenTextAndFile(String text) {
+ final ResourceDefinition resourceDefinition =
+ new StandardResourceDefinition(ResourceCardinality.SINGLE,
Set.of(ResourceType.FILE, ResourceType.TEXT));
+ final ResourceReference resourceReference =
subject.createResourceReference(text, resourceDefinition);
+
+ assertInstanceOf(Utf8TextResource.class, resourceReference);
+ }
+
+ private static Stream<Arguments> disambiguationBetweenTextAndFileArgs() {
final String transformWithSingleLineComment = """
// This is a single line comment in JSLT
{
@@ -90,11 +103,24 @@ public class TestStandardResourceReferenceFactory {
}
""";
- final ResourceDefinition resourceDefinition =
- new StandardResourceDefinition(ResourceCardinality.SINGLE,
Set.of(ResourceType.FILE, ResourceType.TEXT));
- final ResourceReference resourceReference =
subject.createResourceReference(transformWithSingleLineComment,
resourceDefinition);
-
- assertInstanceOf(Utf8TextResource.class, resourceReference);
+ final String transformWithMultiLineComment = """
+ /*
+ This is a multi-line Java comment in a JOLT spec.
+ */
+ [
+ {
+ "operation": "shift",
+ "spec": {
+ "*": "&"
+ }
+ }
+ ]
+ """;
+
+ return Stream.of(
+ Arguments.argumentSet("Leading single line Java comment",
transformWithSingleLineComment),
+ Arguments.argumentSet("Leading multi-line Java comment",
transformWithMultiLineComment)
+ );
}
private StandardResourceDefinition createResourceDefinition() {