Exemplo n.º 1
0
  /** {@inheritDoc} */
  public boolean accept(Object element) {
    boolean passes = true;

    if (element instanceof IFile) {

      IFile file = (IFile) element;
      IProject project = file.getProject();

      if (RepositoryProvider.isShared(project)) {

        RepositoryProvider provider = RepositoryProvider.getProvider(project);

        if (provider != null) {

          Subscriber subscriber = provider.getSubscriber();

          if (subscriber != null) {

            try {
              SyncInfo synchInfo = subscriber.getSyncInfo(file);

              if (synchInfo != null) {
                int kind = synchInfo.getKind();
                passes = (SyncInfo.getDirection(kind) & SyncInfo.OUTGOING) == SyncInfo.OUTGOING;
              }
            } catch (TeamException e) {
              CheckstyleLog.log(e);
            }
          }
        }
      }
    }
    return passes;
  }
  /** Refreshes the check configurations from the persistent store. */
  public static void refresh() {
    try {
      sConfigurations.clear();
      loadBuiltinConfigurations();
      loadFromPersistence();

    } catch (CheckstylePluginException e) {
      CheckstyleLog.log(e);
    }
  }
  /** Load the check configurations from the persistent state storage. */
  private static void loadFromPersistence() throws CheckstylePluginException {

    InputStream inStream = null;

    try {

      IPath configPath = CheckstylePlugin.getDefault().getStateLocation();
      configPath = configPath.append(CHECKSTYLE_CONFIG_FILE);
      File configFile = configPath.toFile();

      //
      // Make sure the files exists, it might not.
      //
      if (!configFile.exists()) {
        return;
      } else {
        inStream = new BufferedInputStream(new FileInputStream(configFile));
      }

      SAXReader reader = new SAXReader();
      Document document = reader.read(inStream);

      Element root = document.getRootElement();

      String version = root.attributeValue(XMLTags.VERSION_TAG);
      if (!CURRENT_CONFIG_FILE_FORMAT_VERSION.equals(version)) {

        // the old (pre 4.0.0) configuration files aren't supported
        // anymore
        CheckstyleLog.log(
            null, "eclipse-cs version 3.x type configuration files are not supported anymore.");
        return;
      }

      String defaultConfigName = root.attributeValue(XMLTags.DEFAULT_CHECK_CONFIG_TAG);

      sConfigurations.addAll(getGlobalCheckConfigurations(root));

      for (ICheckConfiguration config : sConfigurations) {
        if (config.getName().equals(defaultConfigName)) {
          sDefaultCheckConfig = config;
        }
      }
    } catch (IOException e) {
      CheckstylePluginException.rethrow(e, Messages.errorLoadingConfigFile);
    } catch (DocumentException e) {
      CheckstylePluginException.rethrow(e, Messages.errorLoadingConfigFile);
    } finally {
      IOUtils.closeQuietly(inStream);
    }
  }
  private void handleConfigFileError(Exception e, IProject project) {

    CheckstyleLog.log(e, Messages.errorOpeningPropertiesPage);
    CheckstyleUIPlugin.warningDialog(null, Messages.errorOpeningPropertiesPage, e);

    IProjectConfiguration projectConfig =
        ProjectConfigurationFactory.createDefaultProjectConfiguration(project);
    mProjectConfig = new ProjectConfigurationWorkingCopy(projectConfig);
    try {
      mCheckstyleInitiallyActivated = project.hasNature(CheckstyleNature.NATURE_ID);
    } catch (CoreException e1) {
      CheckstyleUIPlugin.errorDialog(null, e1.getMessage(), e1, true);
    }
  }
Exemplo n.º 5
0
  /** {@inheritDoc} */
  @Override
  public void initializeDefaultPreferences() {

    IEclipsePreferences prefs = new DefaultScope().getNode(CheckstylePlugin.PLUGIN_ID);
    prefs.putBoolean(PREF_INCLUDE_RULE_NAMES, false);
    prefs.putBoolean(PREF_INCLUDE_MODULE_IDS, false);
    prefs.putBoolean(PREF_LIMIT_MARKERS_PER_RESOURCE, false);
    prefs.putInt(PREF_MARKER_AMOUNT_LIMIT, MARKER_LIMIT);

    try {
      prefs.flush();
    } catch (BackingStoreException e) {
      CheckstyleLog.log(e);
    }
  }
  /** {@inheritDoc} */
  public boolean isConfigurable(ICheckConfiguration checkConfiguration) {
    boolean isConfigurable = true;

    boolean isProtected =
        Boolean.valueOf(checkConfiguration.getAdditionalData().get(KEY_PROTECT_CONFIG))
            .booleanValue();
    isConfigurable = !isProtected;

    if (!isProtected) {

      // The configuration can be changed when the external configuration
      // file can is writable
      try {
        isConfigurable =
            FileUtils.toFile(checkConfiguration.getResolvedConfigurationFileURL()).canWrite();
      } catch (CheckstylePluginException e) {
        CheckstyleLog.log(e);
        isConfigurable = false;
      }
    }
    return isConfigurable;
  }