groovy.lang.GroovySystem Java Examples

The following examples show how to use groovy.lang.GroovySystem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GradleVersion.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
}
 
Example #2
Source File: CommandLineActionFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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());
}
 
Example #3
Source File: Selector.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Gives the meta class to an Object.
 */
public MetaClass 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;
        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();

    return mc;
}
 
Example #4
Source File: ClassInfo.java    From groovy with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: GroovyScriptEngineFactory.java    From groovy with Apache License 2.0 6 votes vote down vote up
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");
        }

    }
 
Example #6
Source File: CommandLineActionFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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());
}
 
Example #7
Source File: GradleVersion.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
}
 
Example #8
Source File: GroovyScriptEngineFactory.java    From hasor with Apache License 2.0 6 votes vote down vote up
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");
    }
}
 
Example #9
Source File: HibernateCriteriaBuilder.java    From gorm-hibernate5 with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example #10
Source File: MetaElementsProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Map<FieldSignature, CompletionItem> getFields(CompletionContext context) {
    final Map<FieldSignature, CompletionItem> result = new HashMap<FieldSignature, CompletionItem>();
    final Class<?> clazz = loadClass(context);
    
    if (clazz != null) {
        final MetaClass metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(clazz);

        if (metaClass != null) {
            
            for (Object field : metaClass.getProperties()) {
                MetaProperty prop = (MetaProperty) field;
                if (prop.getName().startsWith(context.getPrefix())) {
                    result.put(new FieldSignature(prop.getName()), new CompletionItem.FieldItem(
                            prop.getType().getSimpleName(),
                            prop.getName(),
                            prop.getModifiers(),
                            context.getAnchor()));
                }
            }
            GroovySystem.getMetaClassRegistry().removeMetaClass(clazz);
        }
    }
    
    return result;
}
 
Example #11
Source File: MetaElementsProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Map<MethodSignature, CompletionItem> getStaticMethods(CompletionContext context) {
    final Map<MethodSignature, CompletionItem> result = new HashMap<MethodSignature, CompletionItem>();
    final Class clz = loadClass(context);

    if (clz != null) {
        final MetaClass metaClz = GroovySystem.getMetaClassRegistry().getMetaClass(clz);

        if (metaClz != null) {
            for (MetaMethod method : metaClz.getMetaMethods()) {
                if (method.isStatic()) {
                    populateProposal(clz, method, context.getPrefix(), context.getAnchor(), result, context.isNameOnly());
                }
            }
        }
        GroovySystem.getMetaClassRegistry().removeMetaClass(clz);
    }
    return result;
}
 
Example #12
Source File: MetaElementsProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Map<MethodSignature, CompletionItem> getMethods(CompletionContext context) {
    final Map<MethodSignature, CompletionItem> result = new HashMap<MethodSignature, CompletionItem>();
    final Class clz = loadClass(context);
    
    if (clz != null) {
        final MetaClass metaClz = GroovySystem.getMetaClassRegistry().getMetaClass(clz);

        if (metaClz != null) {
            for (MetaMethod method : metaClz.getMetaMethods()) {
                if (!method.isStatic()) {
                    populateProposal(clz, method, context.getPrefix(), context.getAnchor(), result, context.isNameOnly());
                }
            }
        }
        GroovySystem.getMetaClassRegistry().removeMetaClass(clz);
    }
    return result;
}
 
Example #13
Source File: GrailsDataBinder.java    From AlgoTrader with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: GrailsDataBinder.java    From AlgoTrader with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #15
Source File: GroovyKernelInfoHandler.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #16
Source File: ProxyGenerator.java    From groovy with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #17
Source File: GroovyMain.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public String[] getVersion() {
    return new String[] {
            "Groovy Version: " + GroovySystem.getVersion() + " JVM: " + System.getProperty("java.version") +
            " Vendor: " + System.getProperty("java.vm.vendor")  + " OS: " + System.getProperty("os.name")
    };
}
 
Example #18
Source File: ScriptBytecodeAdapter.java    From groovy with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #19
Source File: Selector.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * For a constructor call we always use the static meta class from the registry
 */
@Override
public MetaClass getMetaClass() {
    Object receiver = args[0];
    mc = GroovySystem.getMetaClassRegistry().getMetaClass((Class<?>) receiver);
    return mc;
}
 
Example #20
Source File: FileSystemCompiler.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public String[] getVersion() {
    return new String[]{
            "Groovy compiler version " + GroovySystem.getVersion(),
            "Copyright 2003-2020 The Apache Software Foundation. http://groovy-lang.org/",
            "",
    };
}
 
Example #21
Source File: InvokerHelper.java    From groovy with Apache License 2.0 5 votes vote down vote up
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(object, property, newValue);
    } else {
        ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object).setProperty(object, property, newValue);
    }
}
 
Example #22
Source File: ConversionHandler.java    From groovy with Apache License 2.0 5 votes vote down vote up
private MetaClass getMetaClass(Object proxy) {
    MetaClass mc = metaClass;
    if (mc == null) {
        mc = ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(proxy);
        metaClass = mc;
    }
    return mc;
}
 
Example #23
Source File: SimpleHibernateProxyHandler.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the meta class is correct for a given class
 *
 * @param target The GroovyObject
 * @param persistentClass The persistent class
 */
private 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));
        }
    }
}
 
Example #24
Source File: GrailsHibernateUtil.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the meta class is correct for a given class
 *
 * @param target The GroovyObject
 * @param persistentClass The persistent class
 */
@Deprecated
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));
        }
    }
}
 
Example #25
Source File: GrailsHibernateUtil.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example #26
Source File: InvokerHelper.java    From groovy with Apache License 2.0 4 votes vote down vote up
public static MetaClass getMetaClass(Object object) {
    if (object instanceof GroovyObject)
        return ((GroovyObject) object).getMetaClass();
    else
        return ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object);
}
 
Example #27
Source File: MixedInMetaClass.java    From groovy with Apache License 2.0 4 votes vote down vote up
public MixedInMetaClass(Object instance, Object owner) {
    super(GroovySystem.getMetaClassRegistry().getMetaClass(instance.getClass()));
    this.owner = new WeakReference(owner);
    MetaClassHelper.doSetMetaClass(instance, this);
}
 
Example #28
Source File: ClassInfo.java    From groovy with Apache License 2.0 4 votes vote down vote up
private static boolean isValidWeakMetaClass(MetaClass metaClass) {
    return isValidWeakMetaClass(metaClass, GroovySystem.getMetaClassRegistry().getMetaClassCreationHandler());
}
 
Example #29
Source File: GroovyResultSetProxy.java    From groovy with Apache License 2.0 4 votes vote down vote up
private MetaClass getMetaClass() {
    if (metaClass == null) {
        metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(DummyResultSet.class);
    }
    return metaClass;
}
 
Example #30
Source File: MockProxyMetaClass.java    From groovy with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}