diff --git a/runFromGit.sh b/runFromGit.sh index 10cf593c..ea473db8 100644 --- a/runFromGit.sh +++ b/runFromGit.sh @@ -4,5 +4,6 @@ java -jar target/Diversify-statements-1.0-SNAPSHOT-jar-with-dependencies.jar git for i in `seq 1 $1` do + java -Xmx2000m -XX:MaxPermSize=256m -jar target/Diversify-statements-1.0-SNAPSHOT-jar-with-dependencies.jar $(cat propertiesFile) & java -Xmx2000m -XX:MaxPermSize=256m -jar target/Diversify-statements-1.0-SNAPSHOT-jar-with-dependencies.jar $(cat propertiesFile) done diff --git a/src/main/java/fr/inria/diversify/Builder.java b/src/main/java/fr/inria/diversify/Builder.java index 86291392..2a62195e 100644 --- a/src/main/java/fr/inria/diversify/Builder.java +++ b/src/main/java/fr/inria/diversify/Builder.java @@ -44,7 +44,7 @@ public void printResult(String output, String git) { } catch (Exception e) { Log.error("error in Main.printResult", e); } - if(git != "") { + if(!git.equals("")) { GitUtil.addToGit(fileName); } // StatisticDiversification stat = new StatisticDiversification(transformations); @@ -85,7 +85,7 @@ protected String prepare(String dirSource, String dirTarget) throws IOException, } protected Integer runTest(String directory) throws InterruptedException, CompileException { - RunMaven rt = new RunMaven(directory, "test", clojureTest); + RunMaven rt = new RunMaven(directory, "test", timeOut,clojureTest); rt.start(); // int count = 0; rt.join(1000*timeOut); @@ -104,10 +104,10 @@ protected Integer runTest(String directory) throws InterruptedException, Compile public void initTimeOut() throws InterruptedException { initThreadGroup(); - RunMaven rt = new RunMaven(projectDir, "test", clojureTest); + RunMaven rt = new RunMaven(projectDir, "test", 0, clojureTest); rt.start(); timeOut = 0; - int factor = 3; + int factor = 4; while (rt.getFailures() == null) { timeOut = timeOut + factor; Thread.sleep(1000); diff --git a/src/main/java/fr/inria/diversify/Main.java b/src/main/java/fr/inria/diversify/Main.java index be5670dc..d04c4499 100644 --- a/src/main/java/fr/inria/diversify/Main.java +++ b/src/main/java/fr/inria/diversify/Main.java @@ -34,14 +34,17 @@ import java.io.FileWriter; import java.io.IOException; +import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.List; +import java.util.Set; public class Main { private CodeFragmentList statements; public static void main(String[] args) throws Exception { + if(args[0].equals("git")) { GitUtil.initGit(args[1]); Runtime r = Runtime.getRuntime(); @@ -75,7 +78,6 @@ public Main(String propertiesFile) throws Exception { sosieOnMultiProject(); else runDiversification(); - suicide(); // if (DiversifyProperties.getProperty("stat").equals("true")) // computeStatistic(); @@ -291,13 +293,11 @@ protected void writeTransformation(String FileName, List transfo } protected void suicide() { -// String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; -// Log.debug("PID :"+pid); + String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; + Log.debug("PID :"+pid); Runtime r = Runtime.getRuntime(); try { - Process p = r.exec("pkill java"); - Thread.sleep(1000); - + r.exec("kill "+pid); } catch (Exception e) { Log.error("suicide ",e); } @@ -307,5 +307,4 @@ protected void initLogLevel() { int level = Integer.parseInt(DiversifyProperties.getProperty("logLevel")); Log.set(level); } - } diff --git a/src/main/java/fr/inria/diversify/test/TestSosie.java b/src/main/java/fr/inria/diversify/test/TestSosie.java index caf1f15e..4e6abd27 100644 --- a/src/main/java/fr/inria/diversify/test/TestSosie.java +++ b/src/main/java/fr/inria/diversify/test/TestSosie.java @@ -48,7 +48,7 @@ protected Integer runTest(String directory) throws InterruptedException, Compile } protected Integer PrunTest(String directory) throws InterruptedException, CompileException { - RunMaven rt = new RunMaven(directory, "package", clojureTest); + RunMaven rt = new RunMaven(directory, "package",timeOut, clojureTest); rt.start(); int count = 0; while (rt.getFailures() == null && count < timeOut) { diff --git a/src/main/java/fr/inria/diversify/transformation/MavenInvocationResult.java b/src/main/java/fr/inria/diversify/transformation/MavenInvocationResult.java index 2a31df22..5bad6284 100644 --- a/src/main/java/fr/inria/diversify/transformation/MavenInvocationResult.java +++ b/src/main/java/fr/inria/diversify/transformation/MavenInvocationResult.java @@ -1,9 +1,62 @@ package fr.inria.diversify.transformation; +import org.apache.maven.shared.invoker.InvocationResult; +import org.codehaus.plexus.util.cli.CommandLineException; + /** * User: Simon * Date: 9/9/13 * Time: 3:20 PM */ -public class MavenInvocationResult { -} +public class MavenInvocationResult implements InvocationResult +{ + + /** + * The exception that prevented to execute the command line, will be null if Maven could be + * successfully started. + */ + private CommandLineException executionException; + + /** + * The exit code reported by the Maven invocation. + */ + private int exitCode = Integer.MIN_VALUE; + + /** + * Creates a new invocation result + */ + MavenInvocationResult() + { + // hide constructor + } + + public int getExitCode() + { + return exitCode; + } + + public CommandLineException getExecutionException() + { + return executionException; + } + + /** + * Sets the exit code reported by the Maven invocation. + * + * @param exitCode The exit code reported by the Maven invocation. + */ + void setExitCode( int exitCode ) + { + this.exitCode = exitCode; + } + + /** + * Sets the exception that prevented to execute the command line. + * + * @param executionException The exception that prevented to execute the command line, may be null. + */ + void setExecutionException( CommandLineException executionException ) + { + this.executionException = executionException; + } +} \ No newline at end of file diff --git a/src/main/java/fr/inria/diversify/transformation/MavenInvoker.java b/src/main/java/fr/inria/diversify/transformation/MavenInvoker.java index 9a1f11da..4764a3d0 100644 --- a/src/main/java/fr/inria/diversify/transformation/MavenInvoker.java +++ b/src/main/java/fr/inria/diversify/transformation/MavenInvoker.java @@ -1,9 +1,229 @@ package fr.inria.diversify.transformation; +import org.apache.maven.shared.invoker.*; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.util.cli.CommandLineException; +import org.codehaus.plexus.util.cli.CommandLineUtils; +import org.codehaus.plexus.util.cli.Commandline; + + +import java.io.File; +import java.io.InputStream; + /** * User: Simon * Date: 9/9/13 * Time: 3:15 PM */ -public class MavenInvoker { -} +@Component( role = Invoker.class, hint = "default" ) +public class MavenInvoker implements Invoker +{ + + public static final String ROLE_HINT = "default"; + + private static final InvokerLogger DEFAULT_LOGGER = new SystemOutLogger(); + + private static final InvocationOutputHandler DEFAULT_OUTPUT_HANDLER = new SystemOutHandler(); + + private File localRepositoryDirectory; + + private InvokerLogger logger = DEFAULT_LOGGER; + + private File workingDirectory; + + private File mavenHome; + + private File mavenExecutable; + + private InvocationOutputHandler outputHandler = DEFAULT_OUTPUT_HANDLER; + + private InputStream inputStream; + + private InvocationOutputHandler errorHandler = DEFAULT_OUTPUT_HANDLER; + + private int timeOut = 0; + + public InvocationResult execute( InvocationRequest request ) + throws MavenInvocationException + { + MavenCommandLineBuilder cliBuilder = new MavenCommandLineBuilder(); + + InvokerLogger logger = getLogger(); + if ( logger != null ) + { + cliBuilder.setLogger( getLogger() ); + } + + File localRepo = getLocalRepositoryDirectory(); + if ( localRepo != null ) + { + cliBuilder.setLocalRepositoryDirectory( getLocalRepositoryDirectory() ); + } + + File mavenHome = getMavenHome(); + if ( mavenHome != null ) + { + cliBuilder.setMavenHome( getMavenHome() ); + } + + File mavenExecutable = getMavenExecutable(); + if ( mavenExecutable != null ) + { + cliBuilder.setMavenExecutable( mavenExecutable ); + } + + + File workingDirectory = getWorkingDirectory(); + if ( workingDirectory != null ) + { + cliBuilder.setWorkingDirectory( getWorkingDirectory() ); + } + + Commandline cli; + try + { + cli = cliBuilder.build( request ); + } + catch ( CommandLineConfigurationException e ) + { + throw new MavenInvocationException( "Error configuring command-line. Reason: " + e.getMessage(), e ); + } + + MavenInvocationResult result = new MavenInvocationResult(); + + try + { + int exitCode = executeCommandLine( cli, request ); + + result.setExitCode( exitCode ); + } + catch ( CommandLineException e ) + { + result.setExecutionException( e ); + } + + return result; + } + + private int executeCommandLine( Commandline cli, InvocationRequest request ) + throws CommandLineException + { + int result = Integer.MIN_VALUE; + + + + InputStream inputStream = request.getInputStream( this.inputStream ); + InvocationOutputHandler outputHandler = request.getOutputHandler( this.outputHandler ); + InvocationOutputHandler errorHandler = request.getErrorHandler( this.errorHandler ); + + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( "Executing: " + cli ); + } + if ( request.isInteractive() ) + { + if ( inputStream == null ) + { + getLogger().warn( + "Maven will be executed in interactive mode" + + ", but no input stream has been configured for this MavenInvoker instance." ); + + result = CommandLineUtils.executeCommandLine( cli, outputHandler, errorHandler ); + } + else + { + result = CommandLineUtils.executeCommandLine( cli, inputStream, outputHandler, errorHandler, timeOut ); + } + } + else + { + if ( inputStream != null ) + { + getLogger().info( "Executing in batch mode. The configured input stream will be ignored." ); + } + + result = CommandLineUtils.executeCommandLine( cli, outputHandler, errorHandler, timeOut ); + } + + return result; + } + + public File getLocalRepositoryDirectory() + { + return localRepositoryDirectory; + } + + public InvokerLogger getLogger() + { + return logger; + } + + public Invoker setLocalRepositoryDirectory( File localRepositoryDirectory ) + { + this.localRepositoryDirectory = localRepositoryDirectory; + return this; + } + + public Invoker setLogger( InvokerLogger logger ) + { + this.logger = ( logger != null ) ? logger : DEFAULT_LOGGER; + return this; + } + + public File getWorkingDirectory() + { + return workingDirectory; + } + + public Invoker setWorkingDirectory( File workingDirectory ) + { + this.workingDirectory = workingDirectory; + return this; + } + + public File getMavenHome() + { + return mavenHome; + } + + public Invoker setMavenHome( File mavenHome ) + { + this.mavenHome = mavenHome; + + return this; + } + + public File getMavenExecutable() + { + return mavenExecutable; + } + + public Invoker setMavenExecutable( File mavenExecutable ) + { + this.mavenExecutable = mavenExecutable; + return this; + } + + public void setTimeOut(int i) { + this.timeOut = i; + } + + + public Invoker setErrorHandler( InvocationOutputHandler errorHandler ) + { + this.errorHandler = errorHandler; + return this; + } + + public Invoker setInputStream( InputStream inputStream ) + { + this.inputStream = inputStream; + return this; + } + + public Invoker setOutputHandler( InvocationOutputHandler outputHandler ) + { + this.outputHandler = outputHandler; + return this; + } +} \ No newline at end of file diff --git a/src/main/java/fr/inria/diversify/transformation/RunMaven.java b/src/main/java/fr/inria/diversify/transformation/RunMaven.java index 9550c849..ad211af5 100644 --- a/src/main/java/fr/inria/diversify/transformation/RunMaven.java +++ b/src/main/java/fr/inria/diversify/transformation/RunMaven.java @@ -22,17 +22,20 @@ public class RunMaven extends Thread { protected String lifeCycle; protected Integer failure = null; protected Boolean clojureTest = false; + private int timeOut; - public RunMaven(String directory, String lifeCycle) { + public RunMaven(String directory, String lifeCycle, int timeOut) { this.directory = directory; this.lifeCycle = lifeCycle; + this.timeOut = timeOut; } - public RunMaven(String directory, String lifeCycle, boolean clojureTest) { + public RunMaven(String directory, String lifeCycle, int timeOut, boolean clojureTest) { this.directory = directory; this.lifeCycle = lifeCycle; this.clojureTest = clojureTest; + this.timeOut = timeOut; } @@ -63,7 +66,8 @@ public void run() { l.add(lifeCycle); request.setGoals(l); - Invoker invoker = new DefaultInvoker(); + + MavenInvoker invoker = new MavenInvoker(); //freebsd File mvnHome = new File("/usr/local/share/java/maven3"); if(!mvnHome.exists()) @@ -71,9 +75,11 @@ public void run() { mvnHome = new File("/usr/share/maven"); invoker.setMavenHome(mvnHome); + invoker.setTimeOut(timeOut); ByteArrayOutputStream os = new ByteArrayOutputStream(); - PrintStreamHandler psh = new PrintStreamHandler(new PrintStream(os), true); + PrintStream stream = new PrintStream(os); + PrintStreamHandler psh = new PrintStreamHandler(stream, true); invoker.setOutputHandler(psh); invoker.setErrorHandler(psh); @@ -86,6 +92,13 @@ public void run() { parseResult(os.toString()); } catch (MavenInvocationException e) { + + e.printStackTrace(); + } + try { + stream.close(); + os.close(); + } catch (IOException e) { e.printStackTrace(); } } diff --git a/src/main/java/fr/inria/diversify/util/GitUtil.java b/src/main/java/fr/inria/diversify/util/GitUtil.java index 412e8603..625c8a9e 100644 --- a/src/main/java/fr/inria/diversify/util/GitUtil.java +++ b/src/main/java/fr/inria/diversify/util/GitUtil.java @@ -51,7 +51,6 @@ private static void updateExpList(String s) throws IOException { } public static void addToGit(String file) { - Log.info("add file: {} to git: {}",file,directory+"/diversify-exp/"); Runtime r = Runtime.getRuntime(); try { Process p = r.exec("sh git/add.sh " +directory+"/diversify-exp/ "+file+ " \"add file "+file+"\""); @@ -59,6 +58,7 @@ public static void addToGit(String file) { } catch (Exception e) { Log.error("addToGit ",e); } + Log.info("add file: {} to git: {}",file,directory+"/diversify-exp/"); } } diff --git a/utils/junit/replace.properties b/utils/junit/replace.properties index 6760ed03..7ef392c5 100644 --- a/utils/junit/replace.properties +++ b/utils/junit/replace.properties @@ -1,5 +1,5 @@ project=../junit -nbRun=100 +nbRun=50 timeOut=-1 result=result/junit jacoco=utils/junit/jacoco.exec