Commit c76389b2 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

fix(groovy) fix provided variable visibility (#937)


Closes BS-17899
parent 7a4de056
......@@ -4,7 +4,6 @@ bin
screenshots
.pmd
*.hprof
.settings/
*.orig
*.tmp
......
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
......@@ -24,8 +24,7 @@ import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
......@@ -83,15 +82,17 @@ public class OpenH2ConsoleHandlerTest {
assertThat(path).contains("tomcat");
}
private File rootFile() throws MalformedURLException, URISyntaxException {
return new File(OpenH2ConsoleHandlerTest.class.getResource("/workspace").toURI().toURL().getFile());
private File rootFile() throws Exception {
return new File(URLDecoder
.decode(OpenH2ConsoleHandlerTest.class.getResource("/workspace").getFile(), "UTF-8"));
}
@Test
public void should_throw_FileNotFoundException_if_h2_jar_is_missing() throws Exception {
doReturn(new File(OpenH2ConsoleHandlerTest.class.getResource("/workspaceWithoutH2").toURI().toURL().getFile()))
.when(openH2ConsoleHandler)
.rootFile(repositoryAccessor);
doReturn(new File(URLDecoder.decode(OpenH2ConsoleHandlerTest.class.getResource("/workspaceWithoutH2").getFile(),
"UTF-8")))
.when(openH2ConsoleHandler)
.rootFile(repositoryAccessor);
expectedException.expect(FileNotFoundException.class);
......
......@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.bonitasoft.studio.businessobject.BusinessObjectPlugin;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
......
......@@ -101,6 +101,8 @@ public class BonitaStudioLog {
final Logger logger = getLogger(bundleId);
if (logger != null) {
logger.info(message);
}else {
System.out.println(message);
}
}
......
......@@ -22,6 +22,7 @@ import static org.bonitasoft.studio.model.process.builders.TaskBuilder.aTask;
import java.util.List;
import org.bonitasoft.engine.expression.ExpressionConstants;
import org.bonitasoft.studio.model.process.MultiInstanceType;
import org.junit.Test;
public class GroovyUtilTest {
......@@ -36,4 +37,15 @@ public class GroovyUtilTest {
ExpressionConstants.TASK_ASSIGNEE_ID.getReturnType()));
}
@Test
public void should_add_loopcounter_for_operation_context() throws Exception {
final List<ScriptVariable> bonitaVariables = GroovyUtil.getBonitaVariables(
anOperation().in(aTask().withMultiInstanceType(MultiInstanceType.STANDARD)).build(), null,
false);
assertThat(bonitaVariables).extracting("name", "type").contains(
tuple(ExpressionConstants.LOOP_COUNTER.getEngineConstantName(),
ExpressionConstants.LOOP_COUNTER.getReturnType()));
}
}
......@@ -5,14 +5,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.groovy;
......@@ -27,29 +25,29 @@ import org.eclipse.jface.viewers.ViewerFilter;
/**
* @author Romain Bioteau
*
*/
public class DisplayEngineExpressionWithName extends ViewerFilter {
private Set<String> namesToAllow;
private Set<String> namesToAllow;
public DisplayEngineExpressionWithName(String[] namesToExclude) {
this.namesToAllow = new HashSet<String>(Arrays.asList(namesToExclude)) ;
}
public DisplayEngineExpressionWithName(String[] namesToAllow) {
this.namesToAllow = new HashSet<String>(Arrays.asList(namesToAllow));
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if(element instanceof Expression){
if(((Expression) element).getType().equals(ExpressionConstants.ENGINE_CONSTANT_TYPE)){
return namesToAllow.contains(((Expression)element).getName());
}
}else if( element instanceof String){
return namesToAllow.contains(element);
}
return true ;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof Expression) {
if (((Expression) element).getType().equals(ExpressionConstants.ENGINE_CONSTANT_TYPE)) {
return namesToAllow.contains(((Expression) element).getName());
}
} else if (element instanceof String) {
return namesToAllow.contains(element);
}
return true;
}
}
......@@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Stream;
import org.bonitasoft.engine.expression.ExpressionConstants;
import org.bonitasoft.forms.server.api.IFormExpressionsAPI;
......@@ -73,6 +74,7 @@ import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
/**
......@@ -88,6 +90,14 @@ public class GroovyUtil {
private static Map<String, Expression> expressions;
private static ViewerFilter NO_FILTER = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return true;
}
};
public static ScriptVariable createScriptVariable(final SimulationData d) {
String type = Object.class.getName();
if (d instanceof SimulationBoolean) {
......@@ -238,14 +248,10 @@ public class GroovyUtil {
public static List<ExpressionConstants> getBonitaConstantsFor(
EObject context, final ViewerFilter[] filters, final boolean isPageFlowContext) {
final List<ExpressionConstants> result = new ArrayList<>();
DisplayEngineExpressionWithName engineFilter = null;
if (filters != null) {
for (final ViewerFilter f : filters) {
if (f instanceof DisplayEngineExpressionWithName) {
engineFilter = (DisplayEngineExpressionWithName) f;
}
}
}
ViewerFilter engineFilter = filters != null ? Stream.of(filters)
.filter(DisplayEngineExpressionWithName.class::isInstance)
.findFirst()
.orElse(NO_FILTER) : NO_FILTER;
result.add(ExpressionConstants.API_ACCESSOR);
result.add(ExpressionConstants.PROCESS_DEFINITION_ID);
......
......@@ -17,6 +17,8 @@ import static org.mockito.Mockito.when;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -122,8 +124,8 @@ public class BosArchiveTest {
return store;
}
private File loadArchiveFile(String filePath) {
return new File(BosArchiveTest.class.getResource(filePath).getFile());
private File loadArchiveFile(String filePath) throws UnsupportedEncodingException {
return new File(URLDecoder.decode(BosArchiveTest.class.getResource(filePath).getFile(),"UTF-8"));
}
private Repository createRepository() throws CoreException {
......
......@@ -13,6 +13,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -88,7 +90,7 @@ public class ImportConflictsCheckerTest {
.orElseThrow(() -> new Exception(fileName + " diagram not found"));
}
private Repository createRepository() throws CoreException {
private Repository createRepository() throws Exception {
final IRepositoryFileStore fileStore = mock(IRepositoryFileStore.class);
when(fileStore.getName()).thenReturn("Customer Support-2.0.proc");
......@@ -167,7 +169,7 @@ public class ImportConflictsCheckerTest {
return bosArchive;
}
private IRepositoryStore<IRepositoryFileStore> createRepositoryStore(String name) {
private IRepositoryStore<IRepositoryFileStore> createRepositoryStore(String name) throws UnsupportedEncodingException {
final IRepositoryStore<IRepositoryFileStore> store = mock(IRepositoryStore.class);
final IFolder folder = createIFolder(name);
......@@ -176,7 +178,7 @@ public class ImportConflictsCheckerTest {
return store;
}
private IFolder createIFolder(String name) {
private IFolder createIFolder(String name) throws UnsupportedEncodingException {
final IFolder folder = mock(IFolder.class);
when(folder.getName()).thenReturn(name);
final IPath path = createIPath(name);
......@@ -184,21 +186,21 @@ public class ImportConflictsCheckerTest {
return folder;
}
private IPath createIPath(String name) {
private IPath createIPath(String name) throws UnsupportedEncodingException {
final IPath path = mock(IPath.class);
final File file = createFile(name);
when(path.toFile()).thenReturn(file);
return path;
}
private File createFile(String name) {
private File createFile(String name) throws UnsupportedEncodingException {
if (Objects.equals(name, "diagrams")) {
return loadFile("/folder");
}
return loadFile("/emptyFolder");
}
private File loadFile(String filePath) {
return new File(BosArchiveTest.class.getResource(filePath).getFile());
private File loadFile(String filePath) throws UnsupportedEncodingException {
return new File(URLDecoder.decode(BosArchiveTest.class.getResource(filePath).getFile(),"UTF-8"));
}
}
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
eclipse.preferences.version=1
encoding/<project>=UTF-8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment