5353import java .io .IOException ;
5454import java .io .InputStream ;
5555import java .io .InputStreamReader ;
56+ import java .net .URISyntaxException ;
5657import java .nio .charset .Charset ;
58+ import java .nio .file .InvalidPathException ;
5759import java .util .ArrayList ;
5860import java .util .LinkedHashMap ;
5961import java .util .List ;
8385import org .knime .core .node .NodeSettingsRO ;
8486import org .knime .core .node .NodeSettingsWO ;
8587import org .knime .core .node .defaultnodesettings .SettingsModelString ;
88+ import org .knime .core .util .FileUtil ;
8689import org .knime .core .util .Pair ;
8790import org .knime .knip .base .data .img .ImgPlusCell ;
8891import org .knime .knip .base .data .img .ImgPlusCellFactory ;
@@ -302,16 +305,16 @@ private SingleCellFactory createResultCellFactory(final DataColumnSpec newColSpe
302305 public DataCell getCell (final DataRow row ) {
303306 RowKey key = row .getKey ();
304307 Pair <String , String > names = m_outFiles .get (key );
305- String outfile = names .getFirst ();
306- String source = names .getSecond ();
307308 DataCell cell ;
308309 try {
310+ String outfile = names .getFirst ();
311+ String source = names .getSecond ();
309312 ImgPlus <T > img = (ImgPlus <T >)imgOpener .getImg (outfile , 0 );
310313 img .setSource (source );
311314 img .setName (key + "_result" );
312315 cell = m_imgPlusCellFactory .createCell (img );
313316 } catch (Exception e ) {
314- cell = new MissingCell (outfile );
317+ cell = new MissingCell ("Error during execution" );
315318 }
316319 return cell ;
317320 }
@@ -344,7 +347,7 @@ private void readResultImages(final ImgPlusCellFactory factory, final DataContai
344347 container .addRowToTable (new DefaultRow (key , cells ));
345348 } catch (Exception e ) {
346349 imgOpener .close ();
347- throw new IllegalStateException ("Can't read image in Ilastik Headless Node at RowId" + key );
350+ throw new IllegalStateException ("Can't read image in Ilastik Headless Node at RowId: " + key );
348351 }
349352 });
350353 imgOpener .close ();
@@ -363,18 +366,30 @@ private void cleanUp(final File tmpDir) {
363366 /**
364367 * @throws IOException
365368 * @throws InterruptedException
369+ * @throws URISyntaxException
366370 */
367371 private boolean runIlastik (final String tmpDirPath , final List <String > inFiles )
368372 throws IOException , InterruptedException {
369373
370374 // get path of ilastik
371375 final String path = IlastikPreferencePage .getPath ();
372376
377+ String outpath ;
378+ try {
379+ outpath = FileUtil .resolveToPath (FileUtil .toURL (m_pathToIlastikProjectFileModel .getStringValue ()))
380+ .toAbsolutePath ().toString ();
381+ } catch (InvalidPathException | URISyntaxException e ) {
382+ throw new IllegalArgumentException ("The Path to the project file could not be resolved: " + e .getMessage ());
383+ }
384+ if (outpath == null ) {
385+ throw new IllegalArgumentException ("The Path to the project file could not be resolved." );
386+ }
387+
373388 // DO NOT TOUCH THIS ORDER!
374389 // inFiles.add(0, "/bin/bash");
375390 inFiles .add (0 , path );
376391 inFiles .add (1 , "--headless" );
377- inFiles .add (2 , "--project=" .concat (m_pathToIlastikProjectFileModel . getStringValue () ));
392+ inFiles .add (2 , "--project=" .concat (outpath ));
378393 inFiles .add (3 , "--output_format=tif" );
379394 inFiles .add (4 , "--output_filename_format=" .concat (tmpDirPath ).concat ("{nickname}_result" ));
380395
0 commit comments