Java Code Examples for org.eclipse.core.runtime.Plugin

The following are top voted examples for showing how to use org.eclipse.core.runtime.Plugin. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: egradle   File: EclipseResourceHelper.java   View source code 6 votes vote down vote up
public IProject createLinkedProject(String projectName, Plugin plugin, IPath linkPath) throws CoreException {
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	IProject project = workspace.getRoot().getProject(projectName);

	IProjectDescription desc = workspace.newProjectDescription(projectName);
	File file = getFileInPlugin(plugin, linkPath);
	IPath projectLocation = new Path(file.getAbsolutePath());
	if (Platform.getLocation().equals(projectLocation))
		projectLocation = null;
	desc.setLocation(projectLocation);

	project.create(desc, NULL_MONITOR);
	if (!project.isOpen())
		project.open(NULL_MONITOR);

	return project;
}
 
Example 2
Project: bts   File: ScopedPreferenceStore.java   View source code 6 votes vote down vote up
/**
 * Dispose the receiver.
 */
private void disposePreferenceStoreListener() {

	IEclipsePreferences root = (IEclipsePreferences) Platform
			.getPreferencesService().getRootNode().node(
					Plugin.PLUGIN_PREFERENCE_SCOPE);
	try {
		if (!(root.nodeExists(nodeQualifier))) {
			return;
		}
	} catch (BackingStoreException e) {
		return;// No need to report here as the node won't have the
		// listener
	}

	IEclipsePreferences preferences = getStorePreferences();
	if (preferences == null) {
		return;
	}
	if (preferencesListener != null) {
		preferences.removePreferenceChangeListener(preferencesListener);
		preferencesListener = null;
	}
}
 
Example 3
Project: bts   File: BundleClasspathUriResolver.java   View source code 6 votes vote down vote up
public URI resolve(Object context, URI classpathUri) {
    if (context instanceof Plugin) {
        context = ((Plugin) context).getBundle();
    }
    if (!(context instanceof Bundle)) {
        throw new IllegalArgumentException("Context must implement Bundle");
    }
    Bundle bundle = (Bundle) context;
    try {
        if (ClasspathUriUtil.isClasspathUri(classpathUri)) {
            URI result = findResourceInBundle(bundle, classpathUri);
	if (classpathUri.fragment() != null)
		result = result.appendFragment(classpathUri.fragment());
	return result;
        }
    } catch (Exception exc) {
        throw new ClasspathUriResolutionException(exc);
    }
    return classpathUri;
}
 
Example 4
Project: bts   File: FixedScopedPreferenceStore.java   View source code 6 votes vote down vote up
/**
 * Dispose the preference store listener.
 */
private void disposePreferenceStoreListener() {

	IEclipsePreferences root = (IEclipsePreferences) Platform
			.getPreferencesService().getRootNode().node(
					Plugin.PLUGIN_PREFERENCE_SCOPE);
	try {
		if (!(root.nodeExists(nodeQualifier))) {
			return;
		}
	} catch (BackingStoreException e) {
		return;// No need to report here as the node won't have the
		// listener
	}

	IEclipsePreferences preferences = getStorePreferences();
	if (preferences == null) {
		return;
	}
	if (preferencesListener != null) {
		preferences.removePreferenceChangeListener(preferencesListener);
		preferencesListener = null;
	}
}
 
Example 5
Project: e4-cookbook-migration-guide   File: ScopedPreferenceStore.java   View source code 6 votes vote down vote up
/**
 * Dispose the receiver.
 */
private void disposePreferenceStoreListener() {

	IEclipsePreferences root = (IEclipsePreferences) Platform
			.getPreferencesService().getRootNode().node(
					Plugin.PLUGIN_PREFERENCE_SCOPE);
	try {
		if (!(root.nodeExists(nodeQualifier))) {
			return;
		}
	} catch (BackingStoreException e) {
		return;// No need to report here as the node won't have the
		// listener
	}

	IEclipsePreferences preferences = getStorePreferences();
	if (preferences == null) {
		return;
	}
	if (preferencesListener != null) {
		preferences.removePreferenceChangeListener(preferencesListener);
		preferencesListener = null;
	}
}
 
Example 6
Project: e4-preferences   File: ScopedPreferenceStore.java   View source code 6 votes vote down vote up
/**
 * Dispose the receiver.
 */
private void disposePreferenceStoreListener() {

	IEclipsePreferences root = (IEclipsePreferences) Platform
			.getPreferencesService().getRootNode().node(
					Plugin.PLUGIN_PREFERENCE_SCOPE);
	try {
		if (!(root.nodeExists(nodeQualifier))) {
			return;
		}
	} catch (BackingStoreException e) {
		return;// No need to report here as the node won't have the
		// listener
	}

	IEclipsePreferences preferences = getStorePreferences();
	if (preferences == null) {
		return;
	}
	if (preferencesListener != null) {
		preferences.removePreferenceChangeListener(preferencesListener);
		preferencesListener = null;
	}
}
 
Example 7
Project: gwt-eclipse-plugin   File: AbstractGwtPlugin.java   View source code 6 votes vote down vote up
protected static void extractJar(
    Plugin plugin, String pathInPluginJar, String pathInStateLocation)
    throws IOException {
  IPath pluginStateLocation = plugin.getStateLocation();
  File fileInStateLocation = pluginStateLocation.append(
      pathInStateLocation).toFile();
  fileInStateLocation.delete();

  FileOutputStream os = null;
  InputStream is = FileLocator.openStream(
      plugin.getBundle(), new Path(pathInPluginJar), false);

  try {
    os = new FileOutputStream(fileInStateLocation);

    byte[] buf = new byte[2048];
    int bytesRead = 0;
    while ((bytesRead = is.read(buf)) != -1) {
      os.write(buf, 0, bytesRead);
    }
  } finally {
    closeStreams(is, os);
  }
}
 
Example 8
Project: APICloud-Studio   File: IdeLog.java   View source code 6 votes vote down vote up
/**
 * Flushes any cached logging messages
 */
public static void flushCache()
{
	caching = false;

	for (Map.Entry<Plugin, List<IStatus>> entry : earlyMessageCache.entrySet())
	{
		for (IStatus status : entry.getValue())
		{
			StatusLevel severity = getStatusLevel(status.getSeverity());
			if (status.getSeverity() == IStatus.ERROR || isOutputEnabled(entry.getKey(), severity, null))
			{
				log(entry.getKey(), status.getSeverity(), status.getMessage(), null, status.getException());
			}
		}
	}

	earlyMessageCache.clear();
}
 
Example 9
Project: APICloud-Studio   File: IdeLog.java   View source code 6 votes vote down vote up
/**
 * Are we currently outputting items of this severity and this scope? Use this method if you want to check before
 * actually composing an error message.
 * 
 * @return
 */
public static boolean isOutputEnabled(Plugin plugin, StatusLevel severity, String scope)
{
	if (!isSeverityEnabled(severity))
	{
		return false;
	}
	try
	{
		if (!Platform.inDebugMode())
		{
			return true;
		}
	}
	catch (Exception e)
	{
		// ignore. May happen if we're running unit tests outside IDE
	}

	return isScopeEnabled(scope);
}
 
Example 10
Project: APICloud-Studio   File: IdeLog.java   View source code 6 votes vote down vote up
/**
 * Constructs the message to log
 * 
 * @param plugin
 * @param severity
 * @param message
 * @param scope
 * @param th
 * @return
 */
public static String buildMessage(Plugin plugin, int severity, String message, String scope, Throwable th)
{
	if (scope == null)
	{
		scope = StringUtil.EMPTY;
	}

	String version;
	if (EclipseUtil.isStandalone())
	{
		version = EclipseUtil.getProductVersion();
	}
	else
	{
		version = EclipseUtil.getStudioVersion();
	}
	return MessageFormat.format("(Build {0}) {1} {2} {3}", //$NON-NLS-1$
			version, getLabel(severity), scope, message);
}
 
Example 11
Project: OpenSPIFe   File: TestUtil.java   View source code 6 votes vote down vote up
/**
 * Finds a URL for test data checked into a local data-test directory.
 * Should work if Run As a JUnit Test or JUnit Plugin Test,
 * as well as Bamboo.  (For Bamboo, remember to check the box for the data-test folder
 * in the plugin's build.xml editor)
 * @param yourPlugin -- use something like Activator.getDefault()
 * @param filePath -- e.g. "data-test/foo.xml" (use slash URL separator, not platform-specific File.separator).
 * @return URL (hint: call openStream)
 * @throws FileNotFoundException
 * @see SharedTestData for large data files you don't want checked out and delivered with the product
 */
public static URL findTestData(Plugin yourPlugin, String filePath) throws FileNotFoundException {
	URL url;
	try {
		if (yourPlugin==null) {
			url = new File(filePath).toURI().toURL();
		} else {
			url = FileLocator.find(yourPlugin.getBundle(),
					new Path(filePath),
					null);
		}
	} catch (IOException e) {
		throw(new FileNotFoundException(filePath + " (" + e.toString() + ")"));
	}
	if (url==null) {
		throw new FileNotFoundException("Can't find URL " + filePath);
	}
	return url;
}
 
Example 12
Project: OpenSPIFe   File: TestUtil.java   View source code 6 votes vote down vote up
/**
 * @param yourPlugin -- use something like Activator.getDefault()
 * @param directoryPath -- e.g. "data-test/" (use slash URL separator, not platform-specific File.separator).
 * @return Listing of directory as a List of URLs.
 * @throws FileNotFoundException
 * @see SharedTestData for large data files you don't want checked out and delivered with the product
 */
public static List<URL> listURLContents(Plugin yourPlugin, String directoryPath) throws FileNotFoundException {
	List<URL> toRet = new ArrayList<URL>();
	if (yourPlugin == null) {
		File dirFile = new File(directoryPath);
		for (File child : dirFile.listFiles()) {
			try {
				toRet.add(child.toURI().toURL());
			} catch (MalformedURLException e) {
				throw(new FileNotFoundException(directoryPath + " (" + e.toString() + ")"));
			}
		}
	} else {
		Bundle bundle = yourPlugin.getBundle();
		Enumeration entryPaths = bundle.getEntryPaths(directoryPath);
		while (entryPaths.hasMoreElements()) {
			String entryPath = (String) entryPaths.nextElement();
			toRet.add(bundle.getEntry(entryPath));
		}
	}
	return toRet;
}
 
Example 13
Project: e4Preferences   File: ScopedPreferenceStore.java   View source code 6 votes vote down vote up
/**
 * Dispose the receiver.
 */
private void disposePreferenceStoreListener() {

	IEclipsePreferences root = (IEclipsePreferences) Platform
			.getPreferencesService().getRootNode().node(
					Plugin.PLUGIN_PREFERENCE_SCOPE);
	try {
		if (!(root.nodeExists(nodeQualifier))) {
			return;
		}
	} catch (BackingStoreException e) {
		return;// No need to report here as the node won't have the
		// listener
	}

	IEclipsePreferences preferences = getStorePreferences();
	if (preferences == null) {
		return;
	}
	if (preferencesListener != null) {
		preferences.removePreferenceChangeListener(preferencesListener);
		preferencesListener = null;
	}
}
 
Example 14
Project: eclipse-silverstripedt   File: DefaultLanguageModelProvider.java   View source code 6 votes vote down vote up
/**
 * Gets the plugin based on the project
 * @param project Project to look for the language plugin for
 * @return Language plugin for the current project
 */
public Plugin getPlugin(IScriptProject project) {
    String ssVersion=CorePreferencesSupport.getInstance().getProjectSpecificPreferencesValue(SilverStripePreferences.SILVERSTRIPE_VERSION, SilverStripeVersion.getDefaultVersion(), project.getProject());
    
    IConfigurationElement languageProvider=SilverStripeVersion.getLanguageDefinition(ssVersion);
    if(languageProvider!=null) {
        Object o;
        try {
            o = languageProvider.createExecutableExtension("activator");
            if(o instanceof AbstractUIPlugin) {
                return (AbstractUIPlugin) o;
            }
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    
    return SilverStripePDTPlugin.getDefault();
}
 
Example 15
Project: egradle   File: EclipseResourceHelper.java   View source code 5 votes vote down vote up
public IFile createLinkedFile(IContainer container, IPath linkPath, Plugin plugin, IPath linkedFileTargetPath)
		throws CoreException {
	File file = getFileInPlugin(plugin, linkedFileTargetPath);
	IFile iFile = container.getFile(linkPath);
	iFile.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
	return iFile;
}
 
Example 16
Project: egradle   File: EclipseResourceHelper.java   View source code 5 votes vote down vote up
public IFolder createLinkedFolder(IContainer container, IPath linkPath, Plugin plugin, IPath linkedFolderTargetPath)
		throws CoreException {
	File file = getFileInPlugin(plugin, linkedFolderTargetPath);
	IFolder iFolder = container.getFolder(linkPath);
	iFolder.createLink(new Path(file.getAbsolutePath()), IResource.ALLOW_MISSING_LOCAL, NULL_MONITOR);
	return iFolder;
}
 
Example 17
Project: egradle   File: EclipseResourceHelper.java   View source code 5 votes vote down vote up
public File getFileInPlugin(Plugin plugin, IPath path) throws CoreException {
	try {
		URL installURL = plugin.getBundle().getEntry(path.toString());
		URL localURL = FileLocator.toFileURL(installURL);
		return new File(localURL.getFile());
	} catch (IOException e) {
		throw new PathException(IStatus.ERROR, path, "cannot get file in plugin", e);
	}
}
 
Example 18
Project: http4e   File: BaseUtils.java   View source code 5 votes vote down vote up
public static void writeToPrefs( String prefName, byte[] prefData){
   try {
      Plugin pl = (Plugin) CoreContext.getContext().getObject("p");
      Preferences prefs = pl.getPluginPreferences();

      String str64 = new String(Base64.encodeBase64(prefData), "UTF8");
      prefs.setValue(prefName, str64);
      pl.savePluginPreferences();

   } catch (UnsupportedEncodingException e) {
      ExceptionHandler.handle(e);
   } catch (Exception ignore) {
      ExceptionHandler.handle(ignore);
   }
}
 
Example 19
Project: http4e   File: BaseUtils.java   View source code 5 votes vote down vote up
public static byte[] readFromPrefs( String prefName){
   try {
      Plugin pl = (Plugin) CoreContext.getContext().getObject("p");
      Preferences prefs = pl.getPluginPreferences();
      String str64 = prefs.getString(prefName);
      byte[] data = Base64.decodeBase64(str64.getBytes("UTF8"));
      return data;

   } catch (UnsupportedEncodingException e) {
      ExceptionHandler.handle(e);
   } catch (Exception ignore) {
      ExceptionHandler.handle(ignore);
   }
   return null;
}
 
Example 20
Project: gwt-eclipse-plugin   File: PluginProperties.java   View source code 5 votes vote down vote up
/**
 * Create an instance by reading in the properties file associated with the
 * plugin class. If there is a failure while reading the file, then fail
 * silently and output an error message.
 * 
 * @param pluginClass the plugin class for which the associated properties
 *          should be loaded
 */
public PluginProperties(Class<? extends Plugin> pluginClass) {
  String propsPath = pluginClass.getName().replace('.', '/').concat(
      ".properties");

  props = new Properties();

  try {
    InputStream instream = pluginClass.getClassLoader().getResourceAsStream(
        propsPath);

    if (instream != null) {
      props.load(instream);
    } else {
      System.err.println("Unable to read properties from file " + propsPath
          + ". The " + pluginClass.getName()
          + " plugin may not run correctly.");
    }
  } catch (IOException iox) {
    /*
     * TODO: Once we start exposing property values through accessors off of
     * plugin classes, we'll be able to pass a proper logger. Right now, we
     * can't do this, because this code is called from static blocks in the
     * plugin classes.
     */
    System.err.println("Unable to read properties from file " + propsPath
        + ". The " + pluginClass.getName() + " plugin may not run correctly.");
    iox.printStackTrace();
  }
}
 
Example 21
Project: PDFReporter-Studio   File: PluginUtilities.java   View source code 5 votes vote down vote up
/**
 * Return the name of the given plug-in. If the plug-in does not have a name, return the unique
 * identifier for the plug-in instead.
 * 
 * @return the name of the given plug-in
 */
public static String getName(Plugin plugin) {
  String label;
  Object bundleName;
  label = null;
  bundleName = plugin.getBundle().getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME);
  if (bundleName instanceof String) {
    label = (String) bundleName;
  }
  if (label == null || label.trim().length() == 0) {
    return getId(plugin);
  }
  return label;
}
 
Example 22
Project: PDFReporter-Studio   File: PluginUtilities.java   View source code 5 votes vote down vote up
/**
 * Return the version identifier associated with the plug-in with the given identifier, or
 * <code>null</code> if there is no such plug-in.
 * 
 * @param pluginId
 *          the identifier of the plug-in
 * 
 * @return the version identifier for the specified plug-in
 */
public static Version getVersion(Plugin plugin) {
  String version;
  if (plugin == null) {
    return null;
  }
  version =
      (String) plugin.getBundle().getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
  return new Version(version);
}
 
Example 23
Project: APICloud-Studio   File: IdeLog.java   View source code 5 votes vote down vote up
/**
 * Logs an error
 * 
 * @param plugin
 * @param message
 * @param th
 */
public static void logError(Plugin plugin, String message, Throwable th, String scope)
{
	if (isErrorEnabled(plugin, scope))
	{
		log(plugin, IStatus.ERROR, message, scope, th);
	}
	else
	{
		logTrace(plugin, IStatus.ERROR, message, scope, th);
	}
}
 
Example 24
Project: APICloud-Studio   File: IdeLog.java   View source code 5 votes vote down vote up
/**
 * Logs a warning
 * 
 * @param plugin
 * @param message
 * @param th
 */
public static void logWarning(Plugin plugin, String message, Throwable th, String scope)
{
	if (isWarningEnabled(plugin, scope))
	{
		log(plugin, IStatus.WARNING, message, scope, th);
	}
	else
	{
		logTrace(plugin, IStatus.INFO, message, scope, th);
	}
}
 
Example 25
Project: APICloud-Studio   File: IdeLog.java   View source code 5 votes vote down vote up
/**
 * Logs an informational message
 * 
 * @param plugin
 * @param message
 * @param th
 */
public static void logInfo(Plugin plugin, String message, Throwable th, String scope)
{
	if (isInfoEnabled(plugin, scope))
	{
		log(plugin, IStatus.INFO, message, scope, th);
	}
	else
	{
		logTrace(plugin, IStatus.INFO, message, scope, th);
	}
}
 
Example 26
Project: APICloud-Studio   File: IdeLog.java   View source code 5 votes vote down vote up
/**
 * Trace this message out anyway if we are in debug mode
 * 
 * @param plugin
 * @param message
 * @param scope
 * @param th
 */
private static void logTrace(Plugin plugin, int severity, String message, String scope, Throwable th)
{
	if (isScopeEnabled(IDebugScopes.LOGGER))
	{
		StatusLevel newSeverity = getStatusLevel(severity);
		boolean inSeverity = isSeverityEnabled(newSeverity);

		String cause = StringUtil.EMPTY;
		if (!inSeverity)
		{
			cause = "Not logging items of current severity."; //$NON-NLS-1$
		}
		else if (!isScopeEnabled(scope))
		{
			cause = "Scope not enabled."; //$NON-NLS-1$
		}

		String traceMessage = MessageFormat.format(
				"(Build {0}) Skipping log of {1} {2} {3}. Cause: {4}", EclipseUtil.getPluginVersion(plugin), //$NON-NLS-1$
				getLabel(severity), scope, message, cause);

		if (plugin != null)
		{
			Status logStatus = new Status(severity, plugin.getBundle().getSymbolicName(), IStatus.OK, traceMessage,
					th);
			plugin.getLog().log(logStatus);
		}
		else
		{
			System.err.println(traceMessage); // CHECKSTYLE:ON
		}
	}
}
 
Example 27
Project: APICloud-Studio   File: IdeLog.java   View source code 5 votes vote down vote up
/**
 * Logs an item to the current plugin's log
 * 
 * @param plugin
 * @param status
 * @param message
 * @param th
 */
public static void log(Plugin plugin, int severity, String message, String scope, Throwable th)
{
	String tempMessage = buildMessage(plugin, severity, message, scope, th);
	String symbolicName = CorePlugin.PLUGIN_ID;
	if (plugin != null && plugin.getBundle() != null)
	{
		symbolicName = plugin.getBundle().getSymbolicName();
	}
	Status logStatus = new Status(severity, symbolicName, IStatus.OK, tempMessage, th);
	log(plugin, logStatus, scope);
}
 
Example 28
Project: APICloud-Studio   File: EclipseUtil.java   View source code 5 votes vote down vote up
/**
 * Retrieves the bundle version of a plugin.
 * 
 * @param plugin
 *            the plugin to retrieve from
 * @return the bundle version, or null if not found.
 */
public static String getPluginVersion(Plugin plugin)
{
	if (!isPluginLoaded(plugin))
	{
		return null;
	}
	return plugin.getBundle().getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION).toString(); // $codepro.audit.disable
																										// com.instantiations.assist.eclipse.analysis.unnecessaryToString
}
 
Example 29
Project: txtUML   File: Dialogs.java   View source code 5 votes vote down vote up
/**
 * Opens an {@link Dialogs}
 * @param title - The title  (if null it will be "Error")
 * @param body - The message (if null it will be e.getLocalizedMessage() )
 * @param e - A Throwable
 */
public static void errorMsgb(String title, String body, Throwable e){
	Plugin plugin = ResourcesPlugin.getPlugin();
	if(title == null){
		title = "Error";
	}
	
	if(body == null){
		body = e.getLocalizedMessage();
	}
	
	StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);

    final String trace = sw.toString(); // stack trace as a string

    // Temp holder of child statuses
    List<Status> childStatuses = new ArrayList<>();

    // Split output by OS-independend new-line
    for (String line : trace.split(System.getProperty("line.separator"))) {
        // build & add status
        childStatuses.add(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), line));
    }

    MultiStatus ms = new MultiStatus(plugin.getBundle().getSymbolicName(), IStatus.ERROR,
            childStatuses.toArray(new Status[] {}), // convert to array of statuses
            e.getLocalizedMessage(), e);
    ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, body, ms);
}
 
Example 30
Project: Eclipse-Postfix-Code-Completion   File: JavaCore.java   View source code 5 votes vote down vote up
private static ClasspathContainerInitializer computeClasspathContainerInitializer(String containerID) {
	Plugin jdtCorePlugin = JavaCore.getPlugin();
	if (jdtCorePlugin == null) return null;

	IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID, JavaModelManager.CPCONTAINER_INITIALIZER_EXTPOINT_ID);
	if (extension != null) {
		IExtension[] extensions =  extension.getExtensions();
		for(int i = 0; i < extensions.length; i++){
			IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
			for(int j = 0; j < configElements.length; j++){
				IConfigurationElement configurationElement = configElements[j];
				String initializerID = configurationElement.getAttribute("id"); //$NON-NLS-1$
				if (initializerID != null && initializerID.equals(containerID)){
					if (JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED)
						verbose_found_container_initializer(containerID, configurationElement);
					try {
						Object execExt = configurationElement.createExecutableExtension("class"); //$NON-NLS-1$
						if (execExt instanceof ClasspathContainerInitializer){
							return (ClasspathContainerInitializer)execExt;
						}
					} catch(CoreException e) {
						// executable extension could not be created: ignore this initializer
						if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
							verbose_failed_to_instanciate_container_initializer(containerID, configurationElement);
							e.printStackTrace();
						}
					}
				}
			}
		}
	}
	return null;
}
 
Example 31
Project: Eclipse-Postfix-Code-Completion   File: JavaCore.java   View source code 5 votes vote down vote up
/**
 * Returns deprecation message of a given classpath variable.
 *
 * @param variableName
 * @return A string if the classpath variable is deprecated, <code>null</code> otherwise.
 * @since 3.3
 */
public static String getClasspathVariableDeprecationMessage(String variableName) {
    JavaModelManager manager = JavaModelManager.getJavaModelManager();

	// Returns the stored deprecation message
	String message = (String) manager.deprecatedVariables.get(variableName);
	if (message != null) {
	    return message;
	}

    // If the variable has been already initialized, then there's no deprecation message
	IPath variablePath = manager.variableGet(variableName);
	if (variablePath != null && variablePath != JavaModelManager.VARIABLE_INITIALIZATION_IN_PROGRESS) {
		return null;
	}

	// Search for extension point to get the possible deprecation message
	Plugin jdtCorePlugin = JavaCore.getPlugin();
	if (jdtCorePlugin == null) return null;

	IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID, JavaModelManager.CPVARIABLE_INITIALIZER_EXTPOINT_ID);
	if (extension != null) {
		IExtension[] extensions =  extension.getExtensions();
		for(int i = 0; i < extensions.length; i++){
			IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
			for(int j = 0; j < configElements.length; j++){
				IConfigurationElement configElement = configElements[j];
				String varAttribute = configElement.getAttribute("variable"); //$NON-NLS-1$
				if (variableName.equals(varAttribute)) {
					String deprecatedAttribute = configElement.getAttribute("deprecated"); //$NON-NLS-1$
					if (deprecatedAttribute != null) {
						return deprecatedAttribute;
					}
				}
			}
		}
	}
	return null;
}
 
Example 32
Project: Eclipse-Postfix-Code-Completion-Juno38   File: JavaCore.java   View source code 5 votes vote down vote up
private static ClasspathContainerInitializer computeClasspathContainerInitializer(String containerID) {
	Plugin jdtCorePlugin = JavaCore.getPlugin();
	if (jdtCorePlugin == null) return null;

	IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID, JavaModelManager.CPCONTAINER_INITIALIZER_EXTPOINT_ID);
	if (extension != null) {
		IExtension[] extensions =  extension.getExtensions();
		for(int i = 0; i < extensions.length; i++){
			IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
			for(int j = 0; j < configElements.length; j++){
				IConfigurationElement configurationElement = configElements[j];
				String initializerID = configurationElement.getAttribute("id"); //$NON-NLS-1$
				if (initializerID != null && initializerID.equals(containerID)){
					if (JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED)
						verbose_found_container_initializer(containerID, configurationElement);
					try {
						Object execExt = configurationElement.createExecutableExtension("class"); //$NON-NLS-1$
						if (execExt instanceof ClasspathContainerInitializer){
							return (ClasspathContainerInitializer)execExt;
						}
					} catch(CoreException e) {
						// executable extension could not be created: ignore this initializer
						if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
							verbose_failed_to_instanciate_container_initializer(containerID, configurationElement);
							e.printStackTrace();
						}
					}
				}
			}
		}
	}
	return null;
}
 
Example 33
Project: Eclipse-Postfix-Code-Completion-Juno38   File: JavaCore.java   View source code 5 votes vote down vote up
/**
 * Returns deprecation message of a given classpath variable.
 *
 * @param variableName
 * @return A string if the classpath variable is deprecated, <code>null</code> otherwise.
 * @since 3.3
 */
public static String getClasspathVariableDeprecationMessage(String variableName) {
    JavaModelManager manager = JavaModelManager.getJavaModelManager();

	// Returns the stored deprecation message
	String message = (String) manager.deprecatedVariables.get(variableName);
	if (message != null) {
	    return message;
	}

    // If the variable has been already initialized, then there's no deprecation message
	IPath variablePath = manager.variableGet(variableName);
	if (variablePath != null && variablePath != JavaModelManager.VARIABLE_INITIALIZATION_IN_PROGRESS) {
		return null;
	}

	// Search for extension point to get the possible deprecation message
	Plugin jdtCorePlugin = JavaCore.getPlugin();
	if (jdtCorePlugin == null) return null;

	IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID, JavaModelManager.CPVARIABLE_INITIALIZER_EXTPOINT_ID);
	if (extension != null) {
		IExtension[] extensions =  extension.getExtensions();
		for(int i = 0; i < extensions.length; i++){
			IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
			for(int j = 0; j < configElements.length; j++){
				IConfigurationElement configElement = configElements[j];
				String varAttribute = configElement.getAttribute("variable"); //$NON-NLS-1$
				if (variableName.equals(varAttribute)) {
					String deprecatedAttribute = configElement.getAttribute("deprecated"); //$NON-NLS-1$
					if (deprecatedAttribute != null) {
						return deprecatedAttribute;
					}
				}
			}
		}
	}
	return null;
}
 
Example 34
Project: birt   File: PreferencesAdapterFactory.java   View source code 5 votes vote down vote up
public Object getAdapter( Object adaptableObject, Class adapterType )
{
	String pluginId = ( (Plugin) adaptableObject ).getBundle( )
			.getSymbolicName( );
	if ( !factoryMap.containsKey( pluginId ) )
	{
		IDEReportPreferenceFactory factory = new IDEReportPreferenceFactory( (Plugin) adaptableObject );
		factoryMap.put( pluginId, factory );
	}
	return factoryMap.get( pluginId );
}
 
Example 35
Project: logicobjects   File: EclipsePluginConfigurator.java   View source code 5 votes vote down vote up
/**
 * Prepares an Eclipse plugin to be used with LOGICOBJECTS
 * @param plugin
 */
public static void configure(Plugin plugin) {
	//enabling javassist to work correctly in Eclipse
	ClassPool classPool = ClassPool.getDefault();
	classPool.appendClassPath(new LoaderClassPath(plugin.getClass().getClassLoader()));
	LogicObjects.getDefault().getContext().getLogicObjectFactory().setClassPool(classPool);
	
	Vfs.addDefaultURLTypes(new BundleUrlType(plugin.getBundle()));  //enabling the Reflections filters to work in Eclipse
	
	String pathLogicFiles = null;
	URL urlPlugin = ClasspathHelper.forClass(plugin.getClass());
	/**
	 * adding all the classes in the plugin to the search path
	 * This line has to be after the call to Vfs.addDefaultURLTypes(...)
	 */
	LogicObjects.getDefault().getContext().addSearchUrl(urlPlugin);
	try {
		pathLogicFiles = FileLocator.toFileURL(urlPlugin).getPath();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
	/**
	 * move to the directory where the plugin is deployed
	 * This code uses the bootstrap engine since this engine will not trigger the loading of Logtalk
	 * After we have moved to the location of the plugin files we can load logtalk afterwards
	 */
	//LogicEngine.getBootstrapEngine().cd(pathLogicFiles); TODO verify that this is not needed anymore (it should work without this since all the logic files are copied to a tmp directory)
	

}
 
Example 36
Project: eclipse-optimus   File: MetadataHandler.java   View source code 5 votes vote down vote up
/**
 * Creates new handler for plugin with formatter
 * 
 * @param plugin
 * @param formatter
 * @throws IOException
 * @throws SecurityException
 */
public MetadataHandler(Plugin plugin, Formatter formatter) throws IOException, SecurityException {
	String filePath = String
			.format(FILEPATTERN, plugin.getStateLocation().toOSString(), System.currentTimeMillis());
	File file = new File(filePath);
	if (file.getParentFile() == null || !file.getParentFile().exists())
		file.getParentFile().mkdirs();

	this.delegate = new FileHandler(filePath);
	this.delegate.setFormatter(formatter);
}
 
Example 37
Project: egradle   File: EclipseResourceHelper.java   View source code 4 votes vote down vote up
public File createTempFileInPlugin(Plugin plugin, IPath path) {
	IPath stateLocation = plugin.getStateLocation();
	stateLocation = stateLocation.append(path);
	return stateLocation.toFile();
}
 
Example 38
Project: workspacemechanic   File: MechanicLog.java   View source code 4 votes vote down vote up
MechanicLog(Plugin plugin) {
  this(plugin.getLog());
}
 
Example 39
Project: andmore2   File: Activator.java   View source code 4 votes vote down vote up
public static Plugin getPlugin() {
	return plugin;
}
 
Example 40
Project: Migrate-Skeletal-Implementation-to-Interface-Refactoring   File: EvaluateMigrationOfSkeletalImplementationToInterfaceRefactoringPlugin.java   View source code 4 votes vote down vote up
public static Plugin getDefault() {
	return plugin;
}