Author: fbricon
Date: 2012-10-02 10:37:38 -0400 (Tue, 02 Oct 2012)
New Revision: 44218
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/DependencyCollector.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/DependencyCollectorFactory.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/ProjectDependency.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/ComponentDependency.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/ComponentDependencyCollector.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/JavaDependency.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/JavaDependencyCollector.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/DeleteExistingJarsJob.java
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/xpl/ConversionUtils.java
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/ConvertToMavenDependencyHandler.java
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/jobs/IdentifyProjectJob.java
Log:
JBIDE-12527 : convert EAR references
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-02
14:17:39 UTC (rev 44217)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/META-INF/MANIFEST.MF 2012-10-02
14:37:38 UTC (rev 44218)
@@ -14,7 +14,8 @@
org.eclipse.ui.ide;bundle-version="3.7.0",
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.jboss.tools.maven.ui;bundle-version="1.4.0",
+ org.eclipse.wst.common.emfworkbench.integration
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-02 14:17:39
UTC (rev 44217)
+++ trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/plugin.xml 2012-10-02 14:37:38
UTC (rev 44218)
@@ -39,9 +39,16 @@
point="org.eclipse.m2e.core.projectConversionParticipants">
<projectConversionParticipant
class="org.jboss.tools.maven.conversion.ui.internal.ClasspathConversionParticipant"
-
id="org.jboss.tools.maven.conversion.ui.internal.ClasspathConversionParticipant"
+
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"
+
id="org.jboss.tools.maven.conversion.ui.ModuleConversionParticipant"
+ name="EAR conversion participant"
+ nature="org.eclipse.wst.common.modulecore.ModuleCoreNature">
+ </projectConversionParticipant>
</extension>
+
</plugin>
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/DependencyCollector.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/DependencyCollector.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/DependencyCollector.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -0,0 +1,23 @@
+/*************************************************************************************
+ * 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.core;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+
+public abstract class DependencyCollector {
+
+ public abstract List<ProjectDependency> collectDependencies(IProject project)
throws CoreException;
+
+ public abstract boolean appliesTo(IProject project) throws CoreException;
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/DependencyCollectorFactory.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/DependencyCollectorFactory.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/DependencyCollectorFactory.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -0,0 +1,45 @@
+/*************************************************************************************
+ * 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.core;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.jboss.tools.maven.conversion.core.internal.ComponentDependencyCollector;
+import org.jboss.tools.maven.conversion.core.internal.JavaDependencyCollector;
+
+public class DependencyCollectorFactory {
+
+ public static DependencyCollectorFactory INSTANCE = new DependencyCollectorFactory();
+
+ Set<DependencyCollector> dependencyCollectors = new
HashSet<DependencyCollector>();
+
+ private DependencyCollectorFactory() {
+ initDependencyCollectors();
+ }
+
+ private void initDependencyCollectors() {
+ dependencyCollectors.clear();
+ dependencyCollectors.add(new JavaDependencyCollector());
+ dependencyCollectors.add(new ComponentDependencyCollector());
+ }
+
+ public DependencyCollector getDependencyCollector(IProject project) throws CoreException
{
+ for (DependencyCollector dc : dependencyCollectors) {
+ if (dc.appliesTo(project)) {
+ return dc;
+ }
+ }
+ return null;
+ }
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/ProjectDependency.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/ProjectDependency.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/ProjectDependency.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -0,0 +1,40 @@
+/*************************************************************************************
+ * 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.core;
+
+import org.eclipse.core.runtime.IPath;
+
+public abstract class ProjectDependency {
+
+ public enum DependencyKind {
+ Project, Archive, Unsupported;
+ }
+
+ private DependencyKind dependencyKind;
+
+ public DependencyKind getDependencyKind() {
+ if (dependencyKind == null) {
+ dependencyKind = DependencyKind.Unsupported;
+ }
+ return dependencyKind;
+ }
+
+ public void setDependencyKind(DependencyKind dependencyKind) {
+ this.dependencyKind = dependencyKind;
+ }
+
+ /**
+ * @return get full path of underlying archive or workspace path of underlying project
+ */
+ public abstract IPath getPath();
+
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/ComponentDependency.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/ComponentDependency.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/ComponentDependency.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -0,0 +1,42 @@
+/*************************************************************************************
+ * 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.core.internal;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.jboss.tools.maven.conversion.core.ProjectDependency;
+
+public class ComponentDependency extends ProjectDependency {
+
+ private IVirtualComponent component;
+
+ public ComponentDependency(IVirtualComponent comp) {
+ super();
+ component = comp;
+ if (comp.isBinary()) {
+ setDependencyKind(DependencyKind.Archive);
+ } else {
+ setDependencyKind(DependencyKind.Project);
+ }
+ }
+
+ public IVirtualComponent getComponent() {
+ return component;
+ }
+
+ @Override
+ public IPath getPath() {
+ if (component.isBinary()) {
+ return (IPath) component.getAdapter(IPath.class);
+ }
+ return component.getProject().getFullPath();
+ }
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/ComponentDependencyCollector.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/ComponentDependencyCollector.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/ComponentDependencyCollector.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -0,0 +1,65 @@
+/*************************************************************************************
+ * 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.core.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.ModuleCoreNature;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
+import org.jboss.tools.maven.conversion.core.DependencyCollector;
+import org.jboss.tools.maven.conversion.core.ProjectDependency;
+
+/**
+ * Collects {@link ProjectDependency}'s from a non-java component project's
references
+ *
+ * @author Fred Bricon
+ *
+ */
+public class ComponentDependencyCollector extends DependencyCollector {
+
+ @Override
+ public List<ProjectDependency> collectDependencies(IProject project) throws
CoreException {
+ if (!appliesTo(project)) {
+ return null;
+ }
+ List<ProjectDependency> moduleDependencies = new
ArrayList<ProjectDependency>();
+ collectReferences(project, moduleDependencies);
+ return moduleDependencies;
+ }
+
+ private void collectReferences(IProject project, List<ProjectDependency>
moduleDependencies) {
+ IVirtualComponent component = ComponentCore.createComponent(project, true);
+ if (component == null) {
+ return;
+ }
+ IVirtualReference[] references = component.getReferences();
+ if (references == null || references.length == 0) {
+ return;
+ }
+ for (IVirtualReference r : references) {
+ moduleDependencies.add(new ComponentDependency(r.getReferencedComponent()));
+ }
+ }
+
+ @Override
+ public boolean appliesTo(IProject project) throws CoreException {
+ return project != null &&
+ ModuleCoreNature.isFlexibleProject(project) &&
+ !project.hasNature(JavaCore.NATURE_ID);
+ }
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/JavaDependency.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/JavaDependency.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/JavaDependency.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -0,0 +1,44 @@
+/*************************************************************************************
+ * 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.core.internal;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.jboss.tools.maven.conversion.core.ProjectDependency;
+
+public class JavaDependency extends ProjectDependency {
+
+ private IClasspathEntry classpathEntry;
+
+ public JavaDependency(IClasspathEntry cpe) {
+ super();
+ Assert.isNotNull(cpe, "classpentry parameter can not be null");
+ classpathEntry = cpe;
+ if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
+ setDependencyKind(DependencyKind.Project);
+ } else if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
+ setDependencyKind(DependencyKind.Archive);
+ } else {
+ setDependencyKind(DependencyKind.Unsupported);
+ }
+ }
+
+ public IClasspathEntry getClasspathEntry() {
+ return classpathEntry;
+ }
+
+ @Override
+ public IPath getPath() {
+ return classpathEntry.getPath();
+ }
+
+}
Added:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/JavaDependencyCollector.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/JavaDependencyCollector.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/core/internal/JavaDependencyCollector.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -0,0 +1,89 @@
+/*************************************************************************************
+ * 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.core.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+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.eclipse.jdt.core.JavaModelException;
+import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
+import org.jboss.tools.maven.conversion.core.DependencyCollector;
+import org.jboss.tools.maven.conversion.core.ProjectDependency;
+
+/**
+ * Collects {@link ProjectDependency}'s from a java project's classpath entries
+ *
+ * @author Fred Bricon
+ *
+ */
+@SuppressWarnings("restriction")
+public class JavaDependencyCollector extends DependencyCollector {
+
+ @Override
+ public List<ProjectDependency> collectDependencies(IProject project) throws
CoreException {
+ if (!appliesTo(project)) {
+ return null;
+ }
+ IJavaProject javaProject = JavaCore.create(project);
+ if (javaProject == null) {
+ return null;
+ }
+ IClasspathEntry[] classpath = javaProject.getRawClasspath();
+ List<ProjectDependency> classpathDependencies = new
ArrayList<ProjectDependency>(classpath.length);
+ extractDependencies(javaProject, classpath, classpathDependencies);
+ return classpathDependencies;
+ }
+
+ private void extractDependencies(IJavaProject javaProject, IClasspathEntry[] classpath,
+ List<ProjectDependency> classpathDependencies) throws JavaModelException {
+ for (IClasspathEntry cpe : classpath) {
+ if (!isValid(cpe)) {
+ continue;
+ }
+ if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
+ IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(),
javaProject );
+ if (container != null) {
+ IClasspathEntry[] cpes = container.getClasspathEntries();
+ if (cpes != null && cpes.length > 0) {
+ extractDependencies(javaProject, cpes, classpathDependencies);
+ }
+ }
+ } else {
+ classpathDependencies.add(new JavaDependency(cpe));
+ }
+ }
+ }
+
+ @Override
+ public boolean appliesTo(IProject project) throws CoreException {
+ return project != null && project.hasNature(JavaCore.NATURE_ID);
+ }
+
+ private boolean isValid(IClasspathEntry cpe) {
+
+ if(IClasspathEntry.CPE_CONTAINER == cpe.getEntryKind()
+ &&
("org.eclipse.jdt.launching.JRE_CONTAINER".equals(cpe.getPath().segment(0))
+ || MavenClasspathHelpers.isMaven2ClasspathContainer(cpe.getPath()))) {
+ return false;
+ }
+ if (IClasspathEntry.CPE_SOURCE == cpe.getEntryKind()) {
+ return false;
+ }
+ return true;
+ }
+
+}
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-02
14:17:39 UTC (rev 44217)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/ConvertToMavenDependencyWizard.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -11,26 +11,31 @@
package org.jboss.tools.maven.conversion.ui.dialog;
import java.util.List;
-import java.util.Set;
import org.apache.maven.model.Dependency;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jface.wizard.Wizard;
+import org.jboss.tools.maven.conversion.core.ProjectDependency;
+/**
+ * Convert project dependencies to Maven dependencies wizard
+ *
+ * @author Fred Bricon
+ *
+ */
public class ConvertToMavenDependencyWizard extends Wizard {
private IProject project;
- private Set<IClasspathEntry> entries;
+ private List<ProjectDependency> entries;
-
IdentifyMavenDependencyPage identificationPage;
+
private List<Dependency> dependencies;
- public ConvertToMavenDependencyWizard(IProject project, Set<IClasspathEntry>
entries) {
+ public ConvertToMavenDependencyWizard(IProject project, List<ProjectDependency>
projectDependencies) {
this.project = project;
- this.entries = entries;
+ this.entries = projectDependencies;
String title = "Convert to Maven ";
if (entries.size() > 1) {
title += "Dependencies";
Modified:
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-02
14:17:39 UTC (rev 44217)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/DeleteExistingJarsJob.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -28,6 +28,7 @@
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;
@@ -37,15 +38,22 @@
private IJavaProject javaProject;
- public DeleteExistingJarsJob(IProject project, Set<IClasspathEntry> entries) {
+ public DeleteExistingJarsJob(IProject project, List<ProjectDependency> entries2)
{
super("Delete classpath entries"
+ ((project == null) ? "" : "for " + project.getName()));
this.javaProject = JavaCore.create(project);
- this.entries = entries;
+ 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 {
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-02
14:17:39 UTC (rev 44217)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/IdentifyMavenDependencyPage.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -17,7 +17,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.maven.model.Dependency;
@@ -28,10 +27,6 @@
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
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.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.resource.JFaceResources;
@@ -61,6 +56,8 @@
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.jboss.tools.maven.conversion.core.ProjectDependency;
+import org.jboss.tools.maven.conversion.core.ProjectDependency.DependencyKind;
import org.jboss.tools.maven.conversion.ui.dialog.xpl.ConversionUtils;
import org.jboss.tools.maven.conversion.ui.dialog.xpl.EditDependencyDialog;
import org.jboss.tools.maven.conversion.ui.internal.CellListener;
@@ -85,11 +82,11 @@
private static final int DEPENDENCY_COLUMN = 2;
- private Map<IClasspathEntry, Dependency> dependencyMap;
+ private Map<ProjectDependency, Dependency> dependencyMap;
- private Map<IClasspathEntry, IdentificationJob> identificationJobs;
+ private Map<ProjectDependency, IdentificationJob> identificationJobs;
- private Set<IClasspathEntry> initialEntries;
+ private List<ProjectDependency> initialEntries;
private Map<Dependency, Boolean> dependencyResolution = new
ConcurrentHashMap<Dependency, Boolean>();
@@ -116,37 +113,20 @@
private Link warningLink;
- private static String MESSAGE = "Identify existing classpath entries as Maven
dependencies. Double-click on a Maven Dependency to edit its details";
+ private static String MESSAGE = "Identify existing project references as Maven
dependencies. Double-click on a Maven dependency to edit its details";
- public IdentifyMavenDependencyPage(IProject project, Set<IClasspathEntry> entries)
{
+ public IdentifyMavenDependencyPage(IProject project, List<ProjectDependency>
entries) {
super("");
this.project = project;
- initialEntries = Collections.unmodifiableSet(entries);
+ initialEntries = Collections.unmodifiableList(entries);
initDependencyMap();
}
private void initDependencyMap() {
- dependencyMap = new LinkedHashMap<IClasspathEntry,
Dependency>(initialEntries.size());
- IJavaProject javaProject = JavaCore.create(project);
- try {
-
- for (IClasspathEntry entry : initialEntries) {
- if ((entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath()
!= null)
- || (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT)) {
- dependencyMap.put(entry, null);
- } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
- IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
javaProject );
- if (container != null) {
- for (IClasspathEntry cpe: container.getClasspathEntries()) {
- dependencyMap.put(cpe, null);
- }
- }
- }
- }
-
- } catch(Exception e) {
- setMessage(e.getLocalizedMessage());
+ dependencyMap = new LinkedHashMap<ProjectDependency,
Dependency>(initialEntries.size());
+ for (ProjectDependency entry : initialEntries) {
+ dependencyMap.put(entry, null);
}
}
@@ -230,7 +210,7 @@
}
});
- deleteJarsBtn = addCheckButton(container, "Delete classpath entries from
project", deleteJars);
+ deleteJarsBtn = addCheckButton(container, "Delete original references from
project", deleteJars);
deleteJarsBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
deleteJars = deleteJarsBtn.getSelection();
@@ -272,20 +252,24 @@
emptyColumn.setWidth(20);
TableViewerColumn sourceColumn = new TableViewerColumn(dependenciesViewer, SWT.NONE);
- sourceColumn.getColumn().setText("Classpath Entry ");
+ sourceColumn.getColumn().setText("Project Reference");
sourceColumn.getColumn().setWidth(270);
sourceColumn.setLabelProvider(new ColumnLabelProvider(){
@Override
@SuppressWarnings("unchecked")
public String getText(Object element) {
- IClasspathEntry cpe = (IClasspathEntry) element;
- return cpe.getPath().lastSegment();
+ ProjectDependency projectDependency = (ProjectDependency) element;
+ return projectDependency.getPath().lastSegment();
}
@Override
public String getToolTipText(Object element) {
+ ProjectDependency projectDependency = (ProjectDependency) element;
+ if (projectDependency.getDependencyKind() == DependencyKind.Project) {
+ return "";
+ }
try {
- return "SHA1 Checksum :
"+IdentificationUtil.getSHA1(ConversionUtils.getFile(((IClasspathEntry) element)));
+ return "SHA1 Checksum :
"+IdentificationUtil.getSHA1(ConversionUtils.getFile(projectDependency.getPath()));
} catch (Exception e) {
e.printStackTrace();
}
@@ -295,9 +279,9 @@
@Override
@SuppressWarnings("unchecked")
public Image getImage(Object element) {
- IClasspathEntry cpe = (IClasspathEntry) element;
+ ProjectDependency projectDependency = (ProjectDependency) element;
Image img;
- if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
+ if (projectDependency.getDependencyKind() ==
ProjectDependency.DependencyKind.Archive) {
img = jarImage;
} else {
img = projectImage;
@@ -325,21 +309,21 @@
@Override
protected void handle(int columnIndex, TableItem item) {
if (columnIndex == DEPENDENCY_COLUMN) {
- IClasspathEntry cpe = (IClasspathEntry) item.getData();
+ ProjectDependency projectDep = (ProjectDependency) item.getData();
- IdentificationJob job = identificationJobs.get(cpe);
+ IdentificationJob job = identificationJobs.get(projectDep);
if (Job.RUNNING == job.getState()) {
return;
}
- Dependency d= dependencyMap.get(cpe);
+ Dependency d= dependencyMap.get(projectDep);
EditDependencyDialog editDependencyDialog = new EditDependencyDialog(getShell());
editDependencyDialog.setDependency(d);
if(editDependencyDialog.open() == Window.OK) {
Dependency newDep = editDependencyDialog.getDependency();
- dependencyMap.put(cpe,newDep);
+ dependencyMap.put(projectDep,newDep);
if (!eq(newDep,d)) {
- resolve(cpe, newDep);
+ resolve(projectDep, newDep);
}
}
}
@@ -364,9 +348,9 @@
}
- private void resolve(IClasspathEntry cpe, Dependency d) {
+ private void resolve(ProjectDependency projectDependency, Dependency d) {
if (d != null) {
- IdentificationJob job = identificationJobs.get(cpe);
+ IdentificationJob job = identificationJobs.get(projectDependency);
job.setDependency(d);
job.setRequestedProcess(Task.RESOLUTION_ONLY);
job.schedule();
@@ -439,7 +423,7 @@
if (monitor == null) {
monitor = new NullProgressMonitor();
}
- for (Map.Entry<IClasspathEntry, Dependency> entry : dependencyMap.entrySet()) {
+ for (Map.Entry<ProjectDependency, Dependency> entry : dependencyMap.entrySet())
{
if (entry.getValue() != null) {
//don't need to run identification
//continue;
@@ -511,28 +495,28 @@
private void initJobs() {
if (identificationJobs == null) {
- identificationJobs = new HashMap<IClasspathEntry,
IdentificationJob>(dependencyMap.size());
+ identificationJobs = new HashMap<ProjectDependency,
IdentificationJob>(dependencyMap.size());
Table t = dependenciesViewer.getTable();
IFileIdentificationManager fileIdentificationManager = new
FileIdentificationManager();
for (final TableItem item : t.getItems()) {
- final IClasspathEntry cpe = (IClasspathEntry)item.getData();
- Dependency dep = dependencyMap.get(cpe);
- if (dep != null) {
+ final ProjectDependency projectDep = (ProjectDependency)item.getData();
+ Dependency mavenDep = dependencyMap.get(projectDep);
+ if (mavenDep != null) {
//already identified
continue;
}
File jar;
try {
final IdentificationJob job;
- if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
- job = new IdentifyProjectJob("Search the Maven coordinates for
"+cpe.getPath(), cpe.getPath());
- } else if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
- jar = ConversionUtils.getFile(cpe);
+ if (projectDep.getDependencyKind() == ProjectDependency.DependencyKind.Project) {
+ job = new IdentifyProjectJob("Search the Maven coordinates for
"+projectDep.getPath(), projectDep.getPath());
+ } else if (projectDep.getDependencyKind() ==
ProjectDependency.DependencyKind.Archive) {
+ jar = ConversionUtils.getFile(projectDep.getPath());
job = new IdentifyJarJob("Search the Maven coordinates for
"+jar.getAbsolutePath(), fileIdentificationManager, jar);
} else {
- job = new DependencyResolutionJob("Resolve the Maven dependency for
"+cpe.getPath());
+ job = new DependencyResolutionJob("Resolve the Maven dependency for
"+projectDep.getPath());
}
job.addJobChangeListener(new IJobChangeListener() {
@@ -555,7 +539,7 @@
@Override
public void done(IJobChangeEvent event) {
Dependency d = job.getDependency();
- dependencyMap.put(cpe, d);
+ dependencyMap.put(projectDep, d);
if (d != null) {
dependencyResolution.put(d, job.isResolvable());
}
@@ -576,12 +560,12 @@
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
- refresh(cpe);
+ refresh(projectDep);
}
});
}
});
- identificationJobs.put(cpe, job);
+ identificationJobs.put(projectDep, job);
} catch (CoreException e) {
e.printStackTrace();
}
@@ -589,7 +573,7 @@
}
}
- private synchronized void refresh(IClasspathEntry key) {
+ private synchronized void refresh(ProjectDependency key) {
if (dependenciesViewer == null || dependenciesViewer.getTable().isDisposed()) {
return;
}
@@ -597,14 +581,14 @@
try {
for (TableItem item : dependenciesViewer.getTable().getItems()) {
@SuppressWarnings("unchecked")
- final IClasspathEntry cpe = (IClasspathEntry)item.getData();
- if (cpe.equals(key)) {
- dependenciesViewer.refresh(cpe, false);
+ final ProjectDependency projectDep = (ProjectDependency)item.getData();
+ if (projectDep.equals(key)) {
+ dependenciesViewer.refresh(projectDep, false);
//Don't force check when there's an existing dependency, only uncheck if
they're is not.
- if (dependencyMap.get(cpe) == null) {
- Job job = identificationJobs.get(cpe);
+ if (dependencyMap.get(projectDep) == null) {
+ Job job = identificationJobs.get(projectDep);
if (job != null && job.getState() == Job.NONE) {
- dependenciesViewer.setChecked(cpe, false);
+ dependenciesViewer.setChecked(projectDep, false);
}
}
setPageComplete(hasNoRunningJobs());
@@ -624,8 +608,8 @@
Object[] selection = dependenciesViewer.getCheckedElements();
List<Dependency> dependencies = new
ArrayList<Dependency>(selection.length);
for (Object o : selection) {
- IClasspathEntry cpe = (IClasspathEntry) o;
- Dependency d = dependencyMap.get(cpe);
+ ProjectDependency projectDep = (ProjectDependency) o;
+ Dependency d = dependencyMap.get(projectDep);
if (d != null) {
dependencies.add(d);
}
@@ -649,23 +633,23 @@
@Override
@SuppressWarnings("unchecked")
public String getText(Object element) {
- IClasspathEntry cpe = (IClasspathEntry) element;
- IdentificationJob job = identificationJobs ==null? null:identificationJobs.get(cpe);
+ ProjectDependency projectDep = (ProjectDependency) element;
+ IdentificationJob job = identificationJobs ==null?
null:identificationJobs.get(projectDep);
if (job != null) {
int jobState = job.getState();
if (jobState == Job.RUNNING || jobState == Job.WAITING) {
return "Identification in progress...";
}
}
- Dependency d = dependencyMap.get(cpe);
+ Dependency d = dependencyMap.get(projectDep);
return IdentifyMavenDependencyPage.toString(d);
}
@Override
@SuppressWarnings("unchecked")
public Image getImage(Object element) {
- IClasspathEntry cpe = (IClasspathEntry) element;
- IdentificationJob job = identificationJobs ==null? null:identificationJobs.get(cpe);
+ ProjectDependency projectDep = (ProjectDependency) element;
+ IdentificationJob job = identificationJobs ==null?
null:identificationJobs.get(projectDep);
if (job != null) {
int jobState = job.getState();
if (jobState == Job.RUNNING || jobState == Job.WAITING) {
@@ -673,7 +657,7 @@
}
}
- Dependency d = dependencyMap.get(cpe);
+ Dependency d = dependencyMap.get(projectDep);
if (d == null) {
return failedImage;
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/xpl/ConversionUtils.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/xpl/ConversionUtils.java 2012-10-02
14:17:39 UTC (rev 44217)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/dialog/xpl/ConversionUtils.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -48,6 +48,11 @@
public static File getFile(IClasspathEntry cpe) throws CoreException {
Assert.isNotNull(cpe, "ClasspathEntry can not be null");
IPath path = cpe.getPath();
+ return getFile(path);
+ }
+
+ public static File getFile(IPath path) throws CoreException {
+ Assert.isNotNull(path, "path can not be null");
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource file = root.findMember(path);
File localFile = null;
@@ -65,7 +70,7 @@
localFile= path.toFile();
}
return localFile;
- }
+ }
public static IFile getIFile(IClasspathEntry cpe) throws CoreException {
Assert.isNotNull(cpe, "ClasspathEntry can not be null");
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/ConvertToMavenDependencyHandler.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/ConvertToMavenDependencyHandler.java 2012-10-02
14:17:39 UTC (rev 44217)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/handlers/ConvertToMavenDependencyHandler.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -49,34 +49,19 @@
Set<IClasspathEntry> entries = getSelectedClasspathEntries(selection);
- //System.err.println(entries);
-
if (entries == null || entries.isEmpty()) {
MessageDialogWithToggle.openInformation(window.getShell(), "Convert to Maven
Dependency", "Nothing to convert");
return null;
}
- /*
- IPath path = libraryFromUI.getClasspathEntry().getPath();
-
- IJavaProject javaProject = libraryFromUI.getJavaProject();
-
- final String libName = libraryFromUI.getLabel();
- */
- /*
- IClasspathContainer containerToMaterialize = JavaCore.getClasspathContainer(path,
javaProject);
-
- IProject project = javaProject.getProject();
-
- */
- ConvertToMavenDependencyWizard wizard = new ConvertToMavenDependencyWizard(
- null, //project,
- entries
- );
-
- WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
- dialog.open();
- return null;
+ ConvertToMavenDependencyWizard wizard = new ConvertToMavenDependencyWizard(
+ null, //project,
+ null
+ );
+
+ WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
+ dialog.open();
+ return null;
}
Modified:
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-02
14:17:39 UTC (rev 44217)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/ClasspathConversionParticipant.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -10,28 +10,22 @@
************************************************************************************/
package org.jboss.tools.maven.conversion.ui.internal;
-import java.util.Collection;
-import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Set;
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.jdt.core.IClasspathContainer;
-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.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.m2e.core.project.conversion.AbstractProjectConversionParticipant;
-import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
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
@@ -39,28 +33,23 @@
@Override
public boolean accept(IProject project) throws CoreException {
- return project.hasNature(JavaCore.NATURE_ID);
+ 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 {
- if (accept(project)) {
-
- IJavaProject javaProject = JavaCore.create(project);
- IClasspathEntry[] classpath = javaProject.getRawClasspath();
- Set<IClasspathEntry> entries = new
LinkedHashSet<IClasspathEntry>(classpath.length);
- for (IClasspathEntry cpe : classpath) {
- if (isValid(cpe)) {
- entries.add(cpe);
- }
- }
-
- if (!hasDependencies(javaProject, entries)) {
+ 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() {
@@ -80,35 +69,4 @@
}
}
- private boolean hasDependencies(IJavaProject javaProject,
Collection<IClasspathEntry> initialEntries) throws JavaModelException {
- for (IClasspathEntry entry : initialEntries) {
- if ((entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath() !=
null)
- || (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT)) {
- return true;
- } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
- IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
javaProject );
- if (container != null) {
- IClasspathEntry[] cpes = container.getClasspathEntries();
- if (cpes != null && cpes.length > 0) {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- private boolean isValid(IClasspathEntry cpe) {
-
- if(IClasspathEntry.CPE_CONTAINER == cpe.getEntryKind()
- &&
("org.eclipse.jdt.launching.JRE_CONTAINER".equals(cpe.getPath().segment(0))
- || MavenClasspathHelpers.isMaven2ClasspathContainer(cpe.getPath()))) {
- return false;
- }
- if (IClasspathEntry.CPE_SOURCE == cpe.getEntryKind()) {
- return false;
- }
- return true;
- }
-
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/jobs/IdentifyProjectJob.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/jobs/IdentifyProjectJob.java 2012-10-02
14:17:39 UTC (rev 44217)
+++
trunk/maven/plugins/org.jboss.tools.maven.conversion.ui/src/org/jboss/tools/maven/conversion/ui/internal/jobs/IdentifyProjectJob.java 2012-10-02
14:37:38 UTC (rev 44218)
@@ -47,13 +47,6 @@
if (a.getArtifactHandler() != null &&
a.getArtifactHandler().getPackaging() != null) {
String type = a.getArtifactHandler().getPackaging();
- //case where classpath dependency is a war : it usually corresponds to
- //a jar of the war classes, having the "classes" classifier.
- if ("war".equals(type)) {
- type = "jar";
- dependency.setClassifier("classes");
- }
-
dependency.setType(type);
}
}