This is an automated email from the ASF dual-hosted git repository. dan-s1 pushed a commit to branch NIFI-16022 in repository https://gitbox.apache.org/repos/asf/nifi-api.git
commit c9e9a40e6f5203c86c2590790ab4712c2a5c4da5 Author: dan-s1 <[email protected]> AuthorDate: Mon Jun 15 18:07:32 2026 +0000 NIFI-16022 Fixed another StandardResourceReferenceFactory disambiguation for File path and comment prefix --- .../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() {
