001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.api.profiles;
021
022import org.apache.commons.lang.builder.ToStringBuilder;
023import org.apache.commons.lang.builder.ToStringStyle;
024import org.sonar.api.ExtensionPoint;
025import org.sonar.api.server.ServerSide;
026import org.sonar.api.utils.ValidationMessages;
027
028import java.io.Reader;
029
030/**
031 * @since 2.3
032 */
033@ServerSide
034@ExtensionPoint
035public abstract class ProfileImporter {
036
037  private String[] supportedLanguages = new String[0];
038  private String importerKey;
039  private String importerName;
040
041  protected ProfileImporter(String key, String name) {
042    this.importerKey = key;
043    this.importerName = name;
044  }
045
046  public abstract RulesProfile importProfile(Reader reader, ValidationMessages messages);
047
048  public String getKey() {
049    return importerKey;
050  }
051
052  public final ProfileImporter setKey(String s) {
053    this.importerKey = s;
054    return this;
055  }
056
057  public final String getName() {
058    return importerName;
059  }
060
061  public final ProfileImporter setName(String s) {
062    this.importerName = s;
063    return this;
064  }
065
066  protected final ProfileImporter setSupportedLanguages(String... languages) {
067    supportedLanguages = (languages != null) ? languages : new String[0];
068    return this;
069  }
070
071  /**
072   * @return if empty, then any languages are supported.
073   */
074  public String[] getSupportedLanguages() {
075    return supportedLanguages;
076  }
077
078  @Override
079  public final boolean equals(Object o) {
080    if (this == o) {
081      return true;
082    }
083    if (o == null || getClass() != o.getClass()) {
084      return false;
085    }
086    ProfileImporter that = (ProfileImporter) o;
087    return !((importerKey != null) ? !importerKey.equals(that.importerKey) : (that.importerKey != null));
088  }
089
090  @Override
091  public final int hashCode() {
092    return (importerKey != null) ? importerKey.hashCode() : 0;
093  }
094
095  @Override
096  public String toString() {
097    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
098      .append("key", importerKey)
099      .append("name", importerName)
100      .append("languages", supportedLanguages)
101      .toString();
102  }
103}