Fixed: Editor open a file in R/O (as external) when debugging a file under linked...
[phpeclipse.git] / net.sourceforge.phpeclipse.launching / src / net / sourceforge / phpdt / internal / launching / PHPRuntime.java
index 0b392a6..1dbea3b 100644 (file)
@@ -29,7 +29,9 @@ public class PHPRuntime {
        protected static PHPRuntime runtime;
 
        protected List installedInterpreters;
+
        protected PHPInterpreter selectedInterpreter;
+
        protected PHPRuntime() {
                super();
        }
@@ -50,7 +52,7 @@ public class PHPRuntime {
 
        public PHPInterpreter getInterpreter(String installLocation) {
                Iterator interpreters = getInstalledInterpreters().iterator();
-               while(interpreters.hasNext()) {
+               while (interpreters.hasNext()) {
                        PHPInterpreter each = (PHPInterpreter) interpreters.next();
                        if (each.getInstallLocation().toString().equals(installLocation))
                                return each;
@@ -67,7 +69,8 @@ public class PHPRuntime {
        public void addInstalledInterpreter(PHPInterpreter anInterpreter) {
                getInstalledInterpreters().add(anInterpreter);
                if (getInstalledInterpreters().size() == 1)
-                       setSelectedInterpreter((PHPInterpreter) getInstalledInterpreters().get(0));
+                       setSelectedInterpreter((PHPInterpreter) getInstalledInterpreters()
+                                       .get(0));
 
                saveRuntimeConfiguration();
        }
@@ -81,7 +84,8 @@ public class PHPRuntime {
        public void setInstalledInterpreters(List newInstalledInterpreters) {
                installedInterpreters = newInstalledInterpreters;
                if (installedInterpreters.size() > 0)
-                       setSelectedInterpreter((PHPInterpreter)installedInterpreters.get(0));
+                       setSelectedInterpreter((PHPInterpreter) installedInterpreters
+                                       .get(0));
                else
                        setSelectedInterpreter(null);
        }
@@ -92,9 +96,11 @@ public class PHPRuntime {
 
        protected Writer getRuntimeConfigurationWriter() {
                try {
-                       OutputStream stream = new BufferedOutputStream(new FileOutputStream(getRuntimeConfigurationFile()));
+                       OutputStream stream = new BufferedOutputStream(
+                                       new FileOutputStream(getRuntimeConfigurationFile()));
                        return new OutputStreamWriter(stream);
-               } catch (FileNotFoundException e) {}
+               } catch (FileNotFoundException e) {
+               }
 
                return null;
        }
@@ -104,11 +110,14 @@ public class PHPRuntime {
                try {
                        File file = getRuntimeConfigurationFile();
                        if (file.exists()) {
-                           XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
-                           reader.setContentHandler(getRuntimeConfigurationContentHandler());
-                           reader.parse(new InputSource(getRuntimeConfigurationReader(file)));
+                               XMLReader reader = SAXParserFactory.newInstance()
+                                               .newSAXParser().getXMLReader();
+                               reader
+                                               .setContentHandler(getRuntimeConfigurationContentHandler());
+                               reader.parse(new InputSource(
+                                               getRuntimeConfigurationReader(file)));
                        }
-               } catch(Exception e) {
+               } catch (Exception e) {
                        PHPLaunchingPlugin.log(e);
                }
        }
@@ -116,19 +125,22 @@ public class PHPRuntime {
        protected Reader getRuntimeConfigurationReader(File file) {
                try {
                        return new FileReader(file);
-               } catch(FileNotFoundException e) {}
+               } catch (FileNotFoundException e) {
+               }
                return new StringReader("");
        }
 
        protected void writeXML(Writer writer) {
                try {
-                       writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><runtimeconfig>");
+                       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());
+                               PHPInterpreter entry = (PHPInterpreter) interpretersIterator
+                                               .next();
+                               // writer.write(entry.getName());
                                writer.write("\" path=\"");
                                writer.write(entry.getInstallLocation().toString());
                                writer.write("\"");
@@ -139,43 +151,72 @@ public class PHPRuntime {
                        }
                        writer.write("</runtimeconfig>");
                        writer.flush();
-               } catch(IOException e) {
+               } 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 {
+                       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");
-                                       java.io.File installLocation;
-                                       if (interpreterName!=null) {
-                                         installLocation = new File(atts.getValue("path")+File.separatorChar+interpreterName);
-                                       } else {
-                                         installLocation = new File(atts.getValue("path"));
-                                       }
-                                       PHPInterpreter interpreter = new PHPInterpreter(installLocation);
+                                       String interpreterName = atts.getValue("name");
+                                       java.io.File installLocation;
+                                       if (interpreterName != null) {
+                                               installLocation = new File(atts.getValue("path")
+                                                               + File.separatorChar + interpreterName);
+                                       } else {
+                                               installLocation = new File(atts.getValue("path"));
+                                       }
+                                       PHPInterpreter interpreter = new PHPInterpreter(
+                                                       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 {}
+
+                       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 stateLocation = PHPLaunchingPlugin.getDefault()
+                               .getStateLocation();
                IPath fileLocation = stateLocation.append("runtimeConfiguration.xml");
                return new File(fileLocation.toOSString());
        }