use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.
the class MavenIndex method doUpdateIndexData.
private void doUpdateIndexData(IndexData data, MavenProgressIndicator progress) throws IOException, MavenServerIndexerException {
final Map<String, Set<String>> groupToArtifactMap = new THashMap<>();
final Map<String, Set<String>> groupWithArtifactToVersionMap = new THashMap<>();
final StringBuilder builder = new StringBuilder();
progress.pushState();
progress.setIndeterminate(true);
try {
myIndexer.processArtifacts(data.indexId, new MavenIndicesProcessor() {
@Override
public void processArtifacts(Collection<MavenId> artifacts) {
for (MavenId each : artifacts) {
String groupId = each.getGroupId();
String artifactId = each.getArtifactId();
String version = each.getVersion();
builder.setLength(0);
builder.append(groupId).append(":").append(artifactId);
String ga = builder.toString();
getOrCreate(groupToArtifactMap, groupId).add(artifactId);
getOrCreate(groupWithArtifactToVersionMap, ga).add(version);
}
}
});
persist(groupToArtifactMap, data.groupToArtifactMap);
persist(groupWithArtifactToVersionMap, data.groupWithArtifactToVersionMap);
} finally {
progress.popState();
}
}
use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.
the class MavenProjectModelModifier method addDependency.
private Promise<Void> addDependency(@NotNull Collection<Module> fromModules, @NotNull final MavenId mavenId, @Nullable String minVersion, @Nullable String maxVersion, @NotNull final DependencyScope scope) {
final List<Trinity<MavenDomProjectModel, MavenId, String>> models = new ArrayList<>(fromModules.size());
List<XmlFile> files = new ArrayList<>(fromModules.size());
List<MavenProject> projectToUpdate = new ArrayList<>(fromModules.size());
final String mavenScope = getMavenScope(scope);
for (Module from : fromModules) {
if (!myProjectsManager.isMavenizedModule(from))
return null;
MavenProject fromProject = myProjectsManager.findProject(from);
if (fromProject == null)
return null;
final MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(myProject, fromProject.getFile());
if (model == null)
return null;
String scopeToSet = null;
String version = null;
if (mavenId.getGroupId() != null && mavenId.getArtifactId() != null) {
MavenDomDependency managedDependency = MavenDependencyCompletionUtil.findManagedDependency(model, myProject, mavenId.getGroupId(), mavenId.getArtifactId());
if (managedDependency != null) {
String managedScope = StringUtil.nullize(managedDependency.getScope().getStringValue(), true);
scopeToSet = (managedScope == null && MavenConstants.SCOPE_COMPILE.equals(mavenScope)) || StringUtil.equals(managedScope, mavenScope) ? null : mavenScope;
}
if (managedDependency == null || StringUtil.isEmpty(managedDependency.getVersion().getStringValue())) {
version = selectVersion(mavenId, minVersion, maxVersion);
}
}
models.add(Trinity.create(model, new MavenId(mavenId.getGroupId(), mavenId.getArtifactId(), version), scopeToSet));
files.add(DomUtil.getFile(model));
projectToUpdate.add(fromProject);
}
new WriteCommandAction(myProject, "Add Maven Dependency", PsiUtilCore.toPsiFileArray(files)) {
@Override
protected void run(@NotNull Result result) throws Throwable {
for (Trinity<MavenDomProjectModel, MavenId, String> trinity : models) {
final MavenDomProjectModel model = trinity.first;
MavenDomDependency dependency = MavenDomUtil.createDomDependency(model, null, trinity.second);
String mavenScope = trinity.third;
if (mavenScope != null) {
dependency.getScope().setStringValue(mavenScope);
}
Document document = PsiDocumentManager.getInstance(myProject).getDocument(DomUtil.getFile(model));
if (document != null) {
FileDocumentManager.getInstance().saveDocument(document);
}
}
}
}.execute();
return myProjectsManager.forceUpdateProjects(projectToUpdate);
}
use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.
the class MavenArtifactSearchPanel method getResult.
@NotNull
public List<MavenId> getResult() {
List<MavenId> result = new ArrayList<>();
for (TreePath each : myResultList.getSelectionPaths()) {
Object sel = each.getLastPathComponent();
MavenArtifactInfo info;
if (sel instanceof MavenArtifactInfo) {
info = (MavenArtifactInfo) sel;
} else {
info = ((MavenArtifactSearchResult) sel).versions.get(0);
}
result.add(new MavenId(info.getGroupId(), info.getArtifactId(), info.getVersion()));
}
return result;
}
use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.
the class Maven2ServerIndexerImpl method addArtifact.
public MavenId addArtifact(int indexId, File artifactFile) throws MavenServerIndexerException {
try {
IndexingContext index = getIndex(indexId);
ArtifactContext artifactContext = myArtifactContextProducer.getArtifactContext(index, artifactFile);
if (artifactContext == null)
return null;
addArtifact(myIndexer, index, artifactContext);
org.sonatype.nexus.index.ArtifactInfo a = artifactContext.getArtifactInfo();
return new MavenId(a.groupId, a.artifactId, a.version);
} catch (Exception e) {
throw new MavenServerIndexerException(wrapException(e));
}
}
use of org.jetbrains.idea.maven.model.MavenId in project intellij-community by JetBrains.
the class Maven3ServerIndexerImpl method processArtifacts.
@Override
public void processArtifacts(int indexId, MavenServerIndicesProcessor processor) throws RemoteException, MavenServerIndexerException {
try {
final int CHUNK_SIZE = 10000;
IndexReader r = getIndex(indexId).getIndexReader();
int total = r.numDocs();
List<MavenId> result = new ArrayList<MavenId>(Math.min(CHUNK_SIZE, total));
for (int i = 0; i < total; i++) {
if (r.isDeleted(i))
continue;
Document doc = r.document(i);
String uinfo = doc.get(SEARCH_TERM_COORDINATES);
if (uinfo == null)
continue;
List<String> parts = StringUtil.split(uinfo, "|");
String groupId = parts.get(0);
String artifactId = parts.get(1);
String version = parts.get(2);
if (groupId == null || artifactId == null || version == null)
continue;
result.add(new MavenId(groupId, artifactId, version));
if (result.size() == CHUNK_SIZE) {
processor.processArtifacts(result);
result.clear();
}
}
if (!result.isEmpty()) {
processor.processArtifacts(result);
}
} catch (Exception e) {
throw new MavenServerIndexerException(wrapException(e));
}
}
Aggregations