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

com.softicar.platform.common.io.classpath.PlainClasspathFileFetcher Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.io.classpath;

import com.softicar.platform.common.io.classpath.file.PlainClasspathFile;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Retrieves {@link PlainClasspathFile} instances that reference files from the
 * given class paths.
 *
 * @author Alexander Schmidt
 */
class PlainClasspathFileFetcher {

	/**
	 * @param classpaths
	 *            the {@link File} instances (either directories or .jar
	 *            archives) that represent the class paths to crawl
	 */
	public List getClasspathFiles(Collection classpaths) {

		Deque stack = new LinkedList<>(toClasspathFiles(classpaths));
		List result = new ArrayList<>();
		while (!stack.isEmpty()) {
			PlainClasspathFile current = stack.removeLast();
			if (current.getFile().isDirectory()) {
				stack.addAll(getFilesFromDirectory(current));
			} else {
				result.add(current);
			}
		}
		return result;
	}

	private List getFilesFromDirectory(PlainClasspathFile classpathFile) {

		return Arrays//
			.asList(classpathFile.getFile().listFiles())
			.stream()
			.map(file -> new PlainClasspathFile(classpathFile.getClasspath(), file))
			.collect(Collectors.toList());
	}

	private List toClasspathFiles(Collection classpaths) {

		return classpaths//
			.stream()
			.map(this::toClasspathFile)
			.collect(Collectors.toList());
	}

	private PlainClasspathFile toClasspathFile(File classpath) {

		return new PlainClasspathFile(classpath, classpath);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy