which included commits to RCS files with non-trunk default branches.
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry exported="true" kind="src" path="/net.sourceforge.phpeclipse"/>
+ <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>
+ <classpathentry kind="lib"
+ path="C:/eclipse/plugins/org.eclipse.debug.core_2.0.0/dtcore.jar"
+ rootpath="" sourcepath="C:/eclipse/plugins/org.eclipse.platform.source_2.0.0/src/org.eclipse.debug.core_2.0.0/dtcoresrc.zip"/>
+ <classpathentry kind="lib" path="C:/eclipse/plugins/org.junit_3.7.0/junit.jar"/>
+ <classpathentry kind="lib" path="C:/eclipse/plugins/org.apache.xerces_4.0.3/xmlParserAPIs.jar"/>
+ <classpathentry kind="lib" path="C:/eclipse/plugins/org.apache.xerces_4.0.3/xercesImpl.jar"/>
+ <classpathentry kind="lib" path="C:/eclipse/plugins/org.eclipse.core.boot_2.0.0/boot.jar"/>
+ <classpathentry kind="lib" path="C:/eclipse/plugins/org.eclipse.core.resources_2.0.0/resources.jar"/>
+ <classpathentry kind="lib" path="C:/eclipse/plugins/org.eclipse.core.runtime_2.0.0/runtime.jar"/>
+ <classpathentry kind="lib"
+ path="C:/eclipse/plugins/org.eclipse.ui_2.0.0/workbench.jar" sourcepath="C:/eclipse/plugins/org.eclipse.platform.source_2.0.0/src/org.eclipse.ui_2.0.0/workbenchsrc.zip"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>net.sourceforge.phpeclipse.launching</name>
+ <comment></comment>
+ <projects>
+ <project>net.sourceforge.phpeclipse</project>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<form>
+ <p/><p><b>Tips on working with this plug-in project</b></p><li>For the view of the new plug-in at a glance, go to the <img href="pageImage"/><a href="OverviewPage">Overview</a>.</li><li>You can test the contributions of this plug-in by launching another instance of the workbench. On the <b>Run</b> menu, click <b>Run As</b> and choose <img href="runTimeWorkbenchImage"/><a href="action.run">Run-time Workbench</a> from the available choices.</li><li>You can add more functionality to this plug-in by adding extensions using the <a href="action.newExtension">New Extension Wizard</a>.</li><li>The plug-in project contains Java code that you can debug. Place breakpoints in Java classes. On the <b>Run</b> menu, select <b>Debug As</b> and choose <img href="runTimeWorkbenchImage"/><a href="action.debug">Run-time Workbench</a> from the available choices.</li>
+</form>
--- /dev/null
+source.launch.jar = src/
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="net.sourceforge.phpeclipse.launching" default="build.jars" basedir=".">
+
+ <property name="bootclasspath" value=""/>
+ <property name="ws" value="win32"/>
+ <property name="os" value="win32"/>
+ <property name="arch" value="x86"/>
+
+ <target name="init" depends="properties">
+ <property name="plugin" value="net.sourceforge.phpeclipse.launching"/>
+ <property name="version.suffix" value="_1.0.3"/>
+ <property name="full.name" value="${plugin}${version.suffix}"/>
+ <property name="temp.folder" value="${basedir}/temp.folder"/>
+ <property name="plugin.destination" value="${basedir}"/>
+ <property name="build.result.folder" value="${basedir}"/>
+ </target>
+
+ <target name="properties" if="eclipse.running">
+ <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
+ </target>
+
+ <target name="build.update.jar" depends="init">
+ <delete dir="${temp.folder}"/>
+ <mkdir dir="${temp.folder}"/>
+ <antcall target="build.jars"/>
+ <antcall target="gather.bin.parts">
+ <param name="destination.temp.folder" value="${temp.folder}/"/>
+ </antcall>
+ <zip zipfile="${plugin.destination}/${full.name}.jar" basedir="${temp.folder}/${full.name}" filesonly="false"/>
+ <delete dir="${temp.folder}"/>
+ </target>
+
+ <target name="gather.bin.parts" depends="init" if="destination.temp.folder">
+ <mkdir dir="${destination.temp.folder}/${full.name}"/>
+ <copy file="${build.result.folder}/launch.jar" todir="${destination.temp.folder}/${full.name}"/>
+ </target>
+
+ <target name="launch.jar" depends="init" unless="launch.jar">
+ <property name="destdir" value="${temp.folder}/launch.jar.bin"/>
+ <delete dir="${temp.folder}/launch.jar.bin"/>
+ <mkdir dir="${temp.folder}/launch.jar.bin"/>
+ <!-- compile the source code -->
+ <javac destdir="${temp.folder}/launch.jar.bin" failonerror="false" verbose="true" debug="on" includeAntRuntime="no" bootclasspath="${bootclasspath}" classpath="../../plugins/org.eclipse.core.resources.win32_2.0.0/resources.jar;../../plugins/org.apache.xerces_4.0.3/xmlParserAPIs.jar;../net.sourceforge.phpeclipse/phpeclipse.jar;../../plugins/org.eclipse.debug.core_2.0.0/dtcore.jar;../../plugins/org.eclipse.swt_2.0.0/ws/${ws}/swt.jar;../../plugins/org.apache.xerces_4.0.3/xercesImpl.jar;../../plugins/org.junit_3.7.0/bin;../../plugins/org.eclipse.core.boot_2.0.0/bin;../../plugins/org.eclipse.core.runtime_2.0.0/runtime.jar;../../plugins/org.eclipse.core.boot_2.0.0/boot.jar;../../plugins/org.eclipse.ui.win32_2.0.0/workbench.jar;../net.sourceforge.phpeclipse/bin;../../plugins/org.apache.xerces_4.0.3/bin;../../plugins/org.eclipse.debug.core_2.0.0/bin;../../plugins/org.eclipse.swt_2.0.0/bin;../../plugins/org.eclipse.core.resources_2.0.0/bin;../../plugins/org.eclipse.core.resources_2.0.0/resources.jar;../../plugins/org.eclipse.swt.win32_2.0.0/ws/${ws}/swt.jar;../../plugins/org.eclipse.ui_2.0.0/workbench.jar;../../plugins/org.eclipse.core.runtime_2.0.0/bin;../../plugins/org.junit_3.7.0/junit.jar;../../plugins/org.eclipse.ui_2.0.0/bin;../../plugins/org.eclipse.ui.win32_2.0.0/workbenchwin32.jar">
+ <src path="src/"/>
+ </javac>
+ <!-- copy necessary resources -->
+ <copy todir="${temp.folder}/launch.jar.bin">
+ <fileset dir="src/" excludes="**/*.java"/>
+ </copy>
+ <mkdir dir="${build.result.folder}"/>
+ <jar jarfile="${build.result.folder}/launch.jar" basedir="${temp.folder}/launch.jar.bin"/>
+ <delete dir="${temp.folder}/launch.jar.bin"/>
+ </target>
+
+ <target name="launchsrc.zip" depends="init" unless="launchsrc.zip">
+ <mkdir dir="${build.result.folder}"/>
+ <zip zipfile="${build.result.folder}/launchsrc.zip" filesonly="false">
+ <fileset dir="src/" includes="**/*.java"/>
+ </zip>
+ </target>
+
+ <target name="build.jars" depends="init">
+ <available property="launch.jar" file="${build.result.folder}/launch.jar"/>
+ <antcall target="launch.jar"/>
+ </target>
+
+ <target name="build.sources" depends="init">
+ <available property="launchsrc.zip" file="${build.result.folder}/launchsrc.zip"/>
+ <antcall target="launchsrc.zip"/>
+ </target>
+
+ <target name="build.zips" depends="init">
+ </target>
+
+ <target name="gather.sources" depends="init" if="destination.temp.folder">
+ <mkdir dir="${destination.temp.folder}/${full.name}"/>
+ <copy file="${build.result.folder}/launchsrc.zip" todir="${destination.temp.folder}/${full.name}"/>
+ </target>
+
+ <target name="gather.logs" depends="init" if="destination.temp.folder">
+ <mkdir dir="${destination.temp.folder}/${full.name}"/>
+ <copy file="${temp.folder}/launch.jar.bin.log" todir="${destination.temp.folder}/${full.name}"/>
+ </target>
+
+ <target name="clean" depends="init">
+ <delete file="${build.result.folder}/launch.jar"/>
+ <delete file="${build.result.folder}/launchsrc.zip"/>
+ <delete file="${plugin.destination}/${full.name}.jar"/>
+ <delete file="${plugin.destination}/${full.name}.zip"/>
+ <delete dir="${temp.folder}"/>
+ </target>
+
+ <target name="refresh" depends="init" if="eclipse.running">
+ <eclipse.refreshLocal resource="${plugin}" depth="infinite"/>
+ </target>
+
+ <target name="zip.plugin" depends="init">
+ <delete dir="${temp.folder}"/>
+ <mkdir dir="${temp.folder}"/>
+ <antcall target="build.jars"/>
+ <antcall target="build.sources"/>
+ <antcall target="gather.bin.parts">
+ <param name="destination.temp.folder" value="${temp.folder}/"/>
+ </antcall>
+ <antcall target="gather.sources">
+ <param name="destination.temp.folder" value="${temp.folder}/"/>
+ </antcall>
+ <delete>
+ <fileset dir="${temp.folder}" includes="**/*.bin.log"/>
+ </delete>
+ <zip zipfile="${plugin.destination}/${full.name}.zip" basedir="${temp.folder}" filesonly="true"/>
+ <delete dir="${temp.folder}"/>
+ </target>
+
+</project>
--- /dev/null
+
+Plugin.name=PHPEclipse Launching Support
+LaunchConfigurationTypePHPApplication.name=PHP Application
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin
+ id="net.sourceforge.phpeclipse.launching"
+ name="%Plugin.name"
+ version="1.0.3"
+ provider-name="eclipseproject.de"
+ class="net.sourceforge.phpdt.internal.launching.PHPLaunchingPlugin">
+
+ <runtime>
+ <library name="launch.jar">
+ <export name="*"/>
+ </library>
+ </runtime>
+ <requires>
+ <import plugin="org.eclipse.core.runtime"/>
+ <import plugin="org.eclipse.core.resources"/>
+ <import plugin="org.eclipse.ui"/>
+ <import plugin="org.eclipse.debug.core"/>
+ <import plugin="org.junit"/>
+ <import plugin="org.apache.xerces"/>
+ <import plugin="net.sourceforge.phpeclipse"/>
+ </requires>
+
+
+ <extension
+ point="org.eclipse.debug.core.launchConfigurationTypes">
+ <launchConfigurationType
+ name="%LaunchConfigurationTypePHPApplication.name"
+ delegate="net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationDelegate"
+ modes="run"
+ id="net.sourceforge.phpdt.launching.LaunchConfigurationTypePHPApplication">
+ <fileExtension
+ default="true"
+ extension="php">
+ </fileExtension>
+ <fileExtension
+ default="true"
+ extension="php3">
+ </fileExtension>
+ <fileExtension
+ default="true"
+ extension="php4">
+ </fileExtension>
+ </launchConfigurationType>
+ </extension>
+
+</plugin>
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.internal.launching;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+
+import net.sourceforge.phpeclipse.resourcesview.PHPProject;
+import org.eclipse.core.boot.BootLoader;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IProcess;
+
+public class InterpreterRunner {
+
+ public InterpreterRunner() {
+ }
+
+ public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {
+ String commandLine = renderCommandLine(configuration);
+ File workingDirectory = configuration.getAbsoluteWorkingDirectory();
+
+ Process nativePHPProcess = null;
+ try {
+ nativePHPProcess = configuration.getInterpreter().exec(commandLine, workingDirectory);
+ } catch (IOException e) {
+ throw new RuntimeException("Unable to execute interpreter: " + commandLine + workingDirectory);
+ }
+
+ IProcess process = DebugPlugin.getDefault().newProcess(launch, nativePHPProcess, renderLabel(configuration));
+ process.setAttribute(PHPLaunchingPlugin.PLUGIN_ID + ".launcher.cmdline", commandLine);
+ return process ;
+ }
+
+ protected String renderLabel(InterpreterRunnerConfiguration configuration) {
+ StringBuffer buffer = new StringBuffer();
+
+ PHPInterpreter interpreter = configuration.getInterpreter();
+ buffer.append("PHP ");
+ buffer.append(interpreter.getCommand());
+ buffer.append(" : ");
+ buffer.append(configuration.getFileName());
+
+ return buffer.toString();
+ }
+
+ protected String renderCommandLine(InterpreterRunnerConfiguration configuration) {
+ PHPInterpreter interpreter = configuration.getInterpreter();
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(this.getDebugCommandLineArgument());
+ // buffer.append(renderLoadPath(configuration));
+ buffer.append(" " + configuration.getInterpreterArguments());
+ // buffer.append(interpreter.endOfOptionsDelimeter);
+ buffer.append(" " + osDependentPath(configuration.getAbsoluteFileName()));
+ buffer.append(" " + configuration.getProgramArguments());
+
+ return buffer.toString();
+ }
+
+// protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
+// StringBuffer loadPath = new StringBuffer();
+//
+// PHPProject project = configuration.getProject();
+// addToLoadPath(loadPath, project.getProject());
+//
+// Iterator referencedProjects = project.getReferencedProjects().iterator();
+// while (referencedProjects.hasNext())
+// addToLoadPath(loadPath, (IProject) referencedProjects.next());
+//
+// return loadPath.toString();
+// }
+
+// protected void addToLoadPath(StringBuffer loadPath, IProject project) {
+//
+// loadPath.append(" -I " + osDependentPath(project.getLocation().toOSString()));
+// }
+
+ protected String osDependentPath(String aPath) {
+ if (BootLoader.getOS().equals(BootLoader.OS_WIN32))
+ aPath = "\"" + aPath + "\"";
+
+ return aPath;
+ }
+
+ protected String getDebugCommandLineArgument() {
+ return "" ;
+ }
+
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.launching;
+
+import java.io.File;
+
+import net.sourceforge.phpeclipse.resourcesview.PHPProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+
+public class InterpreterRunnerConfiguration {
+ protected ILaunchConfiguration configuration;
+
+ public InterpreterRunnerConfiguration(ILaunchConfiguration aConfiguration) {
+ configuration = aConfiguration;
+ }
+
+ public String getAbsoluteFileName() {
+ IPath path = new Path(getFileName());
+ IProject project = getProject().getProject();
+
+ return project.getLocation().toOSString() + "/" + getFileName();
+ }
+
+ public String getFileName() {
+ String fileName = "";
+
+ try {
+ fileName = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, "No file specified in configuration");
+ } catch(CoreException e) {}
+
+ return fileName.replace('\\', '/');
+ }
+
+ public PHPProject getProject() {
+ String projectName = "";
+
+ try {
+ projectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
+ } catch(CoreException e) {
+ PHPLaunchingPlugin.getDefault().log(e);
+ }
+
+ IProject project = PHPLaunchingPlugin.getWorkspace().getRoot().getProject(projectName);
+
+ PHPProject phpProject = new PHPProject();
+ phpProject.setProject(project);
+ return phpProject;
+ }
+
+ public File getAbsoluteWorkingDirectory() {
+ String file = null;
+ try {
+ file = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
+ } catch(CoreException e) {
+ PHPLaunchingPlugin.log(e);
+ }
+ return new File(file);
+ }
+
+ public String getInterpreterArguments() {
+ try {
+ return configuration.getAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
+ } catch(CoreException e) {}
+
+ return "";
+ }
+
+ public String getProgramArguments() {
+ try {
+ return configuration.getAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
+ } catch (CoreException e) {}
+
+ return "";
+ }
+
+ public PHPInterpreter getInterpreter() {
+ String selectedInterpreter = null;
+ try {
+ selectedInterpreter = configuration.getAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
+ } catch(CoreException e) {}
+
+ return PHPRuntime.getDefault().getInterpreter(selectedInterpreter);
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.launching;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.internal.resources.OS;
+import org.eclipse.core.runtime.IPath;
+
+public class PHPInterpreter {
+ //public final String endOfOptionsDelimeter = " -- ";
+
+ protected IPath installLocation;
+ protected String name;
+
+ public PHPInterpreter(String aName, IPath validInstallLocation) {
+ name = aName;
+ installLocation = validInstallLocation;
+ }
+
+ public IPath getInstallLocation() {
+ return installLocation;
+ }
+
+ public void setInstallLocation(IPath validInstallLocation) {
+ installLocation = validInstallLocation;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String newName) {
+ name = newName;
+ }
+
+ public String getCommand() {
+ String directory = installLocation.toOSString() + File.separator;
+ if (new File(directory + "php.exe").isFile())
+ return directory + "php.exe";
+
+ if (new File(directory, "php").isFile())
+ return directory + "php";
+
+ return null;
+ }
+
+ public Process exec(String arguments, File workingDirectory) throws IOException {
+ return Runtime.getRuntime().exec(this.getCommand() + " " + arguments, null, workingDirectory);
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof PHPInterpreter) {
+ PHPInterpreter otherInterpreter = (PHPInterpreter) other;
+ if (name.equals(otherInterpreter.getName()))
+ return installLocation.equals(otherInterpreter.getInstallLocation());
+ }
+
+ return false;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.launching;
+
+
+
+public interface PHPLaunchConfigurationAttribute {
+ static final String PHP_LAUNCH_CONFIGURATION_TYPE = "net.sourceforge.phpdt.launching.LaunchConfigurationTypePHPApplication";
+
+ static final String CUSTOM_LOAD_PATH = PHPLaunchingPlugin.PLUGIN_ID + ".CUSTOM_LOAD_PATH";
+ static final String FILE_NAME = PHPLaunchingPlugin.PLUGIN_ID + ".FILE_NAME";
+ static final String INTERPRETER_ARGUMENTS = PHPLaunchingPlugin.PLUGIN_ID + ".INTERPRETER_ARGUMENTS";
+ static final String MODULE_NAME = PHPLaunchingPlugin.PLUGIN_ID + ".MODULE_NAME";
+ static final String PROGRAM_ARGUMENTS = PHPLaunchingPlugin.PLUGIN_ID + ".PROGRAM_ARGUMENTS";
+ static final String PROJECT_NAME = PHPLaunchingPlugin.PLUGIN_ID + ".PROJECT_NAME";
+ static final String SELECTED_INTERPRETER = PHPLaunchingPlugin.PLUGIN_ID + ".SELECTED_INTERPRETER";
+ static final String WORKING_DIRECTORY = PHPLaunchingPlugin.PLUGIN_ID + ".WORKING_DIRECTORY";
+ static final String USE_DEFAULT_LOAD_PATH = PHPLaunchingPlugin.PLUGIN_ID + ".USE_DEFAULT_LOAD_PATH";
+ static final String USE_DEFAULT_WORKING_DIRECTORY = PHPLaunchingPlugin.PLUGIN_ID + ".USE_DEFAULT_WORKING_DIRECTORY";
+}
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.internal.launching;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
+
+
+public class PHPLaunchConfigurationDelegate implements ILaunchConfigurationDelegate {
+ protected static final InterpreterRunner interpreterRunner = new InterpreterRunner();
+// protected static final DebuggerRunner debuggerRunner = new DebuggerRunner();
+
+ public PHPLaunchConfigurationDelegate() {
+ super();
+ }
+
+ /**
+ * @see ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
+ */
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ if (PHPRuntime.getDefault().getSelectedInterpreter() == null)
+ throw new CoreException(new Status(IStatus.ERROR, PHPLaunchingPlugin.PLUGIN_ID, IStatus.OK, "You must define an interpreter before running PHP.", null));
+// if (mode.equals("debug")) {
+// debuggerRunner.run(new InterpreterRunnerConfiguration(configuration), launch);
+// } else {
+ interpreterRunner.run(new InterpreterRunnerConfiguration(configuration), launch);
+// }
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.launching;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class PHPLaunchingMessages {
+
+ private static final String BUNDLE_NAME = PHPLaunchingMessages.class.getName();
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private PHPLaunchingMessages() {}
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
--- /dev/null
+
+#########################################
+# PHPLaunchingPlugin
+#########################################
+
+PHPLaunchingPlugin.internalErrorOccurred=Internal error occurred
\ No newline at end of file
--- /dev/null
+package net.sourceforge.phpdt.internal.launching;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+
+public class PHPLaunchingPlugin extends Plugin {
+ public static final String PLUGIN_ID = "net.sourceforge.phpeclipse.launching"; //$NON-NLS-1$
+
+ protected static PHPLaunchingPlugin plugin;
+
+ public PHPLaunchingPlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ plugin = this;
+ }
+
+ public static PHPLaunchingPlugin getDefault() {
+ return plugin;
+ }
+
+ public static IWorkspace getWorkspace() {
+ return PHPeclipsePlugin.getWorkspace();
+ }
+
+ public static void log(IStatus status) {
+ getDefault().getLog().log(status);
+ }
+
+ public static void log(Throwable e) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, PHPLaunchingMessages.getString("PHPLaunchingPlugin.internalErrorOccurred"), e)); //$NON-NLS-1$
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.launching;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.parsers.SAXParserFactory;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+public class PHPRuntime {
+ protected static PHPRuntime runtime;
+
+ protected List installedInterpreters;
+ protected PHPInterpreter selectedInterpreter;
+ protected PHPRuntime() {
+ super();
+ }
+
+ public static PHPRuntime getDefault() {
+ if (runtime == null) {
+ runtime = new PHPRuntime();
+ }
+ return runtime;
+ }
+
+ public PHPInterpreter getSelectedInterpreter() {
+ if (selectedInterpreter == null) {
+ loadRuntimeConfiguration();
+ }
+ return selectedInterpreter;
+ }
+
+ public PHPInterpreter getInterpreter(String name) {
+ Iterator interpreters = getInstalledInterpreters().iterator();
+ while(interpreters.hasNext()) {
+ PHPInterpreter each = (PHPInterpreter) interpreters.next();
+ if (each.getName().equals(name))
+ return each;
+ }
+
+ return getSelectedInterpreter();
+ }
+
+ public void setSelectedInterpreter(PHPInterpreter anInterpreter) {
+ selectedInterpreter = anInterpreter;
+ saveRuntimeConfiguration();
+ }
+
+ public void addInstalledInterpreter(PHPInterpreter anInterpreter) {
+ getInstalledInterpreters().add(anInterpreter);
+ if (getInstalledInterpreters().size() == 1)
+ setSelectedInterpreter((PHPInterpreter) getInstalledInterpreters().get(0));
+
+ saveRuntimeConfiguration();
+ }
+
+ public List getInstalledInterpreters() {
+ if (installedInterpreters == null)
+ loadRuntimeConfiguration();
+ return installedInterpreters;
+ }
+
+ public void setInstalledInterpreters(List newInstalledInterpreters) {
+ installedInterpreters = newInstalledInterpreters;
+ if (installedInterpreters.size() > 0)
+ setSelectedInterpreter((PHPInterpreter)installedInterpreters.get(0));
+ else
+ setSelectedInterpreter(null);
+ }
+
+ protected void saveRuntimeConfiguration() {
+ writeXML(getRuntimeConfigurationWriter());
+ }
+
+ protected Writer getRuntimeConfigurationWriter() {
+ try {
+ OutputStream stream = new BufferedOutputStream(new FileOutputStream(getRuntimeConfigurationFile()));
+ return new OutputStreamWriter(stream);
+ } catch (FileNotFoundException e) {}
+
+ return null;
+ }
+
+ protected void loadRuntimeConfiguration() {
+ installedInterpreters = new ArrayList();
+ try {
+ XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+ reader.setContentHandler(getRuntimeConfigurationContentHandler());
+ reader.parse(new InputSource(getRuntimeConfigurationReader()));
+ } catch(Exception e) {
+ PHPLaunchingPlugin.getDefault().log(e);
+ }
+ }
+
+ protected Reader getRuntimeConfigurationReader() {
+ try {
+ return new FileReader(getRuntimeConfigurationFile());
+ } catch(FileNotFoundException e) {}
+ return new StringReader("");
+ }
+
+ protected void writeXML(Writer writer) {
+ try {
+ writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><runtimeconfig>");
+ Iterator interpretersIterator = installedInterpreters.iterator();
+ while (interpretersIterator.hasNext()) {
+ writer.write("<interpreter name=\"");
+
+ PHPInterpreter entry = (PHPInterpreter) interpretersIterator.next();
+ writer.write(entry.getName());
+ writer.write("\" path=\"");
+ writer.write(entry.getInstallLocation().toString());
+ writer.write("\"");
+ if (entry.equals(selectedInterpreter))
+ writer.write(" selected=\"true\"");
+
+ writer.write("/>");
+ }
+ writer.write("</runtimeconfig>");
+ writer.flush();
+ } catch(IOException e) {
+ PHPLaunchingPlugin.log(e);
+ }
+ }
+
+ protected ContentHandler getRuntimeConfigurationContentHandler() {
+ return new ContentHandler() {
+ public void setDocumentLocator(Locator locator) {}
+ public void startDocument() throws SAXException {}
+ public void endDocument() throws SAXException {}
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {}
+ public void endPrefixMapping(String prefix) throws SAXException {}
+ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
+ if ("interpreter".equals(qName)) {
+ String interpreterName = atts.getValue("name");
+ IPath installLocation = new Path(atts.getValue("path"));
+ PHPInterpreter interpreter = new PHPInterpreter(interpreterName, installLocation);
+ installedInterpreters.add(interpreter);
+ if (atts.getValue("selected") != null)
+ selectedInterpreter = interpreter;
+ }
+ }
+ public void endElement(String namespaceURI, String localName, String qName) throws SAXException {}
+ public void characters(char[] ch, int start, int length) throws SAXException {}
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {}
+ public void processingInstruction(String target, String data) throws SAXException {}
+ public void skippedEntity(String name) throws SAXException {}
+ };
+ }
+
+ protected File getRuntimeConfigurationFile() {
+ IPath stateLocation = PHPLaunchingPlugin.getDefault().getStateLocation();
+ IPath fileLocation = stateLocation.append("runtimeConfiguration.xml");
+ return new File(fileLocation.toOSString());
+ }
+}