import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.utils.Durations;
import org.sonar.api.utils.HttpDownloader;
+import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
import org.sonar.api.utils.internal.TempFolderCleaner;
import org.sonar.batch.components.*;
TempFolderCleaner.class,
HttpDownloader.class,
UriReader.class,
- new FileCacheProvider());
+ new FileCacheProvider(),
+ System2.INSTANCE);
}
private void addDatabaseComponents() {
package org.sonar.api.utils;
import org.apache.commons.lang.SystemUtils;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ServerComponent;
import javax.annotation.CheckForNull;
import java.util.Map;
/**
* Proxy over {@link java.lang.System}. It aims to improve testability of classes
* that interact with low-level system methods, for example :
- *
+ * <p/>
* <pre>
* public class MyClass {
* private final System2 system;
* }
* }
*
- * @Test
+ * {@literal @}Test
* public void should_return_xxx() {
* // using Mockito
* System2 system = mock(System2.class);
* assertThat(new MyClass(system).xxx()).isEqualTo(now);
* }
* </pre>
- *
* <p/>
* Note that the name System2 was chosen to not conflict with {@link java.lang.System}.
+ * <p/>
+ * An instance is available in IoC container since 4.3.
*
* @since 4.2
*/
-public class System2 {
+public class System2 implements BatchComponent, ServerComponent {
public static final System2 INSTANCE = new System2();
return SystemUtils.IS_OS_WINDOWS;
}
+ /**
+ * True if Java 7 or Java 8 runtime environment
+ * @since 4.3
+ */
+ public boolean isJavaAtLeast17() {
+ return SystemUtils.isJavaVersionAtLeast(1.7f);
+ }
+
public void println(String obj) {
System.out.print(obj);
}
@Test
public void testEnvVariables() throws Exception {
- Map<String,String> expected = System.getenv();
+ Map<String, String> expected = System.getenv();
assertThat(System2.INSTANCE.envVariables()).isNotNull().isEqualTo(expected);
}
assertThat(System2.INSTANCE.isOsWindows()).isEqualTo(SystemUtils.IS_OS_WINDOWS);
}
+ @Test
+ public void testIsJavaAtLeast17() throws Exception {
+ if (SystemUtils.IS_JAVA_1_6) {
+ assertThat(System2.INSTANCE.isJavaAtLeast17()).isFalse();
+ } else {
+ assertThat(System2.INSTANCE.isJavaAtLeast17()).isTrue();
+ }
+ }
+
@Test
public void testPrintln() throws Exception {
// well, how to assert that ? Adding a System3 dependency to System2 ? :-)
import org.sonar.api.server.rule.RulesDefinitionXmlLoader;
import org.sonar.api.utils.Durations;
import org.sonar.api.utils.HttpDownloader;
+import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
import org.sonar.api.utils.internal.TempFolderCleaner;
import org.sonar.core.component.SnapshotPerspectives;
SemaphoreUpdater.class,
SemaphoresImpl.class,
TempFolderCleaner.class,
- new TempFolderProvider()
+ new TempFolderProvider(),
+ System2.INSTANCE
));
components.addAll(DatabaseMigrations.CLASSES);
components.addAll(DaoUtils.getDaoClasses());