Author: fbricon
Date: 2012-02-29 10:05:41 -0500 (Wed, 29 Feb 2012)
New Revision: 39196
Added:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/AbstractImportMavenExample.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/AbstractImportMavenProjectDelegate.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExampleDelegate.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExampleDelegate.java
Modified:
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/ImportMavenProjectExample.java
Log:
JBDS-2035 : delay m2e activation. Prevents m2e index download on JBoss Central display.
Added:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/AbstractImportMavenExample.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/AbstractImportMavenExample.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/AbstractImportMavenExample.java 2012-02-29
15:05:41 UTC (rev 39196)
@@ -0,0 +1,39 @@
+/*************************************************************************************
+ * 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;
+
+
+import java.io.File;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.tools.project.examples.model.AbstractImportProjectExample;
+import org.jboss.tools.project.examples.model.ProjectExample;
+
+/**
+ * @author Fred Bricon
+ *
+ */
+public abstract class AbstractImportMavenExample extends AbstractImportProjectExample {
+
+ protected abstract AbstractImportMavenProjectDelegate getDelegate();
+
+ @Override
+ public boolean importProject(ProjectExample projectDescription, File file,
+ Map<String, Object> propertiesMap, IProgressMonitor monitor) throws Exception {
+
+ AbstractImportMavenProjectDelegate delegate = getDelegate();
+ delegate.setLocation(getLocation());
+ return delegate.importProject(projectDescription, file, propertiesMap, monitor);
+ }
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/AbstractImportMavenProjectDelegate.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/AbstractImportMavenProjectDelegate.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/AbstractImportMavenProjectDelegate.java 2012-02-29
15:05:41 UTC (rev 39196)
@@ -0,0 +1,35 @@
+/*************************************************************************************
+ * 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;
+
+import java.io.File;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.tools.project.examples.model.ProjectExample;
+
+abstract class AbstractImportMavenProjectDelegate {
+
+ private IPath location;
+
+ protected abstract boolean importProject(ProjectExample projectDescription, File file,
+ Map<String, Object> propertiesMap, IProgressMonitor monitor) throws Exception;
+
+ protected void setLocation(IPath location) {
+ this.location = location;
+ }
+
+ protected IPath getLocation() {
+ return location;
+ }
+
+}
Modified:
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 2012-02-29
14:53:24 UTC (rev 39195)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java 2012-02-29
15:05:41 UTC (rev 39196)
@@ -12,104 +12,14 @@
package org.jboss.tools.maven.project.examples;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.embedder.MavenModelManager;
-import org.eclipse.m2e.core.project.LocalProjectScanner;
-import org.eclipse.m2e.core.project.MavenProjectInfo;
-import org.eclipse.m2e.core.project.ProjectImportConfiguration;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.jboss.tools.project.examples.ProjectExamplesActivator;
-import org.jboss.tools.project.examples.model.AbstractImportProjectExample;
-import org.jboss.tools.project.examples.model.ProjectExample;
-
/**
- * @author snjeza
+ * @author Fred Bricon
*
*/
-public class ImportMavenArchetypeProjectExample extends
- AbstractImportProjectExample {
+public class ImportMavenArchetypeProjectExample extends AbstractImportMavenExample {
- @Override
- public boolean importProject(final ProjectExample projectDescription, File file,
- Map<String, Object> propertiesMap, final IProgressMonitor monitor) throws
Exception {
- List<ProjectExample> projects = new ArrayList<ProjectExample>();
- projects.add(projectDescription);
-// ArchetypeExamplesWizard wizard = new ArchetypeExamplesWizard(projectDescription);
-// WizardDialog wizardDialog = new WizardDialog(getActiveShell(), wizard);
-// int ok = wizardDialog.open();
-// if (ok != Window.OK) {
-// return false;
-// }
- List<String> includedProjects = projectDescription.getIncludedProjects();
- if (includedProjects == null) {
- includedProjects = new ArrayList<String>();
- projectDescription.setIncludedProjects(includedProjects);
- }
- projectDescription.getIncludedProjects().clear();
- String projectName = (String)
propertiesMap.get(ProjectExamplesActivator.PROPERTY_PROJECT_NAME);
- includedProjects.add(projectName);
- String artifactId = (String)
propertiesMap.get(ProjectExamplesActivator.PROPERTY_ARTIFACT_ID);
- IPath location = (IPath)
propertiesMap.get(ProjectExamplesActivator.PROPERTY_LOCATION_PATH);
- String projectFolder = location.append(artifactId).toFile()
- .getAbsolutePath();
- MavenModelManager mavenModelManager = MavenPlugin
- .getMavenModelManager();
- LocalProjectScanner scanner = new LocalProjectScanner(location.toFile(),
- projectFolder, true, mavenModelManager);
- try {
- scanner.run(monitor);
- } catch (InterruptedException e1) {
- return false;
- }
-
- Set<MavenProjectInfo> projectSet = collectProjects(scanner.getProjects());
- ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration();
-
- for (MavenProjectInfo info : projectSet) {
- try {
- projectName = MavenProjectExamplesActivator.getProjectName(info,
importConfiguration);
- if (!includedProjects.contains(projectName)) {
- includedProjects.add(projectName);
- }
- } catch (CoreException e) {
- MavenProjectExamplesActivator.log(e);
- return false;
- }
- }
- MavenProjectExamplesActivator.updateMavenConfiguration(projectName, includedProjects,
monitor);
- return true;
+ protected AbstractImportMavenProjectDelegate getDelegate() {
+ return new ImportMavenArchetypeProjectExampleDelegate();
}
-
- public Set<MavenProjectInfo> collectProjects(
- Collection<MavenProjectInfo> projects) {
- return new LinkedHashSet<MavenProjectInfo>() {
- private static final long serialVersionUID = 1L;
-
- public Set<MavenProjectInfo> collectProjects(
- Collection<MavenProjectInfo> projects) {
- for (MavenProjectInfo projectInfo : projects) {
- add(projectInfo);
- collectProjects(projectInfo.getProjects());
- }
- return this;
- }
- }.collectProjects(projects);
- }
-
- private static Shell getActiveShell() {
- return Display.getDefault().getActiveShell();
- }
-
}
Added:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExampleDelegate.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExampleDelegate.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExampleDelegate.java 2012-02-29
15:05:41 UTC (rev 39196)
@@ -0,0 +1,113 @@
+/*************************************************************************************
+ * 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;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.MavenModelManager;
+import org.eclipse.m2e.core.project.LocalProjectScanner;
+import org.eclipse.m2e.core.project.MavenProjectInfo;
+import org.eclipse.m2e.core.project.ProjectImportConfiguration;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.ProjectExample;
+
+/**
+ * @author snjeza
+ *
+ */
+public class ImportMavenArchetypeProjectExampleDelegate extends
AbstractImportMavenProjectDelegate {
+
+ @Override
+ public boolean importProject(final ProjectExample projectDescription, File file,
+ Map<String, Object> propertiesMap, final IProgressMonitor monitor) throws
Exception {
+ List<ProjectExample> projects = new ArrayList<ProjectExample>();
+ projects.add(projectDescription);
+// ArchetypeExamplesWizard wizard = new ArchetypeExamplesWizard(projectDescription);
+// WizardDialog wizardDialog = new WizardDialog(getActiveShell(), wizard);
+// int ok = wizardDialog.open();
+// if (ok != Window.OK) {
+// return false;
+// }
+ List<String> includedProjects = projectDescription.getIncludedProjects();
+ if (includedProjects == null) {
+ includedProjects = new ArrayList<String>();
+ projectDescription.setIncludedProjects(includedProjects);
+ }
+ projectDescription.getIncludedProjects().clear();
+ String projectName = (String)
propertiesMap.get(ProjectExamplesActivator.PROPERTY_PROJECT_NAME);
+ includedProjects.add(projectName);
+ String artifactId = (String)
propertiesMap.get(ProjectExamplesActivator.PROPERTY_ARTIFACT_ID);
+ IPath location = (IPath)
propertiesMap.get(ProjectExamplesActivator.PROPERTY_LOCATION_PATH);
+ String projectFolder = location.append(artifactId).toFile()
+ .getAbsolutePath();
+ MavenModelManager mavenModelManager = MavenPlugin
+ .getMavenModelManager();
+ LocalProjectScanner scanner = new LocalProjectScanner(location.toFile(),
+ projectFolder, true, mavenModelManager);
+ try {
+ scanner.run(monitor);
+ } catch (InterruptedException e1) {
+ return false;
+ }
+
+ Set<MavenProjectInfo> projectSet = collectProjects(scanner.getProjects());
+ ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration();
+
+ for (MavenProjectInfo info : projectSet) {
+ try {
+ projectName = MavenProjectExamplesActivator.getProjectName(info,
importConfiguration);
+ if (!includedProjects.contains(projectName)) {
+ includedProjects.add(projectName);
+ }
+ } catch (CoreException e) {
+ MavenProjectExamplesActivator.log(e);
+ return false;
+ }
+ }
+ MavenProjectExamplesActivator.updateMavenConfiguration(projectName, includedProjects,
monitor);
+ return true;
+ }
+
+ public Set<MavenProjectInfo> collectProjects(
+ Collection<MavenProjectInfo> projects) {
+ return new LinkedHashSet<MavenProjectInfo>() {
+ private static final long serialVersionUID = 1L;
+
+ public Set<MavenProjectInfo> collectProjects(
+ Collection<MavenProjectInfo> projects) {
+ for (MavenProjectInfo projectInfo : projects) {
+ add(projectInfo);
+ collectProjects(projectInfo.getProjects());
+ }
+ return this;
+ }
+ }.collectProjects(projects);
+ }
+
+ private static Shell getActiveShell() {
+ return Display.getDefault().getActiveShell();
+ }
+
+}
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 2012-02-29
14:53:24 UTC (rev 39195)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java 2012-02-29
15:05:41 UTC (rev 39196)
@@ -10,341 +10,15 @@
************************************************************************************/
package org.jboss.tools.maven.project.examples;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import org.apache.maven.model.Model;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.embedder.MavenModelManager;
-import org.eclipse.m2e.core.project.AbstractProjectScanner;
-import org.eclipse.m2e.core.project.LocalProjectScanner;
-import org.eclipse.m2e.core.project.MavenProjectInfo;
-import org.eclipse.m2e.core.project.ProjectImportConfiguration;
-import org.eclipse.m2e.core.ui.internal.actions.OpenMavenConsoleAction;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.jboss.tools.maven.ui.Activator;
-import org.jboss.tools.project.examples.ProjectExamplesActivator;
-import org.jboss.tools.project.examples.model.AbstractImportProjectExample;
-import org.jboss.tools.project.examples.model.ProjectExample;
-
/**
- * @author snjeza
+ * @author Fred Bricon
*
*/
-public class ImportMavenProjectExample extends AbstractImportProjectExample {
+public class ImportMavenProjectExample extends AbstractImportMavenExample {
- private static final String UNNAMED_PROJECTS = "UnnamedProjects";
//$NON-NLS-1$
-
- private boolean confirm;
-
@Override
- public boolean importProject(ProjectExample projectDescription, File file,
- Map<String, Object> propertiesMap, IProgressMonitor monitor) throws Exception {
- List<ProjectExample> projects = new ArrayList<ProjectExample>();
- projects.add(projectDescription);
- IPath rootPath = getLocation();
- IPath mavenProjectsRoot = rootPath;
- 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 false;
- }
- }
- boolean deleted = deleteDirectory(destination, monitor);
- if (monitor.isCanceled()) {
- return false;
- }
- if (!deleted) {
- Display.getDefault().syncExec(new Runnable() {
-
- @Override
- public void run() {
- MessageDialog.openError(getActiveShell(),
- "Error", "Cannot delete the '" + destination +
"' file.");
- }
- });
- return false;
- }
- }
- boolean ok = ProjectExamplesActivator.extractZipFile(file, destination, monitor);
- monitor.setTaskName("");
- if (monitor.isCanceled()) {
- return false;
- }
- if (!ok) {
- Display.getDefault().syncExec(new Runnable() {
-
- @Override
- public void run() {
- MessageDialog.openError(getActiveShell(),
- "Error",
- "Cannot extract the archive.");
- }
- });
- return false;
- }
- IPreferenceStore store = Activator.getDefault().getPreferenceStore();
- boolean configureSeam = store.getBoolean(Activator.CONFIGURE_SEAM);
- boolean configureJSF = store.getBoolean(Activator.CONFIGURE_JSF);
- boolean configurePortlet = store.getBoolean(Activator.CONFIGURE_PORTLET);
- boolean configureJSFPortlet = store.getBoolean(Activator.CONFIGURE_JSFPORTLET);
- boolean configureSeamPortlet = store.getBoolean(Activator.CONFIGURE_SEAMPORTLET);
- boolean configureCDI = store.getBoolean(Activator.CONFIGURE_CDI);
- boolean configureHibernate = store.getBoolean(Activator.CONFIGURE_HIBERNATE);
- boolean configureJaxRs = store.getBoolean(Activator.CONFIGURE_JAXRS);
- List<String> projectNames;
- try {
- store.setValue(Activator.CONFIGURE_SEAM, false);
- store.setValue(Activator.CONFIGURE_JSF, false);
- store.setValue(Activator.CONFIGURE_PORTLET, false);
- store.setValue(Activator.CONFIGURE_JSFPORTLET, false);
- store.setValue(Activator.CONFIGURE_SEAMPORTLET, false);
- store.setValue(Activator.CONFIGURE_CDI, false);
- store.setValue(Activator.CONFIGURE_HIBERNATE, false);
- store.setValue(Activator.CONFIGURE_JAXRS, false);
- projectNames = importMavenProjects(destination, projectDescription, monitor);
- } finally {
- store.setValue(Activator.CONFIGURE_SEAM, configureSeam);
- store.setValue(Activator.CONFIGURE_JSF, configureJSF);
- store.setValue(Activator.CONFIGURE_PORTLET, configurePortlet);
- store.setValue(Activator.CONFIGURE_JSFPORTLET, configureJSFPortlet);
- store.setValue(Activator.CONFIGURE_SEAMPORTLET, configureSeamPortlet);
- store.setValue(Activator.CONFIGURE_CDI, configureCDI);
- store.setValue(Activator.CONFIGURE_HIBERNATE, configureHibernate);
- store.setValue(Activator.CONFIGURE_JAXRS, configureJaxRs);
- }
- new OpenMavenConsoleAction().run();
- List<String> includedProjects = projectDescription.getIncludedProjects();
- includedProjects.clear();
- projectDescription.getIncludedProjects().addAll(projectNames);
- MavenProjectExamplesActivator.updateMavenConfiguration(projectName, includedProjects,
monitor);
- return true;
+ protected AbstractImportMavenProjectDelegate getDelegate() {
+ return new ImportMavenProjectExampleDelegate();
}
-
- private List<String> importMavenProjects(final File destination,
- final ProjectExample projectDescription, IProgressMonitor monitor) {
- List<String> projectNames = new ArrayList<String>();
- MavenPlugin plugin = MavenPlugin.getDefault();
- try {
- AbstractProjectScanner<MavenProjectInfo> projectScanner =
getProjectScanner(destination);
- projectScanner.run(monitor);
- List<MavenProjectInfo> mavenProjects = projectScanner.getProjects();
- List<MavenProjectInfo> infos = new ArrayList<MavenProjectInfo>();
- infos.addAll(mavenProjects);
- addMavenProjects(infos, mavenProjects);
- final List<IProject> existingProjects = new ArrayList<IProject>();
- ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration();
- String profiles = projectDescription.getDefaultProfiles();
- if (profiles != null && profiles.trim().length() > 0) {
- importConfiguration.getResolverConfiguration()
- .setActiveProfiles(profiles);
- }
- for (MavenProjectInfo info : infos) {
- String projectName = MavenProjectExamplesActivator.getProjectName(info,
importConfiguration);
- IProject project = ResourcesPlugin.getWorkspace().getRoot()
- .getProject(projectName);
- if (project != null && project.exists()) {
- existingProjects.add(project);
- }
- }
- if (existingProjects.size() > 0) {
- Display.getDefault().syncExec(new Runnable() {
-
- @Override
- public void run() {
- String message = getWorkspaceMessage(existingProjects);
-
- confirm = MessageDialog.openConfirm(getActiveShell(),
- "Confirmation", message);
- }
- });
- if (confirm) {
- for (IProject project : existingProjects) {
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE,
- monitor);
- } catch (Exception e) {
- // ignore
- }
- project.delete(true, true, monitor);
- }
- } else {
- return projectNames;
- }
- }
- List<String> includedProjects = projectDescription
- .getIncludedProjects();
- if (includedProjects != null && includedProjects.size() > 0) {
- List<MavenProjectInfo> newInfos = new ArrayList<MavenProjectInfo>();
- for (MavenProjectInfo info : infos) {
- Model model = info.getModel();
- if (model != null && model.getArtifactId() != null
- && model.getArtifactId().trim().length() > 0) {
- for (String includedProject : includedProjects) {
- if (model.getArtifactId().equals(includedProject)) {
- newInfos.add(info);
- }
- }
- }
- }
- infos = newInfos;
- }
- MavenPlugin.getProjectConfigurationManager().importProjects(infos,
- importConfiguration, monitor);
- for (MavenProjectInfo info : infos) {
- Model model = info.getModel();
- if (model != null && model.getArtifactId() != null
- && model.getArtifactId().trim().length() > 0) {
- projectNames.add(model.getArtifactId());
- }
- }
- } catch (CoreException ex) {
- MavenProjectExamplesActivator.log(ex,
- "Projects imported with errors");
- return projectNames;
- } catch (InterruptedException e) {
- MavenProjectExamplesActivator.log(e,
- "Projects imported with errors");
- return projectNames;
- }
- return projectNames;
- }
-
- private List<MavenProjectInfo> addMavenProjects(List<MavenProjectInfo>
infos, List<MavenProjectInfo> mavenProjects) {
- if (mavenProjects == null || mavenProjects.isEmpty()) {
- return mavenProjects;
- }
- for (MavenProjectInfo projectInfo:mavenProjects) {
- Collection<MavenProjectInfo> projects = projectInfo.getProjects();
- if (projects != null && !projects.isEmpty()) {
- for(MavenProjectInfo info:projects) {
- infos.add(info);
- }
- List<MavenProjectInfo> childProjects = new
ArrayList<MavenProjectInfo>();
- childProjects.addAll(projects);
- addMavenProjects(infos, childProjects);
- }
- }
- return mavenProjects;
- }
-
- private AbstractProjectScanner<MavenProjectInfo> getProjectScanner(
- File folder) {
- File root = ResourcesPlugin.getWorkspace().getRoot().getLocation()
- .toFile();
- MavenPlugin mavenPlugin = MavenPlugin.getDefault();
- MavenModelManager modelManager = mavenPlugin.getMavenModelManager();
- return new LocalProjectScanner(root, folder.getAbsolutePath(), false,
- modelManager);
- }
-
- 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();
- }
-
}
Added:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExampleDelegate.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExampleDelegate.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExampleDelegate.java 2012-02-29
15:05:41 UTC (rev 39196)
@@ -0,0 +1,349 @@
+/*************************************************************************************
+ * 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;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.model.Model;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.MavenModelManager;
+import org.eclipse.m2e.core.project.AbstractProjectScanner;
+import org.eclipse.m2e.core.project.LocalProjectScanner;
+import org.eclipse.m2e.core.project.MavenProjectInfo;
+import org.eclipse.m2e.core.project.ProjectImportConfiguration;
+import org.eclipse.m2e.core.ui.internal.actions.OpenMavenConsoleAction;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.maven.ui.Activator;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.ProjectExample;
+
+/**
+ * @author snjeza
+ *
+ */
+public class ImportMavenProjectExampleDelegate extends AbstractImportMavenProjectDelegate
{
+
+ private static final String UNNAMED_PROJECTS = "UnnamedProjects";
//$NON-NLS-1$
+
+ private boolean confirm;
+
+ @Override
+ public boolean importProject(ProjectExample projectDescription, File file,
+ Map<String, Object> propertiesMap, IProgressMonitor monitor) throws Exception {
+ List<ProjectExample> projects = new ArrayList<ProjectExample>();
+ projects.add(projectDescription);
+ IPath rootPath = getLocation();
+ IPath mavenProjectsRoot = rootPath;
+ 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 false;
+ }
+ }
+ boolean deleted = deleteDirectory(destination, monitor);
+ if (monitor.isCanceled()) {
+ return false;
+ }
+ if (!deleted) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ MessageDialog.openError(getActiveShell(),
+ "Error", "Cannot delete the '" + destination +
"' file.");
+ }
+ });
+ return false;
+ }
+ }
+ boolean ok = ProjectExamplesActivator.extractZipFile(file, destination, monitor);
+ monitor.setTaskName("");
+ if (monitor.isCanceled()) {
+ return false;
+ }
+ if (!ok) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ MessageDialog.openError(getActiveShell(),
+ "Error",
+ "Cannot extract the archive.");
+ }
+ });
+ return false;
+ }
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ boolean configureSeam = store.getBoolean(Activator.CONFIGURE_SEAM);
+ boolean configureJSF = store.getBoolean(Activator.CONFIGURE_JSF);
+ boolean configurePortlet = store.getBoolean(Activator.CONFIGURE_PORTLET);
+ boolean configureJSFPortlet = store.getBoolean(Activator.CONFIGURE_JSFPORTLET);
+ boolean configureSeamPortlet = store.getBoolean(Activator.CONFIGURE_SEAMPORTLET);
+ boolean configureCDI = store.getBoolean(Activator.CONFIGURE_CDI);
+ boolean configureHibernate = store.getBoolean(Activator.CONFIGURE_HIBERNATE);
+ boolean configureJaxRs = store.getBoolean(Activator.CONFIGURE_JAXRS);
+ List<String> projectNames;
+ try {
+ store.setValue(Activator.CONFIGURE_SEAM, false);
+ store.setValue(Activator.CONFIGURE_JSF, false);
+ store.setValue(Activator.CONFIGURE_PORTLET, false);
+ store.setValue(Activator.CONFIGURE_JSFPORTLET, false);
+ store.setValue(Activator.CONFIGURE_SEAMPORTLET, false);
+ store.setValue(Activator.CONFIGURE_CDI, false);
+ store.setValue(Activator.CONFIGURE_HIBERNATE, false);
+ store.setValue(Activator.CONFIGURE_JAXRS, false);
+ projectNames = importMavenProjects(destination, projectDescription, monitor);
+ } finally {
+ store.setValue(Activator.CONFIGURE_SEAM, configureSeam);
+ store.setValue(Activator.CONFIGURE_JSF, configureJSF);
+ store.setValue(Activator.CONFIGURE_PORTLET, configurePortlet);
+ store.setValue(Activator.CONFIGURE_JSFPORTLET, configureJSFPortlet);
+ store.setValue(Activator.CONFIGURE_SEAMPORTLET, configureSeamPortlet);
+ store.setValue(Activator.CONFIGURE_CDI, configureCDI);
+ store.setValue(Activator.CONFIGURE_HIBERNATE, configureHibernate);
+ store.setValue(Activator.CONFIGURE_JAXRS, configureJaxRs);
+ }
+ new OpenMavenConsoleAction().run();
+ List<String> includedProjects = projectDescription.getIncludedProjects();
+ includedProjects.clear();
+ projectDescription.getIncludedProjects().addAll(projectNames);
+ MavenProjectExamplesActivator.updateMavenConfiguration(projectName, includedProjects,
monitor);
+ return true;
+ }
+
+ private List<String> importMavenProjects(final File destination,
+ final ProjectExample projectDescription, IProgressMonitor monitor) {
+ List<String> projectNames = new ArrayList<String>();
+ MavenPlugin plugin = MavenPlugin.getDefault();
+ try {
+ AbstractProjectScanner<MavenProjectInfo> projectScanner =
getProjectScanner(destination);
+ projectScanner.run(monitor);
+ List<MavenProjectInfo> mavenProjects = projectScanner.getProjects();
+ List<MavenProjectInfo> infos = new ArrayList<MavenProjectInfo>();
+ infos.addAll(mavenProjects);
+ addMavenProjects(infos, mavenProjects);
+ final List<IProject> existingProjects = new ArrayList<IProject>();
+ ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration();
+ String profiles = projectDescription.getDefaultProfiles();
+ if (profiles != null && profiles.trim().length() > 0) {
+ importConfiguration.getResolverConfiguration()
+ .setActiveProfiles(profiles);
+ }
+ for (MavenProjectInfo info : infos) {
+ String projectName = MavenProjectExamplesActivator.getProjectName(info,
importConfiguration);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+ if (project != null && project.exists()) {
+ existingProjects.add(project);
+ }
+ }
+ if (existingProjects.size() > 0) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ String message = getWorkspaceMessage(existingProjects);
+
+ confirm = MessageDialog.openConfirm(getActiveShell(),
+ "Confirmation", message);
+ }
+ });
+ if (confirm) {
+ for (IProject project : existingProjects) {
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE,
+ monitor);
+ } catch (Exception e) {
+ // ignore
+ }
+ project.delete(true, true, monitor);
+ }
+ } else {
+ return projectNames;
+ }
+ }
+ List<String> includedProjects = projectDescription
+ .getIncludedProjects();
+ if (includedProjects != null && includedProjects.size() > 0) {
+ List<MavenProjectInfo> newInfos = new ArrayList<MavenProjectInfo>();
+ for (MavenProjectInfo info : infos) {
+ Model model = info.getModel();
+ if (model != null && model.getArtifactId() != null
+ && model.getArtifactId().trim().length() > 0) {
+ for (String includedProject : includedProjects) {
+ if (model.getArtifactId().equals(includedProject)) {
+ newInfos.add(info);
+ }
+ }
+ }
+ }
+ infos = newInfos;
+ }
+ MavenPlugin.getProjectConfigurationManager().importProjects(infos,
+ importConfiguration, monitor);
+ for (MavenProjectInfo info : infos) {
+ Model model = info.getModel();
+ if (model != null && model.getArtifactId() != null
+ && model.getArtifactId().trim().length() > 0) {
+ projectNames.add(model.getArtifactId());
+ }
+ }
+ } catch (CoreException ex) {
+ MavenProjectExamplesActivator.log(ex,
+ "Projects imported with errors");
+ return projectNames;
+ } catch (InterruptedException e) {
+ MavenProjectExamplesActivator.log(e,
+ "Projects imported with errors");
+ return projectNames;
+ }
+ return projectNames;
+ }
+
+ private List<MavenProjectInfo> addMavenProjects(List<MavenProjectInfo>
infos, List<MavenProjectInfo> mavenProjects) {
+ if (mavenProjects == null || mavenProjects.isEmpty()) {
+ return mavenProjects;
+ }
+ for (MavenProjectInfo projectInfo:mavenProjects) {
+ Collection<MavenProjectInfo> projects = projectInfo.getProjects();
+ if (projects != null && !projects.isEmpty()) {
+ for(MavenProjectInfo info:projects) {
+ infos.add(info);
+ }
+ List<MavenProjectInfo> childProjects = new
ArrayList<MavenProjectInfo>();
+ childProjects.addAll(projects);
+ addMavenProjects(infos, childProjects);
+ }
+ }
+ return mavenProjects;
+ }
+
+ private AbstractProjectScanner<MavenProjectInfo> getProjectScanner(
+ File folder) {
+ File root = ResourcesPlugin.getWorkspace().getRoot().getLocation()
+ .toFile();
+ MavenPlugin mavenPlugin = MavenPlugin.getDefault();
+ MavenModelManager modelManager = mavenPlugin.getMavenModelManager();
+ return new LocalProjectScanner(root, folder.getAbsolutePath(), false,
+ modelManager);
+ }
+
+ 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();
+ }
+
+}