コード例 #1
0
    public void start() {
      WorkerProcessBuilder builder = workerFactory.create();
      builder.applicationClasspath(classPathRegistry.getClassPath("ANT").getAsFiles());
      builder.sharedPackages("org.apache.tools.ant");
      builder.getJavaCommand().systemProperty("test.system.property", "value");
      builder.getJavaCommand().environment("TEST_ENV_VAR", "value");
      builder.worker(action);

      if (mainClass != null) {
        builder.getJavaCommand().setMain(mainClass);
      }

      proc = builder.build();
      try {
        proc.start();
        assertFalse(startFails);
      } catch (ExecException e) {
        assertTrue(startFails);
        return;
      }
      proc.getConnection().addIncoming(TestListenerInterface.class, exceptionListener);
      if (serverAction != null) {
        serverAction.execute(proc.getConnection());
      }
    }
コード例 #2
0
  @Test
  public void createsAndConfiguresAWorkerProcess() throws Exception {
    final Set<File> processClassPath = Collections.singleton(new File("something.jar"));
    final org.gradle.internal.classpath.ClassPath classPath =
        context.mock(org.gradle.internal.classpath.ClassPath.class);

    context.checking(
        new Expectations() {
          {
            one(classPathRegistry).getClassPath("WORKER_PROCESS");
            will(returnValue(classPath));
            allowing(classPath).getAsFiles();
            will(returnValue(processClassPath));
            allowing(fileResolver).resolveLater(".");
            will(
                returnValue(
                    new Factory<File>() {
                      public File create() {
                        return new File(".");
                      }
                    }));
            allowing(fileResolver).resolveFiles(with(Matchers.<Object>notNullValue()));
            will(returnValue(new SimpleFileCollection()));
          }
        });

    WorkerProcessBuilder builder = factory.create();

    assertThat(builder.getJavaCommand().getMain(), equalTo(GradleWorkerMain.class.getName()));
    assertThat(builder.getLogLevel(), equalTo(LogLevel.LIFECYCLE));

    builder.worker(new TestAction());
    builder.applicationClasspath(Arrays.asList(new File("app.jar")));
    builder.sharedPackages("package1", "package2");

    final Address serverAddress = new SocketInetAddress(InetAddress.getByName("127.0.0.1"), 40);

    context.checking(
        new Expectations() {
          {
            one(messagingServer).accept(with(notNullValue(Action.class)));
            will(returnValue(serverAddress));
            one(idGenerator).generateId();
            will(returnValue("<id>"));
          }
        });

    WorkerProcess process = builder.build();

    assertThat(process, instanceOf(DefaultWorkerProcess.class));

    ObjectInputStream instr = new ObjectInputStream(builder.getJavaCommand().getStandardInput());
    assertThat(instr.readObject(), instanceOf(IsolatedApplicationClassLoaderWorker.class));
  }