Skip to content

Commit dc13fd0

Browse files
johnmayegonw
authored andcommitted
Move the old JNI enums to a seperate (optional) module - this means the InChI works fine. If you need the enums you can optionally include the cdk-jniinchi-support module.
1 parent 9e4556d commit dc13fd0

File tree

8 files changed

+102
-61
lines changed

8 files changed

+102
-61
lines changed

storage/inchi/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
<groupId>javax.vecmath</groupId>
2323
<artifactId>vecmath</artifactId>
2424
</dependency>
25+
<dependency>
26+
<groupId>org.openscience.cdk</groupId>
27+
<artifactId>cdk-jniinchi-support</artifactId>
28+
<version>${project.parent.version}</version>
29+
<optional>true</optional>
30+
</dependency>
2531
<dependency>
2632
<groupId>io.github.dan2097</groupId>
2733
<artifactId>jna-inchi-api</artifactId>

storage/inchi/src/main/java/org/openscience/cdk/inchi/InChIGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected InChIGenerator(IAtomContainer atomContainer, String optStr, boolean ig
165165
private static InchiOptions convertJniToJnaOpts(List<INCHI_OPTION> jniOpts) {
166166
InchiOptions.InchiOptionsBuilder builder = new InchiOptions.InchiOptionsBuilder();
167167
for (INCHI_OPTION jniOpt : jniOpts) {
168-
InchiFlag flag = INCHI_OPTION.wrap(jniOpt);
168+
InchiFlag flag = JniInchiSupport.toJnaOption(jniOpt);
169169
if (flag != null)
170170
builder.withFlag(flag);
171171
}
@@ -507,7 +507,7 @@ private static void swap(Object[] objs, int i, int j) {
507507
* has failed.
508508
*/
509509
public INCHI_RET getReturnStatus() {
510-
return INCHI_RET.wrap(output.getStatus());
510+
return JniInchiSupport.toJniStatus(output.getStatus());
511511
}
512512

513513
/**

storage/inchi/src/main/java/org/openscience/cdk/inchi/InChIToStructure.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import io.github.dan2097.jnainchi.InchiStereo;
2727
import io.github.dan2097.jnainchi.InchiStereoParity;
2828
import io.github.dan2097.jnainchi.InchiStereoType;
29-
import net.sf.jniinchi.INCHI_OPTION;
3029
import net.sf.jniinchi.INCHI_RET;
3130
import io.github.dan2097.jnainchi.InchiInputFromInchiOutput;
3231
import io.github.dan2097.jnainchi.InchiOptions;
@@ -427,7 +426,7 @@ public IAtomContainer getAtomContainer() {
427426
* has failed.
428427
*/
429428
public INCHI_RET getReturnStatus() {
430-
return INCHI_RET.wrap(output.getStatus());
429+
return JniInchiSupport.toJniStatus(output.getStatus());
431430
}
432431

433432
/**

storage/inchi/src/main/java/net/sf/jniinchi/INCHI_OPTION.java renamed to storage/inchi/src/main/java/org/openscience/cdk/inchi/JniInchiSupport.java

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/*
2-
* Copyright (C) 2021 John Mayfield
1+
/* Copyright (C) 2006-2007 Sam Adams <sea36@users.sf.net>
32
*
43
* Contact: cdk-devel@lists.sourceforge.net
54
*
@@ -18,58 +17,32 @@
1817
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1918
*/
2019

21-
package net.sf.jniinchi;
20+
package org.openscience.cdk.inchi;
2221

2322
import io.github.dan2097.jnainchi.InchiFlag;
23+
import io.github.dan2097.jnainchi.InchiStatus;
24+
import net.sf.jniinchi.INCHI_OPTION;
25+
import net.sf.jniinchi.INCHI_RET;
2426

2527
/**
26-
* This class provides backwards compatibility of JNA-INCHI with JNI-INCHI, this enum was exposed in the CDK API.
27-
* @author John Mayfield
28+
* This class provides conversion from JNI InChI enum options to JNA (input) and
29+
* from JNA return status to JNI status (output).
2830
*/
29-
public enum INCHI_OPTION {
30-
SUCF,
31-
ChiralFlagON,
32-
ChiralFlagOFF,
33-
SNon,
34-
SAbs,
35-
SRel,
36-
SRac,
37-
SUU,
38-
NEWPS,
39-
RecMet,
40-
FixedH,
41-
AuxNone,
42-
NoADP,
43-
Compress,
44-
DoNotAddH,
45-
Wnumber,
46-
OutputSDF,
47-
WarnOnEmptyStructure,
48-
FixSp3Bug,
49-
FB,
50-
SPXYZ,
51-
SAsXYZ;
31+
final class JniInchiSupport {
5232

53-
public static INCHI_OPTION wrap(InchiFlag flag) {
54-
switch (flag) {
55-
case SUCF: return SUCF;
56-
case ChiralFlagON: return ChiralFlagON;
57-
case ChiralFlagOFF: return ChiralFlagOFF;
58-
case SNon: return SNon;
59-
case SRel: return SRel;
60-
case SRac: return SRac;
61-
case SUU: return SUU;
62-
case RecMet: return RecMet;
63-
case FixedH: return FixedH;
64-
case AuxNone: return AuxNone;
65-
case DoNotAddH: return DoNotAddH;
66-
case WarnOnEmptyStructure: return WarnOnEmptyStructure;
33+
private JniInchiSupport() {}
6734

68-
default: throw new IllegalArgumentException(flag + " not supported?");
35+
static INCHI_RET toJniStatus(InchiStatus status) {
36+
switch (status) {
37+
case SUCCESS: return INCHI_RET.OKAY;
38+
case WARNING: return INCHI_RET.WARNING;
39+
case ERROR: return INCHI_RET.ERROR;
40+
default:
41+
throw new IllegalArgumentException("Unexpected status!");
6942
}
7043
}
7144

72-
public static InchiFlag wrap(INCHI_OPTION flag) {
45+
static InchiFlag toJnaOption(INCHI_OPTION flag) {
7346
switch (flag) {
7447
case SUCF: return InchiFlag.SUCF;
7548
case ChiralFlagON: return InchiFlag.ChiralFlagON;

storage/jniinchi-support/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>cdk-storage</artifactId>
7+
<groupId>org.openscience.cdk</groupId>
8+
<version>2.7-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>cdk-jniinchi-support</artifactId>
13+
<description>This module provides backwards compatibility support for the JNI based InChI APIs</description>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>junit</groupId>
18+
<artifactId>junit</artifactId>
19+
<scope>test</scope>
20+
</dependency>
21+
</dependencies>
22+
</project>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2021 John Mayfield
3+
*
4+
* Contact: cdk-devel@lists.sourceforge.net
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation; either version 2.1
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*/
20+
21+
package net.sf.jniinchi;
22+
23+
/**
24+
* This class provides backwards compatibility of JNA-INCHI with JNI-INCHI,
25+
* this enum was exposed in the CDK API.
26+
* @author John Mayfield
27+
*/
28+
public enum INCHI_OPTION {
29+
SUCF,
30+
ChiralFlagON,
31+
ChiralFlagOFF,
32+
SNon,
33+
SAbs,
34+
SRel,
35+
SRac,
36+
SUU,
37+
NEWPS,
38+
RecMet,
39+
FixedH,
40+
AuxNone,
41+
NoADP,
42+
Compress,
43+
DoNotAddH,
44+
Wnumber,
45+
OutputSDF,
46+
WarnOnEmptyStructure,
47+
FixSp3Bug,
48+
FB,
49+
SPXYZ,
50+
SAsXYZ;
51+
}

storage/inchi/src/main/java/net/sf/jniinchi/INCHI_RET.java renamed to storage/jniinchi-support/src/main/java/net/sf/jniinchi/INCHI_RET.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020

2121
package net.sf.jniinchi;
2222

23-
import io.github.dan2097.jnainchi.InchiStatus;
24-
2523
/**
26-
* This class provides backwards compatibility of JNA-INCHI with JNI-INCHI, this enum was exposed in the CDK API.
24+
* This class provides backwards compatibility of JNA-INCHI with JNI-INCHI,
25+
* this enum was exposed in the CDK API.
2726
* @author John Mayfield
2827
*/
2928
public enum INCHI_RET {
@@ -35,14 +34,4 @@ public enum INCHI_RET {
3534
FATAL,
3635
UNKNOWN,
3736
BUSY;
38-
39-
public static INCHI_RET wrap(InchiStatus status) {
40-
switch (status) {
41-
case SUCCESS: return INCHI_RET.OKAY;
42-
case WARNING: return INCHI_RET.WARNING;
43-
case ERROR: return INCHI_RET.ERROR;
44-
default:
45-
throw new IllegalArgumentException("Unexpected status!");
46-
}
47-
}
4837
}

storage/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<module>pdb</module>
2121
<module>pdbcml</module>
2222
<module>inchi</module>
23+
<module>jniinchi-support</module>
2324
<module>smiles</module>
2425
</modules>
2526
<packaging>pom</packaging>

0 commit comments

Comments
 (0)