コード例 #1
0
  protected SourceSet addSourceSetTestIntegration(Project project) {
    SourceSet testIntegrationSourceSet =
        GradleUtil.addSourceSet(project, TEST_INTEGRATION_SOURCE_SET_NAME);

    Configuration testIntegrationCompileConfiguration =
        GradleUtil.getConfiguration(
            project, testIntegrationSourceSet.getCompileConfigurationName());

    Configuration testCompileConfiguration =
        GradleUtil.getConfiguration(project, JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME);

    testIntegrationCompileConfiguration.extendsFrom(testCompileConfiguration);

    Configuration testIntegrationRuntimeConfiguration =
        GradleUtil.getConfiguration(
            project, testIntegrationSourceSet.getRuntimeConfigurationName());

    Configuration testRuntimeConfiguration =
        GradleUtil.getConfiguration(project, JavaPlugin.TEST_RUNTIME_CONFIGURATION_NAME);

    testIntegrationRuntimeConfiguration.extendsFrom(
        testRuntimeConfiguration, testIntegrationCompileConfiguration);

    SourceSet mainSourceSet = GradleUtil.getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME);

    FileCollection compileClasspath = testIntegrationSourceSet.getCompileClasspath();

    testIntegrationSourceSet.setCompileClasspath(compileClasspath.plus(mainSourceSet.getOutput()));

    FileCollection runtimeClasspath = testIntegrationSourceSet.getRuntimeClasspath();

    testIntegrationSourceSet.setRuntimeClasspath(runtimeClasspath.plus(mainSourceSet.getOutput()));

    return testIntegrationSourceSet;
  }
コード例 #2
0
ファイル: RunApp.java プロジェクト: newsun/spring-boot
 private String findMainClass(SourceSet main) {
   if (main == null) {
     return null;
   }
   getLogger().info("Looking for main in: " + main.getOutput().getClassesDir());
   try {
     return MainClassFinder.findMainClass(main.getOutput().getClassesDir());
   } catch (IOException ex) {
     throw new IllegalStateException("Cannot find main class", ex);
   }
 }
コード例 #3
0
 private void createBinaryLifecycleTask(SourceSet sourceSet, Project target) {
   Task binaryLifecycleTask = target.task(sourceSet.getClassesTaskName());
   binaryLifecycleTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
   binaryLifecycleTask.setDescription(String.format("Assembles %s.", sourceSet));
   binaryLifecycleTask.dependsOn(sourceSet.getOutput().getDirs());
   binaryLifecycleTask.dependsOn(sourceSet.getCompileJavaTaskName());
   binaryLifecycleTask.dependsOn(sourceSet.getProcessResourcesTaskName());
 }
コード例 #4
0
ファイル: RunApp.java プロジェクト: newsun/spring-boot
  @TaskAction
  public void runApp() {

    final Project project = getProject();
    final SourceSet main = ComputeMain.findMainSourceSet(project);
    final File outputDir = (main == null ? null : main.getOutput().getResourcesDir());
    final Set<File> allResources = new LinkedHashSet<File>();
    if (main != null) {
      allResources.addAll(main.getResources().getSrcDirs());
    }

    project
        .getTasks()
        .withType(
            JavaExec.class,
            new Action<JavaExec>() {

              @Override
              public void execute(JavaExec exec) {
                ArrayList<File> files = new ArrayList<File>(exec.getClasspath().getFiles());
                files.addAll(0, allResources);
                getLogger().info("Adding classpath: " + allResources);
                exec.setClasspath(new SimpleFileCollection(files));
                if (exec.getMain() == null) {
                  final String mainClass = findMainClass(main);
                  exec.setMain(mainClass);
                  exec.getConventionMapping()
                      .map(
                          "main",
                          new Callable<String>() {

                            @Override
                            public String call() throws Exception {
                              return mainClass;
                            }
                          });
                  getLogger().info("Found main: " + mainClass);
                }
                if (outputDir != null) {
                  for (File directory : allResources) {
                    FileUtils.removeDuplicatesFromOutputDirectory(outputDir, directory);
                  }
                }
                exec.exec();
              }
            });
  }
コード例 #5
0
  private void defineConfigurationsForSourceSet(
      SourceSet sourceSet, ConfigurationContainer configurations) {
    Configuration compileConfiguration =
        configurations.findByName(sourceSet.getCompileConfigurationName());
    if (compileConfiguration == null) {
      compileConfiguration = configurations.create(sourceSet.getCompileConfigurationName());
    }
    compileConfiguration.setVisible(false);
    compileConfiguration.setDescription(String.format("Compile classpath for %s.", sourceSet));

    Configuration runtimeConfiguration =
        configurations.findByName(sourceSet.getRuntimeConfigurationName());
    if (runtimeConfiguration == null) {
      runtimeConfiguration = configurations.create(sourceSet.getRuntimeConfigurationName());
    }
    runtimeConfiguration.setVisible(false);
    runtimeConfiguration.extendsFrom(compileConfiguration);
    runtimeConfiguration.setDescription(String.format("Runtime classpath for %s.", sourceSet));

    sourceSet.setCompileClasspath(compileConfiguration);
    sourceSet.setRuntimeClasspath(sourceSet.getOutput().plus(runtimeConfiguration));
  }