Compare commits

...

3 Commits

@ -108,7 +108,11 @@
<version>2.6.10</version>
</dependency>
<dependency>
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
<version>7.5.4</version>
</dependency>
</dependencies>
<build>

@ -192,7 +192,8 @@ public class SonarService {
"-Dsonar.java.binaries=./ " +
"-Dsonar.projectBaseDir=" + projectPath;
log.info("projectPath:{},key:{}, command: {}", projectPath, key, command);
SystemUtil.executeAndGetExitStatus(command);
SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command);
log.info("projectPath:{},key:{}, result: {}", projectPath, key, executeResp.getStatus() != 0 ? executeResp.getOutput() : "success");
}
/**
@ -257,7 +258,7 @@ public class SonarService {
*/
public void scanExcel(String excelPath) {
int homeworkId = 20210101;
int homeworkId = 20230402;
try {
List<Person> personList = ExcelUtil.readExcel(excelPath);

@ -1,17 +1,23 @@
package net.educoder.ecsonar.task;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import com.github.junrar.Junrar;
import net.educoder.ecsonar.model.api.Person;
import net.educoder.ecsonar.model.api.SonarRequest;
import net.educoder.ecsonar.services.SonarService;
import net.educoder.ecsonar.utils.RarUtil;
import net.educoder.ecsonar.utils.UrlUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* @Author: youys
@ -39,7 +45,7 @@ public class ReadExcelRunnable implements Runnable{
String path = String.format("/tmp/%d/%s/", homeworkId, uid);
File file = new File(path);
if(!file.exists()){
file.mkdir();
file.mkdirs();
}
// for (Person person : sonarRequest.getPersonList()) {
// String[] split = StringUtils.split(person.getDownloadUrl(), "/");
@ -51,6 +57,10 @@ public class ReadExcelRunnable implements Runnable{
// }
// }
String key = String.format("%d-%s", homeworkId, uid);
// if(new File(path + "/.scannerwork/").exists()){
// System.out.println(path+ "----exist");
// return;
// }
log.info("开始调用sonar:{}",key);
sonarService.sonar(path,key);
}
@ -83,4 +93,6 @@ public class ReadExcelRunnable implements Runnable{
}
}
}

@ -397,7 +397,15 @@ public class ExcelUtil {
Row row = sheet.getRow(i);
String name = row.getCell(0).getStringCellValue();
// String uid;
// try {
// uid = String.valueOf(row.getCell(1).getNumericCellValue());
// }catch (Exception e){
// uid = row.getCell(1).getStringCellValue();
// }
String uid = row.getCell(1).getStringCellValue();
String downloadUrl = row.getCell(2).getStringCellValue();
Person person = new Person();

@ -0,0 +1,163 @@
package net.educoder.ecsonar.utils;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.core.util.ZipUtil;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
/**
* @Author: youys
* @Date: 2023/5/19
* @Description:
*/
public class RarUtil {
public static void unrar(String sourceFilePath, String outputDirectory) {
String s = RuntimeUtil.execForStr("unar", sourceFilePath,"-o", outputDirectory);
System.out.println("result====" + s);
}
public static void un7Z(String sourceFilePath, String outputDirectory) {
String s = RuntimeUtil.execForStr("unar", sourceFilePath,"-o", outputDirectory);
System.out.println("result====" + s);
}
public static void main(String[] args) {
// unrar("/tmp/20230301/201905962222/20230519153409_wuiol3vn.rar", "/Users/youyongsheng/Desktop/aa");
// un7Z("/tmp/20230301/201905962241/20230519153506_i39sv5p2.7z", "/Users/youyongsheng/Desktop/aa");
// unzip();
valid("/tmp/20230402");
// removeFullCode("/tmp/20230302");
}
public static void unzip(){
String sourceDir = "/tmp/20230401";
String targetDir = "/tmp/20230402";
File directory = new File(sourceDir);
File[] studentDirs = directory.listFiles();
if (studentDirs == null) {
System.out.println("No student directories found.");
return;
}
int i=0;
for (File studentDir : studentDirs) {
if (!studentDir.isDirectory()) {
System.out.println("111--------------------------------");
continue;
}
String studentId = studentDir.getName();
String studentTargetDir = targetDir + "/" + studentId;
File[] zipFiles = studentDir.listFiles();
// File[] zipFiles = studentDir.listFiles((dir, name) -> name.endsWith(".zip"));
// if (zipFiles == null) {
// System.out.println("No zip files found for student: " + studentId);
// continue;
// }
for (File zipFile : zipFiles) {
try {
if(zipFile.getName().endsWith(".zip")){
unzip(zipFile.getAbsolutePath(), studentTargetDir);
}else if(zipFile.getName().endsWith(".rar")){
unRar(zipFile.getAbsolutePath(), studentTargetDir);
}else{
RarUtil.un7Z(zipFile.getAbsolutePath(), studentTargetDir);
}
} catch (Exception e) {
System.out.println("Error occurred while unzipping file: " + zipFile.getName());
}
}
System.out.println("--------------------------------");
}
}
private static void unzip(String zipFilePath, String targetDir) throws IOException {
System.out.println(zipFilePath + " to " + targetDir);
ZipUtil.unzip(zipFilePath,targetDir, Charset.forName("GBK"));
}
private static void unRar(String zipFilePath, String targetDir) throws Exception {
System.out.println(zipFilePath + " to " + targetDir);
RarUtil.unrar(zipFilePath,targetDir);
}
public static void valid(String path){
File directory = new File(path);
File[] studentDirs = directory.listFiles();
if (studentDirs == null) {
System.out.println("No student directories found.");
return;
}
for (File studentDir : studentDirs) {
if (studentDir.isDirectory()) {
File[] files = studentDir.listFiles();
if(files == null || files.length == 0){
System.out.println(studentDir.getName()+" -> null");
}
for (File file : files) {
System.out.println(studentDir.getName()+" ->" + file.getName());
}
System.out.println("--------------------------------");
}
}
}
public static void removeFullCode(String path){
// 删除完整代码
File directory = new File(path);
File[] studentDirs = directory.listFiles();
if (studentDirs == null) {
System.out.println("No student directories found.");
return;
}
for (File studentDir : studentDirs) {
if (studentDir.isDirectory()) {
String stuNo = studentDir.getName();
File[] files = studentDir.listFiles();
if(files.length == 2){
for (File file : files) {
if (file.getName().contains("完整")) {
System.out.println(stuNo + "==11===" + file.getAbsolutePath());
cn.hutool.core.io.FileUtil.del(file.getAbsolutePath());
}
}
}else if(files.length == 1){
File file = files[0];
File[] files1 = file.listFiles();
if(files1 != null && files1.length == 2){
for (File f : files1) {
if (f.getName().contains("完整")) {
System.out.println(stuNo + "==22===" + f.getAbsolutePath());
FileUtil.del(f.getAbsolutePath());
}
}
}
}
}
}
}
}

@ -5,10 +5,10 @@
#spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.initSize=20
spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
#spring.datasource.url=jdbc:postgresql://117.50.14.123:5432/sonar
spring.datasource.master.username=root
spring.datasource.master.password=root
#spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
spring.datasource.master.url=jdbc:postgresql://117.50.14.123:5432/sonar
spring.datasource.master.username=sonar
spring.datasource.master.password=sonar
spring.datasource.master.driverClassName=org.postgresql.Driver
@ -43,8 +43,8 @@ zip.save.path=/tmp/
#excel.template.path=/Users/guange/work/java/ecsonar/src/main/resources/template.xlsx
excel.template.path=template.xlsx
sonar.url=http://127.0.0.1:9000
#sonar.url=http://117.50.14.123:9000
#sonar.url=http://127.0.0.1:9000
sonar.url=http://117.50.14.123:9000
# token令牌
sonar.token=0253a518e824a976ea2f11aec17938cb0f8c0495

Binary file not shown.

@ -67,8 +67,8 @@ public class EcsonarApplicationTests {
public void scanExcel(){
CountDownLatch countDownLatch = new CountDownLatch(1);
String excelPath = "/Users/youyongsheng/Desktop/res.xls";
// String excelPath = "/Users/youyongsheng/Desktop/res-test.xlsx";
// String excelPath = "/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/data.xlsx";
String excelPath = "/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-24/湖南工业大学-2023届软件工程-原始数据.xlsx";
sonarService.scanExcel(excelPath);
try {
@ -81,13 +81,13 @@ public class EcsonarApplicationTests {
@Test
public void writeExcel() throws Exception {
int homeworkId = 20210101;
String directory = "/tmp/20210101/";
int homeworkId = 20230402;
String directory = "/tmp/20230402/";
File file = new File(directory);
File[] files = file.listFiles();
System.out.println("学生数:" + files.length);
List<Person> personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/res.xls");
List<Person> personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-24/湖南工业大学-2023届软件工程-原始数据.xlsx");
Map<String, List<Person>> collect = personList.stream().collect(Collectors.groupingBy(Person::getUid));
@ -100,7 +100,7 @@ public class EcsonarApplicationTests {
Metrics metrics = reportService.getMetrics(projectName);
String templatePath = this.getClass().getClassLoader().getResource("template1.xlsx").getPath();
String outPath = "/Users/youyongsheng/Desktop/202100000004.xlsx";
String outPath = "/Users/youyongsheng/Desktop/ddddd.xlsx";
System.out.println("第"+(i++)+"个学生," + uid);
if (CollectionUtils.isEmpty(collect.get(uid))) {
@ -122,4 +122,7 @@ public class EcsonarApplicationTests {
System.out.println("---------end------------");
}
}

Loading…
Cancel
Save