
io.guixer.logs.GuixerOutLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guixer-logs Show documentation
Show all versions of guixer-logs Show documentation
Log analysis utilities, for Guixer.
The newest version!
package io.guixer.logs;
import static com.google.common.base.Preconditions.checkNotNull;
import static net.avcompris.commons3.databeans.DataBeans.instantiate;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import io.guixer.logs.GuixerOut.Run;
import io.guixer.logs.GuixerOut.TestClass;
import io.guixer.logs.GuixerOut.TestMethod;
public class GuixerOutLoader {
private final GuixerOut guixerOut;
public GuixerOutLoader(
final File guixerOutDir
) throws IOException {
checkNotNull(guixerOutDir, "guixerOutDir");
if (!guixerOutDir.isDirectory()) {
throw new FileNotFoundException(
"guixerOutDir should be a directory, but was: " + guixerOutDir.getCanonicalPath());
}
final MutableGuixerOut guixerOut = instantiate(MutableGuixerOut.class) //
.setDir(guixerOutDir);
this.guixerOut = guixerOut;
final File[] testClassDirs = sortFiles(guixerOutDir.listFiles(file -> file.isDirectory()));
for (final File testClassDir : testClassDirs) {
final String testClassSimpleName = testClassDir.getName();
final MutableTestClass testClass = instantiate(MutableTestClass.class) //
.setSimpleName(testClassSimpleName);
guixerOut.addToTestClasses(testClass);
final File[] testMethodDirs = sortFiles(testClassDir.listFiles(file -> file.isDirectory()));
for (final File testMethodDir : testMethodDirs) {
final String testMethodName = testMethodDir.getName();
final MutableTestMethod testMethod = instantiate(MutableTestMethod.class) //
.setName(testMethodName);
testClass.addToTestMethods(testMethod);
final File[] runDirs = sortFiles(testMethodDir.listFiles(file -> file.isDirectory()));
for (final File runDir : runDirs) {
final File testLogFile = new File(runDir, "test.log");
if (!testLogFile.isFile()) {
throw new FileNotFoundException("Cannot find test.log: " + testLogFile.getCanonicalPath());
}
final String runDirName = runDir.getName();
final MutableRun run = instantiate(MutableRun.class) //
.setDirName(runDirName);
testMethod.addToRuns(run);
final long timeMillis;
try {
timeMillis = Long.parseLong(runDirName);
} catch (final NumberFormatException e) {
throw new RuntimeException("Unable to parse timeMillis: " + runDirName);
}
run.setTimeMillis(timeMillis);
run.setLog(new LogLoader(runDir).getLog());
}
}
}
}
public GuixerOut getGuixerOut() {
return guixerOut;
}
private interface MutableGuixerOut extends GuixerOut {
MutableGuixerOut setDir(
File guixerOutDir
);
MutableGuixerOut addToTestClasses(
TestClass testClass
);
}
private interface MutableTestClass extends TestClass {
MutableTestClass setSimpleName(
String testClassSimpleName
);
MutableTestClass addToTestMethods(
TestMethod testMethod
);
}
private interface MutableTestMethod extends TestMethod {
MutableTestMethod setName(
String testMethodName
);
MutableTestMethod addToRuns(
Run run
);
}
private interface MutableRun extends Run {
MutableRun setDirName(
String dirName
);
MutableRun setTimeMillis(
long timeMillis
);
MutableRun setLog(
Log log
);
}
private static File[] sortFiles(
final File[] files
) {
Arrays.sort(files, new Comparator() {
@Override
public int compare(
final File f1,
final File f2
) {
return f1.getName().compareTo(f2.getName());
}
});
return files;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy