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; }
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); } }); } }
protected Configuration addConfigurationBundle( Project project, WorkspaceExtension workspaceExtension) { Configuration configuration = GradleUtil.addConfiguration(project, BUNDLE_CONFIGURATION_NAME); configuration.setDescription("Configures the Liferay bundle to use for your project."); GradleUtil.addDependency( project, BUNDLE_CONFIGURATION_NAME, workspaceExtension.getBundleArtifactGroup(), workspaceExtension.getBundleArtifactName(), workspaceExtension.getBundleArtifactVersion()); return configuration; }
protected UpdatePropertiesTask addTaskUpdateSDKProperties( Project project, WorkspaceExtension workspaceExtension) { UpdatePropertiesTask updatePropertiesTask = GradleUtil.addTask(project, UPDATE_SDK_PROPERTIES_TASK_NAME, UpdatePropertiesTask.class); updatePropertiesTask.property( "app.server.parent.dir", FileUtil.getAbsolutePath(workspaceExtension.getHomeDir())); String userName = System.getProperty("user.name"); File sdkPropertiesFile = new File(workspaceExtension.getPluginsSDKDir(), "build." + userName + ".properties"); updatePropertiesTask.setPropertiesFile(sdkPropertiesFile); return updatePropertiesTask; }
@Override public void apply(Settings settings) { Gradle gradle = settings.getGradle(); final WorkspaceExtension workspaceExtension = addWorkspaceExtension(settings); for (ProjectConfigurator projectConfigurator : workspaceExtension.getProjectConfigurators()) { for (File rootDir : projectConfigurator.getDefaultRootDirs()) { for (File projectDir : projectConfigurator.getProjectDirs(rootDir)) { String projectPath = GradleUtil.getProjectPath(projectDir, settings.getRootDir()); settings.include(new String[] {projectPath}); _projectConfiguratorsMap.put(projectPath, projectConfigurator); } } } gradle.beforeProject( new Closure<Void>(null) { @SuppressWarnings("unused") public void doCall(Project project) { Plugin<Project> plugin = null; if (project.getParent() == null) { plugin = workspaceExtension.getRootProjectConfigurator(); } else { plugin = _projectConfiguratorsMap.get(project.getPath()); } if (plugin != null) { plugin.apply(project); } } }); }
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); }
protected <T extends AbstractArchiveTask> T addTaskDistBundle( final Project project, String taskName, Class<T> clazz, final Configuration bundleConfiguration, WorkspaceExtension workspaceExtension) { T task = GradleUtil.addTask(project, taskName, clazz); configureTaskCopyBundle(task, bundleConfiguration); task.from( project.file("configs/common"), project.file("configs/" + workspaceExtension.getEnvironment())); task.setBaseName(project.getName()); task.setDescription("Assembles the bundle and zips it up."); task.setDestinationDir(project.getBuildDir()); task.setIncludeEmptyDirs(false); return task; }
protected void configureThemes( Project project, final WorkspaceExtension workspaceExtension, final AbstractArchiveTask[] distBundleTasks) { Project themesProject = GradleUtil.getProject(project, workspaceExtension.getThemesDir()); if (themesProject == null) { return; } Action<Project> action = new Action<Project>() { @Override public void execute(final Project project) { Set<Project> subproject = project.getSubprojects(); if (!subproject.isEmpty()) { return; } project.setBuildDir("build_gradle"); GradleUtil.applyPlugin(project, BasePlugin.class); GradleUtil.applyPlugin(project, GulpPlugin.class); Task assembleTask = GradleUtil.getTask(project, BasePlugin.ASSEMBLE_TASK_NAME); assembleTask.dependsOn(_GULP_BUILD_TASK_NAME); final Task createLiferayThemeJsonTask = addTaskCreateLiferayThemeJson(project, workspaceExtension); Delete cleanTask = (Delete) GradleUtil.getTask(project, BasePlugin.CLEAN_TASK_NAME); cleanTask.delete("build", "dist"); cleanTask.dependsOn( BasePlugin.CLEAN_TASK_NAME + StringUtil.capitalize(NodePlugin.NPM_INSTALL_TASK_NAME)); Task deployTask = project.task(LiferayJavaPlugin.DEPLOY_TASK_NAME); deployTask.dependsOn(_GULP_DEPLOY_TASK_NAME); for (AbstractArchiveTask abstractArchiveTask : distBundleTasks) { abstractArchiveTask.into( "deploy", new Closure<Void>(null) { @SuppressWarnings("unused") public void doCall(CopySpec copySpec) { ConfigurableFileTree fileTree = project.fileTree("dist"); fileTree.builtBy(_GULP_DEPLOY_TASK_NAME); fileTree.include("*.war"); copySpec.from(fileTree); } }); } TaskContainer taskContainer = project.getTasks(); taskContainer.withType( ExecuteGulpTask.class, new Action<ExecuteGulpTask>() { @Override public void execute(ExecuteGulpTask executeGulpTask) { executeGulpTask.dependsOn( createLiferayThemeJsonTask, NodePlugin.NPM_INSTALL_TASK_NAME); } }); } }; themesProject.subprojects(action); }
protected MavenArtifactRepository addRepositoryBundle( Project project, WorkspaceExtension workspaceExtension) { return addRepository(project, workspaceExtension.getBundleMavenUrl()); }