Author: fbricon
Date: 2012-10-03 08:50:06 -0400 (Wed, 03 Oct 2012)
New Revision: 44237
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/AbstractReferenceConversionParticipant.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ComponentReferenceConversionParticipant.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ProjectClasspathConversionParticipant.java
Removed:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.xml
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 Use refactoring API to delete converted dependencies
Modified: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF 2012-10-03
12:25:41 UTC (rev 44236)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF 2012-10-03
12:50:06 UTC (rev 44237)
@@ -15,7 +15,9 @@
org.eclipse.m2e.core.ui;bundle-version="1.1.0",
org.jboss.tools.maven.core;bundle-version="1.4.0",
org.jboss.tools.maven.ui;bundle-version="1.4.0",
- org.eclipse.wst.common.emfworkbench.integration
+ org.eclipse.wst.common.emfworkbench.integration,
+ org.eclipse.ltk.core.refactoring,
+ org.eclipse.ltk.ui.refactoring
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: %BundleVendor
Bundle-Localization: plugin
Modified: trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.xml 2012-10-03 12:25:41
UTC (rev 44236)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.xml 2012-10-03 12:50:06
UTC (rev 44237)
@@ -38,13 +38,13 @@
<extension
point="org.eclipse.m2e.core.projectConversionParticipants">
<projectConversionParticipant
-
class="org.jboss.tools.maven.conversion.ui.internal.ClasspathConversionParticipant"
+
class="org.jboss.tools.maven.conversion.ui.internal.ProjectClasspathConversionParticipant"
id="org.jboss.tools.maven.conversion.ui.ClasspathConversionParticipant"
name="Classpath conversion participant"
nature="org.eclipse.jdt.core.javanature">
</projectConversionParticipant>
<projectConversionParticipant
-
class="org.jboss.tools.maven.conversion.ui.internal.ClasspathConversionParticipant"
+
class="org.jboss.tools.maven.conversion.ui.internal.ComponentReferenceConversionParticipant"
id="org.jboss.tools.maven.conversion.ui.ModuleConversionParticipant"
name="EAR conversion participant"
nature="org.eclipse.wst.common.modulecore.ModuleCoreNature">
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-03
12:25:41 UTC (rev 44236)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java 2012-10-03
12:50:06 UTC (rev 44237)
@@ -14,7 +14,10 @@
import org.apache.maven.model.Dependency;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
+import org.eclipse.ltk.ui.refactoring.resource.DeleteResourcesWizard;
import org.jboss.tools.maven.conversion.core.ProjectDependency;
/**
@@ -29,11 +32,12 @@
private List<ProjectDependency> entries;
- IdentifyMavenDependencyPage identificationPage;
+ private IdentifyMavenDependencyPage identificationPage;
private List<Dependency> dependencies;
public ConvertToMavenDependencyWizard(IProject project, List<ProjectDependency>
projectDependencies) {
+ System.err.println("New wizard");
this.project = project;
this.entries = projectDependencies;
String title = "Convert to Maven ";
@@ -50,8 +54,6 @@
public void addPages() {
identificationPage = new IdentifyMavenDependencyPage(project, entries);
addPage(identificationPage);
- //DependencyConversionPreviewPage page2 = new
DependencyConversionPreviewPage("Foo");
- //addPage(page2);
}
@Override
@@ -67,14 +69,16 @@
dependencies = identificationPage.getDependencies();
if (identificationPage.isDeleteJars()) {
- /* actually only delete classpath entries */
- DeleteExistingJarsJob deleteJob = new DeleteExistingJarsJob(project, entries);
- deleteJob.schedule();
- try {
- deleteJob.join();//wait for job to finish to prevent bad concurrency issues
- } catch (InterruptedException e) {
- e.printStackTrace();
- //ignore
+ //Only delete jars that are directly under a project's hierarchy
+ IResource[] resourcesToDelete = identificationPage.getResourcesToDelete();
+ if (resourcesToDelete != null && resourcesToDelete.length > 0) {
+ DeleteResourcesWizard wizard = new DeleteResourcesWizard(resourcesToDelete);
+ try {
+ RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
+ op.run(getShell(), "Delete project relative jars");
+ } catch(InterruptedException e) {
+ // ignored
+ }
}
}
}
@@ -82,10 +86,8 @@
return true;
}
-
public List<Dependency> getDependencies() {
return dependencies;
}
-
}
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-03
12:25:41 UTC (rev 44236)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java 2012-10-03
12:50:06 UTC (rev 44237)
@@ -20,8 +20,13 @@
import java.util.concurrent.ConcurrentHashMap;
import org.apache.maven.model.Dependency;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+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.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
@@ -74,12 +79,6 @@
public class IdentifyMavenDependencyPage extends WizardPage {
- /*
- private static final String SOURCE_PROPERTY = "SOURCE_PROPERTY";
-
- private static final String DEPENDENCY_PROPERTY = "DEPENDENCY_PROPERTY";
- */
-
private static final int DEPENDENCY_COLUMN = 2;
private Map<ProjectDependency, Dependency> dependencyMap;
@@ -103,7 +102,7 @@
private Button deleteJarsBtn;
- private boolean deleteJars;
+ private boolean deleteJars = true;
private Button startIdentification;
@@ -265,7 +264,7 @@
@Override
public String getToolTipText(Object element) {
ProjectDependency projectDependency = (ProjectDependency) element;
- if (projectDependency.getDependencyKind() == DependencyKind.Project) {
+ if (projectDependency.getDependencyKind() != DependencyKind.Archive) {
return "";
}
try {
@@ -602,21 +601,30 @@
}
public List<Dependency> getDependencies() {
+ List<ProjectDependency> checkedProjectDependencies =
getCheckedProjectDependencies();
+ List<Dependency> dependencies = new
ArrayList<Dependency>(checkedProjectDependencies.size());
+ for (ProjectDependency projectDep : checkedProjectDependencies) {
+ Dependency d = dependencyMap.get(projectDep);
+ if (d != null) {
+ dependencies.add(d);
+ }
+ }
+ return dependencies;
+ }
+
+ public List<ProjectDependency> getCheckedProjectDependencies() {
if (dependenciesViewer == null || dependenciesViewer.getTable().isDisposed()) {
return Collections.emptyList();
}
Object[] selection = dependenciesViewer.getCheckedElements();
- List<Dependency> dependencies = new
ArrayList<Dependency>(selection.length);
+ List<ProjectDependency> selectedDeps = new
ArrayList<ProjectDependency>(selection.length);
for (Object o : selection) {
ProjectDependency projectDep = (ProjectDependency) o;
- Dependency d = dependencyMap.get(projectDep);
- if (d != null) {
- dependencies.add(d);
- }
+ selectedDeps.add(projectDep);
}
- return dependencies;
+ return selectedDeps;
}
-
+
public boolean isDeleteJars() {
return deleteJars;
}
@@ -678,4 +686,23 @@
job.cancel();
}
}
+
+ public IResource[] getResourcesToDelete() {
+ List<IResource> resources = new
ArrayList<IResource>(dependencyMap.size());
+ IPath projectPath = project.getLocation();
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ for (ProjectDependency pd : dependencyMap.keySet()) {
+ if (pd.getDependencyKind() == DependencyKind.Archive) {
+ IPath p = pd.getPath();
+ if (projectPath.isPrefixOf(p)) {
+ p = p.removeFirstSegments(projectPath.segmentCount() -1);
+ }
+ IFile f = root.getFile(p);
+ if (f.exists() && project.equals(f.getProject())) {
+ resources.add(f);
+ }
+ }
+ }
+ return resources.toArray(new IResource[0]);
+ }
}
Copied:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/AbstractReferenceConversionParticipant.java
(from rev 44218,
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java)
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/AbstractReferenceConversionParticipant.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/AbstractReferenceConversionParticipant.java 2012-10-03
12:50:06 UTC (rev 44237)
@@ -0,0 +1,71 @@
+/*************************************************************************************
+ * 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;
+
+import java.util.List;
+
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.m2e.core.project.conversion.AbstractProjectConversionParticipant;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.maven.conversion.core.DependencyCollector;
+import org.jboss.tools.maven.conversion.core.ProjectDependency;
+import org.jboss.tools.maven.conversion.ui.dialog.ConvertToMavenDependencyWizard;
+
+public abstract class AbstractReferenceConversionParticipant extends
+ AbstractProjectConversionParticipant {
+
+ private DependencyCollector dependencyCollector;
+
+ public AbstractReferenceConversionParticipant(DependencyCollector dependencyCollector)
{
+ this.dependencyCollector = dependencyCollector;
+ }
+
+ @Override
+ public boolean accept(IProject project) throws CoreException {
+ return dependencyCollector != null && dependencyCollector.appliesTo(project);
+ }
+
+ @Override
+ public void convert(final IProject project, final Model model, final IProgressMonitor
monitor)
+ throws CoreException {
+
+ if (dependencyCollector != null && dependencyCollector.appliesTo(project)) {
+ List<ProjectDependency> entries =
dependencyCollector.collectDependencies(project);
+ if (entries == null || entries.isEmpty()) {
+ return;
+ }
+ final ConvertToMavenDependencyWizard conversionWizard = new
ConvertToMavenDependencyWizard(project, entries);
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ WizardDialog dialog = new WizardDialog(shell, conversionWizard);
+ if (dialog.open() == Window.OK) {
+ List<Dependency> dependencies = conversionWizard.getDependencies();
+ if (dependencies != null && !dependencies.isEmpty()) {
+ model.setDependencies(dependencies);
+ }
+ }
+ }
+ });
+ }
+ }
+
+}
Deleted:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java 2012-10-03
12:25:41 UTC (rev 44236)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java 2012-10-03
12:50:06 UTC (rev 44237)
@@ -1,72 +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.internal;
-
-import java.util.List;
-
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.Model;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.m2e.core.project.conversion.AbstractProjectConversionParticipant;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.jboss.tools.maven.conversion.core.DependencyCollector;
-import org.jboss.tools.maven.conversion.core.DependencyCollectorFactory;
-import org.jboss.tools.maven.conversion.core.ProjectDependency;
-import org.jboss.tools.maven.conversion.ui.dialog.ConvertToMavenDependencyWizard;
-
-public class ClasspathConversionParticipant extends
- AbstractProjectConversionParticipant {
-
- @Override
- public boolean accept(IProject project) throws CoreException {
- return getDependencyCollector(project) != null;
- }
-
- private DependencyCollector getDependencyCollector(IProject project) throws
CoreException {
- return DependencyCollectorFactory.INSTANCE.getDependencyCollector(project);
- }
-
- @Override
- public void convert(final IProject project, final Model model, final IProgressMonitor
monitor)
- throws CoreException {
-
- DependencyCollector dependencyCollector = getDependencyCollector(project);
- if (dependencyCollector != null) {
- List<ProjectDependency> entries =
dependencyCollector.collectDependencies(project);
- if (entries == null || entries.isEmpty()) {
- return;
- }
- final ConvertToMavenDependencyWizard conversionWizard = new
ConvertToMavenDependencyWizard(project, entries);
- Display.getDefault().syncExec(new Runnable() {
-
- @Override
- public void run() {
- // TODO Auto-generated method stub
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- WizardDialog dialog = new WizardDialog(shell, conversionWizard);
- if (dialog.open() == Window.OK) {
- List<Dependency> dependencies = conversionWizard.getDependencies();
- if (dependencies != null && !dependencies.isEmpty()) {
- model.setDependencies(dependencies);
- }
- }
- }
- });
- }
- }
-
-}
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ComponentReferenceConversionParticipant.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ComponentReferenceConversionParticipant.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ComponentReferenceConversionParticipant.java 2012-10-03
12:50:06 UTC (rev 44237)
@@ -0,0 +1,11 @@
+package org.jboss.tools.maven.conversion.ui.internal;
+
+import org.jboss.tools.maven.conversion.core.internal.ComponentDependencyCollector;
+
+public class ComponentReferenceConversionParticipant extends
AbstractReferenceConversionParticipant {
+
+ public ComponentReferenceConversionParticipant() {
+ super(new ComponentDependencyCollector());
+ }
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ProjectClasspathConversionParticipant.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ProjectClasspathConversionParticipant.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ProjectClasspathConversionParticipant.java 2012-10-03
12:50:06 UTC (rev 44237)
@@ -0,0 +1,11 @@
+package org.jboss.tools.maven.conversion.ui.internal;
+
+import org.jboss.tools.maven.conversion.core.internal.JavaDependencyCollector;
+
+public class ProjectClasspathConversionParticipant extends
AbstractReferenceConversionParticipant {
+
+ public ProjectClasspathConversionParticipant() {
+ super(new JavaDependencyCollector());
+ }
+
+}