diff options
author | Stephan Herrmann | 2017-11-03 19:05:30 +0000 |
---|---|---|
committer | Stephan Herrmann | 2017-11-03 19:05:30 +0000 |
commit | 07f98b747cf0851561570ca89ab65b6276b9c6fd (patch) | |
tree | dba720bf248958852d9af5cdb30a8e67faaa225c | |
parent | b4af11e5f88c03f77aef1a873bd52ed20d0bac71 (diff) | |
download | eclipse.jdt.core-07f98b747cf0851561570ca89ab65b6276b9c6fd.tar.gz eclipse.jdt.core-07f98b747cf0851561570ca89ab65b6276b9c6fd.tar.xz eclipse.jdt.core-07f98b747cf0851561570ca89ab65b6276b9c6fd.zip |
modular projects
Change-Id: I14c1691f106f1005c7e0db88af2db3400bf29f70
3 files changed, 60 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java index be1950e836..53543d79cd 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModuleBuilderTests.java @@ -6204,6 +6204,53 @@ public class ModuleBuilderTests extends ModifyingResourceTests { } } + public void testBug526054() throws Exception { + if (!isJRE9) return; + String save = System.getProperty("modules.to.load"); + System.setProperty("modules.to.load", ""); // load all + JRTUtil.reset(); + ClasspathJrt.resetCaches(); + try { + IJavaProject javaProject = createJava9Project("mod1", new String[] {"src"}); + + String srcMod = + "module mod1 {\n" + + " exports com.mod1.pack1;\n" + + " requires java.xml.ws.annotation;\n" + + "}"; + createFile("/mod1/src/module-info.java", + srcMod); + createFolder("/mod1/src/com/mod1/pack1"); + String srcX = + "package com.mod1.pack1;\n" + + "@javax.annotation.Generated(\"com.acme.generator.CodeGen\")\n" + + "public class Dummy {\n" + + "}"; + createFile("/mod1/src/com/mod1/pack1/Dummy.java", srcX); + + this.problemRequestor.initialize(srcMod.toCharArray()); + getWorkingCopy("/mod1/src/module-info.java", srcMod, true); + assertProblems("module-info should have no problems", + "----------\n" + + "----------\n", + this.problemRequestor); + + this.problemRequestor.initialize(srcX.toCharArray()); + getWorkingCopy("/mod1/src/com/mod1/pack1/Dummy.java", srcX, true); + assertProblems("Dummy should have no problems", + "----------\n" + + "----------\n", + this.problemRequestor); + + javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + assertNoErrors(); + } finally { + System.setProperty("modules.to.load", save); + JRTUtil.reset(); + ClasspathJrt.resetCaches(); + deleteProject("mod1"); + } + } protected void assertNoErrors() throws CoreException { for (IProject p : getWorkspace().getRoot().getProjects()) { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java index 6e804e657a..855525db79 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJrt.java @@ -47,6 +47,8 @@ private String externalAnnotationPath; private ZipFile annotationZipFile; String zipFilename; // keep for equals +static final Set<String> NO_LIMIT_MODULES = new HashSet<>(); + public ClasspathJrt(String zipFilename, IPath externalAnnotationPath) { this.zipFilename = zipFilename; if (externalAnnotationPath != null) @@ -266,7 +268,9 @@ public Collection<String> getModuleNames(Collection<String> limitModules) { private Collection<String> selectModules(Set<String> keySet, Collection<String> limitModules) { Collection<String> rootModules; - if (limitModules != null) { + if (limitModules == NO_LIMIT_MODULES) { + rootModules = new HashSet<>(keySet); + } else if (limitModules != null) { Set<String> result = new HashSet<>(keySet); result.retainAll(limitModules); rootModules = result; diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java index 9b0f03a0d9..bcf5f72c6c 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java @@ -112,8 +112,8 @@ private void computeClasspathLocations( moduleEntries = new HashMap<>(classpathEntries.length); this.moduleUpdater = new ModuleUpdater(javaProject); } - IModuleDescription mod = null; - + IModuleDescription projectModule = javaProject.getModuleDescription(); + String patchedModuleName = ModuleEntryProcessor.pushPatchToFront(classpathEntries); IModule patchedModule = null; @@ -208,6 +208,7 @@ private void computeClasspathLocations( if (moduleEntries != null && isOnModulePath && projectLocations.size() > 0) { IModule info = null; try { + IModuleDescription mod; if ((mod = prereqJavaProject.getModuleDescription()) != null) { SourceModule sourceModule = (SourceModule) mod; info = (ModuleDescriptionInfo) sourceModule.getElementInfo(); @@ -275,8 +276,9 @@ private void computeClasspathLocations( ClasspathLocation bLocation = ClasspathLocation.forLibrary(path.toOSString(), accessRuleSet, externalAnnotationPath, isOnModulePath); bLocations.add(bLocation); if (moduleEntries != null) { + Set<String> libraryLimitModules = (limitModules == null && projectModule != null) ? ClasspathJrt.NO_LIMIT_MODULES : limitModules; patchedModule = collectModuleEntries(bLocation, path, isOnModulePath, - limitModules, patchedModuleName, patchedModule, moduleEntries); + libraryLimitModules, patchedModuleName, patchedModule, moduleEntries); } } continue nextEntry; @@ -288,9 +290,9 @@ private void computeClasspathLocations( this.sourceLocations = new ClasspathMultiDirectory[sLocations.size()]; if (!sLocations.isEmpty()) { sLocations.toArray(this.sourceLocations); - if (moduleEntries != null && (mod = javaProject.getModuleDescription()) != null) { + if (moduleEntries != null && projectModule != null) { try { - AbstractModule sourceModule = (AbstractModule)mod; + AbstractModule sourceModule = (AbstractModule)projectModule; ModuleDescriptionInfo info = (ModuleDescriptionInfo) sourceModule.getElementInfo(); ModulePathEntry projectEntry = new ModulePathEntry(javaProject.getPath(), info, this.sourceLocations); if (!moduleEntries.containsKey(sourceModule.getElementName())) { // can be registered already, if patching @@ -351,7 +353,7 @@ IModule collectModuleEntries(ClasspathLocation bLocation, IPath path, boolean is IModule module = binaryModulePathEntry.getModule(); if (module != null) { String moduleName = String.valueOf(module.name()); - if (limitModules == null || limitModules.contains(moduleName)) { + if (limitModules == null || limitModules == ClasspathJrt.NO_LIMIT_MODULES || limitModules.contains(moduleName)) { moduleEntries.put(moduleName, binaryModulePathEntry); if (patchedModuleName != null) { if (moduleName.equals(patchedModuleName)) |