private void _configureRootTaskDistBundle(final Task warTask) {
    Project project = warTask.getProject();

    Copy copy =
        (Copy)
            GradleUtil.getTask(
                project.getRootProject(), RootProjectConfigurator.DIST_BUNDLE_TASK_NAME);

    copy.dependsOn(warTask);

    copy.into(
        "osgi/modules",
        new Closure<Void>(project) {

          @SuppressWarnings("unused")
          public void doCall(CopySpec copySpec) {
            Project project = warTask.getProject();

            ConfigurableFileTree configurableFileTree = project.fileTree("dist");

            configurableFileTree.builtBy(warTask);
            configurableFileTree.include("*.war");

            copySpec.from(configurableFileTree);
          }
        });
  }
  private ModuleDescriptor findProject(DependencyDescriptor descriptor) {
    String projectPathValue = descriptor.getAttribute(DependencyDescriptorFactory.PROJECT_PATH_KEY);
    if (projectPathValue == null) {
      return null;
    }
    Project project = gradle.getRootProject().project(projectPathValue);
    Module projectModule = ((ProjectInternal) project).getModule();
    ModuleDescriptor projectDescriptor =
        moduleDescriptorConverter.convert(
            project.getConfigurations().getAll(),
            projectModule,
            IvyContext.getContext().getIvy().getSettings());

    for (DependencyArtifactDescriptor artifactDescriptor : descriptor.getAllDependencyArtifacts()) {
      for (Artifact artifact : projectDescriptor.getAllArtifacts()) {
        if (artifact.getName().equals(artifactDescriptor.getName())
            && artifact.getExt().equals(artifactDescriptor.getExt())) {
          String path =
              artifact.getExtraAttribute(DefaultIvyDependencyPublisher.FILE_PATH_EXTRA_ATTRIBUTE);
          ReflectionUtil.invoke(
              artifactDescriptor,
              "setExtraAttribute",
              new Object[] {DefaultIvyDependencyPublisher.FILE_PATH_EXTRA_ATTRIBUTE, path});
        }
      }
    }

    return projectDescriptor;
  }
Exemple #3
0
  @Override
  public void apply(final Project project) {
    this.project = project;
    project.getPluginManager().apply(JavaPlugin.class);
    project.getPluginManager().apply(DistributionPlugin.class);

    addPluginConvention();
    addRunTask();
    addCreateScriptsTask();

    Distribution distribution =
        ((DistributionContainer) project.getExtensions().getByName("distributions"))
            .getByName(DistributionPlugin.MAIN_DISTRIBUTION_NAME);

    ((IConventionAware) distribution)
        .getConventionMapping()
        .map(
            "baseName",
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                return pluginConvention.getApplicationName();
              }
            });
    configureDistSpec(distribution.getContents());
    configureInstallTask(project.getTasks().getAt(TASK_INSTALL_NAME));
  }
 @Override
 public void apply(Project project) {
   project.getPluginManager().apply(TestingModelBasePlugin.class);
   project.getPluginManager().apply(JvmComponentPlugin.class);
   project.getPluginManager().apply(JUnitTestSuitePlugin.class);
   project.getPluginManager().apply(ClojureTestSuiteRules.class);
 }
  private void _addTasksExpandSoyCompileDependencies(
      TranspileJSTask transpileJSTask, Configuration configuration) {

    Project project = transpileJSTask.getProject();

    RenameDependencyClosure renameDependencyClosure =
        new RenameDependencyClosure(project, configuration.getName());

    for (File file : configuration) {
      Copy copy =
          _addTaskExpandCompileDependency(
              project,
              file,
              project.getBuildDir(),
              "expandSoyCompileDependency",
              renameDependencyClosure);

      transpileJSTask.dependsOn(copy);

      String path = FileUtil.getAbsolutePath(copy.getDestinationDir());

      path += "/META-INF/resources/**/*.soy";

      transpileJSTask.soyDependency(path);
    }
  }
  private void addPropertiesToProject(Project project) {
    Properties projectProperties = new Properties();
    File projectPropertiesFile = new File(project.getProjectDir(), Project.GRADLE_PROPERTIES);
    LOGGER.debug("Looking for project properties from: {}", projectPropertiesFile);
    if (projectPropertiesFile.isFile()) {
      projectProperties = GUtil.loadProperties(projectPropertiesFile);
      LOGGER.debug(
          "Adding project properties (if not overwritten by user properties): {}",
          projectProperties.keySet());
    } else {
      LOGGER.debug("project property file does not exists. We continue!");
    }

    Map<String, String> mergedProperties =
        propertiesLoader.mergeProperties(new HashMap(projectProperties));
    ExtraPropertiesExtension extraProperties =
        new DslObject(project).getExtensions().getExtraProperties();
    for (Map.Entry<String, String> entry : mergedProperties.entrySet()) {
      if (project.hasProperty(entry.getKey())) {
        project.setProperty(entry.getKey(), entry.getValue());
      } else {
        extraProperties.set(entry.getKey(), entry.getValue());
      }
    }
  }
  protected Copy addTaskInitBundle(
      final Project project,
      final WorkspaceExtension workspaceExtension,
      final Configuration bundleConfiguration) {

    Copy copy = GradleUtil.addTask(project, INIT_BUNDLE_TASK_NAME, Copy.class);

    copy.doFirst(
        new Action<Task>() {

          @Override
          public void execute(Task task) {
            Copy copy = (Copy) task;

            project.delete(copy.getDestinationDir());
          }
        });

    configureTaskCopyBundle(copy, bundleConfiguration);

    Project rootProject = project.getRootProject();

    copy.from(
        rootProject.file("configs/common"),
        rootProject.file("configs/" + workspaceExtension.getEnvironment()));

    copy.into(workspaceExtension.getHomeDir());

    copy.setDescription(
        "Downloads and unzips the bundle into " + workspaceExtension.getHomeDir() + ".");
    copy.setIncludeEmptyDirs(false);

    return copy;
  }
Exemple #8
0
 private void configureTest(final Project project, final JavaPluginConvention convention) {
   project
       .getTasks()
       .withType(
           Test.class,
           new Action<Test>() {
             public void execute(Test test) {
               configureTestDefaults(test, project, convention);
             }
           });
   project.afterEvaluate(
       new Action<Project>() {
         public void execute(Project project) {
           project
               .getTasks()
               .withType(
                   Test.class,
                   new Action<Test>() {
                     public void execute(Test test) {
                       overwriteIncludesIfSinglePropertyIsSet(test);
                       overwriteDebugIfDebugPropertyIsSet(test);
                     }
                   });
         }
       });
 }
Exemple #9
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();
              }
            });
  }
  @Override
  public void executeNode() {
    final File sourceDir = getSourceDir();
    final File workingDir = getWorkingDir();

    if (!sourceDir.equals(workingDir)) {
      Project project = getProject();

      project.copy(
          new Action<CopySpec>() {

            @Override
            public void execute(CopySpec copySpec) {
              copySpec.from(sourceDir);

              copySpec.include(getSoySrcIncludes());
              copySpec.include(getSrcIncludes());

              copySpec.into(workingDir);
            }
          });
    }

    super.executeNode();
  }
  @Override
  public void apply(final Project project) {
    DefaultTask javaTask = project.getTasks().create("javaTask", MyJavaTask.class);
    javaTask.setDescription("javaTask Demo");

    DefaultTask javaXTask = project.getTasks().create("javaXTask", MyOtherJavaTask.class);
    javaXTask.setDescription("javaXTask Demo");
  }
 public void apply(Project project) {
   project.getExtensions().create("flyway", FlywayExtension.class);
   project.getTasks().create("flywayClean", FlywayCleanTask.class);
   project.getTasks().create("flywayInit", FlywayInitTask.class);
   project.getTasks().create("flywayMigrate", FlywayMigrateTask.class);
   project.getTasks().create("flywayValidate", FlywayValidateTask.class);
   project.getTasks().create("flywayInfo", FlywayInfoTask.class);
   project.getTasks().create("flywayRepair", FlywayRepairTask.class);
 }
Exemple #13
0
  // @Todo: refactor this task configuration to extend a copy task and use replace tokens
  private void addCreateScriptsTask() {
    CreateStartScripts startScripts =
        project.getTasks().create(TASK_START_SCRIPTS_NAME, CreateStartScripts.class);
    startScripts.setDescription(
        "Creates OS specific scripts to run the project as a JVM application.");
    startScripts.setClasspath(
        project
            .getTasks()
            .getAt(JavaPlugin.JAR_TASK_NAME)
            .getOutputs()
            .getFiles()
            .plus(project.getConfigurations().getByName("runtime")));

    startScripts
        .getConventionMapping()
        .map(
            "mainClassName",
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                return pluginConvention.getMainClassName();
              }
            });

    startScripts
        .getConventionMapping()
        .map(
            "applicationName",
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                return pluginConvention.getApplicationName();
              }
            });

    startScripts
        .getConventionMapping()
        .map(
            "outputDir",
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                return new File(project.getBuildDir(), "scripts");
              }
            });

    startScripts
        .getConventionMapping()
        .map(
            "defaultJvmOpts",
            new Callable<Object>() {
              @Override
              public Object call() throws Exception {
                return pluginConvention.getApplicationDefaultJvmArgs();
              }
            });
  }
  @Override
  public void apply(Project project) {
    String appDescription = null;
    String appTitle = null;
    String appVersion = null;

    File appBndFile = project.file("app.bnd");

    if (appBndFile.exists()) {
      Properties properties = GUtil.loadProperties(appBndFile);

      appDescription = properties.getProperty("Liferay-Releng-App-Description");
    }

    Properties appProperties = null;

    Project privateProject = project.findProject(":private" + project.getPath());

    if (privateProject != null) {
      appProperties = _getAppProperties(privateProject);
    }

    if (appProperties == null) {
      appProperties = _getAppProperties(project);
    }

    if (appProperties != null) {
      appTitle = appProperties.getProperty("app.marketplace.title");
      appVersion = appProperties.getProperty("app.marketplace.version");
    }

    _applyPlugins(project);

    LiferayOSGiDefaultsPlugin.configureRepositories(project);

    _configureAppJavadocBuilder(project, privateProject);
    _configureAppTLDDocBuilder(project, privateProject);
    _configureProject(project, appDescription, appVersion);
    _configureTaskAppJavadoc(project, appTitle, appVersion);

    if (privateProject != null) {
      Gradle gradle = project.getGradle();

      StartParameter startParameter = gradle.getStartParameter();

      List<String> taskNames = startParameter.getTaskNames();

      if (taskNames.contains(AppJavadocBuilderPlugin.APP_JAVADOC_TASK_NAME)
          || taskNames.contains(AppJavadocBuilderPlugin.JAR_APP_JAVADOC_TASK_NAME)
          || taskNames.contains(AppTLDDocBuilderPlugin.APP_TLDDOC_TASK_NAME)
          || taskNames.contains(AppTLDDocBuilderPlugin.JAR_APP_TLDDOC_TASK_NAME)) {

        _forceProjectHierarchyEvaluation(privateProject);
      }
    }
  }
  protected Task addTaskCreateLiferayThemeJson(
      Project project, final WorkspaceExtension workspaceExtension) {

    Task task = project.task(CREATE_LIFERAY_THEME_JSON_TASK_NAME);

    final File liferayThemeJsonFile = project.file("liferay-theme.json");

    task.doLast(
        new Action<Task>() {

          @Override
          public void execute(Task task) {
            Project project = task.getProject();

            Map<String, Object> map = new HashMap<>();

            File appServerDir = new File(workspaceExtension.getHomeDir(), "tomcat-7.0.62");

            map.put("appServerPath", appServerDir.getAbsolutePath());

            File appServerThemeDir = new File(appServerDir, "webapps/" + project.getName());

            map.put("appServerPathTheme", appServerThemeDir.getAbsolutePath());

            map.put("deployed", false);

            File deployDir = new File(workspaceExtension.getHomeDir(), "deploy");

            map.put("deployPath", deployDir.getAbsolutePath());
            map.put("themeName", project.getName());

            String json = JsonOutput.toJson(Collections.singletonMap("LiferayTheme", map));

            try {
              Files.write(liferayThemeJsonFile.toPath(), json.getBytes(StandardCharsets.UTF_8));
            } catch (IOException ioe) {
              throw new GradleException(ioe.getMessage(), ioe);
            }
          }
        });

    task.onlyIf(
        new Spec<Task>() {

          @Override
          public boolean isSatisfiedBy(Task task) {
            if (liferayThemeJsonFile.exists()) {
              return true;
            }

            return false;
          }
        });

    return task;
  }
Exemple #16
0
  @Test
  public void addsAnOsgiManifestToEachJar() {
    osgiPlugin.apply(project, new PluginRegistry(), null);

    Task task = project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME);
    assertThat(task.property("osgi"), is(OsgiManifest.class));

    task = project.getTasks().add("otherJar", Jar.class);
    assertThat(task.property("osgi"), is(OsgiManifest.class));
  }
Exemple #17
0
 /** Creates the configurations used by plugin. */
 private void addJacocoConfigurations() {
   Configuration agentConf = project.getConfigurations().create(AGENT_CONFIGURATION_NAME);
   agentConf.setVisible(false);
   agentConf.setTransitive(true);
   agentConf.setDescription("The Jacoco agent to use to get coverage data.");
   Configuration antConf = project.getConfigurations().create(ANT_CONFIGURATION_NAME);
   antConf.setVisible(false);
   antConf.setTransitive(true);
   antConf.setDescription("The Jacoco ant tasks to use to get execute Gradle tasks.");
 }
 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);
 }
  private void _configureProject(Project project, String description, String version) {

    if (Validator.isNotNull(description)) {
      project.setDescription(description);
    }

    if (Validator.isNotNull(version)) {
      project.setVersion(version);
    }
  }
 public DomainObjectSet<NativeBinary> getBinaries(NativeLibraryRequirement requirement) {
   Project project = findProject(requirement);
   LibraryContainer libraryContainer =
       (LibraryContainer) project.getExtensions().findByName("libraries");
   if (libraryContainer == null) {
     throw new LibraryResolveException(
         String.format("Project does not have a libraries container: '%s'", project.getPath()));
   }
   return libraryContainer.getByName(requirement.getLibraryName()).getBinaries();
 }
  @Override
  public void executeNode() throws Exception {
    Project project = getProject();

    if (FileUtil.isChild(getCacheDir(), project.getProjectDir())) {
      super.executeNode();
    } else {
      synchronized (ExecuteNpmTask.class) {
        super.executeNode();
      }
    }
  }
  protected void configureModules(
      Project project,
      final WorkspaceExtension workspaceExtension,
      final AbstractArchiveTask[] distBundleTasks) {

    Project modulesProject = GradleUtil.getProject(project, workspaceExtension.getModulesDir());

    if (modulesProject == null) {
      return;
    }

    Action<Project> action =
        new Action<Project>() {

          @Override
          public void execute(Project project) {
            Set<Project> subprojects = project.getSubprojects();

            if (!subprojects.isEmpty()) {
              return;
            }

            GradleUtil.applyPlugin(project, LiferayPlugin.class);

            LiferayExtension liferayExtension =
                GradleUtil.getExtension(project, LiferayExtension.class);

            liferayExtension.setAppServerParentDir(workspaceExtension.getHomeDir());

            for (AbstractArchiveTask abstractArchiveTask : distBundleTasks) {

              abstractArchiveTask.into(
                  "deploy",
                  new Closure<Void>(null) {

                    @SuppressWarnings("unused")
                    public void doCall(CopySourceSpec copySourceSpec) {
                      copySourceSpec.from(JavaPlugin.JAR_TASK_NAME);
                    }
                  });
            }

            if (workspaceExtension.isModulesDefaultRepositoryEnabled()) {
              addRepositoryModules(project);
            }
          }
        };

    modulesProject.subprojects(action);
  }
  @Override
  public void apply(Project project) {
    project.getPlugins().apply(DependencyManagementPlugin.class);
    DependencyManagementExtension dependencyManagement =
        project.getExtensions().findByType(DependencyManagementExtension.class);
    dependencyManagement.imports(
        new Action<ImportsHandler>() {

          @Override
          public void execute(ImportsHandler importsHandler) {
            importsHandler.mavenBom(SPRING_BOOT_BOM);
          }
        });
  }
 private DefaultProjectOutcomes buildProjectOutput(Project project, ProjectOutcomes parent) {
   DefaultProjectOutcomes projectOutput =
       new DefaultProjectOutcomes(
           project.getName(),
           project.getPath(),
           project.getDescription(),
           project.getProjectDir(),
           getFileOutcomes(project),
           parent);
   for (Project child : project.getChildProjects().values()) {
     projectOutput.addChild(buildProjectOutput(child, projectOutput));
   }
   return projectOutput;
 }
  private DefaultGradleProject<LaunchableGradleTask> buildHierarchy(Project project) {
    List<DefaultGradleProject<LaunchableGradleTask>> children =
        new ArrayList<DefaultGradleProject<LaunchableGradleTask>>();
    for (Project child : project.getChildProjects().values()) {
      children.add(buildHierarchy(child));
    }

    DefaultGradleProject<LaunchableGradleTask> gradleProject =
        new DefaultGradleProject<LaunchableGradleTask>()
            .setPath(project.getPath())
            .setName(project.getName())
            .setDescription(project.getDescription())
            .setBuildDirectory(project.getBuildDir())
            .setProjectDirectory(project.getProjectDir())
            .setChildren(children);

    gradleProject.getBuildScript().setSourceFile(project.getBuildFile());
    gradleProject.setTasks(tasks(gradleProject, (TaskContainerInternal) project.getTasks()));

    for (DefaultGradleProject child : children) {
      child.setParent(gradleProject);
    }

    return gradleProject;
  }
  protected void configurePluginsSDK(
      Project project,
      final WorkspaceExtension workspaceExtension,
      Copy initBundleTask,
      AbstractArchiveTask[] distBundleTasks) {

    final Project pluginsSDKProject =
        GradleUtil.getProject(project, workspaceExtension.getPluginsSDKDir());

    if (pluginsSDKProject == null) {
      return;
    }

    AntBuilder antBuilder = pluginsSDKProject.getAnt();

    antBuilder.importBuild("build.xml");

    final Task warTask = GradleUtil.getTask(pluginsSDKProject, WarPlugin.WAR_TASK_NAME);

    File homeDir = workspaceExtension.getHomeDir();

    if (!homeDir.exists()) {
      warTask.dependsOn(initBundleTask);
    }

    Task updateSDKPropertiesTask =
        addTaskUpdateSDKProperties(pluginsSDKProject, workspaceExtension);

    Task buildTask = pluginsSDKProject.task(LifecycleBasePlugin.BUILD_TASK_NAME);

    buildTask.dependsOn(updateSDKPropertiesTask, warTask);

    for (AbstractArchiveTask abstractArchiveTask : distBundleTasks) {
      abstractArchiveTask.into(
          "deploy",
          new Closure<Void>(null) {

            @SuppressWarnings("unused")
            public void doCall(CopySpec copySpec) {
              ConfigurableFileTree configurableFileTree = pluginsSDKProject.fileTree("dist");

              configurableFileTree.builtBy(warTask);
              configurableFileTree.include("*.war");

              copySpec.from(configurableFileTree);
            }
          });
    }
  }
Exemple #27
0
  public void apply(Project project) {
    JavaBasePlugin javaBasePlugin = project.getPlugins().apply(JavaBasePlugin.class);

    project
        .getConfigurations()
        .add(GROOVY_CONFIGURATION_NAME)
        .setVisible(false)
        .setTransitive(false)
        .setDescription("The groovy libraries to be used for this Groovy project.");

    configureCompileDefaults(project);
    configureSourceSetDefaults(project, javaBasePlugin);

    configureGroovydoc(project);
  }
  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);
  }
Exemple #29
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());
                       }
                     });
               }
             }
           });
 }
  private String _getAppJavadocGroupName(Project project) {
    String groupName = project.getDescription();

    if (Validator.isNull(groupName)) {
      groupName = project.getName();
    }

    TaskContainer taskContainer = project.getTasks();

    WritePropertiesTask recordArtifactTask =
        (WritePropertiesTask)
            taskContainer.findByName(LiferayRelengPlugin.RECORD_ARTIFACT_TASK_NAME);

    if (recordArtifactTask != null) {
      String artifactURL = null;

      File artifactPropertiesFile = recordArtifactTask.getOutputFile();

      if (artifactPropertiesFile.exists()) {
        Properties properties = GUtil.loadProperties(artifactPropertiesFile);

        artifactURL = properties.getProperty("artifact.url");
      }

      if (Validator.isNotNull(artifactURL)) {
        int start = artifactURL.lastIndexOf('/') + 1;
        int end = artifactURL.lastIndexOf('.');

        int pos = artifactURL.indexOf('-', start);

        String moduleName = artifactURL.substring(start, pos);
        String moduleVersion = artifactURL.substring(pos + 1, end);

        StringBuilder sb = new StringBuilder();

        sb.append("Module ");
        sb.append(moduleName);
        sb.append(' ');
        sb.append(moduleVersion);
        sb.append(" - ");
        sb.append(groupName);

        groupName = sb.toString();
      }
    }

    return groupName;
  }