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
 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());
 }
예제 #3
0
 private void attachTasksToBinary(
     ClassDirectoryBinarySpecInternal binary, SourceSet sourceSet, Project target) {
   Task compileTask = target.getTasks().getByPath(sourceSet.getCompileJavaTaskName());
   Task resourcesTask = target.getTasks().getByPath(sourceSet.getProcessResourcesTaskName());
   Task classesTask = target.getTasks().getByPath(sourceSet.getClassesTaskName());
   binary.getTasks().add(compileTask);
   binary.getTasks().add(resourcesTask);
   binary.getTasks().add(classesTask);
   binary.setBuildTask(classesTask);
 }
예제 #4
0
 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);
   }
 }
예제 #5
0
  @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();
              }
            });
  }
 private ClassLoader buildRuntimeScopeClassLoader() {
   final ArrayList<URL> classPathUrls = new ArrayList<URL>();
   final SourceSet mainSourceSet =
       project
           .getConvention()
           .getPlugin(JavaPluginConvention.class)
           .getSourceSets()
           .findByName(SourceSet.MAIN_SOURCE_SET_NAME);
   for (File file : mainSourceSet.getRuntimeClasspath()) {
     try {
       classPathUrls.add(file.toURI().toURL());
     } catch (MalformedURLException e) {
       throw new InjectionException(
           "Could not determine artifact URL [" + file.getPath() + "]", e);
     }
   }
   return new URLClassLoader(
       classPathUrls.toArray(new URL[classPathUrls.size()]), getClass().getClassLoader());
 }
예제 #7
0
 public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) {
   ConventionMapping conventionMapping;
   compile.setDescription(String.format("Compiles the %s.", sourceSet.getJava()));
   conventionMapping = compile.getConventionMapping();
   compile.setSource(sourceSet.getJava());
   conventionMapping.map(
       "classpath",
       new Callable<Object>() {
         public Object call() throws Exception {
           return sourceSet.getCompileClasspath();
         }
       });
   conventionMapping.map(
       "destinationDir",
       new Callable<Object>() {
         public Object call() throws Exception {
           return sourceSet.getOutput().getClassesDir();
         }
       });
 }
예제 #8
0
  private void definePathsForSourceSet(
      final SourceSet sourceSet, ConventionMapping outputConventionMapping, final Project project) {
    outputConventionMapping.map(
        "classesDir",
        new Callable<Object>() {
          public Object call() throws Exception {
            String classesDirName = String.format("classes/%s", sourceSet.getName());
            return new File(project.getBuildDir(), classesDirName);
          }
        });
    outputConventionMapping.map(
        "resourcesDir",
        new Callable<Object>() {
          public Object call() throws Exception {
            String classesDirName = String.format("resources/%s", sourceSet.getName());
            return new File(project.getBuildDir(), classesDirName);
          }
        });

    sourceSet.getJava().srcDir(String.format("src/%s/java", sourceSet.getName()));
    sourceSet.getResources().srcDir(String.format("src/%s/resources", sourceSet.getName()));
  }
  protected void configureEclipseClasspath(Project project, SourceSet testIntegrationSourceSet) {

    EclipseModel eclipseModel = GradleUtil.getExtension(project, EclipseModel.class);

    EclipseClasspath eclipseClasspath = eclipseModel.getClasspath();

    Collection<Configuration> plusConfigurations = eclipseClasspath.getPlusConfigurations();

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

    plusConfigurations.add(configuration);
  }
예제 #10
0
 private void createProcessResourcesTaskForBinary(
     final SourceSet sourceSet, JvmResourceSet resourceSet, final Project target) {
   Copy resourcesTask =
       target.getTasks().create(sourceSet.getProcessResourcesTaskName(), ProcessResources.class);
   resourcesTask.setDescription(String.format("Processes %s.", resourceSet));
   new DslObject(resourcesTask)
       .getConventionMapping()
       .map(
           "destinationDir",
           new Callable<File>() {
             public File call() throws Exception {
               return sourceSet.getOutput().getResourcesDir();
             }
           });
   resourcesTask.from(resourceSet.getSource());
 }
  protected void configureIdeaModule(Project project, SourceSet testIntegrationSourceSet) {

    IdeaModel ideaModel = GradleUtil.getExtension(project, IdeaModel.class);

    IdeaModule ideaModule = ideaModel.getModule();

    Map<String, Map<String, Collection<Configuration>>> scopes = ideaModule.getScopes();

    Map<String, Collection<Configuration>> testScope = scopes.get("TEST");

    Collection<Configuration> plusConfigurations = testScope.get("plus");

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

    plusConfigurations.add(configuration);
  }
예제 #12
0
 private void createCompileJavaTaskForBinary(
     final SourceSet sourceSet, final JavaSourceSet javaSourceSet, Project target) {
   JavaCompile compileTask =
       target.getTasks().create(sourceSet.getCompileJavaTaskName(), JavaCompile.class);
   compileTask.setDescription(String.format("Compiles %s.", javaSourceSet));
   compileTask.setSource(javaSourceSet.getSource());
   compileTask.dependsOn(javaSourceSet);
   ConventionMapping conventionMapping = compileTask.getConventionMapping();
   conventionMapping.map(
       "classpath",
       new Callable<Object>() {
         public Object call() throws Exception {
           return javaSourceSet.getCompileClasspath().getFiles();
         }
       });
   conventionMapping.map(
       "destinationDir",
       new Callable<Object>() {
         public Object call() throws Exception {
           return sourceSet.getOutput().getClassesDir();
         }
       });
 }
예제 #13
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));
  }
예제 #14
0
  private File _getResourcesDir(Project project) {
    SourceSet sourceSet = GradleUtil.getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME);

    return _getSrcDir(sourceSet.getResources());
  }