Author: fbricon
Date: 2011-10-05 07:41:01 -0400 (Wed, 05 Oct 2011)
New Revision: 35362
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizard.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java
Log:
JBIDE-9823 : fix to prevent Archetype properties from being displayed twice in the
Archetype-based Example Wizard
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizard.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizard.java 2011-10-05
11:24:10 UTC (rev 35361)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizard.java 2011-10-05
11:41:01 UTC (rev 35362)
@@ -66,7 +66,6 @@
final String version = model.getVersion();
final String javaPackage = wizardPage.getJavaPackage();
final Properties properties = wizardPage.getProperties();
- final MavenPlugin plugin = MavenPlugin.getDefault();
final Archetype archetype = wizardPage.getArchetype();
final String projectName = configuration.getProjectName(model);
final IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
@@ -74,7 +73,7 @@
final IWorkspaceRunnable wr = new IWorkspaceRunnable() {
public void run(final IProgressMonitor monitor)
throws CoreException {
- plugin.getProjectConfigurationManager().createArchetypeProject(
+ MavenPlugin.getProjectConfigurationManager().createArchetypeProject(
project, new Path(location.getAbsolutePath()), archetype,
groupId, artifactId, version, javaPackage, properties,
configuration, monitor);
@@ -104,6 +103,8 @@
return true;
}
+
+
public void addPages() {
configuration = new ProjectImportConfiguration();
wizardPage = new ArchetypeExamplesWizardPage(configuration, projectDescription);
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java 2011-10-05
11:24:10 UTC (rev 35361)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java 2011-10-05
11:41:01 UTC (rev 35362)
@@ -10,10 +10,27 @@
************************************************************************************/
package org.jboss.tools.maven.project.examples.wizard;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Properties;
+
import org.apache.maven.archetype.catalog.Archetype;
+import org.apache.maven.archetype.common.ArchetypeArtifactManager;
+import org.apache.maven.archetype.exception.UnknownArchetype;
+import org.apache.maven.archetype.metadata.ArchetypeDescriptor;
+import org.apache.maven.archetype.metadata.RequiredProperty;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.IMaven;
+import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import
org.eclipse.m2e.core.ui.internal.wizards.MavenProjectWizardArchetypeParametersPage;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.maven.project.examples.MavenProjectExamplesActivator;
import org.jboss.tools.project.examples.model.ArchetypeModel;
import org.jboss.tools.project.examples.model.Project;
@@ -48,10 +65,30 @@
archetype.setArtifactId(archetypeModel.getArchetypeArtifactId());
archetype.setVersion(archetypeModel.getArchetypeVersion());
archetype.setRepository(archetypeModel.getArchetypeRepository());
- archetype.setProperties(archetypeModel.getArchetypeProperties());
+
+ //Since we set archetypeChanged=false later on, we need to do the equivalent of
+ //MavenProjectWizardArchetypeParametersPage.loadArchetypeDescriptor(),
+ //as we don't have the guarantee archetypeModel holds ALL the required properties
+ //This really is an extra-safe guard, as I believe we'll probably always
+ //redefine all required properties in project-examples-maven-xxx.xml
+ Properties defaultRequiredProperties = getRequiredProperties(archetype);
+ Properties properties = new Properties(archetypeModel.getArchetypeProperties());
+ //Add remaining requiredProperties not defined by default in the example project
+ for (Object key : defaultRequiredProperties.keySet()) {
+ if (!properties.containsKey(key)) {
+ properties.put(key, defaultRequiredProperties.get(key));
+ }
+ }
+ archetype.setProperties(properties);
setArchetype(archetype);
+
+ //JBIDE-9823 : Hack to prevent the properties table to be loaded a 2nd time
+ // when setVisible() is called in MavenProjectWizardArchetypeParametersPage.
+ // It needs to be called AFTER setArchetype(archetype) !!!
+ archetypeChanged = false;
+
+ artifactIdCombo.setText(artifactId);
groupIdCombo.setText(groupId);
- artifactIdCombo.setText(artifactId);
versionCombo.setText(version);
packageCombo.setText(javaPackage);
}
@@ -59,5 +96,54 @@
public Archetype getArchetype() {
return archetype;
}
+
+ private Properties getRequiredProperties(Archetype archetype) {
+ final String groupId = archetype.getGroupId();
+ final String artifactId = archetype.getArtifactId();
+ final String version = archetype.getVersion();
+ final String archetypeName = groupId + ":" + artifactId + ":" +
version; //$NON-NLS-1$ //$NON-NLS-2$
+ final Properties requiredProperties = new Properties();
+ try {
+ getContainer().run(false, true, new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) {
+ monitor.beginTask(NLS.bind("Downloading Archetype {0}",
archetypeName), IProgressMonitor.UNKNOWN); //$NON-NLS-1$
+ try {
+ IMaven maven = MavenPlugin.getMaven();
+ ArtifactRepository localRepository = maven.getLocalRepository();
+
+ List<ArtifactRepository> repositories =
maven.getArtifactRepositories();
+
+ ArchetypeArtifactManager aaMgr =
MavenPluginActivator.getDefault().getArchetypeArtifactManager();
+ if(aaMgr.isFileSetArchetype(groupId, artifactId, version, null,
localRepository, repositories)) {
+ ArchetypeDescriptor descriptor =
aaMgr.getFileSetArchetypeDescriptor(groupId, artifactId, version, null,
+ localRepository, repositories);
+ List<?> properties = descriptor.getRequiredProperties();
+ if(properties != null) {
+ for(Object o : properties) {
+ if(o instanceof RequiredProperty) {
+ RequiredProperty rp = (RequiredProperty) o;
+ requiredProperties.put(rp.getKey(), rp.getDefaultValue());
+ }
+ }
+ }
+ }
+ } catch(UnknownArchetype e) {
+ MavenProjectExamplesActivator.log(e);
+ } catch(CoreException ex) {
+ MavenProjectExamplesActivator.log(ex);
+ } finally {
+ monitor.done();
+ }
+ }
+ });
+ } catch(InterruptedException ex) {
+ // ignore
+ } catch(InvocationTargetException ex) {
+ String msg = NLS.bind("Error downloading archetype {0}",
archetypeName);//$NON-NLS-1$
+ MavenProjectExamplesActivator.log(ex, msg);
+ setErrorMessage(msg + "\n" + ex.toString()); //$NON-NLS-1$
+ }
+ return requiredProperties;
+ }
}
Show replies by date