diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java index 49457fd16ef..ad647b68588 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java @@ -111,6 +111,7 @@ import org.opengrok.indexer.analysis.uue.UuencodeAnalyzerFactory; import org.opengrok.indexer.analysis.vb.VBAnalyzerFactory; import org.opengrok.indexer.analysis.verilog.VerilogAnalyzerFactory; +import org.opengrok.indexer.analysis.yang.YangAnalyzerFactory; import org.opengrok.indexer.analysis.yaml.YamlAnalyzerFactory; import org.opengrok.indexer.configuration.Project; import org.opengrok.indexer.configuration.RuntimeEnvironment; @@ -263,6 +264,7 @@ public class AnalyzerGuru { new BZip2AnalyzerFactory(), new XMLAnalyzerFactory(), new YamlAnalyzerFactory(), + new YangAnalyzerFactory(), MandocAnalyzerFactory.DEFAULT_INSTANCE, TroffAnalyzerFactory.DEFAULT_INSTANCE, new ELFAnalyzerFactory(), @@ -353,7 +355,7 @@ public class AnalyzerGuru { * has been called. */ public static long getVersionNo() { - final int ver32 = 20230921_00; // Edit comment above too! + final int ver32 = 20260217_00; // Edit comment above too! long ver = ver32; if (customizationHashCode != 0) { ver |= (long) customizationHashCode << 32; diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/yang/YangAnalyzer.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/yang/YangAnalyzer.java new file mode 100644 index 00000000000..82a44143b02 --- /dev/null +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/yang/YangAnalyzer.java @@ -0,0 +1,40 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * See LICENSE.txt included in this distribution for the specific + * language governing permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at LICENSE.txt. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2026, Oracle and/or its affiliates. + */ +package org.opengrok.indexer.analysis.yang; + +import org.opengrok.indexer.analysis.AnalyzerFactory; +import org.opengrok.indexer.analysis.plain.PlainAnalyzer; + +/** + * Analyzer for YANG files with plain-text indexing and xref behavior. + */ +public class YangAnalyzer extends PlainAnalyzer { + + /** + * Creates a new instance of YangAnalyzer. + * @param factory defined instance for the analyzer + */ + protected YangAnalyzer(AnalyzerFactory factory) { + super(factory); + } +} diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/yang/YangAnalyzerFactory.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/yang/YangAnalyzerFactory.java new file mode 100644 index 00000000000..4f11543f5bd --- /dev/null +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/yang/YangAnalyzerFactory.java @@ -0,0 +1,48 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * See LICENSE.txt included in this distribution for the specific + * language governing permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at LICENSE.txt. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2026, Oracle and/or its affiliates. + */ +package org.opengrok.indexer.analysis.yang; + +import org.opengrok.indexer.analysis.AbstractAnalyzer; +import org.opengrok.indexer.analysis.FileAnalyzerFactory; + +/** + * Factory for YANG files. + */ +public class YangAnalyzerFactory extends FileAnalyzerFactory { + + private static final String NAME = "Yang"; + + private static final String[] SUFFIXES = { + "YANG" + }; + + public YangAnalyzerFactory() { + super(null, null, SUFFIXES, null, null, "text/plain", + AbstractAnalyzer.Genre.PLAIN, NAME, true); + } + + @Override + protected AbstractAnalyzer newAnalyzer() { + return new YangAnalyzer(this); + } +} diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/AnalyzerGuruTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/AnalyzerGuruTest.java index d240e055e09..c7b3d162aca 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/AnalyzerGuruTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/AnalyzerGuruTest.java @@ -48,6 +48,7 @@ import org.opengrok.indexer.analysis.plain.XMLAnalyzer; import org.opengrok.indexer.analysis.sh.ShAnalyzer; import org.opengrok.indexer.analysis.sh.ShAnalyzerFactory; +import org.opengrok.indexer.analysis.yang.YangAnalyzer; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -66,6 +67,15 @@ class AnalyzerGuruTest { void testGetFileTypeDescriptions() { Map map = AnalyzerGuru.getfileTypeDescriptions(); assertFalse(map.isEmpty()); + assertEquals("Yang", map.get("yang")); + } + + @Test + void testYangAnalyzerBySuffix() throws Exception { + ByteArrayInputStream in = new ByteArrayInputStream( + "module example-yang {}".getBytes(StandardCharsets.UTF_8)); + AbstractAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "/dummy/file.yang"); + assertSame(YangAnalyzer.class, fa.getClass()); } /**