From 1e4fa5da22a4a8973c587c80481fc630f7a888e7 Mon Sep 17 00:00:00 2001 From: qxo <49526356@qq.com> Date: Sun, 17 Dec 2023 08:19:23 +0000 Subject: [PATCH] feat: classpathentry should respect pom resource excludes/includes,: so we build project on eclipse without org.eclipse.m2e.core.maven2Builder --- .../AbstractJavaProjectConfigurator.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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 46fa54450f..0b6ef778ff 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 @@ -566,7 +566,7 @@ private void addResourceDirs(IClasspathDescriptor classpath, IProject project, M // 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 { - addResourceFolder(classpath, path, outputPath, addTestFlag); + addResourceFolder(classpath, path, outputPath, addTestFlag, resource); } // Set folder encoding (null = platform default) if(r.exists()) { @@ -579,14 +579,29 @@ private void addResourceDirs(IClasspathDescriptor classpath, IProject project, M } private void addResourceFolder(IClasspathDescriptor classpath, IPath resourceFolder, IPath outputPath, - boolean addTestFlag) { + boolean addTestFlag, Resource resource) { log.info("Adding resource folder " + resourceFolder); - IClasspathEntryDescriptor descriptor = classpath.addSourceEntry(resourceFolder, outputPath, DEFAULT_INCLUSIONS, - new IPath[] {IPath.fromOSString("**/*.java")}, false /*optional*/); + IClasspathEntryDescriptor descriptor = classpath.addSourceEntry(resourceFolder, outputPath, + toIPathList(resource.getIncludes(), null), + toIPathList(resource.getExcludes(), "**/*.java"), false /*optional*/); descriptor.setClasspathAttribute(IClasspathManager.TEST_ATTRIBUTE, addTestFlag ? "true" : null); descriptor.setClasspathAttribute(IClasspathAttribute.OPTIONAL, "true"); //$NON-NLS-1$ } + private IPath[] toIPathList(final List fileNames, final String defaultPattern) { + if (fileNames == null) { + return defaultPattern != null ? new IPath[] {IPath.fromOSString(defaultPattern)} : DEFAULT_INCLUSIONS; + } + final List retList = new ArrayList<>(); + for (final String files : fileNames) { + retList.add(IPath.fromOSString(files)); + } + if (defaultPattern != null) { + retList.add(IPath.fromOSString(defaultPattern)); + } + return retList.toArray(DEFAULT_INCLUSIONS); + } + private void configureOverlapWithSource(IClasspathDescriptor classpath, IClasspathEntryDescriptor enclosing, IPath resourceFolder) { // resources and sources folders overlap. make sure JDT only processes java sources.