Skip to content

Commit

Permalink
BLADE-728 use latest project template and fix upgrade gradle 7 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjhy committed Aug 18, 2023
1 parent b0d08e8 commit 7f8a6a2
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Setup Java 11
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 11.0.19
distribution: 'zulu'
cache: gradle
- name: Cache
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
- name: Setup Java 11
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 11.0.19
distribution: 'zulu'
cache: gradle
- name: Cache
Expand Down
10 changes: 9 additions & 1 deletion cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ createWrapperZip {
dependencies {
api group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "5.3.0"
api group: "com.liferay", name: "com.liferay.gogo.shell.client", version: "1.0.0"
api group: "com.liferay", name: "com.liferay.project.templates", version: "latest.release"
api group: "com.liferay", name: "com.liferay.project.templates", version: "5.0.237"
api group: "commons-beanutils", name: "commons-beanutils", version: "1.9.4"
api group: "commons-io", name: "commons-io", version: "2.6"
api group: "commons-lang", name: "commons-lang", version: "2.6"
Expand Down Expand Up @@ -132,6 +132,10 @@ dependencies {
testImplementation project(":gradle-tooling")
}

compileTestJava{
dependsOn("unzipPortal")
}

downloadPortal {
src "https://releases-cdn.liferay.com/portal/7.4.3.4-ga4/liferay-ce-portal-tomcat-7.4.3.4-ga4-20211020095956970.tar.gz"
dest new File("${System.getProperty('user.home')}/.liferay/bundles", 'liferay-ce-portal-tomcat-7.4.3.4-ga4-20211020095956970.tar.gz')
Expand Down Expand Up @@ -315,6 +319,10 @@ unzipManifest {
finalizedBy("compileTestJava")
}

processZipsResources{
dependsOn("unzipPortal")
}

unzipPortal {
dependsOn downloadPortal
from tarTree(resources.gzip(downloadPortal.dest))
Expand Down
2 changes: 2 additions & 0 deletions cli/src/test/java/com/liferay/blade/cli/BladeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class BladeTest extends BladeCLI {

public static final String LIFERAY_VERSION_73101 = "7.3.10.u15";

public static final String LIFERAY_VERSION_PORTAL_7456 = "7.4.3.56";

public static final String PRODUCT_VERSION_COMMERCE_206 = "commerce-2.0.6";

public static final String PRODUCT_VERSION_COMMERCE_207 = "commerce-2.0.7-7.2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -499,7 +498,6 @@ public void testInitWithLiferayVersionUnset() throws Exception {
TestUtil.runBlade(_workspaceDir, _extensionsDir, args);
}

@Ignore
@Test
public void testInitWithNameWorkspaceDirectoryEmpty() throws Exception {
String[] args = {
Expand Down Expand Up @@ -681,7 +679,7 @@ private void _verifyGradleBuild() throws Exception {
GradleRunnerUtil.verifyBuildOutput(projectPath.toString(), "foo-1.0.0.jar");
}

private static final String _GRADLE_PLUGINS_WORKSPACE_VERSION = "8.0.0";
private static final String _GRADLE_PLUGINS_WORKSPACE_VERSION = "8.0.3";

private File _extensionsDir = null;
private File _workspaceDir = null;
Expand Down
2 changes: 1 addition & 1 deletion cli/test-resources/projects/testws1/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {

classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd", version: "5.3.0"
classpath group: "com.github.docker-java", name: "docker-java-transport", version: "3.2.8"
classpath(group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "7.0.2") {
classpath(group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "latest.release") {
exclude group: "biz.aQute.bnd", module: "biz.aQute.bnd"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public void testInstallJar() throws Exception {
File workspaceDir = temporaryFolder.newFolder();

String[] args = {
"--base", workspaceDir.getPath(), "init", "-P", "maven", "-v", BladeTest.LIFERAY_VERSION_72107
"--base", workspaceDir.getPath(), "init", "-P", "maven", "-v", BladeTest.LIFERAY_VERSION_PORTAL_7456
};

TestUtil.runBlade(workspaceDir, _extensionsDir, args);

XMLTestUtil.updateWorkspaceBundleUrl(workspaceDir, BladeTest.LIFERAY_VERSION_PORTAL_7456);

args = new String[] {"--base", workspaceDir.getPath(), "server", "init"};

String workspacePath = workspaceDir.getAbsolutePath();
Expand Down Expand Up @@ -79,7 +81,7 @@ public void testInstallJar() throws Exception {

args = new String[] {
"--base", modulesDirectory.getAbsolutePath(), "create", "-t", "mvc-portlet", "foo", "-v",
BladeTest.LIFERAY_VERSION_72107
BladeTest.LIFERAY_VERSION_PORTAL_7456
};

TestUtil.runBlade(workspaceDir, _extensionsDir, args);
Expand All @@ -104,11 +106,13 @@ public void testInstallWar() throws Exception {
File workspaceDir = temporaryFolder.newFolder();

String[] args = {
"--base", workspaceDir.getPath(), "init", "-P", "maven", "-v", BladeTest.LIFERAY_VERSION_72107
"--base", workspaceDir.getPath(), "init", "-P", "maven", "-v", BladeTest.LIFERAY_VERSION_PORTAL_7456
};

TestUtil.runBlade(workspaceDir, _extensionsDir, args);

XMLTestUtil.updateWorkspaceBundleUrl(workspaceDir, BladeTest.LIFERAY_VERSION_PORTAL_7456);

args = new String[] {"--base", workspaceDir.getPath(), "server", "init"};

String workspacePath = workspaceDir.getAbsolutePath();
Expand Down Expand Up @@ -137,7 +141,7 @@ public void testInstallWar() throws Exception {

args = new String[] {
"--base", modulesDirectory.getAbsolutePath(), "create", "-t", "war-mvc-portlet", "foo", "-v",
BladeTest.LIFERAY_VERSION_72107
BladeTest.LIFERAY_VERSION_PORTAL_7456
};

TestUtil.runBlade(workspaceDir, _extensionsDir, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testServerInit() throws Exception {
File workspaceDir = temporaryFolder.newFolder("build", "test", "workspace");

String[] args = {
"--base", workspaceDir.getPath(), "init", "-f", "-P", "maven", "-v", BladeTest.LIFERAY_VERSION_741
"--base", workspaceDir.getPath(), "init", "-f", "-P", "maven", "-v", BladeTest.LIFERAY_VERSION_PORTAL_7456
};

TestUtil.runBlade(workspaceDir, extensionsDir, args);
Expand All @@ -58,6 +58,8 @@ public void testServerInit() throws Exception {
_addNexusRepositoriesElement(document, "pluginRepositories", "pluginRepository");
});

XMLTestUtil.updateWorkspaceBundleUrl(workspaceDir, BladeTest.LIFERAY_VERSION_PORTAL_7456);

args = new String[] {"--base", workspaceDir.getPath(), "server", "init"};

File bundlesDir = new File(workspaceDir.getPath(), "bundles");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
package com.liferay.blade.extensions.maven.profile;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;

import java.nio.file.Path;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.function.Consumer;

import javax.xml.parsers.DocumentBuilder;
Expand All @@ -35,6 +41,12 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;

import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import org.junit.Assert;

import org.w3c.dom.Document;
Expand All @@ -48,6 +60,22 @@
*/
public class XMLTestUtil {

public static final String BUNDLE_URL_PROPERTY = "liferay.workspace.bundle.url";

public static final String LIFERAY_PORTAL_URL = "https://releases-cdn.liferay.com/portal/";

public static final Map<String, String> liferayBundleUrlVersions = new HashMap<String, String>() {
{
put("7.0.6-2", LIFERAY_PORTAL_URL + "7.0.6-ga7/liferay-ce-portal-tomcat-7.0-ga7-20180507111753223.zip");
put("7.1.2", LIFERAY_PORTAL_URL + "7.1.2-ga3/liferay-ce-portal-tomcat-7.1.2-ga3-20190107144105508.tar.gz");
put("7.2.0", LIFERAY_PORTAL_URL + "7.2.0-ga1/liferay-ce-portal-tomcat-7.2.0-ga1-20190531153709761.tar.gz");
put("7.3.7", LIFERAY_PORTAL_URL + "7.3.7-ga8/liferay-ce-portal-tomcat-7.3.7-ga8-20210610183559721.tar.gz");
put(
"7.4.3.56",
LIFERAY_PORTAL_URL + "7.4.3.56-ga56/liferay-ce-portal-tomcat-7.4.3.56-ga56-20221222175515613.tar.gz");
}
};

public static void editXml(File xmlFile, Consumer<Document> consumer) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();

Expand Down Expand Up @@ -123,6 +151,14 @@ public static List<Element> getChildElements(Element element) {
return elements;
}

public static Model getMavenModel(File pomFile) throws IOException, XmlPullParserException {
MavenXpp3Reader mavenReader = new MavenXpp3Reader();

mavenReader.setAddDefaultEntities(true);

return mavenReader.read(new FileReader(pomFile));
}

public static void testXmlElement(
Path path, String parentElementString, List<Element> elements, int index, String expectedTagName,
String expectedTextContent)
Expand Down Expand Up @@ -164,6 +200,35 @@ public static String toString(Element element) throws TransformerException {
return stringWriter.toString();
}

public static void updateMavenPom(Model model, File file) throws IOException {
MavenXpp3Writer mavenWriter = new MavenXpp3Writer();

FileWriter fileWriter = new FileWriter(file);

mavenWriter.write(fileWriter, model);
}

public static void updateWorkspaceBundleUrl(File workspaceDir, String liferayVersion) throws Exception {
try {
File workspacePomFile = new File(workspaceDir, "pom.xml");

if (!workspacePomFile.exists()) {
throw new Exception("Can not find workspace pom.xml file");
}

Model pomModel = getMavenModel(workspacePomFile);

Properties properties = pomModel.getProperties();

properties.setProperty(BUNDLE_URL_PROPERTY, liferayBundleUrlVersions.get(liferayVersion));

updateMavenPom(pomModel, workspacePomFile);
}
catch (Exception exception) {
throw new Exception(exception);
}
}

private static final Transformer _transformer;

static {
Expand Down
7 changes: 7 additions & 0 deletions extensions/project-templates-activator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ eclipse {
}
}

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
dependsOn(":cli:unzipPortal")

archiveBaseName.set("com.liferay.project.templates.activator")
}

Expand Down
7 changes: 7 additions & 0 deletions extensions/project-templates-client-extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ dependencies {
testImplementation project(path: ":cli", configuration: "testApi")
}

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
dependsOn(":cli:unzipPortal")

archiveBaseName.set("com.liferay.project.templates.client.extension")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ eclipse {
}
}

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
dependsOn(":cli:unzipPortal")

archiveBaseName.set("com.liferay.project.templates.content.targeting.report")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ eclipse {
}
}

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
dependsOn(":cli:unzipPortal")

archiveBaseName.set("com.liferay.project.templates.content.targeting.rule")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ eclipse {
}
}

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
dependsOn(":cli:unzipPortal")

archiveBaseName.set("com.liferay.project.templates.content.targeting.tracking.action")
}

Expand Down
7 changes: 7 additions & 0 deletions extensions/project-templates-freemarker-portlet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ eclipse {
}
}

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
dependsOn(":cli:unzipPortal")

archiveBaseName.set("com.liferay.project.templates.freemarker.portlet")
}

Expand Down
1 change: 1 addition & 0 deletions extensions/project-templates-js-theme/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
Expand Down
1 change: 1 addition & 0 deletions extensions/project-templates-js-widget/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
Expand Down
5 changes: 5 additions & 0 deletions extensions/project-templates-social-bookmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ eclipse {
}
}

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
dependsOn(":cli:unzipPortal")

Expand Down
2 changes: 2 additions & 0 deletions extensions/sample-command/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ dependencies {

compileJava{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

jar{
dependsOn(":cli:unzipPortal")
dependsOn(":cli:unzipManifest")
}

test {
Expand Down
Loading

0 comments on commit 7f8a6a2

Please sign in to comment.