This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 204817
Collapse All | Expand All

(-)a/ide.kit/test/qa-functional/data/whitelist_3.txt (-2 lines)
Lines 82-89 Link Here
82
82
83
83
84
#200050
84
#200050
85
org.netbeans.modules.spring.beans.index.SpringBinaryIndexer
86
org.netbeans.modules.spring.beans.index.SpringBinaryIndexer$Factory
87
org.netbeans.modules.web.beans.analysis.CdiEditorAnalysisFactory
85
org.netbeans.modules.web.beans.analysis.CdiEditorAnalysisFactory
88
org.netbeans.modules.web.beans.analysis.WebBeansModelAnalysisFactory
86
org.netbeans.modules.web.beans.analysis.WebBeansModelAnalysisFactory
89
org.netbeans.modules.web.el.ELIndexer$Factory
87
org.netbeans.modules.web.el.ELIndexer$Factory
(-)a/parsing.api/apichanges.xml (+17 lines)
Lines 110-115 Link Here
110
<!-- ACTUAL CHANGES BEGIN HERE: -->
110
<!-- ACTUAL CHANGES BEGIN HERE: -->
111
111
112
  <changes>
112
  <changes>
113
  <change id="ConstrainedBinaryIndexer">
114
      <api name="ParsingAPI"/>
115
      <summary>Added <code>ConstrainedBinaryIndexer</code> to prevent indexer creation when constrained are not fulfilled.</summary>
116
      <version major="1" minor="48"/>
117
      <date day="10" month="11" year="2011"/>
118
      <author login="tzezula"/>
119
      <compatibility source="compatible" binary="compatible" semantic="compatible" deletion="no" addition="yes" modification="no"/>
120
      <description>
121
          <p>
122
              Added <code>ConstrainedBinaryIndexer</code> to prevent indexer creation and calling when declared
123
              constrained are not fulfilled. The <code>ConstrainedBinaryIndexer</code> allows an indexer to specify
124
              constrains which need to be fulfilled, the check is done by infrastructure before the indexer is loaded.
125
          </p>
126
      </description>
127
      <class package="org.netbeans.modules.parsing.spi.indexing" name="ConstrainedBinaryIndexer"/>
128
      <issue number="200050"/>
129
  </change>
113
  <change id="IndexingManager-refreshIndexAndWait-checkEditor">
130
  <change id="IndexingManager-refreshIndexAndWait-checkEditor">
114
      <api name="ParsingAPI"/>
131
      <api name="ParsingAPI"/>
115
      <summary>Adding refreshIndexAndWait method into the IndexingManager allowing to specify if indexers should use modified content of editors</summary>
132
      <summary>Adding refreshIndexAndWait method into the IndexingManager allowing to specify if indexers should use modified content of editors</summary>
(-)a/parsing.api/nbproject/project.properties (-1 / +1 lines)
Lines 3-6 Link Here
3
javac.source=1.6
3
javac.source=1.6
4
javadoc.apichanges=${basedir}/apichanges.xml
4
javadoc.apichanges=${basedir}/apichanges.xml
5
javadoc.arch=${basedir}/arch.xml
5
javadoc.arch=${basedir}/arch.xml
6
spec.version.base=1.47.0
6
spec.version.base=1.48.0
(-)a/parsing.api/nbproject/project.xml (-1 / +1 lines)
Lines 162-168 Link Here
162
                    <build-prerequisite/>
162
                    <build-prerequisite/>
163
                    <compile-dependency/>
163
                    <compile-dependency/>
164
                    <run-dependency>
164
                    <run-dependency>
165
                        <specification-version>7.37</specification-version>
165
                        <specification-version>7.50</specification-version>
166
                    </run-dependency>
166
                    </run-dependency>
167
                </dependency>
167
                </dependency>
168
                <dependency>
168
                <dependency>
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/IndexerRegistrationProcessor.java (+121 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.parsing.impl.indexing;
43
44
import java.util.Collections;
45
import java.util.Set;
46
import javax.annotation.processing.Processor;
47
import javax.annotation.processing.RoundEnvironment;
48
import javax.annotation.processing.SupportedSourceVersion;
49
import javax.lang.model.SourceVersion;
50
import javax.lang.model.element.Element;
51
import javax.lang.model.element.TypeElement;
52
import javax.lang.model.util.Elements;
53
import javax.lang.model.util.Types;
54
import org.netbeans.modules.parsing.spi.indexing.BinaryIndexerFactory;
55
import org.netbeans.modules.parsing.spi.indexing.ConstrainedBinaryIndexer;
56
import org.openide.filesystems.annotations.LayerBuilder.File;
57
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
58
import org.openide.filesystems.annotations.LayerGenerationException;
59
import org.openide.util.lookup.ServiceProvider;
60
61
/**
62
 * {@link LayerGeneratingProcessor} to generate {@link BinaryIndexer} registrations.
63
 * @author Jaroslav Tulach <jtulach@netbeans.org>
64
 * @author Tomas Zezula
65
 */
66
@ServiceProvider(service=Processor.class)
67
@SupportedSourceVersion(SourceVersion.RELEASE_6)
68
public final class IndexerRegistrationProcessor extends LayerGeneratingProcessor {
69
70
    @Override
71
    public Set<String> getSupportedAnnotationTypes() {
72
        return Collections.singleton(ConstrainedBinaryIndexer.Registration.class.getCanonicalName());
73
    }
74
    
75
    @Override
76
    protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
77
        for (Element e : roundEnv.getElementsAnnotatedWith(ConstrainedBinaryIndexer.Registration.class)) {
78
            assert e.getKind().isClass();
79
            final ConstrainedBinaryIndexer.Registration reg = e.getAnnotation(ConstrainedBinaryIndexer.Registration.class);
80
            final Elements elements = processingEnv.getElementUtils();
81
            final Types types = processingEnv.getTypeUtils();
82
            final TypeElement binIndexerType = elements.getTypeElement(ConstrainedBinaryIndexer.class.getName());
83
            if (types.isSubtype(((TypeElement)e).asType(), binIndexerType.asType())) {
84
                final String indexerName = reg.indexerName();
85
                if (indexerName == null) {
86
                    throw new LayerGenerationException("Indexer name has to be given.", e); //NOI18N
87
                }
88
                final File f = layer(e).instanceFile("Editors", null, null);    //NOI18N
89
                f.stringvalue("instanceClass", BinaryIndexerFactory.class.getName());   //NOI18N
90
                f.methodvalue("instanceCreate", ConstrainedBinaryIndexer.class.getName(), "create");    //NOI18N
91
                f.instanceAttribute("delegate", ConstrainedBinaryIndexer.class);
92
                if (reg.requiredResource().length > 0) {
93
                    f.stringvalue("requiredResource", list(reg.requiredResource(), e)); //NOI18N
94
                }
95
                if (reg.mimeType().length > 0) {
96
                    f.stringvalue("mimeType", list(reg.mimeType(), e)); //NOI18N
97
                }
98
                f.stringvalue("name", indexerName);         //NOI18N
99
                f.intvalue("version", reg.indexVersion());  //NOI18N
100
                f.write();
101
            } else {
102
                throw new LayerGenerationException("Annoated element is not a  subclass of BinaryIndexer.",e); //NOI18N
103
            }
104
        }
105
        return true;
106
    }
107
108
    private static String list(String[] arr, Element e) throws LayerGenerationException {
109
        if (arr.length == 1) {
110
            return arr[0];
111
        }
112
        StringBuilder sb = new StringBuilder();
113
        for (String s : arr) {
114
            if (s.indexOf(',') >= 0) {  //NOI18N
115
                throw new LayerGenerationException("',' is not allowed in the text", e);    //NOI18N
116
            }
117
            sb.append(s).append(",");   //NOI18N
118
        }
119
        return sb.substring(0, sb.length() - 1);
120
    }
121
}
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/ProxyBinaryIndexerFactory.java (+212 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.parsing.impl.indexing;
43
44
import java.net.URL;
45
import java.util.*;
46
import org.netbeans.api.annotations.common.CheckForNull;
47
import org.netbeans.api.annotations.common.NonNull;
48
import org.netbeans.modules.parsing.spi.indexing.BinaryIndexer;
49
import org.netbeans.modules.parsing.spi.indexing.BinaryIndexerFactory;
50
import org.netbeans.modules.parsing.spi.indexing.ConstrainedBinaryIndexer;
51
import org.netbeans.modules.parsing.spi.indexing.Context;
52
import org.openide.filesystems.FileObject;
53
import org.openide.util.Parameters;
54
55
/**
56
 *
57
 * @author Jaroslav Tulach <jtulach@netbeans.org>
58
 * @author Tomas Zezula
59
 */
60
public final class ProxyBinaryIndexerFactory extends BinaryIndexerFactory {
61
62
    private static final String ATTR_DELEGATE = "delegate";     //NOI18N
63
    private static final String ATTR_INDEXER_NAME = "name";     //NOI18N
64
    private static final String ATTR_INDEXER_VERSION = "version";   //NOI18N
65
    private static final String ATTR_REQUIRED_RES = "requiredResource"; //NOI18N
66
    private static final String ATTR_REQUIRED_MIME = "mimeType";    //NOI18N
67
    private static final String PROP_CHECKED = "ProxyBinaryIndexerFactory_checked";  //NOI18N
68
    private static final String PROP_MATCHED_FILES = "ProxyBinaryIndexerFactory_matchedFiles";  //NOI18N
69
70
    private final Map<String,Object> params;
71
    private final String indexerName;
72
    private final int indexerVersion;
73
    @org.netbeans.api.annotations.common.SuppressWarnings(
74
            value="DMI_COLLECTION_OF_URLS"
75
            /*,justification="URLs have never host part"*/)    //NOI18N
76
    private final Set<URL> activeRoots;
77
78
    public ProxyBinaryIndexerFactory(
79
            @NonNull final Map<String,Object> params) {
80
        Parameters.notNull("params", params);       //NOI18N
81
        this.params = params;
82
        indexerName = (String)params.get(ATTR_INDEXER_NAME);
83
        Parameters.notNull("indexerName", indexerName);     //NOI18N
84
        Integer iv = (Integer)params.get(ATTR_INDEXER_VERSION);
85
        Parameters.notNull("version", iv);                  //NOI18N
86
        indexerVersion = iv;
87
        activeRoots = new HashSet<URL>();
88
    }
89
90
    @Override
91
    public String getIndexerName() {
92
        return indexerName;
93
    }
94
95
    @Override
96
    public int getIndexVersion() {
97
        return indexerVersion;
98
    }
99
100
    @Override
101
    public BinaryIndexer createIndexer() {
102
        return new Indexer();
103
    }
104
105
    @Override
106
    public void rootsRemoved(Iterable<? extends URL> removedRoots) {
107
        final Set<URL> filtered = new HashSet<URL>();
108
        for (URL removedRoot : removedRoots) {
109
            if (activeRoots.remove(removedRoot)) {
110
                filtered.add(removedRoot);
111
            }
112
        }
113
        SPIAccessor.getInstance().rootsRemoved(
114
                getDelegate(),
115
                Collections.unmodifiableSet(filtered));
116
    }
117
118
    @Override
119
    public boolean scanStarted (final Context context) {
120
        if (supports(context) != null) {
121
            return SPIAccessor.getInstance().scanStarted(getDelegate(),context);
122
        }
123
        return true;
124
    }
125
126
    @Override
127
    public void scanFinished (final Context context) {
128
        if (supports(context) != null) {
129
            SPIAccessor.getInstance().scanFinished(getDelegate(),context);
130
        }
131
    }
132
133
134
    @CheckForNull
135
    private Map<String,? extends Iterable<? extends FileObject>> supports(@NonNull final Context ctx) {
136
        final FileObject root = ctx.getRoot();
137
        if (root == null) {
138
            return null;
139
        }
140
        if (Boolean.TRUE == SPIAccessor.getInstance().getProperty(ctx, PROP_CHECKED)) {
141
            return (Map<String,? extends Iterable<? extends FileObject>>) SPIAccessor.getInstance().getProperty(ctx, PROP_MATCHED_FILES);
142
        }
143
        final Map<String,Queue<FileObject>> matchedFiles = new HashMap<String, Queue<FileObject>>();
144
145
        String s = (String) params.get(ATTR_REQUIRED_RES);
146
        final String[] requiredResources = s == null ? null : s.split(","); //NOI18N
147
        s = (String) params.get(ATTR_REQUIRED_MIME);
148
        final String[] mimeTypes = s == null ? null : s.split(",");         //NOI18N
149
        try {
150
            if (requiredResources != null) {
151
                boolean found = false;
152
                for (String r : requiredResources) {
153
                    if (root.getFileObject(r) != null) {
154
                        found = true;
155
                        break;
156
                    }
157
                }
158
                if (!found) {
159
                    return null;
160
                }
161
            }
162
            if (mimeTypes != null) {
163
                final Enumeration<? extends FileObject> fos = root.getChildren(true);
164
                final Set<String> mimeTypesSet = new HashSet<String>(Arrays.asList(mimeTypes));
165
                while (fos.hasMoreElements()) {
166
                    final FileObject f = fos.nextElement();
167
                    final String mt = f.getMIMEType(mimeTypes);
168
                    if (mimeTypesSet.contains(mt)) {
169
                        Queue<FileObject> q = matchedFiles.get(mt);
170
                        if (q == null) {
171
                            q = new ArrayDeque<FileObject>();
172
                            matchedFiles.put(mt, q);
173
                        }
174
                        q.offer(f);
175
                    }
176
                }
177
                if (matchedFiles.isEmpty()) {
178
                    return null;
179
                }
180
            }
181
            final Map<String, ? extends Iterable<? extends FileObject>> res = Collections.unmodifiableMap(matchedFiles);
182
            SPIAccessor.getInstance().putProperty(ctx, PROP_MATCHED_FILES, res);
183
            return res;
184
        } finally {
185
            SPIAccessor.getInstance().putProperty(ctx, PROP_CHECKED, Boolean.TRUE);
186
        }
187
    }
188
189
    @NonNull
190
    private ConstrainedBinaryIndexer getDelegate() {
191
        final Object delegate = params.get(ATTR_DELEGATE);
192
        if (!(delegate instanceof ConstrainedBinaryIndexer)) {
193
            throw new IllegalArgumentException();
194
        }
195
        return (ConstrainedBinaryIndexer) delegate;
196
    }
197
198
    private final class Indexer extends BinaryIndexer {
199
200
        @Override
201
        protected void index(@NonNull final Context context) {
202
            final Map<String,? extends Iterable<? extends FileObject>> matchedFiles = supports(context);
203
            if (matchedFiles != null) {
204
                activeRoots.add(context.getRootURI());
205
                SPIAccessor.getInstance().index(
206
                    getDelegate(),
207
                    matchedFiles,
208
                    context);
209
            }
210
        }
211
    }
212
}
(-)a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/SPIAccessor.java (-5 / +15 lines)
Lines 44-56 Link Here
44
44
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.net.URL;
46
import java.net.URL;
47
import java.util.Map;
48
import org.netbeans.api.annotations.common.NonNull;
47
import org.netbeans.api.annotations.common.NullAllowed;
49
import org.netbeans.api.annotations.common.NullAllowed;
48
import org.netbeans.modules.parsing.spi.Parser;
50
import org.netbeans.modules.parsing.spi.Parser;
49
import org.netbeans.modules.parsing.spi.indexing.BinaryIndexer;
51
import org.netbeans.modules.parsing.spi.indexing.*;
50
import org.netbeans.modules.parsing.spi.indexing.Context;
51
import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
52
import org.netbeans.modules.parsing.spi.indexing.EmbeddingIndexer;
53
import org.netbeans.modules.parsing.spi.indexing.Indexable;
54
import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport;
52
import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport;
55
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileObject;
56
import org.openide.util.Exceptions;
54
import org.openide.util.Exceptions;
Lines 128-137 Link Here
128
126
129
    public abstract void index (BinaryIndexer indexer, Context context);
127
    public abstract void index (BinaryIndexer indexer, Context context);
130
128
129
    public abstract void index (@NonNull ConstrainedBinaryIndexer indexer, @NonNull Map<String,? extends Iterable<? extends FileObject>> files, @NonNull Context context);
130
131
    public abstract void index (CustomIndexer indexer, Iterable<? extends Indexable> files, Context context);
131
    public abstract void index (CustomIndexer indexer, Iterable<? extends Indexable> files, Context context);
132
132
133
    public abstract void index (EmbeddingIndexer indexer, Indexable indexable, Parser.Result parserResult, Context ctx);
133
    public abstract void index (EmbeddingIndexer indexer, Indexable indexable, Parser.Result parserResult, Context ctx);
134
134
135
    public abstract void setAllFilesJob (Context context, boolean allFilesJob);
135
    public abstract void setAllFilesJob (Context context, boolean allFilesJob);
136
136
137
    public abstract boolean scanStarted(@NonNull ConstrainedBinaryIndexer indexer, @NonNull Context context);
138
139
    public abstract void scanFinished(@NonNull ConstrainedBinaryIndexer indexer, @NonNull Context context);
140
141
    public abstract void rootsRemoved(@NonNull ConstrainedBinaryIndexer indexer, @NonNull Iterable<? extends URL> removed);
142
143
    public abstract void putProperty(@NonNull Context context, @NonNull String propName, @NullAllowed Object value);
144
145
    public abstract Object getProperty(@NonNull Context context, @NonNull String propName);
146
137
}
147
}
(-)a/parsing.api/src/org/netbeans/modules/parsing/spi/indexing/ConstrainedBinaryIndexer.java (+164 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2011 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.parsing.spi.indexing;
43
44
import java.lang.annotation.ElementType;
45
import java.lang.annotation.Retention;
46
import java.lang.annotation.RetentionPolicy;
47
import java.lang.annotation.Target;
48
import java.net.URL;
49
import java.util.Map;
50
import org.netbeans.api.annotations.common.NonNull;
51
import org.netbeans.modules.parsing.impl.indexing.ProxyBinaryIndexerFactory;
52
import org.openide.filesystems.FileObject;
53
54
/**
55
 * An binary indexer with declared constrains on the binary.
56
 * The subclasses of this indexer are registered by {@link ConstrainedBinaryIndexer.Registration}.
57
 * @author Tomas Zezula
58
 * @author Jaroslav Tulach <jtulach@netbeans.org>
59
 * @since 1.48
60
 */
61
public abstract class ConstrainedBinaryIndexer {
62
63
    /**
64
     * Indexes given binary root.
65
     * @param files the files passed the mime type constrain check, categorized
66
     * by the mime types.
67
     * @param context of indexer, contains information about index storage, indexed root.
68
     */
69
    protected abstract void index(
70
        @NonNull Map<String, ? extends Iterable<? extends FileObject>> files,
71
        @NonNull Context context);
72
73
    /**
74
     * Notifies the indexer that a binary root is going to be scanned.
75
     *
76
     * @param context The indexed binary root.
77
     *
78
     * @return <code>false</code> means that the whole root should be rescanned
79
     *   (eg. no up to date check is done, etc)
80
     */
81
    protected boolean scanStarted (@NonNull final Context context) {
82
        return true;
83
    }
84
85
    /**
86
     * Notifies the indexer that scanning of a binary root just finished.
87
     *
88
     * @param context The indexed binary root.
89
     *
90
     */
91
    protected void scanFinished (@NonNull final Context context) {
92
    }
93
94
    /**
95
     * Called by indexing infrastructure to notify indexer that roots were deregistered,
96
     * for example the project owning these roots was closed. The indexer may free memory caches
97
     * for given roots or do any other clean up.
98
     *
99
     * @param removedRoots the iterable of removed roots
100
     */
101
    protected void rootsRemoved (@NonNull final Iterable<? extends URL> removedRoots) {
102
    }
103
104
    /**
105
     * The annotation to register {@link ConstrainedBinaryIndexer} with constrains on
106
     * the scanned binary. The registered indexer is loaded and executed only of
107
     * the constrains are fulfilled.
108
     *
109
     */
110
    @Target(ElementType.TYPE)
111
    @Retention(RetentionPolicy.SOURCE)
112
    public @interface Registration {
113
114
        /**
115
         * Return the name of this indexer. This name should be unique because
116
         * GSF will use this name to produce a separate data directory for each
117
         * indexer where it has its own storage.
118
         *
119
         * @return The indexer name. This does not need to be localized since it
120
         * is never shown to the user, but should contain filesystem safe
121
         * characters.
122
         *
123
         * @see BinaryIndexerFactory
124
         */
125
        String indexerName();
126
127
        /**
128
         * Return the version stamp of the schema that is currently being stored
129
         * by this indexer. Along with the index name this string will be used
130
         * to create a unique data directory for the database.
131
         *
132
         * Whenever you incompatibly change what is stored by the indexer,
133
         * update the version stamp.
134
         *
135
         * @return The version stamp of the current index.
136
         *
137
         * @see BinaryIndexerFactory
138
         */
139
        int indexVersion();
140
141
        /**
142
         * At least one of these resources has to be present to trigger this
143
         * indexer. Use
144
         * <code>{}</code> if the resource check should be skipped.
145
         *
146
         * @return one or more paths inside the binary files that will be
147
         * checked for existence
148
         */
149
        String[] requiredResource() default {};
150
151
        /**
152
         * One or more mime types that have to be present inside of the binary
153
         * to enable this indexer. Use
154
         * <code>{}</code> if the resource check should be skipped.
155
         *
156
         * @return one or more mimetypes this indexer processing
157
         */
158
        String[] mimeType() default {};
159
    }
160
161
    private static BinaryIndexerFactory create(final Map<String,Object> params) {
162
        return new ProxyBinaryIndexerFactory(params);
163
    }
164
}
(-)a/parsing.api/src/org/netbeans/modules/parsing/spi/indexing/Context.java (+18 lines)
Lines 45-52 Link Here
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.net.URL;
46
import java.net.URL;
47
import java.util.Collection;
47
import java.util.Collection;
48
import java.util.HashMap;
49
import java.util.Map;
48
import java.util.logging.Level;
50
import java.util.logging.Level;
49
import java.util.logging.Logger;
51
import java.util.logging.Logger;
52
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.api.annotations.common.NullAllowed;
53
import org.netbeans.api.annotations.common.NullAllowed;
51
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
54
import org.netbeans.modules.parsing.api.indexing.IndexingManager;
52
import org.netbeans.modules.parsing.impl.indexing.CancelRequest;
55
import org.netbeans.modules.parsing.impl.indexing.CancelRequest;
Lines 59-64 Link Here
59
import org.openide.filesystems.FileUtil;
62
import org.openide.filesystems.FileUtil;
60
import org.openide.filesystems.URLMapper;
63
import org.openide.filesystems.URLMapper;
61
import org.openide.util.Exceptions;
64
import org.openide.util.Exceptions;
65
import org.openide.util.Parameters;
62
66
63
/**
67
/**
64
 * Represents a context of indexing given root.
68
 * Represents a context of indexing given root.
Lines 76-81 Link Here
76
    private final boolean sourceForBinaryRoot;
80
    private final boolean sourceForBinaryRoot;
77
    private final CancelRequest cancelRequest;
81
    private final CancelRequest cancelRequest;
78
    private final LogContext logContext;
82
    private final LogContext logContext;
83
    private final Map<String,Object> props;
79
    private FileObject indexFolder;
84
    private FileObject indexFolder;
80
    private boolean allFilesJob;
85
    private boolean allFilesJob;
81
86
Lines 105-110 Link Here
105
        this.sourceForBinaryRoot = sourceForBinaryRoot;
110
        this.sourceForBinaryRoot = sourceForBinaryRoot;
106
        this.cancelRequest = cancelRequest;
111
        this.cancelRequest = cancelRequest;
107
        this.logContext = logContext;
112
        this.logContext = logContext;
113
        this.props = new HashMap<String, Object>();
108
    }
114
    }
109
115
110
    // -----------------------------------------------------------------------
116
    // -----------------------------------------------------------------------
Lines 284-289 Link Here
284
        this.allFilesJob = allFilesJob;
290
        this.allFilesJob = allFilesJob;
285
    }
291
    }
286
292
293
    void putProperty(
294
            @NonNull String propName,
295
            @NullAllowed final Object value) {
296
        Parameters.notNull("propName", propName);   //NOI18N
297
        props.put(propName, value);
298
    }
299
300
    Object getProperty(@NonNull String propName) {
301
        Parameters.notNull("propName", propName);   //NOI18N
302
        return props.get(propName);
303
    }
304
287
    static String getIndexerPath (final String indexerName, final int indexerVersion) {
305
    static String getIndexerPath (final String indexerName, final int indexerVersion) {
288
        final StringBuilder sb = new StringBuilder();
306
        final StringBuilder sb = new StringBuilder();
289
        sb.append(indexerName);
307
        sb.append(indexerName);
(-)a/parsing.api/src/org/netbeans/modules/parsing/spi/indexing/Indexable.java (+55 lines)
Lines 44-49 Link Here
44
44
45
import java.io.IOException;
45
import java.io.IOException;
46
import java.net.URL;
46
import java.net.URL;
47
import java.util.Map;
47
import org.netbeans.api.annotations.common.CheckForNull;
48
import org.netbeans.api.annotations.common.CheckForNull;
48
import org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.api.annotations.common.NullAllowed;
50
import org.netbeans.api.annotations.common.NullAllowed;
Lines 56-61 Link Here
56
import org.netbeans.modules.parsing.spi.Parser.Result;
57
import org.netbeans.modules.parsing.spi.Parser.Result;
57
import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport;
58
import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport;
58
import org.openide.filesystems.FileObject;
59
import org.openide.filesystems.FileObject;
60
import org.openide.util.Parameters;
59
61
60
62
61
/**
63
/**
Lines 238-243 Link Here
238
        public void setAllFilesJob(final Context context, final boolean allFilesJob) {
240
        public void setAllFilesJob(final Context context, final boolean allFilesJob) {
239
            context.setAllFilesJob(allFilesJob);
241
            context.setAllFilesJob(allFilesJob);
240
        }
242
        }
243
244
        @Override
245
        public void index(
246
                @NonNull final ConstrainedBinaryIndexer indexer,
247
                @NonNull final Map<String,? extends Iterable<? extends FileObject>> files,
248
                @NonNull final Context context) {
249
            Parameters.notNull("indexer", indexer);     //NOI18N
250
            Parameters.notNull("files", files);     //NOI18N
251
            Parameters.notNull("context", context); //NOI18N
252
            indexer.index(files, context);
253
        }
254
255
        @Override
256
        public boolean scanStarted(
257
                @NonNull final ConstrainedBinaryIndexer indexer,
258
                @NonNull final Context context) {
259
            Parameters.notNull("indexer", indexer); //NOI18N
260
            Parameters.notNull("context", context); //NOI18N
261
            return indexer.scanStarted(context);
262
        }
263
264
        @Override
265
        public void scanFinished(
266
                @NonNull final ConstrainedBinaryIndexer indexer,
267
                @NonNull final Context context) {
268
            Parameters.notNull("indexer", indexer); //NOI18N
269
            Parameters.notNull("context", context); //NOI18N
270
            indexer.scanFinished(context);
271
        }
272
273
        @Override
274
        public void rootsRemoved(
275
                @NonNull ConstrainedBinaryIndexer indexer,
276
                @NonNull Iterable<? extends URL> removed) {
277
            Parameters.notNull("indexer", indexer); //NOI18N
278
            Parameters.notNull("removed", removed); //NOI18N
279
            indexer.rootsRemoved(removed);
280
        }
281
282
        @Override
283
        public void putProperty(
284
                @NonNull final Context context,
285
                @NonNull final String propName,
286
                @NullAllowed final Object value) {
287
            context.putProperty(propName, value);
288
        }
289
290
        @Override
291
        public Object getProperty(
292
                @NonNull final Context context,
293
                @NonNull final String propName) {
294
            return context.getProperty(propName);
295
        }
241
    }
296
    }
242
297
243
}
298
}
(-)a/spring.beans/nbproject/project.xml (-1 / +1 lines)
Lines 254-260 Link Here
254
                    <compile-dependency/>
254
                    <compile-dependency/>
255
                    <run-dependency>
255
                    <run-dependency>
256
                        <release-version>1</release-version>
256
                        <release-version>1</release-version>
257
                        <specification-version>1.31</specification-version>
257
                        <specification-version>1.48</specification-version>
258
                    </run-dependency>
258
                    </run-dependency>
259
                </dependency>
259
                </dependency>
260
                <dependency>
260
                <dependency>
(-)a/spring.beans/src/org/netbeans/modules/spring/beans/index/SpringBinaryIndexer.java (-42 / +21 lines)
Lines 42-56 Link Here
42
42
43
package org.netbeans.modules.spring.beans.index;
43
package org.netbeans.modules.spring.beans.index;
44
44
45
import java.net.URL;
46
import java.util.ArrayList;
45
import java.util.ArrayList;
47
import java.util.Collection;
46
import java.util.Collection;
48
import java.util.Enumeration;
47
import java.util.Map;
49
import java.util.logging.Level;
48
import java.util.logging.Level;
50
import java.util.logging.Logger;
49
import java.util.logging.Logger;
51
import org.netbeans.api.java.classpath.ClassPath;
50
import org.netbeans.api.java.classpath.ClassPath;
52
import org.netbeans.modules.parsing.spi.indexing.BinaryIndexer;
51
import org.netbeans.modules.parsing.spi.indexing.ConstrainedBinaryIndexer;
53
import org.netbeans.modules.parsing.spi.indexing.BinaryIndexerFactory;
54
import org.netbeans.modules.parsing.spi.indexing.Context;
52
import org.netbeans.modules.parsing.spi.indexing.Context;
55
import org.netbeans.modules.parsing.spi.indexing.support.IndexDocument;
53
import org.netbeans.modules.parsing.spi.indexing.support.IndexDocument;
56
import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport;
54
import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport;
Lines 69-82 Link Here
69
 *
67
 *
70
 * @author alexeybutenko
68
 * @author alexeybutenko
71
 */
69
 */
72
70
@ConstrainedBinaryIndexer.Registration(
73
public class SpringBinaryIndexer extends BinaryIndexer {
71
    mimeType=SpringBinaryIndexer.XSD_MIME,
72
    requiredResource="org/springframework",
73
    indexerName=SpringBinaryIndexer.INDEXER_NAME,
74
    indexVersion=SpringBinaryIndexer.INDEX_VERSION
75
)
76
public class SpringBinaryIndexer extends ConstrainedBinaryIndexer {
74
77
75
   public static final Logger LOGGER = Logger.getLogger(SpringBinaryIndexer.class.getSimpleName());
78
   public static final Logger LOGGER = Logger.getLogger(SpringBinaryIndexer.class.getSimpleName());
76
79
77
    static final String INDEXER_NAME = "SpringBinary"; //NOI18N
80
    static final String INDEXER_NAME = "SpringBinary"; //NOI18N
78
    static final int INDEX_VERSION = 1;
81
    static final int INDEX_VERSION = 1;
79
    private static final String XSD_SUFFIX = ".xsd";    //NOI18N
82
    private static final String XSD_SUFFIX = ".xsd";    //NOI18N
83
    static final String XSD_MIME = "text/xml";  //NOI18N
80
    static final String LIBRARY_MARK_KEY = "xsdSpringSchema";   //NOI18N
84
    static final String LIBRARY_MARK_KEY = "xsdSpringSchema";   //NOI18N
81
    static final String NAMESPACE_MARK_KEY = "namespace";   //NOI18N
85
    static final String NAMESPACE_MARK_KEY = "namespace";   //NOI18N
82
86
Lines 84-90 Link Here
84
    private String version;
88
    private String version;
85
89
86
    @Override
90
    @Override
87
    protected void index(Context context) {
91
    protected void index(
92
        Map<String,? extends Iterable<? extends FileObject>> files,
93
        Context context) {
88
        LOGGER.log(Level.FINE, "indexing " + context.getRoot()); //NOI18N
94
        LOGGER.log(Level.FINE, "indexing " + context.getRoot()); //NOI18N
89
95
90
        FileObject root = context.getRoot();
96
        FileObject root = context.getRoot();
Lines 96-108 Link Here
96
        }
102
        }
97
        version = findVersion(root);
103
        version = findVersion(root);
98
        if (version !=null) {
104
        if (version !=null) {
99
            processXsds(context);
105
            processXsds(files, context);
100
        }
106
        }
101
    }
107
    }
102
108
103
    private void processXsds(Context context) {
109
    private void processXsds(
104
        FileObject root = context.getRoot();
110
        Map<String,? extends Iterable<? extends FileObject>> files,
105
        for (FileObject fileObject : findSpringLibraryDescriptors(root, XSD_SUFFIX)) {
111
        Context context) {
112
        for (FileObject fileObject : findSpringLibraryDescriptors(files.get(XSD_MIME), XSD_SUFFIX)) {
106
            try {
113
            try {
107
                ModelSource source = Utilities.getModelSource(fileObject, true);
114
                ModelSource source = Utilities.getModelSource(fileObject, true);
108
                SchemaModel model = SchemaModelFactory.getDefault().getModel(source);
115
                SchemaModel model = SchemaModelFactory.getDefault().getModel(source);
Lines 126-139 Link Here
126
        }
133
        }
127
    }
134
    }
128
135
129
    private Collection<FileObject> findSpringLibraryDescriptors(FileObject classpathRoot, String suffix) {
136
    private Collection<FileObject> findSpringLibraryDescriptors(Iterable<? extends FileObject> res, String suffix) {
137
        assert res != null;
130
        Collection<FileObject> files = new ArrayList<FileObject>();
138
        Collection<FileObject> files = new ArrayList<FileObject>();
131
        if (classpathRoot.getFileObject("org/springframework") == null) {   //NOI18N
139
        for (FileObject file : res) {
132
            return files;
133
        }
134
        Enumeration<? extends FileObject> fos = classpathRoot.getChildren(true); //scan all files in the jar
135
        while (fos.hasMoreElements()) {
136
            FileObject file = fos.nextElement();
137
            //XXX Version??? spring 2-5 has some xsd's with non 2.5 version
140
            //XXX Version??? spring 2-5 has some xsd's with non 2.5 version
138
            String fileName = file.getNameExt().toLowerCase();
141
            String fileName = file.getNameExt().toLowerCase();
139
            if (fileName !=null && fileName.endsWith(suffix) && version.startsWith(findXsdVersion(file))) { //NOI18N
142
            if (fileName !=null && fileName.endsWith(suffix) && version.startsWith(findXsdVersion(file))) { //NOI18N
Lines 174-201 Link Here
174
        }
177
        }
175
        return null;
178
        return null;
176
    }
179
    }
177
178
    public static class Factory extends BinaryIndexerFactory {
179
180
        @Override
181
        public BinaryIndexer createIndexer() {
182
            return new SpringBinaryIndexer();
183
        }
184
185
        @Override
186
        public void rootsRemoved(Iterable<? extends URL> removedRoots) {
187
//            throw new UnsupportedOperationException("Not supported yet.");
188
        }
189
190
        @Override
191
        public String getIndexerName() {
192
            return INDEXER_NAME;
193
        }
194
195
        @Override
196
        public int getIndexVersion() {
197
            return INDEX_VERSION;
198
        }
199
    }
200
201
}
180
}
(-)a/spring.beans/src/org/netbeans/modules/spring/beans/resources/layer.xml (-3 lines)
Lines 153-161 Link Here
153
        </folder>
153
        </folder>
154
    </folder>
154
    </folder>
155
    <folder name="Editors">
155
    <folder name="Editors">
156
        <file name="org-netbeans-modules-spring-beans-index-SpringBinaryIndexer$Factory.instance">
157
            <attr name="instanceOf" stringvalue="org.netbeans.modules.parsing.spi.indexing.BinaryIndexerFactory"/>
158
        </file>
159
        <folder name="text">
156
        <folder name="text">
160
            <folder name="x-springconfig+xml">
157
            <folder name="x-springconfig+xml">
161
                <folder name="HyperlinkProviders">
158
                <folder name="HyperlinkProviders">

Return to bug 204817