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 257567
Collapse All | Expand All

(-)maven.indexer/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/indexer/Bundle.properties
2
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/maven/indexer/Bundle.properties
3
AutoUpdate-Show-In-Client: false
3
AutoUpdate-Show-In-Client: false
4
OpenIDE-Module-Specification-Version: 2.36
4
OpenIDE-Module-Specification-Version: 2.37
5
OpenIDE-Module: org.netbeans.modules.maven.indexer/2
5
OpenIDE-Module: org.netbeans.modules.maven.indexer/2
6
6
(-)maven.indexer/nbproject/project.xml (+1 lines)
Lines 186-191 Link Here
186
                <package>org.apache.lucene.util.cache</package>
186
                <package>org.apache.lucene.util.cache</package>
187
                <package>org.netbeans.modules.maven.indexer.api</package>
187
                <package>org.netbeans.modules.maven.indexer.api</package>
188
                <package>org.netbeans.modules.maven.indexer.api.ui</package>
188
                <package>org.netbeans.modules.maven.indexer.api.ui</package>
189
                <package>org.netbeans.modules.maven.indexer.spi</package>
189
                <package>org.netbeans.modules.maven.indexer.spi.ui</package>
190
                <package>org.netbeans.modules.maven.indexer.spi.ui</package>
190
                <package>org.netbeans.modules.maven.indexer.spi.impl</package>
191
                <package>org.netbeans.modules.maven.indexer.spi.impl</package>
191
            </friend-packages>
192
            </friend-packages>
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImpl.java (-165 / +168 lines)
Lines 101-107 Link Here
101
import org.codehaus.plexus.util.FileUtils;
101
import org.codehaus.plexus.util.FileUtils;
102
import org.netbeans.api.annotations.common.CheckForNull;
102
import org.netbeans.api.annotations.common.CheckForNull;
103
import org.netbeans.api.annotations.common.NullAllowed;
103
import org.netbeans.api.annotations.common.NullAllowed;
104
import org.netbeans.api.annotations.common.SuppressWarnings;
105
import org.netbeans.modules.maven.embedder.EmbedderFactory;
104
import org.netbeans.modules.maven.embedder.EmbedderFactory;
106
import org.netbeans.modules.maven.embedder.MavenEmbedder;
105
import org.netbeans.modules.maven.embedder.MavenEmbedder;
107
import org.netbeans.modules.maven.indexer.api.NBArtifactInfo;
106
import org.netbeans.modules.maven.indexer.api.NBArtifactInfo;
Lines 110-116 Link Here
110
import org.netbeans.modules.maven.indexer.api.QueryField;
109
import org.netbeans.modules.maven.indexer.api.QueryField;
111
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
110
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
112
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences;
111
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences;
113
import org.netbeans.modules.maven.indexer.api.RepositoryQueries.Result;
114
import org.netbeans.modules.maven.indexer.spi.ArchetypeQueries;
112
import org.netbeans.modules.maven.indexer.spi.ArchetypeQueries;
115
import org.netbeans.modules.maven.indexer.spi.BaseQueries;
113
import org.netbeans.modules.maven.indexer.spi.BaseQueries;
116
import org.netbeans.modules.maven.indexer.spi.ChecksumQueries;
114
import org.netbeans.modules.maven.indexer.spi.ChecksumQueries;
Lines 119-126 Link Here
119
import org.netbeans.modules.maven.indexer.spi.ContextLoadedQuery;
117
import org.netbeans.modules.maven.indexer.spi.ContextLoadedQuery;
120
import org.netbeans.modules.maven.indexer.spi.DependencyInfoQueries;
118
import org.netbeans.modules.maven.indexer.spi.DependencyInfoQueries;
121
import org.netbeans.modules.maven.indexer.spi.GenericFindQuery;
119
import org.netbeans.modules.maven.indexer.spi.GenericFindQuery;
122
import org.netbeans.modules.maven.indexer.spi.Redo;
120
import org.netbeans.modules.maven.indexer.spi.impl.RepositoryIndexerImplementation;
123
import org.netbeans.modules.maven.indexer.spi.RepositoryIndexerImplementation;
121
import org.netbeans.modules.maven.indexer.spi.ResultImplementation;
122
import org.netbeans.modules.maven.indexer.spi.impl.Redo;
124
import org.netbeans.modules.maven.indexer.spi.impl.IndexingNotificationProvider;
123
import org.netbeans.modules.maven.indexer.spi.impl.IndexingNotificationProvider;
125
import org.openide.modules.Places;
124
import org.openide.modules.Places;
126
import org.openide.util.BaseUtilities;
125
import org.openide.util.BaseUtilities;
Lines 132-190 Link Here
132
import org.openide.util.lookup.ServiceProvider;
131
import org.openide.util.lookup.ServiceProvider;
133
import org.openide.util.lookup.ServiceProviders;
132
import org.openide.util.lookup.ServiceProviders;
134
import org.openide.util.NbBundle.Messages;
133
import org.openide.util.NbBundle.Messages;
134
import org.netbeans.modules.maven.indexer.spi.RepositoryIndexQueryProvider;
135
135
136
@ServiceProviders({
136
@ServiceProviders({
137
    @ServiceProvider(service=RepositoryIndexerImplementation.class),
137
    @ServiceProvider(service=RepositoryIndexerImplementation.class),
138
    @ServiceProvider(service=BaseQueries.class),
138
    @ServiceProvider(service=RepositoryIndexQueryProvider.class, position = Integer.MAX_VALUE)
139
    @ServiceProvider(service=ChecksumQueries.class),
140
    @ServiceProvider(service=ArchetypeQueries.class),
141
    @ServiceProvider(service=DependencyInfoQueries.class),
142
    @ServiceProvider(service=ClassesQuery.class),
143
    @ServiceProvider(service=ClassUsageQuery.class),
144
    @ServiceProvider(service=GenericFindQuery.class),
145
    @ServiceProvider(service=ContextLoadedQuery.class)
146
})
139
})
147
public class NexusRepositoryIndexerImpl implements RepositoryIndexerImplementation,
140
public class NexusRepositoryIndexerImpl implements RepositoryIndexerImplementation, RepositoryIndexQueryProvider,
148
        BaseQueries, ChecksumQueries, ArchetypeQueries, DependencyInfoQueries,
141
        BaseQueries, ChecksumQueries, ArchetypeQueries, DependencyInfoQueries,
149
        ClassesQuery, ClassUsageQuery, GenericFindQuery, ContextLoadedQuery {
142
        ClassesQuery, ClassUsageQuery, GenericFindQuery, ContextLoadedQuery {
150
143
151
    
152
    public static abstract class Accessor {
153
  
154
        @SuppressWarnings("MS_SHOULD_BE_FINAL")
155
        public static Accessor ACCESSOR;
156
        
157
        protected Accessor() {
158
            ACCESSOR = this;
159
        }
160
        
161
        public abstract void addSkipped(Result<?> result, Collection<RepositoryInfo> infos);
162
        
163
        public abstract List<RepositoryInfo> getSkipped(Result<?> result);
164
        
165
        public abstract void setStringResults(Result<String> result, Collection<String> newResults);
166
        
167
        public abstract void setVersionResults(Result<NBVersionInfo> result, Collection<NBVersionInfo> newResults);
168
        
169
        public abstract void addSkipped(Result<?> result, RepositoryInfo info);
170
        
171
        public abstract Result<String> createStringResult(Redo<String> redo);
172
        
173
        public abstract Result<NBVersionInfo> createVersionResult(Redo<NBVersionInfo> redo);
174
        
175
        public abstract Result<NBGroupInfo> createGroupResult(Redo<NBGroupInfo> redo);
176
        
177
        public abstract void setGroupResults(Result<NBGroupInfo> result, Collection<NBGroupInfo> newResults);
178
        
179
        public abstract Result<RepositoryQueries.ClassUsage> createClassResult(Redo<RepositoryQueries.ClassUsage> redo);
180
        
181
        public abstract void setClassResults(Result<RepositoryQueries.ClassUsage> result, Collection<RepositoryQueries.ClassUsage> newResults);
182
        
183
        public abstract void addTotalResults(Result<?> result, int moreResults);
184
        
185
        public abstract void addReturnedResults(Result<?> result, int moreResults);
186
    }
187
    
188
    private static final Logger LOGGER = Logger.getLogger(NexusRepositoryIndexerImpl.class.getName());
144
    private static final Logger LOGGER = Logger.getLogger(NexusRepositoryIndexerImpl.class.getName());
189
       
145
       
190
    static {
146
    static {
Lines 215-220 Link Here
215
    private static final Set<Mutex> indexingMutexes = new HashSet<Mutex>();
171
    private static final Set<Mutex> indexingMutexes = new HashSet<Mutex>();
216
    private static final RequestProcessor RP = new RequestProcessor("indexing", 1);
172
    private static final RequestProcessor RP = new RequestProcessor("indexing", 1);
217
173
174
    @Override
175
    public boolean handlesRepository(RepositoryInfo repo) {
176
        // should always come as last when looked up
177
        // handles all remote repos
178
        return true; 
179
    }
180
    
181
    @Override
182
    public BaseQueries getBaseQueries() {
183
        return this;
184
    }
185
186
    @Override
187
    public ChecksumQueries getChecksumQueries() {
188
        return this;
189
    }
190
191
    @Override
192
    public ArchetypeQueries getArchetypeQueries() {
193
        return this;
194
    }
195
196
    @Override
197
    public DependencyInfoQueries getDependencyInfoQueries() {
198
        return this;
199
    }
200
201
    @Override
202
    public ClassesQuery getClassesQuery() {
203
        return this;
204
    }
205
206
    @Override
207
    public ClassUsageQuery getClassUsageQuery() {
208
        return this;
209
    }
210
211
    @Override
212
    public GenericFindQuery getGenericFindQuery() {
213
        return this;
214
    }
215
216
    @Override
217
    public ContextLoadedQuery getContextLoadedQuery() {
218
        return this;
219
    }
220
    
218
    private Mutex getRepoMutex(RepositoryInfo repo) {
221
    private Mutex getRepoMutex(RepositoryInfo repo) {
219
        return getRepoMutex(repo.getId());
222
        return getRepoMutex(repo.getId());
220
    }
223
    }
Lines 911-917 Link Here
911
    }
914
    }
912
915
913
    @Override
916
    @Override
914
    public RepositoryQueries.Result<String> getGroups(List<RepositoryInfo> repos) {
917
    public ResultImplementation<String> getGroups(List<RepositoryInfo> repos) {
915
        return filterGroupIds("", repos);
918
        return filterGroupIds("", repos);
916
    }
919
    }
917
920
Lines 969-985 Link Here
969
    }
972
    }
970
973
971
    @Override
974
    @Override
972
    public RepositoryQueries.Result<String> filterGroupIds(final String prefix, final List<RepositoryInfo> repos) {
975
    public ResultImplementation<String> filterGroupIds(final String prefix, final List<RepositoryInfo> repos) {
973
        RepositoryQueries.Result<String> result = Accessor.ACCESSOR.createStringResult(new Redo<String>() {
976
        Redo<String> redo = new Redo<String>() {
974
            @Override
977
            @Override
975
            public void run(Result<String> result) {
978
            public void run(ResultImpl<String> result) {
976
                filterGroupIds(prefix, result, Accessor.ACCESSOR.getSkipped(result), false);
979
                filterGroupIds(prefix, result, result.getSkipped(), false);
977
            }
980
            }
978
        });
981
        };
982
        ResultImpl<String> result = new ResultImpl<String>(redo);
979
        return filterGroupIds(prefix, result, repos, true);
983
        return filterGroupIds(prefix, result, repos, true);
980
    }
984
    }
981
    
985
    
982
    private RepositoryQueries.Result<String> filterGroupIds(final String prefix, final RepositoryQueries.Result<String> result, 
986
    private ResultImplementation<String> filterGroupIds(final String prefix, final ResultImpl<String> result, 
983
                                                            final List<RepositoryInfo> repos, final boolean skipUnIndexed) {
987
                                                            final List<RepositoryInfo> repos, final boolean skipUnIndexed) {
984
        final Set<String> groups = new TreeSet<String>(result.getResults());
988
        final Set<String> groups = new TreeSet<String>(result.getResults());
985
        final List<RepositoryInfo> slowCheck = new ArrayList<RepositoryInfo>();
989
        final List<RepositoryInfo> slowCheck = new ArrayList<RepositoryInfo>();
Lines 1022-1043 Link Here
1022
//            }
1026
//            }
1023
//        }, skipAction, skipUnIndexed);
1027
//        }, skipAction, skipUnIndexed);
1024
        
1028
        
1025
        Accessor.ACCESSOR.setStringResults(result, groups);
1029
        result.setResults(groups);
1026
        return result;
1030
        return result;
1027
    }
1031
    }
1028
1032
1029
    @Override
1033
    @Override
1030
    public Result<String> getGAVsForPackaging(final String packaging, List<RepositoryInfo> repos) {
1034
    public ResultImplementation<String> getGAVsForPackaging(final String packaging, List<RepositoryInfo> repos) {
1031
        RepositoryQueries.Result<String> result = Accessor.ACCESSOR.createStringResult(new Redo<String>() {
1035
        ResultImpl<String> result = new ResultImpl<>(new Redo<String>() {
1032
            @Override
1036
            @Override
1033
            public void run(Result<String> result) {
1037
            public void run(ResultImpl<String> result) {
1034
                getGAVsForPackaging(packaging, result, Accessor.ACCESSOR.getSkipped(result), false);
1038
                getGAVsForPackaging(packaging, result, result.getSkipped(), false);
1035
            }
1039
            }
1036
        });
1040
        });
1037
        return getGAVsForPackaging(packaging,result, repos, true);
1041
        return getGAVsForPackaging(packaging,result, repos, true);
1038
    }
1042
    }
1039
    
1043
    
1040
    private Result<String> getGAVsForPackaging(final String packaging, final Result<String> result, 
1044
    private ResultImplementation<String> getGAVsForPackaging(final String packaging, final ResultImpl<String> result, 
1041
                                             List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1045
                                             List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1042
        final List<String> infos = new ArrayList<String>(result.getResults());
1046
        final List<String> infos = new ArrayList<String>(result.getResults());
1043
        final SkippedAction skipAction = new SkippedAction(result);
1047
        final SkippedAction skipAction = new SkippedAction(result);
Lines 1055-1084 Link Here
1055
                            }
1059
                            }
1056
                        }
1060
                        }
1057
                    } finally {
1061
                    } finally {
1058
                        Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount());
1062
                        result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount());
1059
                        Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount());
1063
                        result.addTotalResultCount(response.getTotalHitsCount());
1060
                        response.close();
1064
                        response.close();
1061
                    }
1065
                    }
1062
                }
1066
                }
1063
            }
1067
            }
1064
        }, skipAction, skipUnIndexed);
1068
        }, skipAction, skipUnIndexed);
1065
        Accessor.ACCESSOR.setStringResults(result, infos);
1069
        result.setResults(infos);
1066
        return result;        
1070
        return result;        
1067
    }
1071
    }
1068
    
1072
    
1069
1070
    @Override
1073
    @Override
1071
    public Result<NBVersionInfo> getRecords(final String groupId, final String artifactId, final String version, List<RepositoryInfo> repos) {
1074
    public ResultImplementation<NBVersionInfo> getRecords(final String groupId, final String artifactId, final String version, List<RepositoryInfo> repos) {
1072
        RepositoryQueries.Result<NBVersionInfo> result = Accessor.ACCESSOR.createVersionResult(new Redo<NBVersionInfo>() {
1075
        ResultImpl<NBVersionInfo> result = new ResultImpl<>(new Redo<NBVersionInfo>() {
1073
            @Override
1076
            @Override
1074
            public void run(Result<NBVersionInfo> result) {
1077
            public void run(ResultImpl<NBVersionInfo> result) {
1075
                getRecords(groupId, artifactId, version, result, Accessor.ACCESSOR.getSkipped(result), false);
1078
                getRecords(groupId, artifactId, version, result, result.getSkipped(), false);
1076
            }
1079
            }
1077
        });
1080
        });
1078
        return getRecords(groupId, artifactId, version, result, repos, true);
1081
        return getRecords(groupId, artifactId, version, result, repos, true);
1079
    }
1082
    }
1080
    
1083
    
1081
    private Result<NBVersionInfo> getRecords(final String groupId, final String artifactId, final String version, final Result<NBVersionInfo> result, 
1084
    private ResultImplementation<NBVersionInfo> getRecords(final String groupId, final String artifactId, final String version, final ResultImpl<NBVersionInfo> result, 
1082
                                             List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1085
                                             List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1083
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1086
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1084
        final SkippedAction skipAction = new SkippedAction(result);
1087
        final SkippedAction skipAction = new SkippedAction(result);
Lines 1094-1123 Link Here
1094
                            infos.add(convertToNBVersionInfo(ai));
1097
                            infos.add(convertToNBVersionInfo(ai));
1095
                        }
1098
                        }
1096
                    } finally {
1099
                    } finally {
1097
                        Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount());
1100
                        result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount());
1098
                        Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount());
1101
                        result.addTotalResultCount(response.getTotalHitsCount());
1099
                        response.close();
1102
                        response.close();
1100
                    }
1103
                    }
1101
                }
1104
                }
1102
            }
1105
            }
1103
        }, skipAction, skipUnIndexed);
1106
        }, skipAction, skipUnIndexed);
1104
        doSortIssue226100(infos);
1107
        doSortIssue226100(infos);
1105
        Accessor.ACCESSOR.setVersionResults(result, infos);
1108
        result.setResults(infos);
1106
        return result;
1109
        return result;
1107
    }
1110
    }
1108
1111
1109
    @Override
1112
    @Override
1110
    public RepositoryQueries.Result<String> getArtifacts(final String groupId, final List<RepositoryInfo> repos) {
1113
    public ResultImplementation<String> getArtifacts(final String groupId, final List<RepositoryInfo> repos) {
1111
        RepositoryQueries.Result<String> result = Accessor.ACCESSOR.createStringResult(new Redo<String>() {
1114
        ResultImpl<String> result = new ResultImpl<>(new Redo<String>() {
1112
            @Override
1115
            @Override
1113
            public void run(Result<String> result) {
1116
            public void run(ResultImpl<String> result) {
1114
                getArtifacts(groupId, result, Accessor.ACCESSOR.getSkipped(result), false);
1117
                getArtifacts(groupId, result, result.getSkipped(), false);
1115
            }
1118
            }
1116
        });
1119
        });
1117
        return getArtifacts(groupId, result, repos, true);
1120
        return getArtifacts(groupId, result, repos, true);
1118
    }
1121
    }
1119
    
1122
    
1120
    private  RepositoryQueries.Result<String> getArtifacts(final String groupId, final Result<String> result, final List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1123
    private  ResultImplementation<String> getArtifacts(final String groupId, final ResultImpl<String> result, final List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1121
        final Set<String> artifacts = new TreeSet<String>(result.getResults());
1124
        final Set<String> artifacts = new TreeSet<String>(result.getResults());
1122
        final SkippedAction skipAction = new SkippedAction(result);
1125
        final SkippedAction skipAction = new SkippedAction(result);
1123
        iterate(repos, new RepoAction() {
1126
        iterate(repos, new RepoAction() {
Lines 1138-1158 Link Here
1138
                }
1141
                }
1139
            }
1142
            }
1140
        }, skipAction, skipUnIndexed);
1143
        }, skipAction, skipUnIndexed);
1141
        Accessor.ACCESSOR.setStringResults(result, artifacts);
1144
        result.setResults(artifacts);
1142
        return result;
1145
        return result;
1143
    }
1146
    }
1144
1147
1145
    @Override
1148
    @Override
1146
    public RepositoryQueries.Result<NBVersionInfo> getVersions(final String groupId, final String artifactId, List<RepositoryInfo> repos) {
1149
    public ResultImplementation<NBVersionInfo> getVersions(final String groupId, final String artifactId, List<RepositoryInfo> repos) {
1147
        RepositoryQueries.Result<NBVersionInfo> result = Accessor.ACCESSOR.createVersionResult(new Redo<NBVersionInfo>() {
1150
        ResultImpl<NBVersionInfo> result = new ResultImpl<>(new Redo<NBVersionInfo>() {
1148
            @Override
1151
            @Override
1149
            public void run(Result<NBVersionInfo> result) {
1152
            public void run(ResultImpl<NBVersionInfo> result) {
1150
                getVersions(groupId, artifactId, result, Accessor.ACCESSOR.getSkipped(result), false);
1153
                getVersions(groupId, artifactId, result, result.getSkipped(), false);
1151
            }
1154
            }
1152
        });
1155
        });
1153
        return getVersions(groupId, artifactId, result, repos, true);
1156
        return getVersions(groupId, artifactId, result, repos, true);
1154
    }
1157
    }
1155
    private RepositoryQueries.Result<NBVersionInfo> getVersions(final String groupId, final String artifactId, final Result<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1158
    private ResultImplementation<NBVersionInfo> getVersions(final String groupId, final String artifactId, final ResultImpl<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1156
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1159
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1157
        final SkippedAction skipAction = new SkippedAction(result);
1160
        final SkippedAction skipAction = new SkippedAction(result);
1158
        iterate(repos, new RepoAction() {
1161
        iterate(repos, new RepoAction() {
Lines 1167-1196 Link Here
1167
                            infos.add(convertToNBVersionInfo(ai));
1170
                            infos.add(convertToNBVersionInfo(ai));
1168
                        }
1171
                        }
1169
                    } finally {
1172
                    } finally {
1170
                        Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount());
1173
                        result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount());
1171
                        Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount());
1174
                        result.addTotalResultCount(response.getTotalHitsCount());
1172
                        response.close();
1175
                        response.close();
1173
                    }
1176
                    }
1174
                }
1177
                }
1175
            }
1178
            }
1176
        }, skipAction, skipUnIndexed);
1179
        }, skipAction, skipUnIndexed);
1177
        doSortIssue226100(infos);
1180
        doSortIssue226100(infos);
1178
        Accessor.ACCESSOR.setVersionResults(result, infos);
1181
        result.setResults(infos);
1179
        return result;
1182
        return result;
1180
    }
1183
    }
1181
1184
1182
    @Override
1185
    @Override
1183
    public RepositoryQueries.Result<NBVersionInfo> findVersionsByClass(final String className, List<RepositoryInfo> repos) {
1186
    public ResultImplementation<NBVersionInfo> findVersionsByClass(final String className, List<RepositoryInfo> repos) {
1184
        RepositoryQueries.Result<NBVersionInfo> result = Accessor.ACCESSOR.createVersionResult(new Redo<NBVersionInfo>() {
1187
        ResultImpl<NBVersionInfo> result = new ResultImpl(new Redo<NBVersionInfo>() {
1185
            @Override
1188
            @Override
1186
            public void run(Result<NBVersionInfo> result) {
1189
            public void run(ResultImpl<NBVersionInfo> result) {
1187
                findVersionsByClass(className, result, Accessor.ACCESSOR.getSkipped(result), false);
1190
                findVersionsByClass(className, result, result.getSkipped(), false);
1188
            }
1191
            }
1189
        });
1192
        });
1190
        return findVersionsByClass(className, result, repos, true);
1193
        return findVersionsByClass(className, result, repos, true);
1191
    }
1194
    }
1192
    
1195
    
1193
    private RepositoryQueries.Result<NBVersionInfo> findVersionsByClass(final String className, final Result<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1196
    private ResultImplementation<NBVersionInfo> findVersionsByClass(final String className, final ResultImpl<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1194
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1197
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1195
        final SkippedAction skipAction = new SkippedAction(result);
1198
        final SkippedAction skipAction = new SkippedAction(result);
1196
        iterate(repos, new RepoAction() {
1199
        iterate(repos, new RepoAction() {
Lines 1212-1242 Link Here
1212
                        infos.addAll(postProcessClasses(response.getResults(), clsname));
1215
                        infos.addAll(postProcessClasses(response.getResults(), clsname));
1213
                    } finally {
1216
                    } finally {
1214
                        //?? really count in this case?
1217
                        //?? really count in this case?
1215
                        Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount());
1218
                        result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount());
1216
                        Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount());
1219
                        result.addTotalResultCount(response.getTotalHitsCount());
1217
                        response.close();
1220
                        response.close();
1218
                    }
1221
                    }
1219
                }
1222
                }
1220
            }
1223
            }
1221
        }, skipAction, skipUnIndexed);
1224
        }, skipAction, skipUnIndexed);
1222
        doSortIssue226100(infos);
1225
        doSortIssue226100(infos);
1223
        Accessor.ACCESSOR.setVersionResults(result, infos);
1226
        result.setResults(infos);
1224
        return result;
1227
        return result;
1225
    }
1228
    }
1226
1229
1227
    @Override 
1230
    @Override 
1228
    public RepositoryQueries.Result<RepositoryQueries.ClassUsage> findClassUsages(final String className, @NullAllowed List<RepositoryInfo> repos) {
1231
    public ResultImplementation<RepositoryQueries.ClassUsage> findClassUsages(final String className, @NullAllowed List<RepositoryInfo> repos) {
1229
        RepositoryQueries.Result<RepositoryQueries.ClassUsage> result = Accessor.ACCESSOR.createClassResult(new Redo<RepositoryQueries.ClassUsage>() {
1232
        ResultImpl<RepositoryQueries.ClassUsage> result = new ResultImpl<>(new Redo<RepositoryQueries.ClassUsage>() {
1230
            @Override
1233
            @Override
1231
            public void run(Result<RepositoryQueries.ClassUsage> result) {
1234
            public void run(ResultImpl<RepositoryQueries.ClassUsage> result) {
1232
                findClassUsages(className, result, Accessor.ACCESSOR.getSkipped(result), false);
1235
                findClassUsages(className, result, result.getSkipped(), false);
1233
            }
1236
            }
1234
        });
1237
        });
1235
        return findClassUsages(className, result, repos, true);
1238
        return findClassUsages(className, result, repos, true);
1236
        
1239
        
1237
    }
1240
    }
1238
    
1241
    
1239
    private RepositoryQueries.Result<RepositoryQueries.ClassUsage> findClassUsages(final String className, Result<RepositoryQueries.ClassUsage> result, @NullAllowed List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1242
    private ResultImplementation<RepositoryQueries.ClassUsage> findClassUsages(final String className, ResultImpl<RepositoryQueries.ClassUsage> result, @NullAllowed List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1240
        List<RepositoryInfo> localRepos = new ArrayList<RepositoryInfo>();
1243
        List<RepositoryInfo> localRepos = new ArrayList<RepositoryInfo>();
1241
        if (repos == null) {
1244
        if (repos == null) {
1242
            repos = RepositoryPreferences.getInstance().getRepositoryInfos();
1245
            repos = RepositoryPreferences.getInstance().getRepositoryInfos();
Lines 1258-1278 Link Here
1258
                return r1.getArtifact().compareTo(r2.getArtifact());
1261
                return r1.getArtifact().compareTo(r2.getArtifact());
1259
            }
1262
            }
1260
        });
1263
        });
1261
        Accessor.ACCESSOR.setClassResults(result, results);
1264
        result.setResults(results);
1262
        return result;
1265
        return result;
1263
    }
1266
    }
1264
    
1267
    
1265
    @Override
1268
    @Override
1266
    public RepositoryQueries.Result<NBVersionInfo> findDependencyUsage(final String groupId, final String artifactId, final String version, @NullAllowed List<RepositoryInfo> repos) {
1269
    public ResultImplementation<NBVersionInfo> findDependencyUsage(final String groupId, final String artifactId, final String version, @NullAllowed List<RepositoryInfo> repos) {
1267
        RepositoryQueries.Result<NBVersionInfo> result = Accessor.ACCESSOR.createVersionResult(new Redo<NBVersionInfo>() {
1270
        ResultImpl<NBVersionInfo> result = new ResultImpl<>(new Redo<NBVersionInfo>() {
1268
            @Override
1271
            @Override
1269
            public void run(Result<NBVersionInfo> result) {
1272
            public void run(ResultImpl<NBVersionInfo> result) {
1270
                findDependencyUsage(groupId, artifactId, version, result, Accessor.ACCESSOR.getSkipped(result), false);
1273
                findDependencyUsage(groupId, artifactId, version, result, result.getSkipped(), false);
1271
            }
1274
            }
1272
        });
1275
        });
1273
        return findDependencyUsage(groupId, artifactId, version, result, repos, true);
1276
        return findDependencyUsage(groupId, artifactId, version, result, repos, true);
1274
    }
1277
    }
1275
    private RepositoryQueries.Result<NBVersionInfo> findDependencyUsage(String groupId, String artifactId, String version, final Result<NBVersionInfo> result, @NullAllowed List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1278
    private ResultImplementation<NBVersionInfo> findDependencyUsage(String groupId, String artifactId, String version, final ResultImpl<NBVersionInfo> result, @NullAllowed List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1276
        final Query q = ArtifactDependencyIndexCreator.query(groupId, artifactId, version);
1279
        final Query q = ArtifactDependencyIndexCreator.query(groupId, artifactId, version);
1277
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1280
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1278
        final SkippedAction skipAction = new SkippedAction(result);
1281
        final SkippedAction skipAction = new SkippedAction(result);
Lines 1285-1321 Link Here
1285
                            infos.add(convertToNBVersionInfo(ai));
1288
                            infos.add(convertToNBVersionInfo(ai));
1286
                        }
1289
                        }
1287
                    } finally {
1290
                    } finally {
1288
                        Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount());
1291
                        result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount());
1289
                        Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount());
1292
                        result.addTotalResultCount(response.getTotalHitsCount());
1290
                        response.close();
1293
                        response.close();
1291
                    }
1294
                    }
1292
                }
1295
                }
1293
            }
1296
            }
1294
        }, skipAction, skipUnIndexed);
1297
        }, skipAction, skipUnIndexed);
1295
        Accessor.ACCESSOR.setVersionResults(result, infos);
1298
        result.setResults(infos);
1296
        return result;
1299
        return result;
1297
    }
1300
    }
1298
    
1301
    
1299
    @Override
1302
    @Override
1300
    public Result<NBGroupInfo> findDependencyUsageGroups(final String groupId, final String artifactId, final String version, List<RepositoryInfo> repos) {
1303
    public ResultImplementation<NBGroupInfo> findDependencyUsageGroups(final String groupId, final String artifactId, final String version, List<RepositoryInfo> repos) {
1301
        RepositoryQueries.Result<NBGroupInfo> result = Accessor.ACCESSOR.createGroupResult(new Redo<NBGroupInfo>() {
1304
        ResultImpl<NBGroupInfo> result = new ResultImpl<>(new Redo<NBGroupInfo>() {
1302
            @Override
1305
            @Override
1303
            public void run(Result<NBGroupInfo> result) {
1306
            public void run(ResultImpl<NBGroupInfo> result) {
1304
                findDependencyUsageGroups(groupId, artifactId, version, result, Accessor.ACCESSOR.getSkipped(result), false);
1307
                findDependencyUsageGroups(groupId, artifactId, version, result, result.getSkipped(), false);
1305
            }
1308
            }
1306
        });
1309
        });
1307
        return findDependencyUsageGroups(groupId, artifactId, version, result, repos, true);
1310
        return findDependencyUsageGroups(groupId, artifactId, version, result, repos, true);
1308
    }
1311
    }
1309
1312
1310
    private Result<NBGroupInfo> findDependencyUsageGroups(String groupId, String artifactId, String version, Result<NBGroupInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1313
    private ResultImplementation<NBGroupInfo> findDependencyUsageGroups(String groupId, String artifactId, String version, ResultImpl<NBGroupInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1311
        //tempmaps
1314
        //tempmaps
1312
        Map<String, NBGroupInfo> groupMap = new HashMap<String, NBGroupInfo>();
1315
        Map<String, NBGroupInfo> groupMap = new HashMap<String, NBGroupInfo>();
1313
        Map<String, NBArtifactInfo> artifactMap = new HashMap<String, NBArtifactInfo>();
1316
        Map<String, NBArtifactInfo> artifactMap = new HashMap<String, NBArtifactInfo>();
1314
        List<NBGroupInfo> groupInfos = new ArrayList<NBGroupInfo>(result.getResults());
1317
        List<NBGroupInfo> groupInfos = new ArrayList<NBGroupInfo>(result.getResults());
1315
        Result<NBVersionInfo> res = Accessor.ACCESSOR.createVersionResult(new Redo<NBVersionInfo>() {
1318
        ResultImpl<NBVersionInfo> res = new ResultImpl(new Redo<NBVersionInfo>() {
1316
1319
1317
            @Override
1320
            @Override
1318
            public void run(Result<NBVersionInfo> result) {
1321
            public void run(ResultImpl<NBVersionInfo> result) {
1319
                //noop will not be called
1322
                //noop will not be called
1320
            }
1323
            }
1321
        });
1324
        });
Lines 1323-1331 Link Here
1323
        convertToNBGroupInfo(res.getResults(),
1326
        convertToNBGroupInfo(res.getResults(),
1324
                groupMap, artifactMap, groupInfos);
1327
                groupMap, artifactMap, groupInfos);
1325
        if (res.isPartial()) {
1328
        if (res.isPartial()) {
1326
            Accessor.ACCESSOR.addSkipped(result, Accessor.ACCESSOR.getSkipped(res));
1329
            result.addSkipped(res.getSkipped());
1327
        }
1330
        }
1328
        Accessor.ACCESSOR.setGroupResults(result, groupInfos);
1331
        result.setResults(groupInfos);
1329
        return result;
1332
        return result;
1330
        
1333
        
1331
    }
1334
    }
Lines 1357-1373 Link Here
1357
    
1360
    
1358
1361
1359
    @Override
1362
    @Override
1360
    public RepositoryQueries.Result<NBVersionInfo> findBySHA1(final String sha1, List<RepositoryInfo> repos) {
1363
    public ResultImplementation<NBVersionInfo> findBySHA1(final String sha1, List<RepositoryInfo> repos) {
1361
        RepositoryQueries.Result<NBVersionInfo> result = Accessor.ACCESSOR.createVersionResult(new Redo<NBVersionInfo>() {
1364
        ResultImpl<NBVersionInfo> result = new ResultImpl<>(new Redo<NBVersionInfo>() {
1362
            @Override
1365
            @Override
1363
            public void run(Result<NBVersionInfo> result) {
1366
            public void run(ResultImpl<NBVersionInfo> result) {
1364
                findBySHA1(sha1, result, Accessor.ACCESSOR.getSkipped(result), false);
1367
                findBySHA1(sha1, result, result.getSkipped(), false);
1365
            }
1368
            }
1366
        });
1369
        });
1367
        return findBySHA1(sha1, result, repos, true);
1370
        return findBySHA1(sha1, result, repos, true);
1368
    }
1371
    }
1369
    
1372
    
1370
    private RepositoryQueries.Result<NBVersionInfo> findBySHA1(final String sha1, final Result<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1373
    private ResultImplementation<NBVersionInfo> findBySHA1(final String sha1, final ResultImpl<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1371
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1374
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1372
        final SkippedAction skipAction = new SkippedAction(result);
1375
        final SkippedAction skipAction = new SkippedAction(result);
1373
        iterate(repos, new RepoAction() {
1376
        iterate(repos, new RepoAction() {
Lines 1381-1410 Link Here
1381
                            infos.add(convertToNBVersionInfo(ai));
1384
                            infos.add(convertToNBVersionInfo(ai));
1382
                        }
1385
                        }
1383
                    } finally {
1386
                    } finally {
1384
                        Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount());
1387
                        result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount());
1385
                        Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount());
1388
                        result.addTotalResultCount(response.getTotalHitsCount());
1386
                        response.close();
1389
                        response.close();
1387
                    }
1390
                    }
1388
                }
1391
                }
1389
            }
1392
            }
1390
        }, skipAction, skipUnIndexed);
1393
        }, skipAction, skipUnIndexed);
1391
        doSortIssue226100(infos);
1394
        doSortIssue226100(infos);
1392
        Accessor.ACCESSOR.setVersionResults(result, infos);
1395
        result.setResults(infos);
1393
        return result;
1396
        return result;
1394
    }
1397
    }
1395
1398
1396
    @Override
1399
    @Override
1397
    public RepositoryQueries.Result<NBVersionInfo> findArchetypes(List<RepositoryInfo> repos) {
1400
    public ResultImplementation<NBVersionInfo> findArchetypes(List<RepositoryInfo> repos) {
1398
        RepositoryQueries.Result<NBVersionInfo> result = Accessor.ACCESSOR.createVersionResult(new Redo<NBVersionInfo>() {
1401
        ResultImpl<NBVersionInfo> result = new ResultImpl<>(new Redo<NBVersionInfo>() {
1399
            @Override
1402
            @Override
1400
            public void run(Result<NBVersionInfo> result) {
1403
            public void run(ResultImpl<NBVersionInfo> result) {
1401
                findArchetypes( result, Accessor.ACCESSOR.getSkipped(result), false);
1404
                findArchetypes( result, result.getSkipped(), false);
1402
            }
1405
            }
1403
        });
1406
        });
1404
        return findArchetypes( result, repos, true);
1407
        return findArchetypes( result, repos, true);
1405
    }
1408
    }
1406
    
1409
    
1407
    private RepositoryQueries.Result<NBVersionInfo> findArchetypes(final Result<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1410
    private ResultImplementation<NBVersionInfo> findArchetypes(final ResultImpl<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1408
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1411
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1409
        final SkippedAction skipAction = new SkippedAction(result);
1412
        final SkippedAction skipAction = new SkippedAction(result);
1410
        iterate(repos, new RepoAction() {
1413
        iterate(repos, new RepoAction() {
Lines 1423-1452 Link Here
1423
                            infos.add(convertToNBVersionInfo(ai));
1426
                            infos.add(convertToNBVersionInfo(ai));
1424
                        }
1427
                        }
1425
                    } finally {
1428
                    } finally {
1426
                        Accessor.ACCESSOR.addReturnedResults(result, response.getTotalProcessedArtifactInfoCount());
1429
                        result.addReturnedResultCount(response.getTotalProcessedArtifactInfoCount());
1427
                        Accessor.ACCESSOR.addTotalResults(result, response.getTotalHitsCount());
1430
                        result.addTotalResultCount(response.getTotalHitsCount());
1428
                        response.close();
1431
                        response.close();
1429
                    }
1432
                    }
1430
                }
1433
                }
1431
            }
1434
            }
1432
        }, skipAction, skipUnIndexed);
1435
        }, skipAction, skipUnIndexed);
1433
        doSortIssue226100(infos);
1436
        doSortIssue226100(infos);
1434
        Accessor.ACCESSOR.setVersionResults(result, infos);
1437
        result.setResults(infos);
1435
        return result;
1438
        return result;
1436
    }
1439
    }
1437
1440
1438
    @Override
1441
    @Override
1439
    public RepositoryQueries.Result<String> filterPluginArtifactIds(final String groupId, final String prefix, List<RepositoryInfo> repos) {
1442
    public ResultImplementation<String> filterPluginArtifactIds(final String groupId, final String prefix, List<RepositoryInfo> repos) {
1440
        RepositoryQueries.Result<String> result = Accessor.ACCESSOR.createStringResult(new Redo<String>() {
1443
        ResultImpl<String> result = new ResultImpl<>(new Redo<String>() {
1441
            @Override
1444
            @Override
1442
            public void run(Result<String> result) {
1445
            public void run(ResultImpl<String> result) {
1443
                filterPluginArtifactIds(groupId, prefix, result, Accessor.ACCESSOR.getSkipped(result), false);
1446
                filterPluginArtifactIds(groupId, prefix, result, result.getSkipped(), false);
1444
            }
1447
            }
1445
        });
1448
        });
1446
        return filterPluginArtifactIds(groupId, prefix, result, repos, true);
1449
        return filterPluginArtifactIds(groupId, prefix, result, repos, true);
1447
    }
1450
    }
1448
    
1451
    
1449
    private RepositoryQueries.Result<String> filterPluginArtifactIds(final String groupId, final String prefix, Result<String> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1452
    private ResultImplementation<String> filterPluginArtifactIds(final String groupId, final String prefix, ResultImpl<String> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1450
        final Set<String> artifacts = new TreeSet<String>(result.getResults());
1453
        final Set<String> artifacts = new TreeSet<String>(result.getResults());
1451
        final SkippedAction skipAction = new SkippedAction(result);
1454
        final SkippedAction skipAction = new SkippedAction(result);
1452
        iterate(repos, new RepoAction() {
1455
        iterate(repos, new RepoAction() {
Lines 1468-1489 Link Here
1468
                }
1471
                }
1469
            }
1472
            }
1470
        }, skipAction, skipUnIndexed);
1473
        }, skipAction, skipUnIndexed);
1471
        Accessor.ACCESSOR.setStringResults(result, artifacts);
1474
        result.setResults(artifacts);
1472
        return result;
1475
        return result;
1473
    }
1476
    }
1474
1477
1475
    @Override
1478
    @Override
1476
    public RepositoryQueries.Result<String> filterPluginGroupIds(final String prefix, List<RepositoryInfo> repos) {
1479
    public ResultImplementation<String> filterPluginGroupIds(final String prefix, List<RepositoryInfo> repos) {
1477
        RepositoryQueries.Result<String> result = Accessor.ACCESSOR.createStringResult(new Redo<String>() {
1480
        ResultImpl<String> result = new ResultImpl<>(new Redo<String>() {
1478
            @Override
1481
            @Override
1479
            public void run(Result<String> result) {
1482
            public void run(ResultImpl<String> result) {
1480
                filterPluginGroupIds( prefix, result, Accessor.ACCESSOR.getSkipped(result), false);
1483
                filterPluginGroupIds( prefix, result, result.getSkipped(), false);
1481
            }
1484
            }
1482
        });
1485
        });
1483
        return filterPluginGroupIds( prefix, result, repos, true);
1486
        return filterPluginGroupIds( prefix, result, repos, true);
1484
    }
1487
    }
1485
    
1488
    
1486
    private RepositoryQueries.Result<String> filterPluginGroupIds(final String prefix, Result<String> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1489
    private ResultImplementation<String> filterPluginGroupIds(final String prefix, ResultImpl<String> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1487
        final Set<String> artifacts = new TreeSet<String>(result.getResults());
1490
        final Set<String> artifacts = new TreeSet<String>(result.getResults());
1488
        final SkippedAction skipAction = new SkippedAction(result);
1491
        final SkippedAction skipAction = new SkippedAction(result);
1489
        iterate(repos, new RepoAction() {
1492
        iterate(repos, new RepoAction() {
Lines 1506-1526 Link Here
1506
                }
1509
                }
1507
            }
1510
            }
1508
        }, skipAction, skipUnIndexed);
1511
        }, skipAction, skipUnIndexed);
1509
        Accessor.ACCESSOR.setStringResults(result, artifacts);
1512
        result.setResults(artifacts);
1510
        return result;
1513
        return result;
1511
    }
1514
    }
1512
1515
1513
    @Override
1516
    @Override
1514
    public RepositoryQueries.Result<String> filterArtifactIdForGroupId(final String groupId, final String prefix, List<RepositoryInfo> repos) {
1517
    public ResultImplementation<String> filterArtifactIdForGroupId(final String groupId, final String prefix, List<RepositoryInfo> repos) {
1515
        RepositoryQueries.Result<String> result = Accessor.ACCESSOR.createStringResult(new Redo<String>() {
1518
        ResultImpl<String> result = new ResultImpl<>(new Redo<String>() {
1516
            @Override
1519
            @Override
1517
            public void run(Result<String> result) {
1520
            public void run(ResultImpl<String> result) {
1518
                filterArtifactIdForGroupId( groupId, prefix, result, Accessor.ACCESSOR.getSkipped(result), false);
1521
                filterArtifactIdForGroupId( groupId, prefix, result, result.getSkipped(), false);
1519
            }
1522
            }
1520
        });
1523
        });
1521
        return filterArtifactIdForGroupId( groupId, prefix, result, repos, true);
1524
        return filterArtifactIdForGroupId( groupId, prefix, result, repos, true);
1522
    }
1525
    }
1523
    private RepositoryQueries.Result<String> filterArtifactIdForGroupId(final String groupId, final String prefix, Result<String> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1526
    private ResultImplementation<String> filterArtifactIdForGroupId(final String groupId, final String prefix, ResultImpl<String> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1524
        final Set<String> artifacts = new TreeSet<String>(result.getResults());
1527
        final Set<String> artifacts = new TreeSet<String>(result.getResults());
1525
        final SkippedAction skipAction = new SkippedAction(result);
1528
        final SkippedAction skipAction = new SkippedAction(result);
1526
        iterate(repos, new RepoAction() {
1529
        iterate(repos, new RepoAction() {
Lines 1541-1561 Link Here
1541
                }
1544
                }
1542
            }
1545
            }
1543
        }, skipAction, skipUnIndexed);       
1546
        }, skipAction, skipUnIndexed);       
1544
        Accessor.ACCESSOR.setStringResults(result, artifacts);
1547
        result.setResults(artifacts);
1545
        return result;
1548
        return result;
1546
    }
1549
    }
1547
1550
1548
    @Override
1551
    @Override
1549
    public RepositoryQueries.Result<NBVersionInfo> find(final List<QueryField> fields, List<RepositoryInfo> repos) {
1552
    public ResultImplementation<NBVersionInfo> find(final List<QueryField> fields, List<RepositoryInfo> repos) {
1550
        RepositoryQueries.Result<NBVersionInfo> result = Accessor.ACCESSOR.createVersionResult(new Redo<NBVersionInfo>() {
1553
        ResultImpl<NBVersionInfo> result = new ResultImpl<>(new Redo<NBVersionInfo>() {
1551
            @Override
1554
            @Override
1552
            public void run(Result<NBVersionInfo> result) {
1555
            public void run(ResultImpl<NBVersionInfo> result) {
1553
                find( fields, result, Accessor.ACCESSOR.getSkipped(result), false);
1556
                find( fields, result, result.getSkipped(), false);
1554
            }
1557
            }
1555
        });
1558
        });
1556
        return find(fields,  result, repos, true);
1559
        return find(fields,  result, repos, true);
1557
    }
1560
    }
1558
    private RepositoryQueries.Result<NBVersionInfo> find(final List<QueryField> fields, final Result<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1561
    private ResultImplementation<NBVersionInfo> find(final List<QueryField> fields, final ResultImpl<NBVersionInfo> result, List<RepositoryInfo> repos, final boolean skipUnIndexed) {
1559
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1562
        final List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(result.getResults());
1560
        final SkippedAction skipAction = new SkippedAction(result);
1563
        final SkippedAction skipAction = new SkippedAction(result);
1561
        iterate(repos, new RepoAction() {
1564
        iterate(repos, new RepoAction() {
Lines 1633-1647 Link Here
1633
                            infos.add(convertToNBVersionInfo(ai));
1636
                            infos.add(convertToNBVersionInfo(ai));
1634
                        }
1637
                        }
1635
                    } finally {
1638
                    } finally {
1636
                        Accessor.ACCESSOR.addReturnedResults(result, resp.getTotalProcessedArtifactInfoCount());
1639
                        result.addReturnedResultCount(resp.getTotalProcessedArtifactInfoCount());
1637
                        Accessor.ACCESSOR.addTotalResults(result, resp.getTotalHitsCount());
1640
                        result.addTotalResultCount(resp.getTotalHitsCount());
1638
                        resp.close();
1641
                        resp.close();
1639
                    }
1642
                    }
1640
                }
1643
                }
1641
            }
1644
            }
1642
        }, skipAction, skipUnIndexed);
1645
        }, skipAction, skipUnIndexed);
1643
        doSortIssue226100(infos);
1646
        doSortIssue226100(infos);
1644
        Accessor.ACCESSOR.setVersionResults(result, infos);
1647
        result.setResults(infos);
1645
        return result;
1648
        return result;
1646
    }
1649
    }
1647
    
1650
    
Lines 1778-1793 Link Here
1778
1781
1779
    private static class SkippedAction implements RepoAction {
1782
    private static class SkippedAction implements RepoAction {
1780
1783
1781
        private final Result<?> result;
1784
        private final ResultImpl<?> result;
1782
1785
1783
        private SkippedAction(Result<?> result) {
1786
        private SkippedAction(ResultImpl<?> result) {
1784
            this.result = result;
1787
            this.result = result;
1785
        }
1788
        }
1786
        
1789
        
1787
        @Override
1790
        @Override
1788
        public void run(RepositoryInfo repo, IndexingContext context) throws IOException {
1791
        public void run(RepositoryInfo repo, IndexingContext context) throws IOException {
1789
            //indexing context is always null here..
1792
            //indexing context is always null here..
1790
            Accessor.ACCESSOR.addSkipped(result, repo);
1793
            result.addSkipped(repo);
1791
        }
1794
        }
1792
        
1795
        
1793
    }
1796
    }
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/OnStop.java (-1 / +1 lines)
Lines 44-50 Link Here
44
44
45
import java.util.logging.Level;
45
import java.util.logging.Level;
46
import java.util.logging.Logger;
46
import java.util.logging.Logger;
47
import org.netbeans.modules.maven.indexer.spi.RepositoryIndexerImplementation;
47
import org.netbeans.modules.maven.indexer.spi.impl.RepositoryIndexerImplementation;
48
import org.openide.util.Lookup;
48
import org.openide.util.Lookup;
49
49
50
@org.openide.modules.OnStop
50
@org.openide.modules.OnStop
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/ResultImpl.java (+151 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2016 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 2016 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.maven.indexer;
43
44
import java.util.ArrayList;
45
import java.util.Collection;
46
import java.util.Collections;
47
import java.util.List;
48
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
49
import org.netbeans.modules.maven.indexer.spi.ResultImplementation;
50
import org.netbeans.modules.maven.indexer.spi.impl.Redo;
51
import org.netbeans.modules.project.spi.intern.ProjectIDEServices;
52
53
/**
54
 *
55
 * @author tomas
56
 */
57
public class ResultImpl<T> implements ResultImplementation {
58
    private final List<RepositoryInfo> skipped = new ArrayList<RepositoryInfo>();
59
    private List<T> results = new ArrayList<T>();
60
    private final Redo<T> redoAction;
61
62
    int totalResults = 0;
63
    int returnedResults = 0;
64
65
    /**
66
     * used internally by the repository indexing/searching engine(s)
67
     */
68
    public ResultImpl(Redo<T> redo) {
69
        redoAction = redo;
70
    }
71
72
    /**
73
     * returns true is one or more indexes were skipped, eg because the indexing was taking place.
74
     * @return 
75
     */
76
    @Override
77
    public synchronized boolean isPartial() {
78
        return !skipped.isEmpty();
79
    }
80
81
    /**
82
     * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped
83
     */
84
    synchronized void addSkipped(RepositoryInfo info) {
85
        skipped.add(info);
86
    }
87
88
    /**
89
     * waits for currently unaccessible indexes to finish, not to be called in AWT thread.
90
     */
91
    @Override
92
    public void waitForSkipped() {
93
        assert !ProjectIDEServices.isEventDispatchThread();
94
        redoAction.run(this);
95
        synchronized (this) {
96
            skipped.clear();
97
        }
98
    }
99
100
    synchronized void setResults(Collection<T> newResults) {
101
        results.clear();
102
        results.addAll(newResults);
103
    }
104
105
    @Override
106
    public synchronized List<T> getResults() {
107
        return Collections.unmodifiableList(results);
108
    }
109
110
111
    /**
112
     * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped
113
     */
114
    synchronized void addSkipped(Collection<RepositoryInfo> infos) {
115
        skipped.addAll(infos);
116
    }
117
118
    /**
119
     * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped
120
     */
121
    synchronized List<RepositoryInfo> getSkipped() {
122
        return Collections.unmodifiableList(skipped);
123
    }
124
    /**
125
     * total number of hits
126
     * @return
127
     * @since 2.20
128
     */
129
    @Override
130
    public int getTotalResultCount() {
131
        return totalResults;
132
    }
133
134
    void addTotalResultCount(int moreTotalResults) {
135
        totalResults += moreTotalResults;
136
    }
137
    /**
138
     * in some cases not entirely accurate number of processed and returned hits, typically should be less or equals to totalResultCount
139
     * @return 
140
     * @since 2.20
141
     */
142
    @Override
143
    public int getReturnedResultCount() {
144
        return returnedResults;
145
    }
146
147
    void addReturnedResultCount(int moreReturnedResults) {
148
        returnedResults = moreReturnedResults + returnedResults;
149
    }
150
    
151
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryIndexer.java (-7 / +28 lines)
Lines 43-51 Link Here
43
43
44
import java.util.Collection;
44
import java.util.Collection;
45
import org.apache.maven.artifact.Artifact;
45
import org.apache.maven.artifact.Artifact;
46
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.modules.maven.indexer.NexusRepositoryIndexerImpl;
47
import org.netbeans.modules.maven.indexer.spi.RepositoryIndexerImplementation;
47
import org.netbeans.modules.maven.indexer.spi.impl.RepositoryIndexerImplementation;
48
import org.openide.util.Lookup;
48
import org.openide.util.Lookup;
49
import org.netbeans.modules.maven.indexer.spi.RepositoryIndexQueryProvider;
49
50
50
/**
51
/**
51
 *
52
 *
Lines 55-81 Link Here
55
56
56
    public static void indexRepo(RepositoryInfo repo) {
57
    public static void indexRepo(RepositoryInfo repo) {
57
        assert repo != null;
58
        assert repo != null;
58
        findImplementation().indexRepo(repo);
59
        RepositoryIndexerImplementation impl = findImplementation(repo);
60
        if(impl != null) {
61
            // fires 
62
            impl.indexRepo(repo);
63
        } else {
64
            repo.fireChangeIndex();
59
    }
65
    }
66
    }
60
    
67
    
61
    public static void updateIndexWithArtifacts(RepositoryInfo repo, Collection<Artifact> artifacts) {
68
    public static void updateIndexWithArtifacts(RepositoryInfo repo, Collection<Artifact> artifacts) {
62
        assert repo != null;
69
        assert repo != null;
63
        if (artifacts == null || artifacts.isEmpty()) {
70
        if (artifacts == null || artifacts.isEmpty()) {
64
            return;
71
            return;
65
        }
72
        }
66
        findImplementation().updateIndexWithArtifacts(repo, artifacts);
73
        RepositoryIndexerImplementation impl = findImplementation(repo);
74
        if(impl != null) {
75
            impl.updateIndexWithArtifacts(repo, artifacts);
67
    }
76
    }
77
    }
68
78
69
    public static void deleteArtifactFromIndex(RepositoryInfo repo, Artifact artifact) {
79
    public static void deleteArtifactFromIndex(RepositoryInfo repo, Artifact artifact) {
70
        assert repo != null;
80
        assert repo != null;
71
        if (artifact == null) {
81
        if (artifact == null) {
72
            return;
82
            return;
73
        }
83
        }
74
        findImplementation().deleteArtifactFromIndex(repo, artifact);
84
        RepositoryIndexerImplementation impl = findImplementation(repo);
85
        if(impl != null) {
86
            impl.deleteArtifactFromIndex(repo, artifact);
75
    }
87
    }
88
    }
76
    
89
    
77
    static @NonNull RepositoryIndexerImplementation findImplementation() {
90
    static RepositoryIndexerImplementation findImplementation(RepositoryInfo repo) {
78
        return Lookup.getDefault().lookup(RepositoryIndexerImplementation.class);
91
        Lookup l = Lookup.getDefault();
92
        Collection<? extends RepositoryIndexQueryProvider> queryProviders = l.lookupAll(RepositoryIndexQueryProvider.class);
93
        for (RepositoryIndexQueryProvider queryProvider : queryProviders) {
94
            if(!(queryProvider instanceof NexusRepositoryIndexerImpl) && queryProvider.handlesRepository(repo)) {
95
                // skip if 
96
                return null;
79
    }
97
    }
98
        }
99
        return l.lookup(RepositoryIndexerImplementation.class);
100
    }
80
    
101
    
81
}
102
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/api/RepositoryQueries.java (-168 / +195 lines)
Lines 46-63 Link Here
46
import java.io.IOException;
46
import java.io.IOException;
47
import java.util.ArrayList;
47
import java.util.ArrayList;
48
import java.util.Collection;
48
import java.util.Collection;
49
import java.util.Collections;
49
import java.util.HashMap;
50
import java.util.Iterator;
50
import java.util.Iterator;
51
import java.util.LinkedList;
51
import java.util.List;
52
import java.util.List;
53
import java.util.Map;
54
import java.util.Map.Entry;
52
import java.util.Set;
55
import java.util.Set;
53
import java.util.logging.Level;
56
import java.util.logging.Level;
54
import java.util.logging.Logger;
57
import java.util.logging.Logger;
58
import org.apache.lucene.search.BooleanQuery;
55
import org.netbeans.api.annotations.common.NonNull;
59
import org.netbeans.api.annotations.common.NonNull;
56
import org.netbeans.api.annotations.common.NullAllowed;
60
import org.netbeans.api.annotations.common.NullAllowed;
57
import org.netbeans.modules.maven.indexer.NexusRepositoryIndexerImpl;
61
import org.netbeans.modules.maven.indexer.ResultImpl;
58
import org.netbeans.modules.maven.indexer.spi.*;
62
import org.netbeans.modules.maven.indexer.spi.ArchetypeQueries;
63
import org.netbeans.modules.maven.indexer.spi.BaseQueries;
64
import org.netbeans.modules.maven.indexer.spi.ChecksumQueries;
65
import org.netbeans.modules.maven.indexer.spi.ClassUsageQuery;
66
import org.netbeans.modules.maven.indexer.spi.ClassesQuery;
67
import org.netbeans.modules.maven.indexer.spi.ContextLoadedQuery;
68
import org.netbeans.modules.maven.indexer.spi.DependencyInfoQueries;
69
import org.netbeans.modules.maven.indexer.spi.GenericFindQuery;
70
import org.netbeans.modules.maven.indexer.spi.NullResultImpl;
71
import org.netbeans.modules.maven.indexer.spi.ResultImplementation;
59
import org.netbeans.modules.project.spi.intern.ProjectIDEServices;
72
import org.netbeans.modules.project.spi.intern.ProjectIDEServices;
60
import org.openide.util.Lookup;
73
import org.openide.util.Lookup;
74
import org.netbeans.modules.maven.indexer.spi.RepositoryIndexQueryProvider;
61
75
62
/**
76
/**
63
 * Searches Maven repositories in various ways.
77
 * Searches Maven repositories in various ways.
Lines 71-246 Link Here
71
85
72
    /**
86
    /**
73
     * query result set
87
     * query result set
88
     * @param <T>
74
     * @since 2.9
89
     * @since 2.9
75
     */
90
     */
76
    public final static class Result<T> {
91
    public final static class Result<T> {
77
        private final List<RepositoryInfo> skipped = new ArrayList<RepositoryInfo>();
92
        private final ResultImplementation<T> impl;
78
        private List<T> results = new ArrayList<T>();
79
        private final Redo<T> redoAction;
80
        int totalResults = 0;
81
        int returnedResults = 0;
82
        
93
        
83
        /**
94
        /**
84
         * used internally by the repository indexing/searching engine(s)
95
         * Creates a Result instance.
96
         * @param impl 
85
         */
97
         */
86
        Result(Redo<T> redo) {
98
        public Result(ResultImplementation<T> impl) {
87
            redoAction = redo;
99
            this.impl = impl;
88
        }
100
        }
89
        
101
        
90
        /**
102
        /**
91
         * returns true is one or more indexes were skipped, eg because the indexing was taking place.
103
         * Returns true is one or more indexes were skipped, e.g. because the indexing was taking place.
92
         * @return 
104
         * @return 
93
         */
105
         */
94
        public synchronized boolean isPartial() {
106
        public synchronized boolean isPartial() {
95
            return !skipped.isEmpty();
107
            return impl.isPartial();
96
        }
108
        }
97
        
109
        
98
        /**
110
        /**
99
         * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped
111
         * Waits for currently unaccessible indexes to finish, not to be called in AWT thread.
100
         */
112
         */
101
        synchronized void addSkipped(RepositoryInfo info) {
102
            skipped.add(info);
103
        }
104
        
105
        /**
106
         * waits for currently unaccessible indexes to finish, not to be called in AWT thread.
107
         */
108
        public void waitForSkipped() {
113
        public void waitForSkipped() {
109
            assert !ProjectIDEServices.isEventDispatchThread();
114
            assert !ProjectIDEServices.isEventDispatchThread();
110
            redoAction.run(this);
115
            impl.waitForSkipped();
111
            synchronized (this) {
112
                skipped.clear();
113
            }
116
            }
114
        }
115
        
117
        
116
        synchronized void setResults(Collection<T> newResults) {
117
            results.clear();
118
            results.addAll(newResults);
119
        }
120
        
121
        public synchronized List<T> getResults() {
122
            return Collections.unmodifiableList(results);
123
        }
124
        
125
        
126
        /**
118
        /**
127
         * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped
119
         * Returns a list of results
120
         * @return 
128
         */
121
         */
129
        synchronized void addSkipped(Collection<RepositoryInfo> infos) {
122
        public synchronized List<T> getResults() {
130
            skipped.addAll(infos);
123
            return impl.getResults();
131
        }
124
        }
132
        
125
        
133
        /**
126
        /**
134
         * used internally by the repository indexing/searching engine(s) to mark the result as partially skipped
127
         * Total number of hits
135
         */
136
        synchronized List<RepositoryInfo> getSkipped() {
137
            return Collections.unmodifiableList(skipped);
138
        }
139
        /**
140
         * total number of hits
141
         * @return
128
         * @return
142
         * @since 2.20
129
         * @since 2.20
143
         */
130
         */
144
        public int getTotalResultCount() {
131
        public int getTotalResultCount() {
145
            return totalResults;
132
            return impl.getTotalResultCount();
146
        }
133
        }
147
134
148
        void addTotalResultCount(int moreTotalResults) {
149
            totalResults = totalResults + moreTotalResults;
150
        }
151
        /**
135
        /**
152
         * in some cases not entirely accurate number of processed and returned hits, typically should be less or equals to totalResultCount
136
         * in some cases not entirely accurate number of processed and returned hits, typically should be less or equals to totalResultCount
153
         * @return 
137
         * @return 
154
         * @since 2.20
138
         * @since 2.20
155
         */
139
         */
156
        public int getReturnedResultCount() {
140
        public int getReturnedResultCount() {
157
            return returnedResults;
141
            return impl.getReturnedResultCount();
158
        }
142
        }
159
160
        void addReturnedResultCount(int moreReturnedResults) {
161
            returnedResults = returnedResults + moreReturnedResults;
162
        }
143
        }
163
        
144
        
145
    private final static class CompositeResult<T> implements ResultImplementation {
164
        
146
        
147
        private final List<ResultImplementation<T>> results;
165
        
148
        
149
        public CompositeResult(List<ResultImplementation<T>> results) {
150
            this.results = results;
166
    } 
151
    } 
167
    
152
    
168
    
169
    static {
170
        new AccessorImpl();       
171
    }
172
    
173
    
174
    
175
    static class AccessorImpl extends NexusRepositoryIndexerImpl.Accessor {
176
177
        @Override
153
        @Override
178
        public void addSkipped(Result<?> result, Collection<RepositoryInfo> infos) {
154
        public boolean isPartial() {
179
            result.addSkipped(infos);
155
            for (ResultImplementation<T> result : results) {
156
                if(result.isPartial()) {
157
                    return true;
180
        }
158
        }
181
182
        @Override
183
        public List<RepositoryInfo> getSkipped(Result<?> result) {
184
            return result.getSkipped();
185
        }
159
        }
186
160
            return false;
187
        @Override
188
        public void addSkipped(Result<?> result, RepositoryInfo info) {
189
            result.addSkipped(info);
190
        }
161
        }
191
162
192
        @Override
163
        @Override
193
        public Result<String> createStringResult(Redo<String> redo) {
164
        public void waitForSkipped() {
194
            return new Result<String>(redo);
165
            for (ResultImplementation<T> result : results) {
166
                result.waitForSkipped();
195
        }
167
        }
196
197
        @Override
198
        public Result<NBVersionInfo> createVersionResult(Redo<NBVersionInfo> redo) {
199
            return new Result<NBVersionInfo>(redo);
200
        }
168
        }
201
169
202
        @Override
170
        @Override
203
        public void setStringResults(Result<String> result, Collection<String> newResults) {
171
        public List<T> getResults() {
204
            result.setResults(newResults);
172
            List<T> ret = new LinkedList<>();
173
            for (ResultImplementation<T> result : results) {
174
                ret.addAll(result.getResults());
205
        }
175
        }
206
176
            return ret;
207
        @Override
208
        public void setVersionResults(Result<NBVersionInfo> result, Collection<NBVersionInfo> newResults) {
209
            result.setResults(newResults);
210
        }
177
        }
211
178
212
        @Override
179
        @Override
213
        public Result<NBGroupInfo> createGroupResult(Redo<NBGroupInfo> redo) {
180
        public int getTotalResultCount() {
214
            return new Result<NBGroupInfo>(redo);
181
            int ret = 0;
182
            for (ResultImplementation<T> result : results) {
183
                ret += result.getTotalResultCount();
215
        }
184
        }
216
185
            return ret;
217
        @Override
218
        public void setGroupResults(Result<NBGroupInfo> result, Collection<NBGroupInfo> newResults) {
219
            result.setResults(newResults);
220
        }
186
        }
221
187
222
        @Override
188
        @Override
223
        public Result<ClassUsage> createClassResult(Redo<ClassUsage> redo) {
189
        public int getReturnedResultCount() {
224
            return new Result<ClassUsage>(redo);
190
            int ret = 0;
191
            for (ResultImplementation<T> result : results) {
192
                ret += result.getReturnedResultCount();
225
        }
193
        }
226
194
            return ret;
227
        @Override
228
        public void setClassResults(Result<ClassUsage> result, Collection<ClassUsage> newResults) {
229
            result.setResults(newResults);
230
        }
195
        }
231
196
232
        @Override
233
        public void addTotalResults(Result<?> result, int moreResults) {
234
            result.addTotalResultCount(moreResults);
235
        }
197
        }
236
198
237
        @Override
238
        public void addReturnedResults(Result<?> result, int moreResults) {
239
            result.addReturnedResultCount(moreResults);
240
        }
241
    }
242
    
243
    
244
   /**
199
   /**
245
     * One usage result.
200
     * One usage result.
246
     */
201
     */
Lines 268-278 Link Here
268
        }
223
        }
269
    }
224
    }
270
    
225
    
226
    private static interface QueryCall<T> {
227
        ResultImplementation<T> call(RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos);
228
    }
271
    
229
    
272
    private static @NonNull BaseQueries findBaseQueries() {
230
    private static <T> Result<T> getQueryResult(List<RepositoryInfo> repos, QueryCall<T> c) {
273
        return Lookup.getDefault().lookup(BaseQueries.class);
231
        List<ResultImplementation<T>> results = new LinkedList<>();
232
        if (repos == null) {
233
            repos = RepositoryPreferences.getInstance().getRepositoryInfos();
274
    }
234
    }
235
        Map<RepositoryIndexQueryProvider, List<RepositoryInfo>> qp2Repo = getQueryProvider2Repo(repos);
236
        for(Map.Entry<RepositoryIndexQueryProvider, List<RepositoryInfo>> e : qp2Repo.entrySet()) {
237
            results.add(c.call(e.getKey(), e.getValue()));
238
        }
239
        return new Result<>(new CompositeResult<>(results));
240
    }
275
241
242
    private static Map<RepositoryIndexQueryProvider, List<RepositoryInfo>> getQueryProvider2Repo(List<RepositoryInfo> repos) {
243
        Collection<? extends RepositoryIndexQueryProvider> idxs = Lookup.getDefault().lookupAll(RepositoryIndexQueryProvider.class);
244
        Map<RepositoryIndexQueryProvider, List<RepositoryInfo>> qp2Repo = new HashMap<>();
245
        for (RepositoryInfo repo : repos) {
246
            for (RepositoryIndexQueryProvider idx : idxs) {
247
                if(idx.handlesRepository(repo)) {
248
                    List<RepositoryInfo> mappedRepos = qp2Repo.get(idx);
249
                    if(mappedRepos == null) {
250
                        mappedRepos = new LinkedList<>();
251
                        qp2Repo.put(idx, mappedRepos);
252
                    }
253
                    mappedRepos.add(repo);
254
                    break;
255
                }
256
            }
257
        }
258
        return qp2Repo;
259
    }
260
    
276
    /**
261
    /**
277
     * 
262
     * 
278
     * @param repos
263
     * @param repos
Lines 280-286 Link Here
280
     * @since 2.9
265
     * @since 2.9
281
     */
266
     */
282
    public static Result<String> getGroupsResult(@NullAllowed List<RepositoryInfo> repos) {
267
    public static Result<String> getGroupsResult(@NullAllowed List<RepositoryInfo> repos) {
283
        return findBaseQueries().getGroups(repos);
268
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
269
            BaseQueries baseQueries = queryProvider.getBaseQueries();
270
            assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null";
271
            return baseQueries.getGroups(providerRepos);
272
        });
284
    }
273
    }
285
    
274
    
286
    /**
275
    /**
Lines 291-300 Link Here
291
     * @since 2.9
280
     * @since 2.9
292
     */
281
     */
293
    public static Result<String> filterGroupIdsResult(String prefix, @NullAllowed List<RepositoryInfo> repos) {
282
    public static Result<String> filterGroupIdsResult(String prefix, @NullAllowed List<RepositoryInfo> repos) {
294
        return findBaseQueries().filterGroupIds(prefix, repos);
283
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
284
            BaseQueries baseQueries = queryProvider.getBaseQueries();
285
            assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null";
286
            return baseQueries.filterGroupIds(prefix, providerRepos);
287
        });
295
    }
288
    }
296
289
297
    
298
    /**
290
    /**
299
     * 
291
     * 
300
     * @param groupId
292
     * @param groupId
Lines 305-311 Link Here
305
     * @since 2.9
297
     * @since 2.9
306
     */
298
     */
307
    public static Result<NBVersionInfo> getRecordsResult(String groupId, String artifactId, String version, @NullAllowed List<RepositoryInfo> repos) {
299
    public static Result<NBVersionInfo> getRecordsResult(String groupId, String artifactId, String version, @NullAllowed List<RepositoryInfo> repos) {
308
        return findBaseQueries().getRecords(groupId, artifactId, version, repos);
300
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
301
            BaseQueries baseQueries = queryProvider.getBaseQueries();
302
            assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null";
303
            return baseQueries.getRecords(groupId, artifactId, version, providerRepos);
304
        });
309
    }
305
    }
310
    
306
    
311
    /**
307
    /**
Lines 316-325 Link Here
316
     * @since 2.28
312
     * @since 2.28
317
     */
313
     */
318
    public static Result<String> getGAVsForPackaging(String packaging, @NullAllowed List<RepositoryInfo> repos) {
314
    public static Result<String> getGAVsForPackaging(String packaging, @NullAllowed List<RepositoryInfo> repos) {
319
        return findBaseQueries().getGAVsForPackaging(packaging, repos);
315
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
316
            BaseQueries baseQueries = queryProvider.getBaseQueries();
317
            assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null";
318
            return baseQueries.getGAVsForPackaging(packaging, providerRepos);
319
        });
320
    }    
320
    }    
321
321
322
    
323
    /**
322
    /**
324
     * 
323
     * 
325
     * @param groupId
324
     * @param groupId
Lines 328-337 Link Here
328
     * @since 2.9
327
     * @since 2.9
329
     */
328
     */
330
    public static Result<String> getArtifactsResult(String groupId, @NullAllowed List<RepositoryInfo> repos) {
329
    public static Result<String> getArtifactsResult(String groupId, @NullAllowed List<RepositoryInfo> repos) {
331
        return findBaseQueries().getArtifacts(groupId, repos);
330
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
331
            BaseQueries baseQueries = queryProvider.getBaseQueries();
332
            assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null";
333
            return baseQueries.getArtifacts(groupId, providerRepos);
334
        });
332
    }
335
    }
333
336
334
    
335
    /**
337
    /**
336
     * 
338
     * 
337
     * @param groupId
339
     * @param groupId
Lines 341-354 Link Here
341
     * @since 2.9
343
     * @since 2.9
342
     */
344
     */
343
    public static Result<NBVersionInfo> getVersionsResult(String groupId, String artifactId, @NullAllowed List<RepositoryInfo> repos) {
345
    public static Result<NBVersionInfo> getVersionsResult(String groupId, String artifactId, @NullAllowed List<RepositoryInfo> repos) {
344
        return findBaseQueries().getVersions(groupId, artifactId, repos);
346
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
347
            BaseQueries baseQueries = queryProvider.getBaseQueries();
348
            assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null";
349
            return baseQueries.getVersions(groupId, artifactId, providerRepos);
350
        });
345
    }
351
    }
346
352
347
    
348
    private static @NonNull DependencyInfoQueries findDIQ() {
349
        return Lookup.getDefault().lookup(DependencyInfoQueries.class);
350
    }
351
    
352
    /**
353
    /**
353
     * 
354
     * 
354
     * @param groupId
355
     * @param groupId
Lines 359-368 Link Here
359
     * @since 2.9
360
     * @since 2.9
360
     */
361
     */
361
    public static Result<NBGroupInfo> findDependencyUsageResult(String groupId, String artifactId, String version, @NullAllowed List<RepositoryInfo> repos) {
362
    public static Result<NBGroupInfo> findDependencyUsageResult(String groupId, String artifactId, String version, @NullAllowed List<RepositoryInfo> repos) {
362
        return findDIQ().findDependencyUsageGroups(groupId, artifactId, version, repos);
363
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
364
            DependencyInfoQueries dependencyInfoQueries = queryProvider.getDependencyInfoQueries();
365
            return dependencyInfoQueries != null ? 
366
                    dependencyInfoQueries.findDependencyUsageGroups(groupId, artifactId, version, providerRepos) :
367
                    new NullResultImpl<NBGroupInfo>();
368
        });        
363
    }
369
    }
364
    
370
    
365
    
366
    /**
371
    /**
367
     * 
372
     * 
368
     * @param file
373
     * @param file
Lines 377-402 Link Here
377
        } catch (IOException ex) {
382
        } catch (IOException ex) {
378
            Logger.getLogger(RepositoryQueries.class.getName()).log(Level.INFO, "Could not determine SHA-1 of " + file, ex);
383
            Logger.getLogger(RepositoryQueries.class.getName()).log(Level.INFO, "Could not determine SHA-1 of " + file, ex);
379
        }
384
        }
380
        return NexusRepositoryIndexerImpl.Accessor.ACCESSOR.createVersionResult(new Redo<NBVersionInfo>() {
385
        return new Result<>(new NullResultImpl<NBVersionInfo>());
381
            @Override
382
            public void run(Result<NBVersionInfo> result) {
383
                //noop
384
            }
386
            }
385
        });
386
        
387
        
387
    }
388
    
389
    private static ChecksumQueries findChecksumQueries() {
390
        return Lookup.getDefault().lookup(ChecksumQueries.class);
391
    }    
392
393
    private static Result<NBVersionInfo> findBySHA1(String sha1, @NullAllowed List<RepositoryInfo> repos) {
388
    private static Result<NBVersionInfo> findBySHA1(String sha1, @NullAllowed List<RepositoryInfo> repos) {
394
        return findChecksumQueries().findBySHA1(sha1, repos);
389
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
390
            ChecksumQueries checksumQueries = queryProvider.getChecksumQueries();
391
            return checksumQueries != null ? 
392
                    checksumQueries.findBySHA1(sha1, providerRepos) : 
393
                    new NullResultImpl<NBVersionInfo>();
394
        });
395
    }
395
    }
396
    
396
    
397
    private static @NonNull ClassesQuery findClassesQueries() {
398
        return Lookup.getDefault().lookup(ClassesQuery.class);
399
    }    
400
    /**
397
    /**
401
     * 
398
     * 
402
     * @param className
399
     * @param className
Lines 411-417 Link Here
411
     * @since 2.9
408
     * @since 2.9
412
     */
409
     */
413
    public static Result<NBVersionInfo> findVersionsByClassResult(final String className, @NullAllowed List<RepositoryInfo> repos) {
410
    public static Result<NBVersionInfo> findVersionsByClassResult(final String className, @NullAllowed List<RepositoryInfo> repos) {
414
        return findClassesQueries().findVersionsByClass(className, repos);
411
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
412
            ClassesQuery classesQuery = queryProvider.getClassesQuery();
413
            return classesQuery != null ? 
414
                    classesQuery.findVersionsByClass(className, providerRepos) : 
415
                    new NullResultImpl<NBVersionInfo>();
416
        });
415
    }
417
    }
416
418
417
    /**
419
    /**
Lines 440-446 Link Here
440
            RepositoryInfo repositoryInfo = it1.next();
442
            RepositoryInfo repositoryInfo = it1.next();
441
            List<RepositoryInfo> repositoryInfoL = new ArrayList<RepositoryInfo>(1);
443
            List<RepositoryInfo> repositoryInfoL = new ArrayList<RepositoryInfo>(1);
442
            repositoryInfoL.add(repositoryInfo);
444
            repositoryInfoL.add(repositoryInfo);
443
            query.addResults(findClassesQueries().findVersionsByClass(query.getClassName(), repositoryInfoL).getResults(), !it1.hasNext());
445
            Result<NBVersionInfo> queryResult = getQueryResult(repositoryInfoL, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
446
                ClassesQuery classesQuery = queryProvider.getClassesQuery();
447
                return classesQuery != null ? 
448
                        classesQuery.findVersionsByClass(query.getClassName(), providerRepos) : 
449
                        new NullResultImpl<NBVersionInfo>();
450
            });
451
            query.addResults(queryResult.getResults(), !it1.hasNext());
444
            // still someone waiting for results?
452
            // still someone waiting for results?
445
            if (query.countObservers() == 0)
453
            if (query.countObservers() == 0)
446
                return;
454
                return;
Lines 449-458 Link Here
449
            query.addResults(null, true);
457
            query.addResults(null, true);
450
    }
458
    }
451
    
459
    
452
    private static @NonNull ClassUsageQuery findClassUsageQuery() {
453
        return Lookup.getDefault().lookup(ClassUsageQuery.class);
454
    }
455
456
    /**
460
    /**
457
     * Finds all usages of a given class.
461
     * Finds all usages of a given class.
458
     * The implementation may not provide results within the same artifact, or on classes in the JRE.
462
     * The implementation may not provide results within the same artifact, or on classes in the JRE.
Lines 462-475 Link Here
462
     * @since 2.9
466
     * @since 2.9
463
     */
467
     */
464
    public static Result<ClassUsage> findClassUsagesResult(String className, @NullAllowed List<RepositoryInfo> repos) {
468
    public static Result<ClassUsage> findClassUsagesResult(String className, @NullAllowed List<RepositoryInfo> repos) {
465
        return findClassUsageQuery().findClassUsages(className, repos);
469
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
470
            ClassUsageQuery classUsageQuery = queryProvider.getClassUsageQuery();
471
            return classUsageQuery != null ? 
472
                    classUsageQuery.findClassUsages(className, repos) :
473
                    new NullResultImpl<ClassUsage>();
474
        });
466
    }
475
    }
467
476
468
    
469
    private static @NonNull ArchetypeQueries findArchetypeQueries() {
470
        return Lookup.getDefault().lookup(ArchetypeQueries.class);
471
    }
472
    
473
    /**
477
    /**
474
     * 
478
     * 
475
     * @param repos
479
     * @param repos
Lines 477-487 Link Here
477
     * @since 2.9
481
     * @since 2.9
478
     */
482
     */
479
    public static Result<NBVersionInfo> findArchetypesResult(@NullAllowed List<RepositoryInfo> repos) {
483
    public static Result<NBVersionInfo> findArchetypesResult(@NullAllowed List<RepositoryInfo> repos) {
480
        return findArchetypeQueries().findArchetypes(repos);
484
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
485
            ArchetypeQueries archetypeQueries = queryProvider.getArchetypeQueries();
486
            return archetypeQueries != null ? 
487
                    archetypeQueries.findArchetypes(repos) : 
488
                    new NullResultImpl<NBVersionInfo>();
489
        });
481
    }
490
    }
482
    
491
    
483
484
    
485
    /**
492
    /**
486
     * 
493
     * 
487
     * @param groupId
494
     * @param groupId
Lines 491-500 Link Here
491
     * @since 2.9
498
     * @since 2.9
492
     */
499
     */
493
    public static Result<String> filterPluginArtifactIdsResult(String groupId, String prefix, @NullAllowed List<RepositoryInfo> repos) {
500
    public static Result<String> filterPluginArtifactIdsResult(String groupId, String prefix, @NullAllowed List<RepositoryInfo> repos) {
494
        return findBaseQueries().filterPluginArtifactIds(groupId, prefix, repos);
501
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
502
            BaseQueries baseQueries = queryProvider.getBaseQueries();
503
            assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null";
504
            return baseQueries.filterPluginArtifactIds(groupId, prefix, providerRepos);
505
        });
495
    }
506
    }
496
507
497
    
498
    /**
508
    /**
499
     * 
509
     * 
500
     * @param prefix
510
     * @param prefix
Lines 503-516 Link Here
503
     * @since 2.9
513
     * @since 2.9
504
     */
514
     */
505
    public static Result<String> filterPluginGroupIdsResult(String prefix, @NullAllowed List<RepositoryInfo> repos) {
515
    public static Result<String> filterPluginGroupIdsResult(String prefix, @NullAllowed List<RepositoryInfo> repos) {
506
        return findBaseQueries().filterPluginGroupIds(prefix, repos);
516
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
517
            BaseQueries baseQueries = queryProvider.getBaseQueries();
518
            assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null";
519
            return baseQueries.filterPluginGroupIds(prefix, providerRepos);
520
        });
507
    }
521
    }
508
522
509
510
    private static @NonNull GenericFindQuery findFindQuery() {
511
        return Lookup.getDefault().lookup(GenericFindQuery.class);
512
    }
513
    
514
    /**
523
    /**
515
     * @throws BooleanQuery.TooManyClauses This runtime exception can be thrown if given query is too
524
     * @throws BooleanQuery.TooManyClauses This runtime exception can be thrown if given query is too
516
     * general and such search can't be executed as it would probably end with
525
     * general and such search can't be executed as it would probably end with
Lines 525-531 Link Here
525
     * @since 2.9
534
     * @since 2.9
526
     */
535
     */
527
    public static Result<NBVersionInfo> findResult(List<QueryField> fields, @NullAllowed List<RepositoryInfo> repos) {
536
    public static Result<NBVersionInfo> findResult(List<QueryField> fields, @NullAllowed List<RepositoryInfo> repos) {
528
        return findFindQuery().find(fields, repos);
537
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
538
            GenericFindQuery genericFindQuery = queryProvider.getGenericFindQuery();
539
            return genericFindQuery != null ? 
540
                    genericFindQuery.find(fields, providerRepos) : 
541
                    new NullResultImpl<NBVersionInfo>();
542
        });
529
    }
543
    }
530
544
531
    /**
545
    /**
Lines 553-559 Link Here
553
            RepositoryInfo repositoryInfo = it1.next();
567
            RepositoryInfo repositoryInfo = it1.next();
554
            List<RepositoryInfo> repositoryInfoL = new ArrayList<RepositoryInfo>(1);
568
            List<RepositoryInfo> repositoryInfoL = new ArrayList<RepositoryInfo>(1);
555
            repositoryInfoL.add(repositoryInfo);
569
            repositoryInfoL.add(repositoryInfo);
556
            query.addResults(findFindQuery().find(query.getQueryFields(), repositoryInfoL).getResults(), !it1.hasNext());
570
            Result<NBVersionInfo> qeuryResult = getQueryResult(repositoryInfoL, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
571
                GenericFindQuery genericFindQuery = queryProvider.getGenericFindQuery();
572
                return genericFindQuery != null ? 
573
                        genericFindQuery.find(query.getQueryFields(), providerRepos) : 
574
                        new NullResultImpl<NBVersionInfo>();
575
            });
576
            query.addResults(qeuryResult.getResults(), !it1.hasNext());
557
            // still someone waiting for results?
577
            // still someone waiting for results?
558
            if (query.countObservers() == 0)
578
            if (query.countObservers() == 0)
559
                return;
579
                return;
Lines 564-578 Link Here
564
    
584
    
565
    public static @NonNull List<RepositoryInfo> getLoadedContexts() {
585
    public static @NonNull List<RepositoryInfo> getLoadedContexts() {
566
        List<RepositoryInfo> toRet = new ArrayList<RepositoryInfo>();
586
        List<RepositoryInfo> toRet = new ArrayList<RepositoryInfo>();
567
        ContextLoadedQuery clq = Lookup.getDefault().lookup(ContextLoadedQuery.class);
587
        List<RepositoryInfo> repos = RepositoryPreferences.getInstance().getRepositoryInfos();
588
        Map<RepositoryIndexQueryProvider, List<RepositoryInfo>> i2r = getQueryProvider2Repo(repos);
589
        for(Entry<RepositoryIndexQueryProvider, List<RepositoryInfo>> e : i2r.entrySet()) {
590
            ContextLoadedQuery clq = e.getKey().getContextLoadedQuery();
568
        assert clq != null;
591
        assert clq != null;
569
        toRet.addAll(clq.getLoaded(RepositoryPreferences.getInstance().getRepositoryInfos()));
592
            toRet.addAll(clq.getLoaded(repos));
593
        }
570
        return toRet;
594
        return toRet;
571
    }
595
    }
572
596
573
    
574
    public static Result<String> filterArtifactIdForGroupIdResult(String groupId, String prefix, @NullAllowed List<RepositoryInfo> repos) {
597
    public static Result<String> filterArtifactIdForGroupIdResult(String groupId, String prefix, @NullAllowed List<RepositoryInfo> repos) {
575
        return findBaseQueries().filterArtifactIdForGroupId(groupId, prefix, repos);
598
        return getQueryResult(repos, (RepositoryIndexQueryProvider queryProvider, List<RepositoryInfo> providerRepos) -> {
599
            BaseQueries baseQueries = queryProvider.getBaseQueries();
600
            assert baseQueries != null: "RepositoryIndexQueryProvider.getBaseQueries not allowed to return null";
601
            return baseQueries.filterArtifactIdForGroupId(groupId, prefix, providerRepos);
602
        });
576
    }
603
    }
577
604
578
}
605
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ArchetypeQueries.java (-1 / +1 lines)
Lines 53-58 Link Here
53
 */
53
 */
54
public interface ArchetypeQueries {
54
public interface ArchetypeQueries {
55
55
56
    RepositoryQueries.Result<NBVersionInfo> findArchetypes(List<RepositoryInfo> repos);
56
    ResultImplementation<NBVersionInfo> findArchetypes(List<RepositoryInfo> repos);
57
57
58
}
58
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/BaseQueries.java (-9 / +9 lines)
Lines 52-73 Link Here
52
 */
52
 */
53
public interface BaseQueries {
53
public interface BaseQueries {
54
54
55
    RepositoryQueries.Result<String> getGroups(List<RepositoryInfo> repos);
55
    ResultImplementation<String> getGroups(List<RepositoryInfo> repos);
56
56
57
    RepositoryQueries.Result<String> filterGroupIds(String prefix, List<RepositoryInfo> repos);
57
    ResultImplementation<String> filterGroupIds(String prefix, List<RepositoryInfo> repos);
58
58
59
    RepositoryQueries.Result<NBVersionInfo> getRecords(String groupId, String artifactId, String version, List<RepositoryInfo> repos);
59
    ResultImplementation<NBVersionInfo> getRecords(String groupId, String artifactId, String version, List<RepositoryInfo> repos);
60
60
61
    RepositoryQueries.Result<String> getArtifacts(String groupId, List<RepositoryInfo> repos);
61
    ResultImplementation<String> getArtifacts(String groupId, List<RepositoryInfo> repos);
62
62
63
    RepositoryQueries.Result<NBVersionInfo> getVersions(String groupId, String artifactId, List<RepositoryInfo> repos);
63
    ResultImplementation<NBVersionInfo> getVersions(String groupId, String artifactId, List<RepositoryInfo> repos);
64
64
65
    RepositoryQueries.Result<String> filterPluginArtifactIds(String groupId, String prefix, List<RepositoryInfo> repos);
65
    ResultImplementation<String> filterPluginArtifactIds(String groupId, String prefix, List<RepositoryInfo> repos);
66
66
67
    RepositoryQueries.Result<String> filterPluginGroupIds(String prefix, List<RepositoryInfo> repos);
67
    ResultImplementation<String> filterPluginGroupIds(String prefix, List<RepositoryInfo> repos);
68
68
69
    RepositoryQueries.Result<String> filterArtifactIdForGroupId(String groupId, String prefix, List<RepositoryInfo> repos);
69
    ResultImplementation<String> filterArtifactIdForGroupId(String groupId, String prefix, List<RepositoryInfo> repos);
70
70
71
    RepositoryQueries.Result<String> getGAVsForPackaging(String packaging, List<RepositoryInfo> repos);
71
    ResultImplementation<String> getGAVsForPackaging(String packaging, List<RepositoryInfo> repos);
72
72
73
}
73
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ChecksumQueries.java (-1 / +1 lines)
Lines 51-55 Link Here
51
 * @author Milos Kleint
51
 * @author Milos Kleint
52
 */
52
 */
53
public interface ChecksumQueries {
53
public interface ChecksumQueries {
54
    RepositoryQueries.Result<NBVersionInfo> findBySHA1(String sha1, List<RepositoryInfo> repos);
54
    ResultImplementation<NBVersionInfo> findBySHA1(String sha1, List<RepositoryInfo> repos);
55
}
55
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ClassUsageQuery.java (-1 / +1 lines)
Lines 59-64 Link Here
59
     * @param repos repositories of this type to search in
59
     * @param repos repositories of this type to search in
60
     * @return result object with a list of usages
60
     * @return result object with a list of usages
61
     */
61
     */
62
    RepositoryQueries.Result<RepositoryQueries.ClassUsage> findClassUsages(String className, List<RepositoryInfo> repos);
62
    ResultImplementation<RepositoryQueries.ClassUsage> findClassUsages(String className, List<RepositoryInfo> repos);
63
63
64
}
64
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ClassesQuery.java (-2 / +2 lines)
Lines 43-51 Link Here
43
package org.netbeans.modules.maven.indexer.spi;
43
package org.netbeans.modules.maven.indexer.spi;
44
44
45
import java.util.List;
45
import java.util.List;
46
import org.apache.lucene.search.BooleanQuery;
46
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
47
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
47
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
48
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
48
import org.netbeans.modules.maven.indexer.api.RepositoryQueries;
49
49
50
/**
50
/**
51
 * Query to find artifacts information from class names.
51
 * Query to find artifacts information from class names.
Lines 61-65 Link Here
61
     * accordingly, for example by telling user that entered text for
61
     * accordingly, for example by telling user that entered text for
62
     * search is too general.
62
     * search is too general.
63
     */
63
     */
64
    public RepositoryQueries.Result<NBVersionInfo> findVersionsByClass(final String className, List<RepositoryInfo> repos);
64
    public ResultImplementation<NBVersionInfo> findVersionsByClass(final String className, List<RepositoryInfo> repos);
65
}
65
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/DependencyInfoQueries.java (-3 / +2 lines)
Lines 45-51 Link Here
45
import org.netbeans.modules.maven.indexer.api.NBGroupInfo;
45
import org.netbeans.modules.maven.indexer.api.NBGroupInfo;
46
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
46
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
47
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
47
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
48
import org.netbeans.modules.maven.indexer.api.RepositoryQueries;
49
48
50
/**
49
/**
51
 * Query to find dependency information of artifacts.Non mandatory for repository managers.
50
 * Query to find dependency information of artifacts.Non mandatory for repository managers.
Lines 53-60 Link Here
53
 */
52
 */
54
public interface DependencyInfoQueries {
53
public interface DependencyInfoQueries {
55
54
56
    RepositoryQueries.Result<NBVersionInfo> findDependencyUsage(String groupId, String artifactId, String version, List<RepositoryInfo> repoIds);
55
    ResultImplementation<NBVersionInfo> findDependencyUsage(String groupId, String artifactId, String version, List<RepositoryInfo> repoIds);
57
    
56
    
58
    RepositoryQueries.Result<NBGroupInfo> findDependencyUsageGroups(String groupId, String artifactId, String version, List<RepositoryInfo> repoIds);
57
    ResultImplementation<NBGroupInfo> findDependencyUsageGroups(String groupId, String artifactId, String version, List<RepositoryInfo> repoIds);
59
58
60
}
59
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/GenericFindQuery.java (-2 / +2 lines)
Lines 43-52 Link Here
43
package org.netbeans.modules.maven.indexer.spi;
43
package org.netbeans.modules.maven.indexer.spi;
44
44
45
import java.util.List;
45
import java.util.List;
46
import org.apache.lucene.search.BooleanQuery;
46
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
47
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
47
import org.netbeans.modules.maven.indexer.api.QueryField;
48
import org.netbeans.modules.maven.indexer.api.QueryField;
48
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
49
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
49
import org.netbeans.modules.maven.indexer.api.RepositoryQueries;
50
50
51
/**
51
/**
52
 * non mandatory query to for generic searching within the repository.
52
 * non mandatory query to for generic searching within the repository.
Lines 63-68 Link Here
63
     * accordingly, for example by telling user that entered text for
63
     * accordingly, for example by telling user that entered text for
64
     * search is too general.
64
     * search is too general.
65
     */
65
     */
66
    public RepositoryQueries.Result<NBVersionInfo> find(List<QueryField> fields, List<RepositoryInfo> repos);
66
    public ResultImplementation<NBVersionInfo> find(List<QueryField> fields, List<RepositoryInfo> repos);
67
    
67
    
68
}
68
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/NullResultImpl.java (+76 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2016 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 2016 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.maven.indexer.spi;
43
44
import java.util.Collections;
45
import java.util.List;
46
47
/**
48
 * Convenience class.
49
 * 
50
 * @author Tomas Stupka
51
 * @param <T>
52
 */
53
public final class NullResultImpl<T> implements ResultImplementation<T> {        
54
    @Override
55
    public boolean isPartial() {
56
        return false;
57
    }
58
    @Override
59
    public void waitForSkipped() {
60
61
    }
62
    @Override
63
    public List<T> getResults() {            
64
        return Collections.EMPTY_LIST;
65
    }
66
67
    @Override
68
    public int getTotalResultCount() {
69
        return 0;
70
    }
71
    
72
    @Override
73
    public int getReturnedResultCount() {
74
        return 0;
75
    }        
76
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/Redo.java (-53 lines)
Lines 1-53 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.maven.indexer.spi;
43
44
import org.netbeans.modules.maven.indexer.api.RepositoryQueries;
45
46
/**
47
 * used internally by the repository indexing/searching engine(s)
48
 * @author mkleint
49
 */
50
public interface Redo<T> {
51
    void run(RepositoryQueries.Result<T> result);
52
}    
53
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/RepositoryIndexQueryProvider.java (+131 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2016 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 2016 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.maven.indexer.spi;
43
44
import org.netbeans.api.annotations.common.CheckForNull;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.api.annotations.common.NullAllowed;
47
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
48
49
/**
50
 * Provides repository queries.<br> 
51
 * Register via <code>@ServiceProvider(service=RepositoryIndexQueryProvider.class)</code>
52
 * 
53
 * @author Tomas Stupka
54
 * @since 2.37
55
 */
56
public interface RepositoryIndexQueryProvider {
57
    
58
    /** 
59
     * Determines if queries for the given repository are handled by this provider or not.
60
     * 
61
     * @param repo the repository
62
     * @return <code>true</code> if the given repository is handled by this provider, otherwise <code>false</code>
63
     * @since 2.37
64
     */
65
    boolean handlesRepository(RepositoryInfo repo);
66
    
67
    /**
68
     * Returns a {@link ArchetypeQueries} implementation.
69
     * 
70
     * @return ArchetypeQueries or <code>null</code> if not provided
71
     * @since 2.37
72
     */
73
    @CheckForNull 
74
    ArchetypeQueries getArchetypeQueries();
75
    
76
    /**
77
     * Returns a {@link BaseQueries} implementation.
78
     * 
79
     * @return BaseQueries
80
     * @since 2.37
81
     */
82
    @NonNull BaseQueries getBaseQueries();
83
    
84
    /**
85
     * Returns a {@link ChecksumQueries} implementation.
86
     * 
87
     * @return ChecksumQueries or <code>null</code> if not provided
88
     * @since 2.37
89
     */
90
    @CheckForNull ChecksumQueries getChecksumQueries();
91
    
92
    /**
93
     * Returns a {@link ClassUsageQuery} implementation.
94
     * 
95
     * @return ClassUsageQuery or <code>null</code> if not provided
96
     * @since 2.37
97
     */
98
    @CheckForNull ClassUsageQuery getClassUsageQuery();
99
    
100
    /**
101
     * Returns a {@link ClassesQuery} implementation.
102
     * 
103
     * @return ClassesQuery or <code>null</code> if not provided
104
     * @since 2.37
105
     */
106
    @CheckForNull ClassesQuery getClassesQuery();
107
    
108
    /**
109
     * Returns a {@link ContextLoadedQuery} implementation.
110
     * 
111
     * @return ContextLoadedQuery or <code>null</code> if not provided
112
     * @since 2.37
113
     */
114
    @CheckForNull ContextLoadedQuery getContextLoadedQuery();
115
    
116
    /**
117
     * Returns a {@link DependencyInfoQueries} implementation.
118
     * 
119
     * @return DependencyInfoQueries or <code>null</code> if not provided
120
     * @since 2.37
121
     */
122
    @CheckForNull DependencyInfoQueries getDependencyInfoQueries();
123
    
124
    /**
125
     * Returns a {@link GenericFindQuery} implementation.
126
     * 
127
     * @return GenericFindQuery or <code>null</code> if not provided
128
     * @since 2.37
129
     */
130
    @CheckForNull GenericFindQuery getGenericFindQuery();
131
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/RepositoryIndexerImplementation.java (-67 lines)
Lines 1-67 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2008 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.maven.indexer.spi;
43
44
import java.util.Collection;
45
import org.apache.maven.artifact.Artifact;
46
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
47
48
/**
49
 * Implementation of repository indexer (repository manager). Apart from basic
50
 * indexing features also serves as provider of various index queries.
51
 * There is one implementation based on apache indexer
52
 * 
53
 * @author Milos Kleint
54
 */
55
public interface RepositoryIndexerImplementation {
56
    
57
    /**
58
     * Index local repository or retrieve remote prepopulated index for local use.
59
     * @param repo
60
     */
61
    void indexRepo(RepositoryInfo repo);
62
    
63
    void updateIndexWithArtifacts(RepositoryInfo repo, Collection<Artifact> artifacts);
64
65
    void deleteArtifactFromIndex(RepositoryInfo repo, Artifact artifact);
66
67
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/ResultImplementation.java (+84 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2016 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 2016 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.maven.indexer.spi;
43
44
import java.util.List;
45
46
/**
47
 * Implement to provide a maven index query result.
48
 * 
49
 * @author Tomas Stupka
50
 * @param <T>
51
 * @since 2.37
52
 * @see org.netbeans.modules.maven.indexer.api.RepositoryQueries.Result
53
 */
54
public interface ResultImplementation<T> {
55
    /**
56
     * Returns true is one or more indexes were skipped, e.g. because the indexing was taking place.
57
     * @return 
58
     */
59
    public boolean isPartial();
60
    
61
    /**
62
     * Waits for currently unaccessible indexes to finish, not to be called in AWT thread.
63
     */
64
    public void waitForSkipped();
65
    
66
    /**
67
     * Returns the results.
68
     * @return 
69
     */
70
    public List<T> getResults();
71
    
72
    /**
73
     * Total number of hits.
74
     * @return     
75
     */
76
    public int getTotalResultCount();
77
    
78
    /**
79
     * In some cases not entirely accurate number of processed and returned hits, 
80
     * typically should be less or equal to {@link #getReturnedResultCount()}
81
     * @return 
82
     */
83
    public int getReturnedResultCount();
84
}
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/impl/Redo.java (+53 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.maven.indexer.spi.impl;
43
44
import org.netbeans.modules.maven.indexer.ResultImpl;
45
46
/**
47
 * used internally by the repository indexing/searching engine(s)
48
 * @author mkleint
49
 */
50
public interface Redo<T> {
51
    void run(ResultImpl<T> result);
52
}    
53
(-)maven.indexer/src/org/netbeans/modules/maven/indexer/spi/impl/RepositoryIndexerImplementation.java (+72 lines)
Line 0 Link Here
1
package org.netbeans.modules.maven.indexer.spi.impl;
2
3
/*
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
 *
6
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
7
 *
8
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
9
 * Other names may be trademarks of their respective owners.
10
 *
11
 * The contents of this file are subject to the terms of either the GNU
12
 * General Public License Version 2 only ("GPL") or the Common
13
 * Development and Distribution License("CDDL") (collectively, the
14
 * "License"). You may not use this file except in compliance with the
15
 * License. You can obtain a copy of the License at
16
 * http://www.netbeans.org/cddl-gplv2.html
17
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
18
 * specific language governing permissions and limitations under the
19
 * License.  When distributing the software, include this License Header
20
 * Notice in each file and include the License file at
21
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
22
 * particular file as subject to the "Classpath" exception as provided
23
 * by Oracle in the GPL Version 2 section of the License file that
24
 * accompanied this code. If applicable, add the following below the
25
 * License Header, with the fields enclosed by brackets [] replaced by
26
 * your own identifying information:
27
 * "Portions Copyrighted [year] [name of copyright owner]"
28
 *
29
 * If you wish your version of this file to be governed by only the CDDL
30
 * or only the GPL Version 2, indicate your decision by adding
31
 * "[Contributor] elects to include this software in this distribution
32
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
33
 * single choice of license, a recipient has the option to distribute
34
 * your version of this file under either the CDDL, the GPL Version 2 or
35
 * to extend the choice of license to its licensees as provided above.
36
 * However, if you add GPL Version 2 code and therefore, elected the GPL
37
 * Version 2 license, then the option applies only if the new code is
38
 * made subject to such option by the copyright holder.
39
 *
40
 * Contributor(s):
41
 *
42
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
43
 */
44
45
46
import java.util.Collection;
47
import org.apache.maven.artifact.Artifact;
48
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
49
50
/**
51
 * 
52
 * Used internally.
53
 * 
54
 * Implementation of repository indexer (repository manager). Apart from basic
55
 * indexing features also serves as provider of various index queries.
56
 * There is one implementation based on apache indexer
57
 * 
58
 * @author Milos Kleint
59
 */
60
public interface RepositoryIndexerImplementation {
61
    
62
    /**
63
     * Index local repository or retrieve remote prepopulated index for local use.
64
     * @param repo
65
     */
66
    void indexRepo(RepositoryInfo repo);
67
    
68
    void updateIndexWithArtifacts(RepositoryInfo repo, Collection<Artifact> artifacts);
69
70
    void deleteArtifactFromIndex(RepositoryInfo repo, Artifact artifact);
71
72
}
(-)maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusRepositoryIndexerImplTest.java (+15 lines)
Lines 46-53 Link Here
46
import java.util.Collections;
46
import java.util.Collections;
47
import java.util.List;
47
import java.util.List;
48
import org.apache.maven.index.ArtifactInfo;
48
import org.apache.maven.index.ArtifactInfo;
49
import org.netbeans.junit.MockServices;
50
import org.netbeans.modules.maven.indexer.api.AbstractTestQueryProvider;
51
import org.netbeans.modules.maven.indexer.api.AbstractTestQueryProvider.TestIndexer1;
49
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
52
import org.netbeans.modules.maven.indexer.api.NBVersionInfo;
50
import org.netbeans.modules.maven.indexer.api.QueryField;
53
import org.netbeans.modules.maven.indexer.api.QueryField;
54
import org.netbeans.modules.maven.indexer.api.RepositoryQueries;
51
import org.openide.util.test.TestFileUtils;
55
import org.openide.util.test.TestFileUtils;
52
56
53
public class NexusRepositoryIndexerImplTest extends NexusTestBase {
57
public class NexusRepositoryIndexerImplTest extends NexusTestBase {
Lines 62-67 Link Here
62
        assertEquals("[test]", nrii.filterGroupIds("", Collections.singletonList(info)).getResults().toString());
66
        assertEquals("[test]", nrii.filterGroupIds("", Collections.singletonList(info)).getResults().toString());
63
    }
67
    }
64
68
69
    public void testFilterGroupIdsViaRepositoryQueries() throws Exception {
70
        // jusr add some alternative QueryProvider not handlig our request
71
        MockServices.setServices(TestIndexer1.class); 
72
        
73
        install(File.createTempFile("whatever", ".txt", getWorkDir()), "test", "spin", "1.1", "txt");
74
        nrii.indexRepo(info);
75
        // RepositoryQueries should handle the query via our NexusRepositoryIndexerImpl
76
        RepositoryQueries.Result<String> res = RepositoryQueries.filterGroupIdsResult("", Collections.singletonList(info));        
77
        assertEquals("[test]", res.getResults().toString());
78
    }
79
65
    public void testFind() throws Exception {
80
    public void testFind() throws Exception {
66
        installPOM("test", "plugin", "0", "maven-plugin");
81
        installPOM("test", "plugin", "0", "maven-plugin");
67
        install(TestFileUtils.writeZipFile(new File(getWorkDir(), "plugin.jar"), "META-INF/maven/plugin.xml:<plugin><goalPrefix>stuff</goalPrefix></plugin>"), "test", "plugin", "0", "maven-plugin");
82
        install(TestFileUtils.writeZipFile(new File(getWorkDir(), "plugin.jar"), "META-INF/maven/plugin.xml:<plugin><goalPrefix>stuff</goalPrefix></plugin>"), "test", "plugin", "0", "maven-plugin");
(-)maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/NexusTestBase.java (-1 / +2 lines)
Lines 49-54 Link Here
49
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
49
import org.netbeans.modules.maven.indexer.api.RepositoryInfo;
50
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences;
50
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences;
51
import org.openide.modules.api.PlacesTestUtils;
51
import org.openide.modules.api.PlacesTestUtils;
52
import org.openide.util.Lookup;
52
import org.openide.util.Utilities;
53
import org.openide.util.Utilities;
53
import org.openide.util.test.TestFileUtils;
54
import org.openide.util.test.TestFileUtils;
54
55
Lines 75-81 Link Here
75
        artifactInstaller = embedder.lookupComponent(ArtifactInstaller.class);
76
        artifactInstaller = embedder.lookupComponent(ArtifactInstaller.class);
76
        info = new RepositoryInfo("test", "Test", repo.getAbsolutePath(), null);
77
        info = new RepositoryInfo("test", "Test", repo.getAbsolutePath(), null);
77
        RepositoryPreferences.getInstance().addOrModifyRepositoryInfo(info);
78
        RepositoryPreferences.getInstance().addOrModifyRepositoryInfo(info);
78
        nrii = new NexusRepositoryIndexerImpl();
79
        nrii = Lookup.getDefault().lookup(NexusRepositoryIndexerImpl.class);
79
    }
80
    }
80
81
81
    @Override protected Level logLevel() {
82
    @Override protected Level logLevel() {
(-)maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/AbstractTestQueryProvider.java (+181 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2016 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 2016 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.maven.indexer.api;
43
44
import java.net.URISyntaxException;
45
import java.util.Arrays;
46
import java.util.Collection;
47
import java.util.List;
48
import org.apache.maven.artifact.Artifact;
49
import org.netbeans.modules.maven.indexer.spi.ArchetypeQueries;
50
import org.netbeans.modules.maven.indexer.spi.BaseQueries;
51
import org.netbeans.modules.maven.indexer.spi.ChecksumQueries;
52
import org.netbeans.modules.maven.indexer.spi.ClassUsageQuery;
53
import org.netbeans.modules.maven.indexer.spi.ClassesQuery;
54
import org.netbeans.modules.maven.indexer.spi.ContextLoadedQuery;
55
import org.netbeans.modules.maven.indexer.spi.DependencyInfoQueries;
56
import org.netbeans.modules.maven.indexer.spi.GenericFindQuery;
57
import org.netbeans.modules.maven.indexer.spi.ResultImplementation;
58
import org.openide.util.Exceptions;
59
import org.netbeans.modules.maven.indexer.spi.RepositoryIndexQueryProvider;
60
61
/**
62
 *
63
 * @author tomas
64
 */
65
public abstract class AbstractTestQueryProvider implements RepositoryIndexQueryProvider {
66
67
    private static final String TESTREPO = "testrepo";
68
    
69
    public static class TestIndexer1 extends AbstractTestQueryProvider {
70
        public static final String ID = TESTREPO + ".1";
71
        public static RepositoryInfo REPO;
72
        static {
73
            try {REPO = new RepositoryInfo(ID, ID, null, "http://test1"); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); }
74
        }
75
        public TestIndexer1() {
76
            this.repos = new RepositoryInfo[] {REPO};
77
        }
78
        protected String getID() {
79
            return ID;
80
        }
81
    }
82
    public static class TestIndexer2 extends AbstractTestQueryProvider {
83
        public static final String ID = TESTREPO + ".2";
84
        public static RepositoryInfo REPO;
85
        static {
86
            try {REPO = new RepositoryInfo(ID, ID, null, "http://test1"); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); }
87
        }
88
        public TestIndexer2() {
89
            this.repos = new RepositoryInfo[] {REPO};
90
        }
91
        
92
        protected String getID() {
93
            return ID;
94
        }
95
    }
96
    
97
    protected RepositoryInfo[] repos;
98
    public AbstractTestQueryProvider() {
99
    }
100
101
    @Override
102
    public boolean handlesRepository(RepositoryInfo repo) {
103
        for (RepositoryInfo r : repos) {
104
            if(repo.getId().equals(r.getId())) {
105
                return true;
106
            }
107
        }    
108
        return false;
109
    }
110
111
    abstract protected String getID();
112
113
    @Override
114
    public ArchetypeQueries getArchetypeQueries() {
115
        return new ArchetypeQueries() {
116
            @Override
117
            public ResultImplementation<NBVersionInfo> findArchetypes(List<RepositoryInfo> repos) {
118
                return new ResultImplementation<NBVersionInfo>() {
119
                    @Override
120
                    public boolean isPartial() {
121
                        return false;
122
                    }
123
124
                    @Override
125
                    public void waitForSkipped() { }
126
127
                    @Override
128
                    public List<NBVersionInfo> getResults() {
129
                        return Arrays.asList(new NBVersionInfo(getID(), getID(), getID(), "1.0", "jar", "jar", "test", "test", null));
130
                    }
131
132
                    @Override
133
                    public int getTotalResultCount() {
134
                        return 1;
135
                    }
136
137
                    @Override
138
                    public int getReturnedResultCount() {
139
                        return 1;
140
                    }
141
                };
142
            }
143
        };
144
    }
145
    
146
    @Override
147
    public BaseQueries getBaseQueries() {
148
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
149
    }
150
151
    @Override
152
    public ChecksumQueries getChecksumQueries() {
153
        return null;
154
    }
155
156
    @Override
157
    public ClassUsageQuery getClassUsageQuery() {
158
        return null;
159
    }
160
161
    @Override
162
    public ClassesQuery getClassesQuery() {
163
        return null;
164
    }
165
166
    @Override
167
    public ContextLoadedQuery getContextLoadedQuery() {
168
        return null;
169
    }
170
171
    @Override
172
    public DependencyInfoQueries getDependencyInfoQueries() {
173
        return null;
174
    }
175
176
    @Override
177
    public GenericFindQuery getGenericFindQuery() {
178
        return null;
179
    }
180
181
}
(-)maven.indexer/test/unit/src/org/netbeans/modules/maven/indexer/api/RepositoryQueriesTest.java (+144 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 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 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.maven.indexer.api;
44
45
import java.io.File;
46
import java.net.URISyntaxException;
47
import java.util.ArrayList;
48
import java.util.Arrays;
49
import java.util.Collections;
50
import java.util.List;
51
import org.netbeans.junit.MockServices;
52
import org.netbeans.junit.NbTestCase;
53
import org.netbeans.modules.maven.indexer.api.AbstractTestQueryProvider.TestIndexer1;
54
import org.netbeans.modules.maven.indexer.api.AbstractTestQueryProvider.TestIndexer2;
55
import org.netbeans.modules.maven.indexer.spi.ArchetypeQueries;
56
import org.openide.util.Exceptions;
57
58
public class RepositoryQueriesTest extends NbTestCase {
59
60
    public RepositoryQueriesTest(String name) {
61
        super(name);
62
    }
63
    
64
    @Override 
65
    protected void setUp() throws Exception {
66
        super.setUp();
67
    }
68
    
69
    public void testAlternativeQueryProvider() throws URISyntaxException {
70
        
71
    }
72
    
73
    public void testAlternativeResult() throws URISyntaxException {
74
        MockServices.setServices(TestIndexer1.class);
75
        
76
        RepositoryQueries.Result<NBVersionInfo> result = RepositoryQueries.findArchetypesResult(Arrays.asList(TestIndexer1.REPO));
77
        assertEquals(TestIndexer1.ID, result.getResults().get(0).getArtifactId());
78
        assertEquals(1, result.getTotalResultCount());
79
        assertEquals(1, result.getReturnedResultCount());
80
    }
81
    
82
    public void testTwoReposTwoQueryProviders() throws URISyntaxException {
83
        MockServices.setServices(TestIndexer1.class, TestIndexer2.class);
84
85
        RepositoryQueries.Result<NBVersionInfo> result = RepositoryQueries.findArchetypesResult(Arrays.asList(TestIndexer1.REPO, TestIndexer2.REPO));
86
        assertEquals(2, result.getTotalResultCount());
87
        assertEquals(2, result.getReturnedResultCount());
88
        assertArtefactIds(result.getResults(), new String[] {TestIndexer1.ID, TestIndexer2.ID});
89
    }
90
    
91
    public void testTwoReposOneAccepted() throws URISyntaxException {
92
        MockServices.setServices(TestIndexer1.class);
93
        
94
        RepositoryQueries.Result<NBVersionInfo> result = RepositoryQueries.findArchetypesResult(Arrays.asList(TestIndexer1.REPO, TestIndexer2.REPO));
95
        assertEquals(1, result.getTotalResultCount());
96
        assertEquals(1, result.getReturnedResultCount());
97
        assertArtefactIds(result.getResults(), new String[] {TestIndexer1.ID});
98
    }
99
    
100
    public void testNullResult() throws URISyntaxException {
101
        MockServices.setServices(NullQueryProvider.class);
102
        List<RepositoryInfo> repos = Arrays.asList(NullQueryProvider.REPO);
103
        assertEquals(0, RepositoryQueries.findArchetypesResult(repos).getTotalResultCount());
104
        assertEquals(0, RepositoryQueries.findBySHA1Result(new File(""), Arrays.asList(NullQueryProvider.REPO)).getTotalResultCount());
105
        assertEquals(0, RepositoryQueries.findClassUsagesResult("", repos).getTotalResultCount());
106
        assertEquals(0, RepositoryQueries.findDependencyUsageResult("","","", repos).getTotalResultCount());
107
        assertEquals(0, RepositoryQueries.findResult(Collections.EMPTY_LIST, repos).getTotalResultCount());
108
        assertEquals(0, RepositoryQueries.findVersionsByClassResult("", repos).getTotalResultCount());
109
        assertEquals(0, RepositoryQueries.getLoadedContexts().size());
110
    }
111
112
    private void assertArtefactIds(List<NBVersionInfo> infos, String[] ids) {
113
        assertEquals(ids.length, infos.size());
114
        List<String> returnedIds = new ArrayList<>(infos.size());
115
        infos.stream().forEach((info) -> returnedIds.add(info.getArtifactId()));
116
        for (String id : ids) {
117
            assertTrue(returnedIds.contains(id));
118
        }
119
    }
120
121
    public static class NullQueryProvider extends AbstractTestQueryProvider {
122
        static final String ID = "nullrepo";
123
        static RepositoryInfo REPO;
124
        static {
125
            try {
126
                REPO = new RepositoryInfo(ID, ID, null, "http://test1");
127
            } catch (URISyntaxException ex) {
128
                Exceptions.printStackTrace(ex);
129
            }
130
        }
131
132
        public NullQueryProvider() {
133
            this.repos = new RepositoryInfo[] {REPO};
134
        }
135
        protected String getID() {
136
            return ID;
137
        }
138
        @Override
139
        public ArchetypeQueries getArchetypeQueries() {
140
            return null;
141
        }        
142
    }
143
144
}

Return to bug 257567