Skip to content

Commit

Permalink
Merge branch 'sgallandBranch' of https://github.com/sarl/sarl into sg…
Browse files Browse the repository at this point in the history
…allandBranch
  • Loading branch information
ngaud committed Mar 12, 2020
2 parents 2c54389 + c9f2c6a commit c54dfab
Show file tree
Hide file tree
Showing 21 changed files with 243 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ agent HelloChildAgent extends AbstractAgent{
}

on AgentSpawned {
info("AgentSpawned, agentID:" + occurrence.agentIdentifiers + " AgentType: " + occurrence.agentType)
info("AgentSpawned, agentID:" + occurrence.agentID + " AgentType: " + occurrence.agentType)
}

on AgentKilled {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ agent HolarchyManager {
uses Lifecycle, Schedules, DefaultContextInteractions, Logging

on Initialize {
/* Spawn a first holon that will in turn spawn a whole hierarchy of holons
*/
/* Spawn a first holon that will in turn spawn a whole hierarchy of holons
*/
spawn(Holon, #[])
}

Expand Down Expand Up @@ -96,12 +96,14 @@ agent Holon {
info("Create the child #" + i + " at level " + count)
/* spawn a new sub-holon (a holon inside his own internal context)
*/
childUIDs.add(spawnInContext(Holon, innerContext, count, i))
val aid = UUID::randomUUID
spawnInContextWithID(Holon, aid, innerContext, count, i)
childUIDs.add(aid)
}

/* check every seconds if he's himself the last remaining holon as member of its internal context event space
* in this case, its means that all of its members are dead, he can thus die peacefully
* TEMPORAL APPROACH TO DESTROY THE HOLARCHY not the best one, it is better to rely on event to manage the holarchy destruction see the Memberleft on clause
* in this case, its means that all of its members are dead, he can thus die peacefully
* TEMPORAL APPROACH TO DESTROY THE HOLARCHY not the best one, it is better to rely on event to manage the holarchy destruction see the Memberleft on clause
* */
// task("toto").every(1000) [
// if (innerContext.defaultSpace.participants.size == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class BoidsSimulation implements EventListener {

defaultSARLContext = kernel.startWithoutAgent

environment = kernel.startAgent(typeof(Environment), height, width)
environment = UUID::randomUUID
kernel.startAgentWithID(typeof(Environment), environment, height, width)

launchAllBoids
^space = defaultSARLContext.defaultSpace as OpenEventSpace
Expand Down Expand Up @@ -160,7 +161,8 @@ class BoidsSimulation implements EventListener {
var initialPosition = new Vector2d((Math::random - 0.5) * width, (Math::random - 0.5) * height)
var initialVitesse = new Vector2d(Math::random - 0.5, Math::random - 0.5)

var b = kernel.startAgent(typeof(Boid), environment, p, initialPosition, initialVitesse, boidName)
var b = UUID::randomUUID
kernel.startAgentWithID(typeof(Boid), b, environment, p, initialPosition, initialVitesse, boidName)
this.boidBodies.put(b, new PerceivedBoidBody(p, b, initialPosition, initialVitesse))

if (Settings::isLogActivated) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class FireworksFxViewerController extends FxViewerController {
var ^event = new SetupSettings(this.rocketQuantity, this.fireQuantity,
this.gravity, this.draw_zone.width)
if (!this.launched) {
this.launchedAgent = startAgentApplication(typeof(LaunchingArea)) [
this.launchedAgent = UUID::randomUUID
startAgentApplication(typeof(LaunchingArea), this.launchedAgent) [
^event.emitToAgents
]
this.launch_button.disable = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package io.sarl.demos.gameoflife.game

import io.sarl.core.DefaultContextInteractions
import io.sarl.core.Lifecycle
import io.sarl.core.Logging
import java.util.List
Expand All @@ -39,7 +40,7 @@ import org.arakhne.afc.vmutil.locale.Locale
*/
skill DefaultGridManagerSkill implements GridManager {

uses Lifecycle, Logging
uses Lifecycle, Logging, DefaultContextInteractions

val listeners = <EnvironmentListener>newArrayList

Expand Down Expand Up @@ -73,7 +74,8 @@ skill DefaultGridManagerSkill implements GridManager {
for (j : 0 ..< height) {
// FIXME: agents created 2 times ?
// FIXME: double agent spawning apparently come from: https://github.com/sarl/sarl/issues/525
val uuid = CellAgent.spawn
val uuid = UUID::randomUUID
CellAgent.spawnInContextWithID(uuid, defaultContext)

grid.set(i, j, Pair.of(uuid, false))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class MyAppFxViewerController extends FxViewerController {
def initialize {
// Launching of the agent-side of the application
if (!this.launched.getAndSet(true)) {
// First launch => start the agent framework with an agent of type MyAgent.
this.launchedAgent = startAgentApplication(typeof(MyAgent)) [
// First launch => start the agent framework with an agent of type MyAgent and the computed id.
val id = UUID::randomUUID
startAgentApplication(typeof(MyAgent), id) [
// TODO: Put any action that must be done after the first agent launching
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static io.sarl.examples.tests.ExamplesTestUtils.isMavenProject;
import static io.sarl.examples.tests.ExamplesTestUtils.readExtensionPointFromXml;
import static io.sarl.examples.tests.ExamplesTestUtils.readXmlNode;
import static io.sarl.examples.tests.ExamplesTestUtils.unpackFiles;
import static io.sarl.examples.tests.ExamplesTestUtils.*;
import static io.sarl.examples.tests.ExamplesTestUtils.assertFile;
import static io.sarl.examples.wizard.SarlExampleLaunchConfiguration.LAUNCH_PROPERTY_FILE;
import static io.sarl.examples.wizard.SarlExampleLaunchConfiguration.readLaunchConfigurationFromXml;
Expand All @@ -43,8 +43,10 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static io.sarl.tests.api.tools.TestUtils.*;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.stream.Stream;

Expand All @@ -55,11 +57,13 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.opentest4j.TestAbortedException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

import io.sarl.lang.compiler.batch.SarlBatchCompiler;
import io.sarl.lang.util.OutParameter;
import io.sarl.tests.api.tools.TestUtils;

/** Class for testing the examples.
*
Expand All @@ -72,6 +76,21 @@
@DisplayName("Testing all the SARL examples")
public class ExamplesTest {

private static List<File> installFiles(ExampleDescription example, File projectRoot, boolean skipIfInvalidPom) throws Exception {
// The behavior is different in Eclipse Junit and Maven surefire.
final List<File> installedFiles;
if (isEclipseRuntimeEnvironment()) {
if (skipIfInvalidPom && isMavenProject(example.sourceFolder)) {
// Pom file is not valid because Maven has not yet applied the macro replacements into the file.
throw new TestAbortedException();
}
installedFiles = copySourceFiles(projectRoot, example.sourceFolder);
} else {
installedFiles = unpackFiles(projectRoot, example.archive);
}
return installedFiles;
}

/** Replies the dynamics tests for the examples' paths.
*
* @return the dynamic tests.
Expand All @@ -91,11 +110,11 @@ public Stream<DynamicTest> path() throws Exception {
* @throws Exception in case of error for recovering the example descriptions.
*/
@TestFactory
@DisplayName("SARL Compilation")
@DisplayName("SARL compilation of archives")
public Stream<DynamicTest> compilation() throws Exception {
return dynamicTests(example -> {
final File projectRoot = createProject();
final List<File> installedFiles = unpackFiles(projectRoot, example.archive);
final File projectRoot = createProject();
final List<File> installedFiles = installFiles(example, projectRoot, true);
assertFalse(installedFiles.isEmpty(), () -> "No installed file in " + projectRoot);
if (isMavenProject(example.sourceFolder)) {
// Maven compilation
Expand All @@ -119,7 +138,7 @@ public Stream<DynamicTest> compilation() throws Exception {
public Stream<DynamicTest> launchConfiguration() throws Exception {
return dynamicTests(example -> {
final File projectRoot = createProject();
final List<File> installedFiles = unpackFiles(projectRoot, example.archive);
final List<File> installedFiles = installFiles(example, projectRoot, true);
final File launchConfiguration = new File(projectRoot, LAUNCH_PROPERTY_FILE);
assumeTrue(launchConfiguration.exists());

Expand Down Expand Up @@ -159,7 +178,7 @@ public Stream<DynamicTest> launchConfiguration() throws Exception {
public Stream<DynamicTest> fileToOpenInEditor() throws Exception {
return dynamicTests(example -> {
final File projectRoot = createProject();
final List<File> installedFiles = unpackFiles(projectRoot, example.archive);
final List<File> installedFiles = installFiles(example, projectRoot, false);
final File pluginFile = new File(DEFAULT_RELATIVE_PATH, "plugin.xml");
final Document document = readXmlContent(pluginFile);
Node node = readXmlNode(document, "plugin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,58 @@ public static List<File> unpackFiles(File root, File exampleZipFile) throws Exce
return installedFiles;
}

/** Copy the files from the given source folder into the root folder.
*
* @param root the root folder.
* @param sourceFolder the folder to copy.
* @return the list of extracted files.
* @throws Exception if cannot unpack.
* @since 0.11
*/
public static List<File> copySourceFiles(File root, File sourceFolder) throws Exception {
List<File> folders = new ArrayList<>();
if (sourceFolder.isDirectory()) {
final File absSourceFolder = sourceFolder.getAbsoluteFile().getCanonicalFile();
folders.add(sourceFolder);
while (!folders.isEmpty()) {
final File folder = folders.remove(0);
for (final File file : folder.listFiles()) {
if (file.isDirectory()) {
folders.add(file);
} else if (file.isFile()) {
if (!isIgnorableFile(file)) {
final File absFile = file.getAbsoluteFile().getCanonicalFile();
final File relPathFile = FileSystem.makeRelative(absFile, absSourceFolder);
final File targetFile = FileSystem.join(root, relPathFile);
targetFile.getParentFile().mkdirs();
FileSystem.copy(file, targetFile);
}
}
}
}
}

final List<File> installedFiles = new ArrayList<>();
folders = new ArrayList<>();
folders.add(root);
while (!folders.isEmpty()) {
final File folder = folders.remove(0);
for (final File file : folder.listFiles()) {
if (file.isDirectory()) {
folders.add(file);
} else if (file.isFile()) {
if (!isIgnorableFile(file)) {
final File relPathFile = FileSystem.makeRelative(file, root);
installedFiles.add(relPathFile);
} else {
file.delete();
}
}
}
}
return installedFiles;
}

private static boolean isIgnorableFile(File file) {
final String name = file.getName();
return ".classpath".equals(name) || ".project".equals(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ abstract class FxViewerController implements EventListener {
}

/** Start the agent application.
*
*
* @param agentType the type of the agent to launch.
* @param agentID is the identifier of the agent.
* @param whenAgentLaunched the lambda that is called when the agent is really launched.
* @since 0.11
*/
def startAgentApplication(agentType : Class<? extends Agent>,
whenAgentLaunched : () => void) {
def startAgentApplication(agentType : Class<? extends Agent>, agentID : UUID = null, whenAgentLaunched : ()=>void) {
var bootstrap = SRE::bootstrap
if (!bootstrap.active) {
throw new IllegalStateException(Messages::FxViewerController_0)
Expand All @@ -115,11 +116,15 @@ abstract class FxViewerController implements EventListener {
this.globalSpace = context.defaultSpace as OpenEventSpace
this.UISpace = context.createSpace(typeof(OpenEventSpaceSpecification), ID)
new LaunchingCallback(ID, this.globalSpace, whenAgentLaunched)
bootstrap.startAgent(agentType, this)
if (agentID !== null) {
bootstrap.startAgentWithID(agentType, agentID, this)
} else {
bootstrap.startAgent(agentType, this)
}
}

/** Catch exit event from JavaFX. Stop the agents and the JavaFX user interface.
*
*
* @param event the JavaFx event that is the source of the exit.
*/
@FXML
Expand Down
66 changes: 33 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,24 @@
<!-- ======================================= -->

<properties>
<!-- Java Configuration for compiling this project (useful for the SARL development team) -->
<!-- Java Configuration for compiling this project (useful for the SARL
development team) -->
<sarl-dsl.min.jdk.version>1.8</sarl-dsl.min.jdk.version>
<sarl-dsl.min.jre.environment>JavaSE-${sarl-dsl.min.jdk.version}</sarl-dsl.min.jre.environment>
<sarl-dsl.max.jdk.version>1.8</sarl-dsl.max.jdk.version>
<sarl-dsl.next.unsupported.jdk.version>1.9</sarl-dsl.next.unsupported.jdk.version>

<!-- Java Configuration for running the SARL tools (IDE, sarlc, sarldoc...):
***********
* CAUTION *
***********
The versions below must include the versions for the properties "sarl-dsl.*"
-->
<!-- Java Configuration for running the SARL tools (IDE, sarlc, sarldoc...):
*********** * CAUTION * *********** The versions below must include the versions
for the properties "sarl-dsl.*" -->
<sarl-run.min.jdk.version>1.8</sarl-run.min.jdk.version>
<sarl-run.min.jre.environment>JavaSE-${sarl-run.min.jdk.version}</sarl-run.min.jre.environment>
<sarl-run.max.jdk.version>11</sarl-run.max.jdk.version>
<sarl-run.next.unsupported.jdk.version>12</sarl-run.next.unsupported.jdk.version>

<!-- Java Configuration that should be used by the projects compiled with SARL IDE or sarlc:
***********
* CAUTION *
***********
The versions below must include the versions for the properties "sarl-run.*"
-->
<!-- Java Configuration that should be used by the projects compiled with
SARL IDE or sarlc: *********** * CAUTION * *********** The versions below
must include the versions for the properties "sarl-run.*" -->
<user.min.jdk.version>1.8</user.min.jdk.version>
<user.min.jre.environment>JavaSE-${user.min.jdk.version}</user.min.jre.environment>
<user.max.jdk.version>11</user.max.jdk.version>
Expand Down Expand Up @@ -808,6 +803,25 @@
<version>${junit5.version}</version>
</dependency>
</dependencies>
<configuration>
<statelessTestsetReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
<usePhrasedFileName>false</usePhrasedFileName>
<usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
<usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
<usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
</statelessTestsetReporter>
<consoleOutputReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5ConsoleOutputReporter">
<usePhrasedFileName>false</usePhrasedFileName>
</consoleOutputReporter>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter">
<usePhrasedFileName>false</usePhrasedFileName>
<usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
<usePhrasedClassNameInTestCaseSummary>true</usePhrasedClassNameInTestCaseSummary>
</statelessTestsetInfoReporter>
</configuration>
</plugin>

<plugin>
Expand Down Expand Up @@ -1372,26 +1386,12 @@
</profiles>

<repositories>
<!--<repository>
<id>org.eclipse.xtext-snapshot</id>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>-->
<!--<repository>
<id>org.arakhne-snapshot</id>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
<url>http://download.tuxfamily.org/arakhne/maven</url>
</repository>-->
<!--<repository> <id>org.eclipse.xtext-snapshot</id> <snapshots> <enabled>true</enabled>
</snapshots> <releases> <enabled>true</enabled> </releases> <url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository> -->
<!--<repository> <id>org.arakhne-snapshot</id> <snapshots> <enabled>true</enabled>
</snapshots> <releases> <enabled>true</enabled> </releases> <url>http://download.tuxfamily.org/arakhne/maven</url>
</repository> -->
</repositories>

</project>

0 comments on commit c54dfab

Please sign in to comment.