diff --git a/cnd/src/org/netbeans/modules/cnd/loaders/CndSniffyMIMEResolver.java b/cnd/src/org/netbeans/modules/cnd/loaders/CndSniffyMIMEResolver.java deleted file mode 100644 --- a/cnd/src/org/netbeans/modules/cnd/loaders/CndSniffyMIMEResolver.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * The contents of this file are subject to the terms of the Common Development - * and Distribution License (the License). You may not use this file except in - * compliance with the License. - * - * You can obtain a copy of the License at http://www.netbeans.org/cddl.html - * or http://www.netbeans.org/cddl.txt. - * - * When distributing Covered Code, include this CDDL Header Notice in each file - * and include the License file at http://www.netbeans.org/cddl.txt. - * If applicable, add the following below the CDDL Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Portions Copyrighted 2007 Sun Microsystems, Inc. - */ -package org.netbeans.modules.cnd.loaders; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import org.netbeans.modules.cnd.utils.MIMENames; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.MIMEResolver; - -/** - * expensive resolver (read any file) not based neither on extension, name nor magic hex number - * - * @author Vladimir Voskresensky - */ -public class CndSniffyMIMEResolver extends MIMEResolver { - - public CndSniffyMIMEResolver() { - super(MIMENames.CPLUSPLUS_MIME_TYPE, MIMENames.SHELL_MIME_TYPE); - } - - /** - * Resolves FileObject and returns recognized MIME type - * @param fo is FileObject which should be resolved - * @return recognized MIME type or null if not recognized - */ - public String findMIMEType(FileObject fo) { - if (fo.isFolder()) { - return null; - } - if (fo.getExt().length() > 0) { - return null; - } - - String line = getFirstLine(fo); - // Recognize c++ file without extension - if (detectCPPByLine(line)) { - return MIMENames.CPLUSPLUS_MIME_TYPE; - } - // detect special sun headers - if (detectShellByLine(line)) { - return MIMENames.SHELL_MIME_TYPE; - } - return null; - } - - private String getFirstLine(FileObject fo) { - String line = ""; // NOI18N - InputStreamReader isr = null; - BufferedReader br = null; - try { - if (fo.canRead()) { - isr = new InputStreamReader(fo.getInputStream()); - br = new BufferedReader(isr); - try { - line = br.readLine(); - } catch (IOException ex) { - line = ""; // NOI18N - } - } - } catch (IOException ex) { -// ex.printStackTrace(); - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException ex) { -// ex.printStackTrace(); - } - } - if (isr != null) { - try { - isr.close(); - } catch (IOException ex) { -// ex.printStackTrace(); - } - } - } - return line; - } - - /** - * This is a special detector which samples suffix-less header files looking for the - * string "-*- C++ -*-". - * or - * #include directive in the first line - * Note: Not all Sun Studio headerless includes contain this comment. - */ - private boolean detectCPPByLine(String line) { - if (line != null) { - if (line.startsWith("//") && line.indexOf("-*- C++ -*-") > 0) { // NOI18N - return true; - } else { - line = line.replaceAll("\\s", ""); // NOI18N - if (line.startsWith("#include")) { // NOI18N - return true; - } - } - } - return false; - } - - private boolean detectShellByLine(String line) { - if (line != null) { - line = line.replaceAll("\\s", ""); // NOI18N - if (line.startsWith("#!/bin/bash") || // NOI18N - line.startsWith("#!/bin/sh") || // NOI18N - line.startsWith("#!/bin/ksh") || // NOI18N - line.startsWith("#!/bin/csh") || // NOI18N - line.startsWith("#!/bin/csh") || // NOI18N - line.startsWith("#!/usr/bin/perl")) { // NOI18N - return true; - } - } - return false; - } -} \ No newline at end of file diff --git a/cnd/src/org/netbeans/modules/cnd/resources/Bundle.properties b/cnd/src/org/netbeans/modules/cnd/resources/Bundle.properties --- a/cnd/src/org/netbeans/modules/cnd/resources/Bundle.properties +++ b/cnd/src/org/netbeans/modules/cnd/resources/Bundle.properties @@ -102,6 +102,7 @@ # Makefile MIME Resolver Services/MIMEResolver/org-netbeans-modules-cnd-mime-resolver.xml=Makefile files +Services/MIMEResolver/cnd-mime-resolver-content-based.xml=CND Resolver (content check) # Error annotations LBL_error_annotation=C, C++, and Fortran Compilation Errors diff --git a/cnd/src/org/netbeans/modules/cnd/resources/mf-layer.xml b/cnd/src/org/netbeans/modules/cnd/resources/mf-layer.xml --- a/cnd/src/org/netbeans/modules/cnd/resources/mf-layer.xml +++ b/cnd/src/org/netbeans/modules/cnd/resources/mf-layer.xml @@ -309,10 +309,10 @@ - - + + - + diff --git a/cnd/src/org/netbeans/modules/cnd/resources/mime-resolver-content-based.xml b/cnd/src/org/netbeans/modules/cnd/resources/mime-resolver-content-based.xml new file mode 100644 --- /dev/null +++ b/cnd/src/org/netbeans/modules/cnd/resources/mime-resolver-content-based.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/languages.sh/src/META-INF/services/org.openide.filesystems.MIMEResolver b/languages.sh/src/META-INF/services/org.openide.filesystems.MIMEResolver deleted file mode 100644 --- a/languages.sh/src/META-INF/services/org.openide.filesystems.MIMEResolver +++ /dev/null @@ -1,1 +0,0 @@ -org.netbeans.modules.languages.sh.ShellScriptResolver diff --git a/languages.sh/src/org/netbeans/modules/languages/sh/Bundle.properties b/languages.sh/src/org/netbeans/modules/languages/sh/Bundle.properties --- a/languages.sh/src/org/netbeans/modules/languages/sh/Bundle.properties +++ b/languages.sh/src/org/netbeans/modules/languages/sh/Bundle.properties @@ -42,6 +42,8 @@ OpenIDE-Module-Short-Description=Support for editing .sh files. OpenIDE-Module-Long-Description=Support for editing .sh files. +Services/MIMEResolver/ShellMIMEResolver.xml=Sh Files + text/sh=Sh File error=Error diff --git a/languages.sh/src/org/netbeans/modules/languages/sh/ShellMIMEResolver.xml b/languages.sh/src/org/netbeans/modules/languages/sh/ShellMIMEResolver.xml new file mode 100644 --- /dev/null +++ b/languages.sh/src/org/netbeans/modules/languages/sh/ShellMIMEResolver.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + diff --git a/languages.sh/src/org/netbeans/modules/languages/sh/ShellScriptResolver.java b/languages.sh/src/org/netbeans/modules/languages/sh/ShellScriptResolver.java deleted file mode 100644 --- a/languages.sh/src/org/netbeans/modules/languages/sh/ShellScriptResolver.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * Portions Copyrighted 2007 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.languages.sh; - -import java.io.IOException; -import java.io.InputStream; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.MIMEResolver; - -/** - * Detects shell scripts. - */ -public class ShellScriptResolver extends MIMEResolver { - - /** Default constructor for lookup. */ - public ShellScriptResolver() { - super("text/sh"); //NOI18N - } - - public String findMIMEType(FileObject fo) { - if (fo.hasExt("sh")) { //NOI18N - return "text/sh"; //NOI18N - } - if (fo.isData() && fo.hasExt("")) { - try { - InputStream is = fo.getInputStream(); - try { - byte[] bytes = new byte[12]; - int len = is.read(bytes); - if (len > 0 && (startsWith(bytes, "#!/bin/sh") || startsWith(bytes, "#!/bin/bash"))) { //NOI18N - return "text/sh"; //NOI18N - } - } finally { - is.close(); - } - } catch (IOException x) { - } - } - return null; - } - - /** Checks whether byte array starts with given string. - * @return true if byte array starts with given prefix, false otherwise - */ - private static boolean startsWith(byte[] bytes, String prefix) { - byte[] prefixBytes = prefix.getBytes(); - for (int i = 0; i < prefixBytes.length; i++) { - if (i > bytes.length-1 || bytes[i] != prefixBytes[i]) { - return false; - } - } - return true; - } -} diff --git a/languages.sh/src/org/netbeans/modules/languages/sh/layer.xml b/languages.sh/src/org/netbeans/modules/languages/sh/layer.xml --- a/languages.sh/src/org/netbeans/modules/languages/sh/layer.xml +++ b/languages.sh/src/org/netbeans/modules/languages/sh/layer.xml @@ -79,4 +79,12 @@ + + + + + + + + diff --git a/php.project/src/META-INF/services/org.openide.filesystems.MIMEResolver b/php.project/src/META-INF/services/org.openide.filesystems.MIMEResolver deleted file mode 100644 --- a/php.project/src/META-INF/services/org.openide.filesystems.MIMEResolver +++ /dev/null @@ -1,2 +0,0 @@ -org.netbeans.modules.php.project.PhpMimeResolver -#position=999 \ No newline at end of file diff --git a/php.project/src/org/netbeans/modules/php/project/PhpMimeResolver.java b/php.project/src/org/netbeans/modules/php/project/PhpMimeResolver.java deleted file mode 100644 --- a/php.project/src/org/netbeans/modules/php/project/PhpMimeResolver.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2008 Sun Microsystems, Inc. - */ -package org.netbeans.modules.php.project; - -import java.io.IOException; -import java.io.InputStream; -import java.util.HashSet; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.MIMEResolver; -import org.openide.util.Utilities; - -/** - * @author Radek Matous - */ -public class PhpMimeResolver extends MIMEResolver { - - private static final int BYTES_FOR_PRECHECK = 255; - private static final int BYTES_FOR_CHECK_IF_HTML_SIGNED = 4000; - private static final Sign[] EMPTY_SIGNS = new Sign[]{}; - private static final String MIME_TYPE = "text/x-php5";//NOI18N - private static final String UNKNOWN_MIME_TYPE = null; - private static final String[] PHP_WELL_KNOWN_EXTENSION_PREFIXES = {"php", "phtml"};//NOI18N - private static final String[] OTHER_WELL_KNOWN_EXTENSION_PREFIXES = {"java", "rb", "rhtml"};//NOI18N - - private static final String[] WELL_KNOWN_WINDOWS_TROUBLE_FILES = { - "ntuser.dat", - "ntuser.dat.log"};//NOI18N - - - //looking for - private static final byte[] OPEN_TAG = " resolvedExt = new HashSet(); - - public PhpMimeResolver() { - super(MIME_TYPE); - } - - @Override - public String findMIMEType(FileObject fo) { - String ext = fo.getExt(); - if (isWellKnownPhpExtension(ext)) {//shouldn't happen because this mime should go last - return MIME_TYPE; - } else if (isWellKnownOtherExtension(ext)) { - return UNKNOWN_MIME_TYPE; - } else if (resolvedExt.contains(ext)) { - return MIME_TYPE; - } - MutableInteger openTagIdx = new MutableInteger(); - MutableInteger shortOpenTagIdx = new MutableInteger(); - if (!fo.canRead()) {//NOI18N - return UNKNOWN_MIME_TYPE; - } - - if (Utilities.isWindows() && existsInArray(fo.getNameExt().toLowerCase(), - WELL_KNOWN_WINDOWS_TROUBLE_FILES)) { - return UNKNOWN_MIME_TYPE; - } - try { - InputStream inputStream = fo.getInputStream(); - try { - byte[] bytes = new byte[BYTES_FOR_PRECHECK]; - int len = inputStream.read(bytes); - Sign[] signs = new Sign[]{ - new Sign(""), - new Sign("".toLowerCase()) - }; - if (len > 0 && resolve(bytes, len,openTagIdx, shortOpenTagIdx, signs)) { - return returnMimeType(fo, MIME_TYPE); - } else if (isSigned(signs)) { - //just once 4000 bytes - //while (len > 0) { - bytes = new byte[BYTES_FOR_CHECK_IF_HTML_SIGNED]; - len = inputStream.read(bytes); - signs = EMPTY_SIGNS; - if (len > 0 && resolve(bytes, len,openTagIdx, shortOpenTagIdx, signs)) { - return returnMimeType(fo, MIME_TYPE); - } - //} - } - } finally { - inputStream.close(); - } - } catch (IOException ex) { - // #143815 - just log exception and continue - Logger.getLogger(PhpMimeResolver.class.getName()).log(Level.INFO, null, ex); - return null; - } - return returnMimeType(fo, UNKNOWN_MIME_TYPE); - } - - private boolean resolve(byte[] bytes, int len, MutableInteger openTagIdx, - MutableInteger shortOpenTagIdx, Sign[] signs) { - for (int i = 0; i < len; i++) { - byte b = bytes[i]; - //short open tags not tested for now - code not deleted yet - //until the decision whether to check or not will settle down - if (isOpenTag(b, openTagIdx) /*|| isShortOpenTag(b,shortOpenTagIdx)*/) { - return true; - } - for (int j = 0; j < signs.length; j++) { - Sign s = signs[j]; - s.check(b); - } - } - return false; - } - - private boolean isSigned(Sign[] signs) { - for (int j = 0; j < signs.length; j++) { - Sign s = signs[j]; - if (s.isSigned()) { - return true; - } - } - return false; - } - - public String returnMimeType(final FileObject fo, final String mimeType) { - String ext = fo.getExt(); - if (ext != null && ext.trim().length() > 0) { - if (MIME_TYPE.equals(mimeType)) { - resolvedExt.add(ext); - } - } - return mimeType; - } - - private static boolean isWellKnownPhpExtension(String ext) { - return existsInArray(ext, PHP_WELL_KNOWN_EXTENSION_PREFIXES); - } - - private static boolean isWellKnownOtherExtension(String ext) { - return existsInArray(ext, OTHER_WELL_KNOWN_EXTENSION_PREFIXES); - } - - private static boolean existsInArray(String elem, String[] array) { - if (elem != null && elem.trim().length() > 0) { - for (String phpPrefix : array) { - if (elem.startsWith(phpPrefix)) { - return true; - } - } - } - return false; - } - - private boolean isOpenTag(byte b, MutableInteger openTagIdx) { - if (openTagIdx.getValue() < OPEN_TAG.length) { - if (b == OPEN_TAG[openTagIdx.getValue()]) { - openTagIdx.incr(); - } else { - openTagIdx.setValue(0); - } - } - return (openTagIdx.getValue() >= OPEN_TAG.length); - } - - private boolean isShortOpenTag(byte b, MutableInteger shortOpenTagIdx) { - if (shortOpenTagIdx.getValue() < SHORT_OPEN_TAG.length && - b == SHORT_OPEN_TAG[shortOpenTagIdx.getValue()]) { - shortOpenTagIdx.incr(); - } else if (shortOpenTagIdx.getValue() >= SHORT_OPEN_TAG.length && Character.isWhitespace((char) b)) { - shortOpenTagIdx.incr(); - } else { - shortOpenTagIdx.setValue(0); - } - return (shortOpenTagIdx.getValue() >= SHORT_OPEN_TAG.length + 1); - } - - private static class MutableInteger { - private int value = 0; - /** - * @return the value - */ - public int getValue() { - return value; - } - - /** - * @param value the value to set - */ - public void setValue(int value) { - this.value = value; - } - - public void incr() { - this.value += 1; - } - } - - private static class Sign { - - private final byte[] signBytes; - private int signBytesIdx; - - Sign(String sign) { - signBytes = sign.getBytes(); - } - - void check(byte b) { - if (signBytesIdx < signBytes.length) { - if (b == signBytes[signBytesIdx]) { - signBytesIdx++; - } else { - signBytesIdx = 0; - } - } - } - - boolean isSigned() { - return (signBytesIdx >= signBytes.length); - } - } -} diff --git a/php.project/src/org/netbeans/modules/php/project/resources/Bundle.properties b/php.project/src/org/netbeans/modules/php/project/resources/Bundle.properties --- a/php.project/src/org/netbeans/modules/php/project/resources/Bundle.properties +++ b/php.project/src/org/netbeans/modules/php/project/resources/Bundle.properties @@ -45,3 +45,5 @@ OpenIDE-Module-Short-Description=Support for PHP projects. OpenIDE-Module-Long-Description=\ Provides support for PHP projects. + +Services/MIMEResolver/PHPMimeResolver.xml=PHP Files (content check) diff --git a/php.project/src/org/netbeans/modules/php/project/resources/PHPProjectMIMEResolver.xml b/php.project/src/org/netbeans/modules/php/project/resources/PHPProjectMIMEResolver.xml new file mode 100644 --- /dev/null +++ b/php.project/src/org/netbeans/modules/php/project/resources/PHPProjectMIMEResolver.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/php.project/src/org/netbeans/modules/php/project/resources/layer.xml b/php.project/src/org/netbeans/modules/php/project/resources/layer.xml --- a/php.project/src/org/netbeans/modules/php/project/resources/layer.xml +++ b/php.project/src/org/netbeans/modules/php/project/resources/layer.xml @@ -255,4 +255,12 @@ + + + + + + + + diff --git a/ruby/src/META-INF/services/org.openide.filesystems.MIMEResolver b/ruby/src/META-INF/services/org.openide.filesystems.MIMEResolver deleted file mode 100644 --- a/ruby/src/META-INF/services/org.openide.filesystems.MIMEResolver +++ /dev/null @@ -1,1 +0,0 @@ -org.netbeans.modules.ruby.RubyMimeResolver diff --git a/ruby/src/org/netbeans/modules/ruby/AstUtilities.java b/ruby/src/org/netbeans/modules/ruby/AstUtilities.java --- a/ruby/src/org/netbeans/modules/ruby/AstUtilities.java +++ b/ruby/src/org/netbeans/modules/ruby/AstUtilities.java @@ -80,6 +80,7 @@ import org.jruby.nb.ast.types.INameNode; import org.jruby.nb.lexer.yacc.ISourcePosition; import org.jruby.util.ByteList; +import org.netbeans.api.ruby.platform.RubyInstallation; import org.netbeans.modules.gsf.api.CancellableTask; import org.netbeans.modules.gsf.api.CompilationInfo; import org.netbeans.modules.gsf.api.Modifier; @@ -121,7 +122,7 @@ private static final boolean INCLUDE_DEFS_PREFIX = false; public static int getAstOffset(CompilationInfo info, int lexOffset) { - ParserResult result = info.getEmbeddedResult(RubyMimeResolver.RUBY_MIME_TYPE, 0); + ParserResult result = info.getEmbeddedResult(RubyInstallation.RUBY_MIME_TYPE, 0); if (result != null) { TranslatedSource ts = result.getTranslatedSource(); if (ts != null) { @@ -133,7 +134,7 @@ } public static OffsetRange getAstOffsets(CompilationInfo info, OffsetRange lexicalRange) { - ParserResult result = info.getEmbeddedResult(RubyMimeResolver.RUBY_MIME_TYPE, 0); + ParserResult result = info.getEmbeddedResult(RubyInstallation.RUBY_MIME_TYPE, 0); if (result != null) { TranslatedSource ts = result.getTranslatedSource(); if (ts != null) { @@ -1495,7 +1496,7 @@ } public static RubyParseResult getParseResult(CompilationInfo info) { - ParserResult result = info.getEmbeddedResult(RubyMimeResolver.RUBY_MIME_TYPE, 0); + ParserResult result = info.getEmbeddedResult(RubyInstallation.RUBY_MIME_TYPE, 0); if (result == null) { return null; @@ -1505,7 +1506,7 @@ } public static Node getRoot(CompilationInfo info) { - return getRoot(info, RubyMimeResolver.RUBY_MIME_TYPE); + return getRoot(info, RubyInstallation.RUBY_MIME_TYPE); } public static Node getRoot(CompilationInfo info, String mimeType) { diff --git a/ruby/src/org/netbeans/modules/ruby/Bundle.properties b/ruby/src/org/netbeans/modules/ruby/Bundle.properties --- a/ruby/src/org/netbeans/modules/ruby/Bundle.properties +++ b/ruby/src/org/netbeans/modules/ruby/Bundle.properties @@ -1,6 +1,6 @@ OpenIDE-Module-Display-Category=Ruby OpenIDE-Module-Name=Ruby Editing -Services/MIMEResolver/jruby.xml=Ruby Files +Services/MIMEResolver/RubyMIMEResolver.xml=Ruby Files text/x-ruby=Ruby text/x-ruby-string-double=Ruby Quoted Strings text/x-ruby-string-single=Ruby Strings diff --git a/ruby/src/org/netbeans/modules/ruby/RDocFormatter.java b/ruby/src/org/netbeans/modules/ruby/RDocFormatter.java --- a/ruby/src/org/netbeans/modules/ruby/RDocFormatter.java +++ b/ruby/src/org/netbeans/modules/ruby/RDocFormatter.java @@ -60,6 +60,7 @@ import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; +import org.netbeans.api.ruby.platform.RubyInstallation; import org.netbeans.modules.gsf.spi.GsfUtilities; import org.netbeans.modules.ruby.elements.ClassElement; import org.netbeans.modules.ruby.elements.MethodElement; @@ -532,7 +533,7 @@ } Language language = RubyTokenId.language(); - String mimeType = RubyMimeResolver.RUBY_MIME_TYPE; + String mimeType = RubyInstallation.RUBY_MIME_TYPE; if (ruby.indexOf(" <%") != -1) { // NOI18N mimeType = "application/x-httpd-eruby"; // RHTML Collection providers = (Collection) Lookup.getDefault().lookupAll(LanguageProvider.class); @@ -544,7 +545,7 @@ } if (language == null) { - mimeType = RubyMimeResolver.RUBY_MIME_TYPE; + mimeType = RubyInstallation.RUBY_MIME_TYPE; language = RubyTokenId.language(); } } else if (source.get(0).trim().startsWith("<")) { diff --git a/ruby/src/org/netbeans/modules/ruby/RubyCodeCompleter.java b/ruby/src/org/netbeans/modules/ruby/RubyCodeCompleter.java --- a/ruby/src/org/netbeans/modules/ruby/RubyCodeCompleter.java +++ b/ruby/src/org/netbeans/modules/ruby/RubyCodeCompleter.java @@ -91,6 +91,7 @@ import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenId; import org.netbeans.api.lexer.TokenSequence; +import org.netbeans.api.ruby.platform.RubyInstallation; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Utilities; import org.netbeans.modules.gsf.api.CodeCompletionContext; @@ -2067,7 +2068,7 @@ anchor = lexOffset - prefix.length(); - final RubyIndex index = RubyIndex.get(info.getIndex(RubyMimeResolver.RUBY_MIME_TYPE), info.getFileObject()); + final RubyIndex index = RubyIndex.get(info.getIndex(RubyInstallation.RUBY_MIME_TYPE), info.getFileObject()); final Document document = info.getDocument(); if (document == null) { @@ -3140,7 +3141,7 @@ } public ElementHandle resolveLink(String link, ElementHandle elementHandle) { - if (link.indexOf('#') != -1 && elementHandle.getMimeType().equals(RubyMimeResolver.RUBY_MIME_TYPE)) { + if (link.indexOf('#') != -1 && elementHandle.getMimeType().equals(RubyInstallation.RUBY_MIME_TYPE)) { if (link.startsWith("#")) { // Put the current class etc. in front of the method call if necessary Element surrounding = RubyParser.resolveHandle(null, elementHandle); @@ -3387,7 +3388,7 @@ ClassNode node = AstUtilities.findClass(path); if (node != null) { - Index idx = info.getIndex(RubyMimeResolver.RUBY_MIME_TYPE); + Index idx = info.getIndex(RubyInstallation.RUBY_MIME_TYPE); if (idx != null) { RubyIndex index = RubyIndex.get(idx, info.getFileObject()); IndexedClass cls = index.getSuperclass(AstUtilities.getFqnName(path)); diff --git a/ruby/src/org/netbeans/modules/ruby/RubyDeclarationFinder.java b/ruby/src/org/netbeans/modules/ruby/RubyDeclarationFinder.java --- a/ruby/src/org/netbeans/modules/ruby/RubyDeclarationFinder.java +++ b/ruby/src/org/netbeans/modules/ruby/RubyDeclarationFinder.java @@ -277,7 +277,7 @@ // No parse tree - try to just use the syntax info to do a simple index lookup // for methods and classes String text = doc.getText(range.getStart(), range.getLength()); - RubyIndex index = RubyIndex.get(info.getIndex(RubyMimeResolver.RUBY_MIME_TYPE), info.getFileObject()); + RubyIndex index = RubyIndex.get(info.getIndex(RubyInstallation.RUBY_MIME_TYPE), info.getFileObject()); if ((index == null) || (text.length() == 0)) { return DeclarationLocation.NONE; @@ -316,7 +316,7 @@ return DeclarationLocation.NONE; } - RubyIndex index = RubyIndex.get(info.getIndex(RubyMimeResolver.RUBY_MIME_TYPE), info.getFileObject()); + RubyIndex index = RubyIndex.get(info.getIndex(RubyInstallation.RUBY_MIME_TYPE), info.getFileObject()); int tokenOffset = lexOffset; @@ -1208,7 +1208,7 @@ // No parse tree - try to just use the syntax info to do a simple index lookup // for methods and classes String text = doc.getText(range.getStart(), range.getLength()); - RubyIndex index = RubyIndex.get(info.getIndex(RubyMimeResolver.RUBY_MIME_TYPE), info.getFileObject()); + RubyIndex index = RubyIndex.get(info.getIndex(RubyInstallation.RUBY_MIME_TYPE), info.getFileObject()); if ((index == null) || (text.length() == 0)) { return null; @@ -1231,7 +1231,7 @@ } // TODO: @ - field? } - RubyIndex index = RubyIndex.get(info.getIndex(RubyMimeResolver.RUBY_MIME_TYPE), info.getFileObject()); + RubyIndex index = RubyIndex.get(info.getIndex(RubyInstallation.RUBY_MIME_TYPE), info.getFileObject()); TokenHierarchy th = TokenHierarchy.get(doc); @@ -1422,7 +1422,7 @@ Node closest = root; int astOffset = 0; int lexOffset = 0; - RubyIndex index = RubyIndex.get(info.getIndex(RubyMimeResolver.RUBY_MIME_TYPE), info.getFileObject()); + RubyIndex index = RubyIndex.get(info.getIndex(RubyInstallation.RUBY_MIME_TYPE), info.getFileObject()); if (root == null) { return DeclarationLocation.NONE; diff --git a/ruby/src/org/netbeans/modules/ruby/RubyMIMEResolver.xml b/ruby/src/org/netbeans/modules/ruby/RubyMIMEResolver.xml new file mode 100644 --- /dev/null +++ b/ruby/src/org/netbeans/modules/ruby/RubyMIMEResolver.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruby/src/org/netbeans/modules/ruby/RubyMimeResolver.java b/ruby/src/org/netbeans/modules/ruby/RubyMimeResolver.java deleted file mode 100644 --- a/ruby/src/org/netbeans/modules/ruby/RubyMimeResolver.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.ruby; - -import java.io.IOException; -import java.io.InputStream; - -import org.openide.filesystems.FileObject; -import org.openide.filesystems.MIMEResolver; - - -/** - * Recognize Ruby file types - * - * @author Tor Norbye - */ -public class RubyMimeResolver extends MIMEResolver { - /** - * MIME type for Ruby. Don't change this without also consulting the various XML files - * that cannot reference this value directly. - */ - public static final String RUBY_MIME_TYPE = "text/x-ruby"; // application/x-ruby is also used a fair bit. - - /** Number of bytes to sniff from the file headers */ - static final int HEADER_LENGTH = 80; - - public RubyMimeResolver() { - super(RUBY_MIME_TYPE); - } - - public String findMIMEType(FileObject fo) { - String ext = fo.getExt(); - - // // TODO - is this just a Rails thing? Maybe register in the rails support module - // if (ext.equalsIgnoreCase("conf")) { - // return RUBY_MIME_TYPE; - // } - String name = fo.getName(); - - if ("Rakefile".equals(name) || "rakefile".equals(name)) { - return RUBY_MIME_TYPE; - } - - // Read the file header and look for #!/usr/bin/ruby (or similar) markers - // but only for files without extensions or with the extension .cgi - // TODO: Check to see if parent is "script" or "bin" and if so, perform this check - if ((ext.length() == 0) || ext.equals("cgi")) { - byte[] header = readHeader(fo); - - if (header != null) { - if (isRubyHeader(header)) { - return RUBY_MIME_TYPE; - } - } - - return null; - } - - char first = Character.toLowerCase(ext.charAt(0)); // I know ext.length() > 0 from above check - if ((first == 'r') && - (ext.equalsIgnoreCase("rb") || ext.equalsIgnoreCase("rake") || // NOI18N - ext.equalsIgnoreCase("rxml") || // NOI18N - ext.equalsIgnoreCase("rjs") || ext.equalsIgnoreCase("rbw") || - ext.equalsIgnoreCase("rbx"))) { // NOI18N - return RUBY_MIME_TYPE; - } else if (first == 'm' && ext.equalsIgnoreCase("mab")) { // NOI18N - return RUBY_MIME_TYPE; - } else if (first == 'b' && ext.equalsIgnoreCase("builder")) { // NOI18N - return RUBY_MIME_TYPE; - } else if (first == 'g' && ext.equalsIgnoreCase("gemspec")) { // NOI18N - return RUBY_MIME_TYPE; - } - - return null; - } - - private byte[] readHeader(FileObject fo) { - // See if it looks like a Ruby file based on the shebang line - byte[] header = new byte[HEADER_LENGTH]; - - InputStream in = null; - - try { - in = fo.getInputStream(); - - for (int i = 0; i < HEADER_LENGTH;) { - try { - int read = in.read(header, i, HEADER_LENGTH - i); - - if (read < 0) { - return null; // unexpected end - } - - i += read; - } catch (IOException ex) { - return null; // unexpected end - } - } - } catch (IOException openex) { - return null; // unexpected end - } finally { - try { - if (in != null) { - in.close(); - } - } catch (IOException ioe) { - // already closed - } - } - - return header; - } - - public static boolean isRubyHeader(byte[] header) { - int max = header.length; - - if ((max < 2) || (header[0] != '#') || (header[1] != '!')) { - return false; - } - - // See if the first line contains the word "ruby" (but not as a path component) - find: - for (int index = 0; index < max - 3; index++) { - byte b = header[index]; - if (b == '\n') { - break; - } - if (b == 'r' && (header[index + 1] == 'u') && - (header[index + 2] == 'b') && (header[index + 3] == 'y')) { - // No slash/backslash before the end of the line or next word - for (int j = index+4; j < max; j++) { - byte c = header[j]; - if (c == ' ' || c == '\n') { - break; - } else if (c == '/' || c == '\\') { - continue find; - } - } - return true; - } - } - - return false; - } -} diff --git a/ruby/src/org/netbeans/modules/ruby/RubyParseResult.java b/ruby/src/org/netbeans/modules/ruby/RubyParseResult.java --- a/ruby/src/org/netbeans/modules/ruby/RubyParseResult.java +++ b/ruby/src/org/netbeans/modules/ruby/RubyParseResult.java @@ -43,6 +43,7 @@ import org.jruby.nb.ast.Node; import org.jruby.nb.ast.RootNode; import org.jruby.nb.parser.RubyParserResult; +import org.netbeans.api.ruby.platform.RubyInstallation; import org.netbeans.modules.gsf.api.CompilationInfo; import org.netbeans.modules.gsf.api.OffsetRange; import org.netbeans.modules.gsf.api.ParserFile; @@ -68,7 +69,7 @@ public RubyParseResult(RubyParser parser, ParserFile file, AstTreeNode ast, Node root, RootNode realRoot, RubyParserResult jrubyResult) { - super(parser, file, RubyMimeResolver.RUBY_MIME_TYPE); + super(parser, file, RubyInstallation.RUBY_MIME_TYPE); this.ast = ast; this.root = root; this.realRoot = realRoot; diff --git a/ruby/src/org/netbeans/modules/ruby/RubyUtils.java b/ruby/src/org/netbeans/modules/ruby/RubyUtils.java --- a/ruby/src/org/netbeans/modules/ruby/RubyUtils.java +++ b/ruby/src/org/netbeans/modules/ruby/RubyUtils.java @@ -48,7 +48,7 @@ } public static boolean isRubyFile(FileObject f) { - return RubyMimeResolver.RUBY_MIME_TYPE.equals(f.getMIMEType()); + return RubyInstallation.RUBY_MIME_TYPE.equals(f.getMIMEType()); } public static boolean isMarkabyFile(FileObject fileObject) { diff --git a/ruby/src/org/netbeans/modules/ruby/elements/RubyElement.java b/ruby/src/org/netbeans/modules/ruby/elements/RubyElement.java --- a/ruby/src/org/netbeans/modules/ruby/elements/RubyElement.java +++ b/ruby/src/org/netbeans/modules/ruby/elements/RubyElement.java @@ -42,10 +42,10 @@ import java.util.Collections; import java.util.Set; +import org.netbeans.api.ruby.platform.RubyInstallation; import org.netbeans.modules.gsf.api.ElementHandle; import org.netbeans.modules.gsf.api.ElementKind; import org.netbeans.modules.gsf.api.Modifier; -import org.netbeans.modules.ruby.RubyMimeResolver; import org.openide.filesystems.FileObject; @@ -60,7 +60,7 @@ public abstract ElementKind getKind(); public String getMimeType() { - return RubyMimeResolver.RUBY_MIME_TYPE; + return RubyInstallation.RUBY_MIME_TYPE; } public boolean signatureEquals(ElementHandle handle) { diff --git a/ruby/src/org/netbeans/modules/ruby/layer.xml b/ruby/src/org/netbeans/modules/ruby/layer.xml --- a/ruby/src/org/netbeans/modules/ruby/layer.xml +++ b/ruby/src/org/netbeans/modules/ruby/layer.xml @@ -231,5 +231,13 @@ + + + + + + + + diff --git a/ruby/src/org/netbeans/modules/ruby/lexer/LexUtilities.java b/ruby/src/org/netbeans/modules/ruby/lexer/LexUtilities.java --- a/ruby/src/org/netbeans/modules/ruby/lexer/LexUtilities.java +++ b/ruby/src/org/netbeans/modules/ruby/lexer/LexUtilities.java @@ -59,7 +59,6 @@ import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Utilities; import org.netbeans.modules.gsf.spi.GsfUtilities; -import org.netbeans.modules.ruby.RubyMimeResolver; import org.openide.filesystems.FileUtil; import org.openide.loaders.DataObject; import org.openide.util.Exceptions; @@ -121,7 +120,7 @@ /** For a possibly generated offset in an AST, return the corresponding lexing/true document offset */ public static int getLexerOffset(CompilationInfo info, int astOffset) { - ParserResult result = info.getEmbeddedResult(RubyMimeResolver.RUBY_MIME_TYPE, 0); + ParserResult result = info.getEmbeddedResult(RubyInstallation.RUBY_MIME_TYPE, 0); if (result != null) { TranslatedSource ts = result.getTranslatedSource(); if (ts != null) { @@ -136,7 +135,7 @@ if (astRange == OffsetRange.NONE) { return OffsetRange.NONE; } - ParserResult result = info.getEmbeddedResult(RubyMimeResolver.RUBY_MIME_TYPE, 0); + ParserResult result = info.getEmbeddedResult(RubyInstallation.RUBY_MIME_TYPE, 0); if (result != null) { TranslatedSource ts = result.getTranslatedSource(); if (ts != null) { diff --git a/ruby/src/org/netbeans/modules/ruby/lexer/RubyTokenId.java b/ruby/src/org/netbeans/modules/ruby/lexer/RubyTokenId.java --- a/ruby/src/org/netbeans/modules/ruby/lexer/RubyTokenId.java +++ b/ruby/src/org/netbeans/modules/ruby/lexer/RubyTokenId.java @@ -53,7 +53,7 @@ import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenId; import org.netbeans.api.lexer.TokenId; -import org.netbeans.modules.ruby.RubyMimeResolver; +import org.netbeans.api.ruby.platform.RubyInstallation; import org.netbeans.spi.lexer.LanguageEmbedding; import org.netbeans.spi.lexer.LanguageHierarchy; import org.netbeans.spi.lexer.Lexer; @@ -159,7 +159,7 @@ private static final Language language = new LanguageHierarchy() { protected String mimeType() { - return RubyMimeResolver.RUBY_MIME_TYPE; + return RubyInstallation.RUBY_MIME_TYPE; } protected Collection createTokenIds() { diff --git a/ruby/src/org/netbeans/modules/ruby/options/FmtOptions.java b/ruby/src/org/netbeans/modules/ruby/options/FmtOptions.java --- a/ruby/src/org/netbeans/modules/ruby/options/FmtOptions.java +++ b/ruby/src/org/netbeans/modules/ruby/options/FmtOptions.java @@ -69,10 +69,10 @@ import javax.swing.event.DocumentListener; import org.netbeans.api.editor.settings.SimpleValueNames; +import org.netbeans.api.ruby.platform.RubyInstallation; import org.netbeans.modules.options.editor.spi.PreferencesCustomizer; import org.netbeans.modules.options.editor.spi.PreviewProvider; import org.netbeans.modules.ruby.RubyFormatter; -import org.netbeans.modules.ruby.RubyMimeResolver; import org.openide.text.CloneableEditorSupport; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; @@ -301,7 +301,7 @@ previewPane.getAccessibleContext().setAccessibleName(NbBundle.getMessage(FmtOptions.class, "AN_Preview")); //NOI18N previewPane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FmtOptions.class, "AD_Preview")); //NOI18N previewPane.putClientProperty("HighlightsLayerIncludes", "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.SyntaxHighlighting$"); //NOI18N - previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(RubyMimeResolver.RUBY_MIME_TYPE)); + previewPane.setEditorKit(CloneableEditorSupport.getEditorKit(RubyInstallation.RUBY_MIME_TYPE)); previewPane.setEditable(false); } return previewPane;