Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (2)
...@@ -92,6 +92,7 @@ public class FixDirStructure { ...@@ -92,6 +92,7 @@ public class FixDirStructure {
log.info(""); log.info("");
return; return;
} }
removeOneDirPath(dir);
List<File> files = getFileListInProjectRoot(dir); List<File> files = getFileListInProjectRoot(dir);
boolean pomExist = files.stream().anyMatch(f -> f.getName().equals("pom.xml")); boolean pomExist = files.stream().anyMatch(f -> f.getName().equals("pom.xml"));
long multiPomCount = findFiles(dir, "pom.xml").size(); long multiPomCount = findFiles(dir, "pom.xml").size();
...@@ -99,7 +100,6 @@ public class FixDirStructure { ...@@ -99,7 +100,6 @@ public class FixDirStructure {
.filter(f -> !f.isDirectory() && f.getName().matches("pom(\\s*\\((.*)\\))?\\.xml")).count(); .filter(f -> !f.isDirectory() && f.getName().matches("pom(\\s*\\((.*)\\))?\\.xml")).count();
boolean onlyJava = files.stream().filter(f -> !f.getName().equals("pom.xml")) boolean onlyJava = files.stream().filter(f -> !f.getName().equals("pom.xml"))
.allMatch(f -> f.getName().endsWith(".java")); .allMatch(f -> f.getName().endsWith(".java"));
boolean onlyOneDir = files.stream().allMatch(File::isDirectory) && files.size() == 1;
boolean pomAndSrcZip = pomExist && files.size() == 2 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")).allMatch(f -> !f.isDirectory())
&& files.stream().filter(f -> !f.getName().equals("pom.xml")) && files.stream().filter(f -> !f.getName().equals("pom.xml"))
...@@ -109,7 +109,6 @@ public class FixDirStructure { ...@@ -109,7 +109,6 @@ public class FixDirStructure {
log.info(() -> "multi Pom Count in root :" + multiPomCountInRootDir); log.info(() -> "multi Pom Count in root :" + multiPomCountInRootDir);
log.info(() -> "pom Exist : " + pomExist); log.info(() -> "pom Exist : " + pomExist);
log.info(() -> "only Java : " + onlyJava); log.info(() -> "only Java : " + onlyJava);
log.info(() -> "only One Dir : " + onlyOneDir);
log.info(() -> "pom And Src Zip: " + pomAndSrcZip); log.info(() -> "pom And Src Zip: " + pomAndSrcZip);
log.info(() -> "only Tar Gz : " + onlyTarGz); log.info(() -> "only Tar Gz : " + onlyTarGz);
log.info(""); log.info("");
...@@ -123,8 +122,6 @@ public class FixDirStructure { ...@@ -123,8 +122,6 @@ public class FixDirStructure {
downloadAndExpandMultiprojedctEvaluator(dir); downloadAndExpandMultiprojedctEvaluator(dir);
} else if (pomExist && onlyJava) { } else if (pomExist && onlyJava) {
makeMavenProjectStructure(dir); makeMavenProjectStructure(dir);
} else if (onlyOneDir) {
removeOneDirPapth(dir);
} else if (pomAndSrcZip) { } else if (pomAndSrcZip) {
expandSrcZip(dir); expandSrcZip(dir);
} }
...@@ -132,6 +129,11 @@ public class FixDirStructure { ...@@ -132,6 +129,11 @@ public class FixDirStructure {
findMain(dir); 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) { private static List<File> getFileListInProjectRoot(Path dir) {
return Arrays.asList(dir.toFile().listFiles()).stream().filter(f -> !skipNames.contains(f.getName())).toList(); return Arrays.asList(dir.toFile().listFiles()).stream().filter(f -> !skipNames.contains(f.getName())).toList();
} }
...@@ -174,7 +176,7 @@ public class FixDirStructure { ...@@ -174,7 +176,7 @@ public class FixDirStructure {
private static void downloadAndExpandMultiprojedctEvaluator(Path path) { private static void downloadAndExpandMultiprojedctEvaluator(Path path) {
try (InputStream inputStream = new URI( 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()) { .openStream()) {
extractZipStream(inputStream, path, 1); extractZipStream(inputStream, path, 1);
} catch (URISyntaxException ex) { } catch (URISyntaxException ex) {
...@@ -205,32 +207,34 @@ public class FixDirStructure { ...@@ -205,32 +207,34 @@ public class FixDirStructure {
} }
} }
private static void removeOneDirPapth(Path dir) { private static void removeOneDirPath(Path dir) {
List<File> files = getFileListInProjectRoot(dir); while (isOneDir(dir)) {
log.info(() -> "item in dirs count: " + files.size()); List<File> files = Arrays.asList(dir.toFile().listFiles()).stream().toList();
log.info(() -> files.stream().map(File::toString).collect(Collectors.joining(", "))); log.info(() -> "item in dirs count: " + files.size());
Path insideProject = files.stream().filter(File::isDirectory).map(File::toPath).findFirst().orElse(null); log.info(() -> files.stream().map(File::toString).collect(Collectors.joining(", ")));
if (insideProject == null) { Path insideProject = files.stream().filter(File::isDirectory).map(File::toPath).findFirst().orElse(null);
log.info("No singel dir found!!!"); if (insideProject == null) {
return; log.info("No singel dir found!!!");
} return;
for (File file : insideProject.toFile().listFiles()) { }
if (skipNames.contains(file.getName())) { log.info("Only one dir for: " + insideProject);
continue; 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 { try {
Files.move(file.toPath(), file.toPath().getParent().getParent().resolve(file.getName())); Files.delete(insideProject);
} catch (IOException e) { } catch (IOException e) {
System.out.printf("Cannot move %s to %s%n", file.toPath(), file.toPath().getParent().getParent());
e.printStackTrace(); e.printStackTrace();
} }
} }
try {
Files.delete(insideProject);
} catch (IOException e) {
e.printStackTrace();
}
} }
private static void makeMavenProjectStructure(Path dir) { private static void makeMavenProjectStructure(Path dir) {
...@@ -466,6 +470,9 @@ public class FixDirStructure { ...@@ -466,6 +470,9 @@ public class FixDirStructure {
@Override @Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
if(skipNames.contains(dir.getFileName().toString())) {
return FileVisitResult.SKIP_SUBTREE;
}
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
......