Skip to content

Commit f09a0a8

Browse files
Unified the dependency of jakarta.activation to use (#1917)
1 parent 485fd32 commit f09a0a8

File tree

6 files changed

+142
-106
lines changed

6 files changed

+142
-106
lines changed

components/basic-transformers/src/main/java/org/datacleaner/beans/codec/HashTransformer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.security.MessageDigest;
2323
import java.security.NoSuchAlgorithmException;
2424
import java.util.StringJoiner;
25-
import javax.xml.bind.DatatypeConverter;
25+
2626
import javax.inject.Named;
2727

2828
import org.datacleaner.api.Categorized;
@@ -34,6 +34,8 @@
3434
import org.datacleaner.api.Transformer;
3535
import org.datacleaner.components.categories.EncodingCategory;
3636

37+
import jakarta.xml.bind.DatatypeConverter;
38+
3739
@Named("Hash value")
3840
@Description("It creates a hash from specified input. ")
3941
@Categorized(EncodingCategory.class)

desktop/ui/src/main/java/org/datacleaner/cli/CliRunner.java

Lines changed: 88 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ public final class CliRunner implements Closeable {
8080
private final boolean _closeOut;
8181

8282
/**
83-
* Alternative constructor that will specifically specifies the output
84-
* writer. Should be used only for testing, since normally the CliArguments
85-
* should be used to decide which outputwriter to use
83+
* Alternative constructor that will specifically specifies the output writer. Should be used only for testing,
84+
* since normally the CliArguments should be used to decide which outputwriter to use
8685
*
8786
* @param arguments
8887
* @param writer
@@ -234,29 +233,32 @@ private void printColumns(final DataCleanerConfiguration configuration) {
234233
System.err.println("No such datastore: " + datastoreName);
235234
} else {
236235
final DatastoreConnection con = ds.openConnection();
237-
final DataContext dc = con.getDataContext();
238-
final Schema schema;
239-
if (schemaName == null) {
240-
schema = dc.getDefaultSchema();
241-
} else {
242-
schema = dc.getSchemaByName(schemaName);
243-
}
244-
if (schema == null) {
245-
System.err.println("No such schema: " + schemaName);
246-
} else {
247-
final Table table = schema.getTableByName(tableName);
248-
if (table == null) {
249-
write("No such table: " + tableName);
236+
try {
237+
final DataContext dc = con.getDataContext();
238+
final Schema schema;
239+
if (schemaName == null) {
240+
schema = dc.getDefaultSchema();
250241
} else {
251-
final List<String> columnNames = table.getColumnNames();
252-
write("Columns:");
253-
write("--------");
254-
for (final String columnName : columnNames) {
255-
write(columnName);
242+
schema = dc.getSchemaByName(schemaName);
243+
}
244+
if (schema == null) {
245+
System.err.println("No such schema: " + schemaName);
246+
} else {
247+
final Table table = schema.getTableByName(tableName);
248+
if (table == null) {
249+
write("No such table: " + tableName);
250+
} else {
251+
final List<String> columnNames = table.getColumnNames();
252+
write("Columns:");
253+
write("--------");
254+
for (final String columnName : columnNames) {
255+
write(columnName);
256+
}
256257
}
257258
}
259+
} finally {
260+
con.close();
258261
}
259-
con.close();
260262
}
261263
}
262264
}
@@ -273,28 +275,31 @@ private void printTables(final DataCleanerConfiguration configuration) {
273275
System.err.println("No such datastore: " + datastoreName);
274276
} else {
275277
final DatastoreConnection con = ds.openConnection();
276-
final DataContext dc = con.getDataContext();
277-
final Schema schema;
278-
if (schemaName == null) {
279-
schema = dc.getDefaultSchema();
280-
} else {
281-
schema = dc.getSchemaByName(schemaName);
282-
}
283-
if (schema == null) {
284-
System.err.println("No such schema: " + schemaName);
285-
} else {
286-
final List<String> tableNames = schema.getTableNames();
287-
if (tableNames == null || tableNames.isEmpty()) {
288-
System.err.println("No tables in schema!");
278+
try {
279+
final DataContext dc = con.getDataContext();
280+
final Schema schema;
281+
if (schemaName == null) {
282+
schema = dc.getDefaultSchema();
289283
} else {
290-
write("Tables:");
291-
write("-------");
292-
for (final String tableName : tableNames) {
293-
write(tableName);
284+
schema = dc.getSchemaByName(schemaName);
285+
}
286+
if (schema == null) {
287+
System.err.println("No such schema: " + schemaName);
288+
} else {
289+
final List<String> tableNames = schema.getTableNames();
290+
if (tableNames == null || tableNames.isEmpty()) {
291+
System.err.println("No tables in schema!");
292+
} else {
293+
write("Tables:");
294+
write("-------");
295+
for (final String tableName : tableNames) {
296+
write(tableName);
297+
}
294298
}
295299
}
300+
} finally {
301+
con.close();
296302
}
297-
con.close();
298303
}
299304
}
300305
}
@@ -310,17 +315,20 @@ private void printSchemas(final DataCleanerConfiguration configuration) {
310315
System.err.println("No such datastore: " + datastoreName);
311316
} else {
312317
final DatastoreConnection con = ds.openConnection();
313-
final List<String> schemaNames = con.getDataContext().getSchemaNames();
314-
if (schemaNames == null || schemaNames.isEmpty()) {
315-
write("No schemas in datastore!");
316-
} else {
317-
write("Schemas:");
318-
write("--------");
319-
for (final String schemaName : schemaNames) {
320-
write(schemaName);
318+
try {
319+
final List<String> schemaNames = con.getDataContext().getSchemaNames();
320+
if (schemaNames == null || schemaNames.isEmpty()) {
321+
write("No schemas in datastore!");
322+
} else {
323+
write("Schemas:");
324+
write("--------");
325+
for (final String schemaName : schemaNames) {
326+
write(schemaName);
327+
}
321328
}
329+
} finally {
330+
con.close();
322331
}
323-
con.close();
324332
}
325333
}
326334
}
@@ -367,30 +375,34 @@ protected void runJob(final DataCleanerConfiguration configuration) throws Throw
367375
FileHelper.safeClose(inputStream);
368376
}
369377

370-
final AnalysisRunner runner = new AnalysisRunnerImpl(configuration, new CliProgressAnalysisListener());
371-
final AnalysisResultFuture resultFuture = runner.run(analysisJobBuilder.toAnalysisJob());
378+
try {
379+
final AnalysisRunner runner = new AnalysisRunnerImpl(configuration, new CliProgressAnalysisListener());
380+
final AnalysisResultFuture resultFuture = runner.run(analysisJobBuilder.toAnalysisJob());
372381

373-
resultFuture.await();
382+
resultFuture.await();
374383

375-
if (resultFuture.isSuccessful()) {
376-
final CliOutputType outputType = _arguments.getOutputType();
377-
final AnalysisResultWriter writer = outputType.createWriter();
378-
writer.write(resultFuture, configuration, _writerRef, _outputStreamRef);
379-
} else {
380-
write("ERROR!");
381-
write("------");
384+
if (resultFuture.isSuccessful()) {
385+
final CliOutputType outputType = _arguments.getOutputType();
386+
final AnalysisResultWriter writer = outputType.createWriter();
387+
writer.write(resultFuture, configuration, _writerRef, _outputStreamRef);
388+
} else {
389+
write("ERROR!");
390+
write("------");
382391

383-
final List<Throwable> errors = resultFuture.getErrors();
384-
write(errors.size() + " error(s) occurred while executing the job:");
392+
final List<Throwable> errors = resultFuture.getErrors();
393+
write(errors.size() + " error(s) occurred while executing the job:");
385394

386-
for (final Throwable throwable : errors) {
387-
write("------");
388-
final StringWriter stringWriter = new StringWriter();
389-
throwable.printStackTrace(new PrintWriter(stringWriter));
390-
write(stringWriter.toString());
391-
}
395+
for (final Throwable throwable : errors) {
396+
write("------");
397+
final StringWriter stringWriter = new StringWriter();
398+
throwable.printStackTrace(new PrintWriter(stringWriter));
399+
write(stringWriter.toString());
400+
}
392401

393-
throw errors.get(0);
402+
throw errors.get(0);
403+
}
404+
} finally {
405+
analysisJobBuilder.close();
394406
}
395407
}
396408
}
@@ -441,22 +453,22 @@ protected void printBeanDescriptors(final Collection<? extends ComponentDescript
441453
final ConfiguredPropertyDescriptor propertyForInput = propertiesForInput.iterator().next();
442454
if (propertyForInput != null) {
443455
if (propertyForInput.isArray()) {
444-
write(" - Consumes multiple input columns (type: " + propertyForInput.getTypeArgument(0)
445-
.getSimpleName() + ")");
456+
write(" - Consumes multiple input columns (type: "
457+
+ propertyForInput.getTypeArgument(0).getSimpleName() + ")");
446458
} else {
447-
write(" - Consumes a single input column (type: " + propertyForInput.getTypeArgument(0)
448-
.getSimpleName() + ")");
459+
write(" - Consumes a single input column (type: "
460+
+ propertyForInput.getTypeArgument(0).getSimpleName() + ")");
449461
}
450462
}
451463
} else {
452464
write(" - Consumes " + propertiesForInput.size() + " named inputs");
453465
for (final ConfiguredPropertyDescriptor propertyForInput : propertiesForInput) {
454466
if (propertyForInput.isArray()) {
455-
write(" Input columns: " + propertyForInput.getName() + " (type: " + propertyForInput
456-
.getTypeArgument(0).getSimpleName() + ")");
467+
write(" Input columns: " + propertyForInput.getName() + " (type: "
468+
+ propertyForInput.getTypeArgument(0).getSimpleName() + ")");
457469
} else {
458-
write(" Input column: " + propertyForInput.getName() + " (type: " + propertyForInput
459-
.getTypeArgument(0).getSimpleName() + ")");
470+
write(" Input column: " + propertyForInput.getName() + " (type: "
471+
+ propertyForInput.getTypeArgument(0).getSimpleName() + ")");
460472
}
461473
}
462474
}

desktop/ui/src/test/java/org/datacleaner/cli/MainTest.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
import org.apache.commons.lang.SerializationUtils;
3434
import org.apache.metamodel.util.FileHelper;
3535
import org.datacleaner.result.AnalysisResult;
36+
import org.datacleaner.test.TestHelper;
3637
import org.xml.sax.Attributes;
3738
import org.xml.sax.ErrorHandler;
3839
import org.xml.sax.InputSource;
3940
import org.xml.sax.SAXException;
4041
import org.xml.sax.SAXParseException;
4142
import org.xml.sax.helpers.DefaultHandler;
4243

44+
import com.google.common.base.Joiner;
4345
import com.google.common.base.Splitter;
4446

4547
import junit.framework.TestCase;
@@ -57,7 +59,7 @@ protected void setUp() throws Exception {
5759
_originalSysOut = System.out;
5860
useAsSystemOut(_stringWriter);
5961
}
60-
62+
6163
private void useAsSystemOut(final StringWriter stringWriter) {
6264
final OutputStream out = new OutputStream() {
6365
@Override
@@ -73,11 +75,21 @@ protected void tearDown() throws Exception {
7375
super.tearDown();
7476
System.setOut(_originalSysOut);
7577
}
78+
79+
private String getOutput() {
80+
final String out = _stringWriter.toString().replaceAll("\r\n", "\n");
81+
// disregard any line that looks like unrelated Finalizer logging output
82+
final List<String> lines = Splitter.on('\n').splitToList(out);
83+
final Object[] parts = lines.stream().filter(line -> {
84+
return line.indexOf("[Finalizer] ") == -1;
85+
}).toArray();
86+
return Joiner.on('\n').join(parts);
87+
}
7688

7789
public void testUsage() throws Throwable {
7890
Main.main("-usage".split(" "));
7991

80-
final String out1 = _stringWriter.toString();
92+
final String out1 = getOutput();
8193

8294
final String[] lines = out1.split("\n");
8395

@@ -113,28 +125,28 @@ public void testUsage() throws Throwable {
113125
useAsSystemOut(_stringWriter);
114126
Main.main(new String[0]);
115127

116-
final String out2 = _stringWriter.toString();
128+
final String out2 = getOutput();
117129
assertEquals(out1, out2);
118130
}
119131

120132
public void testListDatastores() throws Throwable {
121133
Main.main("-conf src/test/resources/cli-examples/conf.xml -list DATASTORES".split(" "));
122134

123-
final String out = _stringWriter.toString().replaceAll("\r\n", "\n");
135+
final String out = getOutput();
124136
assertEquals("Datastores:\n-----------\nall_datastores\nemployees_csv\norderdb\n", out);
125137
}
126138

127139
public void testListSchemas() throws Throwable {
128140
Main.main("-conf src/test/resources/cli-examples/conf.xml -ds orderdb -list SCHEMAS".split(" "));
129141

130-
final String out = _stringWriter.toString().replaceAll("\r\n", "\n");
142+
final String out = getOutput();
131143
assertEquals("Schemas:\n" + "--------\n" + "INFORMATION_SCHEMA\n" + "PUBLIC\n", out);
132144
}
133145

134146
public void testListTables() throws Throwable {
135147
Main.main("-conf src/test/resources/cli-examples/conf.xml -ds orderdb -schema PUBLIC -list TABLES".split(" "));
136148

137-
final String out = _stringWriter.toString().replaceAll("\r\n", "\n");
149+
final String out = getOutput();
138150
assertEquals(
139151
"Tables:\n-------\nCUSTOMERS\nEMPLOYEES\nOFFICES\nORDERDETAILS\nORDERFACT\nORDERS\nPAYMENTS\nPRODUCTS\n",
140152
out);
@@ -145,7 +157,7 @@ public void testListColumns() throws Throwable {
145157
"-conf src/test/resources/cli-examples/conf.xml -ds orderdb -schema PUBLIC -table EMPLOYEES -list COLUMNS"
146158
.split(" "));
147159

148-
final String out = _stringWriter.toString().replaceAll("\r\n", "\n");
160+
final String out = getOutput();
149161
assertEquals(
150162
"Columns:\n--------\nEMPLOYEENUMBER\nLASTNAME\nFIRSTNAME\nEXTENSION\nEMAIL\nOFFICECODE\nREPORTSTO\nJOBTITLE\n",
151163
out);
@@ -154,32 +166,32 @@ public void testListColumns() throws Throwable {
154166
public void testListTransformers() throws Throwable {
155167
Main.main("-conf src/test/resources/cli-examples/conf.xml -list TRANSFORMERS".split(" "));
156168

157-
final String out = _stringWriter.toString().replaceAll("\r\n", "\n");
169+
final String out = getOutput();
158170
final String[] lines = out.split("\n");
159171

160172
assertEquals("Transformers:", lines[0]);
161173

162-
assertTrue(out, out.indexOf("name: Email standardizer") != -1);
163-
assertTrue(out, out.indexOf(" - Consumes a single input column (type: String)") != -1);
174+
TestHelper.assertStringContains(out, "name: Email standardizer");
175+
TestHelper.assertStringContains(out, " - Consumes a single input column (type: String)");
164176
}
165177

166178
public void testListFilters() throws Throwable {
167179
Main.main("-conf src/test/resources/cli-examples/conf.xml -list FILTERS".split(" "));
168180

169-
final String out = _stringWriter.toString().replaceAll("\r\n", "\n");
181+
final String out = getOutput();
170182
final String[] lines = out.split("\n");
171183

172184
assertEquals("Filters:", lines[0]);
173185

174-
assertTrue(out.indexOf("name: Null check") != -1);
175-
assertTrue(out.indexOf("- Outcome: NOT_NULL") != -1);
176-
assertTrue(out.indexOf("- Outcome: NULL") != -1);
186+
TestHelper.assertStringContains(out, "name: Null check");
187+
TestHelper.assertStringContains(out, "- Outcome: NOT_NULL");
188+
TestHelper.assertStringContains(out, "- Outcome: NULL");
177189
}
178190

179191
public void testListAnalyzers() throws Throwable {
180192
Main.main("-conf src/test/resources/cli-examples/conf.xml -list ANALYZERS".split(" "));
181193

182-
final String out = _stringWriter.toString().replaceAll("\r\n", "\n");
194+
final String out = getOutput();
183195
final String[] lines = out.split("\n");
184196

185197
assertEquals("Analyzers:", lines[0]);
@@ -193,7 +205,7 @@ public void testExampleEmployeesJob() throws Throwable {
193205
"-conf src/test/resources/cli-examples/conf.xml -job src/test/resources/cli-examples/employees_job.xml"
194206
.split(" "));
195207

196-
final String out = _stringWriter.toString().replaceAll("\r\n", "\n");
208+
final String out = getOutput();
197209
final List<String> lines = Splitter.on('\n').splitToList(out);
198210

199211
assertTrue(out, out.indexOf("- Value count (company.com): 4") != -1);

desktop/ui/src/test/java/org/datacleaner/widgets/properties/TableNamePropertyWidgetTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public void testTwoWidgetsForSameProperty() throws Exception {
112112
assertEquals("bar", tableWidget1.getTable().getName());
113113
assertEquals("bar", tableWidget2.getTable().getName());
114114

115+
// clean up
115116
analysisJobBuilder.close();
117+
datastoreWidget1.onPanelRemove();
118+
datastoreWidget2.onPanelRemove();
116119
}
117120

118121
private PropertyWidgetCollection createPropertyWidgetCollection(

0 commit comments

Comments
 (0)