// Path: src/com/jetbrains/crucible/configuration/CrucibleSettings.java
// @State(name = "CrucibleSettings",
//        storages = {
//          @Storage(file = "$APP_CONFIG$" + "/crucibleConnector.xml")
//        }
// )
// public class CrucibleSettings implements PersistentStateComponent<CrucibleSettings> {
//   public String SERVER_URL = "";
//   public String USERNAME = "";
// 
//   @Override
//   public CrucibleSettings getState() {
//     return this;
//   }
// 
//   @Override
//   public void loadState(CrucibleSettings state) {
//     XmlSerializerUtil.copyBean(state, this);
//   }
// 
//   public static CrucibleSettings getInstance() {
//     return ServiceManager.getService(CrucibleSettings.class);
//   }
// 
//   public static final String CRUCIBLE_SETTINGS_PASSWORD_KEY = "CRUCIBLE_SETTINGS_PASSWORD_KEY";
//   private static final Logger LOG = Logger.getInstance(CrucibleConfigurable.class.getName());
// 
//   public void savePassword(String pass) {
//     PasswordSafe.getInstance().set(new CredentialAttributes(CRUCIBLE_SETTINGS_PASSWORD_KEY), new Credentials(USERNAME, pass));
//   }
// 
//   @Nullable
//   public String getPassword() {
//     final Credentials credentials = PasswordSafe.getInstance().get(new CredentialAttributes(CRUCIBLE_SETTINGS_PASSWORD_KEY));
// 
//     return credentials != null ? credentials.getPasswordAsString() : null;
//   }
// }
// 
// Path: src/com/jetbrains/crucible/connection/exceptions/CrucibleApiException.java
// public class CrucibleApiException extends Exception {
// 
//   public CrucibleApiException(String message) {
//     super(message);
//   }
// 
//   public CrucibleApiException(String message, Throwable throwable) {
//     super(message, throwable);
//   }
// }


import com.intellij.openapi.project.Project;
import com.jetbrains.crucible.configuration.CrucibleSettings;
import com.jetbrains.crucible.connection.exceptions.CrucibleApiException;
import org.jetbrains.annotations.Nullable;
import java.net.MalformedURLException;
import java.net.URL;
  public ConnectionState getConnectionState() {
    return myConnectionState;
  }

  public void run() {
    try {
      testConnect();
      if (myConnectionState != ConnectionState.INTERRUPTED && myConnectionState != ConnectionState.FAILED) {
        myConnectionState = ConnectionState.SUCCEEDED;
      }
    }
    catch (CrucibleApiException e) {
      if (myConnectionState != ConnectionState.INTERRUPTED) {
        myConnectionState = ConnectionState.FAILED;
        myException = e;
      }
    }
  }

  public void setInterrupted() {
    myConnectionState = ConnectionState.INTERRUPTED;
  }

  @Nullable
  public String getErrorMessage() {
    return myException == null ? null : myException.getMessage();
  }

  public void testConnect() throws CrucibleApiException {
    final CrucibleSession session = new CrucibleSessionImpl(myProject);
// Path: src/com/jetbrains/crucible/configuration/CrucibleSettings.java
// @State(name = "CrucibleSettings",
//        storages = {
//          @Storage(file = "$APP_CONFIG$" + "/crucibleConnector.xml")
//        }
// )
// public class CrucibleSettings implements PersistentStateComponent<CrucibleSettings> {
//   public String SERVER_URL = "";
//   public String USERNAME = "";
// 
//   @Override
//   public CrucibleSettings getState() {
//     return this;
//   }
// 
//   @Override
//   public void loadState(CrucibleSettings state) {
//     XmlSerializerUtil.copyBean(state, this);
//   }
// 
//   public static CrucibleSettings getInstance() {
//     return ServiceManager.getService(CrucibleSettings.class);
//   }
// 
//   public static final String CRUCIBLE_SETTINGS_PASSWORD_KEY = "CRUCIBLE_SETTINGS_PASSWORD_KEY";
//   private static final Logger LOG = Logger.getInstance(CrucibleConfigurable.class.getName());
// 
//   public void savePassword(String pass) {
//     PasswordSafe.getInstance().set(new CredentialAttributes(CRUCIBLE_SETTINGS_PASSWORD_KEY), new Credentials(USERNAME, pass));
//   }
// 
//   @Nullable
//   public String getPassword() {
//     final Credentials credentials = PasswordSafe.getInstance().get(new CredentialAttributes(CRUCIBLE_SETTINGS_PASSWORD_KEY));
// 
//     return credentials != null ? credentials.getPasswordAsString() : null;
//   }
// }
// 
// Path: src/com/jetbrains/crucible/connection/exceptions/CrucibleApiException.java
// public class CrucibleApiException extends Exception {
// 
//   public CrucibleApiException(String message) {
//     super(message);
//   }
// 
//   public CrucibleApiException(String message, Throwable throwable) {
//     super(message, throwable);
//   }
// }


// Path: src/com/jetbrains/crucible/connection/CrucibleTestConnector.java
import com.intellij.openapi.project.Project;
import com.jetbrains.crucible.configuration.CrucibleSettings;
import com.jetbrains.crucible.connection.exceptions.CrucibleApiException;
import org.jetbrains.annotations.Nullable;
import java.net.MalformedURLException;
import java.net.URL;

  public ConnectionState getConnectionState() {
    return myConnectionState;
  }

  public void run() {
    try {
      testConnect();
      if (myConnectionState != ConnectionState.INTERRUPTED && myConnectionState != ConnectionState.FAILED) {
        myConnectionState = ConnectionState.SUCCEEDED;
      }
    }
    catch (CrucibleApiException e) {
      if (myConnectionState != ConnectionState.INTERRUPTED) {
        myConnectionState = ConnectionState.FAILED;
        myException = e;
      }
    }
  }

  public void setInterrupted() {
    myConnectionState = ConnectionState.INTERRUPTED;
  }

  @Nullable
  public String getErrorMessage() {
    return myException == null ? null : myException.getMessage();
  }

  public void testConnect() throws CrucibleApiException {
    final CrucibleSession session = new CrucibleSessionImpl(myProject);
    final String url = CrucibleSettings.getInstance().SERVER_URL;