Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Tanasenko2016-01-29 22:54:46 +0000
committerFred Bricon2016-02-09 13:49:30 +0000
commit8856d223676122f006498a9e3b9486184edefecf (patch)
tree6e737d0ccb7c1e920c04e3f6606fbda0d8333c49
parente8e85db3c72b4fc534b2eb83500f92f924a28435 (diff)
downloadm2e-core-8856d223676122f006498a9e3b9486184edefecf.tar.gz
m2e-core-8856d223676122f006498a9e3b9486184edefecf.tar.xz
m2e-core-8856d223676122f006498a9e3b9486184edefecf.zip
486721 Eclipse classpathentry generation changed for alternative java
source directories since Mars Change-Id: I924c173f2fad9a58375ff149064bacf2883bf05b Signed-off-by: Anton Tanasenko <atg.sleepless@gmail.com>
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathEntryDescriptor.java4
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java110
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java12
3 files changed, 79 insertions, 47 deletions
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathEntryDescriptor.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathEntryDescriptor.java
index b505651f..9ba99c33 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathEntryDescriptor.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClasspathEntryDescriptor.java
@@ -53,12 +53,16 @@ public interface IClasspathEntryDescriptor {
public void addInclusionPattern(IPath pattern);
+ public void removeInclusionPattern(IPath pattern);
+
public void setInclusionPatterns(IPath[] inclusionPatterns);
public IPath[] getInclusionPatterns();
public void addExclusionPattern(IPath pattern);
+ public void removeExclusionPattern(IPath pattern);
+
public void setExclusionPatterns(IPath[] exclusionPatterns);
public IPath[] getExclusionPatterns();
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
index b08f0715..f65355f9 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java
@@ -249,12 +249,14 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
if(isCompileExecution(compile)) {
mainSourceEncoding = maven.getMojoParameterValue(mavenProject, compile, "encoding", String.class, monitor); //$NON-NLS-1$
try {
- inclusion = toPaths(maven.getMojoParameterValue(mavenProject, compile, "includes", String[].class, monitor)); //$NON-NLS-1$
+ inclusion = toPaths(
+ maven.getMojoParameterValue(mavenProject, compile, "includes", String[].class, monitor)); //$NON-NLS-1$
} catch(CoreException ex) {
log.error("Failed to determine compiler inclusions, assuming defaults", ex);
}
try {
- exclusion = toPaths(maven.getMojoParameterValue(mavenProject, compile, "excludes", String[].class, monitor)); //$NON-NLS-1$
+ exclusion = toPaths(
+ maven.getMojoParameterValue(mavenProject, compile, "excludes", String[].class, monitor)); //$NON-NLS-1$
} catch(CoreException ex) {
log.error("Failed to determine compiler exclusions, assuming defaults", ex);
}
@@ -265,14 +267,14 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
if(isTestCompileExecution(compile)) {
testSourceEncoding = maven.getMojoParameterValue(mavenProject, compile, "encoding", String.class, monitor); //$NON-NLS-1$
try {
- inclusionTest = toPaths(maven.getMojoParameterValue(mavenProject, compile,
- "testIncludes", String[].class, monitor)); //$NON-NLS-1$
+ inclusionTest = toPaths(
+ maven.getMojoParameterValue(mavenProject, compile, "testIncludes", String[].class, monitor)); //$NON-NLS-1$
} catch(CoreException ex) {
log.error("Failed to determine compiler test inclusions, assuming defaults", ex);
}
try {
- exclusionTest = toPaths(maven.getMojoParameterValue(mavenProject, compile,
- "testExcludes", String[].class, monitor)); //$NON-NLS-1$
+ exclusionTest = toPaths(
+ maven.getMojoParameterValue(mavenProject, compile, "testExcludes", String[].class, monitor)); //$NON-NLS-1$
} catch(CoreException ex) {
log.error("Failed to determine compiler test exclusions, assuming defaults", ex);
}
@@ -291,13 +293,13 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
addSourceDirs(classpath, project, mavenProject.getCompileSourceRoots(), classes.getFullPath(), inclusion,
exclusion, mainSourceEncoding, mon.newChild(1));
- addResourceDirs(classpath, project, mavenProject.getBuild().getResources(), classes.getFullPath(),
+ addResourceDirs(classpath, project, mavenProject, mavenProject.getBuild().getResources(), classes.getFullPath(),
mainResourcesEncoding, mon.newChild(1));
addSourceDirs(classpath, project, mavenProject.getTestCompileSourceRoots(), testClasses.getFullPath(),
inclusionTest, exclusionTest, testSourceEncoding, mon.newChild(1));
- addResourceDirs(classpath, project, mavenProject.getBuild().getTestResources(), testClasses.getFullPath(),
- testResourcesEncoding, mon.newChild(1));
+ addResourceDirs(classpath, project, mavenProject, mavenProject.getBuild().getTestResources(),
+ testClasses.getFullPath(), testResourcesEncoding, mon.newChild(1));
} finally {
mon.done();
}
@@ -326,7 +328,7 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
private void addSourceDirs(IClasspathDescriptor classpath, IProject project, List<String> sourceRoots,
IPath outputPath, IPath[] inclusion, IPath[] exclusion, String sourceEncoding, IProgressMonitor monitor)
- throws CoreException {
+ throws CoreException {
for(int i = 0; i < sourceRoots.size(); i++ ) {
IFolder sourceFolder = getFolder(project, sourceRoots.get(i));
@@ -383,8 +385,9 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
return null;
}
- private void addResourceDirs(IClasspathDescriptor classpath, IProject project, List<Resource> resources,
- IPath outputPath, String resourceEncoding, IProgressMonitor monitor) throws CoreException {
+ private void addResourceDirs(IClasspathDescriptor classpath, IProject project, MavenProject mavenProject,
+ List<Resource> resources, IPath outputPath, String resourceEncoding, IProgressMonitor monitor)
+ throws CoreException {
for(Resource resource : resources) {
String directory = resource.getDirectory();
@@ -412,23 +415,24 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
* </resource>
*/
log.error("Skipping resource folder " + r.getFullPath());
+
} else if(r != null && project.equals(r.getProject())) {
- IMavenProjectFacade facade = projectManager.getProject(project);
- IClasspathEntryDescriptor enclosing = getEnclosingEntryDescriptor(classpath, r.getFullPath());
- if(enclosing == null) {
- addResourceFolder(classpath, r.getFullPath(), outputPath, null);
+
+ IPath path = r.getFullPath();
+ IClasspathEntryDescriptor enclosing = getEnclosingEntryDescriptor(classpath, path);
+ if(enclosing != null && overlapsWithSourceFolder(path, project, mavenProject)) {
+ configureOverlapWithSource(classpath, enclosing, path);
+ } else if(overlapsWithOtherResourceFolder(path, project, mavenProject)) {
+ // skip adding resource folders that are included by other resource folders
+ log.info("Skipping resource folder " + path + " since it's contained by another resource folder");
} else {
- IClasspathEntryDescriptor entryDescriptor = getEntryDescriptor(classpath, r.getFullPath());
- if(isNonOverlappingResourceDescriptor(entryDescriptor, facade)) {
- addResourceFolder(classpath, r.getFullPath(), outputPath, entryDescriptor);
- } else {
- addInclusionPattern(classpath, enclosing, r.getFullPath());
- }
+ addResourceFolder(classpath, path, outputPath);
}
// Set folder encoding (null = platform default)
IFolder resourceFolder = project.getFolder(relativePath);
resourceFolder.setDefaultCharset(resourceEncoding, monitor);
+
} else {
log.info("Not adding resources folder " + resourceDirectory.getAbsolutePath());
}
@@ -436,45 +440,57 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon
}
}
- private void addResourceFolder(IClasspathDescriptor classpath, IPath resourceFolder, IPath outputPath,
- IClasspathEntryDescriptor entryDescriptor) {
+ private void addResourceFolder(IClasspathDescriptor classpath, IPath resourceFolder, IPath outputPath) {
log.info("Adding resource folder " + resourceFolder);
- classpath
- .addSourceEntry(resourceFolder, outputPath, DEFAULT_INCLUSIONS, new IPath[] {new Path("**")}, false /*optional*/);
+ classpath.addSourceEntry(resourceFolder, outputPath, DEFAULT_INCLUSIONS, new IPath[] {new Path("**")},
+ false /*optional*/);
}
- private void addInclusionPattern(IClasspathDescriptor classpath, IClasspathEntryDescriptor enclosing,
+ private void configureOverlapWithSource(IClasspathDescriptor classpath, IClasspathEntryDescriptor enclosing,
IPath resourceFolder) {
// resources and sources folders overlap. make sure JDT only processes java sources.
log.info("Resources folder " + resourceFolder + " overlaps with sources folder " + enclosing.getPath());
enclosing.addInclusionPattern(new Path("**/*.java"));
+ enclosing.removeExclusionPattern(new Path("**"));
classpath.touchEntry(resourceFolder);
}
- private boolean isNonOverlappingResourceDescriptor(IClasspathEntryDescriptor cped, IMavenProjectFacade facade) {
- if(cped != null) {
- IProject project = facade.getProject();
- IPath path = cped.getPath();
- if(isContained(path, project, facade.getCompileSourceLocations())
- || isContained(path, project, facade.getTestCompileSourceLocations())) {
- // it's a source folder as well, so here we're having an overlap
- return false;
- }
- return isContained(path, project, facade.getResourceLocations())
- || isContained(path, project, facade.getTestResourceLocations());
+ private boolean overlapsWithSourceFolder(IPath path, IProject project, MavenProject mavenProject) {
+ IPath relPath = path.makeRelativeTo(project.getFullPath());
+ List<String> compile = mavenProject.getCompileSourceRoots();
+ List<String> test = mavenProject.getTestCompileSourceRoots();
+ return isContained(relPath, project, getSourceFolders(project, compile))
+ || isContained(relPath, project, getSourceFolders(project, test));
+ }
+
+ private boolean overlapsWithOtherResourceFolder(IPath path, IProject project, MavenProject mavenProject) {
+ IPath relPath = path.makeRelativeTo(project.getFullPath());
+ return isContained(relPath, project, getOtherResourceFolders(project, mavenProject.getResources(), relPath))
+ || isContained(relPath, project, getOtherResourceFolders(project, mavenProject.getTestResources(), relPath));
+ }
+
+ private IPath[] getSourceFolders(IProject project, List<String> sources) {
+ List<IPath> paths = new ArrayList<>();
+ for(String source : sources) {
+ paths.add(getProjectRelativePath(project, source));
}
- return false;
+ return paths.toArray(new IPath[paths.size()]);
}
- private boolean isContained(IPath fullpath, IProject project, IPath[] relativePathes) {
- for(IPath location : relativePathes) {
- IPath expanded = null;
- if(location.isEmpty()) {
- expanded = project.getFullPath();
- } else {
- expanded = project.getFolder(location).getFullPath();
+ private IPath[] getOtherResourceFolders(IProject project, List<Resource> resources, IPath curPath) {
+ List<IPath> paths = new ArrayList<>();
+ for(Resource res : resources) {
+ IPath path = getProjectRelativePath(project, res.getDirectory());
+ if(!path.equals(curPath)) {
+ paths.add(path);
}
- if(expanded.equals(fullpath)) {
+ }
+ return paths.toArray(new IPath[paths.size()]);
+ }
+
+ private boolean isContained(IPath path, IProject project, IPath[] otherPaths) {
+ for(IPath otherPath : otherPaths) {
+ if(otherPath.isPrefixOf(path)) {
return true;
}
}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java
index bbf4c509..3dae0f22 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ClasspathEntryDescriptor.java
@@ -296,6 +296,12 @@ public class ClasspathEntryDescriptor implements IClasspathEntryDescriptor {
inclusionPatterns.add(pattern);
}
+ public void removeInclusionPattern(IPath pattern) {
+ if(inclusionPatterns != null) {
+ inclusionPatterns.remove(pattern);
+ }
+ }
+
public IPath[] getInclusionPatterns() {
return inclusionPatterns != null ? inclusionPatterns.toArray(new IPath[inclusionPatterns.size()]) : null;
}
@@ -315,6 +321,12 @@ public class ClasspathEntryDescriptor implements IClasspathEntryDescriptor {
exclusionPatterns.add(pattern);
}
+ public void removeExclusionPattern(IPath pattern) {
+ if(exclusionPatterns != null) {
+ exclusionPatterns.remove(pattern);
+ }
+ }
+
public IPath[] getExclusionPatterns() {
return exclusionPatterns != null ? exclusionPatterns.toArray(new IPath[exclusionPatterns.size()]) : null;
}

Back to the top