@Override
	public GhidraScript getScriptInstance(ResourceFile sourceFile, PrintWriter writer)
			throws GhidraScriptLoadException {
		try (OSGiParallelLock lock = new OSGiParallelLock()) {
			Class<?> clazz = loadClass(sourceFile, writer);

			if (GhidraScript.class.isAssignableFrom(clazz)) {
				GhidraScript script = (GhidraScript) clazz.getDeclaredConstructor().newInstance();
				script.setSourceFile(sourceFile);
				return script;
			}

			throw new GhidraScriptLoadException(
				"Ghidra scripts in Java must extend " + GhidraScript.class.getName() + ". " +
					sourceFile.getName() + " does not.");
		}
		catch (ClassNotFoundException e) {
			throw new GhidraScriptLoadException("The class could not be found. " +
				"It must be the public class of the .java file: " + e.getMessage(), e);
		}
		catch (NoClassDefFoundError e) {
			throw new GhidraScriptLoadException("The class could not be found or loaded, " +
				"perhaps due to a previous initialization error: " + e.getMessage(), e);
		}
		catch (ExceptionInInitializerError e) {
			throw new GhidraScriptLoadException(
				"Error during class initialization: " + e.getException(), e.getException());
		}
		catch (InvocationTargetException e) {
			throw new GhidraScriptLoadException(
				"Error during class construction: " + e.getTargetException(),
				e.getTargetException());
		}
		catch (NoSuchMethodException e) {
			throw new GhidraScriptLoadException(
				"The default constructor does not exist: " + e.getMessage(), e);
		}
		catch (IllegalAccessException e) {
			throw new GhidraScriptLoadException(
				"The class or its default constructor is not accessible: " + e.getMessage(), e);
		}
		catch (Exception e) {
			throw new GhidraScriptLoadException("Unexpected error: " + e);
		}
	}
Get the {@link GhidraSourceBundle} containing the given source file, assuming it already
exists.

@param sourceFile the source file
@return the bundle
Ghidra/Features/Base/src/main/java/ghidra/app/script/JavaScriptProvider.java