Author: snjeza
Date: 2011-11-26 09:28:07 -0500 (Sat, 26 Nov 2011)
New Revision: 36677
Removed:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/job/
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples.cheatsheet/src/org/jboss/tools/project/examples/cheatsheet/actions/ImportProjectExample.java
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/Category.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IImportProjectExample.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/ImportDefaultMavenProjectExample.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.java
trunk/examples/tests/org.jboss.tools.project.examples.test/src/org/jboss/tools/project/examples/test/ProjectTest.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/ImportMavenProjectExample.java
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/wizard/ArchetypeExamplesWizard.java
Log:
JBIDE-9863 ProjectExamplesFix assumes the Eclipse project name is identical to the Example
name
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-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/META-INF/MANIFEST.MF 2011-11-26
14:28:07 UTC (rev 36677)
@@ -40,7 +40,6 @@
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
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-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -21,6 +21,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -245,14 +246,18 @@
if (pName == null) {
List<String> projectNames = project.getIncludedProjects();
List<IProject> projects = new ArrayList<IProject>();
- for (String projectName:projectNames) {
- IProject eclipseProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- if (eclipseProject != null && eclipseProject.isOpen()) {
- projects.add(eclipseProject);
+ if (projectNames != null) {
+ for (String projectName : projectNames) {
+ IProject eclipseProject = ResourcesPlugin.getWorkspace()
+ .getRoot().getProject(projectName);
+ if (eclipseProject != null && eclipseProject.isOpen()) {
+ projects.add(eclipseProject);
+ }
}
}
return projects.toArray(new IProject[0]);
}
+ pName = replace(pName, project);
StringTokenizer tokenizer = new StringTokenizer(pName,","); //$NON-NLS-1$
List<IProject> projects = new ArrayList<IProject>();
while (tokenizer.hasMoreTokens()) {
@@ -267,6 +272,19 @@
return projects.toArray(new IProject[0]);
}
+ protected static String replace(String name, Project project) {
+ List<String> includedProjects = project.getIncludedProjects();
+ if (includedProjects != null) {
+ int i = 0;
+ for (String includedProject : includedProjects) {
+ String expression = "${project[" + i + "]}"; //$NON-NLS-1$
//$NON-NLS-2$
+ name = name.replace(expression, includedProject);
+ i++;
+ }
+ }
+ return name;
+ }
+
public IImportProjectExample getImportProjectExample(String importType) {
initImportProjectExamples();
if (importType == null) {
@@ -357,6 +375,7 @@
for(final Project project:projects) {
if (project.isWelcome()) {
String urlString = project.getWelcomeURL();
+ urlString = replace(urlString, project);
URL url = null;
if (urlString.startsWith("/")) { //$NON-NLS-1$
IPath path = new Path(urlString);
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -47,11 +47,29 @@
this.projects = projects;
}
+ public String getDescription() {
+ return getName();
+ }
+
+ public String getShortDescription() {
+ return getName();
+ }
+
+ public IProjectExampleSite getSite() {
+ return site;
+ }
+
@Override
+ public void setSite(IProjectExampleSite site) {
+ this.site = site;
+ }
+
+ @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((site == null) ? 0 : site.hashCode());
return result;
}
@@ -69,24 +87,12 @@
return false;
} else if (!name.equals(other.name))
return false;
+ if (site == null) {
+ if (other.site != null)
+ return false;
+ } else if (!site.equals(other.site))
+ return false;
return true;
}
- public String getDescription() {
- return getName();
- }
-
- public String getShortDescription() {
- return getName();
- }
-
- public IProjectExampleSite getSite() {
- return site;
- }
-
- @Override
- public void setSite(IProjectExampleSite site) {
- this.site = site;
- }
-
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IImportProjectExample.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IImportProjectExample.java 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IImportProjectExample.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -22,7 +22,7 @@
*/
public interface IImportProjectExample {
- List<Project> importProject(Project projectDescription, File file,
+ boolean importProject(Project projectDescription, File file,
IProgressMonitor monitor) throws Exception;
void fix(Project project, IProgressMonitor monitor);
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-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -270,7 +270,10 @@
String value = getContent(child);
boolean found = false;
for (Category cat : list) {
- if (cat.getName().equals(value)) {
+ if (cat.getSite() == null) {
+ cat.setSite(site);
+ }
+ if (cat.getName().equals(value) &&
site.getName().equals(cat.getSite().getName())) {
category = cat;
found = true;
break;
@@ -282,6 +285,7 @@
list.add(category);
}
project.setCategory(category);
+ category.getProjects().add(project);
}
else if (nodeName.equals(NAME)) {
project.setName(getContent(child));
@@ -352,7 +356,6 @@
}
}
}
- category.getProjects().add(project);
}
}
} catch (Exception e) {
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ImportDefaultMavenProjectExample.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ImportDefaultMavenProjectExample.java 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ImportDefaultMavenProjectExample.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -46,13 +46,13 @@
};
@Override
- public List<Project> importProject(Project projectDescription, File file,
+ public boolean importProject(Project projectDescription, File file,
IProgressMonitor monitor) throws Exception {
List<Project> projects = new ArrayList<Project>();
if (projectDescription.getIncludedProjects() == null) {
- importSingleProject(projectDescription, file, monitor);
+ boolean ret = importSingleProject(projectDescription, file, monitor);
projects.add(projectDescription);
- return projects;
+ return ret;
} else {
List<String> projectNames = projectDescription.getIncludedProjects();
for (final String projectName : projectNames) {
@@ -70,7 +70,7 @@
});
if (!ret[0]) {
- return projects;
+ return false;
}
project.delete(true, true, monitor);
}
@@ -109,15 +109,16 @@
}
} catch (Exception e) {
ProjectExamplesActivator.log(e);
+ return false;
}
}
reconfigure(project, monitor);
}
}
- return projects;
+ return true;
}
- private void importSingleProject(Project projectDescription, File file,
+ private boolean importSingleProject(Project projectDescription, File file,
IProgressMonitor monitor) throws CoreException, ZipException,
IOException, InvocationTargetException, InterruptedException {
final String projectName = projectDescription.getName();
@@ -135,7 +136,7 @@
});
if (!ret[0]) {
- return;
+ return false;
}
project.delete(true, true, monitor);
}
@@ -174,10 +175,11 @@
}
} catch (Exception e) {
ProjectExamplesActivator.log(e);
+ return false;
}
}
reconfigure(project, monitor);
-
+ return true;
}
private static Shell getActiveShell() {
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.java 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -55,8 +55,9 @@
});
return Status.OK_STATUS;
}
- importProjectExample.importProject(project, project.getFile(), monitor);
- importProjectExample.fix(project, monitor);
+ if (importProjectExample.importProject(project, project.getFile(), monitor)) {
+ importProjectExample.fix(project, monitor);
+ }
}
} catch (final Exception e) {
Display.getDefault().syncExec(new Runnable() {
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.java 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -16,6 +16,7 @@
import org.eclipse.jface.viewers.ViewerFilter;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.model.Category;
+import org.jboss.tools.project.examples.model.IProjectExampleSite;
import org.jboss.tools.project.examples.model.Project;
import org.jboss.tools.project.examples.model.ProjectModelElement;
@@ -44,9 +45,21 @@
if (site.equals(ProjectExamplesActivator.ALL_SITES)) {
size += category.getProjects().size();
} else {
+ IProjectExampleSite categorySite = category.getSite();
+ if (categorySite == null) {
+ return false;
+ }
+ if (!site.equals(categorySite.getName())) {
+ return false;
+ }
List<Project> projects = category.getProjects();
for (Project project:projects) {
- if (site.equals(project.getSite())) {
+ IProjectExampleSite projectSite = project.getSite();
+ if (projectSite == null) {
+ continue;
+ }
+
+ if (site.equals(projectSite.getName())) {
size++;
}
}
@@ -54,7 +67,10 @@
return size > 0;
}
ProjectModelElement model = (ProjectModelElement) element;
- if ( site.equals(ProjectExamplesActivator.ALL_SITES) || site.equals(model.getSite()))
{
+ if (model.getSite() == null) {
+ return false;
+ }
+ if ( site.equals(ProjectExamplesActivator.ALL_SITES) ||
site.equals(model.getSite().getName())) {
return true;
}
return false;
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples.cheatsheet/src/org/jboss/tools/project/examples/cheatsheet/actions/ImportProjectExample.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples.cheatsheet/src/org/jboss/tools/project/examples/cheatsheet/actions/ImportProjectExample.java 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/plugins/org.jboss.tools.project.examples.cheatsheet/src/org/jboss/tools/project/examples/cheatsheet/actions/ImportProjectExample.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -97,8 +97,9 @@
setName(Messages.NewProjectExamplesWizard_Importing);
try {
IImportProjectExample importProjectExample =
ProjectExamplesActivator.getDefault().getImportProjectExample(project.getImportType());
- importProjectExample.importProject(project, file, monitor);
- importProjectExample.fix(project, monitor);
+ if (importProjectExample.importProject(project, file, monitor)) {
+ importProjectExample.fix(project, monitor);
+ }
} catch (Exception e) {
IStatus status = new Status(IStatus.ERROR,Activator.PLUGIN_ID,e.getMessage(),e);
throw new CoreException(status);
Modified:
trunk/examples/tests/org.jboss.tools.project.examples.test/src/org/jboss/tools/project/examples/test/ProjectTest.java
===================================================================
---
trunk/examples/tests/org.jboss.tools.project.examples.test/src/org/jboss/tools/project/examples/test/ProjectTest.java 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/examples/tests/org.jboss.tools.project.examples.test/src/org/jboss/tools/project/examples/test/ProjectTest.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -172,8 +172,9 @@
url, name, ".zip", monitor); //$NON-NLS-1$
assertNotNull(file);
IImportProjectExample importProjectExample =
ProjectExamplesActivator.getDefault().getImportProjectExample(projectExample.getImportType());
- importProjectExample.importProject(projectExample, file, monitor);
- importProjectExample.fix(projectExample, monitor);
+ if (importProjectExample.importProject(projectExample, file, monitor)) {
+ importProjectExample.fix(projectExample, monitor);
+ }
}
@Test
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 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -11,15 +11,26 @@
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.Set;
import org.eclipse.core.resources.IWorkspaceRoot;
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.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
+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.maven.project.examples.wizard.ArchetypeExamplesWizard;
@@ -33,38 +44,91 @@
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$
-
@Override
- public List<Project> importProject(final Project projectDescription, File file,
- IProgressMonitor monitor) throws Exception {
+ public boolean importProject(final Project projectDescription, File file,
+ final IProgressMonitor monitor) throws Exception {
List<Project> projects = new ArrayList<Project>();
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ projects.add(projectDescription);
+ final 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);
+ IPath mavenProjectsRoot = rootPath;
+ IPath path = mavenProjectsRoot;
final File destination = new File(path.toOSString());
+ final boolean[] ret = new boolean[1];
+ ret[0] = true;
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
ArchetypeExamplesWizard wizard = new ArchetypeExamplesWizard(destination,
projectDescription);
WizardDialog wizardDialog = new WizardDialog(getActiveShell(), wizard);
- wizardDialog.open();
+ int ok = wizardDialog.open();
+ if (ok != Window.OK) {
+ ret[0] = false;
+ return;
+ }
+ List<String> includedProjects = projectDescription.getIncludedProjects();
+ if (includedProjects == null) {
+ includedProjects = new ArrayList<String>();
+ projectDescription.setIncludedProjects(includedProjects);
+ }
+ projectDescription.getIncludedProjects().clear();
+ String projectName = wizard.getProjectName();
+ includedProjects.add(projectName);
+ IPath location = workspaceRoot.getLocation();
+ String artifactId = wizard.getArtifactId();
+ String projectFolder = location.append(artifactId).toFile()
+ .getAbsolutePath();
+ MavenModelManager mavenModelManager = MavenPlugin
+ .getMavenModelManager();
+ LocalProjectScanner scanner = new LocalProjectScanner(
+ workspaceRoot.getLocation().toFile(), //
+ projectFolder, true, mavenModelManager);
+ try {
+ scanner.run(monitor);
+ } catch (InterruptedException e1) {
+ ret[0] = false;
+ return;
+ }
+
+ 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);
+ ret[0] = false;
+ }
+ }
}
});
- return projects;
+ return ret[0];
}
-
+ 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 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -24,9 +24,6 @@
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.Status;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
@@ -38,9 +35,7 @@
import org.eclipse.m2e.core.ui.internal.actions.OpenMavenConsoleAction;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.progress.IProgressConstants;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
-import org.jboss.tools.project.examples.job.ProjectExamplesJob;
import org.jboss.tools.project.examples.model.AbstractImportProjectExample;
import org.jboss.tools.project.examples.model.Project;
@@ -52,17 +47,16 @@
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(Project projectDescription, File file,
+ public boolean importProject(Project projectDescription, File file,
IProgressMonitor monitor) throws Exception {
List<Project> projects = new ArrayList<Project>();
+ projects.add(projectDescription);
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IPath rootPath = workspaceRoot.getLocation();
- IPath mavenProjectsRoot = rootPath;//.append(JBOSS_TOOLS_MAVEN_PROJECTS);
+ IPath mavenProjectsRoot = rootPath;
String projectName = projectDescription.getName();
if (projectName == null || projectName.isEmpty()) {
projectName = UNNAMED_PROJECTS;
@@ -87,12 +81,12 @@
project.delete(false, true, monitor);
}
} else {
- return projects;
+ return false;
}
}
boolean deleted = deleteDirectory(destination, monitor);
if (monitor.isCanceled()) {
- return projects;
+ return false;
}
if (!deleted) {
Display.getDefault().syncExec(new Runnable() {
@@ -103,13 +97,13 @@
"Error", "Cannot delete the '" + destination +
"' file.");
}
});
- return projects;
+ return false;
}
}
boolean ok = ProjectExamplesActivator.extractZipFile(file, destination, monitor);
monitor.setTaskName("");
if (monitor.isCanceled()) {
- return projects;
+ return false;
}
if (!ok) {
Display.getDefault().syncExec(new Runnable() {
@@ -121,78 +115,86 @@
"Cannot extract the archive.");
}
});
- return projects;
+ return false;
}
- importMavenProjects(destination, projectDescription);
- return projects;
+ List<String> projectNames = importMavenProjects(destination, projectDescription,
monitor);
+ new OpenMavenConsoleAction().run();
+ projectDescription.getIncludedProjects().clear();
+ projectDescription.getIncludedProjects().addAll(projectNames);
+ return true;
}
- private void importMavenProjects(final File destination, final Project
projectDescription) {
- Job job = new ProjectExamplesJob("Importing Maven projects") {
- public IStatus runInWorkspace(IProgressMonitor monitor) {
- setProperty(IProgressConstants.ACTION_PROPERTY,
- new OpenMavenConsoleAction());
- 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 = getProjectName(info, importConfiguration);
- IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- if (project != null && project.exists()) {
- existingProjects.add(project);
- }
+ private List<String> importMavenProjects(final File destination,
+ final Project 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 (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 Status.CANCEL_STATUS;
+ });
+ if (confirm) {
+ for (IProject project : existingProjects) {
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE,
+ monitor);
+ } catch (Exception e) {
+ // ignore
}
+ project.delete(true, true, monitor);
}
- MavenPlugin.getProjectConfigurationManager().importProjects(
- infos, importConfiguration, monitor);
- } catch (CoreException ex) {
- MavenProjectExamplesActivator.log(ex, "Projects imported with errors");
- return ex.getStatus();
- } catch (InterruptedException e) {
- return Status.CANCEL_STATUS;
+ } else {
+ return projectNames;
}
- return Status.OK_STATUS;
}
- };
- job.setRule(MavenPlugin.getDefault().getProjectConfigurationManager()
- .getRule());
- job.schedule();
+ 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) {
@@ -245,38 +247,6 @@
return (path.delete());
}
- private String getProjectName(MavenProjectInfo projectInfo,
- ProjectImportConfiguration configuration) throws CoreException {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IWorkspaceRoot root = workspace.getRoot();
-
- File pomFile = projectInfo.getPomFile();
- Model model = projectInfo.getModel();
- IMaven maven = MavenPlugin.getDefault().getMaven();
- if (model == null) {
- model = maven.readModel(pomFile);
- projectInfo.setModel(model);
- }
-
- String projectName = configuration.getProjectName(model);
-
- File projectDir = pomFile.getParentFile();
- String projectParent = projectDir.getParentFile().getAbsolutePath();
-
- if (projectInfo.getBasedirRename() == MavenProjectInfo.RENAME_REQUIRED) {
- File newProject = new File(projectDir.getParent(), projectName);
- if (!projectDir.equals(newProject)) {
- projectDir = newProject;
- }
- } else {
- if (projectParent.equals(root.getLocation().toFile()
- .getAbsolutePath())) {
- projectName = projectDir.getName();
- }
- }
- return projectName;
- }
-
private List<IProject> getExistingProjects(final File destination) {
List<IProject> existingProjects = new ArrayList<IProject>();
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
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-11-26
13:08:52 UTC (rev 36676)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/MavenProjectExamplesActivator.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -1,7 +1,18 @@
package org.jboss.tools.maven.project.examples;
+import java.io.File;
+
+import org.apache.maven.model.Model;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.IMaven;
+import org.eclipse.m2e.core.project.MavenProjectInfo;
+import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -59,4 +70,36 @@
IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message, e);
getDefault().getLog().log(status);
}
+
+ public static String getProjectName(MavenProjectInfo projectInfo,
+ ProjectImportConfiguration configuration) throws CoreException {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceRoot root = workspace.getRoot();
+
+ File pomFile = projectInfo.getPomFile();
+ Model model = projectInfo.getModel();
+ IMaven maven = MavenPlugin.getMaven();
+ if (model == null) {
+ model = maven.readModel(pomFile);
+ projectInfo.setModel(model);
+ }
+
+ String projectName = configuration.getProjectName(model);
+
+ File projectDir = pomFile.getParentFile();
+ String projectParent = projectDir.getParentFile().getAbsolutePath();
+
+ if (projectInfo.getBasedirRename() == MavenProjectInfo.RENAME_REQUIRED) {
+ File newProject = new File(projectDir.getParent(), projectName);
+ if (!projectDir.equals(newProject)) {
+ projectDir = newProject;
+ }
+ } else {
+ if (projectParent.equals(root.getLocation().toFile()
+ .getAbsolutePath())) {
+ projectName = projectDir.getName();
+ }
+ }
+ return projectName;
+ }
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizard.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizard.java 2011-11-26
13:08:52 UTC (rev 36676)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizard.java 2011-11-26
14:28:07 UTC (rev 36677)
@@ -45,6 +45,8 @@
private File location;
private ProjectImportConfiguration configuration;
private ArchetypeExamplesWizardPage wizardPage;
+ private String projectName;
+ private String artifactId;
public ArchetypeExamplesWizard(File location, Project projectDescription) {
super();
@@ -63,12 +65,12 @@
public boolean performFinish() {
final Model model = wizardPage.getModel();
final String groupId = model.getGroupId();
- final String artifactId = model.getArtifactId();
+ artifactId = model.getArtifactId();
final String version = model.getVersion();
final String javaPackage = wizardPage.getJavaPackage();
final Properties properties = wizardPage.getProperties();
final Archetype archetype = wizardPage.getArchetype();
- final String projectName = configuration.getProjectName(model);
+ projectName = configuration.getProjectName(model);
final IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
final IWorkspaceRunnable wr = new IWorkspaceRunnable() {
@@ -117,4 +119,12 @@
wizardPage = new ArchetypeExamplesWizardPage(configuration, projectDescription);
addPage(wizardPage);
}
+
+ public String getProjectName() {
+ return projectName;
+ }
+
+ public String getArtifactId() {
+ return artifactId;
+ }
}