You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by hi...@apache.org on 2012/08/20 15:00:27 UTC

svn commit: r1375002 - in /ant/ivy/ivyde/trunk: doc/ org.apache.ivyde.eclipse/ org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/

Author: hibou
Date: Mon Aug 20 13:00:27 2012
New Revision: 1375002

URL: http://svn.apache.org/viewvc?rev=1375002&view=rev
Log:
Add content types to improve the detection of ivy files and ivysettings, so that IvyDE editors are automatically used

Added:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvyFileContentDescriber.java   (with props)
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsContentDescriber.java   (with props)
Modified:
    ant/ivy/ivyde/trunk/doc/release-notes.html
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml

Modified: ant/ivy/ivyde/trunk/doc/release-notes.html
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/doc/release-notes.html?rev=1375002&r1=1375001&r2=1375002&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/doc/release-notes.html (original)
+++ ant/ivy/ivyde/trunk/doc/release-notes.html Mon Aug 20 13:00:27 2012
@@ -133,6 +133,7 @@ List of changes since <a href="/ivy/ivyd
 </ul>
 <ul>
     <li>IMPROVE: The properties file paths can now be edited</li>
+    <li>IMPROVE: ivy.xml and ivysettings.xml files are not better detected as such, so they can be open with the Ivy editors</li>
 </ul>
 <ul>
     <li>FIX: org.eclipse.swt.SWTException: Invalid thread access with Eclipse Juno (IVYDE-313)</li>

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml?rev=1375002&r1=1375001&r2=1375002&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml Mon Aug 20 13:00:27 2012
@@ -64,10 +64,13 @@
       <editor
             class="org.apache.ivyde.eclipse.ui.editors.IvyModuleDescriptorEditor"
             contributorClass="org.apache.ivyde.eclipse.ui.editors.IvyModuleDescriptorEditorContributor"
-            filenames="ivy.xml,ivy-dev.xml,ivy-snapshot.xml"
+            filenames="ivy.xml"
             icon="icons/logo16x16.gif"
             id="org.apache.ivyde.editors.IvyEditor"
             name="Ivy Editor">
+         <contentTypeBinding
+               contentTypeId="org.apache.ivyde.eclipse.contentType.ivyfile">
+         </contentTypeBinding>
       </editor>
       <editor
             class="org.apache.ivyde.eclipse.ui.editors.IvySettingsEditor"
@@ -76,6 +79,9 @@
             icon="icons/logo16x16.gif"
             id="org.apache.ivyde.editors.IvySettingsEditor"
             name="Ivy Settings Editor">
+         <contentTypeBinding
+               contentTypeId="org.apache.ivyde.eclipse.contentType.ivysettings">
+         </contentTypeBinding>
       </editor>
    </extension>
    <extension
@@ -471,5 +477,29 @@
             state="true">
       </decorator>
    </extension>
+   <extension
+         point="org.eclipse.core.contenttype.contentTypes">
+      <content-type
+            base-type="org.eclipse.core.runtime.xml"
+            file-extensions="xml"
+            file-names="ivy.xml"
+            id="org.apache.ivyde.eclipse.contentType.ivyfile"
+            name="Ivy File"
+            priority="normal">
+         <describer
+               class="org.apache.ivyde.eclipse.ui.editors.IvyFileContentDescriber">
+         </describer>
+      </content-type>
+      <content-type
+            base-type="org.eclipse.core.runtime.xml"
+            file-extensions="xml"
+            id="org.apache.ivyde.eclipse.contentType.ivysettings"
+            name="Ivy Settings"
+            priority="normal">
+         <describer
+               class="org.apache.ivyde.eclipse.ui.editors.IvySettingsContentDescriber">
+         </describer>
+      </content-type>
+   </extension>
 
 </plugin>

Added: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvyFileContentDescriber.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvyFileContentDescriber.java?rev=1375002&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvyFileContentDescriber.java (added)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvyFileContentDescriber.java Mon Aug 20 13:00:27 2012
@@ -0,0 +1,106 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivyde.eclipse.ui.editors;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.ivy.util.XMLHelper;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.content.XMLContentDescriber;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class IvyFileContentDescriber extends XMLContentDescriber implements IExecutableExtension {
+
+    public void
+            setInitializationData(IConfigurationElement config, String propertyName, Object data)
+                    throws CoreException {
+        // nothing to do
+    }
+
+    public int describe(InputStream input, IContentDescription description) throws IOException {
+        // call the basic XML describer to do basic recognition
+        if (super.describe(input, description) == INVALID) {
+            return INVALID;
+        }
+        // super.describe will have consumed some chars, need to rewind
+        input.reset();
+        // Check to see if we matched our criteria.
+        return checkCriteria(new InputSource(input));
+    }
+
+    public int describe(Reader input, IContentDescription description) throws IOException {
+        // call the basic XML describer to do basic recognition
+        if (super.describe(input, description) == INVALID) {
+            return INVALID;
+        }
+        // super.describe will have consumed some chars, need to rewind
+        input.reset();
+        // Check to see if we matched our criteria.
+        return checkCriteria(new InputSource(input));
+    }
+
+    private int checkCriteria(InputSource contents) throws IOException {
+        IvyFileHandler ivyFileHandler = new IvyFileHandler();
+        try {
+            XMLHelper.parse(contents, null, ivyFileHandler, null);
+        } catch (SAXException e) {
+            // we may be handed any kind of contents... it is normal we fail to parse
+            return INDETERMINATE;
+        } catch (ParserConfigurationException e) {
+            // some bad thing happened - force this describer to be disabled
+            String message = "Internal Error: XML parser configuration error during content description for Ivy files";
+            throw new RuntimeException(message);
+        }
+        if (ivyFileHandler.isIvyFile) {
+            return VALID;
+        }
+        return INDETERMINATE;
+    }
+
+    /**
+     * Stupid handler to check that the file starts with 'ivy-module'
+     */
+    private static final class IvyFileHandler extends DefaultHandler {
+        boolean root = true;
+
+        boolean isIvyFile;
+
+        public void startElement(String uri, String localName, String qName, Attributes attributes)
+                throws SAXException {
+            if (!root) {
+                return;
+            }
+
+            if ("ivy-module".equals(localName)) {
+                isIvyFile = true;
+            }
+
+            root = true;
+        }
+    }
+}

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvyFileContentDescriber.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvyFileContentDescriber.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvyFileContentDescriber.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsContentDescriber.java
URL: http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsContentDescriber.java?rev=1375002&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsContentDescriber.java (added)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsContentDescriber.java Mon Aug 20 13:00:27 2012
@@ -0,0 +1,107 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivyde.eclipse.ui.editors;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.ivy.util.XMLHelper;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.content.XMLContentDescriber;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class IvySettingsContentDescriber extends XMLContentDescriber implements
+        IExecutableExtension {
+
+    public void
+            setInitializationData(IConfigurationElement config, String propertyName, Object data)
+                    throws CoreException {
+        // nothing to do
+    }
+
+    public int describe(InputStream input, IContentDescription description) throws IOException {
+        // call the basic XML describer to do basic recognition
+        if (super.describe(input, description) == INVALID) {
+            return INVALID;
+        }
+        // super.describe will have consumed some chars, need to rewind
+        input.reset();
+        // Check to see if we matched our criteria.
+        return checkCriteria(new InputSource(input));
+    }
+
+    public int describe(Reader input, IContentDescription description) throws IOException {
+        // call the basic XML describer to do basic recognition
+        if (super.describe(input, description) == INVALID) {
+            return INVALID;
+        }
+        // super.describe will have consumed some chars, need to rewind
+        input.reset();
+        // Check to see if we matched our criteria.
+        return checkCriteria(new InputSource(input));
+    }
+
+    private int checkCriteria(InputSource contents) throws IOException {
+        IvySettingsHandler ivySettingsHandler = new IvySettingsHandler();
+        try {
+            XMLHelper.parse(contents, null, ivySettingsHandler, null);
+        } catch (SAXException e) {
+            // we may be handed any kind of contents... it is normal we fail to parse
+            return INDETERMINATE;
+        } catch (ParserConfigurationException e) {
+            // some bad thing happened - force this describer to be disabled
+            String message = "Internal Error: XML parser configuration error during content description for Ivy files";
+            throw new RuntimeException(message);
+        }
+        if (ivySettingsHandler.isIvySettings) {
+            return VALID;
+        }
+        return INDETERMINATE;
+    }
+
+    /**
+     * Stupid handler to check that the file starts with 'ivysettings'
+     */
+    private static final class IvySettingsHandler extends DefaultHandler {
+        boolean root = true;
+
+        boolean isIvySettings;
+
+        public void startElement(String uri, String localName, String qName, Attributes attributes)
+                throws SAXException {
+            if (!root) {
+                return;
+            }
+
+            if ("ivysettings".equals(localName)) {
+                isIvySettings = true;
+            }
+
+            root = true;
+        }
+    }
+}

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsContentDescriber.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsContentDescriber.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsContentDescriber.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain