<commit_before>/*
 * Please run this Javascript via
 *
 *    Macros>Evaluate Javascript
 *
 * or by hitting Ctrl+J (on MacOSX, Apple+J).
 *
 * If this fails, please call Edit>Select All,
 * Edit>Copy, switch to the main window call
 * File>New>Script..., Edit>Paste, select
 * Language>JavaScript and then hit the Run
 * button.
 */

importClass(Packages.java.io.File);
importClass(Packages.java.lang.System);
importClass(Packages.java.net.URL);
importClass(Packages.java.net.URLClassLoader);
importClass(Packages.java.util.regex.Pattern);

baseURL = 'http://update.imagej.net/jars/';
jars = [
	'imagej-ui-swing-0.5.0.jar-20140711220647',
	'imagej-plugins-uploader-webdav-0.1.1.jar-20140516211031',
	'imagej-updater-0.5.0.jar-20140721212623',
	'scijava-common-2.27.0.jar-20140711220647',
	'imagej-common-0.8.0.jar-20140701184314',
	'eventbus-1.4.jar-20120404210913',
	'gentyref-1.1.0.jar-20140516211031'
];

isCommandLine = typeof arguments != 'undefined';

urls = [];
remoteCount = localCount = 0;
pattern = Pattern.compile("^(.*/)?([^/]*\\.jar)-[0-9]+$");
for (i = 0; i < jars.length; i++) {
	if (isCommandLine && (matcher = pattern.matcher(jars[i])).matches()) {
		file = new File("jars/" + matcher.group(2));
		if (file.exists()) {
			urls[i] = file.toURI().toURL();
			localCount++;
			continue;
		}
	}
	urls[i] = new URL(baseURL + jars[i]);
	remoteCount++;
}

importClass(Packages.java.lang.ClassLoader);
parent = ClassLoader.getSystemClassLoader().getParent();
loader = new URLClassLoader(urls, parent);

if (isCommandLine) {
	importClass(Packages.java.lang.System);

	var IJ = {
		debugMode: false,

		getDirectory: function(label) {
			// command-line: default to current directory
			return new File("").getAbsolutePath();
		},

		showStatus: function(message) {
			print(message + "\n");
		},

		error: function(message) {
			print(message + "\n");
		},

		handleException: function(exception) {
			exception.printStackTrace();
		}
	}

	var updaterClassName = "net.imagej.updater.CommandLine";
} else {
	try {
		importClass(Packages.ij.IJ);
	} catch (e) {
		// ignore; this is a funny PluginClassLoader problem
	}

	if (typeof IJ == 'undefined') {
		importClass(Packages.java.lang.Thread);
		var IJ = Thread.currentThread().getContextClassLoader().loadClass('ij.IJ').newInstance();
	}

	var updaterClassName = "net.imagej.ui.swing.updater.ImageJUpdater";
}


// make sure that the system property 'imagej.dir' is set correctly
if (System.getProperty("imagej.dir") == null) {
	imagejDir = System.getProperty("ij.dir");
	if (imagejDir == null) {
		imagejDir = IJ.getDirectory("imagej");
	}
	if (imagejDir != null) {
		if (imagejDir.endsWith("/jars/") || imagejDir.endsWith("\\jars\\"))
			imagejDir = imagejDir.substring(0, imagejDir.length() - 5);
	} else {
		url = IJ.getClassLoader().loadClass("ij.IJ").getResource("/ij/IJ.class").toString();<commit_msg>Allow bootstrap.js to be run with a GUI but without ImageJ 1.x<commit_after>/*
 * Please run this Javascript via
 *
 *    Macros>Evaluate Javascript
 *
 * or by hitting Ctrl+J (on MacOSX, Apple+J).
 *
 * If this fails, please call Edit>Select All,
 * Edit>Copy, switch to the main window call
 * File>New>Script..., Edit>Paste, select
 * Language>JavaScript and then hit the Run
 * button.
 */

importClass(Packages.java.io.File);
importClass(Packages.java.lang.System);
importClass(Packages.java.net.URL);
importClass(Packages.java.net.URLClassLoader);
importClass(Packages.java.util.regex.Pattern);

baseURL = 'http://update.imagej.net/jars/';
jars = [
	'imagej-ui-swing-0.5.0.jar-20140711220647',
	'imagej-plugins-uploader-webdav-0.1.1.jar-20140516211031',
	'imagej-updater-0.5.0.jar-20140721212623',
	'scijava-common-2.27.0.jar-20140711220647',
	'imagej-common-0.8.0.jar-20140701184314',
	'eventbus-1.4.jar-20120404210913',
	'gentyref-1.1.0.jar-20140516211031'
];

isCommandLine = typeof arguments != 'undefined';

urls = [];
remoteCount = localCount = 0;
pattern = Pattern.compile("^(.*/)?([^/]*\\.jar)-[0-9]+$");
for (i = 0; i < jars.length; i++) {
	if (isCommandLine && (matcher = pattern.matcher(jars[i])).matches()) {
		file = new File("jars/" + matcher.group(2));
		if (file.exists()) {
			urls[i] = file.toURI().toURL();
			localCount++;
			continue;
		}
	}
	urls[i] = new URL(baseURL + jars[i]);
	remoteCount++;
}

importClass(Packages.java.lang.ClassLoader);
parent = ClassLoader.getSystemClassLoader().getParent();
loader = new URLClassLoader(urls, parent);

if (isCommandLine) {
	importClass(Packages.java.lang.System);

	var IJ = {
		debugMode: false,

		getDirectory: function(label) {
			// command-line: default to current directory
			return new File("").getAbsolutePath();
		},

		showStatus: function(message) {
			print(message + "\n");
		},

		error: function(message) {
			print(message + "\n");
		},

		handleException: function(exception) {
			exception.printStackTrace();
		}
	}

	var updaterClassName = "net.imagej.updater.CommandLine";
} else {
	try {
		importClass(Packages.ij.IJ);
	} catch (e) {
		// ignore; this is a funny PluginClassLoader problem
	}

	if (typeof IJ == 'undefined') {
		importClass(Packages.java.lang.Thread);
		var loader2 = Thread.currentThread().getContextClassLoader();
		try {
			var IJ = loader2.loadClass('ij.IJ').newInstance();
		} catch (e) {
			importClass(Packages.java.awt.BorderLayout);
			importClass(Packages.java.io.ByteArrayOutputStream);
			importClass(Packages.java.io.PrintStream);
			importClass(Packages.java.lang.System);
			importClass(Packages.javax.swing.JFrame);
			importClass(Packages.javax.swing.JTextArea);

			var frame = new JFrame("Remote ImageJ updater");
			var text = new JTextArea(20, 40);
			text.setEditable(false);
			text.setLineWrap(true);
			frame.getContentPane().add(text, BorderLayout.NORTH);
			frame.pack();
			frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

			print = function(message) {
				frame.setVisible(true);
				text.append(message + "\n");
			};

			var IJ = {
				debugMode: "true".equalsIgnoreCase(System.getProperty("scijava.log.level")),

				getDirectory: function(label) {
					// default to current directory
					return new File("").getAbsolutePath();
				},

				showStatus: function(message) {
					print(message);
				},

				error: function(message) {
					print(message);
				},

				handleException: function(exception) {
					var buffer = new ByteArrayOutputStream();
					new Throwable().printStackTrace(new PrintStream(buffer));
					print(buffer.toString("UTF-8"));
				}
			}
		}
	}

	var updaterClassName = "net.imagej.ui.swing.updater.ImageJUpdater";
}


// make sure that the system property 'imagej.dir' is set correctly
if (System.getProperty("imagej.dir") == null) {
	imagejDir = System.getProperty("ij.dir");
	if (imagejDir == null) {
		imagejDir = IJ.getDirectory("imagej");
	}
	if (imagejDir != null) {
		if (imagejDir.endsWith("/jars/") || imagejDir.endsWith("\\jars\\"))
			imagejDir = imagejDir.substring(0, imagejDir.length() - 5);
	} else {
		url = IJ.getClassLoader().loadClass("ij.IJ").getResource("/ij/IJ.class").toString();
{'fraction_non_alphanumeric': 0.16969353007945517, 'fraction_numerical': 0.03688989784335982, 'mean_word_length': 4.1678885630498534, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '180907', 'n_tokens_mistral': 2836, 'n_tokens_neox': 2488, 'n_words': 439}