Ejemplo n.º 1
0
  private void addRunTask() {
    JavaExec run = project.getTasks().create(TASK_RUN_NAME, JavaExec.class);
    run.setDescription("Runs this project as a JVM application");
    run.setGroup(APPLICATION_GROUP);

    JavaPluginConvention javaPluginConvention =
        project.getConvention().getPlugin(JavaPluginConvention.class);
    run.setClasspath(
        javaPluginConvention
            .getSourceSets()
            .getByName(SourceSet.MAIN_SOURCE_SET_NAME)
            .getRuntimeClasspath());
    run.getConventionMapping()
        .map(
            "main",
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                return pluginConvention.getMainClassName();
              }
            });
    run.getConventionMapping()
        .map(
            "jvmArgs",
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                return pluginConvention.getApplicationDefaultJvmArgs();
              }
            });
  }
Ejemplo n.º 2
0
  private void configureSourceSetDefaults(
      final Project project, final JavaBasePlugin javaBasePlugin) {
    final ProjectInternal projectInternal = (ProjectInternal) project;
    project
        .getConvention()
        .getPlugin(JavaPluginConvention.class)
        .getSourceSets()
        .all(
            new Action<SourceSet>() {
              public void execute(SourceSet sourceSet) {
                final DefaultGroovySourceSet groovySourceSet =
                    new DefaultGroovySourceSet(
                        ((DefaultSourceSet) sourceSet).getDisplayName(),
                        projectInternal.getFileResolver());
                ((DynamicObjectAware) sourceSet)
                    .getConvention()
                    .getPlugins()
                    .put("groovy", groovySourceSet);

                groovySourceSet
                    .getGroovy()
                    .srcDir(String.format("src/%s/groovy", sourceSet.getName()));
                sourceSet
                    .getResources()
                    .getFilter()
                    .exclude(
                        new Spec<FileTreeElement>() {
                          public boolean isSatisfiedBy(FileTreeElement element) {
                            return groovySourceSet.getGroovy().contains(element.getFile());
                          }
                        });
                sourceSet.getAllJava().source(groovySourceSet.getGroovy());
                sourceSet.getAllSource().source(groovySourceSet.getGroovy());

                String compileTaskName = sourceSet.getCompileTaskName("groovy");
                GroovyCompile compile =
                    project.getTasks().add(compileTaskName, GroovyCompile.class);
                javaBasePlugin.configureForSourceSet(sourceSet, compile);
                compile.dependsOn(sourceSet.getCompileJavaTaskName());
                compile.setDescription(
                    String.format("Compiles the %s Groovy source.", sourceSet.getName()));
                compile.conventionMapping(
                    "defaultSource",
                    new ConventionValue() {
                      public Object getValue(
                          Convention convention, IConventionAware conventionAwareObject) {
                        return groovySourceSet.getGroovy();
                      }
                    });

                project
                    .getTasks()
                    .getByName(sourceSet.getClassesTaskName())
                    .dependsOn(compileTaskName);
              }
            });
  }
  private JarOutputsModel getProjectInfo(Project project) {
    if (project.getConvention().findPlugin(JavaPluginConvention.class) == null) {
      return null;
    }

    List<JarOutput> result = new LinkedList<JarOutput>();
    TaskCollection<? extends Jar> allJars = project.getTasks().withType(Jar.class);

    for (Jar jar : allJars) {
      result.add(
          new JarOutput(jar.getName(), jar.getArchivePath(), tryGetAllJarSourceSetNames(jar)));
    }

    return new JarOutputsModel(result);
  }
Ejemplo n.º 4
0
 private void addDefaultReportTask(final JacocoPluginExtension extension, final Test task) {
   final JacocoReport reportTask =
       project
           .getTasks()
           .create(
               "jacoco" + StringUtils.capitalise(task.getName()) + "Report", JacocoReport.class);
   reportTask.executionData(task);
   reportTask.sourceSets(
       project
           .getConvention()
           .getPlugin(JavaPluginConvention.class)
           .getSourceSets()
           .getByName("main"));
   ConventionMapping taskMapping = ((IConventionAware) reportTask).getConventionMapping();
   taskMapping
       .getConventionValue(reportTask.getReports(), "reports", false)
       .all(
           new Action<Report>() {
             @Override
             public void execute(final Report report) {
               ConventionMapping reportMapping =
                   ((IConventionAware) report).getConventionMapping();
               // reportMapping.map('enabled', Callables.returning(true));
               if (report.getOutputType().equals(Report.OutputType.DIRECTORY)) {
                 reportMapping.map(
                     "destination",
                     new Callable<File>() {
                       @Override
                       public File call() {
                         return new File(
                             extension.getReportsDir(), task.getName() + "/" + report.getName());
                       }
                     });
               } else {
                 reportMapping.map(
                     "destination",
                     new Callable<File>() {
                       @Override
                       public File call() {
                         return new File(
                             extension.getReportsDir(),
                             task.getName() + "/" + reportTask.getName() + "." + report.getName());
                       }
                     });
               }
             }
           });
 }
Ejemplo n.º 5
0
  public void apply(Project project) {
    project.getPlugins().apply(BasePlugin.class);
    project.getPlugins().apply(ReportingBasePlugin.class);

    JavaPluginConvention javaConvention =
        new JavaPluginConvention((ProjectInternal) project, instantiator);
    project.getConvention().getPlugins().put("java", javaConvention);

    configureCompileDefaults(project, javaConvention);
    configureSourceSetDefaults(javaConvention);

    configureJavaDoc(project, javaConvention);
    configureTest(project, javaConvention);
    configureCheck(project);
    configureBuild(project);
    configureBuildNeeded(project);
    configureBuildDependents(project);
  }
 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());
 }
Ejemplo n.º 7
0
 private void addPluginConvention() {
   pluginConvention = new ApplicationPluginConvention(project);
   pluginConvention.setApplicationName(project.getName());
   project.getConvention().getPlugins().put("application", pluginConvention);
 }