public static void initPageVariables(JellyContext context) { StaplerRequest currentRequest = Stapler.getCurrentRequest(); String rootURL = currentRequest.getContextPath(); Functions h = new Functions(); context.setVariable("h", h); // The path starts with a "/" character but does not end with a "/" character. context.setVariable("rootURL", rootURL); /* load static resources from the path dedicated to a specific version. This "/static/VERSION/abc/def.ghi" path is interpreted by stapler to be the same thing as "/abc/def.ghi", but this avoids the stale cache problem when the user upgrades to new Jenkins. Stapler also sets a long future expiration dates for such static resources. see https://wiki.jenkins-ci.org/display/JENKINS/Hyperlinks+in+HTML */ context.setVariable("resURL",rootURL+getResourcePath()); context.setVariable("imagesURL",rootURL+getResourcePath()+"/images"); context.setVariable("userAgent", currentRequest.getHeader("User-Agent")); IconSet.initPageVariables(context); }
ctx.setVariable("resURL", req.getContextPath() + Jenkins.RESOURCE_PATH); } else { ctx = null;
/** * Set a new variable within the context for the script to use. * @param name * @param value */ public void setVariable(String name, Object value) { m_context.setVariable(name, value); }
/** * Stores this instance in the specified context. It is stored there under a * default key. * * @param context the Jelly context */ public void put(JellyContext context) { context.setVariable(CTX_KEY, this); }
/** * This method is running when an exception occurs whatever * the ignoreFailures value. * * @param project the currentProject * @param e the exception */ public void onException( Project project, Exception e ) { getContext().setVariable( MavenConstants.BUILD_FAILURE, "true" ); failedProjects.add( project ); }
public String getHtml(ProjectConfigInfo projectConfigInfo) throws IOException, ClassNotFoundException, JellyException { String name = getClass().getName().replace('.', '/').replace('$', '/') + "/" + "index.jelly"; URL actionTemplate = getClass().getClassLoader().getResource(name); JellyContext context = new JellyContext(); context.setVariable("p", projectConfigInfo); context.setVariable("it", this); OutputStream outputStream = new ByteArrayOutputStream(); XMLOutput output = XMLOutput.createXMLOutput(outputStream); context.runScript(actionTemplate, output); output.flush(); return "<p>" + outputStream.toString() + " </p>"; }
public void doTag(XMLOutput output) throws BreakException { boolean broken = false; if (test == null || test.evaluateAsBoolean(context)) { broken = true; } if ( var != null ) { context.setVariable( this.var, String.valueOf(broken)); } if ( broken ) { throw new BreakException(); } }
public void doTag(XMLOutput output) throws BreakException { boolean broken = false; if (test == null || test.evaluateAsBoolean(context)) { broken = true; } if ( var != null ) { context.setVariable( this.var, String.valueOf(broken)); } if ( broken ) { throw new BreakException(); } }
public void doTag(XMLOutput output) throws BreakException { boolean broken = false; if (test == null || test.evaluateAsBoolean(context)) { broken = true; } if ( var != null ) { context.setVariable( this.var, String.valueOf(broken)); } if ( broken ) { throw new BreakException(); } }
public void doTag(XMLOutput output) throws JellyTagException { if ( var == null ) { throw new JellyTagException( "<define:script> must have a var attribute" ); } context.setVariable( var, getBody() ); }
/** * Adds {@link XMLOutput} to the context. */ public void run(JellyContext context, XMLOutput output) throws JellyTagException { context.setVariable(getAttribute("var").evaluateAsString(context),output); } };
/** * Executes this tag. This implementation stores the fully initialized menu * bar in the Jelly context. * * @throws JellyTagException if the tag is not correctly used * @throws FormBuilderException if an error occurs */ @Override protected void process() throws JellyTagException, FormBuilderException { getContext().setVariable(getName(), getContainer()); }
public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { if (getVar() == null) { throw new MissingAttributeException("The var attribute cannot be null"); } Document document = getXmlDocument(output); context.setVariable(getVar(), document); }
public void testDynaBeans() throws Exception { DynaClass dynaClass = createDynaClass(); DynaBean dynaBean = dynaClass.newInstance(); dynaBean.set( "stringProperty", "foo" ); dynaBean.set( "intProperty", new Integer(24) ); context.setVariable("dbean", dynaBean); assertExpression("${dbean.stringProperty}", "foo"); assertExpression("${dbean.intProperty}", new Integer(24)); }
public void testExpresssions() throws Exception { context.setVariable("topping", "cheese"); context.setVariable("type", "deepPan"); assertExpression("foo", "foo"); assertExpression("${topping}", "cheese"); assertExpression("some${topping}", "somecheese"); assertExpression(" some ${topping} ", " some cheese "); assertExpression("${topping}y", "cheesey"); assertExpression("A ${topping} ${type} pizza", "A cheese deepPan pizza"); assertExpression("${topping}-${type}", "cheese-deepPan"); }
/** * Gets the System property 'java.runtime.version' and compares it with, * well, the same system property */ public void testSimpleSystemInvoke() throws Exception { setUpScript( "testInvokeStaticTag.jelly" ); Script script = getJelly().compileScript(); getJellyContext().setVariable( "test.simpleSystemInvoke",Boolean.TRUE ); getJellyContext().setVariable( "propertyName", "java.runtime.version" ); script.run( getJellyContext(),getXMLOutput() ); assertTrue( System.getProperty( "java.runtime.version" ).equals( getJellyContext().getVariable("propertyName" ) ) ); }
public void testCaseWithoutValue() throws Exception { setUpScript("testSwitchTag.jelly"); Script script = getJelly().compileScript(); getJellyContext().setVariable("case.without.value",new Boolean(true)); try { script.run(getJellyContext(),getXMLOutput()); fail("Expected MissingAttributeException"); } catch(MissingAttributeException e) { // expected } }
public void testMultipleDefaults() throws Exception { setUpScript("testSwitchTag.jelly"); Script script = getJelly().compileScript(); getJellyContext().setVariable("multiple.defaults",new Boolean(true)); try { script.run(getJellyContext(),getXMLOutput()); fail("Expected JellyException"); } catch(JellyException e) { // expected } }
public void testNewWithNullArg() throws Exception { setUpScript("testNewTag.jelly"); Script script = getJelly().compileScript(); getJellyContext().setVariable("test.newWithNullArg",Boolean.TRUE); script.run(getJellyContext(),getXMLOutput()); assertNotNull(getJellyContext().getVariable("foo")); assertTrue(getJellyContext().getVariable("foo") instanceof Customer); Customer customer = (Customer)(getJellyContext().getVariable("foo")); assertNull(customer.getName()); }
public void testInvokeWithReturnedValueAsArg() throws Exception { setUpScript("testInvokeTag.jelly"); Script script = getJelly().compileScript(); getJellyContext().setVariable("test.invokeWithReturnedValueAsArg",Boolean.TRUE); script.run(getJellyContext(),getXMLOutput()); assertNotNull(getJellyContext().getVariable("customer")); assertTrue(getJellyContext().getVariable("customer") instanceof Customer); Customer customer = (Customer)(getJellyContext().getVariable("customer")); assertEquals("Jane Doe",customer.getName()); assertEquals("Chicago",customer.getCity()); }