Commit 8e1924f8 authored by 肖健鑫's avatar 肖健鑫
Browse files

更新src/Employee.java, src/EmployeeTest.java, src/TestArray.java,...

更新src/Employee.java, src/EmployeeTest.java, src/TestArray.java, src/Client.java, src/GregorianCalendarDemo.java, src/GreetingServer.java, src/GreetingClient.java, src/DateDemo.java, .gitlab-ci.yml, getCommittedMainFilesForCafehunterCli.sh
parents
default:
tags:
- test # runner 需配置相同tag
interruptible: true # 任务可被后来pipeline打断
stages:
- upload-mr-analysis
workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
variables:
HUB_LOGIN_NAME: "admin" # 登录名
HUB_PASSWORD: "1234qwer" # 密码
HUB_URL: "http://www.ustchcs.com/p3-v17/hub-backend-test/" # 平台URL
MERGE_REQUEST_PARAM: "{mergeRequestId:$CI_MERGE_REQUEST_IID,projectId:$CI_PROJECT_ID,jobId:$CI_JOB_ID}"
JAVA_MAIN_SOURCE: "src/main/java" # 检索差异文件脚本变量,表示只检查main文件,不检查test文件
CAFEHUNTER_CLI_SCRIPT: "/root/analysis-tool/bin/hcscli" # 套件命令执行文件
CAFEHUNTER_CLI_LICENSE_PATH: "/root/analysis-tool/Hub-ci.txt" # 授权文件
CAFEHUNTER_CLI_CONFIG_PATH: "/root/analysis-tool/config.yml" # 规则配置文件
# 根据项目进行配置
HUB_PROJECT_ID: "9" # 对应平台项目Id
REPOSITORY_FULL_PATH: "/builds/root/public-java-test" # 项目绝对路径,供套件分析
REPOSITORY_NAME: "public-java-test" # 项目名称
upload-job:
stage: upload-mr-analysis
# 包含分析工具运行所需环境
# 需要设置 runner config: pull_policy = "if-not-present"
# 使用本地镜像,本地需要有这个镜像
# 需要设置 runner config:mac_address(固定IP 工具授权需要)
image: docker.ustchcs.com/ubuntu-javacli-quality:v3.0
allow_failure: false
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
before_script:
# 授权
- locale-gen zh_CN
- export LANG=zh_CN.UTF-8
- export LC_ALL=zh_CN.UTF-8
- export LANGUAGE=zh_CN.UTF-8
- $CAFEHUNTER_CLI_SCRIPT version -i
- $CAFEHUNTER_CLI_SCRIPT -k $CAFEHUNTER_CLI_LICENSE_PATH
# 将游离分支转换为正常分支 以供套件分析
- cd $REPOSITORY_FULL_PATH
- git fetch
- git branch tmp-$CI_JOB_ID-$CI_JOB_NAME $CI_COMMIT_SHA
- git checkout -b $CI_COMMIT_REF_NAME
- git merge tmp-$CI_JOB_ID-$CI_JOB_NAME
# 获取分析文件
- chmod 777 $REPOSITORY_FULL_PATH/getCommittedMainFilesForCafehunterCli.sh
- export COMMITTED_FILES=$($REPOSITORY_FULL_PATH/getCommittedMainFilesForCafehunterCli.sh)
script:
# 分析
- echo "$CAFEHUNTER_CLI_SCRIPT analyze -c $CAFEHUNTER_CLI_CONFIG_PATH $COMMITTED_FILES -umr $REPOSITORY_NAME $HUB_LOGIN_NAME $HUB_PASSWORD $HUB_URL $HUB_PROJECT_ID $MERGE_REQUEST_PARAM"
- $CAFEHUNTER_CLI_SCRIPT analyze -c $CAFEHUNTER_CLI_CONFIG_PATH $COMMITTED_FILES -umr $REPOSITORY_NAME $HUB_LOGIN_NAME $HUB_PASSWORD $HUB_URL $HUB_PROJECT_ID $MERGE_REQUEST_PARAM
# 删除过程中用到的分支
- "git branch -d tmp-$CI_JOB_ID-$CI_JOB_NAME"
- "git checkout $CI_COMMIT_SHA"
- "git branch -D $CI_COMMIT_REF_NAME"
after_script:
- "git branch -d tmp-$CI_JOB_ID-$CI_JOB_NAME"
- "git checkout $CI_COMMIT_SHA"
- "git branch -D $CI_COMMIT_REF_NAME"
\ No newline at end of file
#!/bin/bash
function build() {
local -a COMMITTED_FILES
COMMITTED_FILES=$(git diff --name-only --diff-filter=DCM $CI_COMMIT_SHA origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME)
if [ -z "$COMMITTED_FILES" ]; then
return
fi
local -a check_files
for dir in $COMMITTED_FILES; do
if [[ $dir =~ ${JAVA_MAIN_SOURCE} ]]; then
#如果不是 则跳过剩下的步骤
check_files+=("$REPOSITORY_FULL_PATH/"${dir})
fi
done
if [ -z "$check_files" ]; then
return
fi
S=$(IFS=' '; echo "${check_files[*]}")
echo $S
}
build "$@"
import java.net.*;
import java.io.*;
public class Client {
public static void main(String[] args) throws IOException {
String host = "localhost";
int port = 12345;
Socket socket = new Socket(host, port);
System.out.println("Connected to server");
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("Echo: " + in.readLine());
}
out.close();
in.close();
stdIn.close();
socket.close();
}
}
import java.util.Date;
public class DateDemo {
public static void main(String[] args) {
// 初始化 Date 对象
Date date = new Date();
// 使用 toString() 函数显示日期时间
System.out.println(date.toString());
//c的使用
System.out.printf("全部日期和时间信息:%tc%n",date);
//f的使用
System.out.printf("年-月-日格式:%tF%n",date);
//d的使用
System.out.printf("月/日/年格式:%tD%n",date);
//r的使用
System.out.printf("HH:MM:SS PM格式(12时制):%tr%n",date);
//t的使用
System.out.printf("HH:MM:SS格式(24时制):%tT%n",date);
//R的使用
System.out.printf("HH:MM格式(24时制):%tR",date);
}
}
\ No newline at end of file
public class Employee {
String name;
int age;
String designation;
double salary;
public Employee(String name){
this.name = name;
}
public void empAge(int empAge){
age = empAge;
}
public void empDesignation(String empDesig){
designation = empDesig;
}
public void empSalary(double empSalary){
salary = empSalary;
}
public void printEmployee(){
System.out.println("名字:" + name);
System.out.println("年龄:" + age);
System.out.println("职位:" + designation);
System.out.println("薪水:" + salary);
}
}
public class EmployeeTest{
public static void main(String[] args){
/* 使用构造器创建两个对象 */
Employee empOne = new Employee("RUNOOB1");
Employee empTwo = new Employee("RUNOOB2");
// 调用这两个对象的成员方法
empOne.empAge(26);
empOne.empDesignation("高级程序员");
empOne.empSalary(1000);
empOne.printEmployee();
empTwo.empAge(21);
empTwo.empDesignation("菜鸟程序员");
empTwo.empSalary(500);
empTwo.printEmployee();
}
}
\ No newline at end of file
// 文件名 GreetingClient.java
import java.net.*;
import java.io.*;
public class GreetingClient
{
public static void main(String [] args)
{
String serverName = args[0];
int port = Integer.parseInt(args[1]);
try
{
System.out.println("连接到主机:" + serverName + " ,端口号:" + port);
Socket client = new Socket(serverName, port);
System.out.println("远程主机地址:" + client.getRemoteSocketAddress());
OutputStream outToServer = client.getOutputStream();
DataOutputStream out = new DataOutputStream(outToServer);
out.writeUTF("Hello from " + client.getLocalSocketAddress());
InputStream inFromServer = client.getInputStream();
DataInputStream in = new DataInputStream(inFromServer);
System.out.println("服务器响应: " + in.readUTF());
client.close();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
\ No newline at end of file
// 文件名 GreetingServer.java
import java.net.*;
import java.io.*;
public class GreetingServer extends Thread
{
private ServerSocket serverSocket;
public GreetingServer(int port) throws IOException
{
serverSocket = new ServerSocket(port);
serverSocket.setSoTimeout(10000);
}
public void run()
{
while(true)
{
try
{
System.out.println("等待远程连接,端口号为:" + serverSocket.getLocalPort() + "...");
Socket server = serverSocket.accept();
System.out.println("远程主机地址:" + server.getRemoteSocketAddress());
DataInputStream in = new DataInputStream(server.getInputStream());
System.out.println(in.readUTF());
DataOutputStream out = new DataOutputStream(server.getOutputStream());
out.writeUTF("谢谢连接我:" + server.getLocalSocketAddress() + "\nGoodbye!");
server.close();
}catch(SocketTimeoutException s)
{
System.out.println("Socket timed out!");
break;
}catch(IOException e)
{
e.printStackTrace();
break;
}
}
}
public static void main(String [] args)
{
int port = Integer.parseInt(args[0]);
try
{
Thread t = new GreetingServer(port);
t.run();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
\ No newline at end of file
import java.util.*;
public class GregorianCalendarDemo {
public static void main(String[] args) {
String months[] = {
"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"};
int year;
// 初始化 Gregorian 日历
// 使用当前时间和日期
// 默认为本地时间和时区
GregorianCalendar gcalendar = new GregorianCalendar();
// 显示当前时间和日期的信息
System.out.print("Date: ");
System.out.print(months[gcalendar.get(Calendar.MONTH)]);
System.out.print(" " + gcalendar.get(Calendar.DATE) + " ");
System.out.println(year = gcalendar.get(Calendar.YEAR));
System.out.print("Time: ");
System.out.print(gcalendar.get(Calendar.HOUR) + ":");
System.out.print(gcalendar.get(Calendar.MINUTE) + ":");
System.out.println(gcalendar.get(Calendar.SECOND));
// 测试当前年份是否为闰年
if(gcalendar.isLeapYear(year)) {
System.out.println("当前年份是闰年");
}
else {
System.out.println("当前年份不是闰年");
}
}
}
\ No newline at end of file
public class TestArray {
public static void main(String[] args){
int size = 10;
double[] myList = new double[size];
myList[0] = 5.6;
myList[1] = 4.5;
myList[2] = 3.3;
myList[3] = 13.2;
myList[4] = 4.0;
myList[5] = 34.33;
myList[6] = 34.0;
myList[7] = 45.45;
myList[8] = 99.993;
myList[9] = 11123;
double total = 0;
for(int i = 0; i < size; i++){
total += myList[i];
}
System.out.println("总和为:"+ total);
}
}
Markdown is supported
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