Skip to content

Commit

Permalink
use slf4j logging framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Frotty committed May 27, 2018
1 parent 43b5d66 commit a205fcf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
15 changes: 9 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id "signing"
id "maven-publish"
id "jacoco"
id "com.github.kt3k.coveralls" version "2.5.0"
id 'com.github.kt3k.coveralls' version '2.8.2'
id "java"
}

Expand All @@ -13,7 +13,7 @@ version '1.5.9'

repositories {
jcenter()
mavenCentral()
mavenCentral()
}

task dist(type: Jar) {
Expand All @@ -26,16 +26,19 @@ dist.dependsOn classes
dist.archiveName = "${jar.baseName}.${jar.extension}"

dependencies {
compile 'com.jcraft:jzlib:1.1.3'
compile 'com.esotericsoftware.minlog:minlog:1.2'
compile 'com.jcraft:jzlib:1.1.3'
compile group: 'org.apache.commons', name: 'commons-compress', version: '1.15'
compile group: 'org.tukaani', name: 'xz', version: '1.8'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
testCompile 'org.testng:testng:6.13.1'
}



test {
// enable TestNG support (default is JUnit)
useTestNG()
}

jacocoTestReport {
reports {
xml.enabled true
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/systems/crigges/jmpq3/AttributesFile.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package systems.crigges.jmpq3;

import com.esotericsoftware.minlog.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
Expand All @@ -12,6 +13,7 @@
import java.util.zip.CRC32;

public class AttributesFile {
private Logger log = LoggerFactory.getLogger(this.getClass().getName());
private byte[] file;

private int[] crc32;
Expand Down Expand Up @@ -42,7 +44,7 @@ public AttributesFile(byte[] file) {
for (int i = 0; i < fileCount; i++) {
timestamps[i] = buffer.getLong();
}
Log.info("parsed attributes");
log.info("parsed attributes");
}

public void setEntry(int i, int crc, long timestamp) {
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/systems/crigges/jmpq3/JMpqEditor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package systems.crigges.jmpq3;

import com.esotericsoftware.minlog.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import systems.crigges.jmpq3.BlockTable.Block;
import systems.crigges.jmpq3.security.MPQEncryption;
import systems.crigges.jmpq3.security.MPQHashGenerator;
Expand Down Expand Up @@ -34,6 +35,7 @@
* For platform independence the implementation is pure Java.
*/
public class JMpqEditor implements AutoCloseable {
private Logger log = LoggerFactory.getLogger(this.getClass().getName());
public static final int ARCHIVE_HEADER_MAGIC = ByteBuffer.wrap(new byte[]{'M', 'P', 'Q', 0x1A}).order(ByteOrder.LITTLE_ENDIAN).getInt();
public static final int USER_DATA_HEADER_MAGIC = ByteBuffer.wrap(new byte[]{'M', 'P', 'Q', 0x1B}).order(ByteOrder.LITTLE_ENDIAN).getInt();

Expand Down Expand Up @@ -285,7 +287,7 @@ private void setupTempDir() throws JMpqException {
* Makes the archive readonly.
*/
private void loadDefaultListFile() throws IOException {
Log.info("The mpq doesn't come with a listfile so it cannot be rebuild");
log.info("The mpq doesn't come with a listfile so it cannot be rebuild");
InputStream resource = getClass().getClassLoader().getResourceAsStream("DefaultListfile.txt");
if (resource != null) {
File tempFile = File.createTempFile("jmpq", "lf", tempDir);
Expand Down Expand Up @@ -447,7 +449,7 @@ public void extractAllFiles(File dest) throws JMpqException {
}
if (hasFile("(listfile)") && listFile != null) {
for (String s : listFile.getFiles()) {
Log.info("extracting: " + s);
log.info("extracting: " + s);
File temp = new File(dest.getAbsolutePath() + "\\" + s);
temp.getParentFile().mkdirs();
if (hasFile(s)) {
Expand Down Expand Up @@ -671,12 +673,12 @@ public void close(boolean buildListfile, boolean buildAttributes, boolean recomp
// only rebuild if allowed
if (!canWrite) {
fc.close();
Log.info("closed readonly mpq.");
log.info("closed readonly mpq.");
return;
}

long t = System.nanoTime();
Log.info("Building mpq");
log.info("Building mpq");
if (listFile == null) {
fc.close();
return;
Expand Down Expand Up @@ -713,7 +715,7 @@ public void close(boolean buildListfile, boolean buildAttributes, boolean recomp

sortListfileEntries(existingFiles);

Log.info("Sorted blocks");
log.info("Sorted blocks");
if (attributes != null) {
attributes.setNames(existingFiles);
}
Expand Down Expand Up @@ -744,7 +746,7 @@ public void close(boolean buildListfile, boolean buildAttributes, boolean recomp
currentPos += b.getCompressedSize();
}
}
Log.info("Added existing files");
log.info("Added existing files");
HashMap<String, ByteBuffer> newFileMap = new HashMap<>();
for (ByteBuffer newFile : filesToAdd) {
newFiles.add(internalFilename.get(newFile));
Expand All @@ -754,9 +756,9 @@ public void close(boolean buildListfile, boolean buildAttributes, boolean recomp
newBlocks.add(newBlock);
MpqFile.writeFileAndBlock(newFile.array(), newBlock, fileWriter, newDiscBlockSize, recompress);
currentPos += newBlock.getCompressedSize();
Log.info("Added file " + internalFilename.get(newFile));
log.info("Added file " + internalFilename.get(newFile));
}
Log.info("Added new files");
log.info("Added new files");
if (buildListfile) {
// Add listfile
newFiles.add("(listfile)");
Expand All @@ -766,7 +768,7 @@ public void close(boolean buildListfile, boolean buildAttributes, boolean recomp
newBlocks.add(newBlock);
MpqFile.writeFileAndBlock(listfileArr, newBlock, fileWriter, newDiscBlockSize, "(listfile)", recompress);
currentPos += newBlock.getCompressedSize();
Log.info("Added listfile");
log.info("Added listfile");
}
// if (attributes != null) {
// newFiles.add("(attributes)");
Expand Down Expand Up @@ -851,7 +853,7 @@ public void close(boolean buildListfile, boolean buildAttributes, boolean recomp
writeChannel.close();

t = System.nanoTime() - t;
Log.info("Rebuild complete. Took: " + (t / 1000000) + "ms");
log.info("Rebuild complete. Took: " + (t / 1000000) + "ms");
}

private void sortListfileEntries(ArrayList<String> remainingFiles) {
Expand Down
26 changes: 15 additions & 11 deletions src/test/java/systems/crigges/jmpq3test/MpqTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package systems.crigges.jmpq3test;

import com.esotericsoftware.minlog.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
import systems.crigges.jmpq3.HashTable;
Expand All @@ -23,9 +24,11 @@
* Created by Frotty on 06.03.2017.
*/
public class MpqTests {
private Logger log = LoggerFactory.getLogger(this.getClass().getName());

private static File[] getMpqs() {
return new File(MpqTests.class.getClassLoader().getResource("./mpqs/").getFile()).listFiles((dir, name) -> name.endsWith(".w3x") || name.endsWith(".mpq"));
return new File(MpqTests.class.getClassLoader().getResource("./mpqs/").getFile()).listFiles((dir, name) -> name.endsWith(".w3x") || name.endsWith("" +
".mpq"));
}

private static File getFile(String name) {
Expand Down Expand Up @@ -98,17 +101,18 @@ public void hashTableTest() throws IOException {
public void testRebuild() throws IOException {
File[] mpqs = getMpqs();
for (File mpq : mpqs) {
Log.info(mpq.getName());
log.info(mpq.getName());
JMpqEditor mpqEditor = new JMpqEditor(mpq, MPQOpenOption.FORCE_V0);
mpqEditor.close();
mpqEditor.deleteFile("(listfile)");
mpqEditor.close(false, false, false);
}
}

@Test
public void testRecompressBuild() throws IOException {
File[] mpqs = getMpqs();
for (File mpq : mpqs) {
Log.info(mpq.getName());
log.info(mpq.getName());
JMpqEditor mpqEditor = new JMpqEditor(mpq, MPQOpenOption.FORCE_V0);
long length = mpq.length();
mpqEditor.close(true, true, true);
Expand All @@ -133,7 +137,7 @@ public void testExtractAll() throws IOException {
public void testExtractScriptFile() throws IOException {
File[] mpqs = getMpqs();
for (File mpq : mpqs) {
Log.info("test extract script: " + mpq.getName());
log.info("test extract script: " + mpq.getName());
JMpqEditor mpqEditor = new JMpqEditor(mpq, MPQOpenOption.READ_ONLY, MPQOpenOption.FORCE_V0);
File temp = File.createTempFile("war3mapj", "extracted", JMpqEditor.tempDir);
temp.deleteOnExit();
Expand Down Expand Up @@ -177,11 +181,11 @@ public void testMultipleInstances() throws IOException {
JMpqEditor mpqEditors[] = new JMpqEditor[]{new JMpqEditor(mpq, MPQOpenOption.READ_ONLY, MPQOpenOption.FORCE_V0),
new JMpqEditor(mpq, MPQOpenOption.READ_ONLY, MPQOpenOption.FORCE_V0),
new JMpqEditor(mpq, MPQOpenOption.READ_ONLY, MPQOpenOption.FORCE_V0)};
for (int i = 0; i < mpqEditors.length; i++) {
mpqEditors[i].extractAllFiles(JMpqEditor.tempDir);
for (JMpqEditor mpqEditor1 : mpqEditors) {
mpqEditor1.extractAllFiles(JMpqEditor.tempDir);
}
for (int i = 0; i < mpqEditors.length; i++) {
mpqEditors[i].close();
for (JMpqEditor mpqEditor : mpqEditors) {
mpqEditor.close();
}
}
}
Expand Down Expand Up @@ -278,7 +282,7 @@ public void testRemoveHeaderoffset() throws IOException {
}
Assert.assertNotNull(mpq);

Log.info(mpq.getName());
log.info(mpq.getName());
JMpqEditor mpqEditor = new JMpqEditor(mpq, MPQOpenOption.FORCE_V0);
mpqEditor.setKeepHeaderOffset(false);
mpqEditor.close();
Expand Down

0 comments on commit a205fcf

Please sign in to comment.