Skip to content

Commit

Permalink
Fix Java 5 compatibility (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
tntim96 committed Jul 8, 2014
1 parent ebb103b commit 72b568e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1.0.13 / 2014-??-??
==================
* Fix Java 5 compatibility (https://github.com/tntim96/JSCover/issues/150)
* Don't copy non-report files (https://github.com/tntim96/JSCover/issues/149)
* Internal: Remove checked exception from public API

Expand Down
18 changes: 17 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</jar>
</target>

<target name="jar-all" depends="compile">
<target name="jar-all" depends="compile-acceptance-tests">
<property name="tmpDir" value="${build.dir}/tmp"/>
<mkdir dir="${tmpDir}"/>
<unzip src="${com.github.tntim96:rhino:jar}" dest="${tmpDir}"/>
Expand All @@ -110,6 +110,22 @@
<attribute name="Main-Class" value="jscover.Main"/>
</manifest>
</jar>
<junit haltonfailure="yes" haltonerror="yes" failureProperty="test.failure" errorproperty="test.failure">
<classpath>
<path refid="classpath-main" />
<path refid="compile.classpath" />
<path refid="test.classpath" />
</classpath>
<formatter type="xml" />
<formatter type="brief" usefile="no" />
<batchtest fork="yes" todir="${report.test.dir}">
<fileset dir="${classes.test-acceptance.dir}">
<include name="**/ClassVersionChecker.class" />
</fileset>
</batchtest>
</junit>
<antcall target="report-if-failed"/>
<fail if="test.failure"/>
</target>

<target name="mvn-install-local" depends="jar-all">
Expand Down
39 changes: 39 additions & 0 deletions src/test-acceptance/java/jscover/util/ClassVersionChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package jscover.util;

import org.junit.Test;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

public class ClassVersionChecker {
@Test
public void testClasses() throws IOException {
File zipFile = new File("target/dist/JSCover-all.jar");
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
String fileName = ze.getName();
if (!fileName.endsWith(".class"))
continue;
checkClassVersion2(new File(new File("target/tmp"), fileName));
}
zis.closeEntry();
zis.close();
}

private static void checkClassVersion2(File file) throws IOException {
byte[] buffer = new byte[8];

FileInputStream in = new FileInputStream(file);
in.read(buffer, 0, 8);
in.close();

int majorVersion = buffer[6] << 8 | buffer[7];
//int minorVersion = buffer[4] << 8 | buffer[5];
assertThat(file + " is not a 1.5 class!", majorVersion, equalTo(49));
}
}

0 comments on commit 72b568e

Please sign in to comment.