Skip to content

Commit

Permalink
Bug 580441: Accommodate deleted folder of source files
Browse files Browse the repository at this point in the history
Eliminate ResourceException by avoiding processing a deleted source
folder resource as a modified resource.

Change-Id: Icfa10040d4d3c6c06b2a4c040e7b632e94dff324
  • Loading branch information
jld01 committed Jul 26, 2022
1 parent 96839a0 commit 7c6bd5b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7c6bd5b

Please sign in to comment.