diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/README.txt b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/README.txt index 58b16439453..5368853f439 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/README.txt +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/README.txt @@ -3,5 +3,9 @@ helloworldC.zip: Basic standard Linux GCC C HelloWorld ManagedBuild Project template. Contains Debug + Release configurations. +helloworldCPP.zip: + Minimal standard Linux GCC C++ HelloWorld ManagedBuild Project template + Contains Debug + Release configurations. + bug_335476.zip: Test for noticing environment variable changes. \ No newline at end of file diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/helloworldCPP.zip b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/helloworldCPP.zip index 1b7db76c4f1..c92696a4e14 100644 Binary files a/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/helloworldCPP.zip and b/build/org.eclipse.cdt.managedbuilder.core.tests/resources/builderTests/regressions/helloworldCPP.zip differ diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/CompilationDatabaseGenerationTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/CompilationDatabaseGenerationTest.java index 98739c76c80..d44dc2c2530 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/CompilationDatabaseGenerationTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/CompilationDatabaseGenerationTest.java @@ -15,38 +15,34 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.FileReader; -import java.io.IOException; -import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.core.jsoncdb.CompilationDatabaseInformation; +import org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder; import org.eclipse.cdt.managedbuilder.testplugin.AbstractBuilderTest; import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.preferences.ScopedPreferenceStore; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import com.google.gson.JsonIOException; public class CompilationDatabaseGenerationTest extends AbstractBuilderTest { /** * Tests generation of compile_commands.json in "build" folder - * @throws CoreException */ @Test - public void testCompilationDatabaseGeneration() throws CoreException { + public void testCompilationDatabaseGeneration() throws Exception { setWorkspace("regressions"); final IProject app = loadProject("helloworldC"); - isGenerateFileOptionEnabled(true); + setGenerateFileOptionEnabled(true); app.build(IncrementalProjectBuilder.FULL_BUILD, null); IFile compilationDatabase = app.getFile("build/compile_commands.json"); assertTrue(compilationDatabase.exists()); @@ -54,14 +50,12 @@ public void testCompilationDatabaseGeneration() throws CoreException { /** * Tests format for compile_commands.json. JSON array is expected, containing an element for the c file - * @throws JsonIOException - * @throws CoreException */ @Test - public void testJsonFormat() throws JsonIOException, CoreException { + public void testJsonFormat() throws Exception { setWorkspace("regressions"); final IProject app = loadProject("helloworldC"); - isGenerateFileOptionEnabled(true); + setGenerateFileOptionEnabled(true); app.build(IncrementalProjectBuilder.FULL_BUILD, null); IFile commandsFile = app.getFile("build/compile_commands.json"); if (commandsFile.exists()) { @@ -69,7 +63,6 @@ public void testJsonFormat() throws JsonIOException, CoreException { try (FileReader reader = new FileReader(commandsFile.getLocation().toFile())) { Gson gson = new Gson(); JsonArray jsonArray = gson.fromJson(reader, JsonArray.class); - System.out.println(jsonArray); for (JsonElement element : jsonArray) { CompilationDatabaseInformation compileCommand = gson.fromJson(element, CompilationDatabaseInformation.class); @@ -80,8 +73,6 @@ public void testJsonFormat() throws JsonIOException, CoreException { assertTrue(compileCommand.file().endsWith("src/helloworldC.c")); } - } catch (IOException e) { - assertTrue(false); } } @@ -89,14 +80,13 @@ public void testJsonFormat() throws JsonIOException, CoreException { /** * Test that compile_commands.json is correctly generated when more than one .c file is present as a source file - * @throws CoreException */ @Test - public void testMultipleFiles() throws CoreException { + public void testMultipleFiles() throws Exception { setWorkspace("regressions"); final IProject app = loadProject("helloworldC"); IFile aFile = ManagedBuildTestHelper.createFile(app, "src/newFile.c"); - isGenerateFileOptionEnabled(true); + setGenerateFileOptionEnabled(true); app.build(IncrementalProjectBuilder.FULL_BUILD, null); IFile commandsFile = app.getFile("build/compile_commands.json"); int numberOfElementsFound = 0; @@ -120,31 +110,24 @@ public void testMultipleFiles() throws CoreException { assertEquals(2, numberOfElementsFound); assertTrue(helloworldCIsPresent); assertTrue(newFileIsPresent); - } catch (IOException e) { - assertTrue(false); } - } /** * Tests that cpp files are handled by compile_commands.json file generator - * @throws CoreException */ @Test - @Ignore("This will be temporary skipped due to builder error") - public void isCPPFileAllowed() throws CoreException { + public void isCPPFileAllowed() throws Exception { setWorkspace("regressions"); final IProject app = loadProject("helloworldCPP"); - isGenerateFileOptionEnabled(true); + setGenerateFileOptionEnabled(true); app.build(IncrementalProjectBuilder.FULL_BUILD, null); - System.out.println(app.getLocation()); IFile commandsFile = app.getFile("build/compile_commands.json"); if (commandsFile.exists()) { try (FileReader reader = new FileReader(commandsFile.getLocation().toFile())) { Gson gson = new Gson(); JsonArray jsonArray = gson.fromJson(reader, JsonArray.class); - System.out.println(jsonArray); for (JsonElement element : jsonArray) { CompilationDatabaseInformation compileCommand = gson.fromJson(element, CompilationDatabaseInformation.class); @@ -155,35 +138,33 @@ public void isCPPFileAllowed() throws CoreException { assertTrue(compileCommand.file().endsWith("src/helloworldCPP.cpp")); } - } catch (IOException e) { - assertTrue(false); } } } /** * Tests that compilation database is not generated when feature is disabled - * @throws CoreException */ @Test - public void testCompilationDatabaseGenerationNotEnabled() throws CoreException { + public void testCompilationDatabaseGenerationNotEnabled() throws Exception { setWorkspace("regressions"); final IProject app = loadProject("helloworldC"); - isGenerateFileOptionEnabled(false); + setGenerateFileOptionEnabled(false); app.build(IncrementalProjectBuilder.FULL_BUILD, null); IFile compilationDatabase = app.getFile("build/compile_commands.json"); assertFalse(compilationDatabase.exists()); } - public static boolean isGenerateFileOptionEnabled(boolean value) { - try { - IPreferenceStore preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, - "org.eclipse.cdt.managedbuilder.ui"); //$NON-NLS-1$ - preferenceStore.setDefault("generateFile", value); - return preferenceStore.getBoolean("generateFile"); - } catch (Exception e) { - ManagedBuilderCorePlugin.log(e); - } - return false; + private static void setGenerateFileOptionEnabled(boolean value) { + IPreferenceStore preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, + "org.eclipse.cdt.managedbuilder.ui"); + preferenceStore.setValue(CommonBuilder.COMPILATION_DATABASE_ENABLEMENT, value); + } + + @AfterEach + public void restoreDefaultForGenerateFile() { + IPreferenceStore preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, + "org.eclipse.cdt.managedbuilder.ui"); + preferenceStore.setToDefault(CommonBuilder.COMPILATION_DATABASE_ENABLEMENT); } } diff --git a/build/org.eclipse.cdt.managedbuilder.core/.project b/build/org.eclipse.cdt.managedbuilder.core/.project index cab798d8b70..70542d7e9d9 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/.project +++ b/build/org.eclipse.cdt.managedbuilder.core/.project @@ -25,6 +25,11 @@ + + org.eclipse.pde.ds.core.builder + + + org.eclipse.jdt.core.javanature 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 d82ef0e4309..3d59b08efd7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.core/META-INF/MANIFEST.MF @@ -16,6 +16,7 @@ Export-Package: org.eclipse.cdt.build.core.scannerconfig, org.eclipse.cdt.managedbuilder.envvar, org.eclipse.cdt.managedbuilder.internal.buildmodel;x-friends:="org.eclipse.cdt.managedbuilder.ui", org.eclipse.cdt.managedbuilder.internal.core;x-friends:="org.eclipse.cdt.managedbuilder.ui,org.eclipse.cdt.managedbuilder.headlessbuilderapp", + org.eclipse.cdt.managedbuilder.internal.core.jsoncdb.generator;x-internal:=true, org.eclipse.cdt.managedbuilder.internal.dataprovider;x-internal:=true, org.eclipse.cdt.managedbuilder.internal.envvar;x-internal:=true, org.eclipse.cdt.managedbuilder.internal.language.settings.providers;x-friends:="org.eclipse.cdt.managedbuilder.ui", diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java index e0dab6f4188..58e9bd75771 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/CommonBuilder.java @@ -97,7 +97,7 @@ public class CommonBuilder extends ACBuilder implements IIncrementalProjectBuild private static final String NEWLINE = System.getProperty("line.separator"); //$NON-NLS-1$ private static final String TRACE_FOOTER = "]: "; //$NON-NLS-1$ private static final String TRACE_HEADER = "GeneratedmakefileBuilder trace ["; //$NON-NLS-1$ - private static final String COMPILATION_DATABASE_ENABLEMENT = "generateFile"; //$NON-NLS-1$ + public static final String COMPILATION_DATABASE_ENABLEMENT = "generateCBDFile"; //$NON-NLS-1$ public static boolean VERBOSE = false; private static final int PROGRESS_MONITOR_SCALE = 100; diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/CompilationDatabaseGeneratorBlock.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/CompilationDatabaseGeneratorBlock.java index d100730449e..cf00edf4578 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/CompilationDatabaseGeneratorBlock.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/CompilationDatabaseGeneratorBlock.java @@ -9,6 +9,7 @@ ********************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; +import org.eclipse.cdt.managedbuilder.internal.core.CommonBuilder; import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage; import org.eclipse.cdt.ui.dialogs.ICOptionContainer; @@ -33,15 +34,14 @@ */ public class CompilationDatabaseGeneratorBlock extends AbstractCOptionPage { - private static final String PREF_PAGE_ID = "org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase.JsonCdbGeneratorPreferencePage"; //$NON-NLS-1$ - private final String ENABLE_FILE_GENERATION = "generateFile"; //$NON-NLS-1$ + private static final String PREF_PAGE_ID = "org.eclipse.cdt.managedbuilder.ui.compilationdatabase.JsonCdbPreferencePage"; //$NON-NLS-1$ + private final String ENABLE_FILE_GENERATION = CommonBuilder.COMPILATION_DATABASE_ENABLEMENT; private Button generateFileCheckbox; private IPreferenceStore preferenceStore; private PreferenceScopeBlock fPrefScopeBlock; - protected CompilationDatabaseGeneratorBlock() { + public CompilationDatabaseGeneratorBlock() { preferenceStore = ManagedBuilderUIPlugin.getDefault().getPreferenceStore(); - performDefaults(); } @Override @@ -66,21 +66,16 @@ protected void onPreferenceScopeChange() { generateFileCheckbox = new Button(cdbGeneratorOptions, SWT.CHECK); generateFileCheckbox.setSelection(preferenceStore.getBoolean(ENABLE_FILE_GENERATION)); generateFileCheckbox.setText(Messages.JsonCdbGeneratorPreferencePage_generateCompilationdatabase); - generateFileCheckbox.addListener(SWT.Selection, e -> { - boolean newValue = generateFileCheckbox.getSelection(); - preferenceStore.setValue(ENABLE_FILE_GENERATION, newValue); - }); - } @Override public void performDefaults() { - preferenceStore.setDefault(ENABLE_FILE_GENERATION, false); + preferenceStore.setToDefault(ENABLE_FILE_GENERATION); } @Override public void performApply(IProgressMonitor monitor) throws CoreException { - this.performApply(monitor); + preferenceStore.setValue(ENABLE_FILE_GENERATION, generateFileCheckbox.getSelection()); } private IProject getProject() { diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java index 88c67a21db9..dc2361a25ce 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPreferencePage.java @@ -9,10 +9,12 @@ ********************************************************************************/ package org.eclipse.cdt.managedbuilder.internal.ui.compilationdatabase; +import org.eclipse.cdt.managedbuilder.ui.properties.ManagedBuilderUIPlugin; import org.eclipse.cdt.ui.dialogs.ICOptionContainer; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -72,6 +74,7 @@ public boolean performOk() { try { fOptionBlock.performApply(new NullProgressMonitor()); } catch (CoreException e) { + ManagedBuilderUIPlugin.log(Status.error("Failed to save JSON Compilation Database Generator settings", e)); //$NON-NLS-1$ } return true; } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPropertyPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPropertyPage.java index f4c55ec52a8..9817495d591 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPropertyPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/compilationdatabase/JsonCdbGeneratorPropertyPage.java @@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Preferences; +import org.eclipse.core.runtime.Status; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -54,7 +55,7 @@ public boolean performOk() { try { optionPage.performApply(new NullProgressMonitor()); } catch (CoreException e) { - ManagedBuilderUIPlugin.log(e); + ManagedBuilderUIPlugin.log(Status.error("Failed to save JSON Compilation Database Generator settings", e)); //$NON-NLS-1$ } return true; }