diff --git a/cnd/nbproject/project.xml b/cnd/nbproject/project.xml
--- a/cnd/nbproject/project.xml
+++ b/cnd/nbproject/project.xml
@@ -225,7 +225,7 @@
- 7.13
+ 7.16
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,78 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/languages.sh/nbproject/project.xml b/languages.sh/nbproject/project.xml
--- a/languages.sh/nbproject/project.xml
+++ b/languages.sh/nbproject/project.xml
@@ -19,7 +19,7 @@
- 7.13
+ 7.16
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/shell-mime-resolver.xml=Sh Files
+
text/sh=Sh File
error=Error
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,81 +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.
- */
-@org.openide.util.lookup.ServiceProvider(service=org.openide.filesystems.MIMEResolver.class)
-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/languages.sh/src/org/netbeans/modules/languages/sh/shell-mime-resolver.xml b/languages.sh/src/org/netbeans/modules/languages/sh/shell-mime-resolver.xml
new file mode 100644
--- /dev/null
+++ b/languages.sh/src/org/netbeans/modules/languages/sh/shell-mime-resolver.xml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/php.project/nbproject/project.xml b/php.project/nbproject/project.xml
--- a/php.project/nbproject/project.xml
+++ b/php.project/nbproject/project.xml
@@ -199,7 +199,7 @@
- 7.13
+ 7.16
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,259 +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
- */
-@org.openide.util.lookup.ServiceProvider(service=org.openide.filesystems.MIMEResolver.class, position=999)
-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/php-project-mime-resolver.xml=PHP Files (content check)
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/php.project/src/org/netbeans/modules/php/project/resources/php-project-mime-resolver.xml b/php.project/src/org/netbeans/modules/php/project/resources/php-project-mime-resolver.xml
new file mode 100644
--- /dev/null
+++ b/php.project/src/org/netbeans/modules/php/project/resources/php-project-mime-resolver.xml
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ruby/nbproject/project.xml b/ruby/nbproject/project.xml
--- a/ruby/nbproject/project.xml
+++ b/ruby/nbproject/project.xml
@@ -161,7 +161,7 @@
- 7.13
+ 7.16
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/ruby-mime-resolver.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;
@@ -2073,7 +2074,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) {
@@ -3146,7 +3147,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);
@@ -3393,7 +3394,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.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,184 +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
- */
-@org.openide.util.lookup.ServiceProvider(service=org.openide.filesystems.MIMEResolver.class)
-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;
diff --git a/ruby/src/org/netbeans/modules/ruby/ruby-mime-resolver.xml b/ruby/src/org/netbeans/modules/ruby/ruby-mime-resolver.xml
new file mode 100644
--- /dev/null
+++ b/ruby/src/org/netbeans/modules/ruby/ruby-mime-resolver.xml
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ruby/test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java b/ruby/test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java
--- a/ruby/test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java
+++ b/ruby/test/unit/src/org/netbeans/modules/ruby/RubyMimeResolverTest.java
@@ -38,53 +38,74 @@
* 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 junit.framework.TestCase;
+import java.io.IOException;
+import java.io.OutputStream;
+import org.netbeans.junit.NbTestCase;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
/**
- * @author Tor Norbye
+ * @author Tor Norbye, Jiri Skrivanek
*/
-public class RubyMimeResolverTest extends TestCase {
+public class RubyMimeResolverTest extends NbTestCase {
+
public RubyMimeResolverTest(String testName) {
super(testName);
}
- private boolean checkValidHeader(String header) {
- String truncated = header.length() > RubyMimeResolver.HEADER_LENGTH ?
- header.substring(0, RubyMimeResolver.HEADER_LENGTH) : header;
- byte[] h = truncated.getBytes();
-
- return RubyMimeResolver.isRubyHeader(h);
+ public void testRubyResolver() throws IOException {
+ FileObject fo = FileUtil.createMemoryFileSystem().getRoot().createData("ruby");
+ String[] validHeaders = {
+ "#!/usr/bin/ruby",
+ "#!/usr/bin/ruby1.8",
+ "#!/usr/bin/jruby",
+ "#! /usr/bin/ruby",
+ "#! /usr/bin/ruby\n",
+ "#! /usr/bin/ruby.exe",
+ "#! /usr/bin/ruby.exe ",
+ "#!C:\\programs\\ruby.exe",
+ "#!C:\\programs\\ruby.exe",
+ "#!/Users/tor/dev/ruby/install/ruby-1.8.5/bin/ruby\n",
+ "#!/space/ruby/ruby-1.8.6-p110/bin/ruby1.8.6-p110",
+ "#!/usr/bin/env jruby -J-Xmx512M",
+ "#!/usr/bin/env ruby",
+ "#!/usr/bin/env jruby",
+ "#!/usr/bin/env.exe jruby",
+ "#!D:/Development/Ruby/ruby-1.8.6-dist/bin/ruby"
+ };
+ String[] invalidHeaders = {
+ "# !C:\\programs\\ruby.exe",
+ "#!/bin/sh",
+ //"#!/bin/rubystuff/bin/ksh", // mistakenly resolved as ruby file
+ "#!/usr/bin/rub",
+ "#!/usr/bin/",
+ "#! /usr/bin/rub\ny",
+ //"#! /usr/b\nin/ruby", // mistakenly resolved as ruby file
+ "#/usr/bin/ruby",
+ "#!/usr/bin/env.exe jrub"
+ };
+ for (String header : validHeaders) {
+ assertHeader(fo, header, "text/x-ruby");
+ }
+ for (String header : invalidHeaders) {
+ assertHeader(fo, header, "content/unknown");
+ }
+ fo = FileUtil.createMemoryFileSystem().getRoot().createData("rakefile");
+ assertEquals("rakefile should be resolved.", "text/x-ruby", fo.getMIMEType());
+ fo = FileUtil.createMemoryFileSystem().getRoot().createData("Rakefile");
+ assertEquals("rakefile should be resolved.", "text/x-ruby", fo.getMIMEType());
+ fo = FileUtil.createMemoryFileSystem().getRoot().createData("a.rb");
+ assertEquals("All .rb should be resolved.", "text/x-ruby", fo.getMIMEType());
}
- public void testRubyHeader() {
- assertTrue(checkValidHeader("#!/usr/bin/ruby"));
- assertTrue(checkValidHeader("#!/usr/bin/ruby1.8"));
- assertTrue(checkValidHeader("#!/usr/bin/jruby"));
- assertTrue(checkValidHeader("#! /usr/bin/ruby"));
- assertTrue(checkValidHeader("#! /usr/bin/ruby\n"));
- assertTrue(checkValidHeader("#! /usr/bin/ruby.exe"));
- assertTrue(checkValidHeader("#! /usr/bin/ruby.exe "));
- assertTrue(checkValidHeader("#!C:\\programs\\ruby.exe"));
- assertTrue(checkValidHeader("#!C:\\programs\\ruby.exe"));
- assertTrue(checkValidHeader("#!/Users/tor/dev/ruby/install/ruby-1.8.5/bin/ruby\n"));
- assertTrue(checkValidHeader("#!/space/ruby/ruby-1.8.6-p110/bin/ruby1.8.6-p110"));
- assertTrue(checkValidHeader("#!/usr/bin/env jruby -J-Xmx512M"));
- assertTrue(checkValidHeader("#!/usr/bin/env ruby"));
- assertTrue(checkValidHeader("#!/usr/bin/env jruby"));
- assertTrue(checkValidHeader("#!/usr/bin/env.exe jruby"));
- assertTrue(checkValidHeader("#!D:/Development/Ruby/ruby-1.8.6-dist/bin/ruby"));
-
- assertFalse(checkValidHeader("# !C:\\programs\\ruby.exe"));
- assertFalse(checkValidHeader("#!/bin/sh"));
- assertFalse(checkValidHeader("#!/bin/rubystuff/bin/ksh"));
- assertFalse(checkValidHeader("#!/usr/bin/rub"));
- assertFalse(checkValidHeader("#!/usr/bin/"));
- assertFalse(checkValidHeader("#! /usr/bin/rub\ny"));
- assertFalse(checkValidHeader("#! /usr/b\nin/ruby"));
- assertFalse(checkValidHeader("#/usr/bin/ruby"));
- assertFalse(checkValidHeader("#!/usr/bin/env.exe jrub"));
- }
+ private void assertHeader(FileObject fo, String header, String expectedMimeType) throws IOException {
+ OutputStream os = fo.getOutputStream();
+ os.write(header.getBytes());
+ os.close();
+ String mimeType = fo.getMIMEType();
+ System.out.println(header + "=mimeType=" + mimeType);
+ assertEquals("Header " + header + " wrongly resolved.", expectedMimeType, mimeType);
+ }
}
diff --git a/ruby/test/unit/src/org/netbeans/modules/ruby/RubyTestBase.java b/ruby/test/unit/src/org/netbeans/modules/ruby/RubyTestBase.java
--- a/ruby/test/unit/src/org/netbeans/modules/ruby/RubyTestBase.java
+++ b/ruby/test/unit/src/org/netbeans/modules/ruby/RubyTestBase.java
@@ -133,7 +133,7 @@
String text = RubyTestBase.read(fileObject);
BaseDocument doc = RubyTestBase.createDocument(text);
GsfTestCompilationInfo testInfo = new GsfTestCompilationInfo(this, fileObject, doc, text);
- ParserResult result = testInfo.getEmbeddedResult(RubyMimeResolver.RUBY_MIME_TYPE, 0);
+ ParserResult result = testInfo.getEmbeddedResult(RubyInstallation.RUBY_MIME_TYPE, 0);
return result;
} catch (Exception ex) {
@@ -165,7 +165,7 @@
for (FileObject child : parent.getChildren()) {
if (child.isFolder()) {
addRubyFiles(list, child);
- } else if (child.getMIMEType().equals(RubyMimeResolver.RUBY_MIME_TYPE)) {
+ } else if (child.getMIMEType().equals(RubyInstallation.RUBY_MIME_TYPE)) {
list.add(child);
}
}
diff --git a/ruby/test/unit/src/org/netbeans/modules/ruby/RubyTypeAnalyzerTest.java b/ruby/test/unit/src/org/netbeans/modules/ruby/RubyTypeAnalyzerTest.java
--- a/ruby/test/unit/src/org/netbeans/modules/ruby/RubyTypeAnalyzerTest.java
+++ b/ruby/test/unit/src/org/netbeans/modules/ruby/RubyTypeAnalyzerTest.java
@@ -43,6 +43,7 @@
import org.jruby.nb.ast.MethodDefNode;
import org.jruby.nb.ast.Node;
+import org.netbeans.api.ruby.platform.RubyInstallation;
import org.netbeans.editor.BaseDocument;
import org.netbeans.modules.gsf.GsfTestCompilationInfo;
import org.openide.filesystems.FileObject;
@@ -64,7 +65,7 @@
GsfTestCompilationInfo info = getInfo(fo);
Node root = AstUtilities.getRoot(info);
initializeRegistry();
- 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 caretOffset = -1;
if (caretLine != null) {