groovy.lang.MissingPropertyException Java Examples
The following examples show how to use
groovy.lang.MissingPropertyException.
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: ProjectPropertySettingBuildLoader.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private void addPropertiesToProject(Project project) { Properties projectProperties = new Properties(); File projectPropertiesFile = new File(project.getProjectDir(), Project.GRADLE_PROPERTIES); LOGGER.debug("Looking for project properties from: {}", projectPropertiesFile); if (projectPropertiesFile.isFile()) { projectProperties = GUtil.loadProperties(projectPropertiesFile); LOGGER.debug("Adding project properties (if not overwritten by user properties): {}", projectProperties.keySet()); } else { LOGGER.debug("project property file does not exists. We continue!"); } Map<String, String> mergedProperties = propertiesLoader.mergeProperties(new HashMap(projectProperties)); ExtraPropertiesExtension extraProperties = new DslObject(project).getExtensions().getExtraProperties(); for (Map.Entry<String, String> entry: mergedProperties.entrySet()) { try { project.setProperty(entry.getKey(), entry.getValue()); } catch (MissingPropertyException e) { if (!entry.getKey().equals(e.getProperty())) { throw e; } // Ignore and define as an extra property extraProperties.set(entry.getKey(), entry.getValue()); } } }
Example #2
Source File: ThrowableDisplayer.java From sqoop-on-spark with Apache License 2.0 | 6 votes |
/** * Error hook installed to Groovy shell. * * Will display exception that appeared during executing command. In most * cases we will simply delegate the call to printing throwable method, * however in case that we've received ClientError.CLIENT_0006 (server * exception), we will unwrap server issue and view only that as local * context shouldn't make any difference. * * @param t Throwable to be displayed */ public static void errorHook(Throwable t) { // Based on the kind of exception we are dealing with, let's provide different user experince if(t instanceof SqoopException && ((SqoopException)t).getErrorCode() == ShellError.SHELL_0006) { println("@|red Server has returned exception: |@"); printThrowable(t.getCause(), isVerbose()); } else if(t instanceof SqoopException && ((SqoopException)t).getErrorCode() == ShellError.SHELL_0003) { print("@|red Invalid command invocation: |@"); // In most cases the cause will be actual parsing error, so let's print that alone if (t.getCause() != null) { println(t.getCause().getMessage()); } else { println(t.getMessage()); } } else if(t.getClass() == MissingPropertyException.class) { print("@|red Unknown command: |@"); println(t.getMessage()); } else { println("@|red Exception has occurred during processing command |@"); printThrowable(t, isVerbose()); } }
Example #3
Source File: GroovyRowResult.java From groovy with Apache License 2.0 | 6 votes |
/** * Retrieve the value of the property by its index. * A negative index will count backwards from the last column. * * @param index is the number of the column to look at * @return the value of the property */ public Object getAt(int index) { try { // a negative index will count backwards from the last column. if (index < 0) index += result.size(); Iterator<Object> it = result.values().iterator(); int i = 0; Object obj = null; while ((obj == null) && (it.hasNext())) { if (i == index) obj = it.next(); else it.next(); i++; } return obj; } catch (Exception e) { throw new MissingPropertyException(Integer.toString(index), GroovyRowResult.class, e); } }
Example #4
Source File: BindPath.java From groovy with Apache License 2.0 | 6 votes |
private Object extractNewValue(Object newObject) { Object newValue; try { newValue = InvokerHelper.getProperty(newObject, propertyName); } catch (MissingPropertyException mpe) { //todo we should flag this when the path is created that this is a field not a prop... // try direct method... try { newValue = InvokerHelper.getAttribute(newObject, propertyName); if (newValue instanceof Reference) { newValue = ((Reference) newValue).get(); } } catch (Exception e) { //LOGME? newValue = null; } } return newValue; }
Example #5
Source File: GremlinGroovyScriptEngineOverGraphTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldClearBindingsBetweenEvals() throws Exception { final Graph graph = TinkerFactory.createModern(); final GraphTraversalSource g = graph.traversal(); final ScriptEngine engine = new GremlinGroovyScriptEngine(); engine.put("g", g); engine.put("marko", convertToVertexId(graph, "marko")); assertEquals(g.V(convertToVertexId(graph, "marko")).next(), engine.eval("g.V(marko).next()")); final Bindings bindings = engine.createBindings(); bindings.put("g", g); bindings.put("s", "marko"); assertEquals(engine.eval("g.V().has('name',s).next()", bindings), g.V(convertToVertexId(graph, "marko")).next()); try { engine.eval("g.V().has('name',s).next()"); fail("This should have failed because s is no longer bound"); } catch (Exception ex) { final Throwable t = ExceptionUtils.getRootCause(ex); assertEquals(MissingPropertyException.class, t.getClass()); assertTrue(t.getMessage().startsWith("No such property: s for class")); } }
Example #6
Source File: DriverScriptMetaClass.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public void setProperty( Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass) { if(!frozen) { super.setProperty(sender, object, name, newValue, useSuper, fromInsideClass); } else { if(hasProperty(object, name) == null) { throw new MissingPropertyException(name); } else { throw new ReadOnlyPropertyException(name, getTheClass()); } } }
Example #7
Source File: GroovyCommandDefinition.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public Object getProperty(String property) { try { return super.getProperty(property); } catch(MissingPropertyException e) { if(isValidInstance(property)) { return instance(property); } else { if(this.constants != null) { Object value = this.constants.get(property); if(value != null) { return value; } } throw e; } } }
Example #8
Source File: FactoryBuilderSupport.java From groovy with Apache License 2.0 | 6 votes |
/** * Overloaded to make variables appear as bean properties or via the subscript operator */ public Object getProperty(String property) { try { return getProxyBuilder().doGetProperty(property); } catch (MissingPropertyException mpe) { if ((getContext() != null) && (getContext().containsKey(property))) { return getContext().get(property); } else { try { return getMetaClass().getProperty(this, property); } catch(MissingPropertyException mpe2) { if(mpe2.getProperty().equals(property) && propertyMissingDelegate != null) { return propertyMissingDelegate.call(new Object[]{property}); } throw mpe2; } } } }
Example #9
Source File: GremlinGroovyScriptEngineTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldPromoteDefinedVarsInInterpreterModeWithBindings() throws Exception { final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeGroovyCustomizer()); final Bindings b = new SimpleBindings(); b.put("x", 2); engine.eval("def addItUp = { x, y -> x + y }", b); assertEquals(3, engine.eval("int xxx = 1 + x", b)); assertEquals(4, engine.eval("yyy = xxx + 1", b)); assertEquals(7, engine.eval("def zzz = yyy + xxx", b)); assertEquals(4, engine.eval("zzz - xxx", b)); assertEquals("accessible-globally", engine.eval("if (yyy > 0) { def inner = 'should-stay-local'; outer = 'accessible-globally' }\n outer", b)); assertEquals("accessible-globally", engine.eval("outer", b)); try { engine.eval("inner", b); fail("Should not have been able to access 'inner'"); } catch (Exception ex) { final Throwable root = ExceptionUtils.getRootCause(ex); assertThat(root, instanceOf(MissingPropertyException.class)); } assertEquals(10, engine.eval("addItUp(zzz,xxx)", b)); }
Example #10
Source File: GremlinGroovyScriptEngineTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldPromoteDefinedVarsInInterpreterModeWithNoBindings() throws Exception { final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeGroovyCustomizer()); engine.eval("def addItUp = { x, y -> x + y }"); engine.eval("class A { def sub(int x, int y) {x - y}}"); assertEquals(3, engine.eval("int xxx = 1 + 2")); assertEquals(4, engine.eval("yyy = xxx + 1")); assertEquals(7, engine.eval("def zzz = yyy + xxx")); assertEquals(4, engine.eval("zzz - xxx")); assertEquals("accessible-globally", engine.eval("if (yyy > 0) { def inner = 'should-stay-local'; outer = 'accessible-globally' }\n outer")); assertEquals("accessible-globally", engine.eval("outer")); try { engine.eval("inner"); fail("Should not have been able to access 'inner'"); } catch (Exception ex) { final Throwable root = ExceptionUtils.getRootCause(ex); assertThat(root, instanceOf(MissingPropertyException.class)); } assertEquals(9, engine.eval("new A().sub(10, 1)")); assertEquals(10, engine.eval("addItUp(zzz,xxx)")); }
Example #11
Source File: GroovyResultSetExtension.java From groovy with Apache License 2.0 | 5 votes |
/** * Updates the designated column with an <code>Object</code> value. * * @param columnName the SQL name of the column * @param newValue the updated value * @throws MissingPropertyException if an SQLException happens while setting the new value * @see groovy.lang.GroovyObject#setProperty(java.lang.String, java.lang.Object) * @see ResultSet#updateObject(java.lang.String, java.lang.Object) */ public void setProperty(String columnName, Object newValue) { try { getResultSet().updateObject(columnName, newValue); updated = true; } catch (SQLException e) { throw new MissingPropertyException(columnName, GroovyResultSetProxy.class, e); } }
Example #12
Source File: SqoopCommand.java From sqoop-on-spark with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void resolveVariables(List arg) { List temp = new ArrayList(); GroovyShell gs = new GroovyShell(getBinding()); for(Object obj:arg) { Script scr = gs.parse("\""+(String)obj+"\""); try { temp.add(scr.run().toString()); } catch(MissingPropertyException e) { throw new SqoopException(ShellError.SHELL_0004, e.getMessage(), e); } } Collections.copy(arg, temp); }
Example #13
Source File: ImmutableASTTransformation.java From groovy with Apache License 2.0 | 5 votes |
public static void checkPropNames(Object instance, Map<String, Object> args) { final MetaClass metaClass = InvokerHelper.getMetaClass(instance); for (String k : args.keySet()) { if (metaClass.hasProperty(instance, k) == null) throw new MissingPropertyException(k, instance.getClass()); } }
Example #14
Source File: FactoryBuilderSupport.java From groovy with Apache License 2.0 | 5 votes |
/** * @param name the name of the variable to lookup * @return the variable value */ public Object getVariable(String name) { try { return getProxyBuilder().doGetVariable(name); } catch(MissingPropertyException mpe) { if(mpe.getProperty().equals(name) && propertyMissingDelegate != null) { return propertyMissingDelegate.call(new Object[]{name}); } throw mpe; } }
Example #15
Source File: FactoryBuilderSupport.java From groovy with Apache License 2.0 | 5 votes |
private Object doGetProperty(String property) { Closure[] accessors = resolveExplicitProperty(property); if (accessors != null) { if (accessors[0] == null) { // write only property throw new MissingPropertyException(property + " is declared as write only"); } else { return accessors[0].call(); } } else { return super.getProperty(property); } }
Example #16
Source File: Expando.java From groovy with Apache License 2.0 | 5 votes |
public Object getProperty(String property) { // always use the expando properties first Object result = getProperties().get(property); if (result != null) return result; try { return super.getProperty(property); } catch (MissingPropertyException e) { // IGNORE } return null; }
Example #17
Source File: FactoryBuilderSupport.java From groovy with Apache License 2.0 | 5 votes |
private void doSetProperty(String property, Object newValue) { Closure[] accessors = resolveExplicitProperty(property); if (accessors != null) { if (accessors[1] == null) { // read only property throw new MissingPropertyException(property + " is declared as read only"); } else { accessors[1].call(newValue); } } else { super.setProperty(property, newValue); } }
Example #18
Source File: DefaultConvention.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public Object getProperty(String name) throws MissingPropertyException { if (extensionsStorage.hasExtension(name)) { return extensionsStorage.getByName(name); } for (Object object : plugins.values()) { DynamicObject dynamicObject = new BeanDynamicObject(object); if (dynamicObject.hasProperty(name)) { return dynamicObject.getProperty(name); } } throw new MissingPropertyException(name, Convention.class); }
Example #19
Source File: DefaultNamedDomainObjectCollection.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
@Override public T getProperty(String name) throws MissingPropertyException { T t = findByName(name); if (t == null) { return (T) super.getProperty(name); } return t; }
Example #20
Source File: GroovyRowResult.java From groovy with Apache License 2.0 | 5 votes |
/** * Retrieve the value of the property by its (case-insensitive) name. * * @param property is the name of the property to look at * @return the value of the property */ public Object getProperty(String property) { try { Object key = lookupKeyIgnoringCase(property); if (key != null) { return result.get(key); } throw new MissingPropertyException(property, GroovyRowResult.class); } catch (Exception e) { throw new MissingPropertyException(property, GroovyRowResult.class, e); } }
Example #21
Source File: DelegatingScript.java From groovy with Apache License 2.0 | 5 votes |
@Override public void setProperty(String property, Object newValue) { try { metaClass.setProperty(delegate,property,newValue); } catch (MissingPropertyException e) { super.setProperty(property,newValue); } }
Example #22
Source File: ScriptTaskTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Deployment public void testFailingScript() { Exception expectedException = null; try { runtimeService.startProcessInstanceByKey("failingScript"); } catch (Exception e) { expectedException = e; } // Check if correct exception is found in the stacktrace verifyExceptionInStacktrace(expectedException, MissingPropertyException.class); }
Example #23
Source File: DefaultConvention.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
public Object getProperty(String name) throws MissingPropertyException { if (extensionsStorage.hasExtension(name)) { return extensionsStorage.getByName(name); } for (Object object : plugins.values()) { DynamicObject dynamicObject = new BeanDynamicObject(object); if (dynamicObject.hasProperty(name)) { return dynamicObject.getProperty(name); } } throw new MissingPropertyException(name, Convention.class); }
Example #24
Source File: EclipseGeneratorPlugin.java From gradle-android-eclipse with Apache License 2.0 | 5 votes |
private EclipseModel eclipseModel(Project project) { try { return (EclipseModel) project.property("eclipse"); } catch (MissingPropertyException e) { throw new RuntimeException( "Cannot find 'eclipse' property.\nEnsure that the following is in your project: \n\napply plugin: 'eclipse'\n\n", e); } }
Example #25
Source File: ScriptTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Deployment public void testFailingScript() { Exception expectedException = null; try { runtimeService.startProcessInstanceByKey("failingScript"); } catch (Exception e) { expectedException = e; } // Check if correct exception is found in the stacktrace verifyExceptionInStacktrace(expectedException, MissingPropertyException.class); }
Example #26
Source File: ScriptTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Deployment public void testFailingScript() { Exception expectedException = null; try { runtimeService.startProcessInstanceByKey("failingScript"); } catch (Exception e) { expectedException = e; } // Check if correct exception is found in the stacktrace verifyExceptionInStacktrace(expectedException, MissingPropertyException.class); }
Example #27
Source File: DefaultExtraPropertiesExtension.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public Object getProperty(String name) { if (name.equals("properties")) { return getProperties(); } try { return get(name); } catch (UnknownPropertyException e) { throw new MissingPropertyException(e.getMessage(), name, null); } }
Example #28
Source File: ExtraPropertiesDynamicObjectAdapter.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void setProperty(String name, Object value) throws MissingPropertyException { if (!dynamicOwner.hasProperty(name)) { DeprecationLogger.nagUserAboutDynamicProperty(name, delegate, value); } super.setProperty(name, value); }
Example #29
Source File: AbstractPolymorphicDomainObjectContainer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Object getProperty(String name) throws MissingPropertyException { Object object = findByName(name); if (object == null) { return super.getProperty(name); } return object; }
Example #30
Source File: ConventionAwareHelper.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void propertyMissing(String name, Object value) { if (value instanceof Closure) { map(name, (Closure) value); } else { throw new MissingPropertyException(name, getClass()); } }