Bug 482711 - [launch] Creating the first launch config does not notify
ILaunchConfigurationListener.launchConfigurationAdded()

Change-Id: I1e0741a4c718b8ac2c9f51d90ef3681f6926ac95
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java
index 2051639..65e78f5 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -591,6 +591,9 @@
 	public synchronized ILaunchManager getLaunchManager() {
 		if (fLaunchManager == null) {
 			fLaunchManager = new LaunchManager();
+			fLaunchManager.getAllLaunchConfigurations();
+			// monitor launch configuration renames for launch groups
+			fLaunchManager.addLaunchConfigurationListener(new GroupMemberChangeListener());
 		}
 		return fLaunchManager;
 	}
@@ -726,9 +729,6 @@
 		manager.registerAdapters(actionFactory, ILaunch.class);
 		manager.registerAdapters(actionFactory, IProcess.class);
 		manager.registerAdapters(actionFactory, IDebugElement.class);
-
-		// monitor launch configuration renames for launch groups
-		getLaunchManager().addLaunchConfigurationListener(new GroupMemberChangeListener());
 	}
 
 	/**
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
index caf10c2..4caad68 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -1120,7 +1120,7 @@
 	 *
 	 * @return all launch configuration handles
 	 */
-	private synchronized List<ILaunchConfiguration> getAllLaunchConfigurations() {
+	public synchronized List<ILaunchConfiguration> getAllLaunchConfigurations() {
 		if (fLaunchConfigurationIndex == null) {
 			try {
 				fLaunchConfigurationIndex = new ArrayList<>(20);
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java
index 5447884..4c5b200 100644
--- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchConfigurationTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -1873,4 +1873,36 @@
 		assertTrue(t2.isPrototype());
 	}
 
+	@Test
+	public void testNewInstanceNotifiesListener() throws CoreException {
+		ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+		final ArrayList<String> added = new ArrayList<>();
+		ILaunchConfigurationListener listener = new ILaunchConfigurationListener() {
+
+			@Override
+			public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
+
+			}
+
+			@Override
+			public void launchConfigurationChanged(ILaunchConfiguration configuration) {
+
+			}
+
+			@Override
+			public void launchConfigurationAdded(ILaunchConfiguration configuration) {
+				added.add("Launch Configuration added");
+
+			}
+		};
+		launchManager.addLaunchConfigurationListener(listener);
+		String typeId = "org.eclipse.ui.externaltools.ProgramLaunchConfigurationType";
+
+		ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(typeId);
+		type.newInstance(null, "new-lc").doSave();
+		assertEquals(1, added.size());
+		assertEquals("Launch Configuration added", added.get(0));
+
+	}
+
 }