Skip to content

Commit

Permalink
Merge pull request #3171 from gama-platform/GAMA_1.8.2_headless
Browse files Browse the repository at this point in the history
Gama 1.8.2 headless soft-rework
  • Loading branch information
AlexisDrogoul committed Aug 28, 2021
2 parents 0c64cc9 + 00903ea commit 124d730
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 185 deletions.
13 changes: 11 additions & 2 deletions msi.gama.core/src/msi/gama/kernel/experiment/ExperimentPlan.java
Expand Up @@ -499,13 +499,22 @@ public synchronized void open(final Double seed) {
} else if (isBatch()) {
agent.getScope().getGui().getStatus(agent.getScope())
.informStatus(isTest() ? "Tests ready. Click run to begin." : " Batch ready. Click run to begin.");
agent.getScope().getGui().updateExperimentState(agent.getScope());
agent.getScope().getGui().updateExperimentState(agent.getScope());
}
}
}

@Override
public synchronized void open() {
open(null);
Double seed = null;
if (isHeadless()) {
try {
seed = this.getAgent().getSeed();
} catch (Exception e) { // Catch no seed
seed = null;
}
}
open(seed);
}

/*
Expand Down
Expand Up @@ -2,27 +2,31 @@

import java.io.IOException;
import java.net.URL;
import java.util.List;

import com.google.inject.Injector;

import msi.gama.common.GamlFileExtension;
import msi.gama.lang.gaml.validation.GamlModelBuilder;
import ummisco.gama.dev.utils.DEBUG;

public abstract class AbstractModelLibraryRunner {

protected GamlModelBuilder createBuilder(final Injector injector) {
final GamlModelBuilder builder = new GamlModelBuilder(injector);
return builder;
return new GamlModelBuilder(injector);
}

protected boolean isModel(final URL url) {
final String file = url.getFile();
return file.endsWith(".gaml") || file.endsWith(".experiment");
return isModel(url.getFile());
}

protected boolean isModel(final String file) {
return GamlFileExtension.isGaml(file) || GamlFileExtension.isExperiment(file);
}

protected boolean isTest(final URL url) {
return isModel(url) && url.toString().contains("tests");
final String file = url.getFile();
return isModel(file) && (file.contains("test") || file.contains("Test"));
}

public abstract int start(List<String> args) throws IOException;
public abstract int start() throws IOException;
}
@@ -1,4 +1,4 @@
package msi.gama.headless.batch.validation;
package msi.gama.headless.batch;

import java.io.IOException;
import java.net.URL;
Expand All @@ -14,7 +14,6 @@
import com.google.common.collect.Multimap;
import com.google.inject.Injector;

import msi.gama.headless.batch.AbstractModelLibraryRunner;
import msi.gama.headless.core.Experiment;
import msi.gama.headless.core.HeadlessSimulationLoader;
import msi.gama.kernel.experiment.IExperimentPlan;
Expand All @@ -34,7 +33,7 @@ private ModelLibraryRunner() {
}

@Override
public int start(final List<String> args) throws IOException {
public int start() throws IOException {
final Injector injector = HeadlessSimulationLoader.getInjector();
final GamlModelBuilder builder = createBuilder(injector);
final int[] count = { 0 };
Expand Down
@@ -1,4 +1,4 @@
package msi.gama.headless.batch.test;
package msi.gama.headless.batch;

import java.io.IOException;
import java.io.OutputStream;
Expand All @@ -16,7 +16,6 @@
import com.google.inject.Injector;

import msi.gama.common.preferences.GamaPreferences;
import msi.gama.headless.batch.AbstractModelLibraryRunner;
import msi.gama.headless.core.HeadlessSimulationLoader;
import msi.gama.kernel.experiment.IExperimentPlan;
import msi.gama.kernel.experiment.ParametersSet;
Expand All @@ -33,16 +32,17 @@
public class ModelLibraryTester extends AbstractModelLibraryRunner {

private static ModelLibraryTester instance;
private final static String FAILED_PARAMETER = "-failed";

PrintStream original;
PrintStream nullStream;

private ModelLibraryTester() {}
private ModelLibraryTester() {
DEBUG.ON();
}


@Override
public int start(final List<String> args) throws IOException {
DEBUG.ON();
public int start() throws IOException {
final Injector injector = HeadlessSimulationLoader.getInjector();
final GamlModelBuilder builder = createBuilder(injector);

Expand All @@ -55,9 +55,6 @@ public void write(final int b) {
});
final int[] count = { 0 };
final int[] code = { 0 };
final boolean onlyFailed = args.contains(FAILED_PARAMETER);
final boolean oldPref = GamaPreferences.Runtime.FAILED_TESTS.getValue();
GamaPreferences.Runtime.FAILED_TESTS.set(onlyFailed);
final Multimap<Bundle, String> plugins = GamaBundleLoader.getPluginsWithTests();
final List<URL> allURLs = new ArrayList<>();
for (final Bundle bundle : plugins.keySet()) {
Expand All @@ -77,7 +74,6 @@ public void write(final int b) {
builder.loadURLs(allURLs);

allURLs.forEach(u -> test(builder, count, code, u));
GamaPreferences.Runtime.FAILED_TESTS.set(oldPref);

DEBUG.OUT("" + count[0] + " tests executed in built-in library and plugins. " + code[0] + " failed or aborted");
DEBUG.OUT(code[0]);
Expand Down
@@ -1,4 +1,4 @@
package msi.gama.headless.batch.validation;
package msi.gama.headless.batch;

import java.io.IOException;
import java.net.URL;
Expand All @@ -12,7 +12,6 @@
import com.google.common.collect.Multimap;
import com.google.inject.Injector;

import msi.gama.headless.batch.AbstractModelLibraryRunner;
import msi.gama.headless.core.HeadlessSimulationLoader;
import msi.gama.lang.gaml.validation.GamlModelBuilder;
import msi.gaml.compilation.GamlCompilationError;
Expand All @@ -28,40 +27,35 @@ private ModelLibraryValidator() {
}

@Override
public int start(final List<String> args) throws IOException {
public int start() throws IOException {

final Injector injector = HeadlessSimulationLoader.getInjector();
final GamlModelBuilder builder = createBuilder(injector);
final int[] count = { 0 };
final int[] code = { 0, 0 };
final Multimap<Bundle, String> plugins = GamaBundleLoader.getPluginsWithModels();
List<URL> allURLs = new ArrayList<>();
for (final Bundle bundle : plugins.keySet()) {
for (final String entry : plugins.get(bundle)) {
final Enumeration<URL> urls = bundle.findEntries(entry, "*", true);
if (urls != null) {
while (urls.hasMoreElements()) {
final URL url = urls.nextElement();
if (isModel(url)) {
final URL resolvedFileURL = FileLocator.toFileURL(url);
allURLs.add(resolvedFileURL);
}
}
}
}
}
builder.loadURLs(allURLs);
allURLs.forEach(u -> validate(builder, count, code, u));

this.validatePluginsFromURLs(GamaBundleLoader.getPluginsWithModels(), builder, count, code);

DEBUG.OUT("" + count[0] + " GAMA models compiled in built-in library and plugins. " + code[0]
+ " compilation errors found");

code[1] = code[0];
code[0] = 0;
count[0] = 0;
final Multimap<Bundle, String> tests = GamaBundleLoader.getPluginsWithTests();
allURLs = new ArrayList<>();
for (final Bundle bundle : tests.keySet()) {
for (final String entry : tests.get(bundle)) {

this.validatePluginsFromURLs(GamaBundleLoader.getPluginsWithTests(), builder, count, code);

DEBUG.OUT("" + count[0] + " GAMA tests compiled in built-in library and plugins. " + code[0]
+ " compilation errors found");
DEBUG.OUT(code[0] + code[1]);
return code[0] + code[1];
}

private void validatePluginsFromURLs(final Multimap<Bundle, String> pluginsURLs, final GamlModelBuilder builder,
final int[] count, final int[] code) throws IOException {
List<URL> allURLs = new ArrayList<>();
for (final Bundle bundle : pluginsURLs.keySet()) {
for (final String entry : pluginsURLs.get(bundle)) {
final Enumeration<URL> urls = bundle.findEntries(entry, "*", true);
if (urls != null) {
while (urls.hasMoreElements()) {
Expand All @@ -75,13 +69,7 @@ public int start(final List<String> args) throws IOException {
}
}
builder.loadURLs(allURLs);

allURLs.forEach(u -> validate(builder, count, code, u));

DEBUG.OUT("" + count[0] + " GAMA tests compiled in built-in library and plugins. " + code[0]
+ " compilation errors found");
DEBUG.OUT(code[0] + code[1]);
return code[0] + code[1];
}

private void validate(final GamlModelBuilder builder, final int[] countOfModelsValidated, final int[] returnCode,
Expand Down
Expand Up @@ -74,7 +74,7 @@ public class HeadlessStatement extends AbstractStatement {
private int maxSimulationID = 0;

public String getSimulationId() {
return new Integer(maxSimulationID++).toString();
return String.valueOf(maxSimulationID++);
}

public HeadlessStatement(final IDescription desc) {
Expand Down
57 changes: 40 additions & 17 deletions msi.gama.headless/src/msi/gama/headless/common/DataTypeFactory.java
Expand Up @@ -16,27 +16,50 @@ public final class DataTypeFactory {

public static DataType getObjectMetaData(final Object val) {
DataType type;
if (val instanceof Integer || val instanceof Long) {
type = DataType.INT;
} else if (val instanceof Float || val instanceof Double) {
type = DataType.FLOAT;
} else if (val instanceof Boolean) {
type = DataType.BOOLEAN;
} else if (val instanceof String) {
type = DataType.STRING;
} else {
type = DataType.UNDEFINED;

switch (val.getClass().getSimpleName()) {
case "Integer":
case "Long":
type = DataType.INT;
break;
case "Float":
case "Double":
type = DataType.FLOAT;
break;
case "Boolean":
type = DataType.BOOLEAN;
break;
case "String":
type = DataType.STRING;
break;

default:
type = DataType.UNDEFINED;
break;
}

return type;
}

public static Object getObjectFromText(final String val, final DataType t) {
if (t.equals(DataType.INT)) return Integer.valueOf(val);
if (t.equals(DataType.BOOLEAN)) return Boolean.valueOf(val);
// See #3006
if (t.equals(DataType.FLOAT)) return Double.valueOf(val);
if (t.equals(DataType.STRING)) return val;
return val;
public static Object getObjectFromText(final String val, final DataType t) {
Object result;
switch (t) {
case INT:
result = Integer.valueOf(val);
break;
case BOOLEAN:
result = Boolean.valueOf(val);
break;
case FLOAT:
result = Double.valueOf(val);
break;
case STRING:
default:
result = val;
break;
}

return result;
}

}

0 comments on commit 124d730

Please sign in to comment.