Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special handling for detecting ".cfg.json" file extensions. #57

Merged
merged 2 commits into from
Jan 9, 2024
Merged
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
6 changes: 6 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 https://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="1.16.6" date="not released">
<action type="update" dev="sseifert" issue="57">
Special handling for detecting ".cfg.json" file extensions.
</action>
</release>

<release version="1.16.4" date="2023-10-18">
<action type="fix" dev="sseifert" issue="47">
Increase SnakeYAML codepoint limit to 64MB (from default 3MB).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ public static boolean matchesExtension(String fileExtension, String extension) {
* @return true if file extension matches
*/
public static boolean matchesExtension(File file, String extension) {
return matchesExtension(FilenameUtils.getExtension(file.getName()), extension);
String fileName = file.getName();
String fileExtension;
// special handling for OSGi configuration resource file extension
if (fileName.endsWith(".cfg.json")) {
fileExtension = "cfg.json";
}
else {
fileExtension = FilenameUtils.getExtension(fileName);
}
return matchesExtension(fileExtension, extension);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2024 wcm.io
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package io.wcm.devops.conga.generator.util;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;

import org.junit.jupiter.api.Test;

class FileUtilTest {

@Test
void testMatchesExtension() {
assertTrue(FileUtil.matchesExtension(new File("test.txt"), "txt"));
assertTrue(FileUtil.matchesExtension(new File("test.part2.txt"), "txt"));
assertFalse(FileUtil.matchesExtension(new File("test.pdf"), "txt"));

// special handling for OSGi configuration resource file extension
assertTrue(FileUtil.matchesExtension(new File("test.cfg.json"), "cfg.json"));
}

}
Loading