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 ResourceReference createResourceReference(final String value, final Resou 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 void testCreateResourceReferencesWhenResourceDefinitionIsNull() { 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 disambiguationBetweenTextAndFileArgs() { final String transformWithSingleLineComment = """ // This is a single line comment in JSLT { @@ -90,11 +103,24 @@ public void testDisambiguationBetweenTextAndFile() { } """; - 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() {