All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jetbrains.plugin.structure.teamcity.Validator.kt Maven / Gradle / Ivy

Go to download

Library for parsing JetBrains TeamCity plugins. Can be used to verify that plugin complies with the JetBrains Marketplace requirements.

There is a newer version: 3.291
Show newest version
/*
 * Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 */

package com.jetbrains.plugin.structure.teamcity

import com.jetbrains.plugin.structure.base.plugin.PluginProblem
import com.jetbrains.plugin.structure.base.problems.MAX_NAME_LENGTH
import com.jetbrains.plugin.structure.base.problems.PropertyNotSpecified
import com.jetbrains.plugin.structure.base.problems.validatePropertyLength
import com.jetbrains.plugin.structure.teamcity.TeamcityPluginManager.Companion.DESCRIPTOR_NAME
import com.jetbrains.plugin.structure.teamcity.beans.TeamcityPluginBean
import com.jetbrains.plugin.structure.teamcity.problems.ForbiddenWordInPluginName

internal fun validateTeamcityPluginBean(bean: TeamcityPluginBean): List {
  val problems = arrayListOf()

  if (bean.info?.name.isNullOrBlank()) {
    problems.add(PropertyNotSpecified("name"))
  }

  val beanDisplayName = bean.info?.displayName
  if (beanDisplayName == null || beanDisplayName.isBlank()) {
    problems.add(PropertyNotSpecified("display-name"))
  } else {
    val hasForbiddenWords = ForbiddenWordInPluginName.forbiddenWords.any { beanDisplayName.contains(it, ignoreCase = true) }
    if (hasForbiddenWords) {
      problems.add(ForbiddenWordInPluginName)
    }
  }
  val name = bean.info?.name
  if (name != null) {
    validatePropertyLength(DESCRIPTOR_NAME, "name", name, MAX_NAME_LENGTH, problems)
  }
  if (beanDisplayName != null) {
    validatePropertyLength(DESCRIPTOR_NAME, "display-name", beanDisplayName, MAX_NAME_LENGTH, problems)
  }

  if (bean.info?.version.isNullOrBlank()) {
    problems.add(PropertyNotSpecified("version"))
  }
  if (bean.info?.description.isNullOrBlank()) {
    problems.add(PropertyNotSpecified("description"))
  }
  if (bean.info?.vendor?.name.isNullOrBlank()) {
    problems.add(PropertyNotSpecified("vendor name"))
  }
  if (bean.info?.vendor?.url.isNullOrBlank()) {
    problems.add(PropertyNotSpecified("vendor url"))
  }
  return problems
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy