package org.sonar.runner;
+import org.sonar.runner.utils.SonarRunnerIOUtils;
+
import org.sonar.runner.utils.SonarRunnerVersion;
import org.sonar.runner.bootstrapper.BootstrapException;
-import org.sonar.runner.bootstrapper.BootstrapperIOUtils;
import java.io.File;
import java.io.FileInputStream;
throw new BootstrapException(e);
} finally {
- BootstrapperIOUtils.closeQuietly(in);
+ SonarRunnerIOUtils.closeQuietly(in);
}
}
*/
package org.sonar.runner;
-import org.sonar.runner.utils.SonarRunnerVersion;
-
import org.sonar.runner.bootstrapper.BootstrapClassLoader;
import org.sonar.runner.bootstrapper.BootstrapException;
import org.sonar.runner.bootstrapper.Bootstrapper;
+import org.sonar.runner.utils.SonarRunnerVersion;
import java.io.File;
import java.lang.reflect.Constructor;
String path = properties.getProperty("project.home", ".");
projectDir = new File(path);
if (!projectDir.isDirectory() || !projectDir.exists()) {
- throw new IllegalArgumentException("Project home must be an existing directory: " + path);
+ throw new RunnerException("Project home must be an existing directory: " + path);
}
// project home exists: add its absolute path as "sonar.runner.projectDir" property
properties.put(PROPERTY_PROJECT_DIR, projectDir.getAbsolutePath());
private File initWorkDir() {
String customWorkDir = properties.getProperty(PROPERTY_WORK_DIRECTORY);
if (customWorkDir == null || customWorkDir.trim().length() == 0) {
- return new File(projectDir, DEF_VALUE_WORK_DIRECTORY);
+ return new File(getProjectDir(), DEF_VALUE_WORK_DIRECTORY);
}
return defineCustomizedWorkDir(new File(customWorkDir));
}
if (customWorkDir.isAbsolute()) {
return customWorkDir;
}
- return new File(projectDir, customWorkDir.getPath());
+ return new File(getProjectDir(), customWorkDir.getPath());
}
+ /**
+ * @return the project base directory
+ */
protected File getProjectDir() {
return projectDir;
}
*/
package org.sonar.runner.bootstrapper;
+import org.sonar.runner.utils.SonarRunnerIOUtils;
+
import org.sonar.runner.utils.SonarRunnerVersion;
import java.io.*;
HttpURLConnection connection = newHttpConnection(new URL(fullUrl));
output = new FileOutputStream(toFile, false);
input = connection.getInputStream();
- BootstrapperIOUtils.copyLarge(input, output);
+ SonarRunnerIOUtils.copyLarge(input, output);
} catch (IOException e) {
- BootstrapperIOUtils.closeQuietly(output);
- BootstrapperIOUtils.deleteFileQuietly(toFile);
+ SonarRunnerIOUtils.closeQuietly(output);
+ SonarRunnerIOUtils.deleteFileQuietly(toFile);
throw new BootstrapException("Fail to download the file: " + fullUrl, e);
} finally {
- BootstrapperIOUtils.closeQuietly(input);
- BootstrapperIOUtils.closeQuietly(output);
+ SonarRunnerIOUtils.closeQuietly(input);
+ SonarRunnerIOUtils.closeQuietly(output);
}
}
if (statusCode != HttpURLConnection.HTTP_OK) {
throw new IOException("Status returned by url : '" + fullUrl + "' is invalid : " + statusCode);
}
- return BootstrapperIOUtils.toString(reader);
+ return SonarRunnerIOUtils.toString(reader);
} finally {
- BootstrapperIOUtils.closeQuietly(reader);
+ SonarRunnerIOUtils.closeQuietly(reader);
conn.disconnect();
}
}
+++ /dev/null
-/*
- * Sonar Standalone Runner
- * 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.bootstrapper;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
-
-public final class BootstrapperIOUtils {
-
- private BootstrapperIOUtils() {
- // only static methods
- }
-
- /**
- * The default buffer size to use.
- */
- private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
-
- /**
- * Unconditionally close a <code>Closeable</code>.
- */
- public static void closeQuietly(Closeable closeable) {
- try {
- if (closeable != null) {
- closeable.close();
- }
- } catch (IOException ioe) {
- }
- }
-
- /**
- * Get the contents of a <code>Reader</code> as a String.
- */
- public static String toString(Reader input) throws IOException {
- StringWriter sw = new StringWriter();
- copyLarge(input, sw);
- return sw.toString();
- }
-
- /**
- * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
- */
- public static long copyLarge(InputStream input, OutputStream output) throws IOException {
- byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
- long count = 0;
- int n = 0;
- while (-1 != (n = input.read(buffer))) {
- output.write(buffer, 0, n);
- count += n;
- }
- return count;
- }
-
- /**
- * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
- */
- public static long copyLarge(Reader input, Writer output) throws IOException {
- char[] buffer = new char[DEFAULT_BUFFER_SIZE];
- long count = 0;
- int n = 0;
- while (-1 != (n = input.read(buffer))) {
- output.write(buffer, 0, n);
- count += n;
- }
- return count;
- }
-
- /**
- * Deletes a file (not a directory).
- */
- public static boolean deleteFileQuietly(File file) {
- if (file == null) {
- return false;
- }
- try {
- return file.delete();
- } catch (Exception e) {
- return false;
- }
- }
-
-}
package org.sonar.runner.model;
-import org.sonar.runner.Main;
-import org.sonar.runner.Runner;
-
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.Batch;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
+import org.sonar.runner.Main;
+import org.sonar.runner.Runner;
import java.io.File;
import java.io.InputStream;
--- /dev/null
+/*
+ * Sonar Standalone Runner
+ * 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.utils;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+public final class SonarRunnerIOUtils {
+
+ private SonarRunnerIOUtils() {
+ // only static methods
+ }
+
+ /**
+ * The default buffer size to use.
+ */
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+ /**
+ * Unconditionally close a <code>Closeable</code>.
+ */
+ public static void closeQuietly(Closeable closeable) {
+ try {
+ if (closeable != null) {
+ closeable.close();
+ }
+ } catch (IOException ioe) {
+ }
+ }
+
+ /**
+ * Get the contents of a <code>Reader</code> as a String.
+ */
+ public static String toString(Reader input) throws IOException {
+ StringWriter sw = new StringWriter();
+ copyLarge(input, sw);
+ return sw.toString();
+ }
+
+ /**
+ * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
+ */
+ public static long copyLarge(InputStream input, OutputStream output) throws IOException {
+ byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+ long count = 0;
+ int n = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ /**
+ * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
+ */
+ public static long copyLarge(Reader input, Writer output) throws IOException {
+ char[] buffer = new char[DEFAULT_BUFFER_SIZE];
+ long count = 0;
+ int n = 0;
+ while (-1 != (n = input.read(buffer))) {
+ output.write(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
+ /**
+ * Deletes a file (not a directory).
+ */
+ public static boolean deleteFileQuietly(File file) {
+ if (file == null) {
+ return false;
+ }
+ try {
+ return file.delete();
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+}
*/
package org.sonar.runner.utils;
-import org.sonar.runner.bootstrapper.BootstrapperIOUtils;
import java.io.IOException;
import java.io.InputStream;
this.version = "";
} finally {
- BootstrapperIOUtils.closeQuietly(input);
+ SonarRunnerIOUtils.closeQuietly(input);
}
}
}