/**
   * Adapts the source object to a view object.
   *
   * @param mapper An action that is invoked for each source object in the graph that is to be
   *     adapted. The action can influence how the source object is adapted via the provided {@link
   *     SourceObjectMapping}.
   */
  public <T, S> T adapt(
      Class<T> targetType, S sourceObject, Action<? super SourceObjectMapping> mapper) {
    if (sourceObject == null) {
      return null;
    }
    Class<? extends T> wrapperType = targetTypeProvider.getTargetType(targetType, sourceObject);
    DefaultSourceObjectMapping mapping =
        new DefaultSourceObjectMapping(sourceObject, targetType, wrapperType);
    mapper.execute(mapping);
    wrapperType = mapping.wrapperType.asSubclass(targetType);
    if (wrapperType.isInstance(sourceObject)) {
      return wrapperType.cast(sourceObject);
    }
    if (targetType.isEnum()) {
      return adaptToEnum(targetType, sourceObject);
    }

    MixInMethodInvoker mixInMethodInvoker = null;
    if (mapping.mixInType != null) {
      mixInMethodInvoker =
          new MixInMethodInvoker(
              mapping.mixInType, new AdaptingMethodInvoker(mapper, new ReflectionMethodInvoker()));
    }
    MethodInvoker overrideInvoker = chainInvokers(mixInMethodInvoker, mapping.overrideInvoker);
    Object proxy =
        Proxy.newProxyInstance(
            wrapperType.getClassLoader(),
            new Class<?>[] {wrapperType},
            new InvocationHandlerImpl(sourceObject, overrideInvoker, mapper));
    if (mixInMethodInvoker != null) {
      mixInMethodInvoker.setProxy(proxy);
    }
    return wrapperType.cast(proxy);
  }
  public void execute(WorkerContext workerContext) {
    LoggingManagerInternal loggingManager = createLoggingManager();
    loggingManager.setLevel(logLevel).start();

    FilteringClassLoader filteredWorkerClassLoader =
        new FilteringClassLoader(getClass().getClassLoader());
    filteredWorkerClassLoader.allowPackage("org.slf4j");
    filteredWorkerClassLoader.allowClass(Action.class);
    filteredWorkerClassLoader.allowClass(WorkerContext.class);

    ClassLoader applicationClassLoader = workerContext.getApplicationClassLoader();
    FilteringClassLoader filteredApplication = new FilteringClassLoader(applicationClassLoader);
    ObservableUrlClassLoader implementationClassLoader =
        createImplementationClassLoader(filteredWorkerClassLoader, filteredApplication);

    // Configure classpaths
    for (String sharedPackage : sharedPackages) {
      filteredApplication.allowPackage(sharedPackage);
    }
    implementationClassLoader.addURLs(implementationClassPath);

    // Deserialize the worker action
    Action<WorkerContext> action;
    try {
      ObjectInputStream instr =
          new ClassLoaderObjectInputStream(
              new ByteArrayInputStream(serializedWorkerAction), implementationClassLoader);
      action = (Action<WorkerContext>) instr.readObject();
    } catch (Exception e) {
      throw UncheckedException.asUncheckedException(e);
    }
    action.execute(workerContext);
  }
    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());
      }
    }
 @Override
 public DeploymentDescriptor securityRole(Action<? super EarSecurityRole> action) {
   EarSecurityRole role = instantiator.newInstance(DefaultEarSecurityRole.class);
   action.execute(role);
   securityRoles.add(role);
   return this;
 }
  private BuildResult run(Action<GradleExecutionResult> resultVerification) {
    if (projectDirectory == null) {
      throw new InvalidRunnerConfigurationException(
          "Please specify a project directory before executing the build");
    }

    File testKitDir = createTestKitDir(testKitDirProvider);

    GradleDistribution effectiveDistribution =
        distribution == null ? findGradleInstallFromGradleRunner() : distribution;

    GradleExecutionResult execResult =
        gradleExecutor.run(
            new GradleExecutionParameters(
                effectiveDistribution,
                testKitDir,
                projectDirectory,
                arguments,
                jvmArguments,
                classpath,
                debug,
                standardOutput,
                standardError));

    resultVerification.execute(execResult);
    return createBuildResult(execResult);
  }
 public void execute(ExecutionListener executionListener) {
   LoggingManagerInternal loggingManager =
       loggingServices.getFactory(LoggingManagerInternal.class).create();
   loggingManager.setLevel(loggingConfiguration.getLogLevel());
   loggingManager.colorStdOutAndStdErr(loggingConfiguration.isColorOutput());
   loggingManager.start();
   action.execute(executionListener);
 }
Beispiel #7
0
 @Override
 public synchronized Long maybeStoreEntry(Action<Long> storeEntryAction) {
   if (assignedId == null) {
     assignedId = nextId;
     storeEntryAction.execute(assignedId);
   }
   return assignedId;
 }
 public void execute(ExecutionListener executionListener) {
   try {
     action.execute(executionListener);
   } catch (ReportedException e) {
     executionListener.onFailure(e.getCause());
   } catch (Throwable t) {
     reporter.reportException(t);
     executionListener.onFailure(t);
   }
 }
 private void eachLine(Action<String> action) {
   BufferedReader reader = new BufferedReader(new StringReader(getOutput()));
   String line;
   try {
     while ((line = reader.readLine()) != null) {
       action.execute(line);
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
Beispiel #10
0
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    NoInputsRuleAction that = (NoInputsRuleAction) o;
    return action.equals(that.action);
  }
  public Void call() throws Exception {
    final ObservableUrlClassLoader applicationClassLoader = createApplicationClassLoader();

    WorkerContext context =
        new WorkerContext() {
          public ClassLoader getApplicationClassLoader() {
            return applicationClassLoader;
          }
        };

    worker.execute(context);

    return null;
  }
 public PersistentCache open(
     File cacheDir,
     String displayName,
     CacheUsage usage,
     CacheValidator cacheValidator,
     Map<String, ?> properties,
     FileLockManager.LockMode lockMode,
     Action<? super PersistentCache> initializer) {
   GFileUtils.mkdirs(cacheDir);
   InMemoryCache cache = new InMemoryCache(cacheDir);
   if (initializer != null) {
     initializer.execute(cache);
   }
   return cache;
 }
  private BuildResult run(Action<GradleExecutionResult> resultVerification) {
    if (projectDirectory == null) {
      throw new InvalidRunnerConfigurationException(
          "Please specify a project directory before executing the build");
    }

    GradleExecutionResult execResult =
        gradleExecutor.run(
            gradleHome, gradleUserHomeDir, projectDirectory, arguments, jvmArguments);

    resultVerification.execute(execResult);

    return new DefaultBuildResult(
        execResult.getStandardOutput(), execResult.getStandardError(), execResult.getTasks());
  }
 public void resolve(DependencyMetaData dependency, BuildableComponentIdResolveResult result) {
   ModuleVersionSelector module = dependency.getRequested();
   DefaultDependencyResolveDetails details = new DefaultDependencyResolveDetails(module);
   try {
     rule.execute(details);
   } catch (Throwable e) {
     result.failed(new ModuleVersionResolveException(module, e));
     return;
   }
   if (details.isUpdated()) {
     DependencyMetaData substitutedDependency =
         dependency.withRequestedVersion(details.getTarget());
     resolver.resolve(substitutedDependency, result);
     result.setSelectionReason(details.getSelectionReason());
     return;
   }
   resolver.resolve(dependency, result);
 }
 public void onCreate(ModelNodeInternal node) {
   if (boundTo != null) {
     throw new IllegalStateException(
         String.format(
             "Reference %s for %s is already bound to %s.",
             predicate.getReference(), referrer, boundTo));
   }
   ModelPromise promise = node.getPromise();
   if (isTypeCompatible(promise)) {
     boundTo = node;
     bindAction.execute(this);
   } else {
     throw new InvalidModelRuleException(
         referrer,
         new ModelRuleBindingException(
             IncompatibleTypeReferenceReporter.of(
                     node, promise, predicate.getReference(), writable)
                 .asString()));
   }
 }
Beispiel #16
0
 protected LocallyAvailableResource doAdd(
     File destination, String failureDescription, Action<File> action) {
   try {
     GFileUtils.parentMkdirs(destination);
     File inProgressMarkerFile = getInProgressMarkerFile(destination);
     GFileUtils.touch(inProgressMarkerFile);
     try {
       deleteAction.delete(destination);
       action.execute(destination);
     } catch (Throwable t) {
       deleteAction.delete(destination);
       throw t;
     } finally {
       deleteAction.delete(inProgressMarkerFile);
     }
   } catch (Throwable t) {
     throw new GradleException(failureDescription, t);
   }
   return entryAt(destination);
 }
  RemoteTestClassProcessor forkProcess() {
    WorkerProcessBuilder builder = workerFactory.create();
    builder.setBaseName("Gradle Test Executor");
    builder.applicationClasspath(classPath);
    builder.setLoadApplicationInSystemClassLoader(true);
    builder.worker(new TestWorker(processorFactory));
    options.copyTo(builder.getJavaCommand());
    buildConfigAction.execute(builder);

    workerProcess = builder.build();
    workerProcess.start();

    ObjectConnection connection = workerProcess.getConnection();
    connection.useParameterSerializer(TestEventSerializer.create());
    connection.addIncoming(TestResultProcessor.class, resultProcessor);
    RemoteTestClassProcessor remoteProcessor =
        connection.addOutgoing(RemoteTestClassProcessor.class);
    connection.connect();
    remoteProcessor.startProcessing();
    return remoteProcessor;
  }
 public GradleExecuter using(Action<GradleExecuter> action) {
   action.execute(executer);
   return executer;
 }
 public IvyArtifact artifact(Object source, Action<? super IvyArtifact> config) {
   IvyArtifact artifact = artifact(source);
   config.execute(artifact);
   return artifact;
 }
 public void descriptor(Action<? super IvyModuleDescriptorSpec> configure) {
   configure.execute(descriptor);
 }
 public void configurations(Action<? super IvyConfigurationContainer> config) {
   config.execute(configurations);
 }
 public void source(Action<? super SourceDirectorySet> config) {
   config.execute(getSource());
 }
 public MavenArtifact addArtifact(Object source, Action<? super MavenArtifact> config) {
   MavenArtifact artifact = addArtifact(source);
   config.execute(artifact);
   return artifact;
 }
 public void visitClasses(Action<? super TestClassResult> visitor) {
   for (TestClassResult classResult : results.values()) {
     visitor.execute(classResult);
   }
 }
Beispiel #25
0
 public void execute(T subject, List<?> inputs) {
   action.execute(subject);
 }
 public void walk(Action<? super CopySpecInternal> action) {
   action.execute(this);
   for (CopySpecInternal child : getChildren()) {
     child.walk(action);
   }
 }
Beispiel #27
0
 @Override
 public int hashCode() {
   return action.hashCode();
 }
  @Test
  public void executorDoesNotInterruptExecutionInCaseOfError() {
    action.execute(javaExecSpec);

    verify(javaExecSpec).setIgnoreExitValue(true);
  }
 @Override
 public void execute(MutableModelNode modelNode, T view, List<ModelView<?>> inputs) {
   configAction.execute(view);
 }
Beispiel #30
0
 public void copyTo(OutputStream outstr) {
   generator.execute(outstr);
 }