content: /*
   * Copyright 2016 Andre Pfeiler
   *
   * This file is part of FindBugs-IDEA.
   *
   * FindBugs-IDEA is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * FindBugs-IDEA 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 General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with FindBugs-IDEA.  If not, see <http://www.gnu.org/licenses/>.
   */
  package org.twodividedbyzero.idea.findbugs.gui.preferences;
  
  import com.intellij.openapi.components.PersistentStateComponent;
  import com.intellij.openapi.components.ServiceManager;
  import com.intellij.openapi.components.State;
  import com.intellij.openapi.components.Storage;
  import com.intellij.openapi.components.StorageScheme;
  import com.intellij.openapi.diagnostic.Logger;
  import com.intellij.openapi.project.Project;
  import org.jetbrains.annotations.NotNull;
  import org.jetbrains.annotations.Nullable;
  import org.twodividedbyzero.idea.findbugs.common.FindBugsPluginConstants;
  import org.twodividedbyzero.idea.findbugs.core.ProjectSettings;
  import org.twodividedbyzero.idea.findbugs.core.WorkspaceSettings;
  import org.twodividedbyzero.idea.findbugs.preferences.PersistencePreferencesBean;
  
  /**
   * Legacy settings are converted (by {@link LegacyProjectSettingsConverter}) to {@link ProjectSettings}.
   * The settings are removed when the .ipr or config xml is stored next time.
   */
  @State(
  		name = FindBugsPluginConstants.PLUGIN_ID,
  		storages = {
  				@Storage(id = "other", file = "$PROJECT_FILE$", deprecated = true),
  				@Storage(id = "dir", file = "$PROJECT_CONFIG_DIR$/findbugs-idea.xml", scheme = StorageScheme.DIRECTORY_BASED, deprecated = true)})
  public final class LegacyProjectSettings implements PersistentStateComponent<PersistencePreferencesBean> {
  
  	private static final Logger LOGGER = Logger.getInstance(LegacyProjectSettings.class);
  
  	private PersistencePreferencesBean state;
  
  	@Nullable
  	@Override
  	public PersistencePreferencesBean getState() {
  		return state;
  	}
  
  	@Override
  	public void loadState(final PersistencePreferencesBean state) {
  		this.state = state;
  	}
  
  	public static LegacyProjectSettings getInstance(@NotNull final Project project) {
  		return ServiceManager.getService(project, LegacyProjectSettings.class);
  	}
  
  	void applyTo(@NotNull final ProjectSettings settings, @NotNull final WorkspaceSettings workspaceSettings) {
  		if (state == null) {
  			return;
  		}
  		LOGGER.info("Start convert legacy findbugs-idea project settings");
  		LegacyAbstractSettingsConverter.applyTo(state, settings, workspaceSettings, WorkspaceSettings.PROJECT_IMPORT_FILE_PATH_KEY);
  	}
  }
  