Skip to content
Snippets Groups Projects
Commit 0b4ce1e8 authored by jez04's avatar jez04
Browse files

fix: deep one dir problem, url for multiproject evaluator

parent 1a436858
Branches
No related merge requests found
......@@ -92,6 +92,7 @@ public class FixDirStructure {
log.info("");
return;
}
removeOneDirPath(dir);
List<File> files = getFileListInProjectRoot(dir);
boolean pomExist = files.stream().anyMatch(f -> f.getName().equals("pom.xml"));
long multiPomCount = findFiles(dir, "pom.xml").size();
......@@ -99,7 +100,6 @@ public class FixDirStructure {
.filter(f -> !f.isDirectory() && f.getName().matches("pom(\\s*\\((.*)\\))?\\.xml")).count();
boolean onlyJava = files.stream().filter(f -> !f.getName().equals("pom.xml"))
.allMatch(f -> f.getName().endsWith(".java"));
boolean onlyOneDir = files.stream().allMatch(File::isDirectory) && files.size() == 1;
boolean pomAndSrcZip = pomExist && files.size() == 2
&& files.stream().filter(f -> !f.getName().equals("pom.xml")).allMatch(f -> !f.isDirectory())
&& files.stream().filter(f -> !f.getName().equals("pom.xml"))
......@@ -109,7 +109,6 @@ public class FixDirStructure {
log.info(() -> "multi Pom Count in root :" + multiPomCountInRootDir);
log.info(() -> "pom Exist : " + pomExist);
log.info(() -> "only Java : " + onlyJava);
log.info(() -> "only One Dir : " + onlyOneDir);
log.info(() -> "pom And Src Zip: " + pomAndSrcZip);
log.info(() -> "only Tar Gz : " + onlyTarGz);
log.info("");
......@@ -123,8 +122,6 @@ public class FixDirStructure {
downloadAndExpandMultiprojedctEvaluator(dir);
} else if (pomExist && onlyJava) {
makeMavenProjectStructure(dir);
} else if (onlyOneDir) {
removeOneDirPapth(dir);
} else if (pomAndSrcZip) {
expandSrcZip(dir);
}
......@@ -132,6 +129,11 @@ public class FixDirStructure {
findMain(dir);
}
private static boolean isOneDir(Path dir) {
List<File> files = getFileListInProjectRoot(dir);
return files.stream().allMatch(File::isDirectory) && files.size() == 1;
}
private static List<File> getFileListInProjectRoot(Path dir) {
return Arrays.asList(dir.toFile().listFiles()).stream().filter(f -> !skipNames.contains(f.getName())).toList();
}
......@@ -174,7 +176,7 @@ public class FixDirStructure {
private static void downloadAndExpandMultiprojedctEvaluator(Path path) {
try (InputStream inputStream = new URI(
"https://gitlab.vsb.cz/jez04-vyuka/eval-multiproject/-/archive/main/eval-multiproject-main.zip").toURL()
"https://gitlab.vsb.cz/jez04-vyuka/eval-multiproject/-/archive/release/eval-multiproject-main.zip").toURL()
.openStream()) {
extractZipStream(inputStream, path, 1);
} catch (URISyntaxException ex) {
......@@ -205,32 +207,34 @@ public class FixDirStructure {
}
}
private static void removeOneDirPapth(Path dir) {
List<File> files = getFileListInProjectRoot(dir);
log.info(() -> "item in dirs count: " + files.size());
log.info(() -> files.stream().map(File::toString).collect(Collectors.joining(", ")));
Path insideProject = files.stream().filter(File::isDirectory).map(File::toPath).findFirst().orElse(null);
if (insideProject == null) {
log.info("No singel dir found!!!");
return;
}
for (File file : insideProject.toFile().listFiles()) {
if (skipNames.contains(file.getName())) {
continue;
private static void removeOneDirPath(Path dir) {
while (isOneDir(dir)) {
List<File> files = Arrays.asList(dir.toFile().listFiles()).stream().toList();
log.info(() -> "item in dirs count: " + files.size());
log.info(() -> files.stream().map(File::toString).collect(Collectors.joining(", ")));
Path insideProject = files.stream().filter(File::isDirectory).map(File::toPath).findFirst().orElse(null);
if (insideProject == null) {
log.info("No singel dir found!!!");
return;
}
log.info("Only one dir for: " + insideProject);
for (File file : insideProject.toFile().listFiles()) {
// if (skipNames.contains(file.getName())) {
// continue;
// }
try {
Files.move(file.toPath(), file.toPath().getParent().getParent().resolve(file.getName()));
} catch (IOException e) {
System.out.printf("Cannot move %s to %s%n", file.toPath(), file.toPath().getParent().getParent());
e.printStackTrace();
}
}
try {
Files.move(file.toPath(), file.toPath().getParent().getParent().resolve(file.getName()));
Files.delete(insideProject);
} catch (IOException e) {
System.out.printf("Cannot move %s to %s%n", file.toPath(), file.toPath().getParent().getParent());
e.printStackTrace();
}
}
try {
Files.delete(insideProject);
} catch (IOException e) {
e.printStackTrace();
}
}
private static void makeMavenProjectStructure(Path dir) {
......@@ -466,6 +470,9 @@ public class FixDirStructure {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
if(skipNames.contains(dir.getFileName().toString())) {
return FileVisitResult.SKIP_SUBTREE;
}
return FileVisitResult.CONTINUE;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment