() {
- @Override
- public JavaVersion get() {
- return JavaVersion.JAVA8;
- }
- });
+ final JavaVersion version = JavaVersion.JAVA8;
+ binder.bind(JavaVersion.class).toProvider(() -> version);
+ binder.bind(ProjectCreator.class).toProvider(() -> {
+ return new JavaProjectCreator(version);
+ }).asEagerSingleton();
}
},
};
@@ -374,18 +371,18 @@ protected SarlScript file(String string, boolean validate) throws Exception {
* @mavenartifactid $ArtifactId$
*/
@Singleton
- private static class JavaProjectCreator implements ProjectCreator {
+ private class JavaProjectCreator implements ProjectCreator {
- @Inject
- private Injector injector;
-
- @Inject
@Nullable
- private JavaVersion javaVersion;
+ private final JavaVersion javaVersion;
+ JavaProjectCreator(JavaVersion version) {
+ this.javaVersion = version;
+ }
+
@Override
public Injector getInjector() {
- return this.injector;
+ return getInjectedInjector();
}
@Override
@@ -427,12 +424,26 @@ public String[] getNatures() {
@Override
public void addJreClasspathEntry(IJavaProject javaProject) throws JavaModelException {
- JavaProjectSetupUtil.addJreClasspathEntry(javaProject);
+ IClasspathEntry existingJreContainerClasspathEntry = JREContainerProvider.getJREContainerEntry(javaProject);
+ if (existingJreContainerClasspathEntry == null) {
+ addToClasspath(javaProject, JREContainerProvider.getDefaultJREContainerEntry());
+ }
}
@Override
public void addToClasspath(IJavaProject javaProject, IClasspathEntry newClassPathEntry) throws JavaModelException {
- JavaProjectSetupUtil.addToClasspath(javaProject, newClassPathEntry);
+ IClasspathEntry[] newClassPath;
+ IClasspathEntry[] classPath = javaProject.getRawClasspath();
+ for (IClasspathEntry classPathEntry : classPath) {
+ if (classPathEntry.equals(newClassPathEntry)) {
+ return;
+ }
+ }
+ newClassPath = new IClasspathEntry[classPath.length + 1];
+ System.arraycopy(classPath, 0, newClassPath, 1, classPath.length);
+ newClassPath[0] = newClassPathEntry;
+ javaProject.setRawClasspath(newClassPath, null);
+ helper().awaitAutoBuild();
}
@Override
@@ -449,7 +460,7 @@ public void addToClasspath(IJavaProject javaProject,
newClassPath.toArray(classPath);
javaProject.setRawClasspath(classPath, null);
if (autobuild) {
- reallyWaitForAutoBuild();
+ helper().awaitAutoBuild();
}
}
diff --git a/tests/io.sarl.tests.api/src/io/sarl/tests/api/ExtendedSARLInjectorProvider.java b/tests/io.sarl.tests.api/src/io/sarl/tests/api/ExtendedSARLInjectorProvider.java
new file mode 100644
index 0000000000..18aa32361d
--- /dev/null
+++ b/tests/io.sarl.tests.api/src/io/sarl/tests/api/ExtendedSARLInjectorProvider.java
@@ -0,0 +1,92 @@
+/*
+ * $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.tests.api;
+
+import com.google.inject.Binder;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provider;
+import org.eclipse.xtext.util.JavaVersion;
+import org.eclipse.xtext.xbase.testing.OnTheFlyJavaCompiler2;
+
+import io.sarl.lang.SARLStandaloneSetup;
+import io.sarl.lang.tests.SARLInjectorProvider;
+
+/** Override the module definition for tests only.
+ *
+ * This class is implemented for overriding the default Javba version of the on-the-fly Java compiler
+ * that is used by the testing framework. Indeed, the default Java version for this compiler is Java 6. But,
+ * we are expecting at least Java 8 in tests.
+ *
+ * @author $Author: sgalland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+public class ExtendedSARLInjectorProvider extends SARLInjectorProvider {
+
+ @Override
+ protected Injector internalCreateInjector() {
+ return new SARLStandaloneSetup() {
+ @SuppressWarnings("synthetic-access")
+ @Override
+ public Injector createInjector() {
+ return Guice.createInjector(createRuntimeModule(), createRuntimeTestModule());
+ }
+ }.createInjectorAndDoEMFRegistration();
+ }
+
+ /** Create the module for tests of the runtime libraries.
+ *
+ * @return the module.
+ */
+ @SuppressWarnings("static-method")
+ protected Module createRuntimeTestModule() {
+ return new Module() {
+
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(OnTheFlyJavaCompiler2.class).toProvider(JavaCompilerProvider.class).asEagerSingleton();
+ }
+
+ };
+ }
+
+ /** Provider of the on-the-fly Java compiler.
+ *
+ * @author $Author: sgalland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ */
+ public static class JavaCompilerProvider implements Provider {
+
+ @Override
+ public OnTheFlyJavaCompiler2 get() {
+ return new OnTheFlyJavaCompiler2(
+ SARLInjectorProvider.class.getClassLoader(),
+ JavaVersion.JAVA8);
+ }
+
+ }
+
+}
diff --git a/tests/io.sarl.tests.api/src/io/sarl/tests/api/WorkbenchTestHelper.java b/tests/io.sarl.tests.api/src/io/sarl/tests/api/WorkbenchTestHelper.java
index 04ba299209..1a47a3b895 100644
--- a/tests/io.sarl.tests.api/src/io/sarl/tests/api/WorkbenchTestHelper.java
+++ b/tests/io.sarl.tests.api/src/io/sarl/tests/api/WorkbenchTestHelper.java
@@ -52,15 +52,19 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
@@ -83,7 +87,6 @@
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.xtend.core.xtend.XtendTypeDeclaration;
-import org.eclipse.xtext.junit4.ui.util.IResourcesSetupUtil;
import org.eclipse.xtext.resource.FileExtensionProvider;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.XtextEditorInfo;
@@ -218,14 +221,25 @@ protected void execute(IProgressMonitor monitor) throws CoreException,
}
}.run(null);
- IResourcesSetupUtil.reallyWaitForAutoBuild();
+ awaitAutoBuild();
}
+ private static void deleteProjects(IProject[] projects) throws CoreException {
+ for (IProject iProject : projects) {
+ if (iProject.exists()) {
+ iProject.delete(true,true, new NullProgressMonitor());
+ }
+ }
+ }
+
/** Clear the workspace.
*/
public void clearWorkspace() {
try {
- IResourcesSetupUtil.cleanWorkspace();
+ IProject[] visibleProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ deleteProjects(visibleProjects);
+ IProject[] hiddenProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects(org.eclipse.core.resources.IContainer.INCLUDE_HIDDEN);
+ deleteProjects(hiddenProjects);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -337,6 +351,35 @@ public IFile createFile(String fileName, String content) throws Exception {
return createFileImpl(fullFileName, content);
}
+ private static IProject createProject(IProject project) throws CoreException {
+ if (!project.exists())
+ project.create(new NullProgressMonitor());
+ project.open(new NullProgressMonitor());
+ return project;
+ }
+
+ private static void create(org.eclipse.core.resources.IContainer container)
+ throws InvocationTargetException, InterruptedException {
+ new WorkspaceModifyOperation() {
+
+ @SuppressWarnings("synthetic-access")
+ @Override
+ protected void execute(IProgressMonitor monitor)
+ throws CoreException, InvocationTargetException,
+ InterruptedException {
+ if (!container.exists()) {
+ create(container.getParent());
+ if (container instanceof IFolder) {
+ ((IFolder) container).create(true, true, new NullProgressMonitor());
+ } else {
+ IProject iProject = (IProject) container;
+ createProject(iProject);
+ }
+ }
+ }
+ }.run(new NullProgressMonitor());
+ }
+
/** Create a file.
*
* @param fullFileName the name of the file to create.
@@ -345,7 +388,19 @@ public IFile createFile(String fileName, String content) throws Exception {
* @throws Exception
*/
public IFile createFileImpl(String fullFileName, String content) throws Exception {
- IFile file = IResourcesSetupUtil.createFile(fullFileName, content);
+ final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullFileName));
+ new WorkspaceModifyOperation() {
+ @SuppressWarnings({ "synthetic-access", "resource" })
+ @Override
+ protected void execute(IProgressMonitor monitor)
+ throws CoreException, InvocationTargetException,
+ InterruptedException {
+ create(file.getParent());
+ file.delete(true, new NullProgressMonitor());
+ file.create(new StringInputStream(content), true, new NullProgressMonitor());
+ }
+
+ }.run(new NullProgressMonitor());
getFiles().add(file);
return file;
}
@@ -706,7 +761,7 @@ public IProject createPluginProject(String name, ProjectCreator creator, String.
exception.getLocalizedMessage(), exception));
}
- IResourcesSetupUtil.reallyWaitForAutoBuild();
+ awaitAutoBuild();
return result;
}
@@ -978,7 +1033,18 @@ public void awaitUIUpdate(Functions.Function0 test, final long timeout)
/** Wait for the end of auto-build.
*/
public void awaitAutoBuild() {
- IResourcesSetupUtil.reallyWaitForAutoBuild();
+ boolean wasInterrupted = false;
+ do {
+ try {
+ Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD,
+ null);
+ wasInterrupted = false;
+ } catch (OperationCanceledException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ wasInterrupted = true;
+ }
+ } while (wasInterrupted);
}
/** Do a full build.
@@ -992,7 +1058,20 @@ public void fullBuild(Resource... resources) throws CoreException {
resource.getContents();
}
}
- IResourcesSetupUtil.fullBuild();
+ ResourcesPlugin.getWorkspace().build(
+ IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ boolean wasInterrupted = false;
+ do {
+ try {
+ Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD,
+ null);
+ wasInterrupted = false;
+ } catch (OperationCanceledException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ wasInterrupted = true;
+ }
+ } while (wasInterrupted);
}
/** Generate a filename for a resource that does not exist yet.
diff --git a/tests/io.sarl.util.tests/META-INF/MANIFEST.MF b/tests/io.sarl.util.tests/META-INF/MANIFEST.MF
index 4f156ad744..0d0cc4bfd6 100644
--- a/tests/io.sarl.util.tests/META-INF/MANIFEST.MF
+++ b/tests/io.sarl.util.tests/META-INF/MANIFEST.MF
@@ -7,7 +7,8 @@ Bundle-Name: %Bundle-Name
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: io.sarl.util;bundle-version="0.5.0",
io.sarl.tests.api;bundle-version="0.5.0",
- org.mockito.mockito-core;bundle-version="2.0.111"
+ org.mockito.mockito-core;bundle-version="2.0.111",
+ javax.inject;bundle-version="1.0.0"
Export-Package: io.sarl.util.tests.eventdispatching,
io.sarl.util.tests.sarlspecification,
io.sarl.util.tests.util
diff --git a/tests/io.sarl.util.tests/src/io/sarl/util/tests/eventdispatching/BehaviorGuardEvaluatorRegistryTest.java b/tests/io.sarl.util.tests/src/io/sarl/util/tests/eventdispatching/BehaviorGuardEvaluatorRegistryTest.java
index f03b0a6b8c..301de244b0 100644
--- a/tests/io.sarl.util.tests/src/io/sarl/util/tests/eventdispatching/BehaviorGuardEvaluatorRegistryTest.java
+++ b/tests/io.sarl.util.tests/src/io/sarl/util/tests/eventdispatching/BehaviorGuardEvaluatorRegistryTest.java
@@ -15,37 +15,24 @@
*/
package io.sarl.util.tests.eventdispatching;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
import java.util.UUID;
-import java.util.concurrent.CopyOnWriteArraySet;
import javax.inject.Inject;
-import com.google.common.base.MoreObjects;
import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
-import org.mockito.Mock;
-import org.mockito.Mockito;
import io.sarl.eventdispatching.BehaviorGuardEvaluator;
import io.sarl.eventdispatching.BehaviorGuardEvaluatorRegistry;
import io.sarl.lang.annotation.PerceptGuardEvaluator;
import io.sarl.lang.core.Agent;
-import io.sarl.lang.core.BuiltinCapacitiesProvider;
import io.sarl.lang.core.Event;
import io.sarl.tests.api.AbstractSarlTest;
import io.sarl.tests.api.Nullable;