Search in sources :

Example 1 with MavenDomModule

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);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) MavenDomModule(org.jetbrains.idea.maven.dom.model.MavenDomModule) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 MavenDomModule (org.jetbrains.idea.maven.dom.model.MavenDomModule)1 MavenDomProjectModel (org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)1 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)1