Author: snjeza
Date: 2011-11-28 04:59:41 -0500 (Mon, 28 Nov 2011)
New Revision: 36687
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ImportDefaultProjectExample.java
Removed:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ImportDefaultMavenProjectExample.java
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
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/messages.properties
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/AbstractImportProjectExample.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/Project.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencePage.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/SiteDialog.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.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/wizard/ArchetypeExamplesWizard.java
Log:
JBIDE-10009 project examples should provide way to set the output direcotry
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2011-11-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -64,6 +64,7 @@
public static String ProjectExamplesActivator_Waiting;
public static String ProjectExamplesPreferencePage_Add;
public static String ProjectExamplesPreferencePage_Edit;
+ public static String ProjectExamplesPreferencePage_Output_directory;
public static String ProjectExamplesPreferencePage_Remove;
public static String ProjectExamplesPreferencePage_Show_experimental_sites;
public static String ProjectExamplesPreferencePage_Show_invalid_sites;
@@ -81,7 +82,7 @@
public static String ProjectUtil_Test;
public static String SeamRuntimeFix_Invalid_seam_runtime_fix;
public static String SiteDialog_Add_Project_Example_Site;
- public static String SiteDialog_Browse;
+ public static String Browse;
public static String SiteDialog_Edit_Project_Example_Site;
public static String SiteDialog_Invalid_URL;
public static String SiteDialog_Name;
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-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -93,7 +93,7 @@
import org.jboss.tools.project.examples.model.Project;
import org.jboss.tools.project.examples.model.ProjectFix;
import org.jboss.tools.project.examples.model.ProjectUtil;
-import org.jboss.tools.project.examples.wizard.ImportDefaultMavenProjectExample;
+import org.jboss.tools.project.examples.wizard.ImportDefaultProjectExample;
import org.jboss.tools.project.examples.wizard.NewProjectExamplesJob;
import org.osgi.framework.BundleContext;
@@ -102,8 +102,9 @@
*/
public class ProjectExamplesActivator extends AbstractUIPlugin {
- private static final String README_HTML = "/readme.html";
+ private static final String README_HTML = "/readme.html"; //$NON-NLS-1$
private static final String CHEATSHEET_XML = "/cheatsheet.xml"; //$NON-NLS-1$
+ private static final String PERIOD_CHEATSHEET_XML = "/.cheatsheet.xml";
//$NON-NLS-1$
// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.project.examples";
//$NON-NLS-1$
public static final String ALL_SITES = Messages.ProjectExamplesActivator_All;
@@ -114,6 +115,7 @@
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();
+ public static final String PROJECT_EXAMPLES_OUTPUT_DIRECTORY =
"projectExamplesOutputDirectory"; //$NON-NLS-1$
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$
@@ -144,7 +146,7 @@
};
private Map<String, IImportProjectExample> importProjectExamplesMap;
- private ImportDefaultMavenProjectExample defaultImportProjectExample;
+ private ImportDefaultProjectExample defaultImportProjectExample;
/**
* The constructor
@@ -297,7 +299,7 @@
private void initImportProjectExamples() {
if (importProjectExamplesMap == null) {
- defaultImportProjectExample = new ImportDefaultMavenProjectExample();
+ defaultImportProjectExample = new ImportDefaultProjectExample();
importProjectExamplesMap = new HashMap<String,IImportProjectExample>();
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = registry
@@ -437,23 +439,37 @@
if (project == null || project.isWelcome()) {
return;
}
+ checkCheatsheet(project);
+
+ }
+
+ protected static void checkCheatsheet(Project project) {
List<String> includedProjects = project.getIncludedProjects();
if (includedProjects == null || includedProjects.size() <= 0) {
return;
}
- String projectName = includedProjects.get(0);
- if (projectName == null || projectName.isEmpty()) {
- return;
+ for (String projectName : includedProjects) {
+ if (projectName == null || projectName.isEmpty()) {
+ continue;
+ }
+ IProject eclipseProject = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+ if (eclipseProject == null || !eclipseProject.exists()) {
+ continue;
+ }
+ if (checkCheatsheet(project, eclipseProject, PERIOD_CHEATSHEET_XML,
+ ProjectUtil.CHEATSHEETS)) {
+ return;
+ }
+ if (checkCheatsheet(project, eclipseProject, CHEATSHEET_XML,
+ ProjectUtil.CHEATSHEETS)) {
+ return;
+ }
+ if (checkCheatsheet(project, eclipseProject, README_HTML,
+ ProjectUtil.EDITOR)) {
+ return;
+ }
}
- IProject eclipseProject =
ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- if (eclipseProject == null || !eclipseProject.exists()) {
- return;
- }
- if (checkCheatsheet(project, eclipseProject, CHEATSHEET_XML, ProjectUtil.CHEATSHEETS))
{
- return;
- }
- checkCheatsheet(project, eclipseProject, README_HTML, ProjectUtil.EDITOR);
-
}
private static boolean checkCheatsheet(Project project,
@@ -780,6 +796,9 @@
}
public void done(IJobChangeEvent event) {
+ if (!workspaceJob.getResult().isOK()) {
+ return;
+ }
List<Project> projects = workspaceJob.getProjects();
try {
ProjectExamplesActivator.updatePerspective(projects);
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2011-11-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2011-11-28
09:59:41 UTC (rev 36687)
@@ -51,6 +51,7 @@
ProjectExamplesActivator_Waiting=Waiting...
ProjectExamplesPreferencePage_Add=Add
ProjectExamplesPreferencePage_Edit=Edit
+ProjectExamplesPreferencePage_Output_directory=Output directory:
ProjectExamplesPreferencePage_Remove=Remove
ProjectExamplesPreferencePage_Show_experimental_sites=Show experimental sites
ProjectExamplesPreferencePage_Show_invalid_sites=Show invalid sites
@@ -69,7 +70,7 @@
NewProjectExamplesWizardPage_Site=Site\:
SeamRuntimeFix_Invalid_seam_runtime_fix=Invalid Seam runtime fix in {0}.
SiteDialog_Add_Project_Example_Site=Add Project Example Site
-SiteDialog_Browse=Browse...
+Browse=Browse...
SiteDialog_Edit_Project_Example_Site=Edit Project Example Site
SiteDialog_Invalid_URL=Invalid url.
SiteDialog_Name=Name:
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/AbstractImportProjectExample.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/AbstractImportProjectExample.java 2011-11-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/AbstractImportProjectExample.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -11,7 +11,10 @@
package org.jboss.tools.project.examples.model;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
/**
@@ -45,5 +48,14 @@
public void fix(Project project, IProgressMonitor monitor) {
ProjectExamplesActivator.fix(project, monitor);
}
+
+ @Override
+ public IPath getLocation() {
+ String location =
ProjectExamplesActivator.getDefault().getPreferenceStore().getString(ProjectExamplesActivator.PROJECT_EXAMPLES_OUTPUT_DIRECTORY);
+ if (location == null || location.isEmpty()) {
+ return Platform.getLocation();
+ }
+ return new Path(location);
+ }
}
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-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/IImportProjectExample.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -12,8 +12,8 @@
package org.jboss.tools.project.examples.model;
import java.io.File;
-import java.util.List;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
@@ -34,4 +34,6 @@
String getName();
String getType();
+
+ IPath getLocation();
}
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-11-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -44,7 +44,7 @@
private ArchetypeModel archetypeModel = new ArchetypeModel();
private File file;
private IProjectExampleSite site;
- private String defaultProfiles ="";
+ private String defaultProfiles =""; //$NON-NLS-1$
public Project() {
name=""; //$NON-NLS-1$
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencePage.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencePage.java 2011-11-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/ProjectExamplesPreferencePage.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -12,6 +12,7 @@
import java.net.URL;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.ISelection;
@@ -32,7 +33,10 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.jboss.tools.project.examples.Messages;
@@ -55,6 +59,7 @@
private TreeViewer viewer;
private ProjectExampleSite selectedSite;
private Button showInvalidSites;
+ private Text outputDirectoryText;
@Override
protected Control createContents(Composite parent) {
@@ -73,6 +78,51 @@
showInvalidSites.setText(Messages.ProjectExamplesPreferencePage_Show_invalid_sites);
showInvalidSites.setSelection(store.getBoolean(ProjectExamplesActivator.SHOW_INVALID_SITES));
+ Composite outputDirectoryComposite = new Composite(composite, SWT.NONE);
+ layout = new GridLayout(3, false);
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ outputDirectoryComposite.setLayout(layout);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ outputDirectoryComposite.setLayoutData(gd);
+
+ Label outputDirectoryLabel = new Label(outputDirectoryComposite,SWT.NONE);
+ gd = new GridData(SWT.FILL, SWT.FILL, false, false);
+ gd.verticalAlignment = SWT.CENTER;
+ outputDirectoryLabel.setLayoutData(gd);
+ outputDirectoryLabel.setText(Messages.ProjectExamplesPreferencePage_Output_directory);
+
+ outputDirectoryText = new Text(outputDirectoryComposite, SWT.SINGLE|SWT.BORDER);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, false);
+ gd.verticalAlignment = SWT.CENTER;
+ outputDirectoryText.setLayoutData(gd);
+ String outputDirectoryValue =
store.getString(ProjectExamplesActivator.PROJECT_EXAMPLES_OUTPUT_DIRECTORY);
+ outputDirectoryText.setText(outputDirectoryValue == null ? "" :
outputDirectoryValue); //$NON-NLS-1$
+ Button outputDirectoryBrowse = new Button(outputDirectoryComposite, SWT.PUSH);
+ outputDirectoryBrowse.setText(Messages.Browse);
+ outputDirectoryBrowse.addSelectionListener(new SelectionListener(){
+
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SINGLE);
+ String value = outputDirectoryText.getText();
+ if (value.trim().length() == 0) {
+ value = Platform.getLocation().toOSString();
+ }
+ dialog.setFilterPath(value);
+
+ String result = dialog.open();
+ if (result == null || result.trim().length() == 0) {
+ return;
+ }
+ outputDirectoryText.setText(result);
+
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+
Group sitesGroup = new Group(composite,SWT.NONE);
sitesGroup.setText(Messages.ProjectExamplesPreferencePage_Sites);
GridLayout gl = new GridLayout(2,false);
@@ -197,22 +247,26 @@
protected void performDefaults() {
showExperimentalSites.setSelection(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES_VALUE);
showInvalidSites.setSelection(ProjectExamplesActivator.SHOW_INVALID_SITES_VALUE);
+ outputDirectoryText.setText(""); //$NON-NLS-1$
sites.getUserSites().clear();
- storeSites();
+ storePreferences();
super.performDefaults();
}
@Override
public boolean performOk() {
- storeSites();
+ storePreferences();
return super.performOk();
}
- private void storeSites() {
+ private void storePreferences() {
IPreferenceStore store = ProjectExamplesActivator.getDefault().getPreferenceStore();
store.setValue(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES,
showExperimentalSites.getSelection());
store.setValue(ProjectExamplesActivator.SHOW_INVALID_SITES,
showInvalidSites.getSelection());
-
+ String value = outputDirectoryText.getText();
+ if (!value.isEmpty()) {
+ store.setValue(ProjectExamplesActivator.PROJECT_EXAMPLES_OUTPUT_DIRECTORY, value);
+ }
try {
String userSites = ProjectUtil.getAsXML(sites.getUserSites());
store.setValue(ProjectExamplesActivator.USER_SITES, userSites);
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/SiteDialog.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/SiteDialog.java 2011-11-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/preferences/SiteDialog.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -141,7 +141,7 @@
nameText.setText(selectedSite.getName());
}
Button browse = new Button(container,SWT.PUSH);
- browse.setText(Messages.SiteDialog_Browse);
+ browse.setText(Messages.Browse);
browse.addSelectionListener(new SelectionListener(){
public void widgetSelected(SelectionEvent e) {
Deleted:
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-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ImportDefaultMavenProjectExample.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -1,217 +0,0 @@
-package org.jboss.tools.project.examples.wizard;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-import java.util.zip.ZipFile;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
-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.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.internal.core.JavaProject;
-import org.eclipse.jdt.internal.core.OpenableElementInfo;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.dialogs.IOverwriteQuery;
-import org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider;
-import org.eclipse.ui.wizards.datatransfer.ImportOperation;
-import org.jboss.tools.project.examples.Messages;
-import org.jboss.tools.project.examples.ProjectExamplesActivator;
-import org.jboss.tools.project.examples.model.AbstractImportProjectExample;
-import org.jboss.tools.project.examples.model.Project;
-
-public class ImportDefaultMavenProjectExample extends
- AbstractImportProjectExample {
-
- private static final IOverwriteQuery OVERWRITE_ALL_QUERY = new IOverwriteQuery() {
- public String queryOverwrite(String pathString) {
- return IOverwriteQuery.ALL;
- }
- };
-
- @Override
- public boolean importProject(Project projectDescription, File file,
- IProgressMonitor monitor) throws Exception {
- List<Project> projects = new ArrayList<Project>();
- if (projectDescription.getIncludedProjects() == null) {
- boolean ret = importSingleProject(projectDescription, file, monitor);
- projects.add(projectDescription);
- return ret;
- } else {
- List<String> projectNames = projectDescription.getIncludedProjects();
- for (final String projectName : projectNames) {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IProject project = workspace.getRoot().getProject(projectName);
- final boolean[] ret = new boolean[1];
- if (project.exists()) {
- Display.getDefault().syncExec(new Runnable() {
-
- public void run() {
- ret[0] = MessageDialog.openQuestion(getActiveShell(),
- Messages.NewProjectExamplesWizard_Question,
NLS.bind(Messages.NewProjectExamplesWizard_OverwriteProject,
- projectName));
- }
-
- });
- if (!ret[0]) {
- return false;
- }
- project.delete(true, true, monitor);
- }
- project.create(monitor);
- project.open(monitor);
- ZipFile sourceFile = new ZipFile(file);
- ZipLeveledStructureProvider structureProvider = new ZipLeveledStructureProvider(
- sourceFile);
-
- Enumeration<? extends ZipEntry> entries = sourceFile.entries();
- ZipEntry entry = null;
- List<ZipEntry> filesToImport = new ArrayList<ZipEntry>();
- List<ZipEntry> directories = new ArrayList<ZipEntry>();
- String prefix = projectName + "/"; //$NON-NLS-1$
- while (entries.hasMoreElements()) {
- entry = entries.nextElement();
- if (entry.getName().startsWith(prefix)) {
- if (!entry.isDirectory()) {
- filesToImport.add(entry);
- } else {
- directories.add(entry);
- }
- }
- }
-
- structureProvider.setStrip(1);
- ImportOperation operation = new ImportOperation(project.getFullPath(),
structureProvider.getRoot(),
- structureProvider, OVERWRITE_ALL_QUERY, filesToImport);
- operation.setContext(getActiveShell());
- operation.run(monitor);
- for (ZipEntry directory:directories) {
- IPath resourcePath = new Path(directory.getName());
- try {
- if (resourcePath.segmentCount() > 1 &&
!workspace.getRoot().getFolder(resourcePath).exists()) {
- workspace.getRoot().getFolder(resourcePath).create(false, true, null);
- }
- } catch (Exception e) {
- ProjectExamplesActivator.log(e);
- return false;
- }
- }
- reconfigure(project, monitor);
- }
- }
- return true;
- }
-
- private boolean importSingleProject(Project projectDescription, File file,
- IProgressMonitor monitor) throws CoreException, ZipException,
- IOException, InvocationTargetException, InterruptedException {
- final String projectName = projectDescription.getName();
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- IProject project = workspace.getRoot().getProject(projectName);
- final boolean[] ret = new boolean[1];
- if (project.exists()) {
- Display.getDefault().syncExec(new Runnable() {
-
- public void run() {
- ret[0] = MessageDialog.openQuestion(getActiveShell(),
- Messages.NewProjectExamplesWizard_Question,
NLS.bind(Messages.NewProjectExamplesWizard_OverwriteProject,
- projectName));
- }
-
- });
- if (!ret[0]) {
- return false;
- }
- project.delete(true, true, monitor);
- }
- project.create(monitor);
- project.open(monitor);
- ZipFile sourceFile = new ZipFile(file);
- ZipLeveledStructureProvider structureProvider = new ZipLeveledStructureProvider(
- sourceFile);
-
- Enumeration<? extends ZipEntry> entries = sourceFile.entries();
- ZipEntry entry = null;
- List<ZipEntry> filesToImport = new ArrayList<ZipEntry>();
- List<ZipEntry> directories = new ArrayList<ZipEntry>();
- String prefix = projectName + "/"; //$NON-NLS-1$
- while (entries.hasMoreElements()) {
- entry = entries.nextElement();
- if (entry.getName().startsWith(prefix)) {
- if (!entry.isDirectory()) {
- filesToImport.add(entry);
- } else {
- directories.add(entry);
- }
- }
- }
-
- structureProvider.setStrip(1);
- ImportOperation operation = new ImportOperation(project.getFullPath(),
structureProvider.getRoot(),
- structureProvider, OVERWRITE_ALL_QUERY, filesToImport);
- operation.setContext(getActiveShell());
- operation.run(monitor);
- for (ZipEntry directory:directories) {
- IPath resourcePath = new Path(directory.getName());
- try {
- if (resourcePath.segmentCount() > 1 &&
!workspace.getRoot().getFolder(resourcePath).exists()) {
- workspace.getRoot().getFolder(resourcePath).create(false, true, null);
- }
- } catch (Exception e) {
- ProjectExamplesActivator.log(e);
- return false;
- }
- }
- reconfigure(project, monitor);
- return true;
- }
-
- private static Shell getActiveShell() {
- Display display = Display.getDefault();
- final Shell[] ret = new Shell[1];
- display.syncExec(new Runnable() {
-
- public void run() {
- ret[0] = Display.getCurrent().getActiveShell();
- }
-
- });
- return ret[0];
- }
-
- private static void reconfigure(IProject project, IProgressMonitor monitor) throws
CoreException {
- if (project == null || !project.exists() || !project.isOpen() ||
!project.hasNature(JavaCore.NATURE_ID)) {
- return;
- }
- project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
- IJavaProject javaProject = JavaCore.create(project);
- if (javaProject != null && javaProject.exists() && javaProject.isOpen()
&& javaProject instanceof JavaProject) {
- Object object = ((JavaProject) javaProject).getElementInfo();
- if (object instanceof OpenableElementInfo) {
- // copied from JavaProject.buildStructure(...)
- OpenableElementInfo info = (OpenableElementInfo) object;
- IClasspathEntry[] resolvedClasspath = ((JavaProject)
javaProject).getResolvedClasspath();
- IPackageFragmentRoot[] children = ((JavaProject)
javaProject).computePackageFragmentRoots(resolvedClasspath,false, null /* no reverse map
*/);
- info.setChildren(children);
- ((JavaProject) javaProject).getPerProjectInfo().rememberExternalLibTimestamps();
- }
- }
- }
-
-}
Copied:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ImportDefaultProjectExample.java
(from rev 36677,
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/ImportDefaultProjectExample.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ImportDefaultProjectExample.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -0,0 +1,229 @@
+package org.jboss.tools.project.examples.wizard;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+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.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.core.JavaProject;
+import org.eclipse.jdt.internal.core.OpenableElementInfo;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
+import org.jboss.tools.project.examples.Messages;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.AbstractImportProjectExample;
+import org.jboss.tools.project.examples.model.Project;
+
+public class ImportDefaultProjectExample extends
+ AbstractImportProjectExample {
+
+ private static final IOverwriteQuery OVERWRITE_ALL_QUERY = new IOverwriteQuery() {
+ public String queryOverwrite(String pathString) {
+ return IOverwriteQuery.ALL;
+ }
+ };
+
+ @Override
+ public boolean importProject(Project projectDescription, File file,
+ IProgressMonitor monitor) throws Exception {
+ List<Project> projects = new ArrayList<Project>();
+ if (projectDescription.getIncludedProjects() == null) {
+ boolean ret = importSingleProject(projectDescription, file, monitor);
+ projects.add(projectDescription);
+ return ret;
+ } else {
+ List<String> projectNames = projectDescription.getIncludedProjects();
+ for (final String projectName : projectNames) {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IProject project = workspace.getRoot().getProject(projectName);
+ final boolean[] ret = new boolean[1];
+ if (project.exists()) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ ret[0] = MessageDialog.openQuestion(getActiveShell(),
+ Messages.NewProjectExamplesWizard_Question,
NLS.bind(Messages.NewProjectExamplesWizard_OverwriteProject,
+ projectName));
+ }
+
+ });
+ if (!ret[0]) {
+ return false;
+ }
+ project.delete(true, true, monitor);
+ }
+ createProject(project, monitor);
+ project.open(monitor);
+ ZipFile sourceFile = new ZipFile(file);
+ ZipLeveledStructureProvider structureProvider = new ZipLeveledStructureProvider(
+ sourceFile);
+
+ Enumeration<? extends ZipEntry> entries = sourceFile.entries();
+ ZipEntry entry = null;
+ List<ZipEntry> filesToImport = new ArrayList<ZipEntry>();
+ List<ZipEntry> directories = new ArrayList<ZipEntry>();
+ String prefix = projectName + "/"; //$NON-NLS-1$
+ while (entries.hasMoreElements()) {
+ entry = entries.nextElement();
+ if (entry.getName().startsWith(prefix)) {
+ if (!entry.isDirectory()) {
+ filesToImport.add(entry);
+ } else {
+ directories.add(entry);
+ }
+ }
+ }
+
+ structureProvider.setStrip(1);
+ ImportOperation operation = new ImportOperation(project.getFullPath(),
structureProvider.getRoot(),
+ structureProvider, OVERWRITE_ALL_QUERY, filesToImport);
+ operation.setContext(getActiveShell());
+ operation.run(monitor);
+ for (ZipEntry directory:directories) {
+ IPath resourcePath = new Path(directory.getName());
+ try {
+ if (resourcePath.segmentCount() > 1 &&
!workspace.getRoot().getFolder(resourcePath).exists()) {
+ workspace.getRoot().getFolder(resourcePath).create(false, true, null);
+ }
+ } catch (Exception e) {
+ ProjectExamplesActivator.log(e);
+ return false;
+ }
+ }
+ reconfigure(project, monitor);
+ }
+ }
+ return true;
+ }
+
+ private void createProject(IProject project, IProgressMonitor monitor) throws
CoreException {
+ IPath location = getLocation();
+ if (!Platform.getLocation().equals(location)) {
+ IProjectDescription desc =
project.getWorkspace().newProjectDescription(project.getName());
+ desc.setLocation(location.append(project.getName()));
+ project.create(desc, monitor);
+ } else
+ project.create(monitor);
+ }
+
+ private boolean importSingleProject(Project projectDescription, File file,
+ IProgressMonitor monitor) throws CoreException, ZipException,
+ IOException, InvocationTargetException, InterruptedException {
+ final String projectName = projectDescription.getName();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IProject project = workspace.getRoot().getProject(projectName);
+ final boolean[] ret = new boolean[1];
+ if (project.exists()) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ ret[0] = MessageDialog.openQuestion(getActiveShell(),
+ Messages.NewProjectExamplesWizard_Question,
NLS.bind(Messages.NewProjectExamplesWizard_OverwriteProject,
+ projectName));
+ }
+
+ });
+ if (!ret[0]) {
+ return false;
+ }
+ project.delete(true, true, monitor);
+ }
+ createProject(project, monitor);
+ project.open(monitor);
+ ZipFile sourceFile = new ZipFile(file);
+ ZipLeveledStructureProvider structureProvider = new ZipLeveledStructureProvider(
+ sourceFile);
+
+ Enumeration<? extends ZipEntry> entries = sourceFile.entries();
+ ZipEntry entry = null;
+ List<ZipEntry> filesToImport = new ArrayList<ZipEntry>();
+ List<ZipEntry> directories = new ArrayList<ZipEntry>();
+ String prefix = projectName + "/"; //$NON-NLS-1$
+ while (entries.hasMoreElements()) {
+ entry = entries.nextElement();
+ if (entry.getName().startsWith(prefix)) {
+ if (!entry.isDirectory()) {
+ filesToImport.add(entry);
+ } else {
+ directories.add(entry);
+ }
+ }
+ }
+
+ structureProvider.setStrip(1);
+ ImportOperation operation = new ImportOperation(project.getFullPath(),
structureProvider.getRoot(),
+ structureProvider, OVERWRITE_ALL_QUERY, filesToImport);
+ operation.setContext(getActiveShell());
+ operation.run(monitor);
+ for (ZipEntry directory:directories) {
+ IPath resourcePath = new Path(directory.getName());
+ try {
+ if (resourcePath.segmentCount() > 1 &&
!workspace.getRoot().getFolder(resourcePath).exists()) {
+ workspace.getRoot().getFolder(resourcePath).create(false, true, null);
+ }
+ } catch (Exception e) {
+ ProjectExamplesActivator.log(e);
+ return false;
+ }
+ }
+ reconfigure(project, monitor);
+ return true;
+ }
+
+ private static Shell getActiveShell() {
+ Display display = Display.getDefault();
+ final Shell[] ret = new Shell[1];
+ display.syncExec(new Runnable() {
+
+ public void run() {
+ ret[0] = Display.getCurrent().getActiveShell();
+ }
+
+ });
+ return ret[0];
+ }
+
+ private static void reconfigure(IProject project, IProgressMonitor monitor) throws
CoreException {
+ if (project == null || !project.exists() || !project.isOpen() ||
!project.hasNature(JavaCore.NATURE_ID)) {
+ return;
+ }
+ project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ IJavaProject javaProject = JavaCore.create(project);
+ if (javaProject != null && javaProject.exists() && javaProject.isOpen()
&& javaProject instanceof JavaProject) {
+ Object object = ((JavaProject) javaProject).getElementInfo();
+ if (object instanceof OpenableElementInfo) {
+ // copied from JavaProject.buildStructure(...)
+ OpenableElementInfo info = (OpenableElementInfo) object;
+ IClasspathEntry[] resolvedClasspath = ((JavaProject)
javaProject).getResolvedClasspath();
+ IPackageFragmentRoot[] children = ((JavaProject)
javaProject).computePackageFragmentRoots(resolvedClasspath,false, null /* no reverse map
*/);
+ info.setChildren(children);
+ ((JavaProject) javaProject).getPerProjectInfo().rememberExternalLibTimestamps();
+ }
+ }
+ }
+
+}
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-28
09:20:58 UTC (rev 36686)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -37,6 +37,8 @@
selectedProject, monitor);
if (success) {
projects.add(selectedProject);
+ } else {
+ return Status.CANCEL_STATUS;
}
}
try {
@@ -53,10 +55,12 @@
"Cannot import a project of the '" + project.getImportType() +
"' type.");
}
});
- return Status.OK_STATUS;
+ return Status.CANCEL_STATUS;
}
if (importProjectExample.importProject(project, project.getFile(), monitor)) {
importProjectExample.fix(project, monitor);
+ } else {
+ return Status.CANCEL_STATUS;
}
}
} catch (final Exception e) {
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-28
09:20:58 UTC (rev 36686)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -19,11 +19,13 @@
import java.util.List;
import java.util.Set;
-import org.eclipse.core.resources.IWorkspaceRoot;
+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.core.runtime.jobs.Job;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.m2e.core.MavenPlugin;
@@ -31,6 +33,7 @@
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.UpdateConfigurationJob;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jboss.tools.maven.project.examples.wizard.ArchetypeExamplesWizard;
@@ -49,11 +52,8 @@
final IProgressMonitor monitor) throws Exception {
List<Project> projects = new ArrayList<Project>();
projects.add(projectDescription);
- final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
- IPath rootPath = workspaceRoot.getLocation();
- IPath mavenProjectsRoot = rootPath;
- IPath path = mavenProjectsRoot;
- final File destination = new File(path.toOSString());
+ final IPath location = getLocation();
+ final File destination = new File(location.toOSString());
final boolean[] ret = new boolean[1];
ret[0] = true;
@@ -76,14 +76,13 @@
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(), //
+ location.toFile(), //
projectFolder, true, mavenModelManager);
try {
scanner.run(monitor);
@@ -95,6 +94,7 @@
Set<MavenProjectInfo> projectSet = collectProjects(scanner
.getProjects());
ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration();
+
for (MavenProjectInfo info : projectSet) {
try {
projectName = MavenProjectExamplesActivator
@@ -107,6 +107,35 @@
ret[0] = false;
}
}
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (project != null && project.isAccessible()) {
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ } catch (CoreException e) {
+ // ignore
+ }
+ }
+ if (includedProjects.size() > 0) {
+ IProject[] selectedProjects = new IProject[includedProjects.size()];
+ int i = 0;
+
+ for (String selectedProjectName:includedProjects) {
+ project =
ResourcesPlugin.getWorkspace().getRoot().getProject(selectedProjectName);
+ selectedProjects[i++] = project;
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ } catch (CoreException e) {
+ // ignore
+ }
+ }
+ Job updateJob = new UpdateConfigurationJob(selectedProjects , true, false);
+ updateJob.schedule();
+ try {
+ updateJob.join();
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
}
});
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-28
09:20:58 UTC (rev 36686)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenProjectExample.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -18,15 +18,12 @@
import org.apache.maven.model.Model;
import org.eclipse.core.resources.IProject;
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.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.embedder.MavenModelManager;
import org.eclipse.m2e.core.project.AbstractProjectScanner;
import org.eclipse.m2e.core.project.LocalProjectScanner;
@@ -54,8 +51,7 @@
IProgressMonitor monitor) throws Exception {
List<Project> projects = new ArrayList<Project>();
projects.add(projectDescription);
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
- IPath rootPath = workspaceRoot.getLocation();
+ IPath rootPath = getLocation();
IPath mavenProjectsRoot = rootPath;
String projectName = projectDescription.getName();
if (projectName == null || projectName.isEmpty()) {
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-28
09:20:58 UTC (rev 36686)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizard.java 2011-11-28
09:59:41 UTC (rev 36687)
@@ -23,6 +23,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
@@ -32,6 +33,7 @@
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.jboss.tools.maven.project.examples.MavenProjectExamplesActivator;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.model.Project;
/**
@@ -99,10 +101,13 @@
try {
getContainer().run(true, false, op);
} catch (InterruptedException e) {
- return false;
+ ProjectExamplesActivator.log(e);
+ return true;
} catch (InvocationTargetException e) {
-
- return false;
+ ProjectExamplesActivator.log(e);
+ Throwable ex = e.getTargetException();
+ MessageDialog.openError(getShell(), "Error", ex.getMessage());
+ return true;
}
return true;