diff --git a/dev/checkstyle/suppressions.xml b/dev/checkstyle/suppressions.xml index d862334b813..f7b7b2f04f8 100644 --- a/dev/checkstyle/suppressions.xml +++ b/dev/checkstyle/suppressions.xml @@ -39,6 +39,8 @@ Portions Copyright (c) 2018-2019, Chris Fraire . |JFlexXrefUtils\.java|FileAnalyzerFactory\.java|SearchController\.java| |Context\.java|HistoryContext\.java|Suggester\.java" /> + + command = new ArrayList<>(); + /** + * Gets the command-line arguments used to run ctags. + * @return a defined (immutable) list + */ + public List getArgv() { + initialize(); + return Collections.unmodifiableList(command); + } + + private void initialize() { + env.validateUniversalCtags(); - command.add(binary); - command.add("--c-kinds=+l"); + command = new ArrayList<>(); + command.add(env.getCtags()); + command.add("--kinds-c=+l"); // Workaround for bug #14924: Don't get local variables in Java // code since that creates many false positives. // CtagsTest : bug14924 "too many methods" guards for this // universal ctags are however safe, so enabling for them - command.add("--java-kinds=+l"); + command.add("--kinds-java=+l"); - command.add("--sql-kinds=+l"); - command.add("--Fortran-kinds=+L"); - command.add("--C++-kinds=+l"); + command.add("--kinds-sql=+l"); + command.add("--kinds-Fortran=+L"); + command.add("--kinds-C++=+l"); command.add("--file-scope=yes"); command.add("-u"); command.add("--filter=yes"); @@ -201,10 +208,12 @@ private void initialize() throws IOException { /* Add extra command line options for ctags. */ if (CTagsExtraOptionsFile != null) { - LOGGER.log(Level.INFO, "Adding extra options to ctags"); + LOGGER.log(Level.FINER, "Adding extra options to ctags"); command.add("--options=" + CTagsExtraOptionsFile); } + } + private void run() throws IOException { StringBuilder sb = new StringBuilder(); for (String s : command) { sb.append(s).append(" "); @@ -212,7 +221,7 @@ private void initialize() throws IOException { String commandStr = sb.toString(); LOGGER.log(Level.FINE, "Executing ctags command [{0}]", commandStr); - processBuilder = new ProcessBuilder(command); + ProcessBuilder processBuilder = new ProcessBuilder(command); ctags = processBuilder.start(); ctagsIn = new OutputStreamWriter( @@ -242,7 +251,9 @@ private void initialize() throws IOException { } private void addRustSupport(List command) { - command.add("--langdef=rust"); + if (!env.getCtagsLanguages().contains("Rust")) { // Built-in would be capitalized. + command.add("--langdef=rust"); // Lower-case if user-defined. + } defaultLangMap.add(".RS", "rust"); // Upper-case file spec // The following are not supported yet in Universal Ctags b13cb551 @@ -256,9 +267,12 @@ private void addRustSupport(List command) { } private void addPowerShellSupport(List command) { - command.add("--langdef=powershell"); + if (!env.getCtagsLanguages().contains("PowerShell")) { // Built-in would be capitalized. + command.add("--langdef=powershell"); // Lower-case if user-defined. + } defaultLangMap.add(".PS1", "powershell"); // Upper-case file spec defaultLangMap.add(".PSM1", "powershell"); // Upper-case file spec + command.add("--regex-powershell=/\\$(\\{[^}]+\\})/\\1/v,variable/"); command.add("--regex-powershell=/\\$([[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1/v,variable/"); command.add("--regex-powershell=/^[[:space:]]*(:[^[:space:]]+)/\\1/l,label/"); @@ -275,8 +289,11 @@ private void addPowerShellSupport(List command) { } private void addPascalSupport(List command) { - command.add("--langdef=pascal"); + if (!env.getCtagsLanguages().contains("Pascal")) { // Built-in would be capitalized. + command.add("--langdef=pascal"); // Lower-case if user-defined. + } defaultLangMap.add(".PAS", "pascal"); // Upper-case file spec + command.add("--regex-pascal=/([[:alnum:]_]+)[[:space:]]*=[[:space:]]*\\([[:space:]]*[[:alnum:]_][[:space:]]*\\)/\\1/t,Type/"); command.add("--regex-pascal=/([[:alnum:]_]+)[[:space:]]*=[[:space:]]*class[[:space:]]*[^;]*$/\\1/c,Class/"); command.add("--regex-pascal=/([[:alnum:]_]+)[[:space:]]*=[[:space:]]*interface[[:space:]]*[^;]*$/\\1/i,interface/"); @@ -290,7 +307,9 @@ private void addPascalSupport(List command) { } private void addSwiftSupport(List command) { - command.add("--langdef=swift"); + if (!env.getCtagsLanguages().contains("Swift")) { // Built-in would be capitalized. + command.add("--langdef=swift"); // Lower-case if user-defined. + } defaultLangMap.add(".SWIFT", "swift"); // Upper-case file spec command.add("--regex-swift=/enum[[:space:]]+([^\\{\\}]+).*$/\\1/n,enum,enums/"); command.add("--regex-swift=/typealias[[:space:]]+([^:=]+).*$/\\1/t,typealias,typealiases/"); @@ -303,9 +322,12 @@ private void addSwiftSupport(List command) { } private void addKotlinSupport(List command) { - command.add("--langdef=kotlin"); + if (!env.getCtagsLanguages().contains("Kotlin")) { // Built-in would be capitalized. + command.add("--langdef=kotlin"); // Lower-case if user-defined. + } defaultLangMap.add(".KT", "kotlin"); // Upper-case file spec defaultLangMap.add(".KTS", "kotlin"); // Upper-case file spec + command.add("--regex-kotlin=/^[[:space:]]*((abstract|final|sealed|implicit|lazy)[[:space:]]*)*" + "(private[^ ]*|protected)?[[:space:]]*class[[:space:]]+([[:alnum:]_:]+)/\\4/c,classes/"); command.add("--regex-kotlin=/^[[:space:]]*((abstract|final|sealed|implicit|lazy)[[:space:]]*)*" + @@ -326,8 +348,13 @@ private void addKotlinSupport(List command) { command.add("--regex-kotlin=/^[[:space:]]*import[[:space:]]+([[:alnum:]_.:]+)/\\1/I,imports/"); } + /** + * Override Clojure support with patterns from https://gist.github.com/kul/8704283. + */ private void addClojureSupport(List command) { - command.add("--langdef=clojure"); // clojure support (patterns are from https://gist.github.com/kul/8704283) + if (!env.getCtagsLanguages().contains("Clojure")) { // Built-in would be capitalized. + command.add("--langdef=clojure"); // Lower-case if user-defined. + } defaultLangMap.add(".CLJ", "clojure"); // Upper-case file spec defaultLangMap.add(".CLJS", "clojure"); // Upper-case file spec defaultLangMap.add(".CLJX", "clojure"); // Upper-case file spec @@ -345,9 +372,12 @@ private void addClojureSupport(List command) { } private void addHaskellSupport(List command) { - command.add("--langdef=haskell"); // below was added with #912 + if (!env.getCtagsLanguages().contains("Haskell")) { // Built-in would be capitalized. + command.add("--langdef=haskell"); // below added with #912. Lowercase if user-defined. + } defaultLangMap.add(".HS", "haskell"); // Upper-case file spec defaultLangMap.add(".HSC", "haskell"); // Upper-case file spec + command.add("--regex-haskell=/^[[:space:]]*class[[:space:]]+([a-zA-Z0-9_]+)/\\1/c,classes/"); command.add("--regex-haskell=/^[[:space:]]*data[[:space:]]+([a-zA-Z0-9_]+)/\\1/t,types/"); command.add("--regex-haskell=/^[[:space:]]*newtype[[:space:]]+([a-zA-Z0-9_]+)/\\1/t,types/"); @@ -359,8 +389,11 @@ private void addHaskellSupport(List command) { } private void addScalaSupport(List command) { - command.add("--langdef=scala"); // below is bug 61 to get full scala support + if (!env.getCtagsLanguages().contains("Scala")) { // Built-in would be capitalized. + command.add("--langdef=scala"); // below is bug 61 to get full scala support. Lower-case + } defaultLangMap.add(".SCALA", "scala"); // Upper-case file spec + command.add("--regex-scala=/^[[:space:]]*((abstract|final|sealed|implicit|lazy)[[:space:]]*)*" + "(private|protected)?[[:space:]]*class[[:space:]]+([a-zA-Z0-9_]+)/\\4/c,classes/"); command.add("--regex-scala=/^[[:space:]]*((abstract|final|sealed|implicit|lazy)[[:space:]]*)*" + @@ -408,6 +441,7 @@ public Definitions doCtags(String file) throws IOException, } } else { initialize(); + run(); } CtagsReader rdr = new CtagsReader(); @@ -429,7 +463,7 @@ public Definitions doCtags(String file) throws IOException, * the ctags process completes so that the indexer can * make progress instead of hanging the whole operation. */ - IndexerParallelizer parallelizer = RuntimeEnvironment.getInstance().getIndexerParallelizer(); + IndexerParallelizer parallelizer = env.getIndexerParallelizer(); ExecutorService executor = parallelizer.getCtagsWatcherExecutor(); Future future = executor.submit(() -> { readTags(rdr); diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/swift/SwiftAnalyzer.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/swift/SwiftAnalyzer.java index 6806455e458..d69161e02ac 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/swift/SwiftAnalyzer.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/swift/SwiftAnalyzer.java @@ -46,11 +46,11 @@ protected SwiftAnalyzer(AnalyzerFactory factory) { } /** - * @return {@code "Swift"} to match the OpenGrok-customized definitions + * @return {@code "swift"} to match the OpenGrok-customized definitions */ @Override public String getCtagsLang() { - return "Swift"; + return "swift"; } /** diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java index c9dcc826c50..e9e3e53dc03 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -121,6 +122,11 @@ public final class RuntimeEnvironment { private transient File dtagsEftar = null; + private transient volatile Boolean ctagsFound; + private final transient Set ctagsLanguages = new HashSet<>(); + + public WatchDogService watchDog; + /** * Creates a new instance of RuntimeEnvironment. Private to ensure a * singleton anti-pattern. @@ -180,8 +186,6 @@ public static RuntimeEnvironment getInstance() { return instance; } - public WatchDogService watchDog; - public IndexerParallelizer getIndexerParallelizer() { return lzIndexerParallelizer.get(); } @@ -641,8 +645,6 @@ public void setHitsPerPage(int hitsPerPage) { setConfigurationValue("hitsPerPage", hitsPerPage); } - private transient Boolean ctagsFound; - /** * Validate that there is a Universal ctags program. * @@ -650,15 +652,35 @@ public void setHitsPerPage(int hitsPerPage) { */ public boolean validateUniversalCtags() { if (ctagsFound == null) { - if (!CtagsUtil.validate(getCtags())) { - ctagsFound = false; - } else { - ctagsFound = true; + String ctagsBinary = getCtags(); + configLock.writeLock().lock(); + try { + if (ctagsFound == null) { + ctagsFound = CtagsUtil.validate(ctagsBinary); + if (ctagsFound) { + List languages = CtagsUtil.getLanguages(ctagsBinary); + if (languages != null) { + ctagsLanguages.addAll(languages); + } + } + } + } finally { + configLock.writeLock().unlock(); } } return ctagsFound; } + /** + * Gets the base set of supported Ctags languages. + * @return a defined set which may be empty if + * {@link #validateUniversalCtags()} has not yet been called or if the call + * fails + */ + public Set getCtagsLanguages() { + return Collections.unmodifiableSet(ctagsLanguages); + } + /** * Get the max time a SCM operation may use to avoid being cached. * diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java index 0c32f32a448..844a0ccdd10 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexDatabase.java @@ -742,9 +742,7 @@ private void addFile(File file, String path, Ctags ctags) if (env.getCtagsTimeout() != 0) { ctags.setTimeout(env.getCtagsTimeout()); } - if (ctags.getBinary() != null) { - fa.setCtags(ctags); - } + fa.setCtags(ctags); fa.setProject(Project.getProject(path)); fa.setScopesEnabled(env.isScopesEnabled()); fa.setFoldingEnabled(env.isFoldingEnabled()); diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java index d92dc157dbf..12f7099c0a5 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java @@ -52,6 +52,7 @@ import org.opengrok.indexer.Info; import org.opengrok.indexer.analysis.AnalyzerGuru; import org.opengrok.indexer.analysis.AnalyzerGuruHelp; +import org.opengrok.indexer.analysis.Ctags; import org.opengrok.indexer.configuration.Configuration; import org.opengrok.indexer.configuration.ConfigurationHelp; import org.opengrok.indexer.configuration.LuceneLockName; @@ -64,6 +65,7 @@ import org.opengrok.indexer.index.IndexVersion.IndexVersionException; import org.opengrok.indexer.logger.LoggerFactory; import org.opengrok.indexer.logger.LoggerUtil; +import org.opengrok.indexer.util.CtagsUtil; import org.opengrok.indexer.util.Executor; import org.opengrok.indexer.util.OptionParser; import org.opengrok.indexer.util.Statistics; @@ -107,9 +109,8 @@ public final class Indexer { private static boolean bareConfig = false; private static boolean awaitProfiler; - private static boolean help; + private static int help; private static String helpUsage; - private static boolean helpDetailed; private static String configFilename = null; private static int status = 0; @@ -146,13 +147,16 @@ public static void main(String[] argv) { try { argv = parseOptions(argv); - if (help) { + if (help > 0) { PrintStream helpStream = status != 0 ? System.err : System.out; helpStream.println(helpUsage); - if (helpDetailed) { + if (help > 1) { helpStream.println(AnalyzerGuruHelp.getUsage()); helpStream.println(ConfigurationHelp.getSamples()); } + if (help > 2) { + helpStream.println(getCtagsCommand()); + } System.exit(status); } @@ -425,13 +429,13 @@ public static String[] parseOptions(String[] argv) throws ParseException { * Pre-match any of the --help options so that some possible exception- * generating args handlers (e.g. -R) can be short-circuited. */ - help = Arrays.stream(argv).anyMatch(s -> HELP_OPT_1.equals(s) || + boolean preHelp = Arrays.stream(argv).anyMatch(s -> HELP_OPT_1.equals(s) || HELP_OPT_2.equals(s) || HELP_OPT_3.equals(s)); OptionParser configure = OptionParser.scan(parser -> { parser.on("-R configPath").Do(cfgFile -> { try { - if (!help) { + if (!preHelp) { cfg = Configuration.read(new File((String) cfgFile)); } } catch (IOException e) { @@ -443,19 +447,20 @@ public static String[] parseOptions(String[] argv) throws ParseException { // An example of how to add a data type for option parsing OptionParser.accept(WebAddress.class, Indexer::parseWebAddress); + // Limit usage lines to 72 characters for concise formatting. + optParser = OptionParser.Do(parser -> { parser.setPrologue( String.format("\nUsage: java -jar %s [options] [subDir1 [...]]\n", program)); parser.on(HELP_OPT_3, Indexer.HELP_OPT_2, HELP_OPT_1, - "Display this usage summary.").Do(v -> { - help = true; - helpUsage = parser.getUsage(); + "Display this usage summary.", + " Repeat once for configuration.xml samples.", + " Repeat twice for ctags command-line.").Do(v -> { + ++help; + helpUsage = parser.getUsage(); }); - parser.on("--detailed", - "Display additional help with -h,--help.").Do(v -> helpDetailed = true); - parser.on( "-A (.ext|prefix.):(-|analyzer)", "--analyzer", "/(\\.\\w+|\\w+\\.):(-|[a-zA-Z_0-9.]+)/", "Files with the named prefix/extension should be analyzed", @@ -1116,6 +1121,36 @@ private static void pauseToAwaitProfiler() { } } + private static String getCtagsCommand() { + StringBuilder result = new StringBuilder(); + Ctags ctags = CtagsUtil.newInstance(env); + List argv = ctags.getArgv(); + for (int i = 0; i < argv.size(); ++i) { + if (i > 0) { + result.append("\t"); + } + String arg = argv.get(i); + if (arg == null) { + result.append("UNDEFINED"); + } else { + result.append(maybeEscapeForSh(arg)); + } + if (i + 1 < argv.size()) { + result.append(" \\"); + } + result.append("\n"); + } + return result.toString(); + } + + private static String maybeEscapeForSh(String value) { + if (!value.matches(".*[^-:.+=a-zA-Z0-9_].*")) { + return value; + } + return "$'" + value.replace("\\", "\\\\").replace("'", "\\'").replace("\n", "\\n"). + replace("\r", "\\r").replace("\t", "\\t") + "'"; + } + private Indexer() { } } diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexerParallelizer.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexerParallelizer.java index 6c80d5ebc3e..2866c000c37 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexerParallelizer.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/index/IndexerParallelizer.java @@ -27,14 +27,12 @@ import java.util.concurrent.Executors; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.logging.Logger; -import org.opengrok.indexer.analysis.AnalyzerGuru; import org.opengrok.indexer.analysis.Ctags; import org.opengrok.indexer.analysis.CtagsValidator; import org.opengrok.indexer.configuration.RuntimeEnvironment; -import org.opengrok.indexer.logger.LoggerFactory; import org.opengrok.indexer.util.BoundedBlockingObjectPool; +import org.opengrok.indexer.util.CtagsUtil; import org.opengrok.indexer.util.LazilyInstantiate; import org.opengrok.indexer.util.ObjectFactory; import org.opengrok.indexer.util.ObjectPool; @@ -50,9 +48,6 @@ */ public class IndexerParallelizer implements AutoCloseable { - private static final Logger LOGGER = - LoggerFactory.getLogger(IndexerParallelizer.class); - private final RuntimeEnvironment env; private final int indexingParallelism; @@ -228,7 +223,7 @@ private void createLazyForkJoinPool() { private void createLazyCtagsPool() { lzCtagsPool = LazilyInstantiate.using(() -> new BoundedBlockingObjectPool<>(indexingParallelism, - new CtagsValidator(), new CtagsObjectFactory(env))); + new CtagsValidator(), new CtagsObjectFactory())); } private void createLazyCtagsWatcherExecutor() { @@ -255,41 +250,10 @@ private void createLazyHistoryRenamedExecutor() { Executors.newFixedThreadPool(env.getHistoryRenamedParallelism())); } - /** - * Creates a new instance, and attempts to configure it from the specified - * environment instance. - * @return a defined instance, possibly with a {@code null} ctags binary - * setting if a value was not available from {@link RuntimeEnvironment}. - */ - private static Ctags getNewCtags(RuntimeEnvironment env) { - Ctags ctags = new Ctags(); - - String ctagsBinary = env.getCtags(); - if (ctagsBinary == null) { - LOGGER.severe("Unable to run ctags!" + - " searching definitions will not work!"); - } else { - ctags.setBinary(ctagsBinary); - ctags.setLangMap(AnalyzerGuru.getLangMap()); - - String filename = env.getCTagsExtraOptionsFile(); - if (filename != null) { - ctags.setCTagsExtraOptionsFile(filename); - } - } - return ctags; - } - private class CtagsObjectFactory implements ObjectFactory { - private final RuntimeEnvironment env; - - CtagsObjectFactory(RuntimeEnvironment env) { - this.env = env; - } - public Ctags createNew() { - return getNewCtags(env); + return CtagsUtil.newInstance(env); } } } diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java index 11734dd3075..445b0e2d497 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java @@ -19,12 +19,18 @@ /* * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved. + * Portions Copyright (c) 2019, Chris Fraire . */ package org.opengrok.indexer.util; +import org.opengrok.indexer.analysis.AnalyzerGuru; +import org.opengrok.indexer.analysis.Ctags; +import org.opengrok.indexer.configuration.RuntimeEnvironment; import org.opengrok.indexer.logger.LoggerFactory; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -54,6 +60,49 @@ public static boolean validate(String ctagsBinary) { return true; } - private CtagsUtil() { + /** + * Gets the base set of languages by executing {@code --list-languages} for + * the specified binary. + * @return {@code null} on failure to run, or a defined list + */ + public static List getLanguages(String ctagsBinary) { + Executor executor = new Executor(new String[]{ctagsBinary, "--list-languages"}); + int rc = executor.exec(false); + String output = executor.getOutputString(); + if (output == null || rc != 0) { + LOGGER.log(Level.WARNING, "Failed to get Ctags languages"); + return null; + } + + output = output.replaceAll("\\s+\\[disabled]", ""); + String[] split = output.split("(?m)$"); + List result = new ArrayList<>(); + for (String lang : split) { + lang = lang.trim(); + if (lang.length() > 0) { + result.add(lang); + } + } + return result; + } + + /** + * Creates a new instance, and attempts to configure it from the + * environment. + * @return a defined instance + */ + public static Ctags newInstance(RuntimeEnvironment env) { + Ctags ctags = new Ctags(); + ctags.setLangMap(AnalyzerGuru.getLangMap()); + + String filename = env.getCTagsExtraOptionsFile(); + if (filename != null) { + ctags.setCTagsExtraOptionsFile(filename); } + return ctags; + } + + /** Private to enforce static. */ + private CtagsUtil() { + } } diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/CtagsTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/CtagsTest.java index 2e28ab87f0b..3658879e4d7 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/CtagsTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/CtagsTest.java @@ -19,7 +19,7 @@ /* * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. - * Portions Copyright (c) 2017-2018, Chris Fraire . + * Portions Copyright (c) 2017-2019, Chris Fraire . */ package org.opengrok.indexer.analysis; @@ -34,7 +34,6 @@ import org.opengrok.indexer.condition.ConditionalRun; import org.opengrok.indexer.condition.ConditionalRunRule; import org.opengrok.indexer.condition.CtagsInstalled; -import org.opengrok.indexer.configuration.RuntimeEnvironment; import org.opengrok.indexer.util.TestRepository; /** @@ -53,7 +52,6 @@ public class CtagsTest { @BeforeClass public static void setUpClass() throws Exception { ctags = new Ctags(); - ctags.setBinary(RuntimeEnvironment.getInstance().getCtags()); repository = new TestRepository(); repository.create(CtagsTest.class.getResourceAsStream( @@ -71,7 +69,7 @@ public static void setUpClass() throws Exception { } @AfterClass - public static void tearDownClass() throws Exception { + public static void tearDownClass() { ctags.close(); ctags = null; repository.destroy(); diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/JFlexXrefTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/JFlexXrefTest.java index 3a5ace6ccbf..aed4761b69e 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/JFlexXrefTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/JFlexXrefTest.java @@ -19,7 +19,7 @@ /* * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. - * Portions Copyright (c) 2017-2018, Chris Fraire . + * Portions Copyright (c) 2017-2019, Chris Fraire . */ package org.opengrok.indexer.analysis; @@ -61,7 +61,6 @@ import org.opengrok.indexer.condition.ConditionalRun; import org.opengrok.indexer.condition.ConditionalRunRule; import org.opengrok.indexer.condition.CtagsInstalled; -import org.opengrok.indexer.configuration.RuntimeEnvironment; import static org.opengrok.indexer.util.CustomAssertions.assertLinesEqual; import org.opengrok.indexer.util.TestRepository; import org.xml.sax.InputSource; @@ -87,14 +86,13 @@ public class JFlexXrefTest { @BeforeClass public static void setUpClass() throws Exception { ctags = new Ctags(); - ctags.setBinary(RuntimeEnvironment.getInstance().getCtags()); repository = new TestRepository(); repository.create(JFlexXrefTest.class.getResourceAsStream( "/org/opengrok/indexer/index/source.zip")); } @AfterClass - public static void tearDownClass() throws Exception { + public static void tearDownClass() { ctags.close(); ctags = null; repository.destroy(); diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/c/CAnalyzerFactoryTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/c/CAnalyzerFactoryTest.java index c34f9a5ef65..bcb58364374 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/c/CAnalyzerFactoryTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/c/CAnalyzerFactoryTest.java @@ -19,7 +19,7 @@ /* * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. - * Portions Copyright (c) 2017-2018, Chris Fraire . + * Portions Copyright (c) 2017-2019, Chris Fraire . */ package org.opengrok.indexer.analysis.c; @@ -80,7 +80,6 @@ public InputStream getStream() throws IOException { @BeforeClass public static void setUpClass() throws Exception { ctags = new Ctags(); - ctags.setBinary(RuntimeEnvironment.getInstance().getCtags()); repository = new TestRepository(); repository.create(CAnalyzerFactoryTest.class.getResourceAsStream( @@ -95,7 +94,7 @@ public static void setUpClass() throws Exception { } @AfterClass - public static void tearDownClass() throws Exception { + public static void tearDownClass() { ctags.close(); ctags = null; } diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/c/CxxAnalyzerFactoryTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/c/CxxAnalyzerFactoryTest.java index dcc2080d3ad..1bc0d064fda 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/c/CxxAnalyzerFactoryTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/c/CxxAnalyzerFactoryTest.java @@ -19,7 +19,7 @@ /* * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. - * Portions Copyright (c) 2017-2018, Chris Fraire . + * Portions Copyright (c) 2017-2019, Chris Fraire . */ package org.opengrok.indexer.analysis.c; @@ -80,7 +80,6 @@ public InputStream getStream() throws IOException { @BeforeClass public static void setUpClass() throws Exception { ctags = new Ctags(); - ctags.setBinary(RuntimeEnvironment.getInstance().getCtags()); repository = new TestRepository(); repository.create(CxxAnalyzerFactoryTest.class.getResourceAsStream( @@ -95,7 +94,7 @@ public static void setUpClass() throws Exception { } @AfterClass - public static void tearDownClass() throws Exception { + public static void tearDownClass() { ctags.close(); ctags = null; } diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/clojure/ClojureAnalyzerFactoryTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/clojure/ClojureAnalyzerFactoryTest.java index dd179b817f9..1cef069e834 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/clojure/ClojureAnalyzerFactoryTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/clojure/ClojureAnalyzerFactoryTest.java @@ -19,7 +19,7 @@ /* * Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. - * Portions Copyright (c) 2017-2018, Chris Fraire . + * Portions Copyright (c) 2017-2019, Chris Fraire . */ package org.opengrok.indexer.analysis.clojure; @@ -77,7 +77,6 @@ public InputStream getStream() throws IOException { @BeforeClass public static void setUpClass() throws Exception { ctags = new Ctags(); - ctags.setBinary(RuntimeEnvironment.getInstance().getCtags()); repository = new TestRepository(); repository.create(ClojureAnalyzerFactoryTest.class.getResourceAsStream( diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/csharp/CSharpAnalyzerFactoryTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/csharp/CSharpAnalyzerFactoryTest.java index cade0a9f90d..52a692d1604 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/csharp/CSharpAnalyzerFactoryTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/csharp/CSharpAnalyzerFactoryTest.java @@ -19,7 +19,7 @@ /* * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. - * Portions Copyright (c) 2017-2018, Chris Fraire . + * Portions Copyright (c) 2017-2019, Chris Fraire . */ package org.opengrok.indexer.analysis.csharp; @@ -76,7 +76,6 @@ public InputStream getStream() throws IOException { @BeforeClass public static void setUpClass() throws Exception { ctags = new Ctags(); - ctags.setBinary(RuntimeEnvironment.getInstance().getCtags()); repository = new TestRepository(); repository.create(CSharpAnalyzerFactoryTest.class.getResourceAsStream( @@ -91,7 +90,7 @@ public static void setUpClass() throws Exception { } @AfterClass - public static void tearDownClass() throws Exception { + public static void tearDownClass() { ctags.close(); ctags = null; } diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/java/JavaAnalyzerFactoryTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/java/JavaAnalyzerFactoryTest.java index 3bdc7959ee6..a89d677a6e6 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/java/JavaAnalyzerFactoryTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/java/JavaAnalyzerFactoryTest.java @@ -19,7 +19,7 @@ /* * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. - * Portions Copyright (c) 2017-2018, Chris Fraire . + * Portions Copyright (c) 2017-2019, Chris Fraire . */ package org.opengrok.indexer.analysis.java; @@ -80,7 +80,6 @@ public InputStream getStream() throws IOException { @BeforeClass public static void setUpClass() throws Exception { ctags = new Ctags(); - ctags.setBinary(RuntimeEnvironment.getInstance().getCtags()); repository = new TestRepository(); repository.create(JavaAnalyzerFactoryTest.class.getResourceAsStream( @@ -95,15 +94,13 @@ public static void setUpClass() throws Exception { } @AfterClass - public static void tearDownClass() throws Exception { + public static void tearDownClass() { ctags.close(); ctags = null; } /** * Test of writeXref method, of class CAnalyzerFactory. - * - * @throws java.lang.Exception */ @Test public void testScopeAnalyzer() throws Exception { diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/pascal/PascalAnalyzerFactoryTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/pascal/PascalAnalyzerFactoryTest.java index f9f64446238..a041e084a3b 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/pascal/PascalAnalyzerFactoryTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/pascal/PascalAnalyzerFactoryTest.java @@ -19,7 +19,7 @@ /* * Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. - * Portions Copyright (c) 2017-2018, Chris Fraire . + * Portions Copyright (c) 2017-2019, Chris Fraire . */ package org.opengrok.indexer.analysis.pascal; @@ -78,7 +78,6 @@ public InputStream getStream() throws IOException { @BeforeClass public static void setUpClass() throws Exception { ctags = new Ctags(); - ctags.setBinary(RuntimeEnvironment.getInstance().getCtags()); repository = new TestRepository(); repository.create(PascalAnalyzerFactoryTest.class.getResourceAsStream( @@ -93,7 +92,7 @@ public static void setUpClass() throws Exception { } @AfterClass - public static void tearDownClass() throws Exception { + public static void tearDownClass() { ctags.close(); ctags = null; } diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/util/CtagsUtilTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/util/CtagsUtilTest.java new file mode 100644 index 00000000000..29c76124a01 --- /dev/null +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/util/CtagsUtilTest.java @@ -0,0 +1,51 @@ +/* + * 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) 2019, Chris Fraire . + */ + +package org.opengrok.indexer.util; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.opengrok.indexer.condition.ConditionalRun; +import org.opengrok.indexer.condition.CtagsInstalled; +import org.opengrok.indexer.configuration.RuntimeEnvironment; + +import java.util.List; + +/** + * Represents a container for tests of {@link CtagsUtil}. + */ +@ConditionalRun(CtagsInstalled.class) +public class CtagsUtilTest { + + @Test + public void getLanguages() { + RuntimeEnvironment env = RuntimeEnvironment.getInstance(); + List result = CtagsUtil.getLanguages(env.getCtags()); + assertNotNull("should get Ctags languages", result); + assertTrue("Ctags languages should contains C++", result.contains("C++")); + // Test that the [disabled] tag is stripped for OldC. + assertTrue("Ctags languages should contains OldC", result.contains("OldC")); + } +}