use of org.jetbrains.idea.maven.dom.model.MavenDomModule in project intellij-community by JetBrains.
the class MavenModuleBuilderHelper method configure.
public void configure(final Project project, final VirtualFile root, final boolean isInteractive) {
PsiFile[] psiFiles = myAggregatorProject != null ? new PsiFile[] { getPsiFile(project, myAggregatorProject.getFile()) } : PsiFile.EMPTY_ARRAY;
final VirtualFile pom = new WriteCommandAction<VirtualFile>(project, myCommandName, psiFiles) {
@Override
protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
VirtualFile file;
try {
file = root.createChildData(this, MavenConstants.POM_XML);
MavenUtil.runOrApplyMavenProjectFileTemplate(project, file, myProjectId, isInteractive);
result.setResult(file);
} catch (IOException e) {
showError(project, e);
return;
}
updateProjectPom(project, file);
if (myAggregatorProject != null) {
MavenDomProjectModel model = MavenDomUtil.getMavenDomProjectModel(project, myAggregatorProject.getFile());
if (model != null) {
model.getPackaging().setStringValue("pom");
MavenDomModule module = model.getModules().addModule();
module.setValue(getPsiFile(project, file));
}
}
}
}.execute().getResultObject();
if (pom == null)
return;
if (myAggregatorProject == null) {
MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
manager.addManagedFilesOrUnignore(Collections.singletonList(pom));
}
if (myArchetype == null) {
try {
VfsUtil.createDirectories(root.getPath() + "/src/main/java");
VfsUtil.createDirectories(root.getPath() + "/src/main/resources");
VfsUtil.createDirectories(root.getPath() + "/src/test/java");
} catch (IOException e) {
MavenLog.LOG.info(e);
}
}
// execute when current dialog is closed (e.g. Project Structure)
MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> {
if (!pom.isValid())
return;
EditorHelper.openInEditor(getPsiFile(project, pom));
if (myArchetype != null)
generateFromArchetype(project, pom);
});
}
Aggregations