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

es.prodevelop.pui9.classpath.PuiClasspathFinderRegistry Maven / Gradle / Ivy

The newest version!
package es.prodevelop.pui9.classpath;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.reflections.Reflections;

/**
 * Class path registry used to retrieve the classpath of the application. You
 * can use this class when you want to obtain the list of classpath files
 * 
 * @author Marc Gil - [email protected]
 */
public class PuiClasspathFinderRegistry {

	private static PuiClasspathFinderRegistry instance;

	public static PuiClasspathFinderRegistry getInstance() {
		if (instance == null) {
			instance = new PuiClasspathFinderRegistry();
		}
		return instance;
	}

	private List classpathFinders;

	private PuiClasspathFinderRegistry() {
		classpathFinders = new ArrayList<>();
	}

	/**
	 * Retrieves the list of files that are used by the application classpath
	 * 
	 * @return The list of files that take part of the application classpath
	 */
	public List getClasspath() {
		if (classpathFinders.isEmpty()) {
			Set> set = new Reflections("es.prodevelop.pui9")
					.getSubTypesOf(IClasspathFinder.class);
			for (Class clazz : set) {
				try {
					IClasspathFinder cpf = clazz.newInstance();
					classpathFinders.add(cpf);
				} catch (InstantiationException | IllegalAccessException e) {
				}
			}
		}

		for (IClasspathFinder finder : classpathFinders) {
			List list = finder.getClasspath();
			if (list != null && !list.isEmpty()) {
				return list;
			}
		}

		return Collections.emptyList();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy