Skip to content

Commit d4ae6da

Browse files
committed
Jpylyzer plugin finished
1 parent ab65a14 commit d4ae6da

Some content is hidden

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

87 files changed

+44
-127330
lines changed

jpylyzer-plugin/src/main/java/org/verapdf/JpylyzerConfig.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
@XmlRootElement(namespace = "http://www.verapdf.org/JpylyzerConfig", name = "jpylyzerConfig")
1818
final class JpylyzerConfig {
1919

20+
@XmlElement
21+
private final String cliPath;
2022
@XmlElement
2123
private final String outFolder;
2224
@XmlElement
2325
private final boolean isVerbose;
2426

2527
private JpylyzerConfig() {
26-
this("", false);
28+
this("", "", false);
2729
}
2830

29-
private JpylyzerConfig(String outFolder, boolean isVerbose) {
31+
private JpylyzerConfig(String outFolder, String cliPath, boolean isVerbose) {
32+
this.cliPath = cliPath;
3033
this.outFolder = outFolder;
3134
this.isVerbose = isVerbose;
3235
}
@@ -39,31 +42,37 @@ public boolean isVerbose() {
3942
return isVerbose;
4043
}
4144

45+
public String getCliPath() {
46+
return cliPath;
47+
}
48+
4249
@Override
4350
public boolean equals(Object o) {
4451
if (this == o) return true;
4552
if (o == null || getClass() != o.getClass()) return false;
4653

47-
JpylyzerConfig that = (JpylyzerConfig) o;
54+
JpylyzerConfig config = (JpylyzerConfig) o;
4855

49-
if (isVerbose != that.isVerbose) return false;
50-
return outFolder != null ? outFolder.equals(that.outFolder) : that.outFolder == null;
56+
if (isVerbose != config.isVerbose) return false;
57+
if (cliPath != null ? !cliPath.equals(config.cliPath) : config.cliPath != null) return false;
58+
return outFolder != null ? outFolder.equals(config.outFolder) : config.outFolder == null;
5159

5260
}
5361

5462
@Override
5563
public int hashCode() {
56-
int result = outFolder != null ? outFolder.hashCode() : 0;
64+
int result = cliPath != null ? cliPath.hashCode() : 0;
65+
result = 31 * result + (outFolder != null ? outFolder.hashCode() : 0);
5766
result = 31 * result + (isVerbose ? 1 : 0);
5867
return result;
5968
}
6069

6170
static JpylyzerConfig defaultInstance() {
62-
return new JpylyzerConfig(null, false);
71+
return new JpylyzerConfig(null, null, false);
6372
}
6473

65-
static JpylyzerConfig fromValues(final String outFolder, final boolean isVerbose) {
66-
return new JpylyzerConfig(outFolder, isVerbose);
74+
static JpylyzerConfig fromValues(final String cliPath, final String outFolder, final boolean isVerbose) {
75+
return new JpylyzerConfig(cliPath, outFolder, isVerbose);
6776
}
6877

6978
static String toXml(final JpylyzerConfig toConvert, Boolean prettyXml)

jpylyzer-plugin/src/main/java/org/verapdf/JpylyzerExtractor.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
import java.io.*;
1818
import java.net.URISyntaxException;
1919
import java.net.URL;
20-
import java.nio.file.Path;
21-
import java.nio.file.Paths;
20+
import java.nio.file.*;
2221
import java.util.ArrayList;
2322
import java.util.List;
2423

@@ -66,8 +65,14 @@ private File generateTempFile(byte[] stream, String name) throws IOException {
6665
return temp;
6766
}
6867

69-
private static void exec(List<FeatureTreeNode> nodes, JpylyzerConfig config, File temp) throws InterruptedException, FeatureParsingException, IOException, URISyntaxException {
70-
String scriptPath = getSystemIndependentPath("/jpylyzer-master/jpylyzer/jpylyzer.py");
68+
private void exec(List<FeatureTreeNode> nodes, JpylyzerConfig config, File temp) throws InterruptedException, FeatureParsingException, IOException, URISyntaxException {
69+
String scriptPath = getScriptPath(config);
70+
if (scriptPath == null) {
71+
FeatureTreeNode error = FeatureTreeNode.createRootNode("error");
72+
error.setValue("Can not obtain jpylyzer script or binary");
73+
nodes.add(error);
74+
return;
75+
}
7176
String[] args;
7277
if (config.isVerbose()) {
7378
args = new String[3];
@@ -85,8 +90,7 @@ private static void exec(List<FeatureTreeNode> nodes, JpylyzerConfig config, Fil
8590
FileOutputStream outStream = new FileOutputStream(out);
8691
byte[] buffer = new byte[1024];
8792
int bytesRead;
88-
while ((bytesRead = pr.getInputStream().read(buffer)) != -1)
89-
{
93+
while ((bytesRead = pr.getInputStream().read(buffer)) != -1) {
9094
outStream.write(buffer, 0, bytesRead);
9195
}
9296
pr.waitFor();
@@ -102,7 +106,7 @@ private static void exec(List<FeatureTreeNode> nodes, JpylyzerConfig config, Fil
102106
nodes.add(validationNode);
103107
} catch (ParserConfigurationException | SAXException | XPathExpressionException e) {
104108
FeatureTreeNode error = FeatureTreeNode.createRootNode("error");
105-
node.setValue("Error in obtaining validation result. Error message: " + e.getMessage());
109+
error.setValue("Error in obtaining validation result. Error message: " + e.getMessage());
106110
nodes.add(error);
107111
}
108112
}
@@ -139,11 +143,13 @@ private static File getTempFolder() {
139143
if (!tempFolder.exists()) {
140144
tempFolder.mkdir();
141145
}
146+
tempFolder.deleteOnExit();
142147
return tempFolder;
143148
}
144149

145150
private static File getOutFileInFolder(File folder) throws IOException {
146151
File out = File.createTempFile("veraPDF_Jpylyzer_Plugin_out", ".xml", folder);
152+
out.deleteOnExit();
147153
return out;
148154
}
149155

@@ -176,9 +182,18 @@ public String getDescription() {
176182
return "Extracts features of the Image using Jpylyzer";
177183
}
178184

179-
private static String getSystemIndependentPath(String path) throws URISyntaxException {
180-
URL resourceUrl = ClassLoader.class.getResource(path);
181-
Path resourcePath = Paths.get(resourceUrl.toURI());
182-
return resourcePath.toString();
185+
private String getScriptPath(JpylyzerConfig config) {
186+
String cliPath = config.getCliPath();
187+
if (cliPath == null) {
188+
cliPath = getFolderPath().toString() + "/jpylyzer-master/jpylyzer/jpylyzer.py";
189+
}
190+
191+
File cli = new File(cliPath);
192+
if (!(cli.exists() && cli.isFile())) {
193+
return null;
194+
}
195+
return cliPath;
183196
}
184197
}
198+
199+

jpylyzer-plugin/src/main/resources/jpylyzer-master/.gitignore

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

jpylyzer-plugin/src/main/resources/jpylyzer-master/.opf.yml

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

jpylyzer-plugin/src/main/resources/jpylyzer-master/.travis.yml

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

jpylyzer-plugin/src/main/resources/jpylyzer-master/BUILD_HOWTO_LINUX

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

jpylyzer-plugin/src/main/resources/jpylyzer-master/BUILD_HOWTO_WIN32

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

0 commit comments

Comments
 (0)