-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced IBuildSupport usage to support other build tools such as baz…
…el (#1694) Based on #1674 * Refactored ExtensionsExtractor * Use the ProjectUtils static methods in cases where we know exactly which build support we want to check against the project. Signed-off-by: Siarhei Leanavets <siarhei_leanavets1@epam.com>
- Loading branch information
1 parent
9130c92
commit d7a0f3c
Showing
17 changed files
with
364 additions
and
126 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/ExtensionsExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Red Hat Inc. and others. | ||
* All rights reserved. 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 | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.ls.core.internal; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.core.runtime.IConfigurationElement; | ||
import org.eclipse.core.runtime.Platform; | ||
|
||
/** | ||
* The class simplifies extracting extensions from the extension points. | ||
* | ||
* @author D.Bushenko | ||
* | ||
*/ | ||
public class ExtensionsExtractor { | ||
public static <T> List<T> extractOrderedExtensions(final String namespace, final String extensionPointName) { | ||
|
||
final var extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(namespace, extensionPointName); | ||
final var configs = extensionPoint.getConfigurationElements(); | ||
|
||
Map<Integer, T> extensionMap = new TreeMap<>(); | ||
|
||
for (int i = 0; i < configs.length; i++) { | ||
Integer order = Integer.valueOf(configs[i].getAttribute("order")); | ||
extensionMap.put(order, makeExtension(configs[i])); | ||
} | ||
return extensionMap.values().stream().collect(Collectors.toUnmodifiableList()); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static <T> T makeExtension(IConfigurationElement config) { | ||
try { | ||
return (T) config.createExecutableExtension("class"); | ||
|
||
} catch (Exception ex) { | ||
throw new IllegalArgumentException("Could not create the extension", ex); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...clipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/BuildSupportManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 Red Hat Inc. and others. | ||
* All rights reserved. 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 | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.ls.core.internal.managers; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
|
||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.jdt.ls.core.internal.ExtensionsExtractor; | ||
import org.eclipse.jdt.ls.core.internal.IConstants; | ||
|
||
/** | ||
* This is an orchestrator who is responsible for fetching and searching | ||
* IBuildSupport objects. | ||
* | ||
* @author D.Bushenko | ||
* | ||
*/ | ||
public class BuildSupportManager { | ||
private static final BuildSupportManager instance = new BuildSupportManager(); | ||
private List<IBuildSupport> lazyLoadedBuildSupportList; | ||
|
||
private BuildSupportManager() {} | ||
|
||
public static List<IBuildSupport> obtainBuildSupports() { | ||
if (instance.lazyLoadedBuildSupportList == null) { | ||
instance.lazyLoadedBuildSupportList = ExtensionsExtractor.extractOrderedExtensions(IConstants.PLUGIN_ID, "buildSupport"); | ||
} | ||
|
||
return instance.lazyLoadedBuildSupportList; | ||
} | ||
|
||
public static Optional<IBuildSupport> find(IProject project) { | ||
return instance.find(bs -> bs.applies(project)); | ||
} | ||
|
||
public static Optional<IBuildSupport> find(String buildToolName) { | ||
return instance.find(bs -> bs.buildToolName().equalsIgnoreCase(buildToolName)); | ||
} | ||
|
||
private Optional<IBuildSupport> find(Predicate<? super IBuildSupport> predicate) { | ||
return obtainBuildSupports().stream().filter(predicate).findFirst(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.