1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
8 Klaus Hartlage - www.eclipseproject.de
9 **********************************************************************/
10 package net.sourceforge.phpeclipse.actions;
12 import java.io.IOException;
13 import java.util.HashMap;
14 import java.util.Iterator;
16 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18 import net.sourceforge.phpeclipse.mover.DefaultFilter;
19 import net.sourceforge.phpeclipse.mover.DirectoryWalker;
20 import net.sourceforge.phpeclipse.mover.IFilter;
21 import net.sourceforge.phpeclipse.mover.IMover;
22 import net.sourceforge.phpeclipse.mover.obfuscator.ObfuscatorIgnores;
23 import net.sourceforge.phpeclipse.mover.obfuscator.PHPAnalyzer;
24 import net.sourceforge.phpeclipse.mover.obfuscator.PHPObfuscatorMover;
25 import net.sourceforge.phpeclipse.preferences.ProjectProperties;
26 import net.sourceforge.phpeclipse.views.PHPConsole;
28 import org.eclipse.core.resources.IFile;
29 import org.eclipse.core.resources.IFolder;
30 import org.eclipse.core.resources.IProject;
31 import org.eclipse.core.resources.IResource;
32 import org.eclipse.core.runtime.CoreException;
33 import org.eclipse.jface.action.IAction;
34 import org.eclipse.jface.preference.IPreferenceStore;
35 import org.eclipse.jface.viewers.ISelection;
36 import org.eclipse.jface.viewers.ISelectionProvider;
37 import org.eclipse.jface.viewers.StructuredSelection;
38 import org.eclipse.swt.widgets.Shell;
39 import org.eclipse.ui.IObjectActionDelegate;
40 import org.eclipse.ui.IWorkbenchPart;
46 * Run the PHP Obfuscator
48 public class PHPObfuscatorAction implements IObjectActionDelegate {
50 private IWorkbenchPart workbenchPart;
52 * Constructor for PHPObfuscatorAction.
54 public PHPObfuscatorAction() {
58 public void run(IAction action) {
59 ISelectionProvider selectionProvider = null;
60 selectionProvider = workbenchPart.getSite().getSelectionProvider();
62 StructuredSelection selection = null;
63 selection = (StructuredSelection) selectionProvider.getSelection();
64 PHPConsole console = PHPConsole.getInstance();
66 // HashMap identifierMap = new HashMap(8096);
67 // for (int i=0;i<PREDEFINED_PHP_VARIABLES.length;i++) {
68 // identifierMap.put(PREDEFINED_PHP_VARIABLES[i], new PHPIdentifier(PREDEFINED_PHP_VARIABLES[i],PHPIdentifier.VARIABLE) );
70 HashMap identifierMap = null;
73 Iterator iterator = null;
74 iterator = selection.iterator();
75 while (iterator.hasNext()) {
76 // obj => selected object in the view
77 Object obj = iterator.next();
80 if (obj instanceof IResource) {
82 IResource resource = (IResource) obj;
83 IProject proj = resource.getProject();
86 if (identifierMap == null) {
87 IPreferenceStore store =
88 PHPeclipsePlugin.getDefault().getPreferenceStore();
89 ObfuscatorIgnores ignore = new ObfuscatorIgnores(proj);
90 identifierMap = ignore.getIdentifierMap();
95 ProjectProperties properties = new ProjectProperties(proj);
96 publishPath = properties.getPublish();
97 } catch (CoreException e1) {
99 // e1.printStackTrace();
102 // publishPath = proj.getPersistentProperty(IObfuscatorPreferences.PUBLISH_PROPERTY_NAME);
103 // } catch (CoreException e) {
107 DefaultFilter[] filter =
108 { IFilter.PHP_FILTER, IFilter.DEFAULT_FILTER, };
112 PHPConsole.getInstance(),
113 new Scanner(false, false),
115 new PHPObfuscatorMover(
116 PHPConsole.getInstance(),
117 new Scanner(true, true),
119 DirectoryWalker walker = new DirectoryWalker(mover, filter);
120 switch (resource.getType()) {
121 case IResource.PROJECT :
122 IProject project = (IProject) resource;
123 sourcePath = project.getLocation().toOSString();
125 walker.walk(sourcePath, publishPath);
126 } catch (IOException e) {
129 case IResource.FOLDER :
130 IFolder folder = (IFolder) resource;
131 sourcePath = folder.getLocation().toOSString();
133 walker.walk(sourcePath, publishPath);
134 } catch (IOException e) {
137 case IResource.FILE :
139 IFile file = (IFile) resource;
140 sourcePath = file.getLocation().toOSString();
142 walker.walk(sourcePath, publishPath);
143 } catch (IOException e) {
151 * @see IActionDelegate#selectionChanged(IAction, ISelection)
153 public void selectionChanged(IAction action, ISelection selection) {
157 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
159 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
160 workbenchPart = targetPart;