Projects >> gradle >>87c3702f764aaff3b1016bedf82ebcaf6fab2e01

Chunk
Conflicting content
//        originalIn.close();
    }

<<<<<<< HEAD
=======
    public void run() {
        //TODO SF - very simple/no validation
        String timeoutProperty = startParameter.getSystemPropertiesArgs().get(DaemonTimeout.TIMEOUT_PROPERTY);
        int idleTimeout = (timeoutProperty != null)? Integer.parseInt(timeoutProperty) : 3 * 60 * 60 * 1000;
        LOGGER.info("Daemon idle timeout is configured to: " + idleTimeout/1000 + " secs");
        final StoppableExecutor executor = executorFactory.create("DaemonMain executor");

        server.accept(idleTimeout, new IncomingConnectionHandler() {
            public void handle(final Connection connection, final CompletionHandler serverControl) {
                //we're spinning a thread to do work to avoid blocking the connection
                //This means that the Daemon potentially can have multiple jobs running.
                //We only allow 2 threads max - one for the build, second for potential Stop request
                executor.execute(new Runnable() {
                    public void run() {
                        Command command = null;
                        try {
                            command = lockAndReceive(connection, serverControl);
                            if (command == null) {
                                LOGGER.warn("It seems the client dropped the connection before sending any command. Stopping connection.");
                                unlock(serverControl);  //TODO SF - if receiving is first we don't need this really
                                connection.stop();
                                return;
                            }
                        } catch (BusyException e) {
                            connection.dispatch(new CommandComplete(e));
                            return;
                        }
                        try {
                            doRun(connection, serverControl, command);
                        } finally {
                            unlock(serverControl);
                            connection.stop();
                        }
                    }
                });
            }
        });

        executorFactory.stop();
    }

    private void unlock(CompletionHandler serverControl) {
        serverControl.onActivityComplete();
    }

    private void doRun(final Connection connection, CompletionHandler serverControl, Command command) {
        CommandComplete result = null;
        Throwable failure = null;
        try {
            LoggingOutputInternal loggingOutput = loggingServices.get(LoggingOutputInternal.class);
            OutputEventListener listener = new OutputEventListener() {
                public void onOutput(OutputEvent event) {
                    try {
                        connection.dispatch(event);
                    } catch (Exception e) {
                        //TODO SF we need handling for this. It means the client disconnected
                    }
                }
            };

            // Perform as much as possible of the interaction while the logging is routed to the client
            loggingOutput.addOutputEventListener(listener);
            try {
                result = doRunWithLogging(serverControl, command);
            } finally {
                loggingOutput.removeOutputEventListener(listener);
            }
         } catch (ReportedException e) {
            failure = e;
        } catch (Throwable throwable) {
            LOGGER.error("Could not execute build.", throwable);
            failure = throwable;
        }
        if (failure != null) {
            result = new CommandComplete(UncheckedException.asUncheckedException(failure));
        }
        assert result != null;
        connection.dispatch(result);
    }

    private Command lockAndReceive(Connection connection, CompletionHandler serverControl) {
        try {
            //TODO SF - receiving can be first and the logic gets simpler
            serverControl.onStartActivity();
            return (Command) connection.receive(); //client only sends
            //receiving is blocking
            //can return null (when the other side disconnects)
        } catch (BusyException busy) {
            Command command = (Command) connection.receive();
            if (command instanceof Stop) {
                //that's ok, if the daemon is busy we still want to be able to stop it
                LOGGER.info("The daemon is busy and Stop command was received. Stopping...");
                return command;
            }
            //otherwise it is a build request and we are already busy
            LOGGER.info("The daemon is busy and another build request received. Returning Busy response.");
            throw busy;
        }
    }

    private CommandComplete doRunWithLogging(Stoppable serverControl, Command command) {
        try {
            return doRunWithExceptionHandling(command, serverControl);
        } catch (ReportedException e) {
            throw e;
        } catch (Throwable throwable) {
            StyledTextOutputFactory outputFactory = loggingServices.get(StyledTextOutputFactory.class);
            BuildClientMetaData clientMetaData = command.getClientMetaData();
            BuildExceptionReporter exceptionReporter = new BuildExceptionReporter(outputFactory, new StartParameter(), clientMetaData);
            exceptionReporter.reportException(throwable);
            throw new ReportedException(throwable);
        }
    }

    private CommandComplete doRunWithExceptionHandling(Command command, Stoppable serverControl) {
        LOGGER.info("Executing {}", command);
        if (command instanceof Stop) {
            LOGGER.lifecycle("Stopping");
            serverControl.stop();
            return new CommandComplete(null);
        }

        return build((Build) command);
    }

    private Result build(Build build) {
        Properties originalSystemProperties = new Properties();
        originalSystemProperties.putAll(System.getProperties());
        Properties clientSystemProperties = new Properties();
        clientSystemProperties.putAll(build.getParameters().getSystemProperties());
        System.setProperties(clientSystemProperties);
        try {
            DefaultGradleLauncherActionExecuter executer = new DefaultGradleLauncherActionExecuter(launcherFactory, loggingServices);
            Object result = executer.execute(build.getAction(), build.getParameters());
            return new Result(result);
        } finally {
            System.setProperties(originalSystemProperties);
        }
    }
>>>>>>> 73b3879baed2fd8c4b9f4d14c5b51b570cc7f308
}
Solution content
//        originalIn.close();
    }

}
File
DaemonMain.java
Developer's decision
Version 1
Kind of conflict
Method declaration
Chunk
Conflicting content
        daemon.workingDir(userHomeDir);
        daemon.start();
    }
<<<<<<< HEAD

}
=======
    
    public PersistentDaemonRegistry getDaemonRegistry() {
        return (PersistentDaemonRegistry)super.getDaemonRegistry();
    }
}
>>>>>>> 73b3879baed2fd8c4b9f4d14c5b51b570cc7f308
Solution content
}
        daemon.workingDir(userHomeDir);
        daemon.start();
    }
File
ExternalDaemonConnector.java
Developer's decision
Version 1
Kind of conflict
Method declaration