Author: fbricon
Date: 2012-10-04 11:46:44 -0400 (Thu, 04 Oct 2012)
New Revision: 44302
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/jobs/DeleteExistingClasspathEntriesJob.java
Removed:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DeleteExistingJarsJob.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DependencyConversionPreviewPage.java
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java
Log:
JBIDE-12529 delete all non (source / JRE / Maven) classpath entries
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java 2012-10-04
14:59:00 UTC (rev 44301)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java 2012-10-04
15:46:44 UTC (rev 44302)
@@ -15,14 +15,11 @@
import org.apache.maven.model.Dependency;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaDeleteProcessor;
-import org.eclipse.jdt.internal.ui.refactoring.reorg.DeleteUserInterfaceManager;
-import org.eclipse.jdt.ui.refactoring.RefactoringSaveHelper;
import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.ltk.core.refactoring.Refactoring;
-import org.eclipse.ltk.core.refactoring.participants.DeleteRefactoring;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
+import org.eclipse.ltk.ui.refactoring.resource.DeleteResourcesWizard;
import org.jboss.tools.maven.conversion.core.ProjectDependency;
+import
org.jboss.tools.maven.conversion.ui.internal.jobs.DeleteExistingClasspathEntriesJob;
/**
* Convert project dependencies to Maven dependencies wizard
@@ -66,20 +63,33 @@
}
+ @SuppressWarnings("restriction")
@Override
public boolean performFinish() {
if (identificationPage != null) {
dependencies = identificationPage.getDependencies();
if (identificationPage.isDeleteJars()) {
+ /* Delete classpath entries of Java Projects*/
+ //FIXME use Refactoring API for that!!!
+ DeleteExistingClasspathEntriesJob deleteJob = new
DeleteExistingClasspathEntriesJob(project);
+ deleteJob.schedule();
+ try {
+ deleteJob.join();//wait for job to finish to prevent bad concurrency issues
+ } catch (InterruptedException e) {
+ //ignore
+ }
+
//Only delete jars that are directly under a project's hierarchy
IResource[] resourcesToDelete = identificationPage.getResourcesToDelete();
if (resourcesToDelete != null && resourcesToDelete.length > 0) {
+ //Use refactoring API to delete jars
+ DeleteResourcesWizard wizard = new DeleteResourcesWizard(resourcesToDelete);
try {
- Refactoring refactoring= new DeleteRefactoring(new
JavaDeleteProcessor(resourcesToDelete));
- DeleteUserInterfaceManager.getDefault().getStarter(refactoring).activate(refactoring,
getShell(), RefactoringSaveHelper.SAVE_NOTHING);
- } catch (CoreException e) {
- e.printStackTrace();
+ RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
+ op.run(getShell(), "Delete project relative jars");
+ } catch(InterruptedException e) {
+ // ignore
}
}
}
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DeleteExistingJarsJob.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DeleteExistingJarsJob.java 2012-10-04
14:59:00 UTC (rev 44301)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DeleteExistingJarsJob.java 2012-10-04
15:46:44 UTC (rev 44302)
@@ -1,150 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2012 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.conversion.ui.dialog;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-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.MultiStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.jboss.tools.maven.conversion.core.ProjectDependency;
-import org.jboss.tools.maven.conversion.ui.dialog.xpl.ConversionUtils;
-import org.jboss.tools.maven.core.MavenCoreActivator;
-
-public class DeleteExistingJarsJob extends Job {
-
- private Set<IClasspathEntry> entries;
-
- private IJavaProject javaProject;
-
- public DeleteExistingJarsJob(IProject project, List<ProjectDependency> entries2)
{
- super("Delete classpath entries"
- + ((project == null) ? "" : "for " + project.getName()));
- this.javaProject = JavaCore.create(project);
- this.entries = toClasspathEntries(entries2);
- }
-
- private Set<IClasspathEntry> toClasspathEntries(List<ProjectDependency>
entries2) {
- return null;
- }
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- if (entries == null) {
- return Status.OK_STATUS;
- }
- Set<IPath> pathsToRemove = new HashSet<IPath>();
- Set<IFile> filesToRemove = new HashSet<IFile>();
- try {
-
- for (IClasspathEntry e : entries) {
- collectDeletableEntries(e, pathsToRemove, filesToRemove);
- }
-
- updateClasspath(pathsToRemove, monitor);
- /* Need to use the refactoring API
- deleteFiles(filesToRemove, monitor);
- */
-
- } catch (CoreException e) {
- return new Status(IStatus.ERROR, MavenCoreActivator.PLUGIN_ID, "Unable to delete
classpath entries", e);
- }
-
- return Status.OK_STATUS;
- }
-
- private void deleteFiles(Set<IFile> filesToRemove, IProgressMonitor monitor)
- throws CoreException {
- List<IStatus> exceptions = new ArrayList<IStatus>();
- for (IFile f : filesToRemove) {
- if (f.exists()) {
- try {
- f.delete(true, monitor);
- } catch (CoreException e) {
- exceptions.add(new Status(Status.ERROR, MavenCoreActivator.PLUGIN_ID, 0,
"Unable to delete "+f.getFullPath(), e));
- }
- }
- }
-
- if (!exceptions.isEmpty()) {
- IStatus[] statuses = new IStatus[exceptions.size()];
- exceptions.toArray(statuses);
- IStatus status = new MultiStatus(MavenCoreActivator.PLUGIN_ID, Status.ERROR, statuses
,"Unable to delete files", null);
- throw new CoreException(status );
- }
- }
-
- private void updateClasspath(Set<IPath> pathsToRemove, IProgressMonitor monitor)
throws CoreException {
- if (pathsToRemove.isEmpty()) {
- return;
- }
- ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
- for (IClasspathEntry entry : javaProject.getRawClasspath()) {
- if (!pathsToRemove.contains(entry.getPath())) {
- newEntries.add(entry);
- }
- }
- javaProject.setRawClasspath(
- newEntries.toArray(new IClasspathEntry[newEntries.size()]),
- null);
- }
-
- private void collectDeletableEntries(IClasspathEntry entry,
- Set<IPath> pathsToRemove, Set<IFile> filesToRemove)
- throws CoreException {
- if ((entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
- && entry.getPath() != null)) {
-
- if (pathsToRemove != null) {
- pathsToRemove.add(entry.getPath());
- }
-
- if (filesToRemove != null) {
- IFile f = ConversionUtils.getIFile(entry);
- if (f != null && f.exists()
- && javaProject.getProject().equals(f.getProject())) {
- filesToRemove.add(f);
- }
- }
- return;
- }
-
- if (pathsToRemove == null) {
- return;
- }
- if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
- IPath path = entry.getPath();
- pathsToRemove.add(path);
- IClasspathContainer container = JavaCore.getClasspathContainer( path, javaProject);
- if (container != null) {
- IClasspathEntry[] cpes = container.getClasspathEntries();
- if (cpes != null && cpes.length > 0) {
- collectDeletableEntries(entry, null, filesToRemove);
- }
- }
- }
- // TODO handle other entry kinds
- }
-
-}
\ No newline at end of file
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DependencyConversionPreviewPage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DependencyConversionPreviewPage.java 2012-10-04
14:59:00 UTC (rev 44301)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DependencyConversionPreviewPage.java 2012-10-04
15:46:44 UTC (rev 44302)
@@ -1,57 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2012 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.conversion.ui.dialog;
-
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-
-public class DependencyConversionPreviewPage extends WizardPage {
-
- private Button deleteJarsBtn;
-
- private boolean deleteJars;
-
- protected DependencyConversionPreviewPage(String pageName) {
- super(pageName);
- }
-
- @Override
- public void createControl(Composite parent) {
- Composite container = new Composite(parent, SWT.NONE);
- container.setEnabled(true);
- setControl(container);
-
- deleteJarsBtn = addCheckButton(container, "Delete local project jars after
conversion", deleteJars);
-
- }
-
- private Button addCheckButton(Composite container, String label,
- boolean selected) {
- Button checkBtn = new Button(container, SWT.CHECK);
- checkBtn.setText(label);
- checkBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
- checkBtn.setSelection(selected);
- return checkBtn;
- }
-
- @Override
- public boolean isPageComplete() {
- return false;
- }
-
- public boolean isDeleteJars() {
- return deleteJars;
- }
-
-}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java 2012-10-04
14:59:00 UTC (rev 44301)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java 2012-10-04
15:46:44 UTC (rev 44302)
@@ -33,6 +33,8 @@
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.DialogSettings;
+import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -112,6 +114,8 @@
private Link warningLink;
+ private IDialogSettings dialogSettings;
+
private static String MESSAGE = "Identify existing project references as Maven
dependencies. Double-click on a Maven dependency to edit its details";
@@ -120,6 +124,7 @@
this.project = project;
initialEntries = Collections.unmodifiableList(entries);
initDependencyMap();
+ initDialogSettings();
}
private void initDependencyMap() {
@@ -128,8 +133,29 @@
dependencyMap.put(entry, null);
}
}
+
+ /** Loads the dialog settings using the page name as a section name. */
+ private void initDialogSettings() {
+ IDialogSettings pluginSettings;
+
+ // This is strictly to get SWT Designer working locally without blowing up.
+ if( MavenDependencyConversionActivator.getDefault() == null ) {
+ pluginSettings = new DialogSettings("Workbench");
+ }
+ else {
+ pluginSettings =
MavenDependencyConversionActivator.getDefault().getDialogSettings();
+ }
+
+ dialogSettings = pluginSettings.getSection(getName());
+ if(dialogSettings == null) {
+ dialogSettings = pluginSettings.addNewSection(getName());
+ pluginSettings.addSection(dialogSettings);
+ }
+ }
public void dispose() {
+
+ dialogSettings.put("isDeleteJars", isDeleteJars());
if (jarImage != null) jarImage.dispose();
if (okImage != null) okImage.dispose();
if (projectImage != null) projectImage.dispose();
@@ -209,6 +235,7 @@
}
});
+ deleteJars = dialogSettings.getBoolean("isDeleteJars");
deleteJarsBtn = addCheckButton(container, "Delete original references from
project", deleteJars);
deleteJarsBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Copied:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/jobs/DeleteExistingClasspathEntriesJob.java
(from rev 44218,
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DeleteExistingJarsJob.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/jobs/DeleteExistingClasspathEntriesJob.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/jobs/DeleteExistingClasspathEntriesJob.java 2012-10-04
15:46:44 UTC (rev 44302)
@@ -0,0 +1,78 @@
+/*************************************************************************************
+ * Copyright (c) 2012 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.conversion.ui.internal.jobs;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+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.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
+import org.jboss.tools.maven.conversion.ui.internal.MavenDependencyConversionActivator;
+
+public class DeleteExistingClasspathEntriesJob extends Job {
+
+ private IProject project;
+
+ public DeleteExistingClasspathEntriesJob(IProject project) {
+ super("Delete classpath entries"
+ + ((project == null) ? "" : "for " + project.getName()));
+ this.project = project;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ if (!project.hasNature(JavaCore.NATURE_ID)) {
+ return Status.OK_STATUS;
+ }
+ } catch (CoreException ignore) {
+ return Status.OK_STATUS;
+ }
+ IJavaProject javaProject = JavaCore.create(project);
+ if(javaProject != null) {
+ // remove classpatch containers from JavaProject
+ try {
+ ArrayList<IClasspathEntry> newEntries = new
ArrayList<IClasspathEntry>();
+ for(IClasspathEntry entry : javaProject.getRawClasspath()) {
+ //Keep Source/ JRE / Maven containers
+ if(isKept(entry)) {
+ newEntries.add(entry);
+ }
+ }
+ javaProject.setRawClasspath(newEntries.toArray(new
IClasspathEntry[newEntries.size()]), monitor);
+ } catch (JavaModelException e) {
+ IStatus error = new Status(IStatus.ERROR,
MavenDependencyConversionActivator.PLUGIN_ID, "Unable to update classpath", e);
+ return error;
+ }
+ }
+
+ return Status.OK_STATUS;
+ }
+
+
+ private boolean isKept(IClasspathEntry cpe) {
+ if(IClasspathEntry.CPE_SOURCE == cpe.getEntryKind() ||
+ (IClasspathEntry.CPE_CONTAINER == cpe.getEntryKind()
+ &&
("org.eclipse.jdt.launching.JRE_CONTAINER".equals(cpe.getPath().segment(0))
+ || MavenClasspathHelpers.isMaven2ClasspathContainer(cpe.getPath())))) {
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file