import org.sonar.runner.batch.IsolatedLauncher;
import org.sonar.runner.impl.InternalProperties;
import org.sonar.runner.impl.IsolatedLauncherFactory;
+import org.sonar.runner.impl.VersionUtils;
/**
* Entry point to run SonarQube analysis programmatically.
protected void doStart() {
launcher = launcherFactory.createLauncher(globalProperties());
- if (Utils.isAtLeast52(launcher.getVersion())) {
+ if (VersionUtils.isAtLeast52(launcher.getVersion())) {
launcher.start(globalProperties(), new org.sonar.runner.batch.LogOutput() {
@Override
}
protected void doStop() {
- if (Utils.isAtLeast52(launcher.getVersion())) {
+ if (VersionUtils.isAtLeast52(launcher.getVersion())) {
launcher.stop();
}
}
protected void doExecute(Properties analysisProperties) {
- if (Utils.isAtLeast52(launcher.getVersion())) {
+ if (VersionUtils.isAtLeast52(launcher.getVersion())) {
launcher.execute(analysisProperties);
} else {
Properties prop = new Properties();
*/
package org.sonar.runner.api;
-import javax.annotation.Nullable;
-
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Properties;
-import java.nio.file.attribute.BasicFileAttributes;
+import javax.annotation.Nullable;
class Utils {
private Utils() {
// only util static methods
}
- static boolean isAtLeast52(String version) {
- // it can be snapshot (5.2-SNAPSHOT)
- if (version == null) {
- return false;
- }
-
- int endIndex = Math.min(3, version.length());
- try {
- return Double.parseDouble(version.substring(0, endIndex)) >= 5.2;
- } catch (NumberFormatException e) {
- return false;
- }
- }
-
/**
* Similar to org.apache.commons.lang.StringUtils#join()
*/
--- /dev/null
+/*
+ * SonarQube Runner - API
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.runner.impl;
+
+public class VersionUtils {
+ private VersionUtils() {
+ // only util static methods
+ }
+
+ public static boolean isAtLeast52(String version) {
+ // it can be snapshot (5.2-SNAPSHOT)
+ if (version == null) {
+ return false;
+ }
+
+ int endIndex = Math.min(3, version.length());
+ try {
+ return Double.parseDouble(version.substring(0, endIndex)) >= 5.2;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+}
*/
package org.sonar.runner.api;
-import org.junit.Test;
-
import java.io.Closeable;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
+import org.junit.Test;
-import static org.mockito.Mockito.verify;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.doThrow;
import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
public class UtilsTest {
@Test
assertThat(Utils.join(new String[] {"foo", "bar"}, ",")).isEqualTo("foo,bar");
}
- @Test
- public void parse_version() {
- assertThat(Utils.isAtLeast52("5.2")).isTrue();
- assertThat(Utils.isAtLeast52(null)).isFalse();
- assertThat(Utils.isAtLeast52("52")).isTrue();
- assertThat(Utils.isAtLeast52("5.0")).isFalse();
- assertThat(Utils.isAtLeast52("")).isFalse();
- assertThat(Utils.isAtLeast52("trash")).isFalse();
- assertThat(Utils.isAtLeast52("6.0.0")).isTrue();
- assertThat(Utils.isAtLeast52("5.2-SNAPSHOT")).isTrue();
- }
-
@Test
public void task_should_require_project() {
Properties props = new Properties();
--- /dev/null
+/*
+ * SonarQube Runner - API
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.runner.impl;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class VersionUtilsTest {
+
+ @Test
+ public void parse_version() {
+ assertThat(VersionUtils.isAtLeast52("5.2")).isTrue();
+ assertThat(VersionUtils.isAtLeast52(null)).isFalse();
+ assertThat(VersionUtils.isAtLeast52("52")).isTrue();
+ assertThat(VersionUtils.isAtLeast52("5.0")).isFalse();
+ assertThat(VersionUtils.isAtLeast52("")).isFalse();
+ assertThat(VersionUtils.isAtLeast52("trash")).isFalse();
+ assertThat(VersionUtils.isAtLeast52("6.0.0")).isTrue();
+ assertThat(VersionUtils.isAtLeast52("5.2-SNAPSHOT")).isTrue();
+ }
+}
import org.picocontainer.annotations.Nullable;
import org.sonar.batch.bootstrapper.Batch;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.batch.bootstrapper.LogOutput;
/**
* This class is executed within the classloader provided by the server. It contains the installed plugins and
.setBootstrapProperties((Map) properties);
if (logOutput != null) {
- builder.setLogOutput(new LogOutput() {
-
- @Override
- public void log(String formattedMessage, Level level) {
- logOutput.log(formattedMessage, org.sonar.runner.batch.LogOutput.Level.valueOf(level.name()));
- }
-
- });
+ // Do that is a separate class to avoid NoClassDefFoundError for org/sonar/batch/bootstrapper/LogOutput
+ Compatibility.setLogOutputFor5dot2(builder, logOutput);
}
return builder.build();
--- /dev/null
+/*
+ * SonarQube Runner - Batch
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.runner.batch;
+
+import org.sonar.batch.bootstrapper.Batch;
+import org.sonar.batch.bootstrapper.LogOutput;
+
+public class Compatibility {
+
+ private Compatibility() {
+ // Utility class
+ }
+
+ static void setLogOutputFor5dot2(Batch.Builder builder, final org.sonar.runner.batch.LogOutput logOutput) {
+ builder.setLogOutput(new LogOutput() {
+
+ @Override
+ public void log(String formattedMessage, Level level) {
+ logOutput.log(formattedMessage, org.sonar.runner.batch.LogOutput.Level.valueOf(level.name()));
+ }
+
+ });
+ }
+
+}