Skip to content

Commit

Permalink
Special handling for detecting ".cfg.json" file extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 9, 2024
1 parent dffaf46 commit adabaf7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
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">
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"));
}

}

0 comments on commit adabaf7

Please sign in to comment.