From 8e9b07dd6c66787507a22a049f9100a43a2932b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Galland?= Date: Sun, 7 May 2017 11:32:05 +0200 Subject: [PATCH] [contribs] Transform 'example' module tests from Tycho to Maven testing modules. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit see #616 Signed-off-by: Stéphane Galland --- .../demos/basic/inheritance/inheritance.sarl | 2 +- .../META-INF/MANIFEST.MF | 16 - .../OSGI-INF/l10n/bundle.properties | 2 - .../io.sarl.examples.tests/build.properties | 10 - .../io.sarl.examples.tests/pom.xml | 57 +-- .../io/sarl/examples/tests/ExamplesTest.java | 341 ------------------ .../io/sarl/examples/tests/ExamplesTest.java | 268 ++++++++++++++ contribs/io.sarl.examples/pom.xml | 2 +- tests/pom.xml | 7 +- 9 files changed, 292 insertions(+), 413 deletions(-) delete mode 100644 contribs/io.sarl.examples/io.sarl.examples.tests/META-INF/MANIFEST.MF delete mode 100644 contribs/io.sarl.examples/io.sarl.examples.tests/OSGI-INF/l10n/bundle.properties delete mode 100644 contribs/io.sarl.examples/io.sarl.examples.tests/build.properties delete mode 100644 contribs/io.sarl.examples/io.sarl.examples.tests/src/io/sarl/examples/tests/ExamplesTest.java create mode 100644 contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTest.java diff --git a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-behaviorinheritance/src/main/sarl/io/sarl/demos/basic/inheritance/inheritance.sarl b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-behaviorinheritance/src/main/sarl/io/sarl/demos/basic/inheritance/inheritance.sarl index e0d2f577ec..4700424b4b 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-behaviorinheritance/src/main/sarl/io/sarl/demos/basic/inheritance/inheritance.sarl +++ b/contribs/io.sarl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-basic-behaviorinheritance/src/main/sarl/io/sarl/demos/basic/inheritance/inheritance.sarl @@ -16,7 +16,7 @@ agent AbstractAgent { uses Logging - var i : int = 0; + protected var i : int = 0; on Initialize { info("1: Hello World in the super agent!") diff --git a/contribs/io.sarl.examples/io.sarl.examples.tests/META-INF/MANIFEST.MF b/contribs/io.sarl.examples/io.sarl.examples.tests/META-INF/MANIFEST.MF deleted file mode 100644 index 405c4ffe01..0000000000 --- a/contribs/io.sarl.examples/io.sarl.examples.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,16 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %Bundle-Name -Bundle-SymbolicName: io.sarl.examples.tests;singleton:=true -Bundle-Version: 0.6.0.qualifier -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Bundle-ActivationPolicy: lazy -Require-Bundle: io.sarl.examples.plugin;bundle-version="0.6.0", - io.sarl.tests.api;bundle-version="0.6.0", - io.sarl.tests.testdata;bundle-version="0.6.0", - org.eclipse.core.resources;bundle-version="3.11.1", - org.eclipse.core.runtime;bundle-version="3.12.0", - org.eclipse.jdt.core;bundle-version="3.12.3", - org.arakhne.afc.core.vmutils;bundle-version="14.0.0" -Export-Package: io.sarl.examples.tests - diff --git a/contribs/io.sarl.examples/io.sarl.examples.tests/OSGI-INF/l10n/bundle.properties b/contribs/io.sarl.examples/io.sarl.examples.tests/OSGI-INF/l10n/bundle.properties deleted file mode 100644 index c0dd05c8bc..0000000000 --- a/contribs/io.sarl.examples/io.sarl.examples.tests/OSGI-INF/l10n/bundle.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Properties file for io.sarl.examples.tests -Bundle-Name = io.sarl.examples.tests \ No newline at end of file diff --git a/contribs/io.sarl.examples/io.sarl.examples.tests/build.properties b/contribs/io.sarl.examples/io.sarl.examples.tests/build.properties deleted file mode 100644 index 860909d764..0000000000 --- a/contribs/io.sarl.examples/io.sarl.examples.tests/build.properties +++ /dev/null @@ -1,10 +0,0 @@ -source.. = src/ -bin.includes = META-INF/,\ - .,\ - OSGI-INF/,\ - OSGI-INF/l10n/bundle.properties -jre.compilation.profile = JavaSE-1.8 -#The line below is essential to enable Tycho to compile with Maven a project depending on a eclipse fragment -#You must list the corresponding fragment below -#In out case we have com.google.inject.multibindings fragments of com.google.inject -extra.. = platform:/fragment/com.google.inject.multibindings diff --git a/contribs/io.sarl.examples/io.sarl.examples.tests/pom.xml b/contribs/io.sarl.examples/io.sarl.examples.tests/pom.xml index 20923ebfe9..9f526285fd 100644 --- a/contribs/io.sarl.examples/io.sarl.examples.tests/pom.xml +++ b/contribs/io.sarl.examples/io.sarl.examples.tests/pom.xml @@ -8,46 +8,25 @@ io.sarl.examples.tests - eclipse-test-plugin Example Tests - - - 512M - - - - - tycho-surefire-plugin-macosx-jvm-flags - - - mac - - - - -XstartOnFirstThread - - - - - - - - org.eclipse.tycho - tycho-surefire-plugin - ${tycho.version} - - true - false - alphabetical - io.sarl.eclipse.io_sarl_lang_product - org.eclipse.ui.ide.workbench - -Xms256M -Xmx${tycho-surefire-plugin-max-memory} -XX:+CMSClassUnloadingEnabled -ea ${tycho-surefire-plugin-os-jvm-flags} - true - false - - - - + + + io.sarl + io.sarl.tests.api + test + + + io.sarl.maven + io.sarl.maven.sdk + test + + + io.sarl.examples + io.sarl.examples.plugin + ${sarl.version} + test + + diff --git a/contribs/io.sarl.examples/io.sarl.examples.tests/src/io/sarl/examples/tests/ExamplesTest.java b/contribs/io.sarl.examples/io.sarl.examples.tests/src/io/sarl/examples/tests/ExamplesTest.java deleted file mode 100644 index 5ff4b6ce0a..0000000000 --- a/contribs/io.sarl.examples/io.sarl.examples.tests/src/io/sarl/examples/tests/ExamplesTest.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * $Id$ - * - * SARL is an general-purpose agent programming language. - * More details on http://www.sarl.io - * - * Copyright (C) 2014-2017 the original authors or authors. - * - * Licensed 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 io.sarl.examples.tests; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import com.google.common.collect.Iterables; -import com.google.inject.Injector; -import org.arakhne.afc.vmutil.FileSystem; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.emf.common.util.Diagnostic; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.util.Diagnostician; -import org.junit.Assume; -import org.junit.ComparisonFailure; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.osgi.framework.Bundle; - -import io.sarl.lang.sarl.SarlScript; -import io.sarl.lang.ui.internal.LangActivator; -import io.sarl.tests.api.AbstractSarlUiTest; - -/** Class for testing the examples. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - */ -@RunWith(Parameterized.class) -public class ExamplesTest extends AbstractSarlUiTest { - - private final Injector injector; - - private final Bundle bundle; - - private final String name; - - private final URL exampleArchive; - - private final String exampleTargetFolder; - - /** Constructor. - * - * @param bundle the source bundle. - * @param name the name of the test. - * @param exampleArchive the archive file to open. - * @param exampleTargetFolder the target folder to copy inside. - */ - public ExamplesTest(Bundle bundle, String name, URL exampleArchive, String exampleTargetFolder) { - this.injector = LangActivator.getInstance().getInjector("io.sarl.lang.SARL"); //$NON-NLS-1$ - this.bundle = bundle; - this.name = name; - this.exampleArchive = exampleArchive; - this.exampleTargetFolder = exampleTargetFolder; - this.injector.injectMembers(this); - } - - @Override - public String toString() { - return this.name; - } - - /** Replies the bundle of the examples. - * - * @return the bundle. - */ - protected Bundle getExampleBundle() { - return this.bundle; - } - - /** Replies the archives for the examples. - * - * @return the archive locations. - * @throws Exception in case of error. - */ - @Parameters(name = "Example {1}") - public static Collection getExampleArchives() throws Exception { - final Bundle bundle = Platform.getBundle("io.sarl.examples.plugin"); //$NON-NLS-1$ - if (bundle == null) { - throw new Exception("Bundle not found"); //$NON-NLS-1$ - } - - final Set names = new TreeSet<>(); - final Map rawSources = new TreeMap<>(); - - final Enumeration exampleSources = bundle.getEntryPaths("projects"); //$NON-NLS-1$ - if (exampleSources != null) { - while (exampleSources.hasMoreElements()) { - final String example = exampleSources.nextElement(); - URL url = bundle.getResource(example); - if (url != null) { - final String name = Path.fromPortableString(example).lastSegment(); - rawSources.putIfAbsent(name, example); - names.add(name); - } - } - } - - final Map archiveSources = new TreeMap<>(); - - final Enumeration exampleArchives = bundle.getEntryPaths("contents"); //$NON-NLS-1$ - if (exampleArchives != null) { - while (exampleArchives.hasMoreElements()) { - final String example = exampleArchives.nextElement(); - if (example.endsWith(".zip")) { //$NON-NLS-1$ - final URL url = bundle.getResource(example); - if (url != null) { - final String name = Path.fromPortableString(url.getPath()).removeFileExtension().lastSegment(); - archiveSources.putIfAbsent(name, url); - names.add(name); - } - } - } - } - - if (names.isEmpty()) { - throw new Exception("no test found"); //$NON-NLS-1$ - } - - final List list = new ArrayList<>(); - - for (final String name : names) { - final URL url = archiveSources.get(name); - final String path = rawSources.get(name); - list.add(new Object[] {bundle, name, url, path}); - } - - return list; - } - - /** Run the test for the archive. - * - * @throws Exception in case of error. - */ - @Test - public void archive() throws Exception { - Assume.assumeTrue(this.exampleArchive != null && this.exampleTargetFolder == null); - final IProject project = stage0(); - List installedFiles = decompress(); - Iterable sarlFiles = stage1(project, installedFiles); - assertNoErrors(sarlFiles); - } - - /** Run the test for the archive. - * - * @throws Exception in case of error. - */ - @Test - public void path() throws Exception { - Assume.assumeTrue(this.exampleTargetFolder != null); - final IProject project = stage0(); - List installedFiles = copy(); - Iterable sarlFiles = stage1(project, installedFiles); - assertNoErrors(sarlFiles); - } - - /** Copy the given folder. - * - * @return the extracted files. - * @throws Exception in case of error. - */ - private List copy() throws Exception { - final List result = new ArrayList<>(); - final List folders = new ArrayList<>(); - folders.add(this.exampleTargetFolder); - while (!folders.isEmpty()) { - final String folder = folders.remove(0); - final Enumeration enumeration = this.bundle.getEntryPaths(folder); - while (enumeration.hasMoreElements()) { - final String member = enumeration.nextElement(); - URL url = this.bundle.getResource(member); - if (url != null) { - url = FileLocator.toFileURL(FileLocator.resolve(url)); - if (url != null && "file".equals(url.getProtocol())) { //$NON-NLS-1$ - final IPath targetPath = Path.fromPortableString(member).removeFirstSegments(1); - final File file = FileSystem.convertURLToFile(url); - if (file.isDirectory()) { - folders.add(member); - } else if (file.isFile()) { - final IFile targetFile = helper().getFile(targetPath); - if (!isIgnorableFile(targetFile)) { - try (InputStream inputStream = url.openStream()) { - try (UncloseableInputStream ustream = new UncloseableInputStream(inputStream)) { - helper().createFileImpl(targetFile, ustream); - } - } - result.add(targetFile); - } - } - } - } - } - } - return result; - } - - private static boolean isIgnorableFile(IFile file) { - final String name = file.getName(); - return ".classpath".equals(name) || ".project".equals(name); //$NON-NLS-1$ //$NON-NLS-2$ - } - - private IProject stage0() throws Exception { - return helper().getProject(this.name, true); - } - - private Iterable stage1(IProject project, Iterable installedFiles) throws Exception { - project.refreshLocal(100, null); - project.build(IncrementalProjectBuilder.CLEAN_BUILD, null); - helper().awaitAutoBuild(); - return Iterables.filter( - installedFiles, - (it) -> "sarl".equals(it.getFileExtension())); //$NON-NLS-1$ - } - - /** Uncompress the given file. - * - * @return the extracted files. - * @throws Exception in case of error. - */ - private List decompress() throws Exception { - final List result = new ArrayList<>(); - try (final InputStream inputStream = this.exampleArchive.openStream()) { - try (final ZipInputStream zipInputStream = new ZipInputStream(inputStream)) { - ZipEntry entry = zipInputStream.getNextEntry(); - while (entry != null) { - if (!entry.isDirectory()) { - final IFile currentFile = helper().getFileInRoot(this.name, entry.getName()); - if (!isIgnorableFile(currentFile)) { - try (UncloseableInputStream ustream = new UncloseableInputStream(zipInputStream)) { - helper().createFileImpl(currentFile, ustream); - } - result.add(currentFile); - } - } - entry = zipInputStream.getNextEntry(); - } - } - } - return result; - } - - private void assertNoErrors(Iterable sarlFiles) throws Exception { - final StringBuilder errorDescription = new StringBuilder(); - - assertNotNull(sarlFiles); - assertTrue(sarlFiles.iterator().hasNext()); - - for (final IFile decompressedFile : sarlFiles) { - final SarlScript script = helper().sarlScript(decompressedFile); - final Resource resource = script.eResource(); - assertTrue(decompressedFile.toString() + ": " + //$NON-NLS-1$ - resource.getErrors().toString(), resource.getErrors().isEmpty()); - final Diagnostic diagnostic = Diagnostician.INSTANCE.validate(script); - if (diagnostic.getSeverity() == Diagnostic.ERROR) { - final List diags = new ArrayList<>(); - diags.add(diagnostic); - while (!diags.isEmpty()) { - final Diagnostic diag = diags.remove(0); - if (diag.getSeverity() == Diagnostic.ERROR) { - if (diag.getChildren().isEmpty()) { - errorDescription.append(diag.toString()).append("\nFile: "); //$NON-NLS-1$ - errorDescription.append(decompressedFile).append("\n------\n"); //$NON-NLS-1$ - } else { - diags.addAll(diag.getChildren()); - } - } - } - } - } - if (errorDescription.length() > 0) { - throw new ComparisonFailure("Compilation error(s) found", "", errorDescription.toString()); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** Stream that cannot be closed. - * - * @author $Author: sgalland$ - * @version $FullVersion$ - * @mavengroupid $GroupId$ - * @mavenartifactid $ArtifactId$ - */ - private static class UncloseableInputStream extends FilterInputStream { - - UncloseableInputStream(InputStream stream) { - super(stream); - } - - @Override - public void close() throws IOException { - // - } - } - -} diff --git a/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTest.java b/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTest.java new file mode 100644 index 0000000000..f4adef4518 --- /dev/null +++ b/contribs/io.sarl.examples/io.sarl.examples.tests/src/test/java/io/sarl/examples/tests/ExamplesTest.java @@ -0,0 +1,268 @@ +/* + * $Id$ + * + * SARL is an general-purpose agent programming language. + * More details on http://www.sarl.io + * + * Copyright (C) 2014-2017 the original authors or authors. + * + * Licensed 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 io.sarl.examples.tests; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +import com.google.inject.Injector; +import org.apache.log4j.Level; +import org.arakhne.afc.vmutil.ClasspathUtil; +import org.arakhne.afc.vmutil.FileSystem; +import org.eclipse.xtext.diagnostics.Severity; +import org.eclipse.xtext.util.Strings; +import org.junit.Assume; +import org.junit.BeforeClass; +import org.junit.ComparisonFailure; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import io.sarl.lang.SARLStandaloneSetup; +import io.sarl.lang.SARLVersion; +import io.sarl.lang.compiler.batch.SarlBatchCompiler; +import io.sarl.tests.api.AbstractSarlTest; + +/** Class for testing the examples. + * + * @author $Author: sgalland$ + * @version $FullVersion$ + * @mavengroupid $GroupId$ + * @mavenartifactid $ArtifactId$ + */ +@RunWith(Parameterized.class) +@SuppressWarnings("all") +public class ExamplesTest extends AbstractSarlTest { + + /** Name of the property that contains the root path for the project to test. + */ + public static final String ROOT_TEST_FOLDER_PROPERTY = "io.sarl.examples.test.rootDir"; //$NON-NLS-1$ + + private static final File DEFAULT_RELATIVE_PATH = FileSystem.convertStringToFile("file:../io.sarl.examples.plugin"); //$NON-NLS-1$ + + private static final String PROJECTS_FOLDER_NAME = "projects"; //$NON-NLS-1$ + + /** Replies the archives for the examples. + * + * @return the archive locations. + * @throws Exception in case of error. + */ + @Parameters(name = "Example {1}") + public static Collection getExampleArchives() throws Exception { + final Set names = new TreeSet<>(); + final Map rawSources = new TreeMap<>(); + + File rootPath = null; + final String projectdir = System.getProperty(ROOT_TEST_FOLDER_PROPERTY); + if (!Strings.isEmpty(projectdir)) { + rootPath = FileSystem.convertStringToFile(projectdir); + } + if (rootPath == null) { + rootPath = DEFAULT_RELATIVE_PATH; + } + + final File projectFolder = new File(rootPath, PROJECTS_FOLDER_NAME); + if (projectFolder.isDirectory()) { + for (File child : projectFolder.listFiles()) { + if (child.isDirectory()) { + final String basename = child.getName(); + rawSources.putIfAbsent(basename, child); + names.add(basename); + } + } + } + + if (names.isEmpty()) { + throw new Exception("no test found"); //$NON-NLS-1$ + } + + final List list = new ArrayList<>(); + + for (final String name : names) { + final File folder = rawSources.get(name); + list.add(new Object[] {name, folder}); + } + + return list; + } + + private final String name; + + private final File exampleFolder; + + static SarlBatchCompiler compiler; + + /** Constructor. + * + * @param name the name of the test. + * @param exampleFolder the folder to open. + */ + public ExamplesTest(String name, File exampleFolder) { + this.name = name; + this.exampleFolder = exampleFolder.getAbsoluteFile(); + } + + @BeforeClass + public static void setupClass() throws Exception { + Injector injector = SARLStandaloneSetup.doSetup(); + compiler = injector.getInstance(SarlBatchCompiler.class); + } + + @Override + public String toString() { + return this.name; + } + + @Test + public void path() { + assertNotNull(this.exampleFolder); + } + + @Test + public void compilation() throws Exception { + Assume.assumeTrue(this.exampleFolder != null); + final File projectRoot = createProject(); + final List installedFiles = copyFiles(projectRoot); + assertFalse("No installed file in " + projectRoot, installedFiles.isEmpty()); + List issues = compileFiles(projectRoot, installedFiles); + assertNoIssue(issues); + } + + private void assertNoIssue(List issues) { + if (!issues.isEmpty()) { + throw new ComparisonFailure("Errors in the example code", "", Strings.concat("\n", issues)); + } + } + + private List compileFiles(File root, List installedFiles) throws Exception { + final List issues = new ArrayList<>(); + compiler.setBasePath(root.getAbsolutePath()); + compiler.setTempDirectory(getTempPath(root)); + compiler.addSourcePath(getSourcePath(root)); + compiler.setClassOutputPath(getBinPath(root)); + compiler.setOutputPath(getSourceGenPath(root)); + compiler.setGenerateGeneratedAnnotation(false); + compiler.setGenerateInlineAnnotation(false); + compiler.setGenerateSyntheticSuppressWarnings(true); + compiler.setDeleteTempDirectory(false); + compiler.setClassPath(getClasspath()); + compiler.setJavaSourceVersion(SARLVersion.MINIMAL_JDK_VERSION); + compiler.setAllWarningSeverities(Severity.IGNORE); + compiler.setJavaCompilerVerbose(false); + compiler.getLogger().setLevel(Level.OFF); + compiler.addIssueMessageListener((issue, uri, message) -> { + if (issue.isSyntaxError() || issue.getSeverity().compareTo(Severity.ERROR) >= 0) { + final Integer line = issue.getLineNumber(); + final int issueLine = (line == null ? 0 : line.intValue()); + issues.add(message + " (line " + issueLine + ")"); //$NON-NLS-1$ //$NON-NLS-2$ + } + }); + if (compiler.compile()) { + return Collections.emptyList(); + } + return issues; + } + + private List getClasspath() throws Exception { + final List classpath = new ArrayList<>(); + final Iterator iterator = ClasspathUtil.getClasspath(); + while (iterator.hasNext()) { + final URL url = iterator.next(); + try { + final File file = FileSystem.convertURLToFile(url); + classpath.add(file); + } catch (IllegalArgumentException exception) { + // + } + } + return classpath; + } + + private List copyFiles(File root) throws Exception { + final List installedFiles = new ArrayList<>(); + final List folders = new ArrayList<>(); + folders.add(this.exampleFolder); + 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, this.exampleFolder); + final File targetFile = FileSystem.join(root, relPathFile); + targetFile.getParentFile().mkdirs(); + FileSystem.copy(file, targetFile); + installedFiles.add(relPathFile); + } + } + } + } + return installedFiles; + } + + private static boolean isIgnorableFile(File file) { + final String name = file.getName(); + return ".classpath".equals(name) || ".project".equals(name); + } + + private File getSourcePath(File rootPath) { + return FileSystem.join(rootPath, "src", "main", "sarl"); + } + + private File getSourceGenPath(File rootPath) { + return new File(rootPath, "src-gen"); + } + + private File getBinPath(File rootPath) { + return new File(rootPath, "bin"); + } + + private File getTempPath(File rootPath) { + return new File(rootPath, "build"); + } + + private File createProject() throws Exception { + final File rootPath = FileSystem.createTempDirectory("exampletests", ".tmp").getAbsoluteFile(); + getSourcePath(rootPath).mkdirs(); + getSourceGenPath(rootPath).mkdirs(); + getBinPath(rootPath).mkdirs(); + getTempPath(rootPath).mkdirs(); + FileSystem.deleteOnExit(rootPath); + return rootPath; + } + +} diff --git a/contribs/io.sarl.examples/pom.xml b/contribs/io.sarl.examples/pom.xml index 7fe6e27ca4..d141cdd7bc 100644 --- a/contribs/io.sarl.examples/pom.xml +++ b/contribs/io.sarl.examples/pom.xml @@ -16,7 +16,7 @@ io.sarl.examples.plugin io.sarl.examples.feature - io.sarl.examples.tests + diff --git a/tests/pom.xml b/tests/pom.xml index 172c90d2b5..14f51fa2b5 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -26,12 +26,13 @@ io.sarl.core.tests sarl-maven-plugin.tests io.sarl.maven.docs.generator.tests -