Skip to content

Commit

Permalink
Work around classpath deletion woes of #88
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrueden committed Jul 10, 2020
1 parent 8caa290 commit 372ccff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/imagej/updater/FilesCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public class FilesCollection extends LinkedHashMap<String, FileObject>
implements Iterable<FileObject>
{

static {
XMLFileWriter.prepare();
}

public final static String DEFAULT_UPDATE_SITE = "ImageJ";
private File imagejRoot;
public final LogService log;
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/net/imagej/updater/XMLFileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,32 @@ public void write(final OutputStream out, final boolean local)
out.close();
}

/**
* HACK: Invoke Xalan XML writing classes early, to ensure XML writing
* infrastructure is loaded before the Updater deletes classpath elements.
* <p>
* See <a href=
* "https://github.com/imagej/imagej-updater/issues/88">imagej/imagej-updater#88</a>.
*/
static void prepare() {
final StreamResult streamResult =
new StreamResult(new DTDInserter(new ByteArrayOutputStream()));
final SAXTransformerFactory tf =
(SAXTransformerFactory) TransformerFactory.newInstance();

try {
final TransformerHandler h = tf.newTransformerHandler();
final Transformer serializer = h.getTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(XALAN_INDENT_AMOUNT, "4");
h.setResult(streamResult);
}
catch (final TransformerConfigurationException exc) {
throw new RuntimeException(exc);
}
}

protected void writeSingle(final boolean local, final AttributesImpl attr,
final FileObject file, final long timestampObsolete) throws SAXException {
attr.clear();
Expand Down

0 comments on commit 372ccff

Please sign in to comment.