Skip to content

Commit

Permalink
Switching to Java 17
Browse files Browse the repository at this point in the history
* add explicit OpenNashorn dependency
* fix deprecations
  • Loading branch information
lbergelson committed Feb 2, 2023
1 parent 8108d56 commit 7a70dcd
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 64 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11 ]
java: [ 17 ]
experimental: [false]
# include:
# - java: 17
# experimental: true
fail-fast: false
continue-on-error: ${{ matrix.experimental }}
name: Java ${{ matrix.Java }} build and test
Expand All @@ -40,8 +37,6 @@ jobs:
run: scripts/htsget-scripts/start-htsget-test-server.sh
- name: Run tests
run: ./gradlew test jacocoTestReport
# - name: Upload to codecov
# run: bash <(curl -s https://raw.githubusercontent.com/broadinstitute/codecov-bash-uploader/main/codecov-verified.bash)
- name: Upload test results
if: always()
uses: actions/upload-artifact@v2
Expand Down
38 changes: 16 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
id 'signing'
id 'jacoco'
id 'com.palantir.git-version' version '0.11.0'
id 'com.github.johnrengelman.shadow' version '4.0.4'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.github.spotbugs' version "5.0.13"
}

Expand All @@ -37,17 +37,25 @@ dependencies {
exclude group: "junit"
}

implementation 'org.openjdk.nashorn:nashorn-core:15.4'


api "gov.nih.nlm.ncbi:ngs-java:2.9.0"
api "org.apache.commons:commons-jexl:2.1.1"

testImplementation "org.testng:testng:6.14.3"
testImplementation "com.google.jimfs:jimfs:1.1"
testImplementation "com.google.guava:guava:26.0-jre"
testImplementation 'org.testng:testng:7.7.0'
testImplementation 'com.google.jimfs:jimfs:1.1'
testImplementation "com.google.guava:guava:31.1-jre"
testImplementation "org.apache.commons:commons-lang3:3.7"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
withJavadocJar()
withSourcesJar()
}

final isRelease = Boolean.getBoolean("release")
final gitVersion = gitVersion().replaceAll(".dirty", "")
Expand All @@ -64,6 +72,7 @@ tasks.withType(JavaCompile) {

tasks.withType(Javadoc) {
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('Xdoclint:none', '-quiet')
}

jar {
Expand Down Expand Up @@ -159,20 +168,6 @@ if(project == rootProject) {
}
}

tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}

task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
from sourceSets.main.allSource
archiveClassifier.set('sources')
}

spotbugs {
reportLevel = 'high'
excludeFilter = file('gradle/spotbugs-exclude.xml')
Expand All @@ -197,8 +192,6 @@ publishing {
publications {
htsjdk(MavenPublication) {
from components.java
artifact javadocJar
artifact sourcesJar

pom {
name = 'HTSJDK'
Expand Down Expand Up @@ -250,6 +243,7 @@ signing {
required { isRelease && gradle.taskGraph.hasTask("publishHtsjdkPublicationToMavenRepository") }
sign publishing.publications.htsjdk
}

gradle.taskGraph.beforeTask { Task task ->
println "executing $task ..."
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/htsjdk/samtools/Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static SortedMap<String, Object> allDefaults(){
private static String getStringProperty(final String name, final String def) {
try {
return System.getProperty(Defaults.SAMJDK_PREFIX + name, def);
} catch (final java.security.AccessControlException error) {
} catch (final SecurityException error) {
log.warn(error,"java Security Manager forbids 'System.getProperty(\"" + name + "\")' , returning default value: " + def );
return def;
}
Expand All @@ -178,7 +178,7 @@ private static String getStringProperty(final String name, final String def) {
private static boolean hasProperty(final String name){
try {
return null != System.getProperty(Defaults.SAMJDK_PREFIX + name);
} catch (final java.security.AccessControlException error) {
} catch (final SecurityException error) {
log.warn(error,"java Security Manager forbids 'System.getProperty(\"" + name + "\")' , returning false");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/samtools/TextTagCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ else if (SAMUtils.isValidUnsignedIntegerAttribute(lValue)) {
}
} else if (type.equals("f")) {
try {
return new Float(stringVal);
return Float.parseFloat(stringVal);
} catch (NumberFormatException e) {
throw new SAMFormatException("Tag of type f should have single-precision floating point value");
}
Expand Down
63 changes: 32 additions & 31 deletions src/test/java/htsjdk/samtools/SAMRecordUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,30 +342,31 @@ public void test_getUnsignedIntegerAttribute_valid() {
Assert.assertNull(record.getUnsignedIntegerAttribute(binaryTag));

record.setAttribute("UI", (long) 0L);
Assert.assertEquals(new Long(0L), record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(new Long(0L), record.getUnsignedIntegerAttribute(binaryTag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(binaryTag));

record.setAttribute("UI", BinaryCodec.MAX_UINT);
Assert.assertEquals(new Long(BinaryCodec.MAX_UINT), record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(new Long(BinaryCodec.MAX_UINT), record.getUnsignedIntegerAttribute(binaryTag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(binaryTag));

final SAMBinaryTagAndValue tv_zero = new SAMBinaryTagAndValue(binaryTag, 0L);
record = new SAMRecord(header){
{
setAttributes(tv_zero);
}
};
Assert.assertEquals(new Long(0L), record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(new Long(0L), record.getUnsignedIntegerAttribute(binaryTag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(binaryTag));

final SAMBinaryTagAndValue tv_max = new SAMBinaryTagAndValue(binaryTag, BinaryCodec.MAX_UINT);
record = new SAMRecord(header){
{

setAttributes(tv_max);
}
};
Assert.assertEquals(new Long(BinaryCodec.MAX_UINT), record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(new Long(BinaryCodec.MAX_UINT), record.getUnsignedIntegerAttribute(binaryTag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(stringTag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(binaryTag));
}

/**
Expand All @@ -380,11 +381,11 @@ public void test_getUnsignedIntegerAttribute_valid_alternative() {

record = new SAMRecord(header);
record.setAttribute("UI", 0L);
Assert.assertEquals(new Long(0L), record.getUnsignedIntegerAttribute(tag));
Assert.assertEquals(0L, record.getUnsignedIntegerAttribute(tag));

record = new SAMRecord(header);
record.setAttribute("UI", BinaryCodec.MAX_UINT);
Assert.assertEquals(new Long(BinaryCodec.MAX_UINT), record.getUnsignedIntegerAttribute("UI"));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute("UI"));
}

@Test(expectedExceptions = SAMException.class)
Expand All @@ -406,23 +407,23 @@ public void test_setUnsignedIntegerAttributeTooLarge() {
// SAMBinaryTagAndValue, but we'll leave this test here until the code is removed.
@Test
public void test_isAllowedAttributeDataType() {
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new Byte((byte) 0)));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new Short((short) 0)));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new Integer(0)));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue("a string"));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new Character('C')));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new Float(0.1F)));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new byte[]{0}));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new short[]{0}));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new int[]{0}));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new float[]{0.1F}));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue((byte) 0));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue((short) 0));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue(0));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue("a string"));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue('C'));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue(0.1F));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue(new byte[]{0}));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue(new short[]{0}));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue(new int[]{0}));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue(new float[]{0.1F}));

// unsigned integers:
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new Long(0)));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new Long(BinaryCodec.MAX_UINT)));
Assert.assertTrue(SAMRecord.isAllowedAttributeValue(new Long(-1L)));
Assert.assertFalse(SAMRecord.isAllowedAttributeValue(new Long(BinaryCodec.MAX_UINT + 1L)));
Assert.assertFalse(SAMRecord.isAllowedAttributeValue(new Long(Integer.MIN_VALUE - 1L)));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue(0L));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue(BinaryCodec.MAX_UINT));
Assert.assertTrue(SAMBinaryTagAndValue.isAllowedAttributeValue(-1L));
Assert.assertFalse(SAMBinaryTagAndValue.isAllowedAttributeValue(BinaryCodec.MAX_UINT + 1L));
Assert.assertFalse(SAMBinaryTagAndValue.isAllowedAttributeValue(Integer.MIN_VALUE - 1L));
}

@Test()
Expand Down Expand Up @@ -463,7 +464,7 @@ public void test_setAttribute_null_removes_tag() {
Assert.assertNull(record.getUnsignedIntegerAttribute(tag));

record.setAttribute(tag, BinaryCodec.MAX_UINT);
Assert.assertEquals(new Long(BinaryCodec.MAX_UINT), record.getUnsignedIntegerAttribute(tag));
Assert.assertEquals(BinaryCodec.MAX_UINT, record.getUnsignedIntegerAttribute(tag));

record.setAttribute(tag, null);
Assert.assertNull(record.getUnsignedIntegerAttribute(tag));
Expand Down Expand Up @@ -877,7 +878,7 @@ public void testSetHeaderStrictValidNewHeader() {

// force re-resolution of the reference name against the new header
sam.setHeaderStrict(newHeader);
Assert.assertEquals(sam.getReferenceIndex(), new Integer(0));
Assert.assertEquals(sam.getReferenceIndex(), 0);
}

@Test(expectedExceptions=IllegalArgumentException.class)
Expand All @@ -886,7 +887,7 @@ public void testSetHeaderStrictInvalidReference() {
final SAMFileHeader samHeader = sam.getHeader();

sam.setReferenceName("unresolvable");
Assert.assertEquals(new Integer(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX), sam.getReferenceIndex());
Assert.assertEquals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, sam.getReferenceIndex());

// throw on force re-resolution of the unresolvable reference name
sam.setHeaderStrict(samHeader);
Expand All @@ -898,7 +899,7 @@ public void testSetHeaderStrictInvalidMateReference() {
final SAMFileHeader samHeader = sam.getHeader();

sam.setMateReferenceName("unresolvable");
Assert.assertEquals(new Integer(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX), sam.getMateReferenceIndex());
Assert.assertEquals(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX, sam.getMateReferenceIndex());

// throw on force re-resolution of the unresolvable mate reference name
sam.setHeaderStrict(samHeader);
Expand All @@ -920,7 +921,7 @@ public void testResolveIndexResolvable() {
final SAMRecord sam = createTestRecordHelper();
final SAMFileHeader samHeader = sam.getHeader();
final String contigName = sam.getContig();
Assert.assertEquals(SAMRecord.resolveIndexFromName(contigName, samHeader, true), new Integer(samHeader.getSequenceIndex(contigName)));
Assert.assertEquals(SAMRecord.resolveIndexFromName(contigName, samHeader, true), samHeader.getSequenceIndex(contigName));
}

@Test(expectedExceptions=IllegalStateException.class)
Expand All @@ -944,7 +945,7 @@ public void testResolveIndexUnresolvableNotStrict() {
public void testResolveIndexNoAlignment() {
final SAMFileHeader samHeader = new SAMFileHeader();
Assert.assertEquals(SAMRecord.resolveIndexFromName(
SAMRecord.NO_ALIGNMENT_REFERENCE_NAME, samHeader, true), new Integer(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX));
SAMRecord.NO_ALIGNMENT_REFERENCE_NAME, samHeader, true), SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX);
}

@Test(expectedExceptions=IllegalStateException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ private class BCF2TypedValue {
final Object value;

private BCF2TypedValue(final int value, final BCF2Type type) {
this(new Integer(value), type);
this((Integer)value, type);
}

private BCF2TypedValue(final double value, final BCF2Type type) {
this(new Double(value), type);
this((Double)value, type);
}

private BCF2TypedValue(final Object value, final BCF2Type type) {
Expand Down

0 comments on commit 7a70dcd

Please sign in to comment.