Commit f5455640 authored by Mihai Nita's avatar Mihai Nita

Resolved all try-with-resource warnings from Eclipse

parent 92861224
......@@ -40,16 +40,12 @@ public final class IntegrationtestUtils {
*/
public void writeXliff(List<Event> events, String path) {
XLIFFWriter w = new XLIFFWriter();
try {
try (XLIFFWriter w = new XLIFFWriter()) {
w.setOptions(LocaleId.ENGLISH, "UTF-8");
w.setOutput(path);
for (Event event : events) {
w.handleEvent(event);
}
} finally {
if (w != null)
w.close();
}
}
......@@ -154,27 +150,18 @@ public final class IntegrationtestUtils {
}
public static File asFile(Class<?> testClass, String rootPath, final String fileName) throws URISyntaxException, IOException {
JarFile jarFile = null;
try {
jarFile = new JarFile(rootPath);
} catch (IOException| SecurityException e) {}
if (jarFile != null) {
try {
final Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
final JarEntry entry = entries.nextElement();
final String name = entry.getName();
if (fileName.equals(name)) {
String fpath = Util.buildPath(rootPath, name);
return new File(fpath);
}
try (JarFile jarFile = new JarFile(rootPath)) {
final Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
final JarEntry entry = entries.nextElement();
final String name = entry.getName();
if (fileName.equals(name)) {
jarFile.close();
return new File(Util.buildPath(rootPath, name));
}
} finally {
jarFile.close();
}
} else {
}
} catch (IOException | SecurityException e) {
for (String fname : new File(rootPath).list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
......@@ -188,7 +175,7 @@ public final class IntegrationtestUtils {
return new File(fpath);
}
}
return null;
}
......
......@@ -157,15 +157,14 @@ public final class RoundTripUtils {
*/
public static boolean compareOriginalWithTarget(IFilter filter, String originalfile, String targetFile,
boolean includeSkeleton, boolean ignoreSkelWhitespace, boolean ignoreSegmentation, boolean ignoreFragmentWhitespace) {
RawDocument ord = new RawDocument(Util.toURI(originalfile), "UTF-8", LocaleId.ENGLISH, LocaleId.FRENCH);
RawDocument trd = new RawDocument(Util.toURI(targetFile), "UTF-8", LocaleId.ENGLISH, LocaleId.FRENCH);
List<Event> o = IntegrationtestUtils.getEvents(filter, ord);
List<Event> t = IntegrationtestUtils.getEvents(filter, trd);
boolean r = FilterTestDriver.compareEvents(o, t, includeSkeleton, ignoreSkelWhitespace, ignoreSegmentation, ignoreFragmentWhitespace);
ord.close();
trd.close();
o.clear();
t.clear();
return r;
try (RawDocument ord = new RawDocument(Util.toURI(originalfile), "UTF-8", LocaleId.ENGLISH, LocaleId.FRENCH);
RawDocument trd = new RawDocument(Util.toURI(targetFile), "UTF-8", LocaleId.ENGLISH, LocaleId.FRENCH)) {
List<Event> o = IntegrationtestUtils.getEvents(filter, ord);
List<Event> t = IntegrationtestUtils.getEvents(filter, trd);
boolean r = FilterTestDriver.compareEvents(o, t, includeSkeleton, ignoreSkelWhitespace, ignoreSegmentation, ignoreFragmentWhitespace);
o.clear();
t.clear();
return r;
}
}
}
......@@ -78,25 +78,25 @@ public class MultistepPipelineTestIT
driver.addStep(step4);
// Set the info for the input and output
RawDocument rawDoc = new RawDocument(getUri("test01.xml"), "UTF-8", locEN, locFR);
rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test01.xml"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("test02.xml"), "UTF-8", locEN, locFR);
rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test02.xml"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("test03.xml"), "UTF-8", locEN, locFR);
rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test03.xml"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("test04.xml"), "UTF-8", locEN, locFR);
rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test04.xml"), "UTF-8");
rawDoc.close();
try (RawDocument rawDoc = new RawDocument(getUri("test01.xml"), "UTF-8", locEN, locFR)) {
rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test01.xml"), "UTF-8");
}
try (RawDocument rawDoc = new RawDocument(getUri("test02.xml"), "UTF-8", locEN, locFR)) {
rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test02.xml"), "UTF-8");
}
try (RawDocument rawDoc = new RawDocument(getUri("test03.xml"), "UTF-8", locEN, locFR)) {
rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test03.xml"), "UTF-8");
}
try (RawDocument rawDoc = new RawDocument(getUri("test04.xml"), "UTF-8", locEN, locFR)) {
rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test04.xml"), "UTF-8");
}
driver.processBatch();
......@@ -174,23 +174,23 @@ public class MultistepPipelineTestIT
copySourceToTargetStep.setTargetLocale(locEUES);
driver.addStep(copySourceToTargetStep);
driver.addStep(new FilterEventsWriterStep());
// Set the info for the input and output
RawDocument rawDoc = new RawDocument(getUri("Test01.properties"), "UTF-8", locEN, locEUES);
rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test01.properties"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("Test02.properties"), "UTF-8", locEN, locEUES);
rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test02.properties"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("Test03.properties"), "UTF-8", locEN, locEUES);
rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test03.properties"), "UTF-8");
rawDoc.close();
try (RawDocument rawDoc = new RawDocument(getUri("Test01.properties"), "UTF-8", locEN, locEUES)) {
rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test01.properties"), "UTF-8");
}
try (RawDocument rawDoc = new RawDocument(getUri("Test02.properties"), "UTF-8", locEN, locEUES)) {
rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test02.properties"), "UTF-8");
}
try (RawDocument rawDoc = new RawDocument(getUri("Test03.properties"), "UTF-8", locEN, locEUES)) {
rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test03.properties"), "UTF-8");
}
driver.processBatch();
assertTrue((new File(getOutputUri("Test01.properties"))).exists());
......
......@@ -10,8 +10,7 @@ import net.sf.okapi.filters.html.HtmlFilter;
public final class PipelineTestUtil
{
public static String getFirstTUSource (RawDocument rd) {
IFilter filter = new HtmlFilter();
try {
try (IFilter filter = new HtmlFilter()) {
filter.open(rd);
Event event;
while ( filter.hasNext() ) {
......@@ -22,9 +21,6 @@ public final class PipelineTestUtil
}
}
}
finally {
if ( filter != null ) filter.close();
}
return null;
}
}
......@@ -39,13 +39,13 @@ public class QueryManagerTestIT
String rootDir = Util.getDirectoryName(url.toURI().getPath());
// create local pensieve TM
TmxFilter tmxFilter = new TmxFilter();
ITmWriter tmWriter = TmWriterFactory.createFileBasedTmWriter(rootDir, true);
OkapiTmxImporter tmxHandler = new OkapiTmxImporter(locENUS, tmxFilter);
tmxHandler.importTmx(url.toURI(), locFRFR, tmWriter);
tmxFilter.close();
tmWriter.close();
try (TmxFilter tmxFilter = new TmxFilter()) {
ITmWriter tmWriter = TmWriterFactory.createFileBasedTmWriter(rootDir, true);
OkapiTmxImporter tmxHandler = new OkapiTmxImporter(locENUS, tmxFilter);
tmxHandler.importTmx(url.toURI(), locFRFR, tmWriter);
tmWriter.close();
}
// load up connectors in QueryManager
qm = new QueryManager();
......
......@@ -35,12 +35,12 @@ public class SimpleDocxMemoryLeakTestIT
@SuppressWarnings("resource")
RawDocument rd = new RawDocument(getUri("/docx/OpenXML_text_reference_v1_2.docx"), "UTF-8", locEN);
rd.setFilterConfigId("okf_openxml");
OpenXMLFilter f = new OpenXMLFilter();
f.open(rd);
while(f.hasNext()) {
f.next();
try (OpenXMLFilter f = new OpenXMLFilter()) {
f.open(rd);
while(f.hasNext()) {
f.next();
}
}
f.close();
}
}
}
......@@ -80,21 +80,15 @@ public class PropertyXliffCompareIT
String xliffPrevious = XliffCompareUtils.CURRENT_XLIFF_ROOT + "property/" + sd + f + ".xliff";
RoundTripUtils.extract(LocaleId.ENGLISH, LocaleId.FRENCH, original, xliff, configName, customConfigPath, segment);
XLIFFFilter xf = new XLIFFFilter();
RawDocument ox = new RawDocument(Util.toURI(xliff), StandardCharsets.UTF_8.name(), LocaleId.ENGLISH, LocaleId.FRENCH);
List<Event> oe = IntegrationtestUtils.getTextUnitEvents(xf, ox);
RawDocument px = new RawDocument(Util.toURI(xliffPrevious), StandardCharsets.UTF_8.name(), LocaleId.ENGLISH, LocaleId.FRENCH);
List<Event> pe = IntegrationtestUtils.getTextUnitEvents(xf, px);
try {
try (XLIFFFilter xf = new XLIFFFilter();
RawDocument ox = new RawDocument(Util.toURI(xliff), StandardCharsets.UTF_8.name(), LocaleId.ENGLISH, LocaleId.FRENCH);
RawDocument px = new RawDocument(Util.toURI(xliffPrevious), StandardCharsets.UTF_8.name(), LocaleId.ENGLISH, LocaleId.FRENCH)) {
List<Event> oe = IntegrationtestUtils.getTextUnitEvents(xf, ox);
List<Event> pe = IntegrationtestUtils.getTextUnitEvents(xf, px);
assertTrue("Compare Events: " + f, FilterTestDriver.compareEvents(oe, pe));
} catch(Throwable e) {
errCol.addError(e);
} finally {
ox.close();
px.close();
xf.close();
}
}
}
......@@ -80,21 +80,15 @@ public class RegexXliffCompareIT
String xliffPrevious = XliffCompareUtils.CURRENT_XLIFF_ROOT + "regex/" + sd + f + ".xliff";
RoundTripUtils.extract(LocaleId.ENGLISH, LocaleId.FRENCH, original, xliff, configName, customConfigPath, segment);
XLIFFFilter xf = new XLIFFFilter();
RawDocument ox = new RawDocument(Util.toURI(xliff), StandardCharsets.UTF_8.name(), LocaleId.ENGLISH, LocaleId.FRENCH);
List<Event> oe = IntegrationtestUtils.getTextUnitEvents(xf, ox);
RawDocument px = new RawDocument(Util.toURI(xliffPrevious), StandardCharsets.UTF_8.name(), LocaleId.ENGLISH, LocaleId.FRENCH);
List<Event> pe = IntegrationtestUtils.getTextUnitEvents(xf, px);
try {
try (XLIFFFilter xf = new XLIFFFilter();
RawDocument ox = new RawDocument(Util.toURI(xliff), StandardCharsets.UTF_8.name(), LocaleId.ENGLISH, LocaleId.FRENCH);
RawDocument px = new RawDocument(Util.toURI(xliffPrevious), StandardCharsets.UTF_8.name(), LocaleId.ENGLISH, LocaleId.FRENCH)) {
List<Event> oe = IntegrationtestUtils.getTextUnitEvents(xf, ox);
List<Event> pe = IntegrationtestUtils.getTextUnitEvents(xf, px);
assertTrue("Compare Events: " + f, FilterTestDriver.compareEvents(oe, pe));
} catch(Throwable e) {
errCol.addError(e);
} finally {
ox.close();
px.close();
xf.close();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment