use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class Maven2ServerIndexerImpl method search.
public Set<MavenArtifactInfo> search(int indexId, Query query, int maxResult) throws MavenServerIndexerException {
try {
IndexingContext index = getIndex(indexId);
TopDocs docs = null;
try {
BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
docs = index.getIndexSearcher().search(query, null, maxResult);
} catch (BooleanQuery.TooManyClauses ignore) {
// this exception occurs when too wide wildcard is used on too big data.
}
if (docs == null || docs.scoreDocs.length == 0)
return Collections.emptySet();
Set<MavenArtifactInfo> result = new THashSet<MavenArtifactInfo>();
for (int i = 0; i < docs.scoreDocs.length; i++) {
int docIndex = docs.scoreDocs[i].doc;
Document doc = index.getIndexReader().document(docIndex);
ArtifactInfo a = IndexUtils.constructArtifactInfo(doc, index);
if (a == null)
continue;
a.repository = getRepositoryPathOrUrl(index);
result.add(Maven2ModelConverter.convertArtifactInfo(a));
}
return result;
} catch (Exception e) {
throw new MavenServerIndexerException(wrapException(e));
}
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class Maven3ServerIndexerImpl method search.
@Override
public Set<MavenArtifactInfo> search(int indexId, Query query, int maxResult) throws RemoteException, MavenServerIndexerException {
try {
IndexingContext index = getIndex(indexId);
TopDocs docs = null;
try {
BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
docs = index.getIndexSearcher().search(query, null, maxResult);
} catch (BooleanQuery.TooManyClauses ignore) {
// this exception occurs when too wide wildcard is used on too big data.
}
if (docs == null || docs.scoreDocs.length == 0)
return Collections.emptySet();
Set<MavenArtifactInfo> result = new THashSet<MavenArtifactInfo>();
for (int i = 0; i < docs.scoreDocs.length; i++) {
int docIndex = docs.scoreDocs[i].doc;
Document doc = index.getIndexReader().document(docIndex);
ArtifactInfo a = IndexUtils.constructArtifactInfo(doc, index);
if (a == null)
continue;
a.repository = getRepositoryPathOrUrl(index);
result.add(MavenModelConverter.convertArtifactInfo(a));
}
return result;
} catch (Exception e) {
throw new MavenServerIndexerException(wrapException(e));
}
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class ArtifactoryRepositoryService method findArtifacts.
@NotNull
@Override
public List<MavenArtifactInfo> findArtifacts(@NotNull String url, @NotNull MavenArtifactInfo template) throws IOException {
try {
final String packaging = StringUtil.notNullize(template.getPackaging());
final ArrayList<MavenArtifactInfo> artifacts = new ArrayList<>();
final Gson gson = new Gson();
final String className = template.getClassNames();
if (className == null || className.length() == 0) {
final String name = StringUtil.join(Arrays.asList(template.getGroupId(), template.getArtifactId(), template.getVersion()), ":");
final InputStream stream = new Endpoint.Search.Artifact(url).getArtifactSearchResultJson(name, null).getInputStream();
final ArtifactoryModel.GavcResults results = stream == null ? null : gson.fromJson(new InputStreamReader(stream), ArtifactoryModel.GavcResults.class);
if (results != null && results.results != null) {
for (ArtifactoryModel.GavcResult result : results.results) {
if (!result.uri.endsWith(packaging))
continue;
artifacts.add(convertArtifactInfo(result.uri, url, null));
}
}
} else {
// IDEA-58225
final String searchString = className.endsWith("*") || className.endsWith("?") ? className : className + ".class";
final InputStream stream = new Endpoint.Search.Archive(url).getArchiveSearchResultJson(searchString, null).getInputStream();
final ArtifactoryModel.ArchiveResults results = stream == null ? null : gson.fromJson(new InputStreamReader(stream), ArtifactoryModel.ArchiveResults.class);
if (results != null && results.results != null) {
for (ArtifactoryModel.ArchiveResult result : results.results) {
for (String uri : result.archiveUris) {
if (!uri.endsWith(packaging))
continue;
artifacts.add(convertArtifactInfo(uri, url, result.entry));
}
}
}
}
return artifacts;
} catch (JsonSyntaxException e) {
return Collections.emptyList();
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class NexusRepositoryService method findArtifacts.
@NotNull
@Override
public List<MavenArtifactInfo> findArtifacts(@NotNull String url, @NotNull MavenArtifactInfo template) throws IOException {
try {
final String packaging = StringUtil.notNullize(template.getPackaging());
final String name = StringUtil.join(Arrays.asList(template.getGroupId(), template.getArtifactId(), template.getVersion()), ":");
final SearchResults results = new Endpoint.DataIndex(url).getArtifactlistAsSearchResults(name, template.getGroupId(), template.getArtifactId(), template.getVersion(), null, template.getClassNames());
boolean tooManyResults = results.isTooManyResults();
final SearchResults.Data data = results.getData();
final ArrayList<MavenArtifactInfo> result = new ArrayList<>();
if (data != null) {
for (ArtifactType each : data.getArtifact()) {
if (!Comparing.equal(each.packaging, packaging))
continue;
result.add(convertArtifactInfo(each));
}
}
if (tooManyResults)
result.add(null);
return result;
} catch (UnmarshalException e) {
return Collections.emptyList();
} catch (JAXBException e) {
throw new IOException(e);
}
}
use of org.jetbrains.idea.maven.model.MavenArtifactInfo in project intellij-community by JetBrains.
the class RepositoryAttachDialog method getRepositories.
@NotNull
public List<MavenRepositoryInfo> getRepositories() {
final Pair<MavenArtifactInfo, MavenRepositoryInfo> artifactAndRepo = myCoordinates.get(getCoordinateText());
final MavenRepositoryInfo repository = artifactAndRepo == null ? null : artifactAndRepo.second;
return repository != null ? Collections.singletonList(repository) : ContainerUtil.findAll(myRepositories.values(), Condition.NOT_NULL);
}
Aggregations