All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.disney.groovity.compile.GroovityClassLoader Maven / Gradle / Ivy

There is a newer version: 2.1.0-beta.1
Show newest version
/*******************************************************************************
 * © 2018 Disney | ABC Television Group
 *
 * Licensed under the Apache License, Version 2.0 (the "Apache License")
 * with the following modification; you may not use this file except in
 * compliance with the Apache License and the following modification to it:
 * Section 6. Trademarks. is deleted and replaced with:
 *
 * 6. Trademarks. This License does not grant permission to use the trade
 *     names, trademarks, service marks, or product names of the Licensor
 *     and its affiliates, except as required to comply with Section 4(c) of
 *     the License and to reproduce the content of the NOTICE file.
 *
 * You may obtain a copy of the Apache License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Apache License with the above modification is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the Apache License for the specific
 * language governing permissions and limitations under the Apache License.
 *******************************************************************************/
package com.disney.groovity.compile;

import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.management.ObjectName;

import org.codehaus.groovy.control.CompilerConfiguration;

import com.disney.groovity.ArgsResolver;
import com.disney.groovity.BindingDecorator;
import com.disney.groovity.Groovity;
import com.disney.groovity.GroovityConstants;
import com.disney.groovity.GroovityObjectConverter;
import com.disney.groovity.cache.Cache;
import com.disney.groovity.cache.SoftCacheValueStore;
import com.disney.groovity.conf.Configurator;
import com.disney.groovity.util.AsyncChannel;
import com.disney.groovity.util.AsyncChannelObserver;
import com.disney.groovity.util.ScriptHelper;

import groovy.lang.Closure;
import groovy.lang.GString;
import groovy.lang.GroovyClassLoader;
import groovy.lang.Script;

/**
 * Custom classloader for Groovity; a single class loader is generated per groovity script.  This class loader implements protection domain, 
 * provides access to caches and args resolver as well as the ability to discover all other compiled groovity scripts in separate classloaders.
 *
 * @author Alex Vigdor
 */
public class GroovityClassLoader extends GroovyClassLoader implements GroovityConstants, AsyncChannelObserver{
	private static final Logger log = Logger.getLogger(GroovityClassLoader.class.getName());
	private ProtectionDomain protectionDomain;
	private ScriptHelper helper;
	private Groovity groovity;
	private String sourcePath;
	private String scriptName;
	private ConcurrentHashMap caches;
	private BindingDecorator bindingDecorator;
	private ArgsResolver argsResolver;
	private List mbeanNames = new ArrayList();
	private ScheduledExecutorService scheduler;
	private Logger scriptLogger;
	private Class