mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-08 17:45:24 +02:00
Added support to look in jarred plugin for patterns file.
This commit is contained in:
parent
50a3f9dd3f
commit
f36c370794
3 changed files with 93 additions and 251 deletions
|
@ -13,204 +13,102 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* {Name} (company) - description of contribution.
|
* {Name} (company) - description of contribution.
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.internal.services.local.shells;
|
package org.eclipse.rse.internal.services.local.shells;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
|
||||||
import org.eclipse.core.runtime.PluginVersionIdentifier;
|
|
||||||
import org.eclipse.rse.services.local.Activator;
|
import org.eclipse.rse.services.local.Activator;
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
|
|
||||||
public class Patterns
|
public class Patterns {
|
||||||
{
|
|
||||||
|
|
||||||
private ArrayList _theCommands;
|
private ArrayList _theCommands;
|
||||||
private String _currentCommand;
|
private String _currentCommand;
|
||||||
private String _pluginsPath;
|
|
||||||
private String _version;
|
|
||||||
private long _timeStamp = 0;
|
|
||||||
private File _thePatternsFile;
|
|
||||||
private static String PATTERNS_PACKAGE = "org.eclipse.rse.services.local";
|
|
||||||
private static String PATTERNS_FILE = "patterns.dat";
|
|
||||||
|
|
||||||
public Patterns()
|
public Patterns() {
|
||||||
{
|
|
||||||
_theCommands = new ArrayList();
|
_theCommands = new ArrayList();
|
||||||
parsePatternsFile();
|
parsePatterns();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getPatternsFilePath(Bundle bundle)
|
private void parsePatterns() {
|
||||||
{
|
|
||||||
URL pluginsURL = bundle.getEntry("/");
|
|
||||||
String path = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
path = Platform.resolve(pluginsURL).getPath();
|
|
||||||
File systemsPluginDir = new File(path);
|
|
||||||
path = systemsPluginDir.getParentFile().getAbsolutePath();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPatternsFilePath()
|
|
||||||
{
|
|
||||||
if (_pluginsPath == null)
|
|
||||||
{
|
|
||||||
Bundle bundle = Activator.getDefault().getBundle();
|
Bundle bundle = Activator.getDefault().getBundle();
|
||||||
_pluginsPath = getPatternsFilePath(bundle);
|
URL patterns = bundle.getEntry("/patterns.dat");
|
||||||
String version = (String)(bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION));
|
if (patterns != null) {
|
||||||
_version = (new PluginVersionIdentifier(version)).toString();
|
try {
|
||||||
}
|
InputStream in = patterns.openStream();
|
||||||
return _pluginsPath;
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||||
}
|
|
||||||
|
|
||||||
public void refresh(String theCommand)
|
|
||||||
{
|
|
||||||
_currentCommand = theCommand;
|
|
||||||
parsePatternsFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(String theCommand)
|
|
||||||
{
|
|
||||||
_currentCommand = theCommand;
|
|
||||||
}
|
|
||||||
|
|
||||||
private File getPatternsFile()
|
|
||||||
{
|
|
||||||
if (_thePatternsFile == null)
|
|
||||||
{
|
|
||||||
String pluginDir = getPatternsFilePath();
|
|
||||||
|
|
||||||
|
|
||||||
File thePatternsFile = new File(pluginDir + "/" + PATTERNS_PACKAGE + "/" + PATTERNS_FILE);
|
|
||||||
if (!thePatternsFile.exists())
|
|
||||||
{
|
|
||||||
thePatternsFile = new File(pluginDir + "/" + PATTERNS_PACKAGE + "_" + _version + "/" + PATTERNS_FILE);
|
|
||||||
|
|
||||||
if (!thePatternsFile.exists())
|
|
||||||
{
|
|
||||||
File parentFile = new File(pluginDir);
|
|
||||||
if (parentFile.exists())
|
|
||||||
{
|
|
||||||
// now we're really desparate!
|
|
||||||
// search for a file that looks like it
|
|
||||||
File[] files = parentFile.listFiles();
|
|
||||||
for (int i = 0; i < files.length && !thePatternsFile.exists(); i++)
|
|
||||||
{
|
|
||||||
File c = files[i];
|
|
||||||
if (c.getName().startsWith(PATTERNS_PACKAGE))
|
|
||||||
{
|
|
||||||
thePatternsFile = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_thePatternsFile = thePatternsFile;
|
|
||||||
}
|
|
||||||
return _thePatternsFile;
|
|
||||||
}
|
|
||||||
private void parsePatternsFile()
|
|
||||||
{
|
|
||||||
File thePatternsFile = getPatternsFile();
|
|
||||||
|
|
||||||
long newTimeStamp = 0;
|
|
||||||
if (!thePatternsFile.exists() || ((newTimeStamp = thePatternsFile.lastModified()) == _timeStamp))
|
|
||||||
return;
|
|
||||||
|
|
||||||
_timeStamp = newTimeStamp;
|
|
||||||
|
|
||||||
//If we get here, we are actually going to read\parse the file.
|
|
||||||
BufferedReader reader = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
reader = new BufferedReader(new FileReader(thePatternsFile));
|
|
||||||
_theCommands.clear();
|
_theCommands.clear();
|
||||||
|
|
||||||
String curLine;
|
String curLine;
|
||||||
CommandPattern curCommand = null;
|
CommandPattern curCommand = null;
|
||||||
|
while ((curLine = reader.readLine()) != null) {
|
||||||
//Main Loop that reads each line.
|
|
||||||
while ((curLine = reader.readLine()) != null)
|
|
||||||
{
|
|
||||||
curLine = curLine.trim();
|
curLine = curLine.trim();
|
||||||
// Skip the current line if it is empty or starts with a #
|
// Skip the current line if it is empty or starts with a #
|
||||||
if ((curLine.length() == 0) || (curLine.charAt(0) == '#'))
|
if ((curLine.length() == 0) || (curLine.charAt(0) == '#')) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
// Check if this line is the start of a new command section
|
// Check if this line is the start of a new command section
|
||||||
if (curLine.startsWith("command"))
|
if (curLine.startsWith("command")) {
|
||||||
{
|
|
||||||
int colon = curLine.indexOf(":");
|
int colon = curLine.indexOf(":");
|
||||||
// Check that there is something after the colon
|
// Check that there is something after the colon
|
||||||
if (colon == (curLine.length() - 1))
|
if (colon == (curLine.length() - 1)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
Pattern thePattern = Pattern.compile(curLine.substring(colon + 1, curLine.length()).trim());
|
Pattern thePattern = Pattern.compile(curLine.substring(colon + 1, curLine.length()).trim());
|
||||||
curCommand = new CommandPattern(thePattern);
|
curCommand = new CommandPattern(thePattern);
|
||||||
_theCommands.add(curCommand);
|
_theCommands.add(curCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we get here, the line must be an output pattern
|
// If we get here, the line must be an output pattern
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
int firstSpace = curLine.indexOf(" ");
|
int firstSpace = curLine.indexOf(" ");
|
||||||
int patternWord = curLine.indexOf("pattern");
|
int patternWord = curLine.indexOf("pattern");
|
||||||
int firstEquals = curLine.indexOf("=");
|
int firstEquals = curLine.indexOf("=");
|
||||||
if ((firstEquals == -1) || (firstEquals == (curLine.length() - 1)))
|
if ((firstEquals == -1) || (firstEquals == (curLine.length() - 1))) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
String objType = curLine.substring(0, firstSpace);
|
String objType = curLine.substring(0, firstSpace);
|
||||||
String matchOrder = curLine.substring(firstSpace + 1, patternWord).trim();
|
String matchOrder = curLine.substring(firstSpace + 1, patternWord).trim();
|
||||||
String patternString = curLine.substring(firstEquals + 1, curLine.length());
|
String patternString = curLine.substring(firstEquals + 1, curLine.length());
|
||||||
Pattern thePattern = Pattern.compile(patternString.trim());
|
Pattern thePattern = Pattern.compile(patternString.trim());
|
||||||
|
if (curCommand != null) {
|
||||||
if (curCommand != null)
|
|
||||||
curCommand.addOutputPattern(new OutputPattern(objType, matchOrder, thePattern));
|
curCommand.addOutputPattern(new OutputPattern(objType, matchOrder, thePattern));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e)
|
in.close();
|
||||||
{
|
} catch (IOException e) {
|
||||||
System.out.println(e.getMessage());
|
Activator.getDefault().logException(e);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
System.out.println(e.getMessage());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParsedOutput matchLine(String theLine)
|
public void refresh(String theCommand) {
|
||||||
{
|
_currentCommand = theCommand;
|
||||||
|
parsePatterns();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(String theCommand) {
|
||||||
|
_currentCommand = theCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParsedOutput matchLine(String theLine) {
|
||||||
CommandPattern curCommand;
|
CommandPattern curCommand;
|
||||||
ParsedOutput matchedOutput = null;
|
ParsedOutput matchedOutput = null;
|
||||||
int commands = _theCommands.size();
|
int commands = _theCommands.size();
|
||||||
|
if (_currentCommand != null) {
|
||||||
if (_currentCommand != null)
|
for (int i = 0; i < commands; i++) {
|
||||||
{
|
|
||||||
for (int i = 0; i < commands; i++)
|
|
||||||
{
|
|
||||||
curCommand = (CommandPattern) _theCommands.get(i);
|
curCommand = (CommandPattern) _theCommands.get(i);
|
||||||
if (curCommand.matchCommand(_currentCommand))
|
if (curCommand.matchCommand(_currentCommand)) {
|
||||||
matchedOutput = curCommand.matchLine(theLine);
|
matchedOutput = curCommand.matchLine(theLine);
|
||||||
if (matchedOutput != null)
|
}
|
||||||
|
if (matchedOutput != null) {
|
||||||
return matchedOutput;
|
return matchedOutput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,6 +17,9 @@
|
||||||
package org.eclipse.rse.services.local;
|
package org.eclipse.rse.services.local;
|
||||||
|
|
||||||
import org.eclipse.ui.plugin.*;
|
import org.eclipse.ui.plugin.*;
|
||||||
|
import org.eclipse.core.runtime.ILog;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.resource.ImageDescriptor;
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
|
@ -28,6 +31,24 @@ public class Activator extends AbstractUIPlugin {
|
||||||
//The shared instance.
|
//The shared instance.
|
||||||
private static Activator plugin;
|
private static Activator plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the shared instance.
|
||||||
|
*/
|
||||||
|
public static Activator getDefault() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an image descriptor for the image file at the given
|
||||||
|
* plug-in relative path.
|
||||||
|
*
|
||||||
|
* @param path the path
|
||||||
|
* @return the image descriptor
|
||||||
|
*/
|
||||||
|
public static ImageDescriptor getImageDescriptor(String path) {
|
||||||
|
return AbstractUIPlugin.imageDescriptorFromPlugin("com.ibm.rse.services.files.local", path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor.
|
* The constructor.
|
||||||
*/
|
*/
|
||||||
|
@ -51,20 +72,13 @@ public class Activator extends AbstractUIPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the shared instance.
|
* Logs an throwable to the log for this plugin.
|
||||||
|
* @param t the Throwable to be logged.
|
||||||
*/
|
*/
|
||||||
public static Activator getDefault() {
|
public void logException(Throwable t) {
|
||||||
return plugin;
|
ILog log = getLog();
|
||||||
}
|
String id = getBundle().getSymbolicName();
|
||||||
|
IStatus status = new Status(IStatus.ERROR, id, 0, "Unexpected exception", t);
|
||||||
/**
|
log.log(status);
|
||||||
* Returns an image descriptor for the image file at the given
|
|
||||||
* plug-in relative path.
|
|
||||||
*
|
|
||||||
* @param path the path
|
|
||||||
* @return the image descriptor
|
|
||||||
*/
|
|
||||||
public static ImageDescriptor getImageDescriptor(String path) {
|
|
||||||
return AbstractUIPlugin.imageDescriptorFromPlugin("com.ibm.rse.services.files.local", path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,70 +0,0 @@
|
||||||
/********************************************************************************
|
|
||||||
* Copyright (c) 2006 IBM Corporation. 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
|
|
||||||
*
|
|
||||||
* Initial Contributors:
|
|
||||||
* The following IBM employees contributed to the Remote System Explorer
|
|
||||||
* component that contains this file: David McKnight, Kushal Munir,
|
|
||||||
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
|
||||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* {Name} (company) - description of contribution.
|
|
||||||
********************************************************************************/
|
|
||||||
|
|
||||||
package org.eclipse.rse.services.local.shells;
|
|
||||||
|
|
||||||
import org.eclipse.ui.plugin.*;
|
|
||||||
import org.eclipse.jface.resource.ImageDescriptor;
|
|
||||||
import org.osgi.framework.BundleContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The main plugin class to be used in the desktop.
|
|
||||||
*/
|
|
||||||
public class Activator extends AbstractUIPlugin {
|
|
||||||
|
|
||||||
//The shared instance.
|
|
||||||
private static Activator plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The constructor.
|
|
||||||
*/
|
|
||||||
public Activator() {
|
|
||||||
plugin = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is called upon plug-in activation
|
|
||||||
*/
|
|
||||||
public void start(BundleContext context) throws Exception {
|
|
||||||
super.start(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is called when the plug-in is stopped
|
|
||||||
*/
|
|
||||||
public void stop(BundleContext context) throws Exception {
|
|
||||||
super.stop(context);
|
|
||||||
plugin = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the shared instance.
|
|
||||||
*/
|
|
||||||
public static Activator getDefault() {
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an image descriptor for the image file at the given
|
|
||||||
* plug-in relative path.
|
|
||||||
*
|
|
||||||
* @param path the path
|
|
||||||
* @return the image descriptor
|
|
||||||
*/
|
|
||||||
public static ImageDescriptor getImageDescriptor(String path) {
|
|
||||||
return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.rse.services.shells.local", path);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue