private void _configureTaskTranspileJSForJavaPlugin(TranspileJSTask transpileJSTask) { transpileJSTask.mustRunAfter(JavaPlugin.PROCESS_RESOURCES_TASK_NAME); Project project = transpileJSTask.getProject(); final SourceSet sourceSet = GradleUtil.getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME); transpileJSTask.setSourceDir( new Callable<File>() { @Override public File call() throws Exception { File resourcesDir = _getSrcDir(sourceSet.getResources()); return new File(resourcesDir, "META-INF/resources"); } }); transpileJSTask.setWorkingDir( new Callable<File>() { @Override public File call() throws Exception { SourceSetOutput sourceSetOutput = sourceSet.getOutput(); return new File(sourceSetOutput.getResourcesDir(), "META-INF/resources"); } }); Task classesTask = GradleUtil.getTask(project, JavaPlugin.CLASSES_TASK_NAME); classesTask.dependsOn(transpileJSTask); }
@Override public void apply(Project project) { GradleUtil.applyPlugin(project, NodePlugin.class); final NpmInstallTask npmInstallTask = (NpmInstallTask) GradleUtil.getTask(project, NodePlugin.NPM_INSTALL_TASK_NAME); final DownloadNodeModuleTask downloadMetalCliTask = _addTaskDownloadMetalCli(project); final Configuration jsCompileConfiguration = _addConfigurationJSCompile(project); final Configuration soyCompileConfiguration = _addConfigurationSoyCompile(project); final TranspileJSTask transpileJSTask = _addTaskTranspileJS(project); project.afterEvaluate( new Action<Project>() { @Override public void execute(Project project) { _addTasksExpandJSCompileDependencies( transpileJSTask, npmInstallTask, jsCompileConfiguration); _addTasksExpandSoyCompileDependencies(transpileJSTask, soyCompileConfiguration); _configureTasksTranspileJS(project, downloadMetalCliTask, npmInstallTask); } }); }
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); } }); } }
private void _configureTaskReplaceSoyTranslationForJavaPlugin( final ReplaceSoyTranslationTask replaceSoyTranslationTask) { replaceSoyTranslationTask.dependsOn(JavaPlugin.PROCESS_RESOURCES_TASK_NAME); replaceSoyTranslationTask.setSource( new Callable<File>() { @Override public File call() throws Exception { SourceSet sourceSet = GradleUtil.getSourceSet( replaceSoyTranslationTask.getProject(), SourceSet.MAIN_SOURCE_SET_NAME); SourceSetOutput sourceSetOutput = sourceSet.getOutput(); return sourceSetOutput.getResourcesDir(); } }); Task classesTask = GradleUtil.getTask(replaceSoyTranslationTask.getProject(), JavaPlugin.CLASSES_TASK_NAME); classesTask.dependsOn(replaceSoyTranslationTask); }
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 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; }
@Override public void apply(Project project) { WorkspaceExtension workspaceExtension = GradleUtil.addExtension(project, PLUGIN_NAME, WorkspaceExtension.class); Configuration bundleConfiguration = addConfigurationBundle(project, workspaceExtension); addRepositoryBundle(project, workspaceExtension); Tar distBundleTarTask = addTaskDistBundle( project, DIST_BUNDLE_TAR_TASK_NAME, Tar.class, bundleConfiguration, workspaceExtension); distBundleTarTask.setCompression(Compression.GZIP); distBundleTarTask.setExtension("tar.gz"); Zip distBundleZipTask = addTaskDistBundle( project, DIST_BUNDLE_ZIP_TASK_NAME, Zip.class, bundleConfiguration, workspaceExtension); AbstractArchiveTask[] distBundleTasks = {distBundleTarTask, distBundleZipTask}; Copy initBundleTask = addTaskInitBundle(project, workspaceExtension, bundleConfiguration); configureModules(project, workspaceExtension, distBundleTasks); configurePluginsSDK(project, workspaceExtension, initBundleTask, distBundleTasks); configureThemes(project, workspaceExtension, distBundleTasks); }
public Map<String, String> getBundleDefaultInstructions() { Map<String, String> map = new HashMap<>(); map.put(Constants.BUNDLE_SYMBOLICNAME, project.getName()); map.put(Constants.BUNDLE_VENDOR, "Liferay, Inc."); map.put(Constants.DONOTCOPY, "(.touch)"); map.put(Constants.DSANNOTATIONS, "*"); map.put(Constants.METATYPE, "*"); map.put(Constants.PLUGIN, StringUtil.merge(_BND_PLUGIN_CLASS_NAMES, ",")); map.put(Constants.SOURCES, "false"); map.put("Git-Descriptor", "${system-allow-fail;git describe --dirty --always}"); map.put("Git-SHA", "${system-allow-fail;git rev-list -1 HEAD}"); JavaCompile javaCompile = (JavaCompile) GradleUtil.getTask(project, JavaPlugin.COMPILE_JAVA_TASK_NAME); CompileOptions compileOptions = javaCompile.getOptions(); map.put("Javac-Debug", _getOnOffValue(compileOptions.isDebug())); map.put("Javac-Deprecation", _getOnOffValue(compileOptions.isDeprecation())); String encoding = compileOptions.getEncoding(); if (Validator.isNull(encoding)) { encoding = System.getProperty("file.encoding"); } map.put("Javac-Encoding", encoding); map.put("-jsp", "*.jsp,*.jspf"); map.put("-sass", "*"); return map; }
private DownloadNodeModuleTask _addTaskDownloadMetalCli(Project project) { DownloadNodeModuleTask downloadNodeModuleTask = GradleUtil.addTask(project, DOWNLOAD_METAL_CLI_TASK_NAME, DownloadNodeModuleTask.class); downloadNodeModuleTask.setModuleName("metal-cli"); downloadNodeModuleTask.setModuleVersion(_METAL_CLI_VERSION); return downloadNodeModuleTask; }
private Configuration _addConfigurationSoyCompile(Project project) { Configuration configuration = GradleUtil.addConfiguration(project, SOY_COMPILE_CONFIGURATION_NAME); configuration.setDescription("Configures additional Soy dependencies."); configuration.setVisible(false); return configuration; }
private Copy _addTaskExpandCompileDependency( Project project, File file, File destinationDir, String taskNamePrefix, RenameDependencyClosure renameDependencyClosure) { String taskName = GradleUtil.getTaskName(taskNamePrefix, file); Copy copy = GradleUtil.addTask(project, taskName, Copy.class); copy.doFirst( new Action<Task>() { @Override public void execute(Task task) { Copy copy = (Copy) task; Project project = copy.getProject(); project.delete(copy.getDestinationDir()); } }); copy.from(project.zipTree(file)); String name = renameDependencyClosure.call(file.getName()); name = name.substring(0, name.length() - 4); destinationDir = new File(destinationDir, name); copy.setDescription( "Expands " + file.getName() + " into " + project.relativePath(destinationDir) + "."); copy.setDestinationDir(destinationDir); return copy; }
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); }
private Configuration _addConfigurationSoy(final Project project) { Configuration configuration = GradleUtil.addConfiguration(project, CONFIGURATION_NAME); configuration.defaultDependencies( new Action<DependencySet>() { @Override public void execute(DependencySet dependencySet) { _addDependenciesSoy(project); } }); configuration.setDescription("Configures Closure Templates for this project."); configuration.setVisible(false); return configuration; }
@SuppressWarnings("rawtypes") private ReplaceSoyTranslationTask _addTaskReplaceSoyTranslation(Project project) { final ReplaceSoyTranslationTask replaceSoyTranslationTask = GradleUtil.addTask( project, REPLACE_SOY_TRANSLATION_TASK_NAME, ReplaceSoyTranslationTask.class); replaceSoyTranslationTask.setDescription("Replaces 'goog.getMsg' definitions."); replaceSoyTranslationTask.setGroup(BasePlugin.BUILD_GROUP); replaceSoyTranslationTask.setIncludes(Collections.singleton("**/*.soy.js")); PluginContainer pluginContainer = project.getPlugins(); pluginContainer.withId( _JS_MODULE_CONFIG_GENERATOR_PLUGIN_ID, new Action<Plugin>() { @Override public void execute(Plugin plugin) { replaceSoyTranslationTask.dependsOn(_CONFIG_JS_MODULES_TASK_NAME); } }); pluginContainer.withId( _JS_TRANSPILER_PLUGIN_ID, new Action<Plugin>() { @Override public void execute(Plugin plugin) { replaceSoyTranslationTask.dependsOn(_TRANSPILE_JS_TASK_NAME); } }); pluginContainer.withType( JavaPlugin.class, new Action<JavaPlugin>() { @Override public void execute(JavaPlugin javaPlugin) { _configureTaskReplaceSoyTranslationForJavaPlugin(replaceSoyTranslationTask); } }); return replaceSoyTranslationTask; }
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; }
private TranspileJSTask _addTaskTranspileJS(Project project) { final TranspileJSTask transpileJSTask = GradleUtil.addTask(project, TRANSPILE_JS_TASK_NAME, TranspileJSTask.class); transpileJSTask.setDescription("Transpiles JS files."); transpileJSTask.setGroup(BasePlugin.BUILD_GROUP); PluginContainer pluginContainer = project.getPlugins(); pluginContainer.withType( JavaPlugin.class, new Action<JavaPlugin>() { @Override public void execute(JavaPlugin javaPlugin) { _configureTaskTranspileJSForJavaPlugin(transpileJSTask); } }); return transpileJSTask; }
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; }
private BuildSoyTask _addTaskBuildSoy(Project project) { final BuildSoyTask buildSoyTask = GradleUtil.addTask(project, BUILD_SOY_TASK_NAME, BuildSoyTask.class); buildSoyTask.setDescription("Compiles Closure Templates into JavaScript functions."); buildSoyTask.setGroup(BasePlugin.BUILD_GROUP); buildSoyTask.setIncludes(Collections.singleton("**/*.soy")); PluginContainer pluginContainer = project.getPlugins(); pluginContainer.withType( JavaPlugin.class, new Action<JavaPlugin>() { @Override public void execute(JavaPlugin javaPlugin) { _configureTaskBuildSoyForJavaPlugin(buildSoyTask); } }); return buildSoyTask; }
@Input public String getBundleFileName() { return GradleUtil.toString(_bundleFileName); }
public List<String> getSrcIncludes() { return GradleUtil.toStringList(_srcIncludes); }
public File getSourceDir() { return GradleUtil.toFile(getProject(), _sourceDir); }
@Input public String getOutputDirName() { return GradleUtil.toString(_outputDirName); }
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); }
@InputDirectory @Optional public File getPortalCommonDir() { return GradleUtil.toFile(getProject(), _portalCommonDir); }
@Input public int getPrecision() { return GradleUtil.toInteger(_precision); }
@Input public List<String> getRtlExcludedPathRegexps() { return GradleUtil.toStringList(_rtlExcludedPathRegexps); }
@Input @Optional public String getSassCompilerClassName() { return GradleUtil.toString(_sassCompilerClassName); }
@Input public String getGlobalName() { return GradleUtil.toString(_globalName); }
@Input public String getModules() { return GradleUtil.toString(_modules); }
@InputFile @Optional public File getPortalCommonFile() { return GradleUtil.toFile(getProject(), _portalCommonFile); }