From 7c6bd5bdcb4cf8c31050aeeb102250a27a157728 Mon Sep 17 00:00:00 2001 From: John Dallaway Date: Mon, 25 Jul 2022 15:44:09 +0100 Subject: [PATCH] Bug 580441: Accommodate deleted folder of source files Eliminate ResourceException by avoiding processing a deleted source folder resource as a modified resource. Change-Id: Icfa10040d4d3c6c06b2a4c040e7b632e94dff324 --- .../META-INF/MANIFEST.MF | 2 +- .../core/regressions/Bug_580441Test.java | 70 +++++++++++++++++++ .../META-INF/MANIFEST.MF | 2 +- .../makegen/gnu2/GnuMakefileGenerator.java | 7 +- 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_580441Test.java diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.core.tests/META-INF/MANIFEST.MF index 9d06cc089b6..ccd8ad9d5b8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.core.tests; singleton:=true -Bundle-Version: 8.2.200.qualifier +Bundle-Version: 8.2.300.qualifier Bundle-Activator: org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_580441Test.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_580441Test.java new file mode 100644 index 00000000000..c5dbe8f8852 --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/regressions/Bug_580441Test.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2011, 2022 Broadcom Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Broadcom Corporation - Bug 303953 test + * John Dallaway - Initial implementation (derived from bug 303953 test) + *******************************************************************************/ +package org.eclipse.cdt.managedbuilder.core.regressions; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.ByteArrayInputStream; + +import org.eclipse.cdt.managedbuilder.testplugin.AbstractBuilderTest; +import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.junit.jupiter.api.Test; + +/** + * Test that removal of a directory containing source file(s) is + * processed correctly by the default GnuMakefileGenerator. + */ +public class Bug_580441Test extends AbstractBuilderTest { + + @Test + public void testBuildAfterPopulatedSourceFolderDelete() throws CoreException { + setWorkspace("regressions"); + final IProject app = loadProject("helloworldC"); + + // Create additional source file at src/test/test.c + final IFolder testFolder = app.getFolder("src/test"); + testFolder.create(false, false, null); + testFolder.getFile("test.c").create(new ByteArrayInputStream("int test;".getBytes()), false, null); + + // Build debug configuration + setActiveConfigurationByName(app, "Debug"); + buildConfig(app.getActiveBuildConfig()); + assertTrue(app.getFile("Debug/src/test/test.o").exists(), "test.o not created"); + + // Delete folder containing test.c and build again + testFolder.delete(false, null); + buildConfig(app.getActiveBuildConfig()); + assertFalse(app.getFolder("Debug/src/test").exists(), "test folder not deleted"); + } + + private void buildConfig(IBuildConfiguration config) throws CoreException { + ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { + @Override + public void run(IProgressMonitor monitor) throws CoreException { + ResourcesPlugin.getWorkspace().build(new IBuildConfiguration[] { config }, + IncrementalProjectBuilder.INCREMENTAL_BUILD, true, monitor); + } + }, null); + } + +} diff --git a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF index bb7707b45a0..e83988ef44e 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.managedbuilder.core; singleton:=true -Bundle-Version: 9.4.0.qualifier +Bundle-Version: 9.4.100.qualifier Bundle-Activator: org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu2/GnuMakefileGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu2/GnuMakefileGenerator.java index c1e3d3e71d3..327551719ca 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu2/GnuMakefileGenerator.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu2/GnuMakefileGenerator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2016 IBM Corporation and others. + * Copyright (c) 2003, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -17,6 +17,7 @@ * Marc-Andre Laperle * Liviu Ionescu - [322168] * Dorothea Pilz-Roeder (Advantest Europe GmbH) - [180451] + * John Dallaway - [580441] fix processing on source folder deletion *******************************************************************************/ package org.eclipse.cdt.managedbuilder.makegen.gnu2; @@ -192,7 +193,9 @@ public boolean visit(IResourceDelta delta) throws CoreException { // This is a source file so just add its container if (fo == null || fo.buildsFileType(ext)) { generator.appendDeletedFile(resource); - generator.appendModifiedSubdirectory(resource); + if (resource.getParent().exists()) { + generator.appendModifiedSubdirectory(resource); + } } } break;