Author: snjeza
Date: 2011-02-18 08:22:38 -0500 (Fri, 18 Feb 2011)
New Revision: 29238
Added:
trunk/download.jboss.org/jbosstools/examples/project-examples-maven-3.3.xml
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/job/
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/job/ProjectExamplesJob.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ArchetypeModel.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/
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
Modified:
trunk/examples/plugins/org.jboss.tools.community.project.examples/plugin.properties
trunk/examples/plugins/org.jboss.tools.community.project.examples/plugin.xml
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.project.examples/plugin.xml
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/MavenProjectExamplesActivator.java
Log:
JBIDE-7890 Create project example based on maven archetype
Added:
trunk/download.jboss.org/jbosstools/examples/project-examples-maven-3.3.xml
===================================================================
---
trunk/download.jboss.org/jbosstools/examples/project-examples-maven-3.3.xml
(rev 0)
+++
trunk/download.jboss.org/jbosstools/examples/project-examples-maven-3.3.xml 2011-02-18
13:22:38 UTC (rev 29238)
@@ -0,0 +1,39 @@
+<projects>
+
+ <project>
+ <category>Weld archetypes</category>
+ <name>jboss-javaee6-webapp</name>
+ <included-projects>jboss-javaee6-webapp</included-projects>
+ <shortDescription>Weld Java EE 6 example</shortDescription>
+ <description>
+The example demonstrates Weld Java EE 6 application.
+It will create the jboss-javaee6-webapp project in your workspace based on the
org.jboss.weld.archetypes:jboss-javaee6-webapp:1.0.1.Beta2 archetype.
+ </description>
+ <size>8192</size>
+ <url/>
+ <fixes>
+ <fix type="wtpruntime">
+ <property
name="allowed-types">org.jboss.ide.eclipse.as.runtime.60</property>
+ <property name="description">This project example requires JBoss AS
6.0</property>
+ </fix>
+ </fixes>
+ <importType>mavenArchetype</importType>
+ <importTypeDescription>The project example requires the m2eclipse-core,
m2eclipse-wtp and JBoss Maven Project Examples feature.</importTypeDescription>
+ <mavenArchetype>
+ <archetypeGroupId>org.jboss.weld.archetypes</archetypeGroupId>
+ <archetypeArtifactId>jboss-javaee6-webapp</archetypeArtifactId>
+ <archetypeVersion>1.0.1.Beta2</archetypeVersion>
+ <!--
<
archetypeRepository>http://repository.jboss.org/nexus/content/groups/p...
-->
+ <groupId>org.jboss.tools.examples</groupId>
+ <artifactId>jboss-javaee6-webapp</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <javaPackage>org.jboss.tools.examples</javaPackage>
+ <!--
+ <properties>
+ <property name="name" value="Java EE 6 webapp project"/>
+ </properties>
+ -->
+ </mavenArchetype>
+ </project>
+
+</projects>
\ No newline at end of file
Modified:
trunk/examples/plugins/org.jboss.tools.community.project.examples/plugin.properties
===================================================================
---
trunk/examples/plugins/org.jboss.tools.community.project.examples/plugin.properties 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/examples/plugins/org.jboss.tools.community.project.examples/plugin.properties 2011-02-18
13:22:38 UTC (rev 29238)
@@ -2,4 +2,5 @@
BundleName = JBoss Tools Community Project Examples
JBoss_Tools_Community_Examples = JBoss Tools 3.1 Community Examples
JBoss_Tools_Community_Maven_Examples = JBoss Tools 3.2 Community Maven Examples
+JBoss_Tools_33_Community_Maven_Examples = JBoss Tools 3.3 Community Maven Examples
JBoss_Tools_Community_BPEL_Examples=JBoss Tools Community BPEL Examples
Modified: trunk/examples/plugins/org.jboss.tools.community.project.examples/plugin.xml
===================================================================
---
trunk/examples/plugins/org.jboss.tools.community.project.examples/plugin.xml 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/examples/plugins/org.jboss.tools.community.project.examples/plugin.xml 2011-02-18
13:22:38 UTC (rev 29238)
@@ -23,5 +23,11 @@
name="%JBoss_Tools_Community_Maven_Examples">
<
url>http://download.jboss.org/jbosstools/examples/project-examples-mav...
<experimental>false</experimental>
- </extension>
+ </extension>
+ <extension
+ point="org.jboss.tools.project.examples.projectExamplesXml"
+ name="%JBoss_Tools_33_Community_Maven_Examples">
+
<
url>http://download.jboss.org/jbosstools/examples/project-examples-mav...
+ <experimental>false</experimental>
+ </extension>
</plugin>
Modified: trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2011-02-18
13:22:38 UTC (rev 29238)
@@ -39,6 +39,9 @@
org.jboss.tools.project.examples.dialog,
org.jboss.tools.project.examples.dialog.xpl,
org.jboss.tools.project.examples.filetransfer,
+ org.jboss.tools.project.examples.fixes,
+ org.jboss.tools.project.examples.job,
org.jboss.tools.project.examples.model,
+ org.jboss.tools.project.examples.preferences,
org.jboss.tools.project.examples.wizard
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -54,6 +54,9 @@
public static final boolean SHOW_EXPERIMENTAL_SITES_VALUE = false;
public static final String SHOW_INVALID_SITES = "invalidSites"; //$NON-NLS-1$
public static final boolean SHOW_INVALID_SITES_VALUE = true;
+ public static final String MAVEN_ARCHETYPE = "mavenArchetype"; //$NON-NLS-1$
+ public static final Object PROJECT_EXAMPLES_FAMILY = new Object();
+
private static final String IMPORT_PROJECT_EXAMPLES_EXTENSION_ID =
"org.jboss.tools.project.examples.importProjectExamples"; //$NON-NLS-1$
private static final String NAME = "name"; //$NON-NLS-1$
private static final String TYPE = "type"; //$NON-NLS-1$
@@ -68,6 +71,7 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
+ Job.getJobManager().join(PROJECT_EXAMPLES_FAMILY, monitor);
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD,
monitor);
Job.getJobManager().join(
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/job/ProjectExamplesJob.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/job/ProjectExamplesJob.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/job/ProjectExamplesJob.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -0,0 +1,20 @@
+package org.jboss.tools.project.examples.job;
+
+import org.eclipse.core.resources.WorkspaceJob;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+
+public abstract class ProjectExamplesJob extends WorkspaceJob {
+
+ public ProjectExamplesJob(String name) {
+ super(name);
+ }
+
+ @Override
+ public boolean belongsTo(Object family) {
+ if (family == ProjectExamplesActivator.PROJECT_EXAMPLES_FAMILY)
+ return true;
+
+ return super.belongsTo(family);
+ }
+
+}
Added:
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
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ArchetypeModel.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -0,0 +1,102 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 JBoss by Red Hat 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.project.examples.model;
+
+import java.util.Properties;
+
+/**
+ * @author snjeza
+ *
+ */
+public class ArchetypeModel {
+ private String groupId;
+ private String artifactId;
+ private String version;
+
+ private String archetypeGroupId;
+ private String archetypeArtifactId;
+ private String archetypeVersion;
+ private String archetypeRepository;
+ private String javaPackage;
+ private Properties archetypeProperties = new Properties();
+
+ public String getGroupId() {
+ return groupId;
+ }
+
+ public void setGroupId(String groupId) {
+ this.groupId = groupId;
+ }
+
+ public String getArtifactId() {
+ return artifactId;
+ }
+
+ public void setArtifactId(String artifactId) {
+ this.artifactId = artifactId;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getArchetypeGroupId() {
+ return archetypeGroupId;
+ }
+
+ public void setArchetypeGroupId(String archetypeGroupId) {
+ this.archetypeGroupId = archetypeGroupId;
+ }
+
+ public String getArchetypeArtifactId() {
+ return archetypeArtifactId;
+ }
+
+ public void setArchetypeArtifactId(String archetypeArtifactId) {
+ this.archetypeArtifactId = archetypeArtifactId;
+ }
+
+ public String getArchetypeVersion() {
+ return archetypeVersion;
+ }
+
+ public void setArchetypeVersion(String archetypeVersion) {
+ this.archetypeVersion = archetypeVersion;
+ }
+
+ public String getArchetypeRepository() {
+ return archetypeRepository;
+ }
+
+ public void setArchetypeRepository(String archetypeRepository) {
+ this.archetypeRepository = archetypeRepository;
+ }
+
+ public String getJavaPackage() {
+ return javaPackage;
+ }
+
+ public void setJavaPackage(String javaPackage) {
+ this.javaPackage = javaPackage;
+ }
+
+ public Properties getArchetypeProperties() {
+ return archetypeProperties;
+ }
+
+ public void addProperty(String key, String value) {
+ archetypeProperties.put(key, value);
+ }
+}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -14,6 +14,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+
/**
* @author snjeza
*
@@ -36,6 +38,7 @@
private String perspectiveId;
private String importType;
private String importTypeDescription;
+ private ArchetypeModel archetypeModel = new ArchetypeModel();
public Project() {
name=""; //$NON-NLS-1$
@@ -199,4 +202,12 @@
public void setImportTypeDescription(String importTypeDescription) {
this.importTypeDescription = importTypeDescription;
}
+
+ public ArchetypeModel getArchetypeModel() {
+ return archetypeModel;
+ }
+
+ public boolean isURLRequired() {
+ return !ProjectExamplesActivator.MAVEN_ARCHETYPE.equals(importType);
+ }
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -338,6 +338,9 @@
project.setWelcomeURL(attribute.trim());
}
}
+ if (nodeName.equals("mavenArchetype")) { //$NON-NLS-1$
+ parseMavenArchetype(project, child);
+ }
}
}
}
@@ -367,11 +370,76 @@
Element child = (Element) cNode;
String nodeName = child.getNodeName();
if (nodeName.equals("fix")) { //$NON-NLS-1$
- parseFix(project,child);
+ parseFix(project, child);
}
}
}
}
+
+ private static void parseMavenArchetype(Project project, Element node) {
+ NodeList children = node.getChildNodes();
+ int cLen = children.getLength();
+ ArchetypeModel archetypeModel = project.getArchetypeModel();
+ for (int i = 0; i < cLen; i++) {
+ Node cNode = children.item(i);
+ if (cNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element child = (Element) cNode;
+ String nodeName = child.getNodeName();
+ if (nodeName.equals("archetypeGroupId")) { //$NON-NLS-1$
+ archetypeModel.setArchetypeGroupId(getContent(child));
+ }
+ if (nodeName.equals("archetypeArtifactId")) { //$NON-NLS-1$
+ archetypeModel.setArchetypeArtifactId(getContent(child));
+ }
+ if (nodeName.equals("archetypeVersion")) { //$NON-NLS-1$
+ archetypeModel.setArchetypeVersion(getContent(child));
+ }
+ if (nodeName.equals("archetypeRepository")) { //$NON-NLS-1$
+ archetypeModel.setArchetypeRepository(getContent(child));
+ }
+ if (nodeName.equals("groupId")) { //$NON-NLS-1$
+ archetypeModel.setGroupId(getContent(child));
+ }
+ if (nodeName.equals("artifactId")) { //$NON-NLS-1$
+ archetypeModel.setArtifactId(getContent(child));
+ }
+ if (nodeName.equals("version")) { //$NON-NLS-1$
+ archetypeModel.setVersion(getContent(child));
+ }
+ if (nodeName.equals("javaPackage")) { //$NON-NLS-1$
+ archetypeModel.setJavaPackage(getContent(child));
+ }
+ if (nodeName.equals("properties")) { //$NON-NLS-1$
+ parseProperties(project, child);
+ }
+ }
+ }
+ }
+
+ private static void parseProperties(Project project, Element node) {
+ NodeList children = node.getChildNodes();
+ int cLen = children.getLength();
+ for (int i = 0; i < cLen; i++) {
+ Node cNode = children.item(i);
+ if (cNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element child = (Element) cNode;
+ String nodeName = child.getNodeName();
+ if (nodeName.equals("property")) { //$NON-NLS-1$
+ String key = child.getAttribute("name"); //$NON-NLS-1$
+ if (key == null || key.trim().length() <= 0) {
+ ProjectExamplesActivator.log(Messages.ProjectUtil_Invalid_property);
+ return;
+ }
+ String value = child.getAttribute("value"); //$NON-NLS-1$
+ if (value == null || value.trim().length() <= 0) {
+ ProjectExamplesActivator.log(Messages.ProjectUtil_Invalid_property);
+ return;
+ }
+ project.getArchetypeModel().addProperty(key, value);
+ }
+ }
+ }
+ }
private static void parseFix(Project project, Element node) {
String type = node.getAttribute("type"); //$NON-NLS-1$
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizard.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -155,24 +155,27 @@
Iterator iterator = selection.iterator();
projects.clear();
List<File> files = new ArrayList<File>();
+ File file = null;
while (iterator.hasNext()) {
Object object = iterator.next();
if (object instanceof Project) {
Project project = (Project) object;
- String urlString = project.getUrl();
- String name = project.getName();
- URL url = null;
- try {
- url = new URL(urlString);
- } catch (MalformedURLException e) {
- ProjectExamplesActivator.log(e);
- continue;
+ if (project.isURLRequired()) {
+ String urlString = project.getUrl();
+ String name = project.getName();
+ URL url = null;
+ try {
+ url = new URL(urlString);
+ } catch (MalformedURLException e) {
+ ProjectExamplesActivator.log(e);
+ continue;
+ }
+ file = ProjectUtil.getProjectExamplesFile(url, name,
+ ".zip", monitor); //$NON-NLS-1$
+ if (file == null) {
+ return Status.CANCEL_STATUS;
+ }
}
- final File file = ProjectUtil.getProjectExamplesFile(
- url, name, ".zip", monitor); //$NON-NLS-1$
- if (file == null) {
- return Status.CANCEL_STATUS;
- }
projects.add(project);
files.add(file);
}
@@ -199,7 +202,7 @@
});
return Status.OK_STATUS;
}
- projects = importProjectExample.importProject(project, files.get(i++), monitor);
+ importProjectExample.importProject(project, files.get(i++), monitor);
importProjectExample.fix(project, monitor);
}
}
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 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF 2011-02-18
13:22:38 UTC (rev 29238)
@@ -9,7 +9,8 @@
org.eclipse.core.runtime,
org.jboss.tools.maven.core,
org.jboss.tools.project.examples,
- org.eclipse.ui.ide
+ org.eclipse.ui.ide,
+ org.maven.ide.eclipse.archetype_common;bundle-version="[0.10.0,0.13.0)"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: %Bundle-Vendor
Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/plugin.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/plugin.xml 2011-02-18
12:25:09 UTC (rev 29237)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/plugin.xml 2011-02-18
13:22:38 UTC (rev 29238)
@@ -9,5 +9,14 @@
type="maven">
</importProjectExample>
</extension>
+
+ <extension
+ point="org.jboss.tools.project.examples.importProjectExamples">
+ <importProjectExample
+
class="org.jboss.tools.maven.project.examples.ImportMavenArchetypeProjectExample"
+ name="Import Maven Archetype Project Examples"
+ type="mavenArchetype">
+ </importProjectExample>
+ </extension>
</plugin>
Added:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -0,0 +1,190 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 JBoss by Red Hat 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;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.maven.project.examples.wizard.ArchetypeExamplesWizard;
+import org.jboss.tools.project.examples.model.AbstractImportProjectExample;
+import org.jboss.tools.project.examples.model.Project;
+
+/**
+ * @author snjeza
+ *
+ */
+public class ImportMavenArchetypeProjectExample extends
+ AbstractImportProjectExample {
+
+ private static final String UNNAMED_PROJECTS = "UnnamedProjects";
//$NON-NLS-1$
+
+ private static final String JBOSS_TOOLS_MAVEN_PROJECTS =
"/.JBossToolsMavenProjects"; //$NON-NLS-1$
+
+ private boolean confirm;
+
+ @Override
+ public List<Project> importProject(final Project projectDescription, File file,
+ IProgressMonitor monitor) throws Exception {
+ List<Project> projects = new ArrayList<Project>();
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IPath rootPath = workspaceRoot.getLocation();
+ IPath mavenProjectsRoot = rootPath.append(JBOSS_TOOLS_MAVEN_PROJECTS);
+ String projectName = projectDescription.getName();
+ if (projectName == null || projectName.isEmpty()) {
+ projectName = UNNAMED_PROJECTS;
+ }
+ IPath path = mavenProjectsRoot.append(projectName);
+ final File destination = new File(path.toOSString());
+ if (destination.exists()) {
+ final List<IProject> existingProjects = getExistingProjects(destination);
+ if (existingProjects.size() > 0) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ String title = "Overwrite";
+ String msg = getMessage(destination, existingProjects);
+ confirm = MessageDialog.openQuestion(getActiveShell(),
+ title, msg);
+ }
+ });
+ if (confirm) {
+ monitor.setTaskName("Deleting ...");
+ for (IProject project : existingProjects) {
+ monitor.setTaskName("Deleting " + project.getName());
+ project.delete(false, true, monitor);
+ }
+ } else {
+ return projects;
+ }
+ }
+ boolean deleted = deleteDirectory(destination, monitor);
+ if (monitor.isCanceled()) {
+ return projects;
+ }
+ if (!deleted) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ MessageDialog.openError(getActiveShell(), "Error",
+ "Cannot delete the '" + destination + "' file.");
+ }
+ });
+ return projects;
+ }
+ }
+ monitor.setTaskName("");
+ if (monitor.isCanceled()) {
+ return projects;
+ }
+
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ ArchetypeExamplesWizard wizard = new ArchetypeExamplesWizard(destination,
projectDescription);
+ WizardDialog wizardDialog = new WizardDialog(getActiveShell(), wizard);
+ wizardDialog.open();
+ }
+
+ });
+ return projects;
+ }
+
+
+ private static Shell getActiveShell() {
+ return Display.getDefault().getActiveShell();
+ }
+
+ private static boolean deleteDirectory(File path, IProgressMonitor monitor) {
+ if (path.exists()) {
+ File[] files = path.listFiles();
+ for (File file : files) {
+ if (monitor.isCanceled()) {
+ return false;
+ }
+ monitor.setTaskName("Deleting " + file);
+ if (file.isDirectory()) {
+ deleteDirectory(file, monitor);
+ } else {
+ file.delete();
+ }
+ }
+ }
+ return (path.delete());
+ }
+
+ private List<IProject> getExistingProjects(final File destination) {
+ List<IProject> existingProjects = new ArrayList<IProject>();
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
+ .getProjects();
+ for (IProject project : projects) {
+ if (project != null && project.exists()) {
+ File projectFile = project.getLocation().toFile();
+ if (projectFile.getAbsolutePath().startsWith(
+ destination.getAbsolutePath())) {
+ existingProjects.add(project);
+ }
+ }
+ }
+ return existingProjects;
+ }
+
+ private String getMessage(final File destination, List<IProject> projects) {
+ if (projects.size() > 0) {
+ StringBuilder builder = new StringBuilder();
+ if (projects.size() == 1) {
+ builder.append("\nThere is the '" + projects.get(0).getName()
+ + "' project on the destination location:\n\n");
+ builder.append("Would you like to overwrite it?");
+ } else {
+ builder.append("\nThere are the following projects on the destination
location:\n\n");
+ for (IProject project : projects) {
+ builder.append(project.getName());
+ builder.append("\n"); //$NON-NLS-1$
+ }
+ builder.append("\n"); //$NON-NLS-1$
+ builder.append("Would you like to overwrite them?");
+ }
+ return builder.toString();
+ }
+ return null;
+ }
+
+ private String getWorkspaceMessage(final List<IProject> existingProjects) {
+ StringBuilder builder = new StringBuilder();
+ if (existingProjects.size() == 1) {
+ builder.append("There is the '" + existingProjects.get(0).getName()
+ + "' project in the workspace.\n\n");
+ builder.append("Would you like to delete it?");
+ } else {
+ builder.append("There are the following projects in the workspace:\n\n");
+ for (IProject project : existingProjects) {
+ builder.append(project.getName());
+ builder.append("\n"); //$NON-NLS-1$
+ }
+ builder.append("\n"); //$NON-NLS-1$
+ builder.append("Would you like to delete them?");
+ }
+ return builder.toString();
+ }
+
+}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -11,7 +11,6 @@
package org.jboss.tools.maven.project.examples;
-import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -26,39 +25,32 @@
import org.apache.maven.model.Model;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.progress.IProgressConstants;
+import org.jboss.tools.project.examples.job.ProjectExamplesJob;
import org.jboss.tools.project.examples.model.AbstractImportProjectExample;
import org.jboss.tools.project.examples.model.Project;
import org.maven.ide.eclipse.MavenPlugin;
import org.maven.ide.eclipse.actions.OpenMavenConsoleAction;
-import org.maven.ide.eclipse.core.IMavenConstants;
import org.maven.ide.eclipse.core.MavenConsole;
import org.maven.ide.eclipse.embedder.IMaven;
import org.maven.ide.eclipse.embedder.MavenModelManager;
import org.maven.ide.eclipse.project.AbstractProjectScanner;
-import org.maven.ide.eclipse.project.IMavenProjectImportResult;
import org.maven.ide.eclipse.project.LocalProjectScanner;
import org.maven.ide.eclipse.project.MavenProjectInfo;
import org.maven.ide.eclipse.project.ProjectImportConfiguration;
-import org.maven.ide.eclipse.project.ResolverConfiguration;
/**
* @author snjeza
@@ -145,7 +137,7 @@
}
private void importMavenProjects(final File destination) {
- Job job = new WorkspaceJob("Importing Maven projects") {
+ Job job = new ProjectExamplesJob("Importing Maven projects") {
public IStatus runInWorkspace(IProgressMonitor monitor) {
setProperty(IProgressConstants.ACTION_PROPERTY,
new OpenMavenConsoleAction());
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/MavenProjectExamplesActivator.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/MavenProjectExamplesActivator.java 2011-02-18
12:25:09 UTC (rev 29237)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/MavenProjectExamplesActivator.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -9,7 +9,7 @@
* The activator class controls the plug-in life cycle
*/
public class MavenProjectExamplesActivator extends AbstractUIPlugin {
-
+
// The plug-in ID
public static final String PLUGIN_ID =
"org.jboss.tools.maven.project.examples"; //$NON-NLS-1$
Added:
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
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizard.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -0,0 +1,108 @@
+package org.jboss.tools.maven.project.examples.wizard;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Properties;
+
+import org.apache.maven.archetype.catalog.Archetype;
+import org.apache.maven.model.Model;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.progress.IProgressConstants;
+import org.jboss.tools.project.examples.job.ProjectExamplesJob;
+import org.jboss.tools.project.examples.model.Project;
+import org.maven.ide.eclipse.MavenImages;
+import org.maven.ide.eclipse.MavenPlugin;
+import org.maven.ide.eclipse.actions.OpenMavenConsoleAction;
+import org.maven.ide.eclipse.core.Messages;
+import org.maven.ide.eclipse.project.ProjectImportConfiguration;
+
+public class ArchetypeExamplesWizard extends Wizard implements INewWizard {
+
+ private Project projectDescription;
+ private File location;
+ private ProjectImportConfiguration configuration;
+ private ArchetypeExamplesWizardPage wizardPage;
+
+ public ArchetypeExamplesWizard(File location, Project projectDescription) {
+ super();
+ setWindowTitle("Project Examples Archetype");
+ setDefaultPageImageDescriptor(MavenImages.WIZ_NEW_PROJECT);
+ setNeedsProgressMonitor(true);
+ this.location = location;
+ this.projectDescription = projectDescription;
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ }
+
+ @Override
+ public boolean performFinish() {
+ final Model model = wizardPage.getModel();
+ final String groupId = model.getGroupId();
+ final String artifactId = model.getArtifactId();
+ 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);
+
+ final IWorkspaceRunnable wr = new IWorkspaceRunnable() {
+ public void run(final IProgressMonitor monitor)
+ throws CoreException {
+ plugin.getProjectConfigurationManager().createArchetypeProject(
+ project, new Path(location.getAbsolutePath()), archetype,
+ groupId, artifactId, version, javaPackage, properties,
+ configuration, monitor);
+ }
+ };
+
+ final IRunnableWithProgress op = new IRunnableWithProgress() {
+ public void run(final IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ try {
+ final IWorkspace ws = ResourcesPlugin.getWorkspace();
+ ws.run(wr, ws.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ };
+
+ try {
+ getContainer().run(true, false, op);
+ } catch (InterruptedException e) {
+ return false;
+ } catch (InvocationTargetException e) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public void addPages() {
+ configuration = new ProjectImportConfiguration();
+ wizardPage = new ArchetypeExamplesWizardPage(configuration, projectDescription);
+ addPage(wizardPage);
+ }
+}
Added:
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
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java 2011-02-18
13:22:38 UTC (rev 29238)
@@ -0,0 +1,48 @@
+package org.jboss.tools.maven.project.examples.wizard;
+
+import org.apache.maven.archetype.catalog.Archetype;
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.project.examples.model.ArchetypeModel;
+import org.jboss.tools.project.examples.model.Project;
+import org.maven.ide.eclipse.project.ProjectImportConfiguration;
+import org.maven.ide.eclipse.wizards.MavenProjectWizardArchetypeParametersPage;
+
+public class ArchetypeExamplesWizardPage extends
+ MavenProjectWizardArchetypeParametersPage {
+
+ private Project projectDescription;
+
+ public ArchetypeExamplesWizardPage(
+ ProjectImportConfiguration configuration, Project projectDescription) {
+ super(configuration);
+ this.projectDescription = projectDescription;
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+ Archetype archetype = new Archetype();
+ ArchetypeModel archetypeModel = projectDescription.getArchetypeModel();
+
+ final String groupId = archetypeModel.getGroupId();
+ final String artifactId = archetypeModel.getArtifactId();
+ final String version = archetypeModel.getVersion();
+ final String javaPackage = archetypeModel.getJavaPackage();
+
+ archetype.setGroupId(archetypeModel.getArchetypeGroupId());
+ archetype.setArtifactId(archetypeModel.getArchetypeArtifactId());
+ archetype.setVersion(archetypeModel.getArchetypeVersion());
+ archetype.setRepository(archetypeModel.getArchetypeRepository());
+ archetype.setProperties(archetypeModel.getArchetypeProperties());
+ setArchetype(archetype);
+ groupIdCombo.setText(groupId);
+ artifactIdCombo.setText(artifactId);
+ versionCombo.setText(version);
+ packageCombo.setText(javaPackage);
+ }
+
+ public Archetype getArchetype() {
+ return archetype;
+ }
+
+}