Skip to content

Commit 663f372

Browse files
committed
chore: Refactor
1 parent 4e6b040 commit 663f372

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+16059
-1960
lines changed

.circleci/config.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
java-version: [11, 17]
1515

1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v5
1818

1919
- name: Set up JDK ${{ matrix.java-version }}
2020
uses: actions/setup-java@v3
@@ -31,7 +31,7 @@ jobs:
3131

3232
- name: Upload test results
3333
if: always()
34-
uses: actions/upload-artifact@v3
34+
uses: actions/upload-artifact@v4
3535
with:
3636
name: test-results-java-${{ matrix.java-version }}
3737
path: target/surefire-reports/

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v5
15+
16+
- name: Setup Java
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '21'
20+
distribution: 'temurin'
21+
22+
- name: Cache Maven dependencies
23+
uses: actions/cache@v4
24+
with:
25+
path: ~/.m2
26+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
27+
restore-keys: ${{ runner.os }}-m2
28+
29+
- name: Run tests
30+
run: mvn test
31+
32+
- name: Build project
33+
run: mvn clean package

FileCompression.jar

-20.6 KB
Binary file not shown.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# File Compression
22

3-
[![Build and Test](https://github.com/ayonious/File-Compression/actions/workflows/build.yml/badge.svg)](https://github.com/ayonious/File-Compression/actions/workflows/build.yml)
3+
[![CI](https://github.com/ayonious/File-Compression/workflows/CI/badge.svg)](https://github.com/ayonious/File-Compression/actions)
44
[![codecov](https://codecov.io/gh/ayonious/File-Compression/branch/master/graph/badge.svg)](https://codecov.io/gh/ayonious/File-Compression)
55
[![GitHub stars](https://img.shields.io/github/stars/ayonious/File-Compression?style=social)](https://github.com/ayonious/File-Compression/stargazers)
66

pom.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<maven.compiler.target>21</maven.compiler.target>
1414
<maven.compiler.release>21</maven.compiler.release>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<jacoco.version>0.8.12</jacoco.version>
1617
</properties>
1718

1819
<dependencies>
@@ -67,19 +68,36 @@
6768
<groupId>org.apache.maven.plugins</groupId>
6869
<artifactId>maven-surefire-plugin</artifactId>
6970
<version>3.2.5</version>
71+
<configuration>
72+
<argLine>
73+
--add-opens java.base/java.lang=ALL-UNNAMED
74+
--add-opens java.base/java.util=ALL-UNNAMED
75+
--add-opens java.base/sun.util.resources.cldr.provider=ALL-UNNAMED
76+
${argLine}
77+
</argLine>
78+
</configuration>
7079
</plugin>
7180

7281
<!-- JaCoCo Plugin for code coverage -->
7382
<plugin>
7483
<groupId>org.jacoco</groupId>
7584
<artifactId>jacoco-maven-plugin</artifactId>
76-
<version>0.8.11</version>
85+
<version>${jacoco.version}</version>
86+
<configuration>
87+
<excludes>
88+
<exclude>**/module-info.class</exclude>
89+
<exclude>sun/util/resources/**</exclude>
90+
</excludes>
91+
</configuration>
7792
<executions>
7893
<execution>
7994
<id>prepare-agent</id>
8095
<goals>
8196
<goal>prepare-agent</goal>
8297
</goals>
98+
<configuration>
99+
<propertyName>argLine</propertyName>
100+
</configuration>
83101
</execution>
84102
<execution>
85103
<id>report</id>

renovate.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main/java/prog/Main.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,45 @@
1010
import javax.swing.JOptionPane;
1111
import javax.swing.JPanel;
1212

13-
import prog.huffman.Hzipping;
14-
import prog.huffman.Hunzipping;
15-
import prog.lzw.Lzipping;
16-
import prog.lzw.Lunzipping;
13+
import prog.huffman.HuffmanCompressor;
14+
import prog.huffman.HuffmanDecompressor;
15+
import prog.lzw.LzwCompressor;
16+
import prog.lzw.LzwDecompressor;
17+
import prog.util.Constants;
1718

1819
public class Main extends JFrame implements ActionListener {
1920
// Definition of global values and items that are part of the GUI.
2021

21-
static public File opened_file, other_file;
22-
static long past, future;
23-
static JLabel redLabel, blueLabel, redScore, blueScore;
22+
static public File openedFile, outputFile;
23+
static long originalSize, compressedSize;
24+
static JLabel originalSizeLabel, compressedSizeLabel, originalSizeValue, compressedSizeValue;
2425
static JPanel buttonPanel, titlePanel, scorePanel;
25-
static JButton ZH, UH, ZL, UL, EX;
26+
static JButton huffmanCompressButton, huffmanDecompressButton, lzwCompressButton, lzwDecompressButton, exitButton;
2627

2728
public JPanel createContentPane() {
2829
return MainPanel.createContentPane(this);
2930
}
3031

3132
private void handleHuffmanCompression() {
32-
Hzipping.beginHzipping(opened_file.getPath());
33+
HuffmanCompressor.beginHuffmanCompression(openedFile.getPath());
3334
showCompressionCompleteDialog("Zipping");
34-
updateFileStats(".huffz");
35+
updateFileStats(Constants.HUFFMAN_FILE_EXTENSION);
3536
}
3637

3738
private void handleHuffmanDecompression() {
38-
Hunzipping.beginHunzipping(opened_file.getPath());
39+
HuffmanDecompressor.beginHuffmanDecompression(openedFile.getPath());
3940
showCompressionCompleteDialog("UnZipping");
4041
updateDecompressionStats();
4142
}
4243

4344
private void handleLZWCompression() {
44-
Lzipping.beginLzipping(opened_file.getPath());
45+
LzwCompressor.beginLzwCompression(openedFile.getPath());
4546
showCompressionCompleteDialog("Zipping");
46-
updateFileStats(".LmZWp");
47+
updateFileStats(Constants.LZW_FILE_EXTENSION);
4748
}
4849

4950
private void handleLZWDecompression() {
50-
Lunzipping.beginLunzipping(opened_file.getPath());
51+
LzwDecompressor.beginLzwDecompression(openedFile.getPath());
5152
showCompressionCompleteDialog("UnZipping");
5253
updateDecompressionStats();
5354
}
@@ -59,31 +60,31 @@ private void showCompressionCompleteDialog(String operation) {
5960
}
6061

6162
private void updateFileStats(String extension) {
62-
redScore.setText(opened_file.length() + "Bytes");
63-
other_file = new File(opened_file.getPath() + extension);
64-
future = other_file.length();
65-
blueScore.setText(future + "Bytes");
63+
originalSizeValue.setText(openedFile.length() + "Bytes");
64+
outputFile = new File(openedFile.getPath() + extension);
65+
compressedSize = outputFile.length();
66+
compressedSizeValue.setText(compressedSize + "Bytes");
6667
}
6768

6869
private void updateDecompressionStats() {
69-
redScore.setText(opened_file.length() + "Bytes");
70-
String s = opened_file.getPath();
70+
originalSizeValue.setText(openedFile.length() + "Bytes");
71+
String s = openedFile.getPath();
7172
s = s.substring(0, s.length() - 6);
72-
other_file = new File(s);
73-
future = other_file.length();
74-
blueScore.setText(future + "Bytes");
73+
outputFile = new File(s);
74+
compressedSize = outputFile.length();
75+
compressedSizeValue.setText(compressedSize + "Bytes");
7576
}
7677

7778
public void actionPerformed(ActionEvent e) {
78-
if (e.getSource() == ZH) {
79+
if (e.getSource() == huffmanCompressButton) {
7980
handleHuffmanCompression();
80-
} else if (e.getSource() == UH) {
81+
} else if (e.getSource() == huffmanDecompressButton) {
8182
handleHuffmanDecompression();
82-
} else if (e.getSource() == ZL) {
83+
} else if (e.getSource() == lzwCompressButton) {
8384
handleLZWCompression();
84-
} else if (e.getSource() == UL) {
85+
} else if (e.getSource() == lzwDecompressButton) {
8586
handleLZWDecompression();
86-
} else if (e.getSource() == EX) {
87+
} else if (e.getSource() == exitButton) {
8788
System.exit(0);
8889
}
8990
}

src/main/java/prog/MainFrame.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import javax.swing.*;
44
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
6+
import prog.util.Constants;
67

78
public class MainFrame {
89
private static JFrame createMainFrame() {
9-
JFrame frame = new JFrame("File Compresser");
10+
JFrame frame = new JFrame("File Compressor");
1011
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1112
frame.setBounds(350, 170, 550, 300);
1213
return frame;
@@ -44,10 +45,10 @@ private static void handleFileOpen() {
4445
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
4546
int result = fileChooser.showOpenDialog(null);
4647
if (result == JFileChooser.APPROVE_OPTION) {
47-
Main.opened_file = fileChooser.getSelectedFile();
48-
Main.past = Main.opened_file.length();
49-
Main.redScore.setText(Main.past + "Bytes");
50-
Main.blueScore.setText("NotYetCalculated");
48+
Main.openedFile = fileChooser.getSelectedFile();
49+
Main.originalSize = Main.openedFile.length();
50+
Main.originalSizeValue.setText(Main.originalSize + "Bytes");
51+
Main.compressedSizeValue.setText("NotYetCalculated");
5152
}
5253
}
5354

@@ -64,26 +65,26 @@ private static JMenu createHelpMenu() {
6465
}
6566

6667
private static void showHowToDialog() {
67-
String message = "Two algorithms are used for file compression\n" +
68-
"1. Huffmans Codes\n" +
69-
"2. Lampel-Ziv-Welch\n" +
70-
"To compress a file first open the file then click\n" +
71-
"ZIP HuffZ to zip the file using Huffmans algo.A zipped\n" +
72-
"file with extension .huffz will be created in the same\n" +
73-
"folder. This is the zipped file. During unzipping just open\n" +
68+
String message = "Two algorithms are used for file compression:\n" +
69+
"1. Huffman Coding\n" +
70+
"2. Lempel-Ziv-Welch (LZW)\n" +
71+
"To compress a file, first open the file then click\n" +
72+
"ZIP HuffZ to zip the file using Huffman's algorithm. A compressed\n" +
73+
"file with extension " + Constants.HUFFMAN_FILE_EXTENSION + " will be created in the same\n" +
74+
"folder. This is the compressed file. To decompress, just open\n" +
7475
"this file and click UNZIP HuffZ button.\n\n" +
75-
"Same will happen for LZW. Zipped file's extension will be .LmZWp\n" +
76-
"for LZW. Always make sure that during unzipping you must use\n" +
77-
"the same algorithm that you used for zipping ";
76+
"The same process applies for LZW. Compressed file's extension will be " + Constants.LZW_FILE_EXTENSION + "\n" +
77+
"for LZW. Always make sure that during decompression you must use\n" +
78+
"the same algorithm that you used for compression.";
7879
JOptionPane.showMessageDialog(null, message, "How To...", JOptionPane.PLAIN_MESSAGE);
7980
}
8081

8182
private static void showAboutDialog() {
82-
String message = "File Compresser is a software to zip and unzip files\n" +
83-
"It is developed on JAVA, as a term project of\n" +
84-
" Level - 2, Term - 1,Dept. of CSE,BUET.\n" +
85-
"It is completed by Nahiyan Kamal (St. ID 0805006) under\n" +
86-
"the supervision of Jesun Shahariar of Dept. of CSE, BUET.";
83+
String message = "File Compressor is a software to compress and decompress files.\n" +
84+
"It is developed in Java as a term project for\n" +
85+
"Level 2, Term 1, Department of CSE, BUET.\n" +
86+
"Developed by Nahiyan Kamal (Student ID: 0805006) under\n" +
87+
"the supervision of Jesun Shahariar, Department of CSE, BUET.";
8788
JOptionPane.showMessageDialog(null, message, "About", JOptionPane.PLAIN_MESSAGE);
8889
}
8990

0 commit comments

Comments
 (0)