Skip to content
Snippets Groups Projects
Commit 13ffa46c authored by jez04's avatar jez04
Browse files

Merge branch 'main' into release

parents 764540f2 1a436858
No related merge requests found
...@@ -3,5 +3,4 @@ ...@@ -3,5 +3,4 @@
.classpath .classpath
.project .project
*.class *.class
/examples/
.idea/ .idea/
...@@ -9,10 +9,6 @@ import java.io.InputStream; ...@@ -9,10 +9,6 @@ import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.Channel;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.file.FileVisitResult; import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor; import java.nio.file.FileVisitor;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -21,7 +17,6 @@ import java.nio.file.Paths; ...@@ -21,7 +17,6 @@ import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileAttribute;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
...@@ -33,9 +28,9 @@ import java.util.Map; ...@@ -33,9 +28,9 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
...@@ -57,6 +52,9 @@ import org.w3c.dom.Node; ...@@ -57,6 +52,9 @@ import org.w3c.dom.Node;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
public class FixDirStructure { public class FixDirStructure {
private static final String JUNIT_VERSION = "5.11.0";
private static final String ORG_JUNIT_JUPITER = "org.junit.jupiter";
static { static {
System.setProperty("java.util.logging.SimpleFormatter.format", "%1$tF %1$tT %4$s %2$s: %5$s%6$s%n"); System.setProperty("java.util.logging.SimpleFormatter.format", "%1$tF %1$tT %4$s %2$s: %5$s%6$s%n");
} }
...@@ -72,7 +70,7 @@ public class FixDirStructure { ...@@ -72,7 +70,7 @@ public class FixDirStructure {
log.info("java FixDirStructure <pathToDir>"); log.info("java FixDirStructure <pathToDir>");
} else { } else {
for (String arg : args) { for (String arg : args) {
log.info("Fixing dir maven project dir structure for: " + arg); log.info(() -> "Fixing dir maven project dir structure for: " + arg);
fix(arg); fix(arg);
} }
} }
...@@ -83,7 +81,7 @@ public class FixDirStructure { ...@@ -83,7 +81,7 @@ public class FixDirStructure {
public static void fix(String pathToDir) { public static void fix(String pathToDir) {
Path dir = Paths.get(pathToDir).toAbsolutePath(); Path dir = Paths.get(pathToDir).toAbsolutePath();
log.info("Absolute path: " + dir); log.info(() -> "Absolute path: " + dir);
if (!dir.toFile().exists()) { if (!dir.toFile().exists()) {
log.info("Path not exist!"); log.info("Path not exist!");
log.info(""); log.info("");
...@@ -107,8 +105,8 @@ public class FixDirStructure { ...@@ -107,8 +105,8 @@ public class FixDirStructure {
&& files.stream().filter(f -> !f.getName().equals("pom.xml")) && files.stream().filter(f -> !f.getName().equals("pom.xml"))
.allMatch(f -> f.getName().toLowerCase().matches("src|src.zip")); .allMatch(f -> f.getName().toLowerCase().matches("src|src.zip"));
boolean onlyTarGz = files.size() == 1 && files.stream().allMatch(f -> f.getName().matches(TAR_GZ_PATTERN)); boolean onlyTarGz = files.size() == 1 && files.stream().allMatch(f -> f.getName().matches(TAR_GZ_PATTERN));
log.info(()-> "multi Pom Count :" + multiPomCount); log.info(() -> "multi Pom Count :" + multiPomCount);
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(() -> "only One Dir : " + onlyOneDir);
...@@ -135,15 +133,11 @@ public class FixDirStructure { ...@@ -135,15 +133,11 @@ public class FixDirStructure {
} }
private static List<File> getFileListInProjectRoot(Path dir) { private static List<File> getFileListInProjectRoot(Path dir) {
List<File> files = Arrays.asList(dir.toFile().listFiles()).stream() return Arrays.asList(dir.toFile().listFiles()).stream().filter(f -> !skipNames.contains(f.getName())).toList();
.filter(f -> !skipNames.contains(f.getName())).toList();
return files;
} }
private static void fixMultiplepPoms(Path dir) { private static void fixMultiplepPoms(Path dir) {
List<File> files = getFileListInProjectRoot(dir); List<File> files = getFileListInProjectRoot(dir);
long multiPomCount = files.stream()
.filter(f -> !f.isDirectory() && f.getName().matches("pom(\\s*\\((.*)\\))?\\.xml")).count();
List<File> poms = files.stream() List<File> poms = files.stream()
.filter(f -> !f.isDirectory() && f.getName().matches("pom(\\s*\\((.*)\\))?\\.xml")).toList(); .filter(f -> !f.isDirectory() && f.getName().matches("pom(\\s*\\((.*)\\))?\\.xml")).toList();
Pattern pomExp = Pattern.compile("pom(\\s*\\((.*)\\))?\\.xml"); Pattern pomExp = Pattern.compile("pom(\\s*\\((.*)\\))?\\.xml");
...@@ -163,7 +157,6 @@ public class FixDirStructure { ...@@ -163,7 +157,6 @@ public class FixDirStructure {
String index = matcher.group(1); String index = matcher.group(1);
projectMap.computeIfAbsent(index, key -> new ArrayList<>()).add(src); projectMap.computeIfAbsent(index, key -> new ArrayList<>()).add(src);
} }
List<Path> projects = new ArrayList<Path>();
int projectIndex = 1; int projectIndex = 1;
for (Entry<String, List<File>> entry : projectMap.entrySet()) { for (Entry<String, List<File>> entry : projectMap.entrySet()) {
Path projectPath = dir.resolve("project-" + projectIndex); Path projectPath = dir.resolve("project-" + projectIndex);
...@@ -195,9 +188,15 @@ public class FixDirStructure { ...@@ -195,9 +188,15 @@ public class FixDirStructure {
private static void expandSrcZip(Path dir) { private static void expandSrcZip(Path dir) {
File zip = Arrays.asList(dir.toFile().listFiles()).stream().filter(f -> !f.getName().equals("pom.xml")) File zip = Arrays.asList(dir.toFile().listFiles()).stream().filter(f -> !f.getName().equals("pom.xml"))
.findFirst().get(); .findFirst().orElse(null);
if (zip == null) {
log.warning("No ZIP file found.");
return;
}
File tempZip = zip.toPath().getParent().resolve("temp.zip").toFile(); File tempZip = zip.toPath().getParent().resolve("temp.zip").toFile();
zip.renameTo(tempZip); if (!zip.renameTo(tempZip)) {
log.warning(() -> "Cannot rename file: " + zip);
}
try { try {
unzip(tempZip, tempZip.toPath().getParent()); unzip(tempZip, tempZip.toPath().getParent());
} catch (IOException e) { } catch (IOException e) {
...@@ -207,11 +206,10 @@ public class FixDirStructure { ...@@ -207,11 +206,10 @@ public class FixDirStructure {
} }
private static void removeOneDirPapth(Path dir) { private static void removeOneDirPapth(Path dir) {
List<File> files = getFileListInProjectRoot(dir);
log.info("item in dirs count:" + dir.toFile().listFiles().length); log.info(() -> "item in dirs count: " + files.size());
log.info(Arrays.toString(dir.toFile().listFiles())); log.info(() -> files.stream().map(File::toString).collect(Collectors.joining(", ")));
Path insideProject = Arrays.stream(dir.toFile().listFiles()).filter(File::isDirectory).map(File::toPath) Path insideProject = files.stream().filter(File::isDirectory).map(File::toPath).findFirst().orElse(null);
.findFirst().orElse(null);
if (insideProject == null) { if (insideProject == null) {
log.info("No singel dir found!!!"); log.info("No singel dir found!!!");
return; return;
...@@ -257,6 +255,10 @@ public class FixDirStructure { ...@@ -257,6 +255,10 @@ public class FixDirStructure {
private static void expandTarGz(Path dir) { private static void expandTarGz(Path dir) {
Path tarGzFile = Arrays.stream(dir.toFile().listFiles()).filter(f -> f.getName().matches(TAR_GZ_PATTERN)) Path tarGzFile = Arrays.stream(dir.toFile().listFiles()).filter(f -> f.getName().matches(TAR_GZ_PATTERN))
.map(File::toPath).findFirst().orElse(null); .map(File::toPath).findFirst().orElse(null);
if (tarGzFile == null) {
log.warning("Cannot find tar.gz file.");
return;
}
try { try {
Files.move(tarGzFile, tarGzFile.getParent().resolve("to-expand.tar.gz"), StandardCopyOption.ATOMIC_MOVE); Files.move(tarGzFile, tarGzFile.getParent().resolve("to-expand.tar.gz"), StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) { } catch (IOException e) {
...@@ -339,9 +341,9 @@ public class FixDirStructure { ...@@ -339,9 +341,9 @@ public class FixDirStructure {
try { try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(pom.toFile()); Document doc = builder.parse(pom.toFile());
ifNotExistAddLib(doc, "junit-jupiter-api", "org.junit.jupiter", "5.11.0", "test", true); ifNotExistAddLib(doc, "junit-jupiter-api", ORG_JUNIT_JUPITER, JUNIT_VERSION, "test", true);
ifNotExistAddLib(doc, "junit-jupiter-engine", "org.junit.jupiter", "5.11.0", "test", true); ifNotExistAddLib(doc, "junit-jupiter-engine", ORG_JUNIT_JUPITER, JUNIT_VERSION, "test", true);
ifNotExistAddLib(doc, "junit-jupiter-params", "org.junit.jupiter", "5.11.0", "test", true); ifNotExistAddLib(doc, "junit-jupiter-params", ORG_JUNIT_JUPITER, JUNIT_VERSION, "test", true);
ifNotExistAddLib(doc, "kelvin-java-unittest-support", "cz.vsb.fei", "[0.0.2,)", "test", false); ifNotExistAddLib(doc, "kelvin-java-unittest-support", "cz.vsb.fei", "[0.0.2,)", "test", false);
ifNotExistAddRep(doc, "vsb-education-release", ifNotExistAddRep(doc, "vsb-education-release",
"https://artifactory.cs.vsb.cz/repository/education-releases/"); "https://artifactory.cs.vsb.cz/repository/education-releases/");
...@@ -420,8 +422,6 @@ public class FixDirStructure { ...@@ -420,8 +422,6 @@ public class FixDirStructure {
return result; return result;
} }
private static final List<String> IGNORE_DIR_NAMES = List.of("target", ".settings", "src", "eval-multiproject");
private static final List<String> IGNORE_FILE_NAMES = List.of("AppTest.java"); private static final List<String> IGNORE_FILE_NAMES = List.of("AppTest.java");
private static void findMain(Path rootDir) { private static void findMain(Path rootDir) {
...@@ -431,7 +431,7 @@ public class FixDirStructure { ...@@ -431,7 +431,7 @@ public class FixDirStructure {
List<Path> filesWithMain = new ArrayList<>(); List<Path> filesWithMain = new ArrayList<>();
List<Path> files = findFiles(rootDir, ".*\\.java").stream() List<Path> files = findFiles(rootDir, ".*\\.java").stream()
.filter(path -> !IGNORE_FILE_NAMES.contains(path.getFileName().toString())).toList(); .filter(path -> !IGNORE_FILE_NAMES.contains(path.getFileName().toString())).toList();
log.info(rootDir + ": " + files.size()); log.info(() -> rootDir + ": " + files.size());
for (Path javaFile : files) { for (Path javaFile : files) {
try { try {
if (mainPatter.matcher(Files.readString(javaFile)).find()) { if (mainPatter.matcher(Files.readString(javaFile)).find()) {
...@@ -442,17 +442,14 @@ public class FixDirStructure { ...@@ -442,17 +442,14 @@ public class FixDirStructure {
e.printStackTrace(); e.printStackTrace();
} }
} }
log.info(String.format("Found %d main functions.", filesWithMain.size())); log.info(() -> String.format("Found %d main functions.", filesWithMain.size()));
if (filesWithMain.size() > 1) { if (filesWithMain.size() > 1) {
filesWithMain.sort(Comparator.comparing(p -> p.toAbsolutePath().toString().length())); filesWithMain.sort(Comparator.comparing(p -> p.toAbsolutePath().toString().length()));
// filesWithMain.remove(0);
for (Path file : filesWithMain) { for (Path file : filesWithMain) {
// log.info("file:" + file.toString());
try { try {
String content = Files.readString(file); String content = Files.readString(file);
content = mainPatter.matcher(content).replaceAll("public static void main2(String[] args)"); content = mainPatter.matcher(content).replaceAll("public static void main2(String[] args)");
Files.writeString(file, content, StandardOpenOption.TRUNCATE_EXISTING); Files.writeString(file, content, StandardOpenOption.TRUNCATE_EXISTING);
// log.info(content);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
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