Java 类groovy.lang.GroovySystem 实例源码

项目:Reer    文件:CommandLineActionFactory.java   
public void run() {
    GradleVersion currentVersion = GradleVersion.current();

    final StringBuilder sb = new StringBuilder();
    sb.append("\n------------------------------------------------------------\nGradle ");
    sb.append(currentVersion.getVersion());
    sb.append("\n------------------------------------------------------------\n\nBuild time:   ");
    sb.append(currentVersion.getBuildTime());
    sb.append("\nRevision:     ");
    sb.append(currentVersion.getRevision());
    sb.append("\n\nGroovy:       ");
    sb.append(GroovySystem.getVersion());
    sb.append("\nAnt:          ");
    sb.append(Main.getAntVersion());
    sb.append("\nJVM:          ");
    sb.append(Jvm.current());
    sb.append("\nOS:           ");
    sb.append(OperatingSystem.current());
    sb.append("\n");

    System.out.println(sb.toString());
}
项目:beaker-notebook-archive    文件:GroovyKernelInfoHandler.java   
private void handleMsg(Message message) {
  logger.debug("Processing kernel info request");
  Message reply = new Message();
  HashMap<String, Serializable> map = new HashMap<>(6);
  map.put("protocol_version", "5.0");
  map.put("implementation", "groovy");
  map.put("implementation_version", "1.0.0");
  HashMap<String, Serializable> map1 = new HashMap<String, Serializable>(7);
  map1.put("name", "Groovy");
  map1.put("version", GroovySystem.getVersion());
  map1.put("mimetype", "");
  map1.put("file_extension", ".groovy");
  map1.put("codemirror_mode", "groovy");
  map1.put("nbconverter_exporter", "");
  map.put("language_info", map1);
  map.put("banner", "BeakerX kernel for Apache Groovy");
  map.put("beakerx", true);
  map.put("help_links", new ArrayList<String>());
  reply.setContent(map);
  reply.setHeader(new Header(KERNEL_INFO_REPLY, message.getHeader().getSession()));
  reply.setParentHeader(message.getHeader());
  reply.setIdentities(message.getIdentities());
  send(reply);
}
项目:gorm-hibernate5    文件:HibernateCriteriaBuilder.java   
@Override
protected void createCriteriaInstance() {
    {
        if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
            participate = true;
            hibernateSession = ((SessionHolder)TransactionSynchronizationManager.getResource(sessionFactory)).getSession();
        }
        else {
            hibernateSession = sessionFactory.openSession();
        }

        criteria = hibernateSession.createCriteria(targetClass);
        cacheCriteriaMapping();
        criteriaMetaClass = GroovySystem.getMetaClassRegistry().getMetaClass(criteria.getClass());
    }
}
项目:groovy    文件:GroovyScriptEngineFactory.java   
public Object getParameter(String key) {

        if (ScriptEngine.NAME.equals(key)) {
            return SHORT_NAME;
        } else if (ScriptEngine.ENGINE.equals(key)) {
            return getEngineName();
        } else if (ScriptEngine.ENGINE_VERSION.equals(key)) {
            return VERSION;
        } else if (ScriptEngine.LANGUAGE.equals(key)) {
            return LANGUAGE_NAME;
        } else if (ScriptEngine.LANGUAGE_VERSION.equals(key)) {
            return GroovySystem.getVersion();
        } else if ("THREADING".equals(key)) {
            return "MULTITHREADED";
        } else {
            throw new IllegalArgumentException("Invalid key");
        }

    }
项目:groovy    文件:ClassInfo.java   
private MetaClass getMetaClassUnderLock() {
    MetaClass answer = getStrongMetaClass();
    if (answer!=null) return answer;

    answer = getWeakMetaClass();
    final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
    MetaClassRegistry.MetaClassCreationHandle mccHandle = metaClassRegistry.getMetaClassCreationHandler();

    if (isValidWeakMetaClass(answer, mccHandle)) {
        return answer;
    }

    answer = mccHandle.create(classRef.get(), metaClassRegistry);
    answer.initialize();

    if (GroovySystem.isKeepJavaMetaClasses()) {
        setStrongMetaClass(answer);
    } else {
        setWeakMetaClass(answer);
    }
    return answer;
}
项目:groovy    文件:DefaultGroovyMethods.java   
/**
 * Sets the metaclass for a given class.
 *
 * @param self the class whose metaclass we wish to set
 * @param metaClass the new MetaClass
 * @since 1.6.0
 */
public static void setMetaClass(Class self, MetaClass metaClass) {
    final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
    if (metaClass == null)
        metaClassRegistry.removeMetaClass(self);
    else {
        if (metaClass instanceof HandleMetaClass) {
            metaClassRegistry.setMetaClass(self, ((HandleMetaClass)metaClass).getAdaptee());
        } else {
            metaClassRegistry.setMetaClass(self, metaClass);
        }
        if (self==NullObject.class) {
            NullObject.getNullObject().setMetaClass(metaClass);
        }
    }
}
项目:groovy    文件:DefaultGroovyMethods.java   
private static MetaClass hasPerInstanceMetaClass(Object object) {
    if (object instanceof GroovyObject) {
        MetaClass mc = ((GroovyObject)object).getMetaClass();
        if (mc == GroovySystem.getMetaClassRegistry().getMetaClass(object.getClass()) || mc.getClass() == MetaClassImpl.class)
            return null;
        else
            return mc;
    }
    else {
        ClassInfo info = ClassInfo.getClassInfo(object.getClass());
        info.lock();
        try {
            return info.getPerInstanceMetaClass(object);
        }
        finally {
            info.unlock();
        }
    }
}
项目:groovy    文件:Selector.java   
/**
 * Gives the meta class to an Object.
 */
public void getMetaClass() {
    Object receiver = args[0];
    if (receiver == null) {
        mc = NullObject.getNullObject().getMetaClass();
    } else if (receiver instanceof GroovyObject) {
        mc = ((GroovyObject) receiver).getMetaClass();
    } else if (receiver instanceof Class) {
        Class c = (Class) receiver;
        ClassLoader cl = c.getClassLoader();
        try {
            Class.forName(c.getName(), true, cl);
        } catch (ClassNotFoundException e) {}
        mc = GroovySystem.getMetaClassRegistry().getMetaClass(c);
        this.cache &= !ClassInfo.getClassInfo(c).hasPerInstanceMetaClasses();
    } else {
        mc = ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(receiver);
        this.cache &= !ClassInfo.getClassInfo(receiver.getClass()).hasPerInstanceMetaClasses();
    }
    mc.initialize();
}
项目:groovy    文件:GroovyMain.java   
static void processArgs(String[] args, final PrintStream out) {
    Options options = buildOptions();

    try {
        CommandLine cmd = parseCommandLine(options, args);

        if (cmd.hasOption('h')) {
            printHelp(out, options);
        } else if (cmd.hasOption('v')) {
            String version = GroovySystem.getVersion();
            out.println("Groovy Version: " + version + " JVM: " + System.getProperty("java.version") +
                    " Vendor: " + System.getProperty("java.vm.vendor")  + " OS: " + System.getProperty("os.name"));
        } else {
            // If we fail, then exit with an error so scripting frameworks can catch it
            // TODO: pass printstream(s) down through process
            if (!process(cmd)) {
                System.exit(1);
            }
        }
    } catch (ParseException pe) {
        out.println("error: " + pe.getMessage());
        printHelp(out, options);
    } catch (IOException ioe) {
        out.println("error: " + ioe.getMessage());
    }
}
项目:Pushjet-Android    文件:CommandLineActionFactory.java   
public void run() {
    GradleVersion currentVersion = GradleVersion.current();

    final StringBuilder sb = new StringBuilder();
    sb.append("\n------------------------------------------------------------\nGradle ");
    sb.append(currentVersion.getVersion());
    sb.append("\n------------------------------------------------------------\n\nBuild time:   ");
    sb.append(currentVersion.getBuildTime());
    sb.append("\nBuild number: ");
    sb.append(currentVersion.getBuildNumber());
    sb.append("\nRevision:     ");
    sb.append(currentVersion.getRevision());
    sb.append("\n\nGroovy:       ");
    sb.append(GroovySystem.getVersion());
    sb.append("\nAnt:          ");
    sb.append(Main.getAntVersion());
    sb.append("\nJVM:          ");
    sb.append(Jvm.current());
    sb.append("\nOS:           ");
    sb.append(OperatingSystem.current());
    sb.append("\n");

    System.out.println(sb.toString());
}
项目:Pushjet-Android    文件:GradleVersion.java   
public String prettyPrint() {
    final StringBuilder sb = new StringBuilder();
    sb.append("\n------------------------------------------------------------\nGradle ");
    sb.append(getVersion());
    sb.append("\n------------------------------------------------------------\n\nBuild time:   ");
    sb.append(getBuildTime());
    sb.append("\nBuild number: ");
    sb.append(buildNumber);
    sb.append("\nRevision:     ");
    sb.append(commitId);
    sb.append("\n\nGroovy:       ");
    sb.append(GroovySystem.getVersion());
    sb.append("\nAnt:          ");
    sb.append(Main.getAntVersion());
    sb.append("\nIvy:          ");
    sb.append(Ivy.getIvyVersion());
    sb.append("\nJVM:          ");
    sb.append(Jvm.current());
    sb.append("\nOS:           ");
    sb.append(OperatingSystem.current());
    sb.append("\n");
    return sb.toString();
}
项目:AlgoTrader    文件:GrailsDataBinder.java   
private Map resolveConstrainedProperties(Object object, GrailsDomainClass dc) {
    Map constrainedProperties = null;
    if (dc != null) {
        constrainedProperties = dc.getConstrainedProperties();
    } else {
        // is this dead code? , didn't remove in case it's used somewhere
        MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(object.getClass());
        MetaProperty metaProp = mc.getMetaProperty(CONSTRAINTS_PROPERTY);
        if (metaProp != null) {
            Object constrainedPropsObj = getMetaPropertyValue(metaProp, object);
            if (constrainedPropsObj instanceof Map) {
                constrainedProperties = (Map) constrainedPropsObj;
            }
        }
    }
    return constrainedProperties;
}
项目:okbuck    文件:GroovyUtil.java   
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void setupGroovyHome(Project project) {
    String groovyVersion = GroovySystem.getVersion();

    Configuration groovyConfig = project.getConfigurations().maybeCreate(GROOVY_DEPS_CONFIG);
    project.getDependencies().add(GROOVY_DEPS_CONFIG, "org.codehaus.groovy:groovy:" + groovyVersion);
    new DependencyCache(project, DependencyUtils.createCacheDir(project, GROOVY_HOME_LOCATION + "/lib"))
            .build(groovyConfig);

    File groovyHome = project.file(GROOVY_HOME_LOCATION);

    File groovyStarterConf = new File(groovyHome, "conf/groovy-starter.conf");
    FileUtil.copyResourceToProject("groovy/conf/groovy-starter.conf", groovyStarterConf);

    File groovyc = new File(groovyHome, "bin/groovyc");
    new Groovyc().groovyVersion(groovyVersion).render(groovyc);
    groovyc.setExecutable(true);

    File startGroovy = new File(groovyHome, "bin/startGroovy");
    new StartGroovy().groovyVersion(groovyVersion).render(startGroovy);
    startGroovy.setExecutable(true);
}
项目:okbuck    文件:GroovyUtil.java   
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void setupGroovyHome(Project project) {
    String groovyVersion = GroovySystem.getVersion();

    Configuration groovyConfig = project.getConfigurations().maybeCreate(GROOVY_DEPS_CONFIG);
    project.getDependencies().add(GROOVY_DEPS_CONFIG, "org.codehaus.groovy:groovy:" + groovyVersion);
    new DependencyCache(project, DependencyUtils.createCacheDir(project, GROOVY_HOME_LOCATION + "/lib"))
            .build(groovyConfig);

    File groovyHome = project.file(GROOVY_HOME_LOCATION);

    File groovyStarterConf = new File(groovyHome, "conf/groovy-starter.conf");
    FileUtil.copyResourceToProject("groovy/conf/groovy-starter.conf", groovyStarterConf);

    File groovyc = new File(groovyHome, "bin/groovyc");
    new Groovyc().groovyVersion(groovyVersion).render(groovyc);
    groovyc.setExecutable(true);

    File startGroovy = new File(groovyHome, "bin/startGroovy");
    new StartGroovy().groovyVersion(groovyVersion).render(startGroovy);
    startGroovy.setExecutable(true);
}
项目:Reer    文件:BeanDynamicObject.java   
private MetaClass getMetaClass() {
    if (bean instanceof GroovyObject) {
        return ((GroovyObject) bean).getMetaClass();
    } else {
        return GroovySystem.getMetaClassRegistry().getMetaClass(bean.getClass());
    }
}
项目:HeliosStreams    文件:ManagedScriptFactory.java   
/**
 * Acquires and returns the ManagedScriptFactory singleton instance
 * @return the ManagedScriptFactory singleton instance
 */
public static ManagedScriptFactory getInstance() {
    if(instance==null) {
        synchronized(lock) {
            if(instance==null) {
                GroovySystem.stopThreadedReferenceManager();
                GroovySystem.setKeepJavaMetaClasses(false);
                instance = new ManagedScriptFactory();
                //instance.discoveryService.start();
            }
        }
    }
    return instance;
}
项目:HeliosStreams    文件:MetaClassRegistryCleaner.java   
public static MetaClassRegistryCleaner createAndRegister() {

        MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
        MetaClassRegistryChangeEventListener[] listeners = metaClassRegistry.getMetaClassRegistryChangeEventListeners();
        boolean registered = false;
        for (MetaClassRegistryChangeEventListener listener : listeners) {
            if (listener == INSTANCE) {
                registered = true;break;
            }
        }
        if (!registered) {
            GroovySystem.getMetaClassRegistry().addMetaClassRegistryChangeEventListener(INSTANCE);
        }
        return INSTANCE;
    }
项目:HeliosStreams    文件:MetaClassRegistryCleaner.java   
public synchronized void clean() {
    try {
        cleaning = true;
        MetaClassRegistryImpl registry = (MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry();
        cleanMetaClassOfClass(registry);
        cleanMetaClassOfInstance(registry);
    } finally {
        cleaning = false;
    }
}
项目:gorm-hibernate5    文件:GrailsHibernateUtil.java   
/**
 * Increments the entities version number in order to force an update
 * @param target The target entity
 */
public static void incrementVersion(Object target) {
    MetaClass metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(target.getClass());
    if (metaClass.hasProperty(target, GormProperties.VERSION)!=null) {
        Object version = metaClass.getProperty(target, GormProperties.VERSION);
        if (version instanceof Long) {
            Long newVersion = (Long) version + 1;
            metaClass.setProperty(target, GormProperties.VERSION, newVersion);
        }
    }
}
项目:gorm-hibernate5    文件:GrailsHibernateUtil.java   
/**
 * Ensures the meta class is correct for a given class
 *
 * @param target The GroovyObject
 * @param persistentClass The persistent class
 */
public static void ensureCorrectGroovyMetaClass(Object target, Class<?> persistentClass) {
    if (target instanceof GroovyObject) {
        GroovyObject go = ((GroovyObject)target);
        if (!go.getMetaClass().getTheClass().equals(persistentClass)) {
            go.setMetaClass(GroovySystem.getMetaClassRegistry().getMetaClass(persistentClass));
        }
    }
}
项目:groovy    文件:ScriptBytecodeAdapter.java   
public static int selectConstructorAndTransformArguments(Object[] arguments, int numberOfConstructors, Class which) throws Throwable {
    MetaClass metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(which);
    try {
        return metaClass.selectConstructorAndTransformArguments(numberOfConstructors, arguments);
    } catch (GroovyRuntimeException gre) {
        throw unwrap(gre);
    }
}
项目:groovy    文件:DefaultGroovyMethods.java   
/**
 * Adds a "metaClass" property to all class objects so you can use the syntax
 * <code>String.metaClass.myMethod = { println "foo" }</code>
 *
 * @param c The java.lang.Class instance
 * @return An MetaClass instance
 * @since 1.5.0
 */
public static MetaClass getMetaClass(Class c) {
    MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
    MetaClass mc = metaClassRegistry.getMetaClass(c);
    if (mc instanceof ExpandoMetaClass
            || mc instanceof DelegatingMetaClass && ((DelegatingMetaClass) mc).getAdaptee() instanceof ExpandoMetaClass)
        return mc;
    else {
        return new HandleMetaClass(mc);
    }
}
项目:groovy    文件:DefaultGroovyMethods.java   
/**
 * Set the metaclass for an object.
 * @param self the object whose metaclass we want to set
 * @param metaClass the new metaclass value
 * @since 1.6.0
 */
public static void setMetaClass(Object self, MetaClass metaClass) {
    if (metaClass instanceof HandleMetaClass)
        metaClass = ((HandleMetaClass)metaClass).getAdaptee();

    if (self instanceof Class) {
        GroovySystem.getMetaClassRegistry().setMetaClass((Class) self, metaClass);
    } else {
        ((MetaClassRegistryImpl)GroovySystem.getMetaClassRegistry()).setMetaClass(self, metaClass);
    }
}
项目:groovy    文件:ConversionHandler.java   
private MetaClass getMetaClass(Object proxy) {
    MetaClass mc = metaClass;
    if (mc == null) {
        mc = ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(proxy);
        metaClass = mc;
    }
    return mc;
}
项目:groovy    文件:InvokerHelper.java   
public static void setProperty(Object object, String property, Object newValue) {
    if (object == null) {
        object = NullObject.getNullObject();
    }

    if (object instanceof GroovyObject) {
        GroovyObject pogo = (GroovyObject) object;
        pogo.setProperty(property, newValue);
    } else if (object instanceof Class) {
        metaRegistry.getMetaClass((Class) object).setProperty((Class) object, property, newValue);
    } else {
        ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object).setProperty(object, property, newValue);
    }
}
项目:groovy    文件:ProxyGenerator.java   
private static void setMetaClass(final MetaClass metaClass) {
    final MetaClass newMetaClass = new DelegatingMetaClass(metaClass) {
        @Override
        public Object invokeStaticMethod(Object object, String methodName, Object[] arguments) {
            return InvokerHelper.invokeMethod(INSTANCE, methodName, arguments);
        }
    };
    GroovySystem.getMetaClassRegistry().setMetaClass(ProxyGenerator.class, newMetaClass);
}
项目:scripturian    文件:GroovyAdapter.java   
/**
 * Constructor.
 * 
 * @throws LanguageAdapterException
 *         In case of an initialization error
 */
public GroovyAdapter() throws LanguageAdapterException
{
    super( "Groovy", GroovySystem.getVersion(), "Groovy", GroovySystem.getVersion(), Arrays.asList( "groovy", "gv" ), "groovy", Arrays.asList( "groovy", "gv" ), "groovy" );

    // This will allow the class loader to load our auxiliary classes (see
    // GroovyProgram.prepare)
    groovyClassLoader.addClasspath( getCacheDir().getPath() );
}
项目:AlgoTrader    文件:GrailsDataBinder.java   
private Object autoInstantiateDomainInstance(Class<?> type) {
    Object created = null;
    try {
        MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(type);
        if (mc != null) {
            created = mc.invokeStaticMethod(type, CreateDynamicMethod.METHOD_NAME, new Object[0]);
        }
    } catch (MissingMethodException mme) {
        LOG.warn("Unable to auto-create type, 'create' method not found");
    } catch (GroovyRuntimeException gre) {
        LOG.warn("Unable to auto-create type, Groovy Runtime error: " + gre.getMessage(), gre);
    }
    return created;
}
项目:AlgoTrader    文件:GrailsDataBinder.java   
private void addAssociationToTarget(String name, Object target, Object obj) {
    if (obj == null) {
        return;
    }

    MetaClassRegistry reg = GroovySystem.getMetaClassRegistry();
    MetaClass mc = reg.getMetaClass(target.getClass());
    final String addMethodName = "addTo" + GrailsNameUtils.getClassNameRepresentation(name);
    mc.invokeMethod(target, addMethodName, obj);
}
项目:beakerx    文件:GroovyKernelInfoHandler.java   
@Override
protected HashMap<String, Serializable> doLanguageInfo(HashMap<String, Serializable> languageInfo) {
  languageInfo.put("name", "Groovy");
  languageInfo.put("version", GroovySystem.getVersion());
  languageInfo.put("mimetype", "");
  languageInfo.put("file_extension", ".groovy");
  languageInfo.put("codemirror_mode", "groovy");
  languageInfo.put("nbconverter_exporter", "");
  return languageInfo;
}
项目:Reer    文件:BeanDynamicObject.java   
ClassAdapter(Class<?> cl) {
    classMetaData = GroovySystem.getMetaClassRegistry().getMetaClass(cl);
}
项目:HeliosStreams    文件:MetaClassRegistryCleaner.java   
public static void cleanAndRemove(MetaClassRegistryCleaner cleaner) {
    cleaner.clean();
    GroovySystem.getMetaClassRegistry().removeMetaClassRegistryChangeEventListener(cleaner);
}
项目:groovy    文件:GroovyScriptEngineFactory.java   
public String getLanguageVersion() {
    return GroovySystem.getVersion();
}
项目:groovy    文件:MockProxyMetaClass.java   
/**
 * convenience factory method allowing interceptConstruction to be set.
 */
public static MockProxyMetaClass make(Class theClass, boolean interceptConstruction) {
    MetaClassRegistry metaRegistry = GroovySystem.getMetaClassRegistry();
    MetaClass meta = metaRegistry.getMetaClass(theClass);
    return new MockProxyMetaClass(metaRegistry, theClass, meta, interceptConstruction);
}
项目:groovy    文件:GroovyResultSetProxy.java   
private MetaClass getMetaClass() {
    if (metaClass == null) {
        metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(DummyResultSet.class);
    }
    return metaClass;
}
项目:groovy    文件:ClassInfo.java   
private static boolean isValidWeakMetaClass(MetaClass metaClass) {
    return isValidWeakMetaClass(metaClass, GroovySystem.getMetaClassRegistry().getMetaClassCreationHandler());
}
项目:groovy    文件:MixedInMetaClass.java   
public MixedInMetaClass(Object instance, Object owner) {
    super(GroovySystem.getMetaClassRegistry().getMetaClass(instance.getClass()));
    this.owner = new WeakReference(owner);
    MetaClassHelper.doSetMetaClass(instance, this);
}
项目:groovy    文件:InvokerHelper.java   
public static MetaClass getMetaClass(Object object) {
    if (object instanceof GroovyObject)
        return ((GroovyObject) object).getMetaClass();
    else
        return ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object);
}
项目:groovy    文件:FileSystemCompiler.java   
public static void displayVersion() {
    String version = GroovySystem.getVersion();
    System.err.println("Groovy compiler version " + version);
    System.err.println("Copyright 2003-2018 The Apache Software Foundation. http://groovy-lang.org/");
    System.err.println("");
}
项目:groovy    文件:Selector.java   
/**
 * For a constructor call we always use the static meta class from the registry
 */
@Override
public void getMetaClass() {
    Object receiver = args[0];
    mc = GroovySystem.getMetaClassRegistry().getMetaClass((Class) receiver);
}