CEGRcode/scriptmanager

Gradle Shadow minimize()

Opened this issue · 0 comments

owlang commented

The minimize function is great in that the JAR file was reduced from ~20M to ~10M. But this broke the saveChartAsPNG() command in scriptmanager.charts.HeatMap.java if you run the GUI version and check the "Output Statistics" box.

Affected code snippet adjusted to show where error is being thrown:

// Save PNG if output filepath given
if (output!=null) {
    int width = 640;
    int height = 480;
    try{ ChartUtils.saveChartAsPNG(output, chart, width, height); }
    catch( IOException ioe ){ ioe.printStackTrace(); }
    catch( Exception e ){ e.printStackTrace(); }
}

The stack trace printed when creating the error described above:

java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.jfree.chart.encoders.SunPNGEncoderAdapter
	at org.jfree.chart.encoders.ImageEncoderFactory.newInstance(ImageEncoderFactory.java:104)
	at org.jfree.chart.encoders.EncoderUtil.writeBufferedImage(EncoderUtil.java:132)
	at org.jfree.chart.ChartUtils.writeChartAsPNG(ChartUtils.java:143)
	at org.jfree.chart.ChartUtils.saveChartAsPNG(ChartUtils.java:268)
	at org.jfree.chart.ChartUtils.saveChartAsPNG(ChartUtils.java:243)
	at scriptmanager.charts.HeatMap.createCorrelationHeatmap(HeatMap.java:158)
	at scriptmanager.scripts.BAM_Statistics.BAMGenomeCorrelation.getBAMGenomeCorrelation(BAMGenomeCorrelation.java:111)
	at scriptmanager.window_interface.BAM_Statistics.BAMGenomeCorrelationOutput.run(BAMGenomeCorrelationOutput.java:78)
	at scriptmanager.window_interface.BAM_Statistics.BAMGenomeCorrelationWindow$Task.doInBackground(BAMGenomeCorrelationWindow.java:112)
	at scriptmanager.window_interface.BAM_Statistics.BAMGenomeCorrelationWindow$Task.doInBackground(BAMGenomeCorrelationWindow.java:80)
	at javax.swing.SwingWorker$1.call(SwingWorker.java:295)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at javax.swing.SwingWorker.run(SwingWorker.java:334)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750)
2023-04-07 12:50:15.564

...and the output PNG file is empty.

Re-running this with the minimize() function commented out resolves the issue (no error and correct PNG saved). Given the ClassNotFoundException type, I suspect the default execution of minimize does not pick up all the dependencies we want (in this case, org.jfree.chart.encoders.SunPNGEncoderAdapter is missing.