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

(-)a/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NbmWizardIterator.java (-17 / +3 lines)
Lines 55-61 Link Here
55
import javax.swing.event.ChangeListener;
55
import javax.swing.event.ChangeListener;
56
import javax.xml.namespace.QName;
56
import javax.xml.namespace.QName;
57
import org.apache.maven.cli.MavenCli;
57
import org.apache.maven.cli.MavenCli;
58
import org.netbeans.api.progress.ProgressHandle;
59
import org.netbeans.api.project.Project;
58
import org.netbeans.api.project.Project;
60
import org.netbeans.api.project.ProjectManager;
59
import org.netbeans.api.project.ProjectManager;
61
import org.netbeans.api.validation.adapters.WizardDescriptorAdapter;
60
import org.netbeans.api.validation.adapters.WizardDescriptorAdapter;
Lines 84-90 Link Here
84
import org.openide.util.NbBundle.Messages;
83
import org.openide.util.NbBundle.Messages;
85
import static org.netbeans.modules.maven.apisupport.Bundle.*;
84
import static org.netbeans.modules.maven.apisupport.Bundle.*;
86
85
87
public class NbmWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator<WizardDescriptor> {
86
public class NbmWizardIterator implements WizardDescriptor.BackgroundInstantiatingIterator<WizardDescriptor> {
88
87
89
    public static final String NBM_ARTIFACTID = "nbm_artifactId";
88
    public static final String NBM_ARTIFACTID = "nbm_artifactId";
90
    
89
    
Lines 154-183 Link Here
154
    
153
    
155
    @Override
154
    @Override
156
    public Set<FileObject> instantiate() throws IOException {
155
    public Set<FileObject> instantiate() throws IOException {
157
        assert false : "Cannot call this method if implements WizardDescriptor.ProgressInstantiatingIterator."; //NOI18N
158
        return null;
159
    }
160
    
161
    @Override
162
    public Set<FileObject> instantiate(ProgressHandle handle) throws IOException {
163
        ProjectInfo vi = new ProjectInfo((String) wiz.getProperty("groupId"), (String) wiz.getProperty("artifactId"), (String) wiz.getProperty("version"), (String) wiz.getProperty("package")); //NOI18N
156
        ProjectInfo vi = new ProjectInfo((String) wiz.getProperty("groupId"), (String) wiz.getProperty("artifactId"), (String) wiz.getProperty("version"), (String) wiz.getProperty("package")); //NOI18N
164
157
165
        ArchetypeWizards.logUsage(archetype.getGroupId(), archetype.getArtifactId(), archetype.getVersion());
158
        ArchetypeWizards.logUsage(archetype.getGroupId(), archetype.getArtifactId(), archetype.getVersion());
166
159
167
        try {
168
            String nbm_artifactId = (String) wiz.getProperty(NBM_ARTIFACTID);
160
            String nbm_artifactId = (String) wiz.getProperty(NBM_ARTIFACTID);
169
            int max = nbm_artifactId != null ? 7 : 4;
170
            handle.start(max);
171
            File projFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N
161
            File projFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N
172
            String version = (String) wiz.getProperty(NB_VERSION);
162
            String version = (String) wiz.getProperty(NB_VERSION);
173
            Map<String,String> additional = version != null ? Collections.singletonMap("netbeansVersion", version) : null; // NOI18N
163
            Map<String,String> additional = version != null ? Collections.singletonMap("netbeansVersion", version) : null; // NOI18N
174
            ArchetypeWizards.createFromArchetype(handle, projFile, vi, archetype, additional, 0, true);
164
            ArchetypeWizards.createFromArchetype(projFile, vi, archetype, additional, true);
175
            if (nbm_artifactId != null && projFile.exists()) {
165
            if (nbm_artifactId != null && projFile.exists()) {
176
                //NOW we have the nbm-Platform or nbm suite template
166
                //NOW we have the nbm-Platform or nbm suite template
177
                //create the nbm module
167
                //create the nbm module
178
                ProjectInfo nbm = new ProjectInfo(vi.groupId, nbm_artifactId, vi.version, vi.packageName);
168
                ProjectInfo nbm = new ProjectInfo(vi.groupId, nbm_artifactId, vi.version, vi.packageName);
179
                File nbm_folder = FileUtil.normalizeFile(new File(projFile, nbm_artifactId));
169
                File nbm_folder = FileUtil.normalizeFile(new File(projFile, nbm_artifactId));
180
                ArchetypeWizards.createFromArchetype(handle, nbm_folder, nbm, NB_MODULE_ARCH, additional, 2, false);
170
                ArchetypeWizards.createFromArchetype(nbm_folder, nbm, NB_MODULE_ARCH, additional, false);
181
                trimInheritedFromNbmProject(nbm_folder);
171
                trimInheritedFromNbmProject(nbm_folder);
182
                if (archetype == NB_APP_ARCH) {
172
                if (archetype == NB_APP_ARCH) {
183
                    File appDir = new File(projFile, "application"); //NOI18N
173
                    File appDir = new File(projFile, "application"); //NOI18N
Lines 228-238 Link Here
228
                addSnapshotRepo(projFile);
218
                addSnapshotRepo(projFile);
229
            }
219
            }
230
            Templates.setDefinesMainProject(wiz, projects.size() > 1);
220
            Templates.setDefinesMainProject(wiz, projects.size() > 1);
231
            handle.progress(max);
232
            return projects;
221
            return projects;
233
        } finally {
234
            handle.finish();
235
        }
236
    }
222
    }
237
    
223
    
238
    @Override
224
    @Override
(-)a/maven/src/org/netbeans/modules/maven/api/archetype/ArchetypeWizards.java (-5 / +2 lines)
Lines 47-53 Link Here
47
import java.util.Map;
47
import java.util.Map;
48
import java.util.Set;
48
import java.util.Set;
49
import org.netbeans.api.annotations.common.NullAllowed;
49
import org.netbeans.api.annotations.common.NullAllowed;
50
import org.netbeans.api.progress.ProgressHandle;
51
import org.netbeans.modules.maven.model.ModelOperation;
50
import org.netbeans.modules.maven.model.ModelOperation;
52
import org.netbeans.modules.maven.model.pom.POMModel;
51
import org.netbeans.modules.maven.model.pom.POMModel;
53
import org.netbeans.modules.maven.newproject.ArchetypeWizardUtils;
52
import org.netbeans.modules.maven.newproject.ArchetypeWizardUtils;
Lines 65-80 Link Here
65
64
66
    /**
65
    /**
67
     * Run a single archetype.
66
     * Run a single archetype.
68
     * @param handle a progress handle
69
     * @param projDir the new project directory (must be normalized first!) (note: parent dir is actually passed to plugin, i.e. assumes that project name matches this basedir)
67
     * @param projDir the new project directory (must be normalized first!) (note: parent dir is actually passed to plugin, i.e. assumes that project name matches this basedir)
70
     * @param vi metadata for new project
68
     * @param vi metadata for new project
71
     * @param arch the archetype to process
69
     * @param arch the archetype to process
72
     * @param additionalProperties any additional archetype properties, or null
70
     * @param additionalProperties any additional archetype properties, or null
73
     * @param progressCounter step to set progress handle to (will step to this number +1 and +2)
74
     * @param updateLastUsedProjectDir true to update last-used project directory for next wizard run
71
     * @param updateLastUsedProjectDir true to update last-used project directory for next wizard run
75
     */
72
     */
76
    public static void createFromArchetype(ProgressHandle handle, File projDir, ProjectInfo vi, Archetype arch, @NullAllowed Map<String,String> additionalProperties, int progressCounter, boolean updateLastUsedProjectDir) throws IOException {
73
    public static void createFromArchetype(File projDir, ProjectInfo vi, Archetype arch, @NullAllowed Map<String,String> additionalProperties, boolean updateLastUsedProjectDir) throws IOException {
77
        ArchetypeWizardUtils.createFromArchetype(handle, projDir, vi, arch, additionalProperties, progressCounter, updateLastUsedProjectDir);
74
        ArchetypeWizardUtils.createFromArchetype(projDir, vi, arch, additionalProperties, updateLastUsedProjectDir);
78
    }
75
    }
79
76
80
    /**
77
    /**
(-)a/maven/src/org/netbeans/modules/maven/newproject/ArchetypeWizardUtils.java (-69 / +8 lines)
Lines 64-70 Link Here
64
import org.netbeans.modules.maven.api.execute.RunUtils;
64
import org.netbeans.modules.maven.api.execute.RunUtils;
65
import org.netbeans.modules.maven.execute.BeanRunConfig;
65
import org.netbeans.modules.maven.execute.BeanRunConfig;
66
import org.netbeans.modules.maven.options.MavenCommandSettings;
66
import org.netbeans.modules.maven.options.MavenCommandSettings;
67
import org.netbeans.api.progress.ProgressHandle;
68
import org.netbeans.api.project.Project;
67
import org.netbeans.api.project.Project;
69
import org.netbeans.api.project.ProjectManager;
68
import org.netbeans.api.project.ProjectManager;
70
import org.netbeans.modules.maven.api.ModelUtils;
69
import org.netbeans.modules.maven.api.ModelUtils;
Lines 72-78 Link Here
72
import org.netbeans.modules.maven.api.archetype.ProjectInfo;
71
import org.netbeans.modules.maven.api.archetype.ProjectInfo;
73
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences;
72
import org.netbeans.modules.maven.indexer.api.RepositoryPreferences;
74
import org.netbeans.modules.maven.model.ModelOperation;
73
import org.netbeans.modules.maven.model.ModelOperation;
75
import org.netbeans.modules.maven.model.Utilities;
76
import org.netbeans.modules.maven.model.pom.Dependency;
74
import org.netbeans.modules.maven.model.pom.Dependency;
77
import org.netbeans.modules.maven.model.pom.POMModel;
75
import org.netbeans.modules.maven.model.pom.POMModel;
78
import org.netbeans.spi.project.ui.support.ProjectChooser;
76
import org.netbeans.spi.project.ui.support.ProjectChooser;
Lines 281-289 Link Here
281
    }
279
    }
282
280
283
    /**
281
    /**
284
     * Instantiates archetype stored in given wizard descriptor, with progress UI notification.
282
     * Instantiates archetype stored in given wizard descriptor.
285
     */
283
     */
286
    static Set<FileObject> instantiate(ProgressHandle handle, WizardDescriptor wiz) throws IOException {
284
    static Set<FileObject> instantiate(WizardDescriptor wiz) throws IOException {
287
        ProjectInfo vi = new ProjectInfo((String) wiz.getProperty("groupId"), (String) wiz.getProperty("artifactId"), (String) wiz.getProperty("version"), (String) wiz.getProperty("package")); //NOI18N
285
        ProjectInfo vi = new ProjectInfo((String) wiz.getProperty("groupId"), (String) wiz.getProperty("artifactId"), (String) wiz.getProperty("version"), (String) wiz.getProperty("package")); //NOI18N
288
286
289
        Archetype arch = (Archetype) wiz.getProperty("archetype"); //NOI18N
287
        Archetype arch = (Archetype) wiz.getProperty("archetype"); //NOI18N
Lines 292-337 Link Here
292
        @SuppressWarnings("unchecked")
290
        @SuppressWarnings("unchecked")
293
        Map<String,String> additional = (Map<String,String>) wiz.getProperty(ADDITIONAL_PROPS);
291
        Map<String,String> additional = (Map<String,String>) wiz.getProperty(ADDITIONAL_PROPS);
294
292
295
        try {
293
        File projFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N
296
            ProjectInfo ear_vi = (ProjectInfo)wiz.getProperty("ear_versionInfo"); //NOI18N
294
        createFromArchetype(projFile, vi, arch, additional, true);
297
            if (ear_vi != null) {
295
        Set<FileObject> projects = openProjects(projFile, null);
298
                // enterprise application wizard, multiple archetypes to run
296
        Templates.setDefinesMainProject(wiz, projects.size() > 1);
299
                ProjectInfo web_vi = (ProjectInfo)wiz.getProperty("web_versionInfo"); //NOI18N
297
        return projects;
300
                ProjectInfo ejb_vi = (ProjectInfo)wiz.getProperty("ejb_versionInfo"); //NOI18N
301
302
                handle.start(8 + (web_vi != null ? 3 : 0) + (ejb_vi != null ? 3 : 0));
303
                File rootFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N
304
                createFromArchetype(handle, rootFile, vi, arch, additional, 0, true);
305
                File earFile = FileUtil.normalizeFile((File) wiz.getProperty("ear_projdir")); // NOI18N
306
                createFromArchetype(handle, earFile, ear_vi, (Archetype) wiz.getProperty("ear_archetype"), null, 4, false); //NOI18N
307
                int progressCounter = 6;
308
                if (web_vi != null) {
309
                    createFromArchetype(handle, FileUtil.normalizeFile((File)wiz.getProperty("web_projdir")), web_vi, //NOI18N
310
                            (Archetype)wiz.getProperty("web_archetype"), null, progressCounter, false); //NOI18N
311
                    progressCounter += 3;
312
                }
313
                if (ejb_vi != null) {
314
                    createFromArchetype(handle, FileUtil.normalizeFile((File)wiz.getProperty("ejb_projdir")), ejb_vi, //NOI18N
315
                            (Archetype)wiz.getProperty("ejb_archetype"), null, progressCounter, false); //NOI18N
316
                    progressCounter += 3;
317
                }
318
                addEARDeps((File)wiz.getProperty("ear_projdir"), ejb_vi, web_vi);
319
                progressCounter++;
320
                Set<FileObject> projects = openProjects(rootFile, earFile);
321
                handle.progress(++progressCounter);
322
                return projects;
323
            } else {
324
                handle.start(4);
325
                File projFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N
326
                createFromArchetype(handle, projFile, vi, arch, additional, 0, true);
327
                Set<FileObject> projects = openProjects(projFile, null);
328
                handle.progress(4);
329
                Templates.setDefinesMainProject(wiz, projects.size() > 1);
330
                return projects;
331
            }
332
        } finally {
333
            handle.finish();
334
        }
335
    }
298
    }
336
299
337
    private static final String loggerName = "org.netbeans.ui.metrics.maven"; // NOI18N
300
    private static final String loggerName = "org.netbeans.ui.metrics.maven"; // NOI18N
Lines 345-353 Link Here
345
        Logger.getLogger(loggerName).log(logRecord);
308
        Logger.getLogger(loggerName).log(logRecord);
346
    }
309
    }
347
    
310
    
348
    public static void createFromArchetype(ProgressHandle handle, File projDir, ProjectInfo vi, Archetype arch, @NullAllowed Map<String,String> additional, int progressCounter, boolean updateLastUsedProjectDir) throws IOException {
311
    public static void createFromArchetype(File projDir, ProjectInfo vi, Archetype arch, @NullAllowed Map<String,String> additional, boolean updateLastUsedProjectDir) throws IOException {
349
        handle.progress(++progressCounter);
350
351
        final File parent = projDir.getParentFile();
312
        final File parent = projDir.getParentFile();
352
        if (parent == null) {
313
        if (parent == null) {
353
            throw new IOException("no parent of " + projDir);
314
            throw new IOException("no parent of " + projDir);
Lines 358-368 Link Here
358
        if (!parent.isDirectory() && !parent.mkdirs()) {
319
        if (!parent.isDirectory() && !parent.mkdirs()) {
359
            throw new IOException("could not create " + parent);
320
            throw new IOException("could not create " + parent);
360
        }
321
        }
361
        handle.progress(NbBundle.getMessage(MavenWizardIterator.class, "PRG_Processing_Archetype"), ++progressCounter);
362
363
        runArchetype(parent, vi, arch, additional);
322
        runArchetype(parent, vi, arch, additional);
364
365
        handle.progress(++progressCounter);
366
    }
323
    }
367
324
368
    public static Set<FileObject> openProjects(File dirF, File mainProjectDir) throws IOException {
325
    public static Set<FileObject> openProjects(File dirF, File mainProjectDir) throws IOException {
Lines 410-433 Link Here
410
        }
367
        }
411
    }
368
    }
412
369
413
    private static void addEARDeps (File earDir, ProjectInfo ejbVi, ProjectInfo webVi) {
414
        FileObject earDirFO = FileUtil.toFileObject(FileUtil.normalizeFile(earDir));
415
        if (earDirFO == null) {
416
            return;
417
        }
418
        List<ModelOperation<POMModel>> operations = new ArrayList<ModelOperation<POMModel>>();
419
        if (ejbVi != null) {
420
            // EAR ---> ejb
421
            operations.add(new AddDependencyOperation(ejbVi, "ejb"));
422
        }
423
        if (webVi != null) {
424
            // EAR ---> war
425
            operations.add(new AddDependencyOperation(webVi, "war"));
426
        }
427
428
        Utilities.performPOMModelOperations(earDirFO.getFileObject("pom.xml"), operations);
429
    }
430
431
    public static class AddDependencyOperation implements ModelOperation<POMModel> {
370
    public static class AddDependencyOperation implements ModelOperation<POMModel> {
432
        private final String group;
371
        private final String group;
433
        private final String artifact;
372
        private final String artifact;
(-)a/maven/src/org/netbeans/modules/maven/newproject/BasicEEWizardIterator.java (-8 / +2 lines)
Lines 48-54 Link Here
48
import java.util.Set;
48
import java.util.Set;
49
import javax.swing.JComponent;
49
import javax.swing.JComponent;
50
import javax.swing.event.ChangeListener;
50
import javax.swing.event.ChangeListener;
51
import org.netbeans.api.progress.ProgressHandle;
52
import org.netbeans.api.validation.adapters.WizardDescriptorAdapter;
51
import org.netbeans.api.validation.adapters.WizardDescriptorAdapter;
53
import org.netbeans.modules.maven.api.archetype.Archetype;
52
import org.netbeans.modules.maven.api.archetype.Archetype;
54
import org.netbeans.validation.api.ui.ValidationGroup;
53
import org.netbeans.validation.api.ui.ValidationGroup;
Lines 59-65 Link Here
59
 *
58
 *
60
 *@author Dafe Simonek
59
 *@author Dafe Simonek
61
 */
60
 */
62
public class BasicEEWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator {
61
public class BasicEEWizardIterator implements WizardDescriptor.BackgroundInstantiatingIterator {
63
    
62
    
64
    private int index;
63
    private int index;
65
    private WizardDescriptor.Panel[] panels;
64
    private WizardDescriptor.Panel[] panels;
Lines 98-109 Link Here
98
    }
97
    }
99
    
98
    
100
    public Set/*<FileObject>*/ instantiate() throws IOException {
99
    public Set/*<FileObject>*/ instantiate() throws IOException {
101
        assert false : "Cannot call this method if implements WizardDescriptor.ProgressInstantiatingIterator."; //NOI18N
100
        return ArchetypeWizardUtils.instantiate(wiz);
102
        return null;
103
    }
104
    
105
    public Set instantiate(ProgressHandle handle) throws IOException {
106
        return ArchetypeWizardUtils.instantiate(handle, wiz);
107
    }
101
    }
108
    
102
    
109
    public void initialize(WizardDescriptor wiz) {
103
    public void initialize(WizardDescriptor wiz) {
(-)a/maven/src/org/netbeans/modules/maven/newproject/EAWizardIterator.java (-8 / +50 lines)
Lines 43-72 Link Here
43
package org.netbeans.modules.maven.newproject;
43
package org.netbeans.modules.maven.newproject;
44
44
45
import java.awt.Component;
45
import java.awt.Component;
46
import java.io.File;
46
import java.io.IOException;
47
import java.io.IOException;
47
import java.text.MessageFormat;
48
import java.text.MessageFormat;
48
import java.util.ArrayList;
49
import java.util.ArrayList;
49
import java.util.List;
50
import java.util.List;
51
import java.util.Map;
50
import java.util.NoSuchElementException;
52
import java.util.NoSuchElementException;
51
import java.util.Set;
53
import java.util.Set;
52
import javax.swing.JComponent;
54
import javax.swing.JComponent;
53
import javax.swing.event.ChangeEvent;
55
import javax.swing.event.ChangeEvent;
54
import javax.swing.event.ChangeListener;
56
import javax.swing.event.ChangeListener;
55
import org.netbeans.api.progress.ProgressHandle;
56
import org.netbeans.api.validation.adapters.WizardDescriptorAdapter;
57
import org.netbeans.api.validation.adapters.WizardDescriptorAdapter;
58
import org.netbeans.modules.maven.api.archetype.Archetype;
59
import org.netbeans.modules.maven.api.archetype.ProjectInfo;
60
import org.netbeans.modules.maven.model.ModelOperation;
61
import org.netbeans.modules.maven.model.Utilities;
62
import org.netbeans.modules.maven.model.pom.POMModel;
57
import org.netbeans.validation.api.ui.ValidationGroup;
63
import org.netbeans.validation.api.ui.ValidationGroup;
58
import org.openide.WizardDescriptor;
64
import org.openide.WizardDescriptor;
65
import org.openide.filesystems.FileObject;
66
import org.openide.filesystems.FileUtil;
59
import org.openide.util.NbBundle;
67
import org.openide.util.NbBundle;
60
68
61
/**
69
/**
62
 *
70
 *
63
 *@author Dafe Simonek
71
 *@author Dafe Simonek
64
 */
72
 */
65
public class EAWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator {
73
public class EAWizardIterator implements WizardDescriptor.BackgroundInstantiatingIterator {
66
    
74
    
67
    private static final long serialVersionUID = 1L;
75
    private static final long serialVersionUID = 1L;
68
    
76
    
69
    private static final String USER_DIR_PROP = "user.dir"; //NOI18N
70
    static final String PROPERTY_CUSTOM_CREATOR = "customCreator"; //NOI18N
77
    static final String PROPERTY_CUSTOM_CREATOR = "customCreator"; //NOI18N
71
    private transient int index;
78
    private transient int index;
72
    private transient WizardDescriptor.Panel[] panels;
79
    private transient WizardDescriptor.Panel[] panels;
Lines 97-110 Link Here
97
    }
104
    }
98
    
105
    
99
    public Set/*<FileObject>*/ instantiate() throws IOException {
106
    public Set/*<FileObject>*/ instantiate() throws IOException {
100
        assert false : "Cannot call this method if implements WizardDescriptor.ProgressInstantiatingIterator."; //NOI18N
107
        ProjectInfo ear_vi = (ProjectInfo) wiz.getProperty("ear_versionInfo"); //NOI18N
101
        return null;
108
        assert ear_vi != null;
109
        // enterprise application wizard, multiple archetypes to run
110
        ProjectInfo web_vi = (ProjectInfo) wiz.getProperty("web_versionInfo"); //NOI18N
111
        ProjectInfo ejb_vi = (ProjectInfo) wiz.getProperty("ejb_versionInfo"); //NOI18N
112
        File rootFile = FileUtil.normalizeFile((File) wiz.getProperty("projdir")); // NOI18N
113
        ProjectInfo vi = new ProjectInfo((String) wiz.getProperty("groupId"), (String) wiz.getProperty("artifactId"), (String) wiz.getProperty("version"), (String) wiz.getProperty("package")); //NOI18N
114
        Archetype arch = (Archetype) wiz.getProperty("archetype"); //NOI18N
115
        @SuppressWarnings("unchecked")
116
        Map<String, String> additional = (Map<String, String>) wiz.getProperty(ArchetypeWizardUtils.ADDITIONAL_PROPS);
117
        ArchetypeWizardUtils.createFromArchetype(rootFile, vi, arch, additional, true);
118
        File earFile = FileUtil.normalizeFile((File) wiz.getProperty("ear_projdir")); // NOI18N
119
        ArchetypeWizardUtils.createFromArchetype(earFile, ear_vi, (Archetype) wiz.getProperty("ear_archetype"), null, false); //NOI18N
120
        if (web_vi != null) {
121
            ArchetypeWizardUtils.createFromArchetype(FileUtil.normalizeFile((File) wiz.getProperty("web_projdir")), web_vi, //NOI18N
122
                    (Archetype) wiz.getProperty("web_archetype"), null, false); //NOI18N
123
        }
124
        if (ejb_vi != null) {
125
            ArchetypeWizardUtils.createFromArchetype(FileUtil.normalizeFile((File) wiz.getProperty("ejb_projdir")), ejb_vi, //NOI18N
126
                    (Archetype) wiz.getProperty("ejb_archetype"), null, false); //NOI18N
127
        }
128
        addEARDeps((File) wiz.getProperty("ear_projdir"), ejb_vi, web_vi);
129
        return ArchetypeWizardUtils.openProjects(rootFile, earFile);
102
    }
130
    }
103
    
131
    
104
    public Set instantiate(ProgressHandle handle) throws IOException {
132
    private static void addEARDeps (File earDir, ProjectInfo ejbVi, ProjectInfo webVi) {
105
        return ArchetypeWizardUtils.instantiate(handle, wiz);
133
        FileObject earDirFO = FileUtil.toFileObject(FileUtil.normalizeFile(earDir));
134
        if (earDirFO == null) {
135
            return;
136
        }
137
        List<ModelOperation<POMModel>> operations = new ArrayList<ModelOperation<POMModel>>();
138
        if (ejbVi != null) {
139
            // EAR ---> ejb
140
            operations.add(new ArchetypeWizardUtils.AddDependencyOperation(ejbVi, "ejb"));
141
        }
142
        if (webVi != null) {
143
            // EAR ---> war
144
            operations.add(new ArchetypeWizardUtils.AddDependencyOperation(webVi, "war"));
145
        }
146
147
        Utilities.performPOMModelOperations(earDirFO.getFileObject("pom.xml"), operations);
106
    }
148
    }
107
    
149
108
    public void initialize(WizardDescriptor wiz) {
150
    public void initialize(WizardDescriptor wiz) {
109
        this.wiz = wiz;
151
        this.wiz = wiz;
110
        index = 0;
152
        index = 0;
(-)a/maven/src/org/netbeans/modules/maven/newproject/MavenWizardIterator.java (-9 / +2 lines)
Lines 50-56 Link Here
50
import java.util.Set;
50
import java.util.Set;
51
import javax.swing.JComponent;
51
import javax.swing.JComponent;
52
import javax.swing.event.ChangeListener;
52
import javax.swing.event.ChangeListener;
53
import org.netbeans.api.progress.ProgressHandle;
54
import org.netbeans.api.validation.adapters.WizardDescriptorAdapter;
53
import org.netbeans.api.validation.adapters.WizardDescriptorAdapter;
55
import org.netbeans.modules.maven.api.archetype.Archetype;
54
import org.netbeans.modules.maven.api.archetype.Archetype;
56
import org.netbeans.validation.api.ui.ValidationGroup;
55
import org.netbeans.validation.api.ui.ValidationGroup;
Lines 62-68 Link Here
62
 *
61
 *
63
 *@author mkleint
62
 *@author mkleint
64
 */
63
 */
65
public class MavenWizardIterator implements WizardDescriptor.ProgressInstantiatingIterator<WizardDescriptor> {
64
public class MavenWizardIterator implements WizardDescriptor.BackgroundInstantiatingIterator<WizardDescriptor> {
66
    
65
    
67
    private static final long serialVersionUID = 1L;
66
    private static final long serialVersionUID = 1L;
68
    static final String PROPERTY_CUSTOM_CREATOR = "customCreator"; //NOI18N
67
    static final String PROPERTY_CUSTOM_CREATOR = "customCreator"; //NOI18N
Lines 95-107 Link Here
95
    }
94
    }
96
    
95
    
97
    public @Override Set<FileObject> instantiate() throws IOException {
96
    public @Override Set<FileObject> instantiate() throws IOException {
98
        assert false : "Cannot call this method if implements WizardDescriptor.ProgressInstantiatingIterator."; //NOI18N
97
        return ArchetypeWizardUtils.instantiate(wiz);
99
        return null;
100
    }
101
    
102
    @Override
103
    public Set<FileObject> instantiate(ProgressHandle handle) throws IOException {
104
        return ArchetypeWizardUtils.instantiate(handle, wiz);
105
    }
98
    }
106
    
99
    
107
    @Override
100
    @Override
(-)a/openide.dialogs/src/org/openide/WizardDescriptor.java (-4 / +31 lines)
Lines 1510-1518 Link Here
1510
1510
1511
        assert panels != null;
1511
        assert panels != null;
1512
1512
1513
        err.log (Level.FINE, "Is AsynchronousInstantiatingIterator? " + (panels instanceof AsynchronousInstantiatingIterator));
1513
        if (panels instanceof BackgroundInstantiatingIterator) {
1514
        err.log (Level.FINE, "Is ProgressInstantiatingIterator? " + (panels instanceof ProgressInstantiatingIterator));
1514
            err.fine("is BackgroundInstantiatingIterator");
1515
        if (panels instanceof ProgressInstantiatingIterator) {
1515
        } else if (panels instanceof ProgressInstantiatingIterator) {
1516
            err.fine("is ProgressInstantiatingIterator");
1516
            handle = ProgressHandleFactory.createHandle (PROGRESS_BAR_DISPLAY_NAME);
1517
            handle = ProgressHandleFactory.createHandle (PROGRESS_BAR_DISPLAY_NAME);
1517
1518
1518
            JComponent progressComp = ProgressHandleFactory.createProgressComponent (handle);
1519
            JComponent progressComp = ProgressHandleFactory.createProgressComponent (handle);
Lines 1522-1527 Link Here
1522
1523
1523
            err.log (Level.FINE, "Show progressPanel controlled by iterator later.");
1524
            err.log (Level.FINE, "Show progressPanel controlled by iterator later.");
1524
        } else if (panels instanceof AsynchronousInstantiatingIterator) {
1525
        } else if (panels instanceof AsynchronousInstantiatingIterator) {
1526
            err.fine("is AsynchronousInstantiatingIterator");
1525
            handle = ProgressHandleFactory.createHandle (PROGRESS_BAR_DISPLAY_NAME);
1527
            handle = ProgressHandleFactory.createHandle (PROGRESS_BAR_DISPLAY_NAME);
1526
1528
1527
            JComponent progressComp = ProgressHandleFactory.createProgressComponent (handle);
1529
            JComponent progressComp = ProgressHandleFactory.createProgressComponent (handle);
Lines 1879-1884 Link Here
1879
    }
1881
    }
1880
1882
1881
    /**
1883
    /**
1884
     * Iterator for a wizard that will create new objects after the wizard has been closed.
1885
     * Suitable for cases where the instantiation might be quite time consuming, has its own progress/cancellation UI,
1886
     * or otherwise would be undesirable to run with the wizard dialog open.
1887
     * @param <Data> in practice this should be {@link WizardDescriptor}
1888
     * @since XXX
1889
     */
1890
    public interface BackgroundInstantiatingIterator<Data> extends AsynchronousInstantiatingIterator<Data> {
1891
1892
        /**
1893
         * Called in a separate thread when the Finish button is clicked and the wizard is closed.
1894
         * @return a set of objects created (the exact type is at the discretion of the caller)
1895
         * @throws IOException when instantiate fails
1896
         */
1897
        Set/*<?>*/ instantiate() throws IOException;
1898
    }
1899
1900
    /**
1882
     * Iterator for a wizard that wants to notify users while instantiate is running by a progress bar.
1901
     * Iterator for a wizard that wants to notify users while instantiate is running by a progress bar.
1883
     * The method <code>instantiate</code> is called outside ATW queue.
1902
     * The method <code>instantiate</code> is called outside ATW queue.
1884
     * (This interface can replace
1903
     * (This interface can replace
Lines 2143-2154 Link Here
2143
                        if (panels instanceof AsynchronousInstantiatingIterator) {
2162
                        if (panels instanceof AsynchronousInstantiatingIterator) {
2144
                            err.log (Level.FINE, "Do ASYNCHRONOUS_JOBS_RP.post(performFinish)."); // NOI18N
2163
                            err.log (Level.FINE, "Do ASYNCHRONOUS_JOBS_RP.post(performFinish)."); // NOI18N
2145
                            ASYNCHRONOUS_JOBS_RP.post (performFinish);
2164
                            ASYNCHRONOUS_JOBS_RP.post (performFinish);
2165
                            if (panels instanceof BackgroundInstantiatingIterator) {
2166
                                Window parentWindow = SwingUtilities.getWindowAncestor((Component) getMessage());
2167
                                if (parentWindow != null) {
2168
                                    parentWindow.setVisible(false);
2169
                                } else {
2170
                                    err.log(Level.WARNING, "could not find parent window of {0}", getMessage());
2171
                                }
2172
                            }
2146
                        } else {
2173
                        } else {
2147
                            err.log (Level.FINE, "Run performFinish."); // NOI18N
2174
                            err.log (Level.FINE, "Run performFinish."); // NOI18N
2148
                            performFinish.run ();
2175
                            performFinish.run ();
2149
                        }
2176
                        }
2150
2177
2151
                        err.log (Level.FINE, "onValidPerformer on finish button exit."); // NOI18N
2178
                        err.log(Level.FINE, "onValidPerformer on finish button exit on {0}", panels);
2152
2179
2153
                    }
2180
                    }
2154
                };
2181
                };
(-)a/openide.loaders/src/org/openide/actions/NewTemplateAction.java (-1 / +1 lines)
Lines 163-169 Link Here
163
    }
163
    }
164
    
164
    
165
    protected boolean asynchronous() {
165
    protected boolean asynchronous() {
166
        return false;
166
        return true;
167
    }
167
    }
168
168
169
    /* Enables itself only when activates node is DataFolder.
169
    /* Enables itself only when activates node is DataFolder.
(-)a/openide.loaders/src/org/openide/loaders/TemplateWizard.java (-23 / +41 lines)
Lines 52-57 Link Here
52
import java.net.*;
52
import java.net.*;
53
import java.text.MessageFormat;
53
import java.text.MessageFormat;
54
import java.util.*;
54
import java.util.*;
55
import java.util.concurrent.ArrayBlockingQueue;
56
import java.util.concurrent.BlockingQueue;
55
import java.util.logging.Level;
57
import java.util.logging.Level;
56
import java.util.logging.Logger;
58
import java.util.logging.Logger;
57
import javax.swing.*;
59
import javax.swing.*;
Lines 118-124 Link Here
118
    /** Component which we are listening on for changes of steps */
120
    /** Component which we are listening on for changes of steps */
119
    private Component lastComp;
121
    private Component lastComp;
120
    
122
    
121
    private Set<DataObject> newObjects = null;
123
    private BlockingQueue<Union2<Set<DataObject>,IOException>> newObjects = null;
122
124
123
    private ProgressHandle progressHandle;
125
    private ProgressHandle progressHandle;
124
    
126
    
Lines 160-166 Link Here
160
    protected void initialize () {
162
    protected void initialize () {
161
        if (iterator != null) {
163
        if (iterator != null) {
162
            iterator.initialize(this);
164
            iterator.initialize(this);
163
            newObjects = null;
165
            newObjects = new ArrayBlockingQueue<Union2<Set<DataObject>,IOException>>(1);
164
        }
166
        }
165
        super.initialize ();
167
        super.initialize ();
166
    }
168
    }
Lines 189-194 Link Here
189
                    TemplateWizardIteratorWrapper newIterImplWrapper = new TemplateWizardIteratorWrapper.ProgressInstantiatingIterator (this.iterator.getOriginalIterImpl ());
191
                    TemplateWizardIteratorWrapper newIterImplWrapper = new TemplateWizardIteratorWrapper.ProgressInstantiatingIterator (this.iterator.getOriginalIterImpl ());
190
                    this.iterator = newIterImplWrapper;
192
                    this.iterator = newIterImplWrapper;
191
                    this.setPanelsAndSettings(newIterImplWrapper, this);
193
                    this.setPanelsAndSettings(newIterImplWrapper, this);
194
                } else if (newIt instanceof WizardDescriptor.BackgroundInstantiatingIterator) {
195
                    TemplateWizardIteratorWrapper newIterImplWrapper = new TemplateWizardIteratorWrapper.BackgroundInstantiatingIterator (this.iterator.getOriginalIterImpl ());
196
                    this.iterator = newIterImplWrapper;
197
                    this.setPanelsAndSettings(newIterImplWrapper, this);
192
                } else if (newIt instanceof WizardDescriptor.AsynchronousInstantiatingIterator) {
198
                } else if (newIt instanceof WizardDescriptor.AsynchronousInstantiatingIterator) {
193
                    TemplateWizardIteratorWrapper newIterImplWrapper = new TemplateWizardIteratorWrapper.AsynchronousInstantiatingIterator (this.iterator.getOriginalIterImpl ());
199
                    TemplateWizardIteratorWrapper newIterImplWrapper = new TemplateWizardIteratorWrapper.AsynchronousInstantiatingIterator (this.iterator.getOriginalIterImpl ());
194
                    this.iterator = newIterImplWrapper;
200
                    this.iterator = newIterImplWrapper;
Lines 358-363 Link Here
358
    }
364
    }
359
    
365
    
360
    /** Chooses the template and instantiates it.
366
    /** Chooses the template and instantiates it.
367
     * <p>Beware that this blocks while the wizard is running;
368
     * and if a {@link org.openide.WizardDescriptor.BackgroundInstantiatingIterator} might be selected,
369
     * should not be called from the AWT event queue.
361
    * @return set of instantiated data objects (DataObject) 
370
    * @return set of instantiated data objects (DataObject) 
362
    *   or null if user canceled the dialog
371
    *   or null if user canceled the dialog
363
    * @exception IOException I/O error
372
    * @exception IOException I/O error
Lines 368-374 Link Here
368
    }
377
    }
369
378
370
    /** Chooses the template and instantiates it.
379
    /** Chooses the template and instantiates it.
371
    *
380
     * See {@link #instantiate()} regarding threading behavior.
372
    * @param template predefined template that should be instantiated
381
    * @param template predefined template that should be instantiated
373
    * @return set of instantiated data objects (DataObject) 
382
    * @return set of instantiated data objects (DataObject) 
374
    *   or null if user canceled the dialog
383
    *   or null if user canceled the dialog
Lines 380-386 Link Here
380
    }
389
    }
381
390
382
    /** Chooses the template and instantiates it.
391
    /** Chooses the template and instantiates it.
383
    *
392
     * See {@link #instantiate()} regarding threading behavior.
384
    * @param template predefined template that should be instantiated
393
    * @param template predefined template that should be instantiated
385
    * @param targetFolder the target folder
394
    * @param targetFolder the target folder
386
    *
395
    *
Lines 401-407 Link Here
401
    
410
    
402
    Set<DataObject> instantiateNewObjects (ProgressHandle handle) throws IOException {
411
    Set<DataObject> instantiateNewObjects (ProgressHandle handle) throws IOException {
403
        progressHandle = handle;
412
        progressHandle = handle;
404
        try {
413
        Union2<Set<DataObject>,IOException> val;
405
            // #17341. The problem is handling ESC -> value is not
414
            // #17341. The problem is handling ESC -> value is not
406
            // set to CANCEL_OPTION for such cases.
415
            // set to CANCEL_OPTION for such cases.
407
            Object option = getValue();
416
            Object option = getValue();
Lines 410-436 Link Here
410
419
411
                // show wait cursor when handling instantiate
420
                // show wait cursor when handling instantiate
412
                showWaitCursor (); 
421
                showWaitCursor (); 
413
422
                try {
414
                newObjects = handleInstantiate ();
423
                    val = Union2.createFirst(handleInstantiate());
415
                if (lastComp != null) {
424
                } catch (IOException x) {
416
                    lastComp.removePropertyChangeListener(propL());
425
                    val = Union2.createSecond(x);
417
                    lastComp = null;
426
                } finally {
427
                    showNormalCursor();
418
                }
428
                }
419
            } else {
429
            } else {
420
                if (lastComp != null) {
430
                val = Union2.createFirst(null);
421
                    lastComp.removePropertyChangeListener(propL());
422
                    lastComp = null;
423
                }
424
                newObjects = null;
425
            }
431
            }
426
432
            if (lastComp != null) {
427
        } finally {
433
                lastComp.removePropertyChangeListener(propL());
434
                lastComp = null;
435
            }
428
            
436
            
429
            // set normal cursor back
437
        newObjects.add(val);
430
            showNormalCursor ();
438
        if (val.hasFirst()) {
439
            return val.first();
440
        } else {
441
            throw val.second();
431
        }
442
        }
432
            
433
        return newObjects;
434
    }
443
    }
435
444
436
    /** Chooses the template and instantiates it.
445
    /** Chooses the template and instantiates it.
Lines 501-510 Link Here
501
        } catch (IllegalStateException ise) {
510
        } catch (IllegalStateException ise) {
502
            thrownMessage = ise;
511
            thrownMessage = ise;
503
        }
512
        }
504
        
505
        // here can return newObjects because instantiateNewObjects() was called
513
        // here can return newObjects because instantiateNewObjects() was called
506
        // from WizardDescriptor before close dialog (on Finish)
514
        // from WizardDescriptor before close dialog (on Finish)
507
        return newObjects;
515
        Union2<Set<DataObject>,IOException> val;
516
        try {
517
            val = newObjects.take();
518
        } catch (InterruptedException x) {
519
            throw new IOException(x);
520
        }
521
        if (val.hasFirst()) {
522
            return val.first();
523
        } else {
524
            throw val.second();
525
        }
508
    }
526
    }
509
    
527
    
510
    private void showWaitCursor () {
528
    private void showWaitCursor () {
(-)a/openide.loaders/src/org/openide/loaders/TemplateWizardIteratorWrapper.java (-1 / +7 lines)
Lines 179-185 Link Here
179
            super (it);
179
            super (it);
180
        }
180
        }
181
    }
181
    }
182
    
182
183
    static class BackgroundInstantiatingIterator extends InstantiatingIterator implements WizardDescriptor.BackgroundInstantiatingIterator<WizardDescriptor> {
184
        public BackgroundInstantiatingIterator (TemplateWizardIterImpl it) {
185
            super (it);
186
        }
187
    }
188
183
    static class ProgressInstantiatingIterator extends InstantiatingIterator implements WizardDescriptor.ProgressInstantiatingIterator<WizardDescriptor> {
189
    static class ProgressInstantiatingIterator extends InstantiatingIterator implements WizardDescriptor.ProgressInstantiatingIterator<WizardDescriptor> {
184
        private TemplateWizardIterImpl itImpl;
190
        private TemplateWizardIterImpl itImpl;
185
        public ProgressInstantiatingIterator (TemplateWizardIterImpl it) {
191
        public ProgressInstantiatingIterator (TemplateWizardIterImpl it) {
(-)a/projectui/src/org/netbeans/modules/project/ui/actions/NewFile.java (-3 / +6 lines)
Lines 137-143 Link Here
137
        doPerform( context, null, true );
137
        doPerform( context, null, true );
138
    }
138
    }
139
139
140
    private void doPerform( Lookup context, DataObject template, boolean inProject ) {
140
    private void doPerform( Lookup context, final DataObject template, boolean inProject ) {
141
141
142
        if ( context == null ) {
142
        if ( context == null ) {
143
            context = getLookup();
143
            context = getLookup();
Lines 154-166 Link Here
154
            return;
154
            return;
155
        }
155
        }
156
156
157
        NewFileWizard wd = new NewFileWizard( preselectedProject( context ) /* , null */ );
157
        final NewFileWizard wd = new NewFileWizard( preselectedProject( context ) /* , null */ );
158
        
158
        
159
        DataFolder preselectedFolder = preselectedFolder( context );
159
        DataFolder preselectedFolder = preselectedFolder( context );
160
        if ( preselectedFolder != null ) {
160
        if ( preselectedFolder != null ) {
161
            wd.setTargetFolder( preselectedFolder );
161
            wd.setTargetFolder( preselectedFolder );
162
        }
162
        }
163
163
164
        RP.post(new Runnable() {
165
            @Override public void run() {
164
        try {
166
        try {
165
            Set resultSet = template == null ? wd.instantiate () : wd.instantiate( template );
167
            Set resultSet = template == null ? wd.instantiate () : wd.instantiate( template );
166
168
Lines 199-205 Link Here
199
        //Project project = Templates.getProject( wd );
201
        //Project project = Templates.getProject( wd );
200
        FileObject foTemplate = Templates.getTemplate( wd );
202
        FileObject foTemplate = Templates.getTemplate( wd );
201
        OpenProjectList.getDefault().updateTemplatesLRU( foTemplate );
203
        OpenProjectList.getDefault().updateTemplatesLRU( foTemplate );
202
204
            }
205
        });
203
    }
206
    }
204
207
205
    // Context Aware action implementation -------------------------------------
208
    // Context Aware action implementation -------------------------------------
(-)a/projectui/src/org/netbeans/modules/project/ui/actions/NewProject.java (-11 / +12 lines)
Lines 131-143 Link Here
131
        FileObject fo = FileUtil.getConfigFile( "Templates/Project" ); //NOI18N
131
        FileObject fo = FileUtil.getConfigFile( "Templates/Project" ); //NOI18N
132
        final NewProjectWizard wizard = prepareWizardDescriptor(fo);
132
        final NewProjectWizard wizard = prepareWizardDescriptor(fo);
133
        
133
        
134
        
134
        final Set newObjects;
135
        SwingUtilities.invokeLater( new Runnable() {
135
        try {
136
            
136
            newObjects = wizard.instantiate();
137
            public void run() {
137
        } catch (IOException e) {
138
                try {
138
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
139
                    
139
            return;
140
                    Set newObjects = wizard.instantiate();
140
        }
141
                    // #75960 - test if any folder was created during the wizard and if yes and it's empty delete it
141
                    // #75960 - test if any folder was created during the wizard and if yes and it's empty delete it
142
                    Preferences prefs = NbPreferences.forModule(OpenProjectListSettings.class);
142
                    Preferences prefs = NbPreferences.forModule(OpenProjectListSettings.class);
143
                    String nbPrjDirPath = prefs.get(OpenProjectListSettings.PROP_CREATED_PROJECTS_FOLDER, null);
143
                    String nbPrjDirPath = prefs.get(OpenProjectListSettings.PROP_CREATED_PROJECTS_FOLDER, null);
Lines 148-156 Link Here
148
                            prjDir.delete();
148
                            prjDir.delete();
149
                        }
149
                        }
150
                    }
150
                    }
151
                    
151
152
                    //#69618: the non-project cache may contain a project folder listed in newObjects:
152
                    //#69618: the non-project cache may contain a project folder listed in newObjects:
153
                    ProjectManager.getDefault().clearNonProjectCache();
153
                    ProjectManager.getDefault().clearNonProjectCache();
154
        
155
        SwingUtilities.invokeLater( new Runnable() {
156
            
157
            public void run() {
154
                    ProjectUtilities.WaitCursor.show();
158
                    ProjectUtilities.WaitCursor.show();
155
                    
159
                    
156
                    if ( newObjects != null && !newObjects.isEmpty() ) {
160
                    if ( newObjects != null && !newObjects.isEmpty() ) {
Lines 225-233 Link Here
225
                        
229
                        
226
                    }
230
                    }
227
                    ProjectUtilities.WaitCursor.hide();
231
                    ProjectUtilities.WaitCursor.hide();
228
                } catch ( IOException e ) {
229
                    ErrorManager.getDefault().notify( ErrorManager.INFORMATIONAL, e );
230
                }
231
            }
232
            }
232
            
233
            
233
        } );
234
        } );

Return to bug 191951