Return-Path: X-Original-To: apmail-ant-notifications-archive@minotaur.apache.org Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 285D1DB7E for ; Mon, 20 Aug 2012 13:01:17 +0000 (UTC) Received: (qmail 28638 invoked by uid 500); 20 Aug 2012 13:01:17 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 28588 invoked by uid 500); 20 Aug 2012 13:01:16 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 28576 invoked by uid 99); 20 Aug 2012 13:01:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Aug 2012 13:01:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Aug 2012 13:01:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 300A52388A40 for ; Mon, 20 Aug 2012 13:00:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Mon, 20 Aug 2012 13:00:27 -0000 To: notifications@ant.apache.org From: hibou@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120820130028.300A52388A40@eris.apache.org> 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 + + + + + + + + + + + + + + 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