[jbosstools-commits] JBoss Tools SVN: r43798 - in trunk: examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model and 8 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Sep 18 11:19:51 EDT 2012


Author: fbricon
Date: 2012-09-18 11:19:51 -0400 (Tue, 18 Sep 2012)
New Revision: 43798

Added:
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/commons-codec-1.3.jar
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/commons-logging-1.1.1.jar
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/httpclient-4.0.1.jar
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/httpcore-4.0.1.jar
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/jboss-logging-3.1.2.GA.jar
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/snakeyaml-1.10.jar
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/stacks-client-1.0.0.CR2.jar
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksManager.java
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksUtil.java
Modified:
   trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml
   trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ArchetypeModel.java
   trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectExampleUtil.java
   trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesRequirementsPage.java
   trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard2.java
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/.classpath
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/build.properties
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java
   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/MavenProjectConstants.java
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/NewProjectExamplesStacksRequirementsPage.java
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/xpl/MavenProjectWizardArchetypeParametersPage.java
Log:
JBIDE-12472 Use JDF stacks to manage different archetype versions
JBIDE-12166 Support selection of "blank" archetypes


Modified: trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/plugin.xml	2012-09-18 15:19:51 UTC (rev 43798)
@@ -77,7 +77,11 @@
     <extension
         point="org.jboss.tools.project.examples.projectExamplesXml"
         name="Shared Examples">
-        <url>http://download.jboss.org/jbosstools/examples/project-examples-shared-4.0.Alpha1.xml</url>
+        <!--
+        <url>http://download.jboss.org/jbosstools/examples/project-examples-shared-4.0.Alpha2.xml</url>
+        -->
+        <url>file://D:/Dev/jbt-trunk/download.jboss.org/jbosstools/examples/project-examples-shared-4.0.Alpha2.xml</url>
+        
         <experimental>false</experimental>
     </extension>
     

Modified: trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ArchetypeModel.java
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ArchetypeModel.java	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ArchetypeModel.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -16,7 +16,7 @@
  * @author snjeza
  * 
  */
-public class ArchetypeModel {
+public class ArchetypeModel implements Cloneable {
 	private String groupId;
 	private String artifactId;
 	private String version;
@@ -99,4 +99,9 @@
 	public void addProperty(String key, String value) {
 		archetypeProperties.put(key, value);
 	}
+	
+	@Override
+	public Object clone() throws CloneNotSupportedException {
+		return super.clone();
+	}
 }

Modified: trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectExampleUtil.java
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectExampleUtil.java	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectExampleUtil.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -479,7 +479,7 @@
 								} else if (nodeName.equals("essentialEnterpriseDependencies")) { //$NON-NLS-1$
 									parseEssentialEnterpriseDependencies(project, child);
 								} else if (nodeName.equals("stacksId")) { //$NON-NLS-1$
-									String stacksId = child.getAttribute("stacksId"); //$NON-NLS-1$
+									String stacksId = getContent(child); 
 									if (stacksId != null) {
 										project.setStacksId(stacksId);
 									}

Modified: trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesRequirementsPage.java
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesRequirementsPage.java	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesRequirementsPage.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -68,11 +68,13 @@
 public class NewProjectExamplesRequirementsPage extends WizardPage implements IProjectExamplesWizardPage {
 
 	private static final String PAGE_NAME = "org.jboss.tools.project.examples.requirements"; //$NON-NLS-1$
-	private ProjectExample projectExample;
-	private Text descriptionText;
-	private Text projectSize;
+	protected ProjectExample projectExample;
+	protected Text descriptionText;
+	protected Label projectSizeLabel;
+	protected Text projectSize;
+	protected WizardContext wizardContext;
+	protected TableViewer tableViewer;
 	private List<ProjectFix> fixes = new ArrayList<ProjectFix>();
-	private TableViewer tableViewer;
 	private ArrayList<ProjectFix> unsatisfiedFixes = new ArrayList<ProjectFix>();
 	private Image checkboxOn;
 	private Image checkboxOff;
@@ -90,6 +92,36 @@
 		checkboxOff = RuntimeUIActivator.imageDescriptorFromPlugin(RuntimeUIActivator.PLUGIN_ID, "/icons/xpl/incomplete_tsk.gif").createImage();
 	}
 
+	protected void setDescriptionArea(Composite composite) {
+		Label descriptionLabel = new Label(composite,SWT.NONE);
+		descriptionLabel.setText(Messages.NewProjectExamplesWizardPage_Description);
+		GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
+		gd.horizontalSpan = 2;
+		descriptionLabel.setLayoutData(gd);
+		descriptionText = new Text(composite, SWT.H_SCROLL | SWT.V_SCROLL
+				| SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
+		gd = new GridData(SWT.FILL, SWT.FILL, false, false);
+		GC gc = new GC(composite.getParent());
+		gd.heightHint = Dialog.convertHeightInCharsToPixels(gc
+				.getFontMetrics(), 6);
+		gc.dispose();
+		gd.horizontalSpan = 2;
+		gd.widthHint = 250;
+		descriptionText.setLayoutData(gd);
+	}
+	
+	protected void setSelectionArea(Composite composite) {
+		projectSizeLabel = new Label(composite,SWT.NULL);
+		projectSizeLabel.setText(Messages.NewProjectExamplesWizardPage_Project_size);
+		projectSize = new Text(composite,SWT.READ_ONLY);
+		projectSize.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+		
+		Label label = new Label(composite, SWT.NONE);
+		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+		gd.horizontalSpan = 2;
+		label.setLayoutData(gd);
+	}
+	
 	protected void setTitleAndDescription(ProjectExample projectExample) {
 		setTitle( "Requirements" );
         setDescription( "Project Example Requirements" );
@@ -104,7 +136,7 @@
 				if (projectExample.getDescription() != null) {
 					descriptionText.setText(projectExample.getDescription());
 				}
-				if (projectExample.getSizeAsText() != null) {
+				if (projectExample.getSizeAsText() != null && projectSize != null) {
 					projectSize.setText(projectExample.getSizeAsText());
 				}
 			}
@@ -113,7 +145,9 @@
 	        setDescription( "Project Example Requirements" );
 	        if (descriptionText != null) {
 	        	descriptionText.setText(""); //$NON-NLS-1$
-	        	projectSize.setText(""); //$NON-NLS-1$
+	        	if (projectSize != null) {
+	        		projectSize.setText(""); //$NON-NLS-1$
+	        	}
 	        }
 		}
 	}
@@ -133,31 +167,11 @@
 		composite.setLayoutData(gd);
 		Dialog.applyDialogFont(composite);
 
-		Label descriptionLabel = new Label(composite,SWT.NONE);
-		descriptionLabel.setText(Messages.NewProjectExamplesWizardPage_Description);
-		gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
-		gd.horizontalSpan = 2;
-		descriptionLabel.setLayoutData(gd);
-		descriptionText = new Text(composite, SWT.H_SCROLL | SWT.V_SCROLL
-				| SWT.READ_ONLY | SWT.BORDER | SWT.WRAP);
-		gd = new GridData(SWT.FILL, SWT.FILL, false, false);
-		GC gc = new GC(parent);
-		gd.heightHint = Dialog.convertHeightInCharsToPixels(gc
-				.getFontMetrics(), 6);
-		gc.dispose();
-		gd.horizontalSpan = 2;
-		gd.widthHint = 250;
-		descriptionText.setLayoutData(gd);
+		//Set description
+		setDescriptionArea(composite);
 		
-		Label projectSizeLabel = new Label(composite,SWT.NULL);
-		projectSizeLabel.setText(Messages.NewProjectExamplesWizardPage_Project_size);
-		projectSize = new Text(composite,SWT.READ_ONLY);
-		projectSize.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-		
-		Label label = new Label(composite, SWT.NONE);
-		gd = new GridData(SWT.FILL, SWT.FILL, true, false);
-		gd.horizontalSpan = 2;
-		label.setLayoutData(gd);
+		//Set project size label or runtime/archetype selection
+		setSelectionArea(composite);
 				
 		Group fixesGroup = new Group(composite, SWT.NONE);
 		gd = new GridData(SWT.FILL, SWT.FILL, true, false);
@@ -569,6 +583,16 @@
 
 	}
 
+
+	public void setDescriptionText(String longDescription) {
+		if (descriptionText != null) {
+			if (longDescription == null) {
+				longDescription = "";
+			}
+			descriptionText.setText(longDescription);
+		}
+	}
+	
 	@Override
 	public IWizardPage getNextPage() {
 		// FIXME
@@ -625,8 +649,7 @@
 
 	@Override
 	public void setWizardContext(WizardContext context) {
-		// TODO Auto-generated method stub
-		
+		this.wizardContext = context;
 	}
 
 	@Override

Modified: trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard2.java
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard2.java	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard2.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -177,13 +177,9 @@
 		Set<String> keySet = extensionPages.keySet();
 		for (String key:keySet) {
 			List<ContributedPage> contributions = extensionPages.get(key);
-			boolean canSetProjectExample = isCentral && projectExample != null && key.equals(projectExample.getImportType());
 			for(ContributedPage page:contributions) {
 				try {
 					IProjectExamplesWizardPage contributedPage = (IProjectExamplesWizardPage) page.getConfigurationElement().createExecutableExtension(ProjectExamplesActivator.CLASS);
-					if (canSetProjectExample) {
-						contributedPage.setProjectExample(projectExample);
-					}
 					contributedPages.add(contributedPage);
 				} catch (CoreException e) {
 					ProjectExamplesActivator.log(e);
@@ -290,6 +286,10 @@
 			IProjectExamplesWizardPage ewp = (IProjectExamplesWizardPage)page;
 			ewp.setWizardContext(wizardContext);
 			wizardContext.addListener(ewp);
+			if (projectExample != null && ewp.getProjectExampleType().equals(projectExample.getImportType())) {
+				ewp.setProjectExample(projectExample);
+			}
+
 		}
 		super.addPage(page);
 	}

Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/.classpath
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/.classpath	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/.classpath	2012-09-18 15:19:51 UTC (rev 43798)
@@ -1,7 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+	<classpathentry exported="true" kind="lib" path="lib/commons-codec-1.3.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/commons-logging-1.1.1.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/httpclient-4.0.1.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/httpcore-4.0.1.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/jboss-logging-3.1.2.GA.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/snakeyaml-1.10.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/stacks-client-1.0.0.CR2.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
-	<classpathentry kind="src" path="src/"/>
+	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="output" path="target/classes"/>
 </classpath>

Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF	2012-09-18 15:19:51 UTC (rev 43798)
@@ -23,3 +23,11 @@
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Bundle-Vendor: %Bundle-Vendor
+Bundle-ClassPath: lib/stacks-client-1.0.0.CR2.jar,
+ lib/commons-codec-1.3.jar,
+ lib/commons-logging-1.1.1.jar,
+ lib/httpclient-4.0.1.jar,
+ lib/httpcore-4.0.1.jar,
+ lib/jboss-logging-3.1.2.GA.jar,
+ lib/snakeyaml-1.10.jar,
+ .

Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/build.properties
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/build.properties	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/build.properties	2012-09-18 15:19:51 UTC (rev 43798)
@@ -9,5 +9,11 @@
                about.mappings,\
                about.properties,\
                jboss_about.png,\
-               icons/
+               icons/,\
+               lib/commons-codec-1.3.jar,\
+               lib/commons-logging-1.1.1.jar,\
+               lib/httpclient-4.0.1.jar,\
+               lib/httpcore-4.0.1.jar,\
+               lib/jboss-logging-3.1.2.GA.jar,\
+               lib/snakeyaml-1.10.jar
 src.includes = src/

Added: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/commons-codec-1.3.jar
===================================================================
(Binary files differ)


Property changes on: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/commons-codec-1.3.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/commons-logging-1.1.1.jar
===================================================================
(Binary files differ)


Property changes on: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/commons-logging-1.1.1.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/httpclient-4.0.1.jar
===================================================================
(Binary files differ)


Property changes on: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/httpclient-4.0.1.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/httpcore-4.0.1.jar
===================================================================
(Binary files differ)


Property changes on: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/httpcore-4.0.1.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/jboss-logging-3.1.2.GA.jar
===================================================================
(Binary files differ)


Property changes on: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/jboss-logging-3.1.2.GA.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/snakeyaml-1.10.jar
===================================================================
(Binary files differ)


Property changes on: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/snakeyaml-1.10.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/stacks-client-1.0.0.CR2.jar
===================================================================
(Binary files differ)


Property changes on: trunk/maven/plugins/org.jboss.tools.maven.project.examples/lib/stacks-client-1.0.0.CR2.jar
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksManager.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksManager.java	                        (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksManager.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -0,0 +1,55 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.project.examples.stacks;
+import static org.jboss.tools.project.examples.model.ProjectExampleUtil.getProjectExamplesFile;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.jdf.stacks.model.Stacks;
+import org.jboss.jdf.stacks.parser.Parser;
+
+
+public class StacksManager {
+
+	private static final String STACKS_URL;
+	
+	static {
+		String defaultUrl = "http://raw.github.com/jboss-jdf/jdf-stack/1.0.0.CR1/stacks.yaml"; //$NON-NLS-1$
+		STACKS_URL = System.getProperty("org.jboss.examples.stacks.url", defaultUrl); //$NON-NLS-1$
+	}
+	
+	public Stacks getStacks(IProgressMonitor monitor) throws MalformedURLException {
+		Stacks stacks = null;
+		File f = getProjectExamplesFile(new URL(STACKS_URL), "stacks", "yaml", monitor); //$NON-NLS-1$ //$NON-NLS-2$
+		if (f != null && f.exists()) {
+			FileInputStream fis = null;
+			try {
+				fis = new FileInputStream(f);
+				Parser p  = new Parser();
+				stacks =  p.parse(fis);
+			} catch (Exception e) {
+				e.printStackTrace();
+			} finally {
+				try {
+					fis.close();
+				} catch(Exception e) {
+					//ignore
+				}
+			}
+		}
+		return stacks;
+		
+	}
+}

Added: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksUtil.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksUtil.java	                        (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/stacks/StacksUtil.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -0,0 +1,184 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.maven.project.examples.stacks;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.jboss.jdf.stacks.model.Archetype;
+import org.jboss.jdf.stacks.model.ArchetypeVersion;
+import org.jboss.jdf.stacks.model.Runtime;
+import org.jboss.jdf.stacks.model.Stacks;
+import org.jboss.tools.project.examples.model.ArchetypeModel;
+
+public class StacksUtil {
+	/*
+	public static final String EAP_TYPE = "EAP";
+
+	public static final String AS_TYPE = "AS";
+	*/
+	private StacksUtil() {
+		// no need for public constructor
+	}
+
+	public static Archetype getArchetype(String archetypeId, Stacks fromStacks) {
+		if (fromStacks == null || archetypeId == null) {
+			return null;
+		}
+
+		for (Archetype a : fromStacks.getAvailableArchetypes()) {
+			if (archetypeId.equals(a.getArtifactId())) {
+				return a;
+			}
+		}
+
+		return null;
+	}
+	
+	public static List<Runtime> getCompatibleRuntimes(Archetype archetype, Stacks fromStacks, String ... runtimeTypes) {
+		if (fromStacks == null || archetype == null) {
+			return Collections.emptyList();
+		}
+
+		List<Runtime> runtimes = new ArrayList<Runtime>();
+		
+		for (Runtime runtime : getRuntimes(fromStacks, runtimeTypes)) {
+			List<ArchetypeVersion> versions = getCompatibleArchetypeVersions(archetype, runtime); 
+			if (!versions.isEmpty()) {
+				runtimes.add(runtime);
+			}
+		}
+		return Collections.unmodifiableList(runtimes);
+	}
+
+	public static List<Runtime> getRuntimes(Stacks fromStacks, String ... runtimeTypes) {
+		if (fromStacks == null) {
+			return Collections.emptyList();
+		}
+		
+		List<Runtime> runtimes = new ArrayList<Runtime>();
+		List<String> runtimeTypeFilter = null;
+		if (runtimeTypes != null && runtimeTypes.length > 0) {
+			runtimeTypeFilter = Arrays.asList(runtimeTypes);
+		}
+		
+		for (Runtime runtime : fromStacks.getAvailableRuntimes()) {
+			
+			if (runtimeTypeFilter != null) {
+				String runtimeType = getRuntimeType(runtime);
+				if (!runtimeTypeFilter.contains(runtimeType)) {
+					continue;
+				}
+			}
+			runtimes.add(runtime);
+		}
+		return Collections.unmodifiableList(runtimes);
+	}
+
+
+	/*
+	public static List<Runtime> getCompatibleRuntimes(Archetype archetype, Stacks fromStacks) {
+		return getCompatibleRuntimes(archetype, fromStacks, AS_TYPE, EAP_TYPE);
+	}
+	*/
+
+	/**
+	 * Returns an unmodifiable {@link List} of compatible {@link ArchetypeVersion} of an {@link Archetype} for a given {@link Runtime}. 
+	 * The recommended {@link ArchetypeVersion} is always first in the list. 
+	 * @param archetype
+	 * @param runtime
+	 * @return a non-null {@link List} of compatible {@link ArchetypeVersion}.  
+	 */
+	public static List<ArchetypeVersion> getCompatibleArchetypeVersions(Archetype archetype, Runtime runtime) {
+		if (archetype == null || runtime == null) {
+			return Collections.emptyList();
+		}
+
+		List<ArchetypeVersion> compatibleVersions = new ArrayList<ArchetypeVersion>(); 
+		List<ArchetypeVersion> versions = runtime.getArchetypes();
+		if (versions != null && !versions.isEmpty()) {
+			String bestVersion = archetype.getRecommendedVersion(); 
+			for (ArchetypeVersion v : versions) {
+				if (archetype.equals(v.getArchetype())) {
+					if (v.getVersion().equals(bestVersion)) {
+						//Put best version on top
+						compatibleVersions.add(0, v);
+					}
+					else {
+						compatibleVersions.add(v);
+					}
+				}
+			}
+		}
+		return Collections.unmodifiableList(compatibleVersions);
+	}
+
+	public static boolean isRuntimeCompatible(ArchetypeVersion archetypeVersion, Runtime runtime) {
+		if (archetypeVersion == null || runtime == null) {
+			return false;
+		}
+
+		List<ArchetypeVersion> versions = runtime.getArchetypes();
+		return versions != null && versions.contains(archetypeVersion);
+	}
+
+	/*
+	public static boolean isEnterprise(Runtime runtime) {
+		return EAP_TYPE.equals(getRuntimeType(runtime)); 
+	}
+	*/
+
+	public static String getRuntimeType(Runtime runtime) {
+		if (runtime == null) {
+			return null;
+		}
+		
+		Properties p = runtime.getLabels();
+		return (String)p.get("runtimeType"); 
+	}
+
+	public static ArchetypeModel createArchetypeModel(ArchetypeModel archetypeModel, ArchetypeVersion archetypeVersion) throws CloneNotSupportedException {
+		ArchetypeModel a = (ArchetypeModel) archetypeModel.clone(); 
+		a.setArchetypeArtifactId(archetypeVersion.getArchetype().getArtifactId());
+		a.setArchetypeGroupId(archetypeVersion.getArchetype().getGroupId());
+		a.setArchetypeVersion(archetypeVersion.getVersion());
+		return a;
+	}
+
+	public static ArchetypeVersion getDefaultArchetypeVersion(String archetypeId, Stacks fromStacks) {
+		if (fromStacks == null || archetypeId == null) {
+			return null;
+		}
+
+		Archetype targetArchetype = getArchetype(archetypeId, fromStacks);
+		return getDefaultArchetypeVersion(targetArchetype, fromStacks);
+	}
+
+	public static ArchetypeVersion getDefaultArchetypeVersion(Archetype archetype, Stacks fromStacks) {
+		if (fromStacks == null || archetype == null) {
+			return null;
+		}
+
+		List<ArchetypeVersion>  versions = fromStacks.getAvailableArchetypeVersions(); 
+		for (ArchetypeVersion version : versions) {
+			if (archetype.equals(version.getArchetype())
+			&& version.getVersion().equals(archetype.getRecommendedVersion())) {
+				return version;
+			}
+		}
+		return (versions.isEmpty())?null:versions.get(0);
+	}
+
+	
+}
\ No newline at end of file

Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -62,6 +62,7 @@
 import org.jboss.tools.maven.project.examples.Messages;
 import org.jboss.tools.maven.project.examples.utils.MavenArtifactHelper;
 import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.ArchetypeModel;
 import org.jboss.tools.project.examples.model.ProjectExample;
 import org.jboss.tools.project.examples.wizard.IProjectExamplesWizardPage;
 import org.jboss.tools.project.examples.wizard.NewProjectExamplesWizard2;
@@ -93,6 +94,7 @@
 	private IRuntimeLifecycleListener listener;
 	private Button isWorkspace;
 	private Combo outputDirectoryCombo;
+	private ArchetypeModel archetypeModel;
 	
 	public ArchetypeExamplesWizardFirstPage() {
 		super(new ProjectImportConfiguration(), "", "",new ArrayList<IWorkingSet>());
@@ -183,8 +185,8 @@
 
 		
 		/*
-		projectNameCombo.setText(projectDescription.getArchetypeModel().getArtifactId());
-		packageCombo.setText(projectDescription.getArchetypeModel().getJavaPackage());
+		projectNameCombo.setText(archetypeModel.getArtifactId());
+		packageCombo.setText(archetypeModel.getJavaPackage());
 		*/
 	}
 	
@@ -361,22 +363,23 @@
 			return;
 		}
 		projectDescription = projectExample;
-		String projectName = projectDescription.getArchetypeModel().getArtifactId();
-		if (StringUtils.isNotBlank(projectName)) {
-			IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
-			if (!p.exists()) {
-				projectNameCombo.setText(projectName);
+		if (archetypeModel != null) {
+			String projectName = archetypeModel.getArtifactId();
+			if (StringUtils.isNotBlank(projectName)) {
+				IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+				if (!p.exists()) {
+					projectNameCombo.setText(projectName);
+				}
 			}
+			
+			String packageName = archetypeModel.getJavaPackage();
+			if (StringUtils.isBlank(packageName) && packageCombo.getItemCount() > 0) {
+				packageName = packageCombo.getItem(0);
+			}
+			if (packageName != null) {
+				packageCombo.setText(packageName);
+			}
 		}
-		
-		String packageName = projectDescription.getArchetypeModel().getJavaPackage();
-		if (StringUtils.isBlank(packageName) && packageCombo.getItemCount() > 0) {
-			packageName = packageCombo.getItem(0);
-		}
-		if (packageName != null) {
-			packageCombo.setText(packageName);
-		}
-		
 		//Force setting of enterprise value
 		context.setProperty(MavenProjectConstants.ENTERPRISE_TARGET, isEnterpriseTargetRuntime());
 
@@ -513,6 +516,7 @@
 			if (projectExample.getDescription() != null) {
 				setDescription(ProjectExamplesActivator.getShortDescription(projectExample.getDescription()));
 			}
+			archetypeModel = projectExample.getArchetypeModel();
 			initDefaultValues();
 		} 
 	}

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	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -77,6 +77,8 @@
 	private MissingRepositoryWarningComponent warningComponent;
 	private IStatus enterpriseRepoStatus;
 
+	private ArchetypeModel archetypeModel;
+	
 	public ArchetypeExamplesWizardPage() {
 		super(new ProjectImportConfiguration());
 	}
@@ -103,14 +105,17 @@
 		});
 		
 		if (projectExample != null && !initialized) {
-			initialize();
+			initializeArchetype();
 		}
 		
 	}
 
-	protected void initialize() {
+	protected void initializeArchetype() {
+		if (getContainer() == null || archetypeModel == null) {
+			return;
+		}
+		//System.err.println("Initializing archetype data "+ archetypeModel.getArchetypeArtifactId() + " "+archetypeModel.getArchetypeVersion());
 		Archetype archetype = new Archetype();
-		ArchetypeModel archetypeModel = projectDescription.getArchetypeModel();
 
 		archetype.setGroupId(archetypeModel.getArchetypeGroupId());
 		archetype.setArtifactId(archetypeModel.getArchetypeArtifactId());
@@ -141,7 +146,9 @@
 		// when setVisible() is called in MavenProjectWizardArchetypeParametersPage.
 		// It needs to be called AFTER setArchetype(archetype) !!! 
 		archetypeChanged = false;
-		resolverConfigurationComponent.setExpanded(!resolverConfigurationComponent.getResolverConfiguration().getActiveProfileList().isEmpty());
+		if (resolverConfigurationComponent != null) {
+			resolverConfigurationComponent.setExpanded(!resolverConfigurationComponent.getResolverConfiguration().getActiveProfileList().isEmpty());
+		}
 		initialized = true;
 	}
 
@@ -452,9 +459,8 @@
 			    }
 			}
 			projectDescription = projectExample;
-			if (getContainer() != null) {
-				initialize();
-			}
+			archetypeModel  = projectDescription.getArchetypeModel();
+			initializeArchetype();
 		}
 	}
 	
@@ -475,6 +481,11 @@
 			//Make sure it's a boolean :
 			Boolean enterprise = Boolean.parseBoolean(value.toString());
 			updateArchetypeProperty("enterprise", enterprise.toString());
+		} else if (MavenProjectConstants.ARCHETYPE_MODEL.equals(key)) {
+			if (value instanceof ArchetypeModel) {
+				archetypeModel = (ArchetypeModel)value;
+				initializeArchetype();
+			}
 		}
 	}
 

Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/MavenProjectConstants.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/MavenProjectConstants.java	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/MavenProjectConstants.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -12,6 +12,8 @@
 
 	public static final String MAVEN_MODEL = "mavenModel";
 	
+	public static final String ARCHETYPE_MODEL = "archetypeModel";
+	
 	private MavenProjectConstants(){
 	}
 }

Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/NewProjectExamplesStacksRequirementsPage.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/NewProjectExamplesStacksRequirementsPage.java	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/NewProjectExamplesStacksRequirementsPage.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -10,6 +10,23 @@
  ************************************************************************************/
 package org.jboss.tools.maven.project.examples.wizard;
 
+import static org.jboss.tools.maven.project.examples.stacks.StacksUtil.createArchetypeModel;
+import static org.jboss.tools.maven.project.examples.stacks.StacksUtil.getArchetype;
+
+import java.net.MalformedURLException;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.jdf.stacks.model.ArchetypeVersion;
+import org.jboss.jdf.stacks.model.Stacks;
+import org.jboss.tools.maven.project.examples.stacks.StacksManager;
+import org.jboss.tools.maven.project.examples.stacks.StacksUtil;
+import org.jboss.tools.project.examples.model.ArchetypeModel;
 import org.jboss.tools.project.examples.model.ProjectExample;
 import org.jboss.tools.project.examples.wizard.NewProjectExamplesRequirementsPage;
 
@@ -17,8 +34,21 @@
 
 	private static final String PAGE_NAME = "org.jboss.tools.project.examples.stacksrequirements"; //$NON-NLS-1$
 
+	org.jboss.jdf.stacks.model.Archetype stacksArchetype;   
+
+	private ArchetypeVersion version;
+	
+	private Button useBlankArchetype;
+
+	private Stacks stacks;
+	
 	public NewProjectExamplesStacksRequirementsPage() {
 		this(null);
+		try {
+			stacks = new StacksManager().getStacks(new NullProgressMonitor());
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		}
 	}
 	
 	public NewProjectExamplesStacksRequirementsPage(ProjectExample projectExample) {
@@ -29,5 +59,88 @@
 	public String getProjectExampleType() {
 		return "mavenArchetype";
 	}
+	
+	@Override
+	protected void setDescriptionArea(Composite composite) {
+		super.setDescriptionArea(composite);
+	}
+	
+	@Override
+	public void setProjectExample(ProjectExample projectExample) {
+		super.setProjectExample(projectExample);
+		if (projectExample != null) {
+			String stacksId = projectExample.getStacksId();
+			stacksArchetype = getArchetype(stacksId, stacks);
+			setArchetypeVersion();
+		}
+	}
 
+	private void setArchetypeVersion() {
+		if (stacksArchetype == null) {
+			return;
+		}
+		
+		org.jboss.jdf.stacks.model.Archetype a;
+		
+		if (useBlankArchetype != null && useBlankArchetype.getSelection()) {
+			a = stacksArchetype.getBlank();
+		} else {
+			a = stacksArchetype;
+		}
+		version = StacksUtil.getDefaultArchetypeVersion(a, stacks);
+
+		
+		StringBuilder description = new StringBuilder(version.getArchetype().getDescription());
+		description.append("\r\n").append("\r\n")
+		           .append("Project based on the ")
+		           .append(version.getArchetype().getGroupId())
+		           .append(":")
+		           .append(version.getArchetype().getArtifactId())
+		           .append(":")
+		           .append(version.getVersion())
+		           .append(" Maven archetype");
+		
+		setDescriptionText(description.toString());
+		
+		ArchetypeModel mavenArchetype;
+		try {
+			mavenArchetype = createArchetypeModel(projectExample.getArchetypeModel(), version);
+			
+			wizardContext.setProperty(MavenProjectConstants.ARCHETYPE_MODEL, mavenArchetype);
+		} catch (CloneNotSupportedException e) {
+			e.printStackTrace();
+		}
+		
+	}
+
+	@Override
+	protected void setSelectionArea(Composite composite) {
+		useBlankArchetype = new Button(composite, SWT.CHECK);
+		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+		gd.verticalAlignment = SWT.BOTTOM;
+		useBlankArchetype.setLayoutData(gd);
+		useBlankArchetype.setText("Create an empty project");
+		useBlankArchetype.addSelectionListener(new SelectionListener() {
+			
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				setArchetypeVersion();
+			}
+			
+			@Override
+			public void widgetDefaultSelected(SelectionEvent e) {
+				widgetSelected(e);
+			}
+		});
+	}
+	
+	@Override
+	public void setVisible(boolean visible) {
+		if (visible) {
+			useBlankArchetype.setVisible(stacksArchetype != null 
+					&& stacksArchetype.getBlank() != null );	
+		}
+		super.setVisible(visible);
+	}
+	
 }

Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/xpl/MavenProjectWizardArchetypeParametersPage.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/xpl/MavenProjectWizardArchetypeParametersPage.java	2012-09-18 15:14:33 UTC (rev 43797)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/xpl/MavenProjectWizardArchetypeParametersPage.java	2012-09-18 15:19:51 UTC (rev 43798)
@@ -45,7 +45,6 @@
 import org.eclipse.m2e.core.embedder.IMaven;
 import org.eclipse.m2e.core.internal.MavenPluginActivator;
 import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory.RemoteCatalogFactory;
-import org.eclipse.m2e.core.internal.archetype.ArchetypeManager;
 import org.eclipse.m2e.core.project.ProjectImportConfiguration;
 import org.eclipse.m2e.core.ui.internal.Messages;
 import org.eclipse.m2e.core.ui.internal.components.TextComboBoxCellEditor;
@@ -368,23 +367,26 @@
 
   public void setArchetype(Archetype archetype) {
     if(archetype == null) {
-      propertiesTable.removeAll();
+      if (propertiesTable != null)
+    	  propertiesTable.removeAll();
       archetypeChanged = false;
     } else if(!archetype.equals(this.archetype)) {
       this.archetype = archetype;
-      propertiesTable.removeAll();
       requiredProperties.clear();
       optionalProperties.clear();
       archetypeChanged = true;
 
-      Properties properties = archetype.getProperties();
-      if(properties != null) {
-        for(Iterator<Map.Entry<Object, Object>> it = properties.entrySet().iterator(); it.hasNext();) {
-          Map.Entry<?, ?> e = it.next();
-          String key = (String) e.getKey();
-          addTableItem(key, (String) e.getValue());
-          optionalProperties.add(key);
-        }
+      if (propertiesTable != null) {
+    	  propertiesTable.removeAll();
+    	  Properties properties = archetype.getProperties();
+    	  if(properties != null) {
+    		  for(Iterator<Map.Entry<Object, Object>> it = properties.entrySet().iterator(); it.hasNext();) {
+    			  Map.Entry<?, ?> e = it.next();
+    			  String key = (String) e.getKey();
+    			  addTableItem(key, (String) e.getValue());
+    			  optionalProperties.add(key);
+    		  }
+    	  }
       }
     }
   }



More information about the jbosstools-commits mailing list