All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.actuate.jar.maven.MavenJarDepsEndpoint Maven / Gradle / Ivy

The newest version!
package org.zodiac.actuate.jar.maven;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
import org.springframework.web.bind.annotation.GetMapping;
import org.zodiac.commons.jar.maven.DependencyAnalyzer;

import java.util.concurrent.CompletableFuture;

@RestControllerEndpoint(id = MavenJarDepsEndpoint.ENDPOINT_NAME)
public class MavenJarDepsEndpoint implements InitializingBean {

    //public static final String ENDPOINT_NAME = "maven-jardeps";
    public static final String ENDPOINT_NAME = "jardeps";

    private Logger log = LoggerFactory.getLogger(getClass());

    private Object lock = new Object();

    private volatile Object cachedJarDependencies;

    public MavenJarDepsEndpoint() {
    }

    @GetMapping
    public Object invoke() {
        try {
            if (cachedJarDependencies == null) {
                synchronized (lock) {
                    if (cachedJarDependencies == null) {
                        cachedJarDependencies = DependencyAnalyzer.getAllPomInfo();
                    }
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return cachedJarDependencies;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        init();
    }

    protected void init() {
        CompletableFuture.runAsync(() -> {
            try {
                cachedJarDependencies = DependencyAnalyzer.getAllPomInfo();
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        });
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy