From da86fc15c92f03b29e49dd6001ba4faf5f3cd437 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Tue, 9 Jan 2024 15:07:58 +0100 Subject: [PATCH] remove OsgiCfgJsonFileHeader because aem analyser plugin dislikes osgi config jsons with comments --- .../fileheader/OsgiCfgJsonFileHeader.java | 75 ------------------- ...evops.conga.generator.spi.FileHeaderPlugin | 1 - .../fileheader/OsgiCfgJsonFileHeaderTest.java | 71 ------------------ 3 files changed, 147 deletions(-) delete mode 100644 conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiCfgJsonFileHeader.java delete mode 100644 conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiCfgJsonFileHeaderTest.java diff --git a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiCfgJsonFileHeader.java b/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiCfgJsonFileHeader.java deleted file mode 100644 index 1b56da7..0000000 --- a/conga-sling-plugin/src/main/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiCfgJsonFileHeader.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * #%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.plugins.sling.fileheader; - -import org.apache.commons.lang3.StringUtils; - -import io.wcm.devops.conga.generator.plugins.fileheader.AbstractFileHeader; -import io.wcm.devops.conga.generator.spi.context.FileContext; -import io.wcm.devops.conga.generator.spi.context.FileHeaderContext; -import io.wcm.devops.conga.generator.util.FileUtil; - -/** - * Adds file headers to OSGi .cfg.json files. - *

- * Those are actually JSON files, but inline comments are supported, see - * Specs - *

- */ -public final class OsgiCfgJsonFileHeader extends AbstractFileHeader { - - /** - * Plugin name - */ - public static final String NAME = "osgi-cfg-json"; - - private static final String FILE_EXTENSION = "cfg.json"; - - @Override - public String getName() { - return NAME; - } - - @Override - public boolean accepts(FileContext file, FileHeaderContext context) { - return FileUtil.matchesExtension(file, FILE_EXTENSION); - } - - @Override - protected String sanitizeComment(String line) { - return StringUtils.replace(StringUtils.replace(line, "/*", "/+"), "*/", "+/"); - } - - @Override - protected String getCommentBlockStart() { - return "/*\n"; - } - - @Override - protected String getCommentBlockEnd() { - return "*/\n"; - } - - @Override - public FileHeaderContext extract(FileContext file) { - return extractFileHeaderBetweenBlockStartEnd(file); - } - -} diff --git a/conga-sling-plugin/src/main/resources/META-INF/services/io.wcm.devops.conga.generator.spi.FileHeaderPlugin b/conga-sling-plugin/src/main/resources/META-INF/services/io.wcm.devops.conga.generator.spi.FileHeaderPlugin index f9bf4d6..4082206 100644 --- a/conga-sling-plugin/src/main/resources/META-INF/services/io.wcm.devops.conga.generator.spi.FileHeaderPlugin +++ b/conga-sling-plugin/src/main/resources/META-INF/services/io.wcm.devops.conga.generator.spi.FileHeaderPlugin @@ -1,3 +1,2 @@ -io.wcm.devops.conga.plugins.sling.fileheader.OsgiCfgJsonFileHeader io.wcm.devops.conga.plugins.sling.fileheader.OsgiConfigFileHeader io.wcm.devops.conga.plugins.sling.fileheader.ProvisioningFileHeader \ No newline at end of file diff --git a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiCfgJsonFileHeaderTest.java b/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiCfgJsonFileHeaderTest.java deleted file mode 100644 index 0aec4b1..0000000 --- a/conga-sling-plugin/src/test/java/io/wcm/devops/conga/plugins/sling/fileheader/OsgiCfgJsonFileHeaderTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * #%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.plugins.sling.fileheader; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.util.List; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import com.google.common.collect.ImmutableList; - -import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; -import io.wcm.devops.conga.generator.spi.context.FileContext; -import io.wcm.devops.conga.generator.spi.context.FileHeaderContext; -import io.wcm.devops.conga.generator.util.PluginManagerImpl; - -class OsgiCfgJsonFileHeaderTest { - - private FileHeaderPlugin underTest; - - @BeforeEach - void setUp() { - underTest = new PluginManagerImpl().get(OsgiCfgJsonFileHeader.NAME, FileHeaderPlugin.class); - } - - @Test - void testApply() throws Exception { - File file = new File("target/generation-test/fileHeader.cfg.json"); - FileUtils.copyFile(new File(getClass().getResource("/configSample.cfg.json").toURI()), file); - - List lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); - FileHeaderContext context = new FileHeaderContext().commentLines(lines); - FileContext fileContext = new FileContext().file(file); - - assertTrue(underTest.accepts(fileContext, context)); - underTest.apply(fileContext, context); - - assertTrue(StringUtils.contains(FileUtils.readFileToString(file, StandardCharsets.UTF_8), - "Der Jodelkaiser\naus dem Oetztal\nist wieder daheim.\n")); - - FileHeaderContext extractContext = underTest.extract(fileContext); - assertEquals(lines, extractContext.getCommentLines()); - - file.delete(); - } - -}