KN321136 5 months ago
parent c39f35cbda
commit 933e961d6a

@ -0,0 +1,27 @@
# ---> Java
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
/target

@ -0,0 +1,118 @@
//Jenkins配置流水线时应该将默认Jenkinsfile改为Jenkinsfile127
//修改cstatm211601,可批量替换
pipeline {
agent any
options {
//跳过从源代码控制中检出代码使用阶段stage('拉取Gitea源码')
skipDefaultCheckout(true)
}
stages {
stage('拉取Gitea源码') {
steps {
cleanWs()//清除Jenkins的工作区WorkSpace
//gitea为Jenkins中的凭据:用访问gitea的账号、密码生成
//修改2018211601自己的学号
git credentialsId: 'gitea', url: 'http://localhost:3000/2018211601/cstatm211601.git'
}
}
stage('Maven Sonar 打包') {
steps {
//SonarQube为Jenkins系统中配置的服务器名称并设置SonarQube口令
withSonarQubeEnv('SonarQube'){
//Maven使用SonarQube进行源码扫描
//-D为SonarQube扫描属性
//127上的口令-Dsonar.token=SonarQube登录、账号、安全、通用口令生成复制
bat '''mvn clean package sonar:sonar -Dsonar.projectKey=cstatm211601
-Dsonar.projectName=cstatm211601 -Dsonar.java.binaries=. -Dsonar.skipPackageDesign=true
-Dsonar.token=squ_d7d970c7b6c36fe2b3b7bc3ccea60239f8028878'''
}
}
}
stage('QualityGate质量门禁') {
steps {
script{
sleep(30)//休眠30秒等待扫描结果返回质量门禁获取数据
//超时10分钟等待足够时间避免质量门禁失败
timeout(time: 10, unit: 'MINUTES'){
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "流水线由于门禁失败而退出: ${qg.status}"
}
}
}
}
}
//JDK的各个工具参数可查阅命令行如keytool /
stage('keytool生成密钥'){
steps{
// liudongliang 改为自己姓名拼音
//keytool很长但不能换行
bat '''
keytool -genkey -alias mykey -keystore mykeystore.store -storetype PKCS12 -keyalg RSA -storepass mystorepass -validity 365 -keysize 2048 -dname "CN=liudongliang, OU=chzu, L=xxxy, S=chuzhou, O=anhui, C=CH"
'''
}
}
stage('jarsigner数字签名') {
steps {
bat '''
MKDIR app
MOVE /Y "target\\cstatm211601-0.0.1-SNAPSHOT-jar-with-dependencies.jar" "app\\cstatm211601.jar"
jarsigner -keystore myKeystore.store app\\cstatm211601.jar mykey -storepass mystorepass
'''
}
}
stage('jpackage生成msi'){
steps{
//必须安装、配置WixTools
//修改主类名com.atm.view.gui.Gui
bat '''
jpackage -i ./app --type msi -n cstatm211601_msi --main-jar cstatm211601.jar --main-class com.atm.view.gui.Gui --vendor dll --verbose --win-console --win-dir-chooser --win-shortcut --win-menu
'''
}
post {
success {
//Jenkins制品
archiveArtifacts 'cstatm211601_msi-1.0.msi'
}
}
}
stage('jar打包War(jar&msi)') {
steps {
bat 'jar cfM cstatm211601.war index.html cstatm211601.jnlp ./app/cstatm211601.jar cstatm211601_msi-1.0.msi'
}
}
//部署tomcat9为部署的Web服务器选项最新tomcat9而实际服务器为tomcat10
//'tomcat'为Jenkins凭据id,访问tomcat,必须为管理员权限
stage('部署War至local127tomcat'){
steps{
deploy adapters: [tomcat9(credentialsId: 'tomcat', path: '', url: 'http://localhost:8080')], contextPath: '/cstatm211601', war: 'cstatm211601.war'
}
}
stage('local127访问cstatm211601'){
steps{
echo "explorer http://localhost:8080/cstatm211601/index.html"
}
}
//试看谁第一个发邮件给我?
stage("通知邮件") {
steps{
script {
mail to: '602924803@qq.com',
subject: "软件流水线: ${currentBuild.fullDisplayName}",
body: " ${env.JOB_NAME}-构建#${env.BUILD_ID}-状态#${currentBuild.currentResult}\n 控制台 ${BUILD_URL} 查看结果。"
}
}
}
}
post {
always {
//清理工作区函数
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true,
patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
[pattern: '.propsfile', type: 'EXCLUDE']])
}
}
}

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- 修改cstatm206004,可批量替换 -->
<jnlp codebase="http://116.204.84.48:8080/cstatm206004/" href="cstatm206004.jnlp">
<information>
<title>JWS to Run cstatm</title>
<vendor>czldl</vendor>
<description>ATM EAGitOps</description>
<homepage href="http://116.204.84.48:8080/cstatm206004/index.html"/>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<update check="always" policy="always"/>
<resources>
<j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+" />
<jar href="app/cstatm206004.jar" main="true"/>
</resources>
<!-- 修改主类com.atm.view.gui.Gui -->
<application-desc name="ATM EAGitOps" main-class="org.atm.view.gui.Gui"/>
</jnlp>

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<!-- 修改cstatm206004,可批量替换 -->
<head>
<meta charset="UTF-8">
<title>计科231《软件工程基础》期中考试</title>
</head>
<body>
学号_____姓名______
<hr />
<h4>本地localhost:8080</h4>
<a href="http://localhost:8080/cstatm206004/app/cstatm206004.jar">(127Tomcat)下载 cstatm206004.jar,java -jar cstatm206004.jar 执行</a>
<hr/>
<a href="http://localhost:8080/cstatm206004/cstatm206004_msi-1.0.msi">(127Tomcat)下载 cstatm206004-1.0.msi ,安装、执行</a>
</body>
</html>

@ -0,0 +1,117 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 修改cstatm206004,可批量替换 -->
<!-- 1修改groupId:org.atm -->
<groupId>org.atm</groupId>
<!-- 修改cstatm206004 -->
<artifactId>cstatm206004</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- 修改cstatm206004 -->
<name>cstatm206004</name>
<description>期中考试 cstatm206004</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.report.outputEncoding>UTF-8</project.report.outputEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.10.0.2594</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<!-- 2修改主类com.atm.view.gui.Gui -->
<mainClass>
org.atm.view.gui.Gui
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<skipTests>false</skipTests>
<argLine>${argLine} -Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<configuration>
<skip>false</skip>
<destFile>target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,15 @@
package org.atm.ctrl;
public class Validate {
private static final int len = 7;
public static boolean is7RandNumeric(String str) {
boolean flag = str != null && str.matches("\\d{" + len + "}");
if (!flag) {
System.out.println(str + " must is " + len + " Numeric!");
return false;
} else
return true;
}
}// end Validate

@ -0,0 +1,80 @@
package org.atm.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DbUtil {
protected static PreparedStatement ps = null;
protected static ResultSet rs = null;
protected static Connection conn = null;
public static synchronized Connection getConn() {
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/cstatm-mte", "postgres", "gitops123");
} catch (Exception e) {
System.err.println("Load org.postgresql.Driver FailedCheck pgJDBC jar is not Exist!");
return null;
}
return conn;
}
public static void close() {
try {
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
System.err.println("Close DB link Failed!");
return;
}
}
public static PreparedStatement executePreparedStatement(String sql) {
try {
ps = getConn().prepareStatement(sql);
} catch (Exception e) {
System.err.println("Create PreparedStatement Failed!");
return null;
}
return ps;
}
public static ResultSet executeQuery(String sql) {
try {
ps = executePreparedStatement(sql);
rs = ps.executeQuery();
} catch (SQLException e) {
System.err.println("Execute Query Failed!");
return null;
}
return rs;
}
public static void executeUpdate(String sql) {
try {
ps = executePreparedStatement(sql);
ps.executeUpdate();
} catch (SQLException e) {
System.err.println("Execute Update Failed!");
} finally {
try {
if (ps != null)
ps.close();
} catch (SQLException e) {
System.err.println("Close Resources Failed!");
return;
}
}
}
}// end DbUtil

@ -0,0 +1,34 @@
package org.atm.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.atm.model.Customer;
public class Login {
/**
*
* @param c
*/
public Customer login(Customer c) {
Customer returnCustomer = null;
try {
ResultSet rs = DbUtil.executeQuery(
"select * from customer where cid='" + c.getCid() + "' and cpin='" + c.getCpin() + "'");
if (rs!=null && rs.next()) {
returnCustomer = new Customer();
returnCustomer.setCid(rs.getString("cid"));
returnCustomer.setCpin(rs.getString("cpin"));
returnCustomer.setCname(rs.getString("cname"));
System.out.println("welcome," + rs.getString("cname"));
return returnCustomer;
}
} catch (SQLException e) {
System.err.println("Fetch ResultSet Failed!");
return returnCustomer;
}
System.out.println("No Customer!");
return returnCustomer;
}
}// end Login

@ -0,0 +1,77 @@
package org.atm.model;
public class Customer {
private String cid;
private String cname;
private String cpin;
public Customer() {
}
/**
*
* @param cid
* @param cpin
*/
public Customer(String cid, String cpin) {
this.cid = cid;
this.cpin = cpin;
this.cname = "";
}
/**
*
* @param cid
* @param cpin
* @param cname
*/
public Customer(String cid, String cpin, String cname) {
this.cid = cid;
this.cpin = cpin;
this.cname = cname;
}
/**
* @return String return the cid
*/
public String getCid() {
return cid;
}
/**
* @param cid the cid to set
*/
public void setCid(String cid) {
this.cid = cid;
}
/**
* @return String return the cname
*/
public String getCname() {
return cname;
}
/**
* @param cname the cname to set
*/
public void setCname(String cname) {
this.cname = cname;
}
/**
* @return String return the cpin
*/
public String getCpin() {
return cpin;
}
/**
* @param cpin the cpin to set
*/
public void setCpin(String cpin) {
this.cpin = cpin;
}
}

@ -0,0 +1,93 @@
package org.atm.view.gui;
import org.atm.model.Customer;
import org.atm.ctrl.Validate;
import org.atm.dao.Login;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Gui extends JFrame {
private JButton jButtonLogin;
private JLabel jLabelCid;
private JLabel jLabelCpin;
private JPanel jPanel;
private JPanel jPanelBtn;
private JPanel jPanelCid;
private JPanel jPanelCpin;
private JTextField jTextFieldCid;
private JPasswordField jTextFieldCpin;
public Gui() {
this.setTitle("GUI ATM MTE From EA For CS231");
this.setSize(300, 200);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
jPanel = new JPanel(new GridLayout(3, 1));
jPanelCid = new JPanel();
jLabelCid = new JLabel("CID");
jLabelCid.setForeground(Color.RED);
jLabelCid.setFont(new Font("", Font.BOLD, 15));
jTextFieldCid = new JTextField(15);
jPanelCid.add(jLabelCid);
jPanelCid.add(jTextFieldCid);
jPanelCpin = new JPanel();
jLabelCpin = new JLabel("CPIN");
jLabelCpin.setForeground(Color.RED);
jLabelCpin.setFont(new Font("", Font.BOLD, 15));
jTextFieldCpin = new JPasswordField(15);
jPanelCpin.add(jLabelCpin);
jPanelCpin.add(jTextFieldCpin);
jPanelBtn = new JPanel();
jButtonLogin = new JButton("LOGIN");
jPanelBtn.add(jButtonLogin);
jPanel.add(jPanelCid);
jPanel.add(jPanelCpin);
jPanel.add(jPanelBtn);
this.add(jPanel);
this.setVisible(true);
jButtonLogin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String cid = new String(jTextFieldCid.getText());
if (cid.length() <= 0) {
JOptionPane.showMessageDialog(null, "CID NULL");
System.out.println("CID NULL");
} else {
String cpin = new String(jTextFieldCpin.getPassword());
Customer inputCustomer = new Customer(cid, cpin);
Customer returnCustomer = null;
if (Validate.is7RandNumeric(cid) && Validate.is7RandNumeric(cpin))
returnCustomer = new Login().login(inputCustomer);
if (returnCustomer != null) {
JOptionPane.showMessageDialog(null, "LOGIN SUCCEEDED!", "PROMPT",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "ID OR PIN ERROR!", "PROMPT",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
});
}
public static void main(String[] args) {
new Gui();
}
}// end Gui

@ -0,0 +1,58 @@
package org.atm.ctrl;
import org.junit.Assert;
import org.atm.ctrl.Validate;
public class ValidateTest extends junit.framework.TestCase {
/**
*
* @param arg0
*/
public ValidateTest(String arg0) {
super(arg0);
}
/**
*
* @param args
*/
public static void main(String[] args) {
}
/**
*
* @exception Exception
*/
protected void setUp()
throws Exception {
super.setUp();
}
/**
*
* @exception Exception
*/
protected void tearDown()
throws Exception {
super.tearDown();
}
public final void testIsNumeric_01_7() {
Assert.assertTrue(Validate.is7RandNumeric("2060041"));
}
public final void testIsNumeric_02_d() {
Assert.assertFalse(Validate.is7RandNumeric("123456d"));
}
public final void testIsNumeric_03_8() {
Assert.assertFalse(Validate.is7RandNumeric("12345678"));
}
public final void testIsNumeric_04_null() {
Assert.assertFalse(Validate.is7RandNumeric(""));
}
public final void testIsNumeric_05_6() {
Assert.assertFalse(Validate.is7RandNumeric("123456"));
}
}// end ValidateTest

@ -0,0 +1,16 @@
package org.atm.dao;
import org.junit.runners.Suite;
import org.junit.runner.RunWith;
import junit.framework.TestSuite;
import junit.framework.Test;
@RunWith(Suite.class)
@Suite.SuiteClasses({org.atm.ctrl.ValidateTest.class, org.atm.dao.LoginTest.class})
public class LoginIntegratedTest {
public static Test suit() {
TestSuite suite = new TestSuite();
return suite;
}
}// end LoginITest

@ -0,0 +1,15 @@
package org.atm.dao;
import org.junit.Assert;
import org.atm.dao.Login;
import org.atm.model.Customer;
public class LoginTest extends junit.framework.TestCase {
public final void testLogin_01() {
Assert.assertNotNull(new Login().login(new Customer("2060041", "2060041")));
}
public final void testLogin_02() {
Assert.assertNull(new Login().login(new Customer("1234578", "1234589")));
}
}
Loading…
Cancel
Save