{"id":7224,"date":"2019-08-05T19:22:22","date_gmt":"2019-08-05T13:52:22","guid":{"rendered":"https:\/\/www.argildx.us\/?p=7224"},"modified":"2020-07-02T17:55:33","modified_gmt":"2020-07-02T12:25:33","slug":"on-deploy-scripts-an-acs-aem-commons-utility","status":"publish","type":"post","link":"https:\/\/www.argildx.us\/technology\/on-deploy-scripts-an-acs-aem-commons-utility\/","title":{"rendered":"On-Deploy Scripts \u2013 an ACS AEM Commons Utility"},"content":{"rendered":"
Developers need to perform certain tasks during deployment to AEM server. Component reauthoring is one of the major tasks for a developer making changes to existing components. In this article, we’ll talk about using on-deploy scripts<\/strong> to simplify reauthoring tasks in AEM.<\/p>\n Problem Statement:<\/u><\/strong><\/p>\n If the component is to be configured on one or two pages, then reauthoring is simple. However, if the component needs to be configured on many pages, then it’s tedious for an author to reauthor the same component on every page.<\/p>\n This is one of the scenarios in which we can use on-deploy script. Here is a list of problems we will try to solve.<\/p>\n What Problems are We Trying to Solve?<\/u><\/strong><\/p>\n Available Methodology to Solve the Above Problems<\/u><\/strong><\/p>\n Issues with Servlet or Ad-hoc Scripts<\/u><\/strong><\/p>\n ACS AEM Commons provides a useful utility called \u201cOn-Deploy Scripts,\u201d which help developers create one-time scripts that execute upon deployment to an AEM server. This feature is available for v3.15.0 <\/strong>and higher versions of ACS-AEM Commons.<\/p>\n So, to overcome this problem we can use On-Deploy Scripts.<\/p>\n Advantages of On-Deploy Scripts:<\/u><\/strong><\/p>\n On-Deploy Scripts allows developers to create one-time scripts that execute upon deployment to an AEM server. Some advantages of this one-time script creation<\/strong> feature are given below.<\/p>\n How To use:<\/u><\/strong><\/p>\n \u201ccom.adobe.acs.commons.ondeploy.impl.OnDeployExecutorImpl.xml\u201d<\/p>\n Demo:<\/u><\/strong><\/p>\n A working demo present on bitbucket https:\/\/bitbucket.org\/argildx\/aemdev-meetup-s1\/overview<\/a><\/p>\n Read our article about another ACS AEM Commons Utility, Ensure Service User<\/a><\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":" Developers need to perform certain tasks during deployment to AEM server. Component reauthoring is one of the major tasks for a developer making changes to existing components. In this article, we’ll talk about using on-deploy scripts to simplify reauthoring tasks in AEM. Problem Statement: If the component is to be configured on one or two … Read more<\/a><\/p>\n","protected":false},"author":29,"featured_media":7226,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","content-type":"","footnotes":""},"categories":[66],"tags":[1619,1620,1621],"yst_prominent_words":[1011,366,1008,1009,1012,1003,1010,1013,1001,996,1002,998,1005,1007,1000,1014,999,1006,1004,997],"acf":[],"yoast_head":"\n\n
\n
\n
\n
\n
\n
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n <jcr:root xmlns:sling=\"http:\/\/sling.apache.org\/jcr\/sling\/1.0\"\r\n xmlns:jcr=\"http:\/\/www.jcp.org\/jcr\/1.0\" jcr:primaryType=\"sling:OsgiConfig\"\/><\/pre>\n
\n
\n
@Component(immediate = true, service= OnDeployScriptProvider.class, property = { \"name =service.description\", \"value =Developer service that identifies code scripts to execute upon deployment\"})\r\npublic class OnDeployScriptProviderImpl implements OnDeployScriptProvider {\r\n\u00a0\u00a0\u00a0 @Override\r\n\u00a0\u00a0\u00a0 public List<OnDeployScript> getScripts() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return Arrays.asList(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Add Script instances here e.g. new Script1(), new Script2(), new Script3()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 );\r\n\u00a0\u00a0\u00a0 }\r\n}<\/pre>\n
\n
\n
public class ScriptUpdateProperty extends OnDeployScriptBase implements OnDeployScript {\r\n\u00a0\u00a0\u00a0 @Override\r\n\u00a0\u00a0\u00a0 protected void execute() throws Exception {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Node nodeUpdate = getOrCreateNode(\"content\/we-retail\/us\/en\/onDeployePage\/jcr:content\",\"cq:Page','cq:PageContent\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 nodeUpdate.setProperty(\"sling:resourceType\",\"weretail\/components\/structure\/page\");\r\n\u00a0\u00a0\u00a0 }}<\/pre>\n
\n