<commit_before>/*******************************************************************************
 * Copyright 2011 Google Inc. All Rights Reserved.
 * 
 *  All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 *  Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *******************************************************************************/
package com.google.gdt.eclipse.managedapis;

import com.google.gdt.eclipse.core.AbstractGooglePlugin;
import com.google.gdt.eclipse.core.extensions.ExtensionQuery;
import com.google.gdt.eclipse.core.extensiontypes.IManagedApiProjectStateTest;
import com.google.gdt.eclipse.core.natures.NatureUtils;
import com.google.gdt.eclipse.managedapis.directory.ApiDirectory;
import com.google.gdt.eclipse.managedapis.directory.ApiDirectoryFactory;
import com.google.gdt.eclipse.managedapis.extensiontypes.IManagedApiProjectInitializationCallback;
import com.google.gdt.eclipse.managedapis.impl.IconCache;
import com.google.gdt.eclipse.managedapis.impl.ManagedApiChecker;
import com.google.gdt.eclipse.managedapis.impl.RemoteApiDirectory;
import com.google.gdt.eclipse.managedapis.platform.PluginResources;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jdt.core.JavaCore;
import org.osgi.framework.BundleContext;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Entrypoint for the ManagedApi plugin and container of contants used by the
 * plugin as a whole.
 */
public class ManagedApiPlugin extends AbstractGooglePlugin {

  public static final boolean SINGLE_CLASSPATH_CONTAINER = false;

  public static final String DEPENDENCIES_FOLDER_NAME = "dependencies";

  public static final String PLUGIN_ID = "com.google.gdt.eclipse.managedapis";

  public static final String API_CONTAINER_PATH_ID = PLUGIN_ID
      + ".MANAGED_API_CONTAINER";

  public static final Path API_CONTAINER_PATH = new Path(API_CONTAINER_PATH_ID);

  public static final
      String COPY_CLASSPATH_ENTRIES_TARGET_PATH_KEY = "COPY_CLASSPATH_ENTRIES_TARGET_PATH";

  public static final String DEFAULT_MANAGED_API_DIRECTORY_HREF =
      "https://developers.google.com/resources/api-libraries/5935";

  public static final String STAGING_MANAGED_API_DIRECTORY_HREF =
      "https://codegen-staging.appspot.com/resources/api-libraries/5935";

  public static final
      String DEFAULT_MANAGED_API_ICON_PREFETCH_HREF = "http://api-directory.googleapis.com/icons";

  public static final String ICON_KEY_CLASSPATH_CONTAINER = "x16";

  public static final String ICON_KEY_API_IMPORT = "x32";

  public static final QualifiedName MANAGED_API_FLAG_QNAME = new QualifiedName(
      PLUGIN_ID, "PROJECT_FLAG");

  public static final String
      MANAGED_API_ROOT_FOLDER_DEFAULT_PATH = ".google_apis";
  
  public static final String SWARM_LIB_FOLDER_NAME = "endpoint-libs";

  public static final String
      MANAGED_API_ROOT_FOLDER_PATH_KEY = "MANAGED_API_ROOT_FOLDER_PATH";

  public static final QualifiedName
      MANAGED_API_SESSION_KEY_QNAME = new QualifiedName(
          PLUGIN_ID, "MANAGED_API_SESSION_KEY");
  
  // Latest in the 1.14 series
  public static final String API_CLIENT_LANG_VERSION = "1.16.x";

  public static final long API_DIRECTORY_CACHE_TTL = 4 * 60 * 60 * 1000; // 4HRS

  public static final long CHECK_MANAGED_APIS_FREQ = 2 * 60 * 60 * 1000;// 2 HRS

  public static final boolean DO_DELETES = false;

  private static ManagedApiPlugin plugin;

  private static String defaultManagedApiDirectoryInUse = DEFAULT_MANAGED_API_DIRECTORY_HREF;

  /**
   * Provide access to updated set of initialization callbacks configured for
   * this workspace.
   * 
   * @return the callbacks
   */
  public static IManagedApiProjectInitializationCallback[] findProjectInitializationCallbacks() {
    IManagedApiProjectInitializationCallback[] callbacks;
    getDefault().extensionsLock.lock();
    try {
      callbacks = getDefault().projectInitializationCallbacks;
    } finally {
      getDefault().extensionsLock.unlock();
    }
    return callbacks;
  }

  public static ManagedApiPlugin getDefault() {
    return plugin;
  }

  public static String getManagedApiDirectoryHref() {
    String overrideHref = System.getenv("MANAGED_API_DIRECTORY_HREF");
    if (overrideHref == null) {
      return defaultManagedApiDirectoryInUse;
    } else {
      return overrideHref;
    }
  }

  public static String getManagedApiIconBundleHref() {
    String overrideHref = System.getenv("MANAGED_API_ICON_PREFETCH_HREF");
    if (overrideHref == null) {
      return DEFAULT_MANAGED_API_ICON_PREFETCH_HREF;
    } else {
      return overrideHref;
    }
  }

  public static boolean isManagedApiClasspathContainer(IPath containerPath) {
    return containerPath.segment(0).equals(API_CONTAINER_PATH_ID);
  }

  public static boolean isValidToAddManagedApiProjectState(IProject project) {
    try {
      if (NatureUtils.hasNature(project, JavaCore.NATURE_ID)) {
        boolean isValid = true;
        getDefault().extensionsLock.lock();
        try {
          for (IManagedApiProjectStateTest tester :
              getDefault().managedApiProjectStateTests) {
            isValid &= tester.isValidToAddManagedApiProjectState(project);
          }
        } finally {
          getDefault().extensionsLock.unlock();
        }
        return isValid;
      }
    } catch (CoreException e) {<commit_msg>Update client library to 1.18.x. Remove unneeded/unused method. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=68708481<commit_after>/*******************************************************************************
 * Copyright 2011 Google Inc. All Rights Reserved.
 * 
 *  All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 *  Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *******************************************************************************/
package com.google.gdt.eclipse.managedapis;

import com.google.gdt.eclipse.core.AbstractGooglePlugin;
import com.google.gdt.eclipse.core.extensions.ExtensionQuery;
import com.google.gdt.eclipse.core.extensiontypes.IManagedApiProjectStateTest;
import com.google.gdt.eclipse.core.natures.NatureUtils;
import com.google.gdt.eclipse.managedapis.directory.ApiDirectory;
import com.google.gdt.eclipse.managedapis.directory.ApiDirectoryFactory;
import com.google.gdt.eclipse.managedapis.extensiontypes.IManagedApiProjectInitializationCallback;
import com.google.gdt.eclipse.managedapis.impl.IconCache;
import com.google.gdt.eclipse.managedapis.impl.ManagedApiChecker;
import com.google.gdt.eclipse.managedapis.impl.RemoteApiDirectory;
import com.google.gdt.eclipse.managedapis.platform.PluginResources;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jdt.core.JavaCore;
import org.osgi.framework.BundleContext;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Entrypoint for the ManagedApi plugin and container of contants used by the
 * plugin as a whole.
 */
public class ManagedApiPlugin extends AbstractGooglePlugin {

  public static final boolean SINGLE_CLASSPATH_CONTAINER = false;

  public static final String DEPENDENCIES_FOLDER_NAME = "dependencies";

  public static final String PLUGIN_ID = "com.google.gdt.eclipse.managedapis";

  public static final String API_CONTAINER_PATH_ID = PLUGIN_ID
      + ".MANAGED_API_CONTAINER";

  public static final Path API_CONTAINER_PATH = new Path(API_CONTAINER_PATH_ID);

  public static final
      String COPY_CLASSPATH_ENTRIES_TARGET_PATH_KEY = "COPY_CLASSPATH_ENTRIES_TARGET_PATH";

  public static final String DEFAULT_MANAGED_API_DIRECTORY_HREF =
      "https://developers.google.com/resources/api-libraries/5935";

  public static final String STAGING_MANAGED_API_DIRECTORY_HREF =
      "https://codegen-staging.appspot.com/resources/api-libraries/5935";

  public static final String ICON_KEY_CLASSPATH_CONTAINER = "x16";

  public static final String ICON_KEY_API_IMPORT = "x32";

  public static final QualifiedName MANAGED_API_FLAG_QNAME = new QualifiedName(
      PLUGIN_ID, "PROJECT_FLAG");

  public static final String
      MANAGED_API_ROOT_FOLDER_DEFAULT_PATH = ".google_apis";
  
  public static final String SWARM_LIB_FOLDER_NAME = "endpoint-libs";

  public static final String
      MANAGED_API_ROOT_FOLDER_PATH_KEY = "MANAGED_API_ROOT_FOLDER_PATH";

  public static final QualifiedName
      MANAGED_API_SESSION_KEY_QNAME = new QualifiedName(
          PLUGIN_ID, "MANAGED_API_SESSION_KEY");
  
  // Latest in the 1.18 series
  public static final String API_CLIENT_LANG_VERSION = "1.18.x";

  public static final long API_DIRECTORY_CACHE_TTL = 4 * 60 * 60 * 1000; // 4HRS

  public static final long CHECK_MANAGED_APIS_FREQ = 2 * 60 * 60 * 1000;// 2 HRS

  public static final boolean DO_DELETES = false;

  private static ManagedApiPlugin plugin;

  private static String defaultManagedApiDirectoryInUse = DEFAULT_MANAGED_API_DIRECTORY_HREF;

  /**
   * Provide access to updated set of initialization callbacks configured for
   * this workspace.
   * 
   * @return the callbacks
   */
  public static IManagedApiProjectInitializationCallback[] findProjectInitializationCallbacks() {
    IManagedApiProjectInitializationCallback[] callbacks;
    getDefault().extensionsLock.lock();
    try {
      callbacks = getDefault().projectInitializationCallbacks;
    } finally {
      getDefault().extensionsLock.unlock();
    }
    return callbacks;
  }

  public static ManagedApiPlugin getDefault() {
    return plugin;
  }

  public static String getManagedApiDirectoryHref() {
    String overrideHref = System.getenv("MANAGED_API_DIRECTORY_HREF");
    if (overrideHref == null) {
      return defaultManagedApiDirectoryInUse;
    } else {
      return overrideHref;
    }
  }

  public static boolean isManagedApiClasspathContainer(IPath containerPath) {
    return containerPath.segment(0).equals(API_CONTAINER_PATH_ID);
  }

  public static boolean isValidToAddManagedApiProjectState(IProject project) {
    try {
      if (NatureUtils.hasNature(project, JavaCore.NATURE_ID)) {
        boolean isValid = true;
        getDefault().extensionsLock.lock();
        try {
          for (IManagedApiProjectStateTest tester :
              getDefault().managedApiProjectStateTests) {
            isValid &= tester.isValidToAddManagedApiProjectState(project);
          }
        } finally {
          getDefault().extensionsLock.unlock();
        }
        return isValid;
      }
    } catch (CoreException e) {
{'fraction_non_alphanumeric': 0.10368169060591052, 'fraction_numerical': 0.00866765725606736, 'mean_word_length': 4.481900452488688, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '23406', 'n_tokens_mistral': 3626, 'n_tokens_neox': 3496, 'n_words': 803}