-REM This is where the sanity test execution for windows needs to go (see run.sh)
+rem Inject the sanitytest jar as a controller plugin
+copy .\target\dependency\sanitytest*.jar .\target\distribution.opendaylight-osgipackage\opendaylight\plugins
+
+rem Store the current working directory in a variable so that we can get back to it later
+set cwd=%cd%
+
+rem Switch to the distribution folder
+cd .\target\distribution.opendaylight-osgipackage\opendaylight
+
+rem Run the controller
+cmd.exe /c run.bat
+
+rem Store the exit value of the controller in a variable
+set success=%ERRORLEVEL%
+
+rem Switch back to the directory from which this script was invoked
+cd %cwd%
+
+rem Remove the sanitytest jar from the plugins directory
+del .\target\distribution.opendaylight-osgipackage\opendaylight\plugins\sanitytest*.jar
+
+rem Exit using the exit code that we had captured earlier after running the controller
+exit /b %SUCCESS%
\ No newline at end of file
@ECHO OFF
-SETLOCAL
-SETLOCAL ENABLEDELAYEDEXPANSION
IF EXIST "%JAVA_HOME%" (
- set basedir=%~dp0
+ REM CONTINUE
+) ELSE (
+ ECHO JAVA_HOME environment variable is not set
+ EXIT 2
+)
+
+set basedir=%~dp0
REM Now set the classpath:
- set cp="!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar;!basedir!lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar;!basedir!lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
+set cp="%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar;%basedir%lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar;%basedir%lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
REM Now set framework classpath
- set fwcp="file:\!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar,file:\!basedir!lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar,file:\!basedir!lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
+set fwcp="file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar,file:\%basedir%lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar,file:\%basedir%lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
REM echo cp: %cp%
REM echo fwcp: %fwcp%
-REM echo %JAVA_HOME%\bin\java.exe %* -Djava.io.tmpdir=!basedir!work\tmp -Dosgi.install.area=!basedir! -Dosgi.configuration.area=!basedir!configuration -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework=file:\!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar -classpath %cp% org.eclipse.equinox.launcher.Main -console -consoleLog
-"%JAVA_HOME%\bin\java.exe" %* -Djava.io.tmpdir="!basedir!work\tmp" -Dosgi.install.area=!basedir! -Dosgi.configuration.area="!basedir!configuration" -Dosgi.frameworkClassPath=!fwcp! -Dosgi.framework="file:\!basedir!lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar" -classpath !cp! org.eclipse.equinox.launcher.Main -console -consoleLog
+REM echo %JAVA_HOME%\bin\java.exe %* -Djava.io.tmpdir=%basedir%work\tmp -Dosgi.install.area=%basedir% -Dosgi.configuration.area=%basedir%configuration -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework=file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar -classpath %cp% org.eclipse.equinox.launcher.Main -console -consoleLog
+"%JAVA_HOME%\bin\java.exe" %* -Djava.io.tmpdir="%basedir%work\tmp" -Dosgi.install.area=%basedir% -Dosgi.configuration.area="%basedir%configuration" -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework="file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar" -classpath %cp% org.eclipse.equinox.launcher.Main -console -consoleLog
+
+exit %ERRORLEVEL%
+
-) ELSE (
- ECHO JAVA_HOME environment variable is not set
- PAUSE
-)
-ENDLOCAL
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
public class Sanity {
static void copy(InputStream in, OutputStream out) throws IOException {
System.out.println("Current working directory = " + cwd);
String os = System.getProperty("os.name").toLowerCase();
- String script = "./run.sh";
+ List<String> script = new ArrayList<String>();
if(os.contains("windows")){
- System.out.println("Sorry no sanity testing on Windows yet");
- System.exit(0);
- return;
+ script.add("cmd.exe");
+ script.add("/c");
+ script.add("run.bat");
+ } else {
+ script.add("./run.sh");
}
ProcessBuilder processBuilder = new ProcessBuilder();
- processBuilder.command(script);
+ processBuilder.inheritIO().command(script);
Process p = processBuilder.start();
copy(p.getInputStream(), System.out);
import org.osgi.framework.wiring.BundleRevision;
public class Activator implements BundleActivator {
- //30 Second
- private static final int DELAY = 30000;
+ //10 Second initial, 1 second subsequent
+ private static final int INITIAL_DELAY = 10000;
+ private static final int SUBSEQUENT_DELAY = 1000;
private String stateToString(int state) {
return "RESOLVED";
case Bundle.UNINSTALLED:
return "UNINSTALLED";
+ case Bundle.STARTING:
+ return "STARTING";
default:
- return "Not CONVERTED";
+ return "Not CONVERTED: state value is " + state;
}
}
monitorTimer.schedule(new TimerTask() {
@Override
public void run() {
+ int countup = 0;
boolean failed = false;
- for(Bundle bundle : bundleContext.getBundles()){
- /*
- * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED
- */
- if(!(bundle.getState() == Bundle.ACTIVE) ||
- (bundle.getState() != Bundle.RESOLVED &&
- (bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0))
- if(bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.RESOLVED) {
- System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
- failed = true;
+ boolean resolved = false;
+ while (!resolved) {
+ resolved = true;
+ failed = false;
+ for(Bundle bundle : bundleContext.getBundles()){
+ /*
+ * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED
+ */
+ int state = bundle.getState();
+ if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
+ //fragment
+ if (state != Bundle.RESOLVED) {
+ System.out.println("------ Failed to activate/resolve fragment = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
+ failed = true;
+ if (state == Bundle.STARTING)
+ resolved = false;
+ }
+ } else {
+ if(state != Bundle.ACTIVE) {
+ System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
+ failed = true;
+ if (state == Bundle.STARTING)
+ resolved = false;
+ }
+ }
+ }
+ if (!resolved) {
+ countup++;
+ if (countup < 60) {
+ System.out.println("all bundles haven't finished starting, will repeat");
+ try {
+ Thread.sleep(SUBSEQUENT_DELAY);
+ } catch (Exception e) {
+ ;
+ }
+ } else
+ resolved = true;
}
}
if(failed){
- System.exit(-1);
+ System.out.flush();
+ System.out.println("exiting with 1 as failed");
+ System.out.close();
+ Runtime.getRuntime().exit(1);
} else {
- System.exit(0);
+ System.out.flush();
+ System.out.println("exiting with 0 as succeeded");
+ System.out.close();
+ Runtime.getRuntime().exit(0);
}
}
- }, DELAY);
+ }, INITIAL_DELAY);
}
public void stop(BundleContext bundleContext) throws Exception {