Experiment: usages in non-Java resources.
1.1 --- a/remoting/server/indexer/impl/nbproject/genfiles.properties Fri May 10 21:52:04 2013 +0200
1.2 +++ b/remoting/server/indexer/impl/nbproject/genfiles.properties Sat May 11 14:04:14 2013 +0200
1.3 @@ -3,6 +3,6 @@
1.4 build.xml.stylesheet.CRC32=a56c6a5b@1.47
1.5 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
1.6 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
1.7 -nbproject/build-impl.xml.data.CRC32=330c1756
1.8 +nbproject/build-impl.xml.data.CRC32=38fc9eee
1.9 nbproject/build-impl.xml.script.CRC32=87e6e497
1.10 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.51
1.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.58
2.1 --- a/remoting/server/indexer/impl/nbproject/project.xml Fri May 10 21:52:04 2013 +0200
2.2 +++ b/remoting/server/indexer/impl/nbproject/project.xml Sat May 11 14:04:14 2013 +0200
2.3 @@ -130,6 +130,15 @@
2.4 </run-dependency>
2.5 </dependency>
2.6 <dependency>
2.7 + <code-name-base>org.netbeans.modules.queries</code-name-base>
2.8 + <build-prerequisite/>
2.9 + <compile-dependency/>
2.10 + <run-dependency>
2.11 + <release-version>1</release-version>
2.12 + <specification-version>1.34</specification-version>
2.13 + </run-dependency>
2.14 + </dependency>
2.15 + <dependency>
2.16 <code-name-base>org.netbeans.modules.sendopts</code-name-base>
2.17 <build-prerequisite/>
2.18 <compile-dependency/>
3.1 --- a/remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/spi/IndexAccessor.java Fri May 10 21:52:04 2013 +0200
3.2 +++ b/remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/spi/IndexAccessor.java Sat May 11 14:04:14 2013 +0200
3.3 @@ -1,6 +1,43 @@
3.4 /*
3.5 - * To change this template, choose Tools | Templates
3.6 - * and open the template in the editor.
3.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3.8 + *
3.9 + * Copyright 2011-2012 Oracle and/or its affiliates. All rights reserved.
3.10 + *
3.11 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
3.12 + * Other names may be trademarks of their respective owners.
3.13 + *
3.14 + * The contents of this file are subject to the terms of either the GNU
3.15 + * General Public License Version 2 only ("GPL") or the Common
3.16 + * Development and Distribution License("CDDL") (collectively, the
3.17 + * "License"). You may not use this file except in compliance with the
3.18 + * License. You can obtain a copy of the License at
3.19 + * http://www.netbeans.org/cddl-gplv2.html
3.20 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
3.21 + * specific language governing permissions and limitations under the
3.22 + * License. When distributing the software, include this License Header
3.23 + * Notice in each file and include the License file at
3.24 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
3.25 + * particular file as subject to the "Classpath" exception as provided
3.26 + * by Oracle in the GPL Version 2 section of the License file that
3.27 + * accompanied this code. If applicable, add the following below the
3.28 + * License Header, with the fields enclosed by brackets [] replaced by
3.29 + * your own identifying information:
3.30 + * "Portions Copyrighted [year] [name of copyright owner]"
3.31 + *
3.32 + * If you wish your version of this file to be governed by only the CDDL
3.33 + * or only the GPL Version 2, indicate your decision by adding
3.34 + * "[Contributor] elects to include this software in this distribution
3.35 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
3.36 + * single choice of license, a recipient has the option to distribute
3.37 + * your version of this file under either the CDDL, the GPL Version 2 or
3.38 + * to extend the choice of license to its licensees as provided above.
3.39 + * However, if you add GPL Version 2 code and therefore, elected the GPL
3.40 + * Version 2 license, then the option applies only if the new code is
3.41 + * made subject to such option by the copyright holder.
3.42 + *
3.43 + * Contributor(s):
3.44 + *
3.45 + * Portions Copyrighted 2011-2012 Sun Microsystems, Inc.
3.46 */
3.47 package org.netbeans.modules.jackpot30.backend.impl.spi;
3.48
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/remoting/server/indexer/impl/src/org/netbeans/modules/jackpot30/backend/impl/spi/Utilities.java Sat May 11 14:04:14 2013 +0200
4.3 @@ -0,0 +1,88 @@
4.4 +/*
4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4.6 + *
4.7 + * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
4.8 + *
4.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
4.10 + * Other names may be trademarks of their respective owners.
4.11 + *
4.12 + * The contents of this file are subject to the terms of either the GNU
4.13 + * General Public License Version 2 only ("GPL") or the Common
4.14 + * Development and Distribution License("CDDL") (collectively, the
4.15 + * "License"). You may not use this file except in compliance with the
4.16 + * License. You can obtain a copy of the License at
4.17 + * http://www.netbeans.org/cddl-gplv2.html
4.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
4.19 + * specific language governing permissions and limitations under the
4.20 + * License. When distributing the software, include this License Header
4.21 + * Notice in each file and include the License file at
4.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
4.23 + * particular file as subject to the "Classpath" exception as provided
4.24 + * by Oracle in the GPL Version 2 section of the License file that
4.25 + * accompanied this code. If applicable, add the following below the
4.26 + * License Header, with the fields enclosed by brackets [] replaced by
4.27 + * your own identifying information:
4.28 + * "Portions Copyrighted [year] [name of copyright owner]"
4.29 + *
4.30 + * If you wish your version of this file to be governed by only the CDDL
4.31 + * or only the GPL Version 2, indicate your decision by adding
4.32 + * "[Contributor] elects to include this software in this distribution
4.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
4.34 + * single choice of license, a recipient has the option to distribute
4.35 + * your version of this file under either the CDDL, the GPL Version 2 or
4.36 + * to extend the choice of license to its licensees as provided above.
4.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
4.38 + * Version 2 license, then the option applies only if the new code is
4.39 + * made subject to such option by the copyright holder.
4.40 + *
4.41 + * Contributor(s):
4.42 + *
4.43 + * Portions Copyrighted 2013 Sun Microsystems, Inc.
4.44 + */
4.45 +package org.netbeans.modules.jackpot30.backend.impl.spi;
4.46 +
4.47 +import java.io.BufferedReader;
4.48 +import java.io.IOException;
4.49 +import java.io.InputStreamReader;
4.50 +import java.io.Reader;
4.51 +import java.nio.charset.Charset;
4.52 +import java.util.logging.Level;
4.53 +import java.util.logging.Logger;
4.54 +import org.netbeans.api.queries.FileEncodingQuery;
4.55 +import org.openide.filesystems.FileObject;
4.56 +
4.57 +/**
4.58 + *
4.59 + * @author lahvac
4.60 + */
4.61 +public class Utilities {
4.62 +
4.63 + private Utilities() { }
4.64 +
4.65 + public static String readFully(FileObject source) throws IOException {
4.66 + Reader in = null;
4.67 + StringBuilder result = new StringBuilder();
4.68 +
4.69 + try {
4.70 + Charset charset = FileEncodingQuery.getEncoding(source);
4.71 + in = new BufferedReader(new InputStreamReader(source.getInputStream(), charset));
4.72 +
4.73 + int read;
4.74 +
4.75 + while ((read = in.read()) != (-1)) {
4.76 + result.append((char) read);
4.77 + }
4.78 + } finally {
4.79 + if (in != null) {
4.80 + try {
4.81 + in.close();
4.82 + } catch (IOException ex) {
4.83 + Logger.getLogger(Utilities.class.getName()).log(Level.SEVERE, null, ex);
4.84 + }
4.85 + }
4.86 + }
4.87 +
4.88 + return result.toString();
4.89 + }
4.90 +
4.91 +}
5.1 --- a/remoting/server/indexer/source/nbproject/genfiles.properties Fri May 10 21:52:04 2013 +0200
5.2 +++ b/remoting/server/indexer/source/nbproject/genfiles.properties Sat May 11 14:04:14 2013 +0200
5.3 @@ -3,6 +3,6 @@
5.4 build.xml.stylesheet.CRC32=a56c6a5b@2.45
5.5 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5.6 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
5.7 -nbproject/build-impl.xml.data.CRC32=006ca2fd
5.8 +nbproject/build-impl.xml.data.CRC32=d1935879
5.9 nbproject/build-impl.xml.script.CRC32=279e9fd9
5.10 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.45
5.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.53
6.1 --- a/remoting/server/indexer/source/src/org/netbeans/modules/jackpot30/indexer/source/SourceIndexer.java Fri May 10 21:52:04 2013 +0200
6.2 +++ b/remoting/server/indexer/source/src/org/netbeans/modules/jackpot30/indexer/source/SourceIndexer.java Sat May 11 14:04:14 2013 +0200
6.3 @@ -41,11 +41,7 @@
6.4 */
6.5 package org.netbeans.modules.jackpot30.indexer.source;
6.6
6.7 -import java.io.BufferedReader;
6.8 import java.io.IOException;
6.9 -import java.io.InputStreamReader;
6.10 -import java.io.Reader;
6.11 -import java.nio.charset.Charset;
6.12 import java.util.logging.Level;
6.13 import java.util.logging.Logger;
6.14 import org.apache.lucene.document.CompressionTools;
6.15 @@ -54,8 +50,8 @@
6.16 import org.apache.lucene.document.Field.Index;
6.17 import org.apache.lucene.document.Field.Store;
6.18 import org.netbeans.api.editor.mimelookup.MimeRegistration;
6.19 -import org.netbeans.api.queries.FileEncodingQuery;
6.20 import org.netbeans.modules.jackpot30.backend.impl.spi.IndexAccessor;
6.21 +import org.netbeans.modules.jackpot30.backend.impl.spi.Utilities;
6.22 import org.netbeans.modules.parsing.spi.indexing.Context;
6.23 import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
6.24 import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
6.25 @@ -90,7 +86,7 @@
6.26 Document doc = new Document();
6.27
6.28 doc.add(new Field("relativePath", relPath, Store.YES, Index.NOT_ANALYZED));
6.29 - doc.add(new Field(KEY_CONTENT, CompressionTools.compressString(readFully(file)), Store.YES));
6.30 + doc.add(new Field(KEY_CONTENT, CompressionTools.compressString(Utilities.readFully(file)), Store.YES));
6.31 doc.add(new Field("fileMimeType", file.getMIMEType(), Store.YES, Index.NO));
6.32 doc.add(new Field("sizeInBytes", Long.toString(file.getSize()), Store.YES, Index.NO));
6.33
6.34 @@ -101,32 +97,6 @@
6.35 }
6.36 }
6.37
6.38 - private static String readFully(FileObject source) throws IOException {
6.39 - Reader in = null;
6.40 - StringBuilder result = new StringBuilder();
6.41 -
6.42 - try {
6.43 - Charset charset = FileEncodingQuery.getEncoding(source);
6.44 - in = new BufferedReader(new InputStreamReader(source.getInputStream(), charset));
6.45 -
6.46 - int read;
6.47 -
6.48 - while ((read = in.read()) != (-1)) {
6.49 - result.append((char) read);
6.50 - }
6.51 - } finally {
6.52 - if (in != null) {
6.53 - try {
6.54 - in.close();
6.55 - } catch (IOException ex) {
6.56 - Logger.getLogger(SourceIndexer.class.getName()).log(Level.SEVERE, null, ex);
6.57 - }
6.58 - }
6.59 - }
6.60 -
6.61 - return result.toString();
6.62 - }
6.63 -
6.64 @MimeRegistration(mimeType="", service=CustomIndexerFactory.class)
6.65 public static final class FactoryImpl extends CustomIndexerFactory {
6.66
7.1 --- a/remoting/server/indexer/usages/nbproject/genfiles.properties Fri May 10 21:52:04 2013 +0200
7.2 +++ b/remoting/server/indexer/usages/nbproject/genfiles.properties Sat May 11 14:04:14 2013 +0200
7.3 @@ -3,6 +3,6 @@
7.4 build.xml.stylesheet.CRC32=a56c6a5b@2.47
7.5 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
7.6 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
7.7 -nbproject/build-impl.xml.data.CRC32=80410336
7.8 +nbproject/build-impl.xml.data.CRC32=fe444955
7.9 nbproject/build-impl.xml.script.CRC32=16d3b827
7.10 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.47
7.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.58
8.1 --- a/remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImpl.java Fri May 10 21:52:04 2013 +0200
8.2 +++ b/remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/IndexerImpl.java Sat May 11 14:04:14 2013 +0200
8.3 @@ -106,8 +106,8 @@
8.4 public class IndexerImpl implements JavaIndexerPlugin {
8.5
8.6 private static final boolean NAVIGABLE = Boolean.getBoolean("jackpot.navigable.index");
8.7 - private static final String KEY_SIGNATURES = "signatures";
8.8 - private static final String KEY_MARKER = "usagesIndexMarker";
8.9 + static final String KEY_SIGNATURES = "signatures";
8.10 + static final String KEY_MARKER = "usagesIndexMarker";
8.11
8.12 private final URL root;
8.13
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/remoting/server/indexer/usages/src/org/netbeans/modules/jackpot30/indexer/usages/ResourceIndexerImpl.java Sat May 11 14:04:14 2013 +0200
9.3 @@ -0,0 +1,176 @@
9.4 +/*
9.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9.6 + *
9.7 + * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
9.8 + *
9.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
9.10 + * Other names may be trademarks of their respective owners.
9.11 + *
9.12 + * The contents of this file are subject to the terms of either the GNU
9.13 + * General Public License Version 2 only ("GPL") or the Common
9.14 + * Development and Distribution License("CDDL") (collectively, the
9.15 + * "License"). You may not use this file except in compliance with the
9.16 + * License. You can obtain a copy of the License at
9.17 + * http://www.netbeans.org/cddl-gplv2.html
9.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
9.19 + * specific language governing permissions and limitations under the
9.20 + * License. When distributing the software, include this License Header
9.21 + * Notice in each file and include the License file at
9.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
9.23 + * particular file as subject to the "Classpath" exception as provided
9.24 + * by Oracle in the GPL Version 2 section of the License file that
9.25 + * accompanied this code. If applicable, add the following below the
9.26 + * License Header, with the fields enclosed by brackets [] replaced by
9.27 + * your own identifying information:
9.28 + * "Portions Copyrighted [year] [name of copyright owner]"
9.29 + *
9.30 + * If you wish your version of this file to be governed by only the CDDL
9.31 + * or only the GPL Version 2, indicate your decision by adding
9.32 + * "[Contributor] elects to include this software in this distribution
9.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
9.34 + * single choice of license, a recipient has the option to distribute
9.35 + * your version of this file under either the CDDL, the GPL Version 2 or
9.36 + * to extend the choice of license to its licensees as provided above.
9.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
9.38 + * Version 2 license, then the option applies only if the new code is
9.39 + * made subject to such option by the copyright holder.
9.40 + *
9.41 + * Contributor(s):
9.42 + *
9.43 + * Portions Copyrighted 2013 Sun Microsystems, Inc.
9.44 + */
9.45 +package org.netbeans.modules.jackpot30.indexer.usages;
9.46 +
9.47 +import java.io.IOException;
9.48 +import java.util.HashSet;
9.49 +import java.util.Set;
9.50 +import java.util.regex.Matcher;
9.51 +import java.util.regex.Pattern;
9.52 +import org.apache.lucene.document.Document;
9.53 +import org.apache.lucene.document.Field;
9.54 +import org.apache.lucene.document.Field.Index;
9.55 +import org.apache.lucene.document.Field.Store;
9.56 +import org.apache.lucene.index.Term;
9.57 +import org.apache.lucene.search.BooleanClause;
9.58 +import org.apache.lucene.search.BooleanClause.Occur;
9.59 +import org.apache.lucene.search.BooleanQuery;
9.60 +import org.apache.lucene.search.TermQuery;
9.61 +import org.netbeans.api.editor.mimelookup.MimeRegistration;
9.62 +import org.netbeans.modules.jackpot30.backend.impl.spi.IndexAccessor;
9.63 +import org.netbeans.modules.jackpot30.backend.impl.spi.Utilities;
9.64 +import org.netbeans.modules.parsing.spi.indexing.Context;
9.65 +import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
9.66 +import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
9.67 +import org.netbeans.modules.parsing.spi.indexing.Indexable;
9.68 +import org.openide.filesystems.FileObject;
9.69 +import org.openide.filesystems.URLMapper;
9.70 +import org.openide.util.Exceptions;
9.71 +
9.72 +/**
9.73 + *
9.74 + * @author lahvac
9.75 + */
9.76 +public class ResourceIndexerImpl extends CustomIndexer {
9.77 +
9.78 + @Override
9.79 + protected void index(Iterable<? extends Indexable> files, Context context) {
9.80 + for (Indexable indexable : files) {
9.81 + doIndexFile(indexable);
9.82 + }
9.83 + }
9.84 +
9.85 + private static final Pattern INTERESTING_PATTERN = Pattern.compile("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*([.-]\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)+");
9.86 +
9.87 + private void doIndexFile(Indexable indexable) {
9.88 + if (!IndexAccessor.getCurrent().isAcceptable(indexable.getURL()) || "text/x-java".equals(indexable.getMimeType())) return;
9.89 + try {
9.90 + doDelete(indexable);
9.91 +
9.92 + FileObject file = URLMapper.findFileObject(indexable.getURL());
9.93 +
9.94 + if (file == null) return ;
9.95 +
9.96 + final String relative = IndexAccessor.getCurrent().getPath(indexable.getURL());
9.97 + final Document usages = new Document();
9.98 +
9.99 + usages.add(new Field("file", relative, Store.YES, Index.NOT_ANALYZED));
9.100 + usages.add(new Field(IndexerImpl.KEY_MARKER, "true", Store.NO, Index.NOT_ANALYZED));
9.101 +
9.102 + //sources indexer does the same, we should really look into files only once!
9.103 + String content = Utilities.readFully(file);
9.104 + Matcher matcher = INTERESTING_PATTERN.matcher(content);
9.105 + Set<String> SEEN_SIGNATURES = new HashSet<String>();
9.106 +
9.107 + while (matcher.find()) {
9.108 + String reference = matcher.group();
9.109 + String[] elements = reference.split("[.-]");
9.110 + StringBuilder currentElement = new StringBuilder();
9.111 +
9.112 + currentElement.append(elements[0]);
9.113 +
9.114 + for (int i = 1; i < elements.length; i++) {
9.115 + currentElement.append(".");
9.116 + currentElement.append(elements[i]);
9.117 + String serialized = "OTHER:" + currentElement.toString();
9.118 +
9.119 + if (SEEN_SIGNATURES.add(serialized)) {
9.120 + usages.add(new Field(IndexerImpl.KEY_SIGNATURES, serialized, Store.YES, Index.NOT_ANALYZED));
9.121 + }
9.122 + }
9.123 + }
9.124 +
9.125 + IndexAccessor.getCurrent().getIndexWriter().addDocument(usages);
9.126 + } catch (IOException ex) {
9.127 + Exceptions.printStackTrace(ex);
9.128 + }
9.129 + }
9.130 +
9.131 + private static void doDelete(Indexable indexable) throws IOException {
9.132 + BooleanQuery q = new BooleanQuery();
9.133 +
9.134 + q.add(new BooleanClause(new TermQuery(new Term("file", IndexAccessor.getCurrent().getPath(indexable.getURL()))), Occur.MUST));
9.135 + q.add(new BooleanClause(new TermQuery(new Term(IndexerImpl.KEY_MARKER, "true")), Occur.MUST));
9.136 +
9.137 + IndexAccessor.getCurrent().getIndexWriter().deleteDocuments(q);
9.138 + }
9.139 +
9.140 + @MimeRegistration(mimeType="", service=CustomIndexerFactory.class)
9.141 + public static final class FactoryImpl extends CustomIndexerFactory {
9.142 +
9.143 + @Override
9.144 + public CustomIndexer createIndexer() {
9.145 + return new ResourceIndexerImpl();
9.146 + }
9.147 +
9.148 + @Override
9.149 + public boolean supportsEmbeddedIndexers() {
9.150 + return true;
9.151 + }
9.152 +
9.153 + @Override
9.154 + public void filesDeleted(Iterable<? extends Indexable> deleted, Context context) {
9.155 + for (Indexable indexable : deleted) {
9.156 + try {
9.157 + doDelete(indexable);
9.158 + } catch (IOException ex) {
9.159 + Exceptions.printStackTrace(ex);
9.160 + }
9.161 + }
9.162 + }
9.163 +
9.164 + @Override
9.165 + public void filesDirty(Iterable<? extends Indexable> dirty, Context context) { }
9.166 +
9.167 + @Override
9.168 + public String getIndexerName() {
9.169 + return "resource-usages-indexer";
9.170 + }
9.171 +
9.172 + @Override
9.173 + public int getIndexVersion() {
9.174 + return 1;
9.175 + }
9.176 +
9.177 + }
9.178 +
9.179 +}