Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Arguments> disambiguationBetweenTextAndFileArgs() {
final String transformWithSingleLineComment = """
// This is a single line comment in JSLT
{
Expand All @@ -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() {
Expand Down
Loading