Author: xcoulon
Date: 2011-11-09 05:47:47 -0500 (Wed, 09 Nov 2011)
New Revision: 36244
Added:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/ProjectUtil.java
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/jaxrs-3layers-child/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/jaxrs-3layers-child/pom.xml
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/pom.xml
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/pom.xml
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/core/
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/core/ProjectUtilTest.java
Modified:
trunk/maven/plugins/org.jboss.tools.maven.jaxrs/src/org/jboss/tools/maven/jaxrs/configurators/JaxrsProjectConfigurator.java
Log:
FIXED - issue JBIDE-10037: EE6 EAR Archetype fails to close after completion
https://issues.jboss.org/browse/JBIDE-10037
Rework after fbricon's code review
Added:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/ProjectUtil.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/ProjectUtil.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/ProjectUtil.java 2011-11-09
10:47:47 UTC (rev 36244)
@@ -0,0 +1,63 @@
+package org.jboss.tools.maven.core;
+
+import java.io.File;
+import java.net.URI;
+
+import org.apache.maven.project.MavenProject;
+import org.eclipse.core.internal.resources.Project;
+import org.eclipse.core.resources.IContainer;
+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.Path;
+import org.eclipse.jdt.core.JavaCore;
+
+/**
+ * A utility class for Eclipse Projects.
+ * @author Xavier Coulon
+ *
+ */
+public class ProjectUtil {
+
+ /**
+ * Refreshes the projects hierarchy. For example, if the project on
+ * which a facet should be installed is 'Parent1/Parent2/Child',
+ * then both Parent1, Parent2 and Child are refreshed.
+ *
+ * @param basedir : the base directory (absolute file system path) of the (child)
project to refresh.
+ * @param refreshDepth: the refresh depth
+ * @param monitor : the progress monitor
+ * @return the number of projects that were refreshed
+ * @throws CoreException
+ * in case of problem during refresh
+ * @see IResource for depth values.
+ */
+ public static int refreshHierarchy(File basedir, int refreshDepth, IProgressMonitor
monitor) throws CoreException {
+ try {
+ int count = 0;
+ final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ final IProject[] projects = root.getProjects();
+ final IPath rootLocation = root.getLocation();
+ IPath basedirPath = new Path(basedir.getAbsolutePath());
+ while(basedirPath.matchingFirstSegments(rootLocation) > 0) {
+ for(IProject project : projects) {
+ final IPath projectLocation = project.getLocation();
+ if(projectLocation.equals(basedirPath) && project.isOpen()) {
+ project.refreshLocal(refreshDepth, monitor);
+ count++;
+ break;
+ }
+ }
+ basedirPath = basedirPath.removeLastSegments(1);
+ }
+ return count;
+ } finally {
+ monitor.done();
+ }
+ }
+
+}
Property changes on:
trunk/maven/plugins/org.jboss.tools.maven.core/src/org/jboss/tools/maven/core/ProjectUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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 2011-11-09
10:14:43 UTC (rev 36243)
+++
trunk/maven/plugins/org.jboss.tools.maven.jaxrs/src/org/jboss/tools/maven/jaxrs/configurators/JaxrsProjectConfigurator.java 2011-11-09
10:47:47 UTC (rev 36244)
@@ -16,10 +16,12 @@
import org.eclipse.core.resources.IMarker;
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.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
@@ -44,6 +46,7 @@
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.jboss.tools.common.util.EclipseJavaUtil;
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.ui.Activator;
import org.maven.ide.eclipse.wtp.WarPluginConfiguration;
@@ -78,49 +81,11 @@
@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor)
throws CoreException {
MavenProject mavenProject = request.getMavenProject();
- refreshHierarchy(mavenProject, new SubProgressMonitor(monitor, 1));
IProject project = request.getProject();
configureInternal(mavenProject, project, monitor);
}
- /**
- * Refreshes the Maven projects hierarchy. For example, if the project on
- * which the JAX-RS facet should be installed is 'Parent1/Parent2/Child',
- * then both Parent1, Parent2 and Child are refreshed.
- *
- * @param mavenProject
- * @throws CoreException
- * in case of problem during refresh
- */
- private void refreshHierarchy(MavenProject mavenProject, IProgressMonitor monitor)
throws CoreException {
- try {
- File basedir = mavenProject.getBasedir();
- IProject project = getProjectAt(basedir);
- while (project != null) {
- project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
- basedir = basedir.getParentFile();
- project = getProjectAt(basedir);
- }
- } finally {
- monitor.done();
- }
- }
- /**
- * Returns the project given its absolute location on the filesystem
- * @param basedir
- * @return the project or null if no project exists at the given location
- */
- private IProject getProjectAt(File basedir) {
- IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
- .getProjects();
- for (IProject project : projects) {
- if (project.getLocation().toFile().equals(basedir)) {
- return project;
- }
- }
- return null;
- }
private void configureInternal(MavenProject mavenProject,IProject project,
@@ -169,6 +134,9 @@
if (facetVersion != null) {
IStatus status = facetVersion.getConstraint().check(fproj.getProjectFacets());
if (status.isOK()) {
+ // refreshing the project hierarchy to make sure that Eclipse "sees" the
.settings folder and file, to be able to add the JAX-RS Facet
+ // 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();
Added:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/jaxrs-3layers-child/pom.xml
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/jaxrs-3layers-child/pom.xml
(rev 0)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/jaxrs-3layers-child/pom.xml 2011-11-09
10:47:47 UTC (rev 36244)
@@ -0,0 +1,18 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>jaxrs-3layers-middle</artifactId>
+ <groupId>foo.bar</groupId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>jaxrs-3layers-child</artifactId>
+ <packaging>war</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.spec.javax.ws.rs</groupId>
+ <artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
+ <scope>provided</scope>
+ <version>1.0.0.Final</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Property changes on:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/jaxrs-3layers-child/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/pom.xml
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/pom.xml
(rev 0)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/pom.xml 2011-11-09
10:47:47 UTC (rev 36244)
@@ -0,0 +1,13 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>jaxrs-3layers-root</artifactId>
+ <groupId>foo.bar</groupId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>jaxrs-3layers-middle</artifactId>
+ <packaging>pom</packaging>
+ <modules>
+ <module>jaxrs-3layers-child</module>
+ </modules>
+</project>
\ No newline at end of file
Property changes on:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/pom.xml
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/pom.xml
(rev 0)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/pom.xml 2011-11-09
10:47:47 UTC (rev 36244)
@@ -0,0 +1,10 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>foo.bar</groupId>
+ <artifactId>jaxrs-3layers-root</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <modules>
+ <module>jaxrs-3layers-middle</module>
+ </modules>
+</project>
\ No newline at end of file
Property changes on:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/projects/jaxrs/jaxrs-3layers-root/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/core/ProjectUtilTest.java
===================================================================
---
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/core/ProjectUtilTest.java
(rev 0)
+++
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/core/ProjectUtilTest.java 2011-11-09
10:47:47 UTC (rev 36244)
@@ -0,0 +1,28 @@
+package org.jboss.tools.maven.core;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.m2e.core.project.ResolverConfiguration;
+import org.jboss.tools.maven.configurators.tests.AbstractMavenConfiguratorTest;
+import org.junit.Test;
+
+@SuppressWarnings("restriction")
+public class ProjectUtilTest extends AbstractMavenConfiguratorTest {
+
+ @Test
+ public void testShouldRefreshProjectHierarchy() throws IOException, CoreException,
InterruptedException {
+ //String projectLocation =
"projects/jaxrs/jaxrs-3layers-root/jaxrs-3layers-middle/jaxrs-3layers-child";
+ IProject[] jaxrsProject = importProjects("projects/jaxrs/",
+ new String[]{"jaxrs-3layers-root/pom.xml",
+ "jaxrs-3layers-root/jaxrs-3layers-middle/pom.xml",
+ "jaxrs-3layers-root/jaxrs-3layers-middle/jaxrs-3layers-child/pom.xml"}, new
ResolverConfiguration());
+ waitForJobsToComplete(new NullProgressMonitor());
+ File basedir = jaxrsProject[2].getLocation().toFile();
+ assertEquals(3, ProjectUtil.refreshHierarchy(basedir, IResource.DEPTH_INFINITE, new
NullProgressMonitor()));
+ }
+}
Property changes on:
trunk/maven/tests/org.jboss.tools.maven.configurators.tests/src/org/jboss/tools/maven/core/ProjectUtilTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain