Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Merge pull request #79 from itesla/groovy_extension_renaming
Browse files Browse the repository at this point in the history
Groovy script extension refactoring
  • Loading branch information
mathbagu committed Mar 16, 2017
2 parents eb03cec + 81fea42 commit 201b0c6
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class GroovyScripts {
}

static void run(Reader codeReader, ComputationManager computationManager, Binding binding, Writer out) {
run(codeReader, computationManager, binding, new ServiceLoaderGroovyExtensionLoader(), out)
run(codeReader, computationManager, binding, ServiceLoader.load(GroovyScriptExtension.class), out)
}

static void run(Reader codeReader, ComputationManager computationManager, GroovyExtensionLoader extensionLoader, Writer out) {
run(codeReader, computationManager, new Binding(), extensionLoader, out)
static void run(Reader codeReader, ComputationManager computationManager, Iterable<GroovyScriptExtension> extensions, Writer out) {
run(codeReader, computationManager, new Binding(), extensions, out)
}

static void run(Reader codeReader, ComputationManager computationManager, Binding binding, GroovyExtensionLoader extensionLoader, Writer out) {
static void run(Reader codeReader, ComputationManager computationManager, Binding binding, Iterable<GroovyScriptExtension> extensions, Writer out) {
assert codeReader
assert computationManager
assert extensionLoader
assert extensions != null

CompilerConfiguration conf = new CompilerConfiguration()

Expand All @@ -55,7 +55,7 @@ class GroovyScripts {
}

// load extensions
extensionLoader.load(binding, computationManager)
extensions.forEach { it.load(binding, computationManager) }

GroovyShell shell = new GroovyShell(binding, conf)
shell.evaluate(codeReader)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public interface GroovyExtension {
public interface GroovyScriptExtension {

void load(Binding binding, ComputationManager computationManager);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class GroovyScriptAbstractTest {

protected abstract String getExpectedOutput();

protected List<GroovyExtension> getExtensions() {
protected List<GroovyScriptExtension> getExtensions() {
return Collections.emptyList();
}

Expand All @@ -36,7 +36,7 @@ public void test() throws IOException {
ComputationManager computationManager = Mockito.mock(ComputationManager.class);
StringWriter out = new StringWriter();
try (Reader codeReader = getCodeReader()) {
GroovyScripts.run(codeReader, computationManager, new GroovyExtensionLoaderTest(getExtensions()), out);
GroovyScripts.run(codeReader, computationManager, getExtensions(), out);
} finally {
out.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package eu.itesla_project.iidm.import_

import com.google.auto.service.AutoService
import eu.itesla_project.computation.ComputationManager
import eu.itesla_project.computation.script.GroovyExtension
import eu.itesla_project.computation.script.GroovyScriptExtension
import eu.itesla_project.iidm.network.Identifiable

import java.nio.file.FileSystem
Expand All @@ -17,8 +17,8 @@ import java.nio.file.FileSystems
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
@AutoService(GroovyExtension.class)
class ImportGroovyExtension implements GroovyExtension {
@AutoService(GroovyScriptExtension.class)
class ImportGroovyScriptExtension implements GroovyScriptExtension {

static {
Identifiable.metaClass.propertyMissing = { String name ->
Expand All @@ -34,14 +34,14 @@ class ImportGroovyExtension implements GroovyExtension {

private final ImportersLoader importersLoader

ImportGroovyExtension(FileSystem fileSystem, ImportersLoader importersLoader) {
ImportGroovyScriptExtension(FileSystem fileSystem, ImportersLoader importersLoader) {
assert fileSystem;
assert importersLoader;
this.fileSystem = fileSystem
this.importersLoader = importersLoader;
}

ImportGroovyExtension() {
ImportGroovyScriptExtension() {
this(FileSystems.getDefault(), new ImportersServiceLoader())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class IdentifiablePropertyTest {
@Before
void setUp() throws Exception {
// to force static init loading
ImportGroovyExtension.toString()
ImportGroovyScriptExtension.toString()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import eu.itesla_project.computation.script.GroovyExtension;
import eu.itesla_project.computation.script.GroovyScriptExtension;
import eu.itesla_project.computation.script.GroovyScriptAbstractTest;
import eu.itesla_project.iidm.datasource.ReadOnlyDataSource;
import eu.itesla_project.iidm.network.Network;
Expand All @@ -26,7 +26,7 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class ImportGroovyExtensionTest extends GroovyScriptAbstractTest {
public class ImportGroovyScriptExtensionTest extends GroovyScriptAbstractTest {

private FileSystem fileSystem;

Expand Down Expand Up @@ -71,8 +71,8 @@ protected String getExpectedOutput() {
}

@Override
protected List<GroovyExtension> getExtensions() {
protected List<GroovyScriptExtension> getExtensions() {
ImportersLoader loader = new ImportersLoaderList(Collections.singletonList(fooImporter), Collections.emptyList());
return Collections.singletonList(new ImportGroovyExtension(fileSystem, loader));
return Collections.singletonList(new ImportGroovyScriptExtension(fileSystem, loader));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ package eu.itesla_project.loadflow.api
import com.google.auto.service.AutoService
import eu.itesla_project.commons.config.ComponentDefaultConfig
import eu.itesla_project.computation.ComputationManager
import eu.itesla_project.computation.script.GroovyExtension
import eu.itesla_project.computation.script.GroovyScriptExtension
import eu.itesla_project.iidm.network.Network
import eu.itesla_project.loadflow.api.mock.LoadFlowFactoryMock

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
@AutoService(GroovyExtension.class)
class LoadFlowGroovyExtension implements GroovyExtension {
@AutoService(GroovyScriptExtension.class)
class LoadFlowGroovyScriptExtension implements GroovyScriptExtension {

private final LoadFlowFactory loadFlowFactory;

private final LoadFlowParameters parameters;

LoadFlowGroovyExtension(LoadFlowFactory loadFlowFactory, LoadFlowParameters parameters) {
LoadFlowGroovyScriptExtension(LoadFlowFactory loadFlowFactory, LoadFlowParameters parameters) {
assert loadFlowFactory
assert parameters
this.loadFlowFactory = loadFlowFactory
this.parameters = parameters
}

LoadFlowGroovyExtension() {
LoadFlowGroovyScriptExtension() {
this(ComponentDefaultConfig.load().newFactoryImpl(LoadFlowFactory.class),
LoadFlowParameters.load());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package eu.itesla_project.loadflow.api;

import eu.itesla_project.computation.ComputationManager;
import eu.itesla_project.computation.script.GroovyExtension;
import eu.itesla_project.computation.script.GroovyScriptExtension;
import eu.itesla_project.computation.script.GroovyScriptAbstractTest;
import eu.itesla_project.iidm.network.Network;
import org.junit.Before;
Expand All @@ -21,7 +21,7 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class LoadFlowGroovyExtensionTest extends GroovyScriptAbstractTest {
public class LoadFlowGroovyScriptExtensionTest extends GroovyScriptAbstractTest {

private LoadFlowFactory loadFlowFactory;

Expand Down Expand Up @@ -58,8 +58,8 @@ protected String getExpectedOutput() {
}

@Override
protected List<GroovyExtension> getExtensions() {
return Arrays.asList(new LoadFlowGroovyExtension(loadFlowFactory, new LoadFlowParameters()),
protected List<GroovyScriptExtension> getExtensions() {
return Arrays.asList(new LoadFlowGroovyScriptExtension(loadFlowFactory, new LoadFlowParameters()),
(binding, computationManager) -> binding.setVariable("n", fooNetwork));
}
}

0 comments on commit 201b0c6

Please sign in to comment.