コード例 #1
1
  /**
   * 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);
  }
コード例 #2
0
  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);
  }
コード例 #3
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());
      }
    }
コード例 #4
0
 @Override
 public DeploymentDescriptor securityRole(Action<? super EarSecurityRole> action) {
   EarSecurityRole role = instantiator.newInstance(DefaultEarSecurityRole.class);
   action.execute(role);
   securityRoles.add(role);
   return this;
 }
コード例 #5
0
  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);
  }
コード例 #6
0
 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);
 }
コード例 #7
0
ファイル: DefaultVisitedTree.java プロジェクト: Zhuoli/gradle
 @Override
 public synchronized Long maybeStoreEntry(Action<Long> storeEntryAction) {
   if (assignedId == null) {
     assignedId = nextId;
     storeEntryAction.execute(assignedId);
   }
   return assignedId;
 }
コード例 #8
0
 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);
   }
 }
コード例 #9
0
 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);
   }
 }
コード例 #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);
  }
コード例 #11
0
  public Void call() throws Exception {
    final ObservableUrlClassLoader applicationClassLoader = createApplicationClassLoader();

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

    worker.execute(context);

    return null;
  }
コード例 #12
0
 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;
 }
コード例 #13
0
  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());
  }
コード例 #14
0
 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);
 }
コード例 #15
0
 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()));
   }
 }
コード例 #16
0
ファイル: PathKeyFileStore.java プロジェクト: BuildAPE/gradle
 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);
 }
コード例 #17
0
  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;
  }
コード例 #18
0
 public GradleExecuter using(Action<GradleExecuter> action) {
   action.execute(executer);
   return executer;
 }
コード例 #19
0
 public IvyArtifact artifact(Object source, Action<? super IvyArtifact> config) {
   IvyArtifact artifact = artifact(source);
   config.execute(artifact);
   return artifact;
 }
コード例 #20
0
 public void descriptor(Action<? super IvyModuleDescriptorSpec> configure) {
   configure.execute(descriptor);
 }
コード例 #21
0
 public void configurations(Action<? super IvyConfigurationContainer> config) {
   config.execute(configurations);
 }
コード例 #22
0
 public void source(Action<? super SourceDirectorySet> config) {
   config.execute(getSource());
 }
コード例 #23
0
 public MavenArtifact addArtifact(Object source, Action<? super MavenArtifact> config) {
   MavenArtifact artifact = addArtifact(source);
   config.execute(artifact);
   return artifact;
 }
コード例 #24
0
 public void visitClasses(Action<? super TestClassResult> visitor) {
   for (TestClassResult classResult : results.values()) {
     visitor.execute(classResult);
   }
 }
コード例 #25
0
 public void execute(T subject, List<?> inputs) {
   action.execute(subject);
 }
コード例 #26
0
 public void walk(Action<? super CopySpecInternal> action) {
   action.execute(this);
   for (CopySpecInternal child : getChildren()) {
     child.walk(action);
   }
 }
コード例 #27
0
 @Override
 public int hashCode() {
   return action.hashCode();
 }
コード例 #28
0
  @Test
  public void executorDoesNotInterruptExecutionInCaseOfError() {
    action.execute(javaExecSpec);

    verify(javaExecSpec).setIgnoreExitValue(true);
  }
コード例 #29
0
 @Override
 public void execute(MutableModelNode modelNode, T view, List<ModelView<?>> inputs) {
   configAction.execute(view);
 }
コード例 #30
0
ファイル: MapFileTree.java プロジェクト: tariq1890/gradle
 public void copyTo(OutputStream outstr) {
   generator.execute(outstr);
 }