X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPObfuscatorAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPObfuscatorAction.java index 222b3a8..1a24c29 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPObfuscatorAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPObfuscatorAction.java @@ -19,10 +19,10 @@ import net.sourceforge.phpeclipse.mover.DefaultFilter; import net.sourceforge.phpeclipse.mover.DirectoryWalker; import net.sourceforge.phpeclipse.mover.IFilter; import net.sourceforge.phpeclipse.mover.IMover; +import net.sourceforge.phpeclipse.mover.obfuscator.ObfuscatorIgnores; import net.sourceforge.phpeclipse.mover.obfuscator.PHPAnalyzer; -import net.sourceforge.phpeclipse.mover.obfuscator.PHPIdentifier; import net.sourceforge.phpeclipse.mover.obfuscator.PHPObfuscatorMover; -import net.sourceforge.phpeclipse.preferences.IObfuscatorPreferences; +import net.sourceforge.phpeclipse.preferences.ProjectProperties; import net.sourceforge.phpeclipse.views.PHPConsole; import org.eclipse.core.resources.IFile; @@ -39,54 +39,22 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; +/** + * + * @author khartlage + * + * Run the PHP Obfuscator + */ public class PHPObfuscatorAction implements IObjectActionDelegate { - private static String[] PREDEFINED_PHP_VARIABLES = - { - "$this", - "$AUTH_TYPE", - "$CONTENT_LENGTH", - "$CONTENT_TYPE", - "$GATEWAY_INTERFACE", - "$GLOBALS", - "$HTTP_ACCEPT", - "$HTTP_COOKIE", - "$HTTP_COOKIE_VARS", - "$HTTP_POST_VARS", - "$HTTP_REFERER", - "$HTTP_USER_AGENT", - "$PATH_INFO", - "$PATH_TRANSLATED", - "$PHP_AUTH_PW", - "$PHP_AUTH_USER", - "$PHP_ERRORMSG", - "$PHP_SELF", - "$QUERY_STRING", - "$REMOTE_ADDR", - "$REMOTE_HOST", - "$REMOTE_IDENT", - "$REMOTE_USER", - "$REQUEST_METHOD", - "$SCRIPT_NAME", - "$SERVER_NAME", - "$SERVER_PORT", - "$SERVER_PROTOCOL", - "$SERVER_SOFTWARE" - }; + private IWorkbenchPart workbenchPart; /** - * Constructor for Action1. + * Constructor for PHPObfuscatorAction. */ public PHPObfuscatorAction() { super(); } - /** - * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) - */ - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - workbenchPart = targetPart; - } - public void run(IAction action) { ISelectionProvider selectionProvider = null; selectionProvider = workbenchPart.getSite().getSelectionProvider(); @@ -95,7 +63,11 @@ public class PHPObfuscatorAction implements IObjectActionDelegate { selection = (StructuredSelection) selectionProvider.getSelection(); PHPConsole console = PHPConsole.getInstance(); - IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + // HashMap identifierMap = new HashMap(8096); + // for (int i=0;i<PREDEFINED_PHP_VARIABLES.length;i++) { + // identifierMap.put(PREDEFINED_PHP_VARIABLES[i], new PHPIdentifier(PREDEFINED_PHP_VARIABLES[i],PHPIdentifier.VARIABLE) ); + // } + HashMap identifierMap = null; Shell shell = null; Iterator iterator = null; @@ -106,28 +78,44 @@ public class PHPObfuscatorAction implements IObjectActionDelegate { // is it a resource if (obj instanceof IResource) { + IResource resource = (IResource) obj; IProject proj = resource.getProject(); String sourcePath; - // String publishPath = "c:\\temp"; + + if (identifierMap == null) { + IPreferenceStore store = + PHPeclipsePlugin.getDefault().getPreferenceStore(); + ObfuscatorIgnores ignore = new ObfuscatorIgnores(proj); + identifierMap = ignore.getIdentifierMap(); + } + String publishPath; try { - publishPath = proj.getPersistentProperty(IObfuscatorPreferences.PUBLISH_PROPERTY_NAME); - } catch (CoreException e) { + ProjectProperties properties = new ProjectProperties(proj); + publishPath = properties.getPublish(); + } catch (CoreException e1) { return; + // e1.printStackTrace(); } - HashMap identifierMap = new HashMap(8096); - for (int i=0;i<PREDEFINED_PHP_VARIABLES.length;i++) { - identifierMap.put(PREDEFINED_PHP_VARIABLES[i], new PHPIdentifier(PREDEFINED_PHP_VARIABLES[i],PHPIdentifier.VARIABLE) ); - } - DefaultFilter[] filter = { - IFilter.PHP_FILTER, - IFilter.DEFAULT_FILTER, - }; + // try { + // publishPath = proj.getPersistentProperty(IObfuscatorPreferences.PUBLISH_PROPERTY_NAME); + // } catch (CoreException e) { + // return; + // } + + DefaultFilter[] filter = + { IFilter.PHP_FILTER, IFilter.DEFAULT_FILTER, }; IMover[] mover = { - new PHPAnalyzer(PHPConsole.getInstance(), new Scanner(false, false), identifierMap), - new PHPObfuscatorMover(PHPConsole.getInstance(), new Scanner(true, true), identifierMap)}; + new PHPAnalyzer( + PHPConsole.getInstance(), + new Scanner(false, false), + identifierMap), + new PHPObfuscatorMover( + PHPConsole.getInstance(), + new Scanner(true, true), + identifierMap)}; DirectoryWalker walker = new DirectoryWalker(mover, filter); switch (resource.getType()) { case IResource.PROJECT : @@ -165,4 +153,11 @@ public class PHPObfuscatorAction implements IObjectActionDelegate { public void selectionChanged(IAction action, ISelection selection) { } + /** + * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + workbenchPart = targetPart; + } + }