You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2018/11/13 05:03:52 UTC
svn commit: r1846485 - in /ofbiz/ofbiz-framework/trunk: ./
framework/base/ant-scripts/ framework/base/config/
framework/base/groovyScript/ framework/base/groovyScripts/
framework/base/src/main/java/org/apache/ofbiz/base/util/
framework/base/testdef/ fr...
Author: jleroux
Date: Tue Nov 13 05:03:51 2018
New Revision: 1846485
URL: http://svn.apache.org/viewvc?rev=1846485&view=rev
Log:
Improved: Clean some Groovy files in base component
(OFBIZ-10646)
Following discussion at https://markmail.org/message/y3izmnxd7jd6jbkf
this cleans some Groovy files in the base component, notably:
* remove ant-scripts folder and its content.
* Rename framework/base/groovyScript to framework/base/groovyScripts;
* Move GroovyInit.groovy and GroovyServiceTest.groovy respectively to
framework/base/groovyScripts and framework/common/groovyScripts
and change their paths where used.
* Removes GroovyInit.groovy from excludedConfigFiles in build.gradle
* After OFBIZ-10611 it's possible to move GroovyBaseScript.groovy from
framework/service/src/main/java/org/apache/ofbiz/service/engine
to
framework/service/src/main/groovy/org/apache/ofbiz/service/engine
* Removes FileUtilTests.groovy from basetests.xml (missed it in OFBIZ-10611)
* Fixes a typo in test-suite.xsd
Added:
ofbiz/ofbiz-framework/trunk/framework/base/groovyScripts/
- copied from r1846484, ofbiz/ofbiz-framework/trunk/framework/base/groovyScript/
ofbiz/ofbiz-framework/trunk/framework/base/groovyScripts/GroovyInit.groovy
- copied unchanged from r1846391, ofbiz/ofbiz-framework/trunk/framework/base/config/GroovyInit.groovy
ofbiz/ofbiz-framework/trunk/framework/common/groovyScripts/GroovyServiceTest.groovy
- copied unchanged from r1846484, ofbiz/ofbiz-framework/trunk/framework/common/minilang/GroovyServiceTest.groovy
ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/
ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/
ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/
ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/
ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/
ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/
ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy (with props)
Removed:
ofbiz/ofbiz-framework/trunk/framework/base/ant-scripts/
ofbiz/ofbiz-framework/trunk/framework/base/config/GroovyInit.groovy
ofbiz/ofbiz-framework/trunk/framework/base/groovyScript/
ofbiz/ofbiz-framework/trunk/framework/common/minilang/GroovyServiceTest.groovy
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
Modified:
ofbiz/ofbiz-framework/trunk/build.gradle
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java
ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml
ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_test.xml
ofbiz/ofbiz-framework/trunk/framework/testtools/dtd/test-suite.xsd
Modified: ofbiz/ofbiz-framework/trunk/build.gradle
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/build.gradle?rev=1846485&r1=1846484&r2=1846485&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/build.gradle (original)
+++ ofbiz/ofbiz-framework/trunk/build.gradle Tue Nov 13 05:03:51 2018
@@ -221,7 +221,6 @@ def excludedConfigFiles = [
'*.txt',
'*.jks',
'fop.xconf',
- 'GroovyInit.groovy',
'MiniLang.xslt',
'AutoImportTemplate.ftl',
'axis2',
Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java?rev=1846485&r1=1846484&r2=1846485&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java Tue Nov 13 05:03:51 2018
@@ -63,7 +63,7 @@ public class GroovyUtil {
* the workaround is to execute at startup a script containing the @BaseScript annotation.
*/
try {
- GroovyUtil.runScriptAtLocation("ofbizhome://framework/base/config/GroovyInit.groovy", null, null);
+ GroovyUtil.runScriptAtLocation("ofbizhome://framework/base/groovyScripts/GroovyInit.groovy", null, null);
} catch (Exception e) {
Debug.logWarning("The following error occurred during the initialization of Groovy: " + e.getMessage(), module);
}
Modified: ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml?rev=1846485&r1=1846484&r2=1846485&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/testdef/basetests.xml Tue Nov 13 05:03:51 2018
@@ -43,7 +43,6 @@
<junit-test-suite class-name="org.apache.ofbiz.base.test.BaseUnitTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilPropertiesTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilXmlTests"/>
- <groovy-test-suite name="simple" location="component://base/groovyScript/test/SimpleTests.groovy"/>
- <groovy-test-suite name="fileUtil" location="component://base/groovyScript/test/FileUtilTests.groovy"/>
+ <groovy-test-suite name="simple" location="component://base/groovyScripts/test/SimpleTests.groovy"/>
</test-group>
</test-suite>
Modified: ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_test.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_test.xml?rev=1846485&r1=1846484&r2=1846485&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_test.xml (original)
+++ ofbiz/ofbiz-framework/trunk/framework/common/servicedef/services_test.xml Tue Nov 13 05:03:51 2018
@@ -151,25 +151,25 @@ under the License.
<attribute name="result" type="String" mode="OUT"/>
</service>
- <service name="testGroovy" engine="groovy" location="component://common/minilang/GroovyServiceTest.groovy" invoke="">
+ <service name="testGroovy" engine="groovy" location="component://common/groovyScripts/GroovyServiceTest.groovy" invoke="">
<description>Test Groovy Script Service</description>
<attribute name="message" type="String" mode="IN" optional="true"/>
<attribute name="result" type="String" mode="OUT"/>
</service>
- <service name="testGroovyMethod" engine="groovy" location="component://common/minilang/GroovyServiceTest.groovy" invoke="testMethod">
+ <service name="testGroovyMethod" engine="groovy" location="component://common/groovyScripts/GroovyServiceTest.groovy" invoke="testMethod">
<description>Test Groovy Script Service Method Invocation</description>
<attribute name="message" type="String" mode="IN" optional="true"/>
<attribute name="result" type="String" mode="OUT"/>
</service>
- <service name="testScriptEngineGroovy" engine="script" location="component://common/minilang/GroovyServiceTest.groovy" invoke="">
+ <service name="testScriptEngineGroovy" engine="script" location="component://common/groovyScripts/GroovyServiceTest.groovy" invoke="">
<description>Test Script Engine With Groovy Script</description>
<attribute name="message" type="String" mode="IN" optional="true"/>
<attribute name="result" type="String" mode="OUT"/>
</service>
- <service name="testScriptEngineGroovyMethod" engine="script" location="component://common/minilang/GroovyServiceTest.groovy" invoke="testMethod">
+ <service name="testScriptEngineGroovyMethod" engine="script" location="component://common/groovyScripts/GroovyServiceTest.groovy" invoke="testMethod">
<description>Test Script Engine With Groovy Script Method Invocation</description>
<attribute name="message" type="String" mode="IN" optional="true"/>
<attribute name="result" type="String" mode="OUT"/>
Added: ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy?rev=1846485&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy (added)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy Tue Nov 13 05:03:51 2018
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.apache.ofbiz.service.engine
+
+import java.util.Map
+
+import org.apache.ofbiz.base.util.Debug
+import org.apache.ofbiz.entity.util.EntityQuery
+import org.apache.ofbiz.service.DispatchContext
+import org.apache.ofbiz.service.LocalDispatcher
+import org.apache.ofbiz.service.ModelService
+import org.apache.ofbiz.service.ServiceUtil
+import org.apache.ofbiz.service.ExecutionServiceException
+import org.apache.ofbiz.entity.GenericValue
+
+abstract class GroovyBaseScript extends Script {
+ public static final String module = GroovyBaseScript.class.getName()
+
+ Map runService(String serviceName, Map inputMap) throws ExecutionServiceException {
+ LocalDispatcher dispatcher = binding.getVariable('dispatcher');
+ DispatchContext dctx = dispatcher.getDispatchContext();
+ if (!inputMap.userLogin) {
+ inputMap.userLogin = this.binding.getVariable('parameters').userLogin
+ }
+ if (!inputMap.timeZone) {
+ inputMap.timeZone = this.binding.getVariable('parameters').timeZone
+ }
+ if (!inputMap.locale) {
+ inputMap.locale = this.binding.getVariable('parameters').locale
+ }
+ Map serviceContext = dctx.makeValidContext(serviceName, ModelService.IN_PARAM, inputMap)
+ Map result = dispatcher.runSync(serviceName, serviceContext)
+ if (ServiceUtil.isError(result)) {
+ throw new ExecutionServiceException(ServiceUtil.getErrorMessage(result))
+ }
+ return result
+ }
+
+ Map run(Map args) throws ExecutionServiceException {
+ return runService((String)args.get('service'), (Map)args.get('with', new HashMap()))
+ }
+
+ Map makeValue(String entityName) throws ExecutionServiceException {
+ return result = binding.getVariable('delegator').makeValue(entityName)
+ }
+
+ Map makeValue(String entityName, Map inputMap) throws ExecutionServiceException {
+ return result = binding.getVariable('delegator').makeValidValue(entityName, inputMap)
+ }
+
+ EntityQuery from(def entity) {
+ return EntityQuery.use(binding.getVariable('delegator')).from(entity)
+ }
+
+ EntityQuery select(String... fields) {
+ return EntityQuery.use(binding.getVariable('delegator')).select(fields)
+ }
+
+ EntityQuery select(Set<String> fields) {
+ return EntityQuery.use(binding.getVariable('delegator')).select(fields)
+ }
+
+ @Deprecated
+ GenericValue findOne(String entityName, Map<String, ? extends Object> fields, boolean useCache) {
+ return from(entityName).where(fields).cache(useCache).queryOne()
+ }
+
+ def success(String message) {
+ // TODO: implement some clever i18n mechanism based on the userLogin and locale in the binding
+ if (this.binding.hasVariable('request')) {
+ // the script is invoked as an "event"
+ if (message) {
+ this.binding.getVariable('request').setAttribute("_EVENT_MESSAGE_", message)
+ }
+ return 'success'
+ } else {
+ // the script is invoked as a "service"
+ if (message) {
+ return ServiceUtil.returnSuccess(message)
+ } else {
+ return ServiceUtil.returnSuccess()
+ }
+ }
+ }
+ Map failure(String message) {
+ // TODO: implement some clever i18n mechanism based on the userLogin and locale in the binding
+ if (message) {
+ return ServiceUtil.returnFailure(message)
+ } else {
+ return ServiceUtil.returnFailure()
+ }
+ }
+ def error(String message) {
+ // TODO: implement some clever i18n mechanism based on the userLogin and locale in the binding
+ if (this.binding.hasVariable('request')) {
+ // the script is invoked as an "event"
+ if (message) {
+ this.binding.getVariable('request').setAttribute("_ERROR_MESSAGE_", message)
+ }
+ return 'error'
+ } else {
+ if (message) {
+ return ServiceUtil.returnError(message)
+ } else {
+ return ServiceUtil.returnError()
+ }
+ }
+ }
+ def logInfo(String message) {
+ Debug.logInfo(message, module)
+ }
+ def logWarning(String message) {
+ Debug.logWarning(message, module)
+ }
+ def logError(String message) {
+ Debug.logError(message, module)
+ }
+
+ def logVerbose(String message) {
+ Debug.logVerbose(message, module)
+ }
+}
Propchange: ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange: ofbiz/ofbiz-framework/trunk/framework/service/src/main/groovy/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: ofbiz/ofbiz-framework/trunk/framework/testtools/dtd/test-suite.xsd
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/testtools/dtd/test-suite.xsd?rev=1846485&r1=1846484&r2=1846485&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/testtools/dtd/test-suite.xsd (original)
+++ ofbiz/ofbiz-framework/trunk/framework/testtools/dtd/test-suite.xsd Tue Nov 13 05:03:51 2018
@@ -102,7 +102,7 @@ under the License.
<xs:annotation>
<xs:documentation>
Give the location where is groovy file that contaions the test suite.
- You can use a flexible url location like component://mycomponent/groovyScript/test/MySuiteTest.groovy
+ You can use a flexible url location like component://mycomponent/groovyScripts/test/MySuiteTest.groovy
</xs:documentation>
</xs:annotation>
</xs:attribute>