--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.sonar-plugins</groupId>
+ <artifactId>parent</artifactId>
+ <version>8</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+
+ <artifactId>sonar-runner</artifactId>
+ <version>0.1-SNAPSHOT</version>
+
+ <name>Sonar Standalone Runner</name>
+ <description></description>
+ <url>http://docs.codehaus.org/display/SONAR/Sonar+Standalone+Runner</url>
+ <inceptionYear>2011</inceptionYear>
+ <organization>
+ <name>SonarSource</name>
+ <url>http://www.sonarsource.com</url>
+ </organization>
+ <licenses>
+ <license>
+ <name>GNU LGPL 3</name>
+ <url>http://www.gnu.org/licenses/lgpl.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <developers>
+ <developer>
+ <id>godin</id>
+ <name>Evgeny Mandrikov</name>
+ <timezone>+3</timezone>
+ </developer>
+ <developer>
+ <id>simon.brandhof</id>
+ <name>Simon Brandhof</name>
+ <timezone>+1</timezone>
+ </developer>
+ </developers>
+
+ <scm>
+ <connection>scm:svn:http://svn.codehaus.org/sonar-plugins/trunk/sonar-cli</connection>
+ <developerConnection>scm:svn:https://svn.codehaus.org/sonar-plugins/trunk/sonar-cli</developerConnection>
+ <url>http://svn.sonar-plugins.codehaus.org</url>
+ </scm>
+ <issueManagement>
+ </issueManagement>
+ <ciManagement>
+ </ciManagement>
+
+ <properties>
+ <sonar.version>2.6-SNAPSHOT</sonar.version>
+ </properties>
+
+ <dependencies>
+ <!-- Would be embedded in final JAR -->
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-batch-bootstrapper</artifactId>
+ <version>${sonar.version}</version>
+ </dependency>
+ <!-- Would be available after bootstrapping -->
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>0.9.15</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-batch</artifactId>
+ <version>${sonar.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <mainClass>org.sonar.cli.BootstrapLauncher</mainClass>
+ </transformer>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
--- /dev/null
+#!/bin/sh
+#
+# Sonar Runner Startup Script for Unix
+#
+
+if [ -z "$SONAR_RUNNER_HOME" ] ; then
+ PRG="$0"
+
+ SONAR_RUNNER_HOME=`dirname "$PRG"`/..
+
+ # make it fully qualified
+ SONAR_RUNNER_HOME=`cd "$SONAR_RUNNER_HOME" && pwd`
+fi
+
+echo "Info: Using sonar-runner at $SONAR_RUNNER_HOME"
+
+JAVACMD="`which java`"
+
+exec "$JAVACMD"
+ -classpath "${SONAR_RUNNER_HOME}"/lib/sonar-runner-*.jar \
+ "$@"
--- /dev/null
+#sonar.host.url=http://localhost:9000
+
+#----- PostgreSQL
+#sonar.jdbc.url=jdbc:postgresql://localhost/sonar
+#sonar.jdbc.driver=org.postgresql.Driver
+
+#----- MySQL
+#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
+#sonar.jdbc.driver=com.mysql.jdbc.Driver
+
+#----- Oracle
+#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
+#sonar.jdbc.driver=oracle.jdbc.driver.OracleDriver
+
+#----- Global database settings
+#sonar.jdbc.username=sonar
+#sonar.jdbc.password=sonar
--- /dev/null
+#!/bin/sh
+
+# TODO remove hard-coded version
+java -jar ../../../target/sonar-cli-0.1-SNAPSHOT.jar project.properties
--- /dev/null
+project.key=my:project
+project.name=My project
+project.version=1.0
+
+project.build.directory=output
+
+#project.sources=src/main/java
+#project.sources=src/main/resources
+#project.binaries=output/classes
+#project.language=java
+#sonar.dynamicAnalysis=reuseReports
+#sonar.surefire.reports=output/junit/
--- /dev/null
+package org.sonar.cli.example;
+
+class HelloWorld {
+ public void sayHello() {
+ System.out.println("Hello world");
+ }
+}
--- /dev/null
+/*
+ * Sonar CLI
+ * Copyright (C) 2009 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.cli;
+
+import org.sonar.batch.bootstrapper.BatchDownloader;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.List;
+
+public class BootstrapLauncher {
+
+ private static final String LAUNCHER_CLASS_NAME = "org.sonar.cli.Launcher";
+
+ private String[] args;
+
+ public static void main(String[] args) throws Exception {
+ new BootstrapLauncher(args).bootstrap();
+ }
+
+ public BootstrapLauncher(String[] args) {
+ this.args = args;
+ }
+
+ public void bootstrap() throws Exception {
+ ClassLoader cl = getInitialClassLoader();
+
+ Class launcherClass = cl.loadClass(LAUNCHER_CLASS_NAME);
+
+ Method[] methods = launcherClass.getMethods();
+ Method mainMethod = null;
+
+ for (int i = 0; i < methods.length; ++i) {
+ if (!("main".equals(methods[i].getName()))) {
+ continue;
+ }
+
+ int modifiers = methods[i].getModifiers();
+
+ if (!(Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers))) {
+ continue;
+ }
+
+ if (methods[i].getReturnType() != Void.TYPE) {
+ continue;
+ }
+
+ Class[] paramTypes = methods[i].getParameterTypes();
+ if (paramTypes.length != 1) {
+ continue;
+ }
+ if (paramTypes[0] != String[].class) {
+ continue;
+ }
+ mainMethod = methods[i];
+ break;
+ }
+
+ if (mainMethod == null) {
+ throw new NoSuchMethodException(LAUNCHER_CLASS_NAME + ":main(String[] args)");
+ }
+
+ Thread.currentThread().setContextClassLoader(cl);
+
+ mainMethod.invoke(launcherClass, new Object[] { this.args });
+ }
+
+ private static ClassLoader getInitialClassLoader() throws Exception {
+ BatchDownloader downloader = new BatchDownloader("http://localhost:9000"); // TODO hard-coded value
+ List<File> files = downloader.downloadBatchFiles(new File("/tmp/sonar-boot"));
+ ChildFirstClassLoader classLoader = new ChildFirstClassLoader();
+ for (File file : files) {
+ System.out.println(file);
+ classLoader.addFile(file);
+ }
+ // Add JAR with Sonar CLI - it's a Jar which contains this class
+ classLoader.addURL(BootstrapLauncher.class.getProtectionDomain().getCodeSource().getLocation());
+ return classLoader;
+ }
+}
--- /dev/null
+/*
+ * Sonar CLI
+ * Copyright (C) 2009 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.cli;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+public class ChildFirstClassLoader extends URLClassLoader {
+ public ChildFirstClassLoader() {
+ super(new URL[0]);
+ }
+
+ @Override
+ public void addURL(URL url) {
+ super.addURL(url);
+ }
+
+ public void addFile(File file) {
+ try {
+ addURL(file.toURI().toURL());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Searches for classes using child-first strategy.
+ */
+ @Override
+ protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+ // First, check if the class has already been loaded
+ Class<?> c = findLoadedClass(name);
+ // If not loaded, search the local (child) resources
+ if (c == null) {
+ try {
+ c = findClass(name);
+ } catch (ClassNotFoundException e) {
+ // ignore
+ }
+ }
+ // If we could not find it, delegate to parent
+ // Note that we don't attempt to catch any ClassNotFoundException
+ if (c == null) {
+ if (getParent() != null) {
+ c = getParent().loadClass(name);
+ } else {
+ c = getSystemClassLoader().loadClass(name);
+ }
+ }
+ if (resolve) {
+ resolveClass(c);
+ }
+ return c;
+ }
+}
--- /dev/null
+/*
+ * Sonar CLI
+ * Copyright (C) 2009 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.cli;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.SystemConfiguration;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.platform.Environment;
+import org.sonar.api.utils.SonarException;
+import org.sonar.batch.Batch;
+import org.sonar.batch.bootstrapper.ProjectDefinition;
+import org.sonar.batch.bootstrapper.Reactor;
+
+import java.io.*;
+import java.util.Properties;
+
+public class Launcher {
+
+ private String[] args;
+
+ public static void main(String[] args) throws Exception {
+ new Launcher(args).execute();
+ }
+
+ public Launcher(String[] args) {
+ this.args = args;
+ }
+
+ public void execute() throws Exception {
+ initLogging();
+ ProjectDefinition project = defineProject(new File(args[0]));
+ Reactor reactor = new Reactor(project);
+ Batch batch = new Batch(getInitialConfiguration(), Environment.ANT, reactor); // TODO environment
+ batch.execute();
+ }
+
+ private void initLogging() {
+ LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
+ JoranConfigurator jc = new JoranConfigurator();
+ jc.setContext(context);
+ context.reset();
+ InputStream input = Batch.class.getResourceAsStream("/org/sonar/batch/logback.xml");
+ // System.setProperty("ROOT_LOGGER_LEVEL", getLog().isDebugEnabled() ? "DEBUG" : "INFO");
+ System.setProperty("ROOT_LOGGER_LEVEL", "INFO");
+ try {
+ jc.doConfigure(input);
+
+ } catch (JoranException e) {
+ throw new SonarException("can not initialize logging", e);
+
+ } finally {
+ IOUtils.closeQuietly(input);
+ }
+ }
+
+ private ProjectDefinition defineProject(File file) {
+ File baseDir = file.getParentFile();
+ File workDir = new File(baseDir, ".sonar");
+ Properties properties = new Properties();
+ try {
+ properties.load(new FileInputStream(file));
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ ProjectDefinition definition = new ProjectDefinition(baseDir, workDir, properties);
+ // TODO for some reason it can't be relative
+ definition.addSourceDir(new File(baseDir, "src").getAbsolutePath()); // TODO hard-coded value
+ // TODO definition.addTestDir(path);
+ // TODO definition.addBinaryDir(path);
+ // TODO definition.addLibrary(path);
+
+ System.out.println(baseDir);
+
+ return definition;
+ }
+
+ private Configuration getInitialConfiguration() {
+ // TODO
+ return new SystemConfiguration();
+ }
+
+}