<commit_before>/*
 * Copyright 2001-2012 <NAME>
 *
 * 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.
 */

package woko.tooling.cli

import woko.tooling.utils.Logger
import woko.Woko
import woko.WokoInitListener
import net.sourceforge.jfacets.IFacetDescriptorManager
import woko.tooling.utils.PomHelper
import org.apache.maven.model.Dependency
import woko.tooling.utils.AppUtils

abstract class Command {

    final String name
    final String shortDesc
    final String argSpec
    final String longHelp
    final Logger logger
    final File projectDir
    final Runner runner

    private def webXmlSlurped
    private PomHelper pomHelper

    Command(Runner runner, String name, String shortDesc, String argSpec, String longHelp) {
        this.projectDir = runner.workingDir
        this.logger = runner.logger
        this.name = name
        this.shortDesc = shortDesc
        this.argSpec = argSpec
        this.longHelp = longHelp
        this.runner = runner
    }

    protected String getArgAt(List<String> args, int i) {
        if (i>args.size()) {
            return null
        }
        if (i<0) {
            return null
        }
        return args[i]
    }

    protected def getWebXml() {
        if (!webXmlSlurped) {
            String pathToWebXml = "$projectDir.absolutePath/src/main/webapp/WEB-INF/web.xml"
            File webXmlFile = new File(pathToWebXml)
            if (!webXmlFile) {
                logger.error("Unable to locate the web.xml in your project ! Should be in $pathToWebXml")
                return null
            }
            webXmlSlurped = new XmlSlurper().parse(webXmlFile)
        }
        return webXmlSlurped
    }

    protected List<String> computeFacetPackages() {
        def packages = computeUserFacetPackages()
        packages.addAll(Woko.DEFAULT_FACET_PACKAGES);
        return packages
    }<commit_msg>fix NPE in tooling when no facet packages are provided in web.xml<commit_after>/*
 * Copyright 2001-2012 <NAME>
 *
 * 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.
 */

package woko.tooling.cli

import woko.tooling.utils.Logger
import woko.Woko
import woko.WokoInitListener
import net.sourceforge.jfacets.IFacetDescriptorManager
import woko.tooling.utils.PomHelper
import org.apache.maven.model.Dependency
import woko.tooling.utils.AppUtils

abstract class Command {

    final String name
    final String shortDesc
    final String argSpec
    final String longHelp
    final Logger logger
    final File projectDir
    final Runner runner

    private def webXmlSlurped
    private PomHelper pomHelper

    Command(Runner runner, String name, String shortDesc, String argSpec, String longHelp) {
        this.projectDir = runner.workingDir
        this.logger = runner.logger
        this.name = name
        this.shortDesc = shortDesc
        this.argSpec = argSpec
        this.longHelp = longHelp
        this.runner = runner
    }

    protected String getArgAt(List<String> args, int i) {
        if (i>args.size()) {
            return null
        }
        if (i<0) {
            return null
        }
        return args[i]
    }

    protected def getWebXml() {
        if (!webXmlSlurped) {
            String pathToWebXml = "$projectDir.absolutePath/src/main/webapp/WEB-INF/web.xml"
            File webXmlFile = new File(pathToWebXml)
            if (!webXmlFile) {
                logger.error("Unable to locate the web.xml in your project ! Should be in $pathToWebXml")
                return null
            }
            webXmlSlurped = new XmlSlurper().parse(webXmlFile)
        }
        return webXmlSlurped
    }

    protected List<String> computeFacetPackages() {
        def packages = computeUserFacetPackages()
        if (packages) {
            packages.addAll(Woko.DEFAULT_FACET_PACKAGES);
        } else {
            packages = Woko.DEFAULT_FACET_PACKAGES
        }
        return packages
    }
{'fraction_non_alphanumeric': 0.07137047580317202, 'fraction_numerical': 0.005286701911346075, 'mean_word_length': 2.5185979971387695, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '369875', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1334, 'n_words': 436}