Author: fbricon
Date: 2011-10-24 05:00:26 -0400 (Mon, 24 Oct 2011)
New Revision: 35924
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/ILibraryMaterializationPostProcessor.java
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/ILibraryMaterializationPostProcessorFactory.java
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/MaterializeLibraryJob.java
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/internal/buildpath/LibraryMaterializationPostProcessorFactory.java
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/internal/buildpath/MavenLibraryMaterializationPostProcessor.java
Log:
JBIDE-9996 : fix remove exclusion patterns on source folders when materializing Maven
Library
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/ILibraryMaterializationPostProcessor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/ILibraryMaterializationPostProcessor.java 2011-10-24
06:56:50 UTC (rev 35923)
+++
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/ILibraryMaterializationPostProcessor.java 2011-10-24
09:00:26 UTC (rev 35924)
@@ -1,13 +1,23 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 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.common.jdt.core.buildpath;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
public interface ILibraryMaterializationPostProcessor {
- void execute(IJavaProject javaProject, IPath containerPath) throws CoreException;
+ void execute(IJavaProject javaProject, IPath containerPath, IProgressMonitor monitor)
throws CoreException;
boolean applies(IJavaProject javaProject, IPath containerPath) throws CoreException;
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/ILibraryMaterializationPostProcessorFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/ILibraryMaterializationPostProcessorFactory.java 2011-10-24
06:56:50 UTC (rev 35923)
+++
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/ILibraryMaterializationPostProcessorFactory.java 2011-10-24
09:00:26 UTC (rev 35924)
@@ -1,3 +1,13 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 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.common.jdt.core.buildpath;
public interface ILibraryMaterializationPostProcessorFactory {
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/MaterializeLibraryJob.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/MaterializeLibraryJob.java 2011-10-24
06:56:50 UTC (rev 35923)
+++
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/buildpath/MaterializeLibraryJob.java 2011-10-24
09:00:26 UTC (rev 35924)
@@ -90,7 +90,7 @@
//Finally execute post processors (needed to remove project nature, for ex.)
for (ILibraryMaterializationPostProcessor processor : getPostProcessors()) {
- processor.execute(javaProject, containerToRemovePath);
+ processor.execute(javaProject, containerToRemovePath, monitor);
}
//Refresh project
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/internal/buildpath/LibraryMaterializationPostProcessorFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/internal/buildpath/LibraryMaterializationPostProcessorFactory.java 2011-10-24
06:56:50 UTC (rev 35923)
+++
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/internal/buildpath/LibraryMaterializationPostProcessorFactory.java 2011-10-24
09:00:26 UTC (rev 35924)
@@ -1,3 +1,13 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 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.common.jdt.core.internal.buildpath;
import org.jboss.tools.common.jdt.core.buildpath.ILibraryMaterializationPostProcessor;
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/internal/buildpath/MavenLibraryMaterializationPostProcessor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/internal/buildpath/MavenLibraryMaterializationPostProcessor.java 2011-10-24
06:56:50 UTC (rev 35923)
+++
trunk/common/plugins/org.jboss.tools.common.jdt/src/org/jboss/tools/common/jdt/core/internal/buildpath/MavenLibraryMaterializationPostProcessor.java 2011-10-24
09:00:26 UTC (rev 35924)
@@ -1,26 +1,78 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 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.common.jdt.core.internal.buildpath;
+import java.util.ArrayList;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+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.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.jdt.core.buildpath.ILibraryMaterializationPostProcessor;
-public class MavenLibraryMaterializationPostProcessor implements
ILibraryMaterializationPostProcessor {
+class MavenLibraryMaterializationPostProcessor implements
ILibraryMaterializationPostProcessor {
- private static final String MAVEN_NATURE_ID =
"org.eclipse.m2e.core.maven2Nature";
-
- public boolean applies(IJavaProject javaProject, IPath containerPath) throws
CoreException {
- boolean applies = javaProject != null &&
javaProject.getProject().hasNature(MAVEN_NATURE_ID)
- &&
("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER".equals(containerPath.toPortableString()));
- return applies;
- }
-
- public void execute(IJavaProject javaProject, IPath containerPath) throws CoreException
{
- if (applies(javaProject, containerPath)) {
- System.err.println("Removing "+ MAVEN_NATURE_ID + " from "+
javaProject.getProject().getName());
- EclipseUtil.removeNatureFromProject(javaProject.getProject(), MAVEN_NATURE_ID);
- }
- }
+ private static final String MAVEN_NATURE_ID =
"org.eclipse.m2e.core.maven2Nature";
+ public boolean applies(IJavaProject javaProject, IPath containerPath) throws
CoreException {
+ boolean applies = javaProject != null
+ && javaProject.getProject().hasNature(MAVEN_NATURE_ID)
+ && ("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"
+ .equals(containerPath.toPortableString()));
+ return applies;
+ }
+
+ public void execute(IJavaProject javaProject, IPath containerPath,
+ IProgressMonitor monitor) throws CoreException {
+ if (applies(javaProject, containerPath)) {
+ removeExclusionPatterns(javaProject, monitor);
+ EclipseUtil.removeNatureFromProject(javaProject.getProject(), MAVEN_NATURE_ID);
+ }
+ }
+
+ private void removeExclusionPatterns(IJavaProject javaProject, IProgressMonitor monitor)
throws JavaModelException {
+ IClasspathEntry[] entries = javaProject.getRawClasspath();
+ ArrayList<IClasspathEntry> newEntriesList = new
ArrayList<IClasspathEntry>(entries.length);
+ for (IClasspathEntry entry : entries) {
+ if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ IPath[] newExclusionPatterns = getExclusionPatterns(entry.getExclusionPatterns());
+ IClasspathEntry newEntry = JavaCore.newSourceEntry( entry.getPath(),
+ entry.getInclusionPatterns(),
+ newExclusionPatterns,
+ entry.getOutputLocation(),
+ entry.getExtraAttributes());
+ newEntriesList.add(newEntry);
+ } else {
+ newEntriesList.add(entry);
+ }
+ }
+
+ IClasspathEntry[] newEntries = new IClasspathEntry[newEntriesList.size()];
+ newEntriesList.toArray(newEntries);
+ javaProject.setRawClasspath(newEntries, monitor);
+ }
+
+ private IPath[] getExclusionPatterns(IPath[] existingPatterns ) {
+ ArrayList<IPath> exclusionPatterns = new
ArrayList<IPath>(existingPatterns.length);
+ for (IPath p : existingPatterns) {
+ if (!"**".equals(p.toPortableString())) {
+ exclusionPatterns.add(p);
+ }
+ }
+ IPath[] newExclusionPatterns = new IPath[exclusionPatterns.size()];
+ exclusionPatterns.toArray(newExclusionPatterns);
+ return newExclusionPatterns;
+ }
}