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

de.is24.deadcode4j.analyzer.SpringNamespaceHandlerAnalyzer Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package de.is24.deadcode4j.analyzer;

import de.is24.deadcode4j.AnalysisContext;
import org.apache.commons.io.IOUtils;

import javax.annotation.Nonnull;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import static com.google.common.collect.Iterables.filter;

/**
 * Analyzes 
 * spring.handlers property files and lists the defined namespace handlers as classes being
 * referenced.
 */
public class SpringNamespaceHandlerAnalyzer extends AnalyzerAdapter {

    @Override
    public void doAnalysis(@Nonnull AnalysisContext analysisContext, @Nonnull File file) {
        if (file.getAbsolutePath().endsWith("META-INF/spring.handlers")) {
            logger.debug("Analyzing property file [{}]...", file);
            registerSpringHandlersDefinedIn(analysisContext, file);
        }
    }

    private void registerSpringHandlersDefinedIn(AnalysisContext analysisContext, File file) {
        Properties springNamespaceHandlers = readPropertyFile(file);
        analysisContext.addDependencies("_Spring-NamespaceHandler_", filter(springNamespaceHandlers.values(), String.class));
    }

    private Properties readPropertyFile(File file) {
        Properties properties = new Properties();
        FileInputStream in = null;
        try {
            in = new FileInputStream(file);
            properties.load(in);
        } catch (IOException e) {
            throw new RuntimeException("Failed to read [" + file + "]!", e);
        } finally {
            IOUtils.closeQuietly(in);
        }
        return properties;
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy