Skip to content

Commit

Permalink
Fix #186: issues with m2e configurator for gmaven source folders
Browse files Browse the repository at this point in the history
  • Loading branch information
kdvolder committed Jul 12, 2016
1 parent 1b267ac commit 31fe9f3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions extras/org.codehaus.groovy.m2eclipse/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 0 additions & 1 deletion extras/org.codehaus.groovy.m2eclipse/.project
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eclipse.preferences.version=1
groovy.compiler.level=21
groovy.compiler.level=23
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
*******************************************************************************/
package org.codehaus.groovy.m2eclipse;

import java.util.HashSet;
import java.util.Set;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.project.MavenProject;
import org.codehaus.groovy.eclipse.core.model.GroovyRuntime;
import org.codehaus.jdt.groovy.model.GroovyNature;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -37,7 +41,10 @@
public class GroovyProjectConfigurator extends AbstractJavaProjectConfigurator
implements IJavaProjectConfigurator {

@Override
private static final String SRC_MAIN_GROOVY = "src/main/groovy";
private static final String SRC_TEST_GROOVY = "src/test/groovy";

@Override
public void configure(ProjectConfigurationRequest request,
IProgressMonitor monitor) throws CoreException {
super.configure(request, monitor);
Expand Down Expand Up @@ -69,28 +76,38 @@ public void configureClasspath(IMavenProjectFacade facade,
IJavaProject javaProject = JavaCore.create(facade.getProject());
IPath projectPath = facade.getFullPath();

if (sourceType == SourceType.TEST || sourceType == SourceType.BOTH) {
IPath testPath = projectPath.append("src/test/groovy"); //$NON-NLS-1$
Set<IPath> toRemove = new HashSet<IPath>();

IFolder testFolder = javaProject.getProject().getFolder(SRC_TEST_GROOVY);
IPath testPath = testFolder.getFullPath(); //$NON-NLS-1$
if (testFolder.exists() && (sourceType == SourceType.TEST || sourceType == SourceType.BOTH)) {
IPath testOutPath = projectPath.append("target/test-classes"); //$NON-NLS-1$
if (!hasEntry(javaProject, testPath)) {
GroovyRuntime.addClassPathEntryToFront(javaProject, JavaCore.newSourceEntry(testPath, new Path[0], testOutPath));
}
} else {
toRemove.add(testPath);
}

if (sourceType == SourceType.MAIN || sourceType == SourceType.BOTH) {
IPath sourcePath = projectPath.append("src/main/groovy"); //$NON-NLS-1$
IFolder sourceFolder = javaProject.getProject().getFolder(SRC_MAIN_GROOVY);
IPath sourcePath = sourceFolder.getFullPath();
if (sourceFolder.exists() && (sourceType == SourceType.MAIN || sourceType == SourceType.BOTH)) {
IPath sourceOutPath = projectPath.append("target/classes"); //$NON-NLS-1$
if (!hasEntry(javaProject, sourcePath)) {
GroovyRuntime.addClassPathEntryToFront(javaProject, JavaCore.newSourceEntry(sourcePath, new Path[0], sourceOutPath));
}
} else {
toRemove.add(sourcePath);
}

// now remove the generated sources from the classpath if it exists
// We should remove the generated sources from the classpath if it exists
toRemove.add(projectPath.append("target/generated-sources/groovy-stubs/main"));

// Also remove stuff that was there already which we control, but that shouldn't be there according to the gmaven conf
IClasspathEntry[] allEntries = javaProject.getRawClasspath();
for (IClasspathEntry entry : allEntries) {
if (entry.getPath().equals(javaProject.getProject().getFolder("target/generated-sources/groovy-stubs/main").getFullPath())) {
if (toRemove.contains(entry.getPath())) {
GroovyRuntime.removeClassPathEntry(javaProject, entry);
break;
}
}
}
Expand Down Expand Up @@ -186,8 +203,8 @@ private SourceType getSourceTypeInGMavenProject(Plugin plugin) {
*/
private SourceType getSourceTypeInGECProject(IMavenProjectFacade facade) {
IProject project = facade.getProject();
boolean srcMainGroovy = project.getFolder("src/main/groovy").exists();
boolean srcTestGroovy = project.getFolder("src/test/groovy").exists();
boolean srcMainGroovy = project.getFolder(SRC_MAIN_GROOVY).exists();
boolean srcTestGroovy = project.getFolder(SRC_TEST_GROOVY).exists();
if (srcMainGroovy) {
if (srcTestGroovy) {
return SourceType.BOTH;
Expand Down

0 comments on commit 31fe9f3

Please sign in to comment.