[jbosstools-commits] JBoss Tools SVN: r42440 - in trunk/maven/plugins: org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/xpl and 4 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Jul 6 09:32:45 EDT 2012


Author: fbricon
Date: 2012-07-06 09:32:45 -0400 (Fri, 06 Jul 2012)
New Revision: 42440

Added:
   trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/xpl/ArtifactHelper.java
   trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/xpl/WTPProjectsUtil.java
Modified:
   trunk/maven/plugins/org.jboss.tools.maven.core/META-INF/MANIFEST.MF
   trunk/maven/plugins/org.jboss.tools.maven.jaxrs/src/org/jboss/tools/maven/jaxrs/configurators/JaxrsProjectConfigurator.java
   trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/META-INF/MANIFEST.MF
   trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/src/org/jboss/tools/maven/jbosspackaging/configurators/JBossPackagingArchiverConfigurator.java
   trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/src/org/jboss/tools/maven/jbosspackaging/configurators/SarProjectConfigurator.java
   trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF
Log:
JBIDE-12293 : ensure compatibility with eclipse.org's m2e-wtp 

Modified: trunk/maven/plugins/org.jboss.tools.maven.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.core/META-INF/MANIFEST.MF	2012-07-06 12:57:02 UTC (rev 42439)
+++ trunk/maven/plugins/org.jboss.tools.maven.core/META-INF/MANIFEST.MF	2012-07-06 13:32:45 UTC (rev 42440)
@@ -15,18 +15,20 @@
  org.eclipse.m2e.core;bundle-version="[1.0,1.2)";visibility:=reexport,
  org.eclipse.m2e.maven.runtime;bundle-version="[1.0,1.2)";visibility:=reexport,
  org.eclipse.jdt.core;visibility:=reexport,
- org.eclipse.m2e.jdt;bundle-version="[1.0,1.2)";visibility:=reexport,
+ org.eclipse.m2e.jdt;bundle-version="[1.0,2.0)";visibility:=reexport,
  org.eclipse.jst.j2ee;visibility:=reexport,
  org.eclipse.jst.j2ee.web;visibility:=reexport,
  org.jboss.tools.common;visibility:=reexport,
  org.eclipse.jdt.launching;visibility:=reexport,
  org.eclipse.ui.workbench;visibility:=reexport,
- org.eclipse.m2e.model.edit;bundle-version="[1.0,1.2)";visibility:=reexport,
+ org.eclipse.m2e.model.edit;bundle-version="[1.0,2.0)";visibility:=reexport,
  org.eclipse.core.expressions,
- org.maven.ide.eclipse.wtp;bundle-version="[0.13.0,0.17.0)";visibility:=reexport,
+ org.maven.ide.eclipse.wtp;bundle-version="[0.13.0,0.16.0)";resolution:=optional;visibility:=reexport,
  org.eclipse.jdt.ui;bundle-version="3.7.0",
  org.eclipse.jpt.common.core;bundle-version="1.0.0",
- org.eclipse.jpt.jpa.core
+ org.eclipse.jpt.jpa.core,
+ org.eclipse.wst.common.emfworkbench.integration,
+ org.eclipse.m2e.wtp;bundle-version="0.16.0";resolution:=optional
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-Vendor: %Bundle-Vendor

Added: trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/xpl/ArtifactHelper.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/xpl/ArtifactHelper.java	                        (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/xpl/ArtifactHelper.java	2012-07-06 13:32:45 UTC (rev 42440)
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * 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
+ *******************************************************************************/
+
+package org.jboss.tools.maven.core.xpl;
+
+import java.util.Collection;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.jdt.internal.BuildPathManager;
+import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent;
+
+
+/**
+ * 
+ * Helper for Maven artifacts. Class copied from m2e-wtp.
+ *
+ * @author Fred Bricon
+ */
+//XXX Should probably be refactored to another Maven helper class.
+ at SuppressWarnings("restriction")
+public class ArtifactHelper {
+
+  private static final String M2_REPO_PREFIX = VirtualArchiveComponent.VARARCHIVETYPE + IPath.SEPARATOR
+  + BuildPathManager.M2_REPO + IPath.SEPARATOR;
+
+  /**
+   * Returns an artifact's path relative to the local repository
+   */
+  //XXX Does maven API provide that kind of feature? 
+  public static IPath getLocalRepoRelativePath(Artifact artifact) {
+    if (artifact == null) {
+      throw new IllegalArgumentException("artifact must not be null");
+    }
+    
+    IPath m2repo = JavaCore.getClasspathVariable(BuildPathManager.M2_REPO); //always set
+    IPath absolutePath = new Path(artifact.getFile().getAbsolutePath());
+    IPath relativePath = absolutePath.removeFirstSegments(m2repo.segmentCount()).makeRelative().setDevice(null);
+    return relativePath;
+  }
+  
+  /**
+   * Returns an IProject from a maven artifact
+   * @param artifact
+   * @return an IProject if the artifact is a workspace project or null
+   */
+  public static IProject getWorkspaceProject(Artifact artifact) {
+    IMavenProjectFacade facade = getWorkspaceProjectMavenFacade(artifact);
+    return (facade == null)?null:facade.getProject();
+  }
+
+  /**
+   * Returns an IMavenProjectFacade from a maven artifact
+   * @param artifact
+   * @return an IMavenProjectFacade if the artifact is a workspace project or null
+   */
+  public static IMavenProjectFacade getWorkspaceProjectMavenFacade(Artifact artifact) {
+    IMavenProjectFacade workspaceProject = MavenPlugin.getMavenProjectRegistry()
+    .getMavenProject(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
+
+    if(workspaceProject != null && workspaceProject.getFullPath(artifact.getFile()) != null) {
+      return workspaceProject;
+    }
+    return null;
+  }
+
+  /**
+   * Returns the M2_REPO variable path for an artifact. ex : var/M2_REPO/groupid/artifactid/version/filename
+   * @param artifact
+   * @return the M2_REPO variable path for the artifact, null if the artifact is a workspace project
+   */
+  public static String getM2REPOVarPath(Artifact artifact)
+  {
+    if (getWorkspaceProject(artifact) != null)
+    {
+     return null; 
+    }
+    return M2_REPO_PREFIX + ArtifactHelper.getLocalRepoRelativePath(artifact).toPortableString();
+  }
+
+  /**
+   * Temporary fix for app-client type artifacts, where the artifactHandler is not correctly loaded 
+   * thus the extension and the addtoclasspath value are incorrect.
+   * @param artifactHandler
+   */
+  @Deprecated
+  public static void fixArtifactHandler(ArtifactHandler artifactHandler) {
+	  if ("app-client".equals(artifactHandler.getExtension()) && artifactHandler instanceof DefaultArtifactHandler) {
+		  ((DefaultArtifactHandler)artifactHandler).setExtension("jar");
+		  ((DefaultArtifactHandler)artifactHandler).setAddedToClasspath(true);
+	  }
+  }
+  
+  public static Artifact getArtifact(Collection<Artifact> artifacts, ArtifactKey key) {
+    if (artifacts == null || key == null || artifacts.isEmpty()) {
+      return null;
+    }
+    for (Artifact a : artifacts) {
+      ArtifactKey ak = toArtifactKey(a);
+      if (key.equals(ak)) {
+        return a;
+      }
+    }
+    return null;
+  }
+  
+  /**
+   * Gets an ArtifactKey from an Artifact. This method fixes the flawed ArtifactKey(Artifact a) constructor
+   * which doesn't copy the artifact classifier; 
+   */
+  public static ArtifactKey toArtifactKey(Artifact a) {
+    return new ArtifactKey(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(), a.getClassifier());
+  }
+  
+}

Added: trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/xpl/WTPProjectsUtil.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/xpl/WTPProjectsUtil.java	                        (rev 0)
+++ trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/xpl/WTPProjectsUtil.java	2012-07-06 13:32:45 UTC (rev 42440)
@@ -0,0 +1,596 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * 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
+ *******************************************************************************/
+
+package org.jboss.tools.maven.core.xpl;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.project.MavenProject;
+import org.eclipse.core.resources.IFolder;
+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.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathAttribute;
+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.jst.common.project.facet.core.JavaFacet;
+import org.eclipse.jst.common.project.facet.core.internal.JavaFacetUtil;
+import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants;
+import org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent;
+import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
+import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities;
+import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants;
+import org.eclipse.m2e.core.internal.IMavenConstants;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.core.project.MavenProjectUtils;
+import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.ModuleCoreNature;
+import org.eclipse.wst.common.componentcore.internal.ComponentResource;
+import org.eclipse.wst.common.componentcore.internal.StructureEdit;
+import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent;
+import org.eclipse.wst.common.componentcore.internal.impl.ResourceTreeNode;
+import org.eclipse.wst.common.componentcore.internal.impl.ResourceTreeRoot;
+import org.eclipse.wst.common.componentcore.internal.util.FacetedProjectUtilities;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject.Action;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+
+/**
+ * Utility class for WTP projects. Copied from m2e-wtp.
+ * 
+ * @author Fred Bricon
+ */
+ at SuppressWarnings("restriction")
+public class WTPProjectsUtil {
+
+  public static final IProjectFacet UTILITY_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.UTILITY);
+
+  public static final IProjectFacetVersion UTILITY_10 = UTILITY_FACET.getVersion("1.0");
+
+  public static final IProjectFacet EJB_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.EJB);
+
+  public static final IProjectFacet JCA_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.JCA);
+  
+  public static final IProjectFacet WEB_FRAGMENT_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.WEBFRAGMENT);
+
+  public static final IProjectFacetVersion WEB_FRAGMENT_3_0 = WEB_FRAGMENT_FACET.getVersion("3.0");
+
+  public static final IProjectFacet DYNAMIC_WEB_FACET = ProjectFacetsManager
+      .getProjectFacet(IJ2EEFacetConstants.DYNAMIC_WEB);
+
+  public static final IProjectFacet APP_CLIENT_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.APPLICATION_CLIENT);
+
+  public static final IClasspathAttribute NONDEPENDENCY_ATTRIBUTE = JavaCore.newClasspathAttribute(
+      IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, "");
+
+  /**
+   * Defaults Web facet version to 2.5
+   */
+  public static final IProjectFacetVersion DEFAULT_WEB_FACET = DYNAMIC_WEB_FACET.getVersion("2.5");
+
+  public static final IProjectFacet EAR_FACET = ProjectFacetsManager
+      .getProjectFacet(IJ2EEFacetConstants.ENTERPRISE_APPLICATION);
+
+  /**
+   * Checks if a project has a given class in its classpath 
+   * @param project : the workspace project
+   * @param className : the fully qualified name of the class to search for
+   * @return true if className is found in the project's classpath (provided the project is a JavaProject and its classpath has been set.)   
+   */
+  public static boolean hasInClassPath(IProject project, String className) {
+    boolean result = false;
+    if (project != null){
+      IJavaProject javaProject = JavaCore.create(project);
+      try {
+        if (javaProject!= null && javaProject.findType(className)!=null){
+         result = true; 
+        }
+      } catch(JavaModelException ex) {
+        //Ignore this
+      }
+    }
+    return result;
+  }
+
+  
+  /**
+   * Checks if the project is one of Dynamic Web, EJB, Application client, EAR or JCA project.
+   * @param project - the project to be checked.
+   * @return true if the project is a JEE - or legacy J2EE - project (but not a utility project). 
+   */
+  public static boolean isJavaEEProject(IProject project) {
+    return (J2EEProjectUtilities.isLegacyJ2EEProject(project) || J2EEProjectUtilities.isJEEProject(project)) && !JavaEEProjectUtilities.isUtilityProject(project); 
+  }
+  
+  /**
+   * Delete a project's component resources having a given runtimePath
+   * @param project - the project to modify
+   * @param runtimePath - the component resource runtime path (i.e. deploy path)
+   * @param monitor - an eclipse monitor
+   * @throws CoreException
+   */
+  public static void deleteLinks(IProject project, IPath runtimePath, IProgressMonitor monitor) throws CoreException {
+    deleteLinks(project, runtimePath, null, monitor);
+  }
+
+  /**
+   * Delete a project's component resources having a given runtimePath
+   * @param project - the project to modify
+   * @param runtimePath - the component resource runtime path (i.e. deploy path)
+   * @param sourcePathToKeep - the list of source paths to keep
+   * @param monitor - an eclipse monitor
+   * @throws CoreException
+   */
+  public static void deleteLinks(IProject project, IPath runtimePath, List<IPath> sourcePathToKeep, IProgressMonitor monitor) throws CoreException {
+    //Looks like WTP'APIS doesn't have such feature, hence this implementation.
+    StructureEdit moduleCore = null;
+    try {
+      moduleCore = StructureEdit.getStructureEditForWrite(project);
+      if (moduleCore == null) {
+        return;
+      }
+      WorkbenchComponent component = moduleCore.getComponent();
+      if (component == null)  {
+        return;
+      }
+      ResourceTreeRoot root = ResourceTreeRoot.getDeployResourceTreeRoot(component);
+      ComponentResource[] resources = root.findModuleResources(runtimePath, 0);
+      for (ComponentResource link : resources) {
+        if (runtimePath.equals(link.getRuntimePath()) && 
+           (sourcePathToKeep == null || !sourcePathToKeep.contains(link.getSourcePath()))) {
+          component.getResources().remove(link);
+        }
+      }
+   }
+   finally {
+     if (moduleCore != null) {
+       moduleCore.saveIfNecessary(monitor);
+       moduleCore.dispose();
+     }
+    }
+  }
+  
+  public static void insertLinkBefore(IProject project, IPath newSource, IPath referenceSource, IPath runtimePath, IProgressMonitor monitor) throws CoreException {
+    //Looks like WTP'APIS doesn't have such feature, hence this implementation.
+    StructureEdit moduleCore = null;
+    try {
+      moduleCore = StructureEdit.getStructureEditForWrite(project);
+      if (moduleCore == null) {
+        return;
+      }
+      WorkbenchComponent component = moduleCore.getComponent();
+      if (component == null)  {
+        return;
+      }
+      
+      int i = 0;
+      int refPosition = -1;
+      int newSourcePosition = -1;
+      List<ComponentResource> resources = component.getResources();
+      
+      for (ComponentResource resource : resources) {
+        IPath sourcePath = resource.getSourcePath();
+        if (referenceSource.equals(sourcePath)) {
+          refPosition = i;
+        } else if (newSource.equals(sourcePath)) {
+          newSourcePosition = i;
+        }
+        if (refPosition > -1 &&  newSourcePosition > -1) {
+          break;
+        }
+        i++;
+      }
+      if (refPosition < 0) {
+        refPosition = i;
+      }
+      IResource folder = project.getFolder(newSource);
+      if (newSourcePosition > refPosition) {
+        component.getResources().move(newSourcePosition, refPosition);
+      } else if (newSourcePosition < 0) {
+        ComponentResource componentResource = moduleCore.createWorkbenchModuleResource(folder);
+        componentResource.setRuntimePath(runtimePath);
+        component.getResources().add(refPosition,componentResource);
+      }
+   }
+   finally {
+     if (moduleCore != null) {
+       moduleCore.saveIfNecessary(monitor);
+       moduleCore.dispose();
+     }
+    }
+  }
+
+  public static void insertLinkFirst(IProject project, IPath newSource, IPath runtimePath, IProgressMonitor monitor) throws CoreException {
+    //Looks like WTP'APIS doesn't have such feature, hence this implementation.
+    StructureEdit moduleCore = null;
+    try {
+      moduleCore = StructureEdit.getStructureEditForWrite(project);
+      if (moduleCore == null) {
+        return;
+      }
+      WorkbenchComponent component = moduleCore.getComponent();
+      if (component == null)  {
+        return;
+      }
+      
+      IResource folder = project.getFolder(newSource);
+      ComponentResource componentResource = moduleCore.createWorkbenchModuleResource(folder);
+      componentResource.setRuntimePath(runtimePath);
+      component.getResources().add(0,componentResource);
+   }
+   finally {
+     if (moduleCore != null) {
+       moduleCore.saveIfNecessary(monitor);
+       moduleCore.dispose();
+     }
+    }
+  }
+  
+  public static boolean hasLink(IProject project, IPath runtimePath, IPath aProjectRelativeLocation, IProgressMonitor monitor) throws CoreException {
+    StructureEdit moduleCore = null;
+    try {
+      moduleCore = StructureEdit.getStructureEditForRead(project);
+      if( moduleCore != null ) {
+        WorkbenchComponent component = moduleCore.getComponent();
+        if (component != null) {
+          ResourceTreeRoot root = ResourceTreeRoot.getDeployResourceTreeRoot(component);
+          ComponentResource[] resources = root.findModuleResources(runtimePath, ResourceTreeNode.CREATE_NONE);
+          if (resources.length > 0) {
+            for (int resourceIndx = 0; resourceIndx < resources.length; resourceIndx++) {
+              if (aProjectRelativeLocation.makeAbsolute().equals(resources[resourceIndx].getSourcePath())) {
+                return true;
+              }
+            }
+          }
+        }
+      }
+    }
+    finally {
+      if (moduleCore != null) {
+        moduleCore.dispose();
+      }
+    }
+    return false;
+  }
+
+  /**
+   * @param project
+   * @param dir
+   * @return
+   */
+  public static IPath tryProjectRelativePath(IProject project, String resourceLocation) {
+    if(resourceLocation == null) {
+      return null;
+    }
+    IPath projectLocation = project.getLocation();
+    IPath directory = Path.fromOSString(resourceLocation); // this is an absolute path!
+    if(projectLocation == null || !projectLocation.isPrefixOf(directory)) {
+      return directory;
+    }
+    return directory.removeFirstSegments(projectLocation.segmentCount()).makeRelative().setDevice(null);
+  }
+  
+  
+  public static boolean hasChanged(IVirtualReference[] existingRefs, IVirtualReference[] refArray) {
+    
+    if (existingRefs==refArray) {
+      return false;
+    }
+    if (existingRefs == null || existingRefs.length != refArray.length) {
+      return true;
+    }
+    for (int i=0; i<existingRefs.length;i++){
+      IVirtualReference existingRef = existingRefs[i];
+      IVirtualReference newRef = refArray[i];
+      if ((existingRef.getArchiveName() != null && !existingRef.getArchiveName().equals(newRef.getArchiveName())) ||
+          (existingRef.getArchiveName() == null && newRef.getArchiveName() != null) ||
+          !existingRef.getReferencedComponent().equals(newRef.getReferencedComponent()) ||
+          !existingRef.getRuntimePath().equals(newRef.getRuntimePath())) 
+      {
+        return true;  
+      }
+    }
+    return false;    
+  }
+  
+  public static boolean hasChanged2(IVirtualReference[] existingRefs, IVirtualReference[] refArray) {
+    
+    if (existingRefs==refArray) {
+      return false;
+    }
+    if (existingRefs == null || existingRefs.length != refArray.length) {
+      return true;
+    }
+    for (int i=0; i<existingRefs.length;i++){
+      IVirtualReference existingRef = existingRefs[i];
+      IVirtualReference newRef = refArray[i];
+      if (
+          !existingRef.getReferencedComponent().equals(newRef.getReferencedComponent()) ||
+          !existingRef.getRuntimePath().equals(newRef.getRuntimePath())) 
+      {
+        return true;  
+      }
+    }
+    return false;    
+  }
+  
+  /**
+   * Remove the WTP classpath containers that might conflicts with the Maven Library 
+   * classpath container 
+   * @param project
+   * @throws JavaModelException
+   */
+  public static void removeWTPClasspathContainer(IProject project) throws JavaModelException {
+    IJavaProject javaProject = JavaCore.create(project);
+    if(javaProject != null) {
+      // remove classpatch container from JavaProject
+      ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
+      for(IClasspathEntry entry : javaProject.getRawClasspath()) {
+    	String path = entry.getPath().toString();
+        if(!"org.eclipse.jst.j2ee.internal.module.container".equals(path)
+        	&& !"org.eclipse.jst.j2ee.internal.web.container".equals(path)) {
+	          newEntries.add(entry);
+        }
+      }
+      javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[newEntries.size()]), null);
+    }
+  }
+
+ /**
+  * Adds uninstall actions of facets from the faceted project that conflict with the given facetVersion. 
+  */
+  public static void removeConflictingFacets(IFacetedProject project, IProjectFacetVersion facetVersion, Set<Action> actions) {
+    if (project == null) {
+      throw new IllegalArgumentException("project can not be null");
+    }
+    if (facetVersion == null) {
+      throw new IllegalArgumentException("Facet version can not be null");
+    }
+    if (actions == null) {
+      throw new IllegalArgumentException("actions can not be null");
+    }
+    for (IProjectFacetVersion existingFacetVersion : project.getProjectFacets()) {
+      if (facetVersion.conflictsWith(existingFacetVersion)) {
+        actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.UNINSTALL, existingFacetVersion, null));
+      }
+    }
+  }
+
+  /**
+   * @param actions
+   * @param project
+   * @param facetedProject
+   */
+  public static void installJavaFacet(Set<Action> actions, IProject project, IFacetedProject facetedProject) {
+    IProjectFacetVersion javaFv = JavaFacet.FACET.getVersion(JavaFacetUtil.getCompilerLevel(project));
+    if(!facetedProject.hasProjectFacet(JavaFacet.FACET)) {
+      actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, javaFv, null));
+    } else if(!facetedProject.hasProjectFacet(javaFv)) {
+      actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, javaFv, null));
+    } 
+  }
+
+  /**
+   * @param project
+   * @return
+   */
+  @SuppressWarnings("restriction")
+  public static boolean hasWebFragmentFacet(IProject project) {
+    return FacetedProjectUtilities.isProjectOfType(project, WTPProjectsUtil.WEB_FRAGMENT_FACET.getId());
+  }
+
+  /**
+   * @param mavenProject
+   * @return
+   */
+  public static boolean isQualifiedAsWebFragment(IMavenProjectFacade facade) {
+    if ("jar".equals(facade.getPackaging())) {
+      IFolder classes = getClassesFolder(facade);
+      if (classes != null && classes.getFile("META-INF/web-fragment.xml").exists()) {
+        return true;
+      } else {
+        //No processed/filtered web-fragment.xml found 
+        //fall back : iterate over the resource folders
+        IProject project = facade.getProject();
+        for (IPath resourceFolderPath : facade.getResourceLocations()) {
+          if (resourceFolderPath != null && project.exists(resourceFolderPath.append("META-INF/web-fragment.xml"))) {
+            return true;
+          }
+        }
+      }
+    }
+    return false;
+  }
+  
+  /**
+   * Return the project's classes folder, a.k.a. output build directory
+   * @param facade
+   * @return the project's classes folder
+   */
+  public static IFolder getClassesFolder(IMavenProjectFacade facade) {
+    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+    IFolder output = root.getFolder(facade.getOutputLocation());
+    return output;
+  }
+
+
+  public static void removeTestFolderLinks(IProject project, MavenProject mavenProject, IProgressMonitor monitor,
+      String folder) throws CoreException {
+    IVirtualComponent component = ComponentCore.createComponent(project);
+    if (component == null){
+      return;
+    }
+    IVirtualFolder jsrc = component.getRootFolder().getFolder(folder);
+    for(IPath location : MavenProjectUtils.getSourceLocations(project, mavenProject.getTestCompileSourceRoots())) {
+      if (location == null) continue;
+      jsrc.removeLink(location, 0, monitor);
+    }
+    for(IPath location : MavenProjectUtils.getResourceLocations(project, mavenProject.getTestResources())) {
+      if (location == null) continue;
+      jsrc.removeLink(location, 0, monitor);
+    }
+
+    //MECLIPSEWTP-217 : exclude other test source folders, added by build-helper for instance
+    if (project.hasNature(JavaCore.NATURE_ID)) {
+      IJavaProject javaProject = JavaCore.create(project);
+      if (javaProject == null) {
+        return;
+      }
+      IPath testOutputDirPath = MavenProjectUtils.getProjectRelativePath(project, mavenProject.getBuild().getTestOutputDirectory());
+      if (testOutputDirPath == null) {
+        return;
+      }
+      IPath testPath = project.getFullPath().append(testOutputDirPath);
+      IClasspathEntry[] cpes = javaProject.getRawClasspath();
+      IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+      for (IClasspathEntry cpe : cpes) {
+        if (cpe != null && cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+          IPath outputLocation = cpe.getOutputLocation();
+          if (testPath.equals(outputLocation)) {
+            IPath sourcePath = root.getFolder(cpe.getPath()).getProjectRelativePath();
+            if (sourcePath != null) {
+              jsrc.removeLink(sourcePath, 0, monitor);
+            }
+          }
+        }
+      }
+    }
+  }
+
+
+  public static void setNonDependencyAttributeToContainer(IProject project, IProgressMonitor monitor) throws JavaModelException {
+    updateContainerAttributes(project, NONDEPENDENCY_ATTRIBUTE, IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY, monitor);
+  }
+
+  public static void updateContainerAttributes(IProject project, IClasspathAttribute attributeToAdd, String attributeToDelete, IProgressMonitor monitor)
+  throws JavaModelException {
+    IJavaProject javaProject = JavaCore.create(project);
+    if (javaProject == null) return;
+    IClasspathEntry[] cp = javaProject.getRawClasspath();
+    for(int i = 0; i < cp.length; i++ ) {
+      if(IClasspathEntry.CPE_CONTAINER == cp[i].getEntryKind()
+          && MavenClasspathHelpers.isMaven2ClasspathContainer(cp[i].getPath())) {
+        LinkedHashMap<String, IClasspathAttribute> attrs = new LinkedHashMap<String, IClasspathAttribute>();
+        for(IClasspathAttribute attr : cp[i].getExtraAttributes()) {
+          if (!attr.getName().equals(attributeToDelete)) {
+            attrs.put(attr.getName(), attr);            
+          }
+        }
+        attrs.put(attributeToAdd.getName(), attributeToAdd);
+        IClasspathAttribute[] newAttrs = attrs.values().toArray(new IClasspathAttribute[attrs.size()]);
+        cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newAttrs, cp[i].isExported());
+        break;
+      }
+    }
+    javaProject.setRawClasspath(cp, monitor);
+  }
+
+
+  /**
+   * Add the ModuleCoreNature to a project, if necessary.
+   * 
+   * @param project An accessible project.
+   * @param monitor A progress monitor to track the time to completion
+   * @throws CoreException if the ModuleCoreNature cannot be added
+   */
+  public static void fixMissingModuleCoreNature(IProject project, IProgressMonitor monitor) throws CoreException {
+    //MECLIPSEWTP-41 Fix the missing moduleCoreNature
+    if (null == ModuleCoreNature.addModuleCoreNatureIfNecessary(project, monitor)) {
+      //If we can't add the missing nature, then the project is useless, so let's tell the user
+      throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, "Unable to add the ModuleCoreNature to "+project.getName(),null));
+    }
+  }
+
+
+  /**
+   * @return true if the Maven project associated ArtifactHandler's language is java.
+   */
+  public static boolean isJavaProject(IMavenProjectFacade facade) {
+    //Java rocks ... not
+    if (facade == null 
+     || facade.getMavenProject() == null
+     || facade.getMavenProject().getArtifact() == null
+     || facade.getMavenProject().getArtifact().getArtifactHandler() == null) {
+      return false;
+    }
+    String language = facade.getMavenProject().getArtifact().getArtifactHandler().getLanguage();
+    return "java".equals(language);
+  }
+  
+  /**
+   * Sets the default deployment descriptor folder for Eclipse > Indigo
+   */
+  public static void setDefaultDeploymentDescriptorFolder(IVirtualFolder folder, IPath aProjectRelativeLocation, IProgressMonitor monitor) {
+    try {
+      Method getDefaultDeploymentDescriptorFolder = J2EEModuleVirtualComponent.class.getMethod("getDefaultDeploymentDescriptorFolder", 
+                                                                                               IVirtualFolder.class);
+      IPath currentDefaultLocation =(IPath) getDefaultDeploymentDescriptorFolder.invoke(null, folder);
+      if (aProjectRelativeLocation.equals(currentDefaultLocation)) {
+        return;
+      }
+      Method setDefaultDeploymentDescriptorFolder = J2EEModuleVirtualComponent.class.getMethod("setDefaultDeploymentDescriptorFolder", 
+                                                                                               IVirtualFolder.class, 
+                                                                                               IPath.class, 
+                                                                                               IProgressMonitor.class);
+      setDefaultDeploymentDescriptorFolder.invoke(null, folder, aProjectRelativeLocation, monitor);
+    } catch (NoSuchMethodException nsme) {
+      //Not available in this WTP version, let's ignore it
+    } catch(Exception ex) {
+      //The exception shouldn't halt the configuration process.
+      ex.printStackTrace();
+    } 
+  }
+
+  
+  /**
+   * Gets the default deployment descriptor folder's relative path. 
+   */
+  public static IFolder getDefaultDeploymentDescriptorFolder(IVirtualFolder vFolder) {
+    IPath defaultPath = null;
+    try {
+      Method getDefaultDeploymentDescriptorFolder = J2EEModuleVirtualComponent.class.getMethod("getDefaultDeploymentDescriptorFolder", 
+                                                                                               IVirtualFolder.class);
+      defaultPath =(IPath) getDefaultDeploymentDescriptorFolder.invoke(null, vFolder);
+      
+    } catch (NoSuchMethodException nsme) {
+      //Not available in this WTP version, let's ignore it
+    } catch(Exception ex) {
+      //The exception shouldn't halt the configuration process.
+      ex.printStackTrace();
+    }
+    
+    IFolder folder;
+    IVirtualComponent component = vFolder.getComponent();
+    if (defaultPath == null) {
+      folder = (IFolder)vFolder.getUnderlyingFolder();
+    } else {
+      folder = component.getProject().getFolder(defaultPath);
+    }
+    
+    return folder;
+  }  
+}

Modified: trunk/maven/plugins/org.jboss.tools.maven.jaxrs/src/org/jboss/tools/maven/jaxrs/configurators/JaxrsProjectConfigurator.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jaxrs/src/org/jboss/tools/maven/jaxrs/configurators/JaxrsProjectConfigurator.java	2012-07-06 12:57:02 UTC (rev 42439)
+++ trunk/maven/plugins/org.jboss.tools.maven.jaxrs/src/org/jboss/tools/maven/jaxrs/configurators/JaxrsProjectConfigurator.java	2012-07-06 13:32:45 UTC (rev 42440)
@@ -10,7 +10,9 @@
  ************************************************************************************/
 package org.jboss.tools.maven.jaxrs.configurators;
 
+import org.apache.maven.model.Plugin;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
@@ -43,8 +45,8 @@
 import org.jboss.tools.maven.core.IJBossMavenConstants;
 import org.jboss.tools.maven.core.ProjectUtil;
 import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider;
+import org.jboss.tools.maven.core.xpl.WTPProjectsUtil;
 import org.jboss.tools.maven.ui.Activator;
-import org.maven.ide.eclipse.wtp.WarPluginConfiguration;
 
 /**
  * JAX-RS maven project configurator.
@@ -134,8 +136,7 @@
 				// see https://issues.jboss.org/browse/JBIDE-10037
 				ProjectUtil.refreshHierarchy(mavenProject.getBasedir(), IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 1));
 				IDataModel model = createJaxRsDataModel(fproj,facetVersion);
-				WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, fproj.getProject());
-				String warSourceDirectory = config.getWarSourceDirectory();
+				String warSourceDirectory = getWarSourceDirectory(mavenProject, fproj.getProject());
 				model.setProperty(IJAXRSFacetInstallDataModelProperties.WEBCONTENT_DIR, warSourceDirectory);
 				model.setProperty(IJAXRSFacetInstallDataModelProperties.UPDATEDD, false);
 				fproj.installProjectFacet(facetVersion, model, monitor);
@@ -148,6 +149,25 @@
 		}
 	}
 
+	//Copied from WarPlugin in m2e-wtp
+	private String getWarSourceDirectory(MavenProject mavenProject, IProject project) {
+	    Plugin plugin = mavenProject.getPlugin("org.apache.maven.plugins:maven-war-plugin");
+	    if (plugin != null && plugin.getConfiguration() instanceof Xpp3Dom) {
+	    	Xpp3Dom dom = (Xpp3Dom)plugin.getConfiguration(); 
+	    	Xpp3Dom[] warSourceDirectory = dom.getChildren("warSourceDirectory");
+	    	if(warSourceDirectory != null && warSourceDirectory.length > 0) {
+	    		// first one wins
+	    		String dir = warSourceDirectory[0].getValue();
+	    		if(project != null) {
+	    			return WTPProjectsUtil.tryProjectRelativePath(project, dir).toOSString();
+	    		}
+	    		return dir;
+	    	}
+	    }
+		return "src/main/webapp";
+	}
+
+
 	private IDataModel createJaxRsDataModel(IFacetedProject fproj,
 			IProjectFacetVersion facetVersion) {
 		IDataModel config = (IDataModel) new JAXRSFacetInstallDataModelProvider().create();

Modified: trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/META-INF/MANIFEST.MF	2012-07-06 12:57:02 UTC (rev 42439)
+++ trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/META-INF/MANIFEST.MF	2012-07-06 13:32:45 UTC (rev 42440)
@@ -13,8 +13,7 @@
  org.eclipse.jst.j2ee,
  org.eclipse.wst.common.emfworkbench.integration;bundle-version="1.2.100",
  org.sonatype.m2e.mavenarchiver;bundle-version="0.14.0",
- org.jboss.ide.eclipse.as.ui.mbeans;bundle-version="2.3.0",
- org.maven.ide.eclipse.wtp;bundle-version="[0.13.0,0.17.0)
+ org.jboss.ide.eclipse.as.ui.mbeans;bundle-version="2.3.0"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-Vendor: %Bundle-Vendor

Modified: trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/src/org/jboss/tools/maven/jbosspackaging/configurators/JBossPackagingArchiverConfigurator.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/src/org/jboss/tools/maven/jbosspackaging/configurators/JBossPackagingArchiverConfigurator.java	2012-07-06 12:57:02 UTC (rev 42439)
+++ trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/src/org/jboss/tools/maven/jbosspackaging/configurators/JBossPackagingArchiverConfigurator.java	2012-07-06 13:32:45 UTC (rev 42440)
@@ -1,9 +1,5 @@
 package org.jboss.tools.maven.jbosspackaging.configurators;
 
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.m2e.core.project.IMavenProjectFacade;
 import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
 import org.sonatype.m2e.mavenarchiver.internal.JarArchiverConfigurator;
 
@@ -18,16 +14,4 @@
 
 	protected abstract String getGoal();
 
-	@Override
-	public void generateManifest(IMavenProjectFacade mavenFacade, IFile manifest, IProgressMonitor monitor)
-			throws CoreException {
-		super.generateManifest(mavenFacade, manifest, monitor);
-	}
-	
-	@Override
-	protected boolean needsNewManifest(IFile manifest, IMavenProjectFacade oldFacade, IMavenProjectFacade newFacade,
-			IProgressMonitor monitor) {
-		// TODO Auto-generated method stub
-		return super.needsNewManifest(manifest, oldFacade, newFacade, monitor);
-	}
 }

Modified: trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/src/org/jboss/tools/maven/jbosspackaging/configurators/SarProjectConfigurator.java
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/src/org/jboss/tools/maven/jbosspackaging/configurators/SarProjectConfigurator.java	2012-07-06 12:57:02 UTC (rev 42439)
+++ trunk/maven/plugins/org.jboss.tools.maven.jbosspackaging/src/org/jboss/tools/maven/jbosspackaging/configurators/SarProjectConfigurator.java	2012-07-06 13:32:45 UTC (rev 42440)
@@ -54,8 +54,8 @@
 import org.jboss.ide.eclipse.as.ui.mbeans.project.JBossSARFacetDataModelProvider;
 import org.jboss.tools.maven.core.IJBossMavenConstants;
 import org.jboss.tools.maven.core.internal.project.facet.MavenFacetInstallDataModelProvider;
-import org.maven.ide.eclipse.wtp.ArtifactHelper;
-import org.maven.ide.eclipse.wtp.WTPProjectsUtil;
+import org.jboss.tools.maven.core.xpl.ArtifactHelper;
+import org.jboss.tools.maven.core.xpl.WTPProjectsUtil;
 
 /**
  * 

Modified: trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF	2012-07-06 12:57:02 UTC (rev 42439)
+++ trunk/maven/plugins/org.jboss.tools.maven.project.examples/META-INF/MANIFEST.MF	2012-07-06 13:32:45 UTC (rev 42440)
@@ -10,7 +10,7 @@
  org.jboss.tools.maven.core,
  org.jboss.tools.project.examples,
  org.eclipse.ui.ide,
- org.eclipse.m2e.archetype.common;bundle-version="[1.0,1.2)",
+ org.eclipse.m2e.archetype.common;bundle-version="[1.0.0,2.0.0)",
  org.eclipse.m2e.core.ui;bundle-version="[1.0,1.2)",
  org.eclipse.wst.web.ui;bundle-version="1.1.400",
  org.eclipse.ui.forms,



More information about the jbosstools-commits mailing list