
de.pfabulist.loracle.spi.CustomService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of loracle-maven-plugin Show documentation
Show all versions of loracle-maven-plugin Show documentation
maven plugin to check the licenses of all dependencies and possible incompatibilities
package de.pfabulist.loracle.spi;
import com.esotericsoftware.minlog.Log;
import de.pfabulist.loracle.custom.LoracleCustom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import static de.pfabulist.roast.NonnullCheck._nn;
/**
* Copyright (c) 2006 - 2016, Stephan Pfab
* SPDX-License-Identifier: BSD-2-Clause
*/
public class CustomService {
private static Optional service = Optional.empty();
private final ServiceLoader loader;
private Optional> all = Optional.empty();
private CustomService() {
loader = ServiceLoader.load( LoracleCustom.class );
}
public static synchronized CustomService getInstance() {
if( !service.isPresent() ) {
service = Optional.of( new CustomService() );
}
//noinspection ConstantConditions
return service.get();
}
public synchronized List getAll() {
if ( !all.isPresent()) {
List list = new ArrayList<>();
try {
Iterator providers = loader.iterator();
while( providers.hasNext() ) {
list.add( _nn( providers.next()));
}
} catch( ServiceConfigurationError serviceError ) {
Log.warn( serviceError.getMessage() );
return Collections.emptyList();
}
all = Optional.of( list );
}
return _nn(all.get());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy