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

org.sonar.api.platform.LocalExtension Maven / Gradle / Ivy

There is a newer version: 5.1
Show newest version
/*
 * Sonar, open source software quality management tool.
 * Copyright (C) 2009 SonarSource SA
 * mailto:contact AT sonarsource DOT com
 *
 * Sonar is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * Sonar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sonar; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 */
package org.sonar.api.platform;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.BaseIdentifiable;

import javax.persistence.*;
import java.net.URI;
import java.util.Date;

/**
 * Locally installed extension.
 *
 * @since 2.2
 */
@Entity
@Table(name = "extensions")
public class LocalExtension extends BaseIdentifiable {

  public static enum Type {
    PLUGIN, PLUGIN_EXTENSION
  }

  @Column(name = "plugin_key", updatable = true, nullable = false, length = 100)
  private String pluginKey;

  @Column(name = "version", updatable = true, nullable = true, length = 100)
  private String version;

  @Enumerated(EnumType.STRING)
  @Column(name = "extension_type", updatable = true, nullable = false)
  private Type type = Type.PLUGIN;

  @Column(name = "name", updatable = true, nullable = true, length = 100)
  private String name;

  @Column(name = "description", updatable = true, nullable = true, length = 3000)
  private String description;

  @Column(name = "organization", updatable = true, nullable = true, length = 100)
  private String organization;

  @Column(name = "organization_url", updatable = true, nullable = true, length = 500)
  private String organizationUrl;

  @Column(name = "license", updatable = true, nullable = true, length = 50)
  private String license;

  @Column(name = "filename", updatable = true, nullable = false, length = 100)
  private String filename;

  @Column(name = "installation_date", updatable = true, nullable = true)
  private Date installationDate;

  @Column(name = "plugin_class", updatable = true, nullable = true, length = 100)
  private String pluginClass;

  @Column(name = "homepage", updatable = true, nullable = true, length = 500)
  private String homepage;

  @Column(name = "core", updatable = true, nullable = true)
  private Boolean core;

  public LocalExtension() {
  }

  public LocalExtension(Type type, String pluginKey) {
    if (StringUtils.isBlank(pluginKey)) {
      throw new IllegalArgumentException("LocalExtension.pluginKey can not be blank");
    }
    if (type == null) {
      throw new IllegalArgumentException("LocalExtension.type can not be null");
    }
    this.pluginKey = pluginKey;
    this.type = type;
  }

  public String getPluginKey() {
    return pluginKey;
  }

  public LocalExtension setPluginKey(String s) {
    this.pluginKey = s;
    return this;
  }

  public Type getType() {
    return type;
  }

  public LocalExtension setType(Type type) {
    if (type == null) {
      throw new IllegalArgumentException("LocalExtension.type can not be null");
    }
    this.type = type;
    return this;
  }

  public String getFilename() {
    return filename;
  }

  public LocalExtension setFilename(String filename) {
    this.filename = filename;
    return this;
  }

  public String getName() {
    return name;
  }

  public LocalExtension setName(String name) {
    this.name = name;
    return this;
  }

  public String getDescription() {
    return description;
  }

  public LocalExtension setDescription(String description) {
    this.description = description;
    return this;
  }

  public String getOrganization() {
    return organization;
  }

  public LocalExtension setOrganization(String organization) {
    this.organization = organization;
    return this;
  }

  public String getOrganizationUrl() {
    return organizationUrl;
  }

  public LocalExtension setOrganizationUrl(URI uri) {
    this.organizationUrl = (uri != null ? uri.toString() : null);
    return this;
  }

  public LocalExtension setOrganizationUrl(String s) {
    this.organizationUrl = s;
    return this;
  }

  public String getLicense() {
    return license;
  }

  public LocalExtension setLicense(String license) {
    this.license = license;
    return this;
  }

  public String getVersion() {
    return version;
  }

  public LocalExtension setVersion(String s) {
    this.version = s;
    return this;
  }

  public Date getInstallationDate() {
    return installationDate;
  }

  public LocalExtension setInstallationDate(Date installationDate) {
    this.installationDate = installationDate;
    return this;
  }

  public String getPluginClass() {
    return pluginClass;
  }

  public LocalExtension setPluginClass(String s) {
    this.pluginClass = s;
    return this;
  }

  public String getHomepage() {
    return homepage;
  }

  public LocalExtension setHomepage(URI uri) {
    this.homepage = (uri != null ? uri.toString() : null);
    return this;
  }

  public LocalExtension setHomepage(String s) {
    this.homepage = s;
    return this;
  }

  public Boolean isCore() {
    return core;
  }

  public LocalExtension setCore(Boolean b) {
    this.core = b;
    return this;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    LocalExtension extension = (LocalExtension) o;
    if (!pluginKey.equals(extension.pluginKey)) {
      return false;
    }
    if (type != extension.type) {
      return false;
    }
    if (type == LocalExtension.Type.PLUGIN_EXTENSION) {
      return StringUtils.equals(name, extension.name);
    }
    return true;
  }

  @Override
  public int hashCode() {
    int result = pluginKey.hashCode();
    result = 31 * result + type.hashCode();
    if (type == LocalExtension.Type.PLUGIN_EXTENSION) {
      result = 31 * result + (name != null ? name.hashCode() : 0);
    }
    return result;
  }

  @Override
  public String toString() {
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
        .append("id", getId())
        .append("type", type)
        .append("pluginKey", pluginKey)
        .append("version", version)
        .append("homepage", homepage)
        .append("installationDate", installationDate)
        .toString();
  }


  public static LocalExtension createPlugin(String pluginKey) {
    return new LocalExtension(Type.PLUGIN, pluginKey);
  }

  public static LocalExtension createPluginExtension(String pluginKey, String extensionName) {
    return new LocalExtension(Type.PLUGIN_EXTENSION, pluginKey).setName(extensionName).setFilename(extensionName);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy