
dev.equo.ide.IdeHook Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2023 EquoTech, Inc. 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:
* EquoTech, Inc. - initial API and implementation
*******************************************************************************/
package dev.equo.ide;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* If you add a {@code Bundle-IdeHook} header to the manifest of a jar that points to the fully
* qualified name of a class that implements this interface, then that class will be instantiated
* and called at various points in the lifecycle of the IDE.
*/
public interface IdeHook extends Serializable {
@SuppressWarnings("serial")
class List extends ArrayList {
public List copy() {
List copy = new List();
copy.addAll(this);
return copy;
}
InstantiatedList instantiate() {
var list = new InstantiatedList();
for (int i = 0; i < size(); ++i) {
var hookGenerator = get(i);
try {
list.list.add(hookGenerator.instantiate());
} catch (Exception e) {
list.logError(hookGenerator, e);
}
}
return list;
}
}
class InstantiatedList {
interface ThrowingConsumer {
void accept(IdeHookInstantiated hook) throws Exception;
}
interface ThrowingBiConsumer {
void accept(IdeHookInstantiated hook, T arg) throws Exception;
}
private final ArrayList list = new ArrayList<>();
private final Logger logger = LoggerFactory.getLogger(IdeHook.class);
private @Nullable ArrayList> errorsToReport = new ArrayList<>();
private @Nullable BiConsumer
© 2015 - 2025 Weber Informatics LLC | Privacy Policy