diff --git a/build.gradle b/build.gradle index 8996ade56..0e860fa8a 100644 --- a/build.gradle +++ b/build.gradle @@ -228,11 +228,6 @@ subprojects { "name: \"com.liferay.blade.extensions.maven.profile\", version: \"$version\"" } - buildGradle.text = buildGradle.text.replaceAll(/name: "com.liferay.project.templates.client.extension", version: "(.*)-SNAPSHOT"/) { - all, version -> - "name: \"com.liferay.project.templates.client.extension\", version: \"$version\"" - } - buildGradle.text = buildGradle.text.replaceAll(/name: "com.liferay.project.templates.js.theme", version: "(.*)-SNAPSHOT"/) { all, version -> "name: \"com.liferay.project.templates.js.theme\", version: \"$version\"" @@ -267,15 +262,6 @@ subprojects { "name: \"com.liferay.blade.extensions.maven.profile\", version: \"${newVersion}-SNAPSHOT\"" } - buildGradle.text = buildGradle.text.replaceAll(/name: "com.liferay.project.templates.client.extension", version: "(.*)"/) { - all, version -> - Version currentVersion = new Version(version) - - Version newVersion = new Version(currentVersion.major, currentVersion.minor, currentVersion.micro + 1) - - "name: \"com.liferay.project.templates.client.extension\", version: \"${newVersion}-SNAPSHOT\"" - } - buildGradle.text = buildGradle.text.replaceAll(/name: "com.liferay.project.templates.js.theme", version: "(.*)"/) { all, version -> Version currentVersion = new Version(version) diff --git a/cli/blade-jar-smoke-tests.gradle b/cli/blade-jar-smoke-tests.gradle index 2c1ee3e7d..2fb7371a5 100644 --- a/cli/blade-jar-smoke-tests.gradle +++ b/cli/blade-jar-smoke-tests.gradle @@ -1,8 +1,6 @@ import org.apache.tools.ant.taskdefs.condition.Os task smokeTests -task testBladeCreateCommandClientExtension(type: JavaExec) -task testBladeCreateCommandClientExtensionInCurrentDir(type: JavaExec) task testBladeCreateCommandFormField(type: JavaExec) task testBladeCreateCommandJsTheme(type: JavaExec) task testBladeCreateCommandListTemplates(type: JavaExec) @@ -42,60 +40,6 @@ ByteArrayOutputStream standardStream = new ByteArrayOutputStream() File initDir = new File(buildDir, "initTest") File clientExtensionDir = new File(initDir, "client-extension") -testBladeCreateCommandClientExtension { - dependsOn testBladeInitCommand - - doFirst { - clientExtensionDir.mkdirs() - } - - onlyIf { - !Os.isFamily(Os.FAMILY_WINDOWS) - } - - args = [jar.archivePath, "create", "-t", "client-extension", "--extension-name", "test123", "--extension-type", "customElement", "-d", clientExtensionDir.path, "customelementtest"] - errorOutput = errorStream - standardOutput = standardStream - workingDir = initDir - - doLast { - String error = errorStream.toString().toLowerCase() - File projectDir = new File(clientExtensionDir, "customelementtest") - boolean projectDirExists = projectDir.exists() - - errorStream.reset() - standardStream.reset() - - assert projectDirExists - assert !error.contains("error") - } -} - -testBladeCreateCommandClientExtensionInCurrentDir { - dependsOn testBladeInitCommand - - onlyIf { - !Os.isFamily(Os.FAMILY_WINDOWS) - } - - args = [jar.archivePath, "create", "-t", "client-extension", "--extension-name", "test123", "--extension-type", "customElement", "customelementtest1"] - errorOutput = errorStream - standardOutput = standardStream - workingDir = initDir - - doLast { - String error = errorStream.toString().toLowerCase() - File projectDir = new File(initDir, "customelementtest1") - boolean projectDirExists = projectDir.exists() - - errorStream.reset() - standardStream.reset() - - assert projectDirExists - assert !error.contains("error") - } -} - testBladeCreateCommandFormField { dependsOn testBladeInitCommand @@ -284,7 +228,7 @@ testBladeInitCommand { initDir.mkdirs() } - args = [jar.archivePath, "init", "-v", "dxp-7.2-ga1"] + args = [jar.archivePath, "init", "-v", "dxp-7.2.8"] errorOutput = errorStream standardOutput = standardStream workingDir = initDir @@ -361,7 +305,7 @@ testBladeInitCommandList { standardStream.reset() assert !error.contains("error") - assert !output.contains("dxp-7.2-sp1") + assert !output.contains("dxp-2023.q4.6") } } @@ -383,7 +327,7 @@ testBladeInitCommandListAll { standardStream.reset() assert !error.contains("error") - assert output.contains("dxp-7.2-sp1") + assert output.contains("dxp-2023.q4.6") } } diff --git a/cli/bnd.bnd b/cli/bnd.bnd index cb130d5ee..c41b77487 100644 --- a/cli/bnd.bnd +++ b/cli/bnd.bnd @@ -18,6 +18,8 @@ Private-Package:\ \ aQute.service.reporter;-split-package:=merge-first,\ \ + com.fasterxml.jackson.*,\ + \ com.liferay.blade.gradle.tooling,\ \ groovy.json,\ @@ -321,8 +323,8 @@ Private-Package:\ @com.liferay.gogo.shell.client-1.0.0.jar,\ @com.liferay.project.templates-*.jar,\ @jansi-*.jar,\ + ${project.buildDir}/releases.json,\ ${project.buildDir}/tooling.zip,\ ${project.buildDir}/wrapper.zip,\ - ${project.buildDir}/.product_info.json,\ mvnw.cmd -sources: false \ No newline at end of file diff --git a/cli/build.gradle b/cli/build.gradle index f57e46948..fd8e49341 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -19,6 +19,7 @@ buildscript { } apply plugin: "biz.aQute.bnd.builder" +apply plugin: "idea" apply plugin: "java-library" apply plugin: "maven-publish" @@ -31,7 +32,7 @@ tasks.register('copyMavenProfileJar', Copy) tasks.register('createToolingZip', Zip) tasks.register('createWrapperZip', Zip) tasks.register('downloadPortal', Download) -tasks.register('downloadProductInfo', Download) +tasks.register('downloadReleasesJson', Download) tasks.register('unzipManifest', Copy) tasks.register('unzipPortal', Copy) @@ -76,8 +77,9 @@ createWrapperZip { dependencies { api group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "5.3.0" + api group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.16.1" api group: "com.liferay", name: "com.liferay.gogo.shell.client", version: "1.0.0" - api group: "com.liferay", name: "com.liferay.project.templates", version: "5.0.269" + api group: "com.liferay", name: "com.liferay.project.templates", version: "5.0.289" api group: "commons-io", name: "commons-io", version: "2.7" api group: "commons-lang", name: "commons-lang", version: "2.6" api group: "org.apache.ant", name: "ant", version: "1.10.11" @@ -112,7 +114,6 @@ dependencies { api name: "org.objectweb.asm.util-6.0.0" bladeExtensions group: "com.liferay.blade", name: "com.liferay.blade.extensions.maven.profile", version: "1.0.39-SNAPSHOT" - bladeExtensions group: "com.liferay.blade", name: "com.liferay.project.templates.client.extension", version: "1.0.6-SNAPSHOT" bladeExtensions group: "com.liferay.blade", name: "com.liferay.project.templates.js.theme", version: "1.0.22-SNAPSHOT" bladeExtensions group: "com.liferay.blade", name: "com.liferay.project.templates.js.widget", version: "1.0.23-SNAPSHOT" @@ -139,8 +140,8 @@ downloadPortal { onlyIfNewer true } -downloadProductInfo { - src "https://releases-cdn.liferay.com/tools/workspace/.product_info.json" +downloadReleasesJson { + src "https://releases-cdn.liferay.com/releases.json" dest buildDir onlyIfNewer true } @@ -148,7 +149,7 @@ downloadProductInfo { jar { dependsOn("unzipPortal") archiveFileName.set("blade.jar") - from createToolingZip, createWrapperZip, downloadProductInfo + from createToolingZip, createWrapperZip, downloadReleasesJson } processResources { @@ -323,6 +324,6 @@ unzipPortal { finalizedBy("processZipsResources") } -version = "5.0.2-SNAPSHOT" +version = "6.0.0-SNAPSHOT" apply from: "blade-jar-smoke-tests.gradle" \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java b/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java index 3c2be9d3a..e93af1aba 100644 --- a/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java +++ b/cli/src/main/java/com/liferay/blade/cli/BladeCLI.java @@ -25,13 +25,14 @@ import com.liferay.blade.cli.command.validator.ParameterValidator; import com.liferay.blade.cli.command.validator.ValidatorFunctionPredicate; import com.liferay.blade.cli.gradle.GradleExecutionException; -import com.liferay.blade.cli.util.BladeUtil; +import com.liferay.blade.cli.util.ArrayUtil; import com.liferay.blade.cli.util.CombinedClassLoader; import com.liferay.blade.cli.util.FileUtil; import com.liferay.blade.cli.util.Pair; import com.liferay.blade.cli.util.ProcessesUtil; -import com.liferay.blade.cli.util.ProductInfo; import com.liferay.blade.cli.util.Prompter; +import com.liferay.blade.cli.util.ReleaseUtil; +import com.liferay.blade.cli.util.ResourceUtil; import java.io.BufferedReader; import java.io.File; @@ -406,6 +407,16 @@ public void printUsage(String command, String message) { public void run(String[] args) throws Exception { try { + if (ArrayUtil.contains(args, "--trace")) { + ResourceUtil.setTrace(true); + } + + if (ArrayUtil.contains(args, "--refresh-releases")) { + System.out.println("Checking for new releases..."); + + ReleaseUtil.populateReleases(0); + } + _removeOutDatedTempDir(); Extensions extensions = getExtensions(); @@ -473,7 +484,9 @@ public void run(String[] args) throws Exception { Object commandArgs = objects.get(0); - _validateParameters((BaseArgs)commandArgs); + BaseArgs baseArgs = (BaseArgs)commandArgs; + + _validateParameters(baseArgs); String parameterMessage = null; @@ -862,16 +875,14 @@ private Map _buildMavenPossibleValuesMap( Iterator it = options.iterator(); - Map productInfos = BladeUtil.getProductInfos(true, error()); - Map optionsMap = new LinkedHashMap<>(); for (int x = 1; it.hasNext(); x++) { String option = it.next(); - ProductInfo productInfo = new ProductInfo((Map)productInfos.get(option)); + ReleaseUtil.ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(option); - optionsMap.put(String.valueOf(x), productInfo.getTargetPlatformVersion()); + optionsMap.put(String.valueOf(x), releaseEntry.getTargetPlatformVersion()); } return optionsMap; diff --git a/cli/src/main/java/com/liferay/blade/cli/command/BaseArgs.java b/cli/src/main/java/com/liferay/blade/cli/command/BaseArgs.java index 024a03cc5..5c0cf1bf1 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/BaseArgs.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/BaseArgs.java @@ -36,6 +36,10 @@ public boolean isQuiet() { return _quiet; } + public boolean isRefreshReleases() { + return _refreshReleases; + } + public boolean isTrace() { return _trace; } @@ -52,6 +56,10 @@ public void setQuiet(boolean quiet) { _quiet = quiet; } + public void setRefreshReleases(boolean refreshReleases) { + _refreshReleases = refreshReleases; + } + @Parameter( description = "Specify a new base directory (default working directory).", hidden = true, names = "--base" ) @@ -69,6 +77,9 @@ public void setQuiet(boolean quiet) { @Parameter(description = "Do not print any optional messages to console.", hidden = true, names = {"-q", "--quiet"}) private boolean _quiet; + @Parameter(description = "Force Blade to check for new releases", names = "--refresh-releases") + private boolean _refreshReleases; + @Parameter(description = "Print exception stack traces when they occur.", hidden = true, names = "--trace") private boolean _trace; diff --git a/cli/src/main/java/com/liferay/blade/cli/command/ConvertCommand.java b/cli/src/main/java/com/liferay/blade/cli/command/ConvertCommand.java index 00f63c769..4da66ff87 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/ConvertCommand.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/ConvertCommand.java @@ -13,7 +13,7 @@ import com.liferay.blade.cli.util.CopyDirVisitor; import com.liferay.blade.cli.util.FileUtil; import com.liferay.blade.cli.util.ListUtil; -import com.liferay.blade.cli.util.ProductInfo; +import com.liferay.blade.cli.util.ReleaseUtil; import com.liferay.blade.cli.util.StringUtil; import com.liferay.blade.gradle.model.GradleDependency; import com.liferay.project.templates.extensions.ProjectTemplatesArgs; @@ -66,8 +66,6 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.LoadProperties; -import org.json.JSONObject; - import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; @@ -1160,13 +1158,14 @@ private List _getReleaseApirtifactIds() { String productKey = productKeyOpt.get(); - Optional targetPlatformVersionFromProduct = _getTargetPlatformVersionFromProduct(productKey); + String targetPlatformVersion = ReleaseUtil.withReleaseEntry( + productKey, ReleaseUtil.ReleaseEntry::getTargetPlatformVersion); - if (!targetPlatformVersionFromProduct.isPresent()) { + if (targetPlatformVersion == null) { return Collections.emptyList(); } - String simplifiedVersion = BladeUtil.simplifyTargetPlatformVersion(targetPlatformVersionFromProduct.get()); + String simplifiedVersion = BladeUtil.simplifyTargetPlatformVersion(targetPlatformVersion); String[] versionParts = simplifiedVersion.split("\\."); @@ -1202,43 +1201,6 @@ else if (productKey.startsWith("portal")) { return Collections.emptyList(); } - @SuppressWarnings("unchecked") - private Optional _getTargetPlatformVersionFromProduct(String productKey) { - try { - File userHomeDir = new File(System.getProperty("user.home")); - - userHomeDir = userHomeDir.getCanonicalFile(); - - Path userHomePath = userHomeDir.toPath(); - - Path productInfoPath = userHomePath.resolve(".liferay/workspace/.product_info.json"); - - if (!Files.exists(productInfoPath)) { - Map productInfos = BladeUtil.getProductInfos(); - - ProductInfo productInfo = new ProductInfo((Map)productInfos.get(productKey)); - - return Optional.of(productInfo.getTargetPlatformVersion()); - } - - JSONObject jsonObject = new JSONObject(new String(Files.readAllBytes(productInfoPath.normalize()))); - - return Optional.ofNullable( - jsonObject.get(productKey) - ).map( - JSONObject.class::cast - ).map( - info -> info.get("targetPlatformVersion") - ).map( - Object::toString - ); - } - catch (Exception exception) { - } - - return Optional.empty(); - } - private boolean _hasServiceXmlFile(File dir) { Path dirPath = dir.toPath(); diff --git a/cli/src/main/java/com/liferay/blade/cli/command/CreateArgs.java b/cli/src/main/java/com/liferay/blade/cli/command/CreateArgs.java index 50ef6436d..d3bd6b1be 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/CreateArgs.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/CreateArgs.java @@ -52,14 +52,6 @@ public File getDir() { return _dir; } - public String getExtensionName() { - return _extensionName; - } - - public String getExtensionType() { - return _extensionType; - } - public String getFramework() { return _framework; } @@ -144,14 +136,6 @@ public void setDir(File dir) { _dir = dir; } - public void setExtensionName(String extensionName) { - _extensionName = extensionName; - } - - public void setExtensionType(String extensionType) { - _extensionType = extensionType; - } - public void setFramework(String framework) { _framework = framework; } @@ -240,14 +224,6 @@ public void setViewType(String viewType) { @Parameter(description = "The directory where to create the new project.", names = {"-d", "--dir"}) private File _dir; - @Parameter(description = "Sets the name of client-extension template.", hidden = true, names = "--extension-name") - private String _extensionName; - - @Parameter( - description = "Sets the type of the client-extension template.", hidden = true, names = "--extension-type" - ) - private String _extensionType; - @Parameter( description = "The name of the framework to use in the generated project.", hidden = true, names = "--framework" ) diff --git a/cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java b/cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java index ce24ea41b..a027ef0bc 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java @@ -373,8 +373,6 @@ protected Map getProjectTemplateArgsExtProperties(CreateArgs cre properties.put("setAddOns", createArgs.getAddOns()); properties.put("setContributorType", createArgs.getContributorType()); properties.put("setDependencyInjector", createArgs.getDependencyInjector()); - properties.put("setExtensionName", createArgs.getExtensionName()); - properties.put("setExtensionType", createArgs.getExtensionType()); properties.put("setFramework", createArgs.getFramework()); properties.put("setFrameworkDependencies", createArgs.getFrameworkDependencies()); properties.put("setHostBundleSymbolicName", createArgs.getHostBundleBSN()); @@ -472,6 +470,12 @@ private boolean _checkDir(File file) { } private String _checkTemplateVersionRange(File templateFile, ProjectTemplatesArgs projectTemplatesArgs) { + String versionString = projectTemplatesArgs.getLiferayVersion(); + + if (VersionUtil.isLiferayQuarterlyVersion(versionString)) { + return ""; + } + try (InputStream fileInputStream = Files.newInputStream(templateFile.toPath(), StandardOpenOption.READ); JarInputStream in = new JarInputStream(fileInputStream)) { @@ -483,17 +487,14 @@ private String _checkTemplateVersionRange(File templateFile, ProjectTemplatesArg VersionRange versionRange = new VersionRange(versionRangeValue); - String versionString = projectTemplatesArgs.getLiferayVersion(); - - String liferayVersionString = new String( - String.valueOf(VersionUtil.getMajorVersion(versionString)) + "." + - String.valueOf(VersionUtil.getMinorVersion(versionString))); + String liferayVersionString = String.format( + "%s.%s", VersionUtil.getMajorVersion(versionString), VersionUtil.getMinorVersion(versionString)); if (!versionRange.includes(Version.parseVersion(liferayVersionString))) { - return new String( - "Error: The " + projectTemplatesArgs.getTemplate() + - " project can only be created in liferay version range: " + versionRange + - ", current liferay version is " + liferayVersionString + "."); + return String.format( + "Error: The %s project can only be created in liferay version range: %s, current liferay version " + + "is %s.", + projectTemplatesArgs.getTemplate(), versionRange, liferayVersionString); } } catch (Exception exception) { diff --git a/cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java b/cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java index 35f602619..dfa9f99f2 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java @@ -5,14 +5,12 @@ package com.liferay.blade.cli.command; -import aQute.bnd.version.Version; - import com.liferay.blade.cli.BladeCLI; import com.liferay.blade.cli.BladeSettings; import com.liferay.blade.cli.WorkspaceProvider; import com.liferay.blade.cli.gradle.GradleExec; import com.liferay.blade.cli.util.BladeUtil; -import com.liferay.blade.cli.util.ProductInfo; +import com.liferay.blade.cli.util.ReleaseUtil; import com.liferay.project.templates.ProjectTemplates; import com.liferay.project.templates.extensions.ProjectTemplatesArgs; import com.liferay.project.templates.extensions.util.FileUtil; @@ -56,9 +54,14 @@ public void execute() throws Exception { InitArgs initArgs = getArgs(); if (initArgs.isList()) { - List keys = BladeUtil.getWorkspaceProductKeys(!initArgs.isAll()); - - keys.forEach(bladeCLI::out); + ReleaseUtil.releaseEntriesStream( + ).filter( + releaseEntry -> initArgs.isAll() || releaseEntry.isPromoted() + ).map( + ReleaseUtil.ReleaseEntry::getReleaseKey + ).forEach( + bladeCLI::out + ); return; } @@ -188,65 +191,32 @@ public void execute() throws Exception { projectTemplatesArgs.setGradle(!mavenBuild); - String liferayVersion; - String workspaceProductKey; - - Map productInfos = BladeUtil.getProductInfos(initArgs.isTrace(), bladeCLI.error()); - - if (!mavenBuild) { - workspaceProductKey = _getDefaultProductKey(initArgs); - - if (_legacyProductKeys.contains(workspaceProductKey)) { - _addError( - "This version of blade does not support " + workspaceProductKey + ". Please use blade 3.9.2 to " + - "initialize a workspace with this version. https://bit.ly/3lVgTeH"); - - return; - } - - Object productInfoObject = productInfos.get(workspaceProductKey); - - if (productInfoObject == null) { - _addError("Unable to get product info for selected version " + workspaceProductKey); - - return; - } - - ProductInfo productInfo = new ProductInfo((Map)productInfoObject); + Optional releaseEntryOptional = _getDefaultReleaseEntry( + initArgs.getLiferayProduct(), initArgs.getLiferayVersion()); - Version targetPlatformVersion = _makeCompatibleVersion(productInfo.getTargetPlatformVersion()); + if (!releaseEntryOptional.isPresent()) { + _addError("Unable to get product info for selected version " + initArgs.getLiferayVersion()); - liferayVersion = new String( - targetPlatformVersion.getMajor() + "." + targetPlatformVersion.getMinor() + "." + - targetPlatformVersion.getMicro()); + return; } - else { - workspaceProductKey = _setProductAndVersionForMaven(productInfos, initArgs); - liferayVersion = initArgs.getLiferayVersion(); - } + ReleaseUtil.ReleaseEntry releaseEntry = releaseEntryOptional.get(); - Object productInfoObject = productInfos.get(workspaceProductKey); + String workspaceProductKey = releaseEntry.getReleaseKey(); - if (productInfoObject == null) { - _addError("Unable to get product info for selected version " + workspaceProductKey); + if (!mavenBuild && _legacyProductKeys.contains(workspaceProductKey)) { + _addError( + "This version of blade does not support " + workspaceProductKey + ". Please use blade 3.9.2 to " + + "initialize a workspace with this version. https://bit.ly/3lVgTeH"); return; } - if (Objects.equals(initArgs.getLiferayProduct(), "commerce")) { - initArgs.setLiferayProduct("dxp"); - } - - projectTemplatesArgs.setLiferayVersion(liferayVersion); - + projectTemplatesArgs.setLiferayProduct(releaseEntry.getProduct()); + projectTemplatesArgs.setLiferayVersion(releaseEntry.getTargetPlatformVersion()); projectTemplatesArgs.setMaven(mavenBuild); projectTemplatesArgs.setName(name); - if (mavenBuild) { - projectTemplatesArgs.setLiferayProduct(initArgs.getLiferayProduct()); - } - String template = "workspace"; Map initTemplates = BladeUtil.getInitTemplates(bladeCLI); @@ -320,27 +290,37 @@ private void _addError(String msg) { getBladeCLI().addErrors("init", Collections.singleton(msg)); } - private String _getDefaultProductKey(InitArgs initArgs) throws Exception { - String liferayVersion = initArgs.getLiferayVersion(); + private Optional _getDefaultReleaseEntry(String liferayProduct, String liferayVersion) { + ReleaseUtil.ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(liferayVersion); - if (liferayVersion.startsWith("portal") || liferayVersion.startsWith("dxp") || - liferayVersion.startsWith("commerce")) { - - return initArgs.getLiferayVersion(); + if (releaseEntry.getReleaseKey() != null) { + return Optional.of(releaseEntry); } - List productInfoKeys = BladeUtil.getWorkspaceProductKeys(false); + Optional defaultVersion = ReleaseUtil.withReleaseEntriesStream( + stream -> stream.filter( + releaseEntry1 -> Objects.equals(releaseEntry1.getProduct(), liferayProduct) + ).filter( + releaseEntry1 -> Objects.equals(releaseEntry1.getTargetPlatformVersion(), liferayVersion) + ).findFirst()); - Optional defaultVersion = productInfoKeys.stream( - ).filter( - value -> value.startsWith(initArgs.getLiferayProduct() + "-" + initArgs.getLiferayVersion()) - ).findFirst(); + if (!defaultVersion.isPresent()) { + defaultVersion = ReleaseUtil.withReleaseEntriesStream( + stream -> stream.filter( + releaseEntry1 -> Objects.equals(releaseEntry1.getProduct(), liferayProduct) + ).filter( + releaseEntry1 -> Objects.equals(releaseEntry1.getProductGroupVersion(), liferayVersion) + ).findFirst()); + } if (!defaultVersion.isPresent()) { - return initArgs.getLiferayVersion(); + defaultVersion = ReleaseUtil.withReleaseEntriesStream( + stream -> stream.filter( + releaseEntry1 -> Objects.equals(releaseEntry1.getTargetPlatformVersion(), liferayVersion) + ).findFirst()); } - return defaultVersion.get(); + return defaultVersion; } private boolean _isPluginsSDK(File dir) { @@ -396,21 +376,6 @@ private boolean _isPluginsSDK70(File dir) { return false; } - private Version _makeCompatibleVersion(String targetPlatformVersion) { - int dash = targetPlatformVersion.indexOf("-"); - - Version productTargetPlatformVersion = null; - - if (dash != -1) { - productTargetPlatformVersion = Version.parseVersion(targetPlatformVersion.substring(0, dash)); - } - else { - productTargetPlatformVersion = Version.parseVersion(targetPlatformVersion); - } - - return productTargetPlatformVersion; - } - private void _moveContentsToDirectory(File src, File dest) throws Exception { Path srcPath = src.toPath(); @@ -480,46 +445,6 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttribu }); } - @SuppressWarnings("unchecked") - private String _setProductAndVersionForMaven(Map productInfos, InitArgs initArgs) throws Exception { - String possibleProductKey = _getDefaultProductKey(initArgs); - - if (possibleProductKey.startsWith("portal") || possibleProductKey.startsWith("dxp") || - possibleProductKey.startsWith("commerce")) { - - Object productInfoObject = productInfos.get(possibleProductKey); - - if (Objects.nonNull(productInfoObject)) { - ProductInfo productInfo = new ProductInfo((Map)productInfoObject); - - initArgs.setLiferayVersion(productInfo.getTargetPlatformVersion()); - - String[] productKeyValues = possibleProductKey.split("-"); - - initArgs.setLiferayProduct(productKeyValues[0]); - - return possibleProductKey; - } - } - else { - for (Map.Entry entryKey : productInfos.entrySet()) { - ProductInfo productInfo = new ProductInfo((Map)entryKey.getValue()); - - if (Objects.equals(possibleProductKey, productInfo.getTargetPlatformVersion())) { - possibleProductKey = entryKey.getKey(); - - String[] productKeyValues = possibleProductKey.split("-"); - - initArgs.setLiferayProduct(productKeyValues[0]); - - return possibleProductKey; - } - } - } - - return null; - } - private void _setWorkspacePluginVersion(Path path, String version) throws Exception { Path settingsPath = path.resolve("settings.gradle"); diff --git a/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayDefaultVersionValidator.java b/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayDefaultVersionValidator.java index da427fa39..2aacf8e1a 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayDefaultVersionValidator.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayDefaultVersionValidator.java @@ -5,9 +5,10 @@ package com.liferay.blade.cli.command.validator; -import com.liferay.blade.cli.util.BladeUtil; +import com.liferay.blade.cli.util.ReleaseUtil; import java.util.List; +import java.util.stream.Collectors; /** * @author Christopher Bryan Boyd @@ -18,7 +19,14 @@ public class LiferayDefaultVersionValidator extends LiferayMoreVersionValidator @Override public List get() { - return BladeUtil.getWorkspaceProductKeys(true); + return ReleaseUtil.withReleaseEntriesStream( + stream -> stream.filter( + ReleaseUtil.ReleaseEntry::isPromoted + ).map( + ReleaseUtil.ReleaseEntry::getReleaseKey + ).collect( + Collectors.toList() + )); } } \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidator.java b/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidator.java index b43158c1c..a640c2485 100644 --- a/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidator.java +++ b/cli/src/main/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidator.java @@ -7,14 +7,10 @@ import com.beust.jcommander.ParameterException; -import com.liferay.blade.cli.WorkspaceConstants; -import com.liferay.blade.cli.util.BladeUtil; -import com.liferay.blade.cli.util.ProductKeyUtil; -import com.liferay.project.templates.extensions.util.VersionUtil; +import com.liferay.blade.cli.util.ReleaseUtil; -import java.util.ArrayList; import java.util.List; -import java.util.Set; +import java.util.stream.Collectors; /** * @author Simon Jiang @@ -23,21 +19,19 @@ public class LiferayMoreVersionValidator implements ValidatorSupplier { @Override public List get() { - return BladeUtil.getWorkspaceProductKeys(false); + return ReleaseUtil.withReleaseEntriesStream( + stream -> stream.map( + ReleaseUtil.ReleaseEntry::getReleaseKey + ).collect( + Collectors.toList() + )); } @Override public void validate(String name, String value) throws ParameterException { - List possibleValues = new ArrayList<>(get()); - - Set allTargetPlatformVersions = BladeUtil.getWorkspaceProductTargetPlatformVersions(false); - - possibleValues.addAll(WorkspaceConstants.originalLiferayVersions); - - if ((!possibleValues.contains(value) && !allTargetPlatformVersions.contains(value)) || - (!ProductKeyUtil.verifyPortalDxpWorkspaceProduct(value) && !VersionUtil.isLiferayVersion(value) && - !ProductKeyUtil.verifyCommerceWorkspaceProduct(value))) { + ReleaseUtil.ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(value); + if (releaseEntry == null) { throw new ParameterException(value + " is not a valid value."); } } diff --git a/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java b/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java index fd7b24ce3..8803b2158 100644 --- a/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java +++ b/cli/src/main/java/com/liferay/blade/cli/gradle/GradleWorkspaceProvider.java @@ -12,12 +12,11 @@ import com.liferay.blade.cli.WorkspaceProvider; import com.liferay.blade.cli.command.BaseArgs; import com.liferay.blade.cli.util.BladeUtil; -import com.liferay.blade.cli.util.ProductInfo; +import com.liferay.blade.cli.util.ReleaseUtil; import java.io.File; import java.io.FilenameFilter; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Properties; @@ -75,17 +74,14 @@ public String getLiferayVersion(File workspaceDir) { if (!baseLiferayVersion.isPresent()) { String productKey = gradleProperties.getProperty(WorkspaceConstants.DEFAULT_WORKSPACE_PRODUCT_PROPERTY); - Map productInfoMap = BladeUtil.getProductInfos(); + String targetPlatformVersion = ReleaseUtil.withReleaseEntry( + productKey, ReleaseUtil.ReleaseEntry::getTargetPlatformVersion); - ProductInfo productInfo = new ProductInfo((Map)productInfoMap.get(productKey)); - - if (productInfo != null) { - baseLiferayVersion = Optional.ofNullable( - productInfo.getTargetPlatformVersion() - ).filter( - BladeUtil::isNotEmpty - ); - } + baseLiferayVersion = Optional.ofNullable( + targetPlatformVersion + ).filter( + BladeUtil::isNotEmpty + ); } if (!baseLiferayVersion.isPresent()) { diff --git a/cli/src/main/java/com/liferay/blade/cli/util/ArrayUtil.java b/cli/src/main/java/com/liferay/blade/cli/util/ArrayUtil.java index 51da873ee..c8e09bf1f 100644 --- a/cli/src/main/java/com/liferay/blade/cli/util/ArrayUtil.java +++ b/cli/src/main/java/com/liferay/blade/cli/util/ArrayUtil.java @@ -7,6 +7,8 @@ import java.lang.reflect.Array; +import java.util.Objects; + /** * @author Gregory Amerson */ @@ -38,6 +40,20 @@ public static T[] append(T[] array1, T[] array2) { return newArray; } + public static boolean contains(Object[] array, Object value) { + if (isEmpty(array)) { + return false; + } + + for (Object object : array) { + if (Objects.equals(object, value)) { + return true; + } + } + + return false; + } + public static boolean isEmpty(Object[] array) { if ((array == null) || (array.length == 0)) { return true; diff --git a/cli/src/main/java/com/liferay/blade/cli/util/BladeUtil.java b/cli/src/main/java/com/liferay/blade/cli/util/BladeUtil.java index a749b28d5..a9ca3c342 100644 --- a/cli/src/main/java/com/liferay/blade/cli/util/BladeUtil.java +++ b/cli/src/main/java/com/liferay/blade/cli/util/BladeUtil.java @@ -11,8 +11,6 @@ import com.liferay.project.templates.ProjectTemplates; import com.liferay.project.templates.extensions.util.ProjectTemplatesUtil; -import groovy.json.JsonSlurper; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -39,7 +37,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -49,7 +46,6 @@ import java.util.Objects; import java.util.Properties; import java.util.Scanner; -import java.util.Set; import java.util.function.Predicate; import java.util.jar.Attributes; import java.util.jar.JarFile; @@ -318,43 +314,6 @@ public static String getManifestProperty(Path pathToJar, String propertyName) th } } - public static Map getProductInfos() { - return getProductInfos(false, null); - } - - @SuppressWarnings("unchecked") - public static synchronized Map getProductInfos(boolean trace, PrintStream printStream) { - if (!_productInfoMap.isEmpty()) { - return _productInfoMap; - } - - JsonSlurper jsonSlurper = new JsonSlurper(); - - try { - Path productInfoPath = downloadFile(_PRODUCT_INFO_URL, _workspaceCacheDir.toPath(), ".product_info.json"); - - try (BufferedReader reader = Files.newBufferedReader(productInfoPath)) { - _productInfoMap = (Map)jsonSlurper.parse(reader); - } - } - catch (Exception exception1) { - if (trace && (printStream != null)) { - exception1.printStackTrace(printStream); - } - - try (InputStream resourceAsStream = BladeUtil.class.getResourceAsStream("/.product_info.json")) { - _productInfoMap = (Map)jsonSlurper.parse(resourceAsStream); - } - catch (Exception exception2) { - if (trace && (printStream != null)) { - exception2.printStackTrace(printStream); - } - } - } - - return _productInfoMap; - } - public static Properties getProperties(File file) { Properties properties = new Properties(); @@ -389,54 +348,6 @@ public static Map getTemplates(BladeCLI bladeCLI) throws Excepti return ProjectTemplates.getTemplates(templatesFiles); } - @SuppressWarnings("unchecked") - public static List getWorkspaceProductKeys(boolean promoted) { - Map productInfos = getProductInfos(); - - return productInfos.keySet( - ).stream( - ).filter( - key -> Objects.nonNull(productInfos.get(key)) - ).filter( - key -> { - ProductInfo productInfo = new ProductInfo((Map)productInfos.get(key)); - - if (productInfo.getTargetPlatformVersion() == null) { - return false; - } - - if (promoted && !productInfo.isPromoted()) { - return false; - } - - return true; - } - ).sorted( - ProductKeyUtil.comparator - ).collect( - Collectors.toList() - ); - } - - @SuppressWarnings("unchecked") - public static Set getWorkspaceProductTargetPlatformVersions(boolean promoted) { - Map productInfos = getProductInfos(); - - return productInfos.entrySet( - ).stream( - ).filter( - entry -> Objects.nonNull(productInfos.get(entry.getKey())) - ).map( - entry -> new ProductInfo((Map)entry.getValue()) - ).filter( - product -> Objects.nonNull(product.getTargetPlatformVersion()) && (!promoted || product.isPromoted()) - ).map( - ProductInfo::getTargetPlatformVersion - ).collect( - Collectors.toSet() - ); - } - public static boolean hasGradleWrapper(File dir) { File gradlew = new File(dir, _GRADLEW_UNIX_FILE_NAME); File gradleBat = new File(dir, _GRADLEW_WINDOWS_FILE_NAME); @@ -851,17 +762,10 @@ private static Path _downloadFile( "build." + System.getenv("HOSTNAME") + ".properties", "build.properties" }; - private static final String _DEFAULT_WORKSPACE_CACHE_DIR_NAME = ".liferay/workspace"; - private static final String _GRADLEW_UNIX_FILE_NAME = "gradlew"; private static final String _GRADLEW_WINDOWS_FILE_NAME = "gradlew.bat"; - private static final String _PRODUCT_INFO_URL = "https://releases.liferay.com/tools/workspace/.product_info.json"; - private static final Pattern _microPattern = Pattern.compile("((([efs])p)|(ga)|(u))([0-9]+)(-[0-9]+)?"); - private static Map _productInfoMap = Collections.emptyMap(); - private static final File _workspaceCacheDir = new File( - System.getProperty("user.home"), _DEFAULT_WORKSPACE_CACHE_DIR_NAME); } \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyInfo.java b/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyInfo.java deleted file mode 100644 index 15f13c4a9..000000000 --- a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyInfo.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com - * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 - */ - -package com.liferay.blade.cli.util; - -import java.util.Comparator; - -/** - * @author Drew Brokke - */ -public class ProductKeyInfo implements Comparable { - - @Override - public int compareTo(final ProductKeyInfo keyInfo) { - return Comparator.comparing( - ProductKeyInfo::getProductRank - ).thenComparing( - ProductKeyInfo::isQuarterly - ).thenComparing( - ProductKeyInfo::getMajorProductKeyVersion - ).thenComparing( - ProductKeyInfo::getMinorProductKeyVersion - ).thenComparing( - ProductKeyInfo::getMicroProductKeyVersion - ).reversed( - ).compare( - this, keyInfo - ); - } - - public ProductKeyVersion getMajorProductKeyVersion() { - return _majorProductKeyVersion; - } - - public ProductKeyVersion getMicroProductKeyVersion() { - return _microProductKeyVersion; - } - - public ProductKeyVersion getMinorProductKeyVersion() { - return _minorProductKeyVersion; - } - - public String getProduct() { - return _product; - } - - public int getProductRank() { - return _productRank; - } - - public boolean isQuarterly() { - return _quarterly; - } - - public void setMajorProductKeyVersion(ProductKeyVersion majorProductKeyVersion) { - _majorProductKeyVersion = majorProductKeyVersion; - } - - public void setMicroProductKeyVersion(ProductKeyVersion microProductKeyVersion) { - _microProductKeyVersion = microProductKeyVersion; - } - - public void setMinorProductKeyVersion(ProductKeyVersion minorProductKeyVersion) { - _minorProductKeyVersion = minorProductKeyVersion; - } - - public void setProduct(String product) { - _product = product; - } - - public void setProductRank(int productRank) { - _productRank = productRank; - } - - public void setQuarterly(boolean quarterly) { - _quarterly = quarterly; - } - - private ProductKeyVersion _majorProductKeyVersion = ProductKeyVersion.BLANK; - private ProductKeyVersion _microProductKeyVersion = ProductKeyVersion.BLANK; - private ProductKeyVersion _minorProductKeyVersion = ProductKeyVersion.BLANK; - private String _product; - private int _productRank = -1; - private boolean _quarterly = false; - -} \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyUtil.java b/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyUtil.java deleted file mode 100644 index 8011dbb6c..000000000 --- a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyUtil.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com - * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 - */ - -package com.liferay.blade.cli.util; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @author Drew Brokke - */ -public class ProductKeyUtil { - - public static final Comparator comparator = ProductKeyUtil::compare; - public static final Pattern productKeyCommercePattern = Pattern.compile( - "^(?commerce)-(?[1-9]\\.\\d\\.\\d)(?:-(?[1-9]\\.\\d))?$"); - public static final Pattern productKeyDXPNonquarterlyPattern = Pattern.compile( - "^(?dxp)-(?[1-9]\\.\\d)-(?(?:de|ep|fp|ga|sp|u)\\d+)$"); - public static final Pattern productKeyDXPQuarterlyPattern = Pattern.compile( - "^(?dxp)-(?2\\d{3})\\.(?q[1234])\\.(?\\d+)$"); - public static final Pattern productKeyPortalPattern = Pattern.compile( - "^(?portal)-(?[1-9]\\.\\d)-(?ga\\d+)$"); - - public static int compare(String productKey1, String productKey2) { - ProductKeyInfo keyInfo1 = createProductKeyInfo(productKey1); - - return keyInfo1.compareTo(createProductKeyInfo(productKey2)); - } - - public static ProductKeyInfo createProductKeyInfo(String productKey) { - Matcher matcher = _getFirstMatchingMatcher( - productKey, productKeyDXPQuarterlyPattern, productKeyDXPNonquarterlyPattern, productKeyPortalPattern, - productKeyCommercePattern); - - if (matcher == null) { - throw new IllegalArgumentException(String.format("%s is not a valid Liferay product key\n", productKey)); - } - - ProductKeyInfo productKeyInfo = new ProductKeyInfo(); - - _withGroup( - matcher, "product", - group -> { - productKeyInfo.setProduct(group); - - productKeyInfo.setProductRank(_getProductRank(group)); - }); - _withGroup(matcher, "major", group -> productKeyInfo.setMajorProductKeyVersion(createProductKeyVersion(group))); - _withGroup( - matcher, "minor", - group -> { - ProductKeyVersion minorProductKeyVersion = createProductKeyVersion(group); - - productKeyInfo.setMinorProductKeyVersion(minorProductKeyVersion); - - if (Objects.equals(productKeyInfo.getProduct(), "dxp") && - Objects.equals(minorProductKeyVersion.getType(), "q")) { - - productKeyInfo.setQuarterly(true); - } - }); - _withGroup(matcher, "micro", group -> productKeyInfo.setMicroProductKeyVersion(createProductKeyVersion(group))); - - return productKeyInfo; - } - - public static ProductKeyVersion createProductKeyVersion(String versionString) { - ProductKeyVersion productKeyVersion = new ProductKeyVersion(); - - StringBuilder numberStringBuilder = new StringBuilder(); - StringBuilder typeStringBuilder = new StringBuilder(); - - for (char c : versionString.toCharArray()) { - if (Character.isDigit(c)) { - numberStringBuilder.append(c); - } - else if (Character.isAlphabetic(c)) { - typeStringBuilder.append(c); - } - } - - if (numberStringBuilder.length() > 0) { - productKeyVersion.setNumber(Integer.parseInt(numberStringBuilder.toString())); - } - - productKeyVersion.setType(typeStringBuilder.toString()); - - return productKeyVersion; - } - - public static boolean verifyCommerceWorkspaceProduct(String product) { - return _matchesAny(product, productKeyCommercePattern); - } - - public static boolean verifyPortalDxpWorkspaceProduct(String product) { - return _matchesAny( - product, productKeyDXPQuarterlyPattern, productKeyDXPNonquarterlyPattern, productKeyPortalPattern); - } - - private static Matcher _getFirstMatchingMatcher(String s, Pattern... patterns) { - for (Pattern pattern : patterns) { - Matcher matcher = pattern.matcher(s); - - if (matcher.matches()) { - return matcher; - } - } - - return null; - } - - private static int _getProductRank(String name) { - return _orderedProducts.size() - _orderedProducts.indexOf(name); - } - - private static boolean _matchesAny(String s, Pattern... patterns) { - Matcher matcher = _getFirstMatchingMatcher(s, patterns); - - if (matcher != null) { - return true; - } - - return false; - } - - private static void _withGroup(Matcher matcher, String groupName, Consumer consumer) { - try { - String group = matcher.group(groupName); - - if (group != null) { - consumer.accept(group); - } - } - catch (Exception exception) { - } - } - - private static final List _orderedProducts = Collections.unmodifiableList( - Arrays.asList("dxp", "portal", "commerce")); - -} \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyVersion.java b/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyVersion.java deleted file mode 100644 index 38b7f32ca..000000000 --- a/cli/src/main/java/com/liferay/blade/cli/util/ProductKeyVersion.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com - * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 - */ - -package com.liferay.blade.cli.util; - -import java.util.Comparator; - -/** - * @author Drew Brokke - */ -public class ProductKeyVersion implements Comparable { - - public static final ProductKeyVersion BLANK = new ProductKeyVersion(); - - @Override - public int compareTo(final ProductKeyVersion version) { - return Comparator.comparingInt( - ProductKeyVersion::getNumber - ).thenComparing( - ProductKeyVersion::getType - ).compare( - this, version - ); - } - - public int getNumber() { - return _number; - } - - public String getType() { - return _type; - } - - public void setNumber(int number) { - _number = number; - } - - public void setType(String type) { - _type = type; - } - - private int _number = 0; - private String _type; - -} \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/util/ReleaseUtil.java b/cli/src/main/java/com/liferay/blade/cli/util/ReleaseUtil.java new file mode 100644 index 000000000..7268f8734 --- /dev/null +++ b/cli/src/main/java/com/liferay/blade/cli/util/ReleaseUtil.java @@ -0,0 +1,142 @@ +/** + * SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com + * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 + */ + +package com.liferay.blade.cli.util; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.File; + +import java.time.temporal.ChronoUnit; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Stream; + +/** + * @author Drew Brokke + */ +public class ReleaseUtil { + + public static ReleaseEntry getReleaseEntry(String releaseKey) { + if (_releaseUtil == null) { + populateReleases(_DEFAULT_MAX_AGE); + } + + return _releaseUtil._releaseEntryMap.getOrDefault(releaseKey, _EMPTY_RELEASE_ENTRY); + } + + public static void populateReleases(int maxAge) { + _releaseUtil = new ReleaseUtil(maxAge); + } + + public static Stream releaseEntriesStream() { + if (_releaseUtil == null) { + populateReleases(_DEFAULT_MAX_AGE); + } + + return _releaseUtil._releaseEntries.stream(); + } + + public static T withReleaseEntriesStream(Function, T> function) { + return function.apply(releaseEntriesStream()); + } + + public static T withReleaseEntry(String releaseKey, Function function) { + return function.apply(getReleaseEntry(releaseKey)); + } + + public static class ReleaseEntry { + + public String getProduct() { + return _product; + } + + public String getProductGroupVersion() { + return _productGroupVersion; + } + + public String getProductVersion() { + return _productVersion; + } + + public String getReleaseKey() { + return _releaseKey; + } + + public String getTargetPlatformVersion() { + return _targetPlatformVersion; + } + + public String getUrl() { + return _url; + } + + public boolean isPromoted() { + return _promoted; + } + + @JsonProperty("product") + private String _product; + + @JsonProperty("productGroupVersion") + private String _productGroupVersion; + + @JsonProperty("productVersion") + private String _productVersion; + + @JsonProperty("promoted") + private boolean _promoted; + + @JsonProperty("releaseKey") + private String _releaseKey; + + @JsonProperty("targetPlatformVersion") + private String _targetPlatformVersion; + + @JsonProperty("url") + private String _url; + + } + + private ReleaseUtil(int maxAge) { + File releasesJsonFile = new File(_workspaceCacheDir, "releases.json"); + + _releaseEntries = ResourceUtil.readJson( + ReleaseEntries.class, ResourceUtil.getLocalFileResolver(System.getenv("BLADE_LOCAL_RELEASES_JSON_FILE")), + ResourceUtil.getLocalFileResolver(releasesJsonFile, maxAge, ChronoUnit.DAYS), + ResourceUtil.getURLResolver( + _workspaceCacheDir, "https://releases-cdn.liferay.com/releases.json", "releases.json"), + ResourceUtil.getURLResolver( + _workspaceCacheDir, "https://releases.liferay.com/releases.json", "releases.json"), + ResourceUtil.getClassLoaderResolver("/releases.json")); + + if (_releaseEntries == null) { + throw new RuntimeException("Could not find releases.json"); + } + + _releaseEntryMap.clear(); + + for (ReleaseEntry releaseEntry : _releaseEntries) { + _releaseEntryMap.put(releaseEntry.getReleaseKey(), releaseEntry); + } + } + + private static final int _DEFAULT_MAX_AGE = 7; + + private static final ReleaseEntry _EMPTY_RELEASE_ENTRY = new ReleaseEntry(); + + private static ReleaseUtil _releaseUtil; + + private final ReleaseEntries _releaseEntries; + private final Map _releaseEntryMap = new HashMap<>(); + private final File _workspaceCacheDir = new File(System.getProperty("user.home"), ".liferay/workspace"); + + private static class ReleaseEntries extends ArrayList { + } + +} \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/util/ResourceUtil.java b/cli/src/main/java/com/liferay/blade/cli/util/ResourceUtil.java new file mode 100644 index 000000000..56b413b22 --- /dev/null +++ b/cli/src/main/java/com/liferay/blade/cli/util/ResourceUtil.java @@ -0,0 +1,344 @@ +/** + * SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com + * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 + */ + +package com.liferay.blade.cli.util; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import java.net.URI; +import java.net.URL; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileTime; + +import java.time.Duration; +import java.time.Instant; +import java.time.temporal.TemporalUnit; + +import java.util.Date; +import java.util.Objects; + +import org.apache.hc.client5.http.auth.AuthScope; +import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpHead; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.protocol.HttpClientContext; +import org.apache.hc.client5.http.protocol.RedirectLocations; +import org.apache.hc.client5.http.utils.DateUtils; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpHeaders; +import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.http.HttpStatus; +import org.apache.hc.core5.http.protocol.BasicHttpContext; +import org.apache.hc.core5.http.protocol.HttpContext; + +/** + * @author Drew Brokke + */ +public class ResourceUtil { + + public static Resolver getClassLoaderResolver(String resourcePath) { + return () -> { + _print("Trying to get resource from class path: %s", resourcePath); + + return Objects.requireNonNull( + ResourceUtil.class.getResourceAsStream(resourcePath), + "Unable to get resource from class path: " + resourcePath); + }; + } + + public static Resolver getLocalFileResolver(File file) { + return () -> { + _print("Trying to get resource from local file: %s", file.getAbsolutePath()); + + _checkFileExists(file); + + return Files.newInputStream(file.toPath()); + }; + } + + public static Resolver getLocalFileResolver(File file, long maxAge, TemporalUnit temporalUnit) { + return () -> { + _print( + "Trying to get resource from local file with max age of %s %s: %s", maxAge, temporalUnit, + file.getAbsolutePath()); + + _checkFileExists(file); + + BasicFileAttributes basicFileAttributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class); + + FileTime fileTime = basicFileAttributes.lastModifiedTime(); + + Duration age = Duration.between(fileTime.toInstant(), Instant.now()); + + if (age.compareTo(Duration.of(maxAge, temporalUnit)) > 0) { + throw new Exception( + String.format("Cached file %s is older than max age of %s %s", file, maxAge, temporalUnit)); + } + + return Files.newInputStream(file.toPath()); + }; + } + + public static Resolver getLocalFileResolver(String file) { + if (StringUtil.isNullOrEmpty(file)) { + return () -> null; + } + + return getLocalFileResolver(new File(file)); + } + + public static Resolver getURIResolver(File cacheDir, URI uri, String targetFileName) { + return () -> { + _print("Trying to get resource from URL %s", uri); + + URL url = uri.toURL(); + + try { + Path path = _downloadFile(url.toString(), cacheDir.toPath(), targetFileName); + + Files.setLastModifiedTime(path, FileTime.from(Instant.now())); + + return Files.newInputStream(path); + } + catch (Exception exception) { + throw new Exception( + String.format("Unable to get resource from URL %s: %s", url, exception.getMessage()), exception); + } + }; + } + + public static Resolver getURLResolver(File cacheDir, String url, String targetFileName) { + return getURIResolver(cacheDir, URI.create(url), targetFileName); + } + + public static T readJson(Class clazz, Resolver... resolvers) { + return _withInputStream(inputStream -> _objectMapper.readValue(inputStream, clazz), resolvers); + } + + public static void setTrace(boolean trace) { + ResourceUtil._trace = trace; + } + + @FunctionalInterface + public interface Resolver { + + public InputStream resolve() throws Exception; + + } + + @FunctionalInterface + public interface Transformer { + + public T transform(InputStream inputStream) throws Exception; + + } + + private static void _checkFileExists(File file) throws Exception { + if (!file.exists()) { + throw new FileNotFoundException("Unable to get resource from local file: " + file.getAbsolutePath()); + } + } + + private static void _checkResponseStatus(HttpResponse httpResponse) throws IOException { + if (httpResponse.getCode() != HttpStatus.SC_OK) { + throw new IOException(httpResponse.getReasonPhrase()); + } + } + + private static Path _downloadFile( + CloseableHttpClient closeableHttpClient, URI uri, Path cacheDirPath, String targetFileName) + throws Exception { + + HttpHead httpHead = new HttpHead(uri); + + HttpContext httpContext = new BasicHttpContext(); + + Date lastModifiedDate; + + try (CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpHead, httpContext)) { + _checkResponseStatus(closeableHttpResponse); + + Header dispositionHeader = closeableHttpResponse.getFirstHeader("Content-Disposition"); + + if (dispositionHeader == null) { + RedirectLocations redirectLocations = (RedirectLocations)httpContext.getAttribute( + HttpClientContext.REDIRECT_LOCATIONS); + + if ((redirectLocations != null) && (redirectLocations.size() > 0)) { + uri = redirectLocations.get(redirectLocations.size() - 1); + } + } + + Header lastModifiedHeader = closeableHttpResponse.getFirstHeader(HttpHeaders.LAST_MODIFIED); + + if (lastModifiedHeader != null) { + lastModifiedDate = DateUtils.parseDate(lastModifiedHeader.getValue()); + } + else { + lastModifiedDate = new Date(); + } + } + + Files.createDirectories(cacheDirPath); + + Path targetPath = cacheDirPath.resolve(targetFileName); + + if (Files.exists(targetPath)) { + FileTime fileTime = Files.getLastModifiedTime(targetPath); + + if (fileTime.toMillis() == lastModifiedDate.getTime()) { + return targetPath; + } + + Files.delete(targetPath); + } + + HttpGet httpGet = new HttpGet(uri); + + try (CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpGet)) { + _checkResponseStatus(closeableHttpResponse); + + HttpEntity httpEntity = closeableHttpResponse.getEntity(); + + try (InputStream inputStream = httpEntity.getContent(); + OutputStream outputStream = Files.newOutputStream(targetPath)) { + + byte[] buffer = new byte[10 * 1024]; + int read = -1; + + while ((read = inputStream.read(buffer)) >= 0) { + outputStream.write(buffer, 0, read); + } + } + } + + Files.setLastModifiedTime(targetPath, FileTime.fromMillis(lastModifiedDate.getTime())); + + return targetPath; + } + + private static Path _downloadFile(String urlString, Path cacheDirPath, String targetFileName) throws Exception { + URL downladURL = new URL(urlString); + + URI downladURI = downladURL.toURI(); + + if (Objects.equals(downladURI.getScheme(), "file")) { + return Paths.get(downladURI); + } + + try (CloseableHttpClient closeableHttpClient = _getHttpClient(downladURL.toURI(), null, null)) { + return _downloadFile(closeableHttpClient, downladURI, cacheDirPath, targetFileName); + } + } + + private static CloseableHttpClient _getHttpClient(URI uri, String userName, String password) { + HttpClientBuilder httpClientBuilder = HttpClients.custom(); + + RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); + + requestConfigBuilder.setCookieSpec(RequestConfig.DEFAULT.getCookieSpec()); + requestConfigBuilder.setRedirectsEnabled(true); + + httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build()); + + String scheme = uri.getScheme(); + + String proxyHost = System.getProperty(scheme + ".proxyHost"); + String proxyPort = System.getProperty(scheme + ".proxyPort"); + + String proxyUser = userName; + + if (Objects.isNull(proxyUser)) { + proxyUser = System.getProperty(scheme + ".proxyUser"); + } + + String proxyPassword = password; + + if (Objects.isNull(proxyPassword)) { + proxyPassword = System.getProperty(scheme + ".proxyPassword"); + } + + if ((proxyUser != null) && (proxyPassword != null)) { + BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + + if ((proxyHost != null) && (proxyPort != null)) { + credentialsProvider.setCredentials( + new AuthScope(proxyHost, Integer.parseInt(proxyPort)), + new UsernamePasswordCredentials(proxyUser, proxyPassword.toCharArray())); + } + + httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); + } + else { + if ((proxyHost != null) && (proxyPort != null)) { + httpClientBuilder.setProxy(new HttpHost(proxyHost, Integer.parseInt(proxyPort))); + } + } + + httpClientBuilder.useSystemProperties(); + + return httpClientBuilder.build(); + } + + private static void _print(String message, Object... args) { + if (_trace) { + System.out.printf(message + "%n", args); + } + } + + private static T _withInputStream(Transformer transformer, Resolver... resolvers) { + InputStream inputStream1 = null; + + for (Resolver resolver : resolvers) { + try { + inputStream1 = resolver.resolve(); + } + catch (Exception exception) { + _print(exception.getMessage()); + } + + if (inputStream1 != null) { + break; + } + } + + if (inputStream1 == null) { + _print("Resource not found"); + + return null; + } + + try (InputStream inputStream2 = inputStream1) { + _print("Found resource"); + + return transformer.transform(inputStream2); + } + catch (Exception exception) { + throw new RuntimeException("Unable to read resource", exception); + } + } + + private static final ObjectMapper _objectMapper = new ObjectMapper(); + private static boolean _trace; + +} \ No newline at end of file diff --git a/cli/src/main/java/com/liferay/blade/cli/util/StringUtil.java b/cli/src/main/java/com/liferay/blade/cli/util/StringUtil.java index 3a2b466d8..fbc19ae4b 100644 --- a/cli/src/main/java/com/liferay/blade/cli/util/StringUtil.java +++ b/cli/src/main/java/com/liferay/blade/cli/util/StringUtil.java @@ -32,10 +32,8 @@ public static boolean equals(String s1, Object o) { } public static boolean isNullOrEmpty(String arg) { - boolean hasContent = Optional.of( + boolean hasContent = Optional.ofNullable( arg - ).filter( - s -> s != null ).map( String::trim ).filter( diff --git a/cli/src/test/java/com/liferay/blade/cli/BladeTest.java b/cli/src/test/java/com/liferay/blade/cli/BladeTest.java index 19f6c2514..ca81b39de 100644 --- a/cli/src/test/java/com/liferay/blade/cli/BladeTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/BladeTest.java @@ -6,6 +6,7 @@ package com.liferay.blade.cli; import com.liferay.blade.cli.command.BaseArgs; +import com.liferay.blade.cli.util.ReleaseUtil; import java.io.File; import java.io.IOException; @@ -18,6 +19,7 @@ import java.util.Objects; import java.util.Scanner; +import java.util.function.Predicate; import java.util.stream.Stream; /** @@ -25,12 +27,6 @@ */ public class BladeTest extends BladeCLI { - public static final String LIFERAY_VERSION_70 = "7.0"; - - public static final String LIFERAY_VERSION_71 = "7.1"; - - public static final String LIFERAY_VERSION_72 = "7.2"; - public static final String LIFERAY_VERSION_73 = "7.3"; public static final String LIFERAY_VERSION_741 = "7.4.1-1"; @@ -41,32 +37,70 @@ public class BladeTest extends BladeCLI { 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"; - - public static final String PRODUCT_VERSION_DXP_70 = "dxp-7.0-sp17"; - - public static final String PRODUCT_VERSION_DXP_71 = "dxp-7.1-sp7"; - - public static final String PRODUCT_VERSION_DXP_72 = "dxp-7.2-sp7"; - - public static final String PRODUCT_VERSION_DXP_73 = "dxp-7.3-u15"; - - public static final String PRODUCT_VERSION_DXP_74 = "dxp-7.4-u38"; + public static final String PRODUCT_VERSION_DXP_70 = getFirstProductKey( + _getProductPredicate( + "dxp" + ).and( + _getProductGroupVersionPredicate("7.0") + )); + + public static final String PRODUCT_VERSION_DXP_71 = getFirstProductKey( + _getProductPredicate( + "dxp" + ).and( + _getProductGroupVersionPredicate("7.1") + )); + + public static final String PRODUCT_VERSION_DXP_72 = getFirstProductKey( + _getProductPredicate( + "dxp" + ).and( + _getProductGroupVersionPredicate("7.2") + )); + + public static final String PRODUCT_VERSION_DXP_73 = getFirstProductKey( + _getProductPredicate( + "dxp" + ).and( + _getProductGroupVersionPredicate("7.3") + )); + + public static final String PRODUCT_VERSION_DXP_74 = getFirstProductKey( + _getProductPredicate( + "dxp" + ).and( + _getProductGroupVersionPredicate("7.4") + )); public static final String PRODUCT_VERSION_DXP_74_U72 = "dxp-7.4-u72"; - public static final String PRODUCT_VERSION_PORTAL_71 = "portal-7.1-ga4"; + public static final String PRODUCT_VERSION_PORTAL_73 = getFirstProductKey( + _getProductPredicate( + "portal" + ).and( + _getProductGroupVersionPredicate("7.3") + )); - public static final String PRODUCT_VERSION_PORTAL_73 = "portal-7.3-ga8"; + // Temporarily hard-coded due to an upstream issue with release metadata - public static final String PRODUCT_VERSION_PORTAL_74 = "portal-7.4-ga4"; + public static final String PRODUCT_VERSION_PORTAL_74 = "portal-7.4-ga107"; public static BladeTestBuilder builder() { return new BladeTestBuilder(); } + public static String getFirstProductKey(Predicate predicate) { + return ReleaseUtil.withReleaseEntriesStream( + releaseEntryStream -> releaseEntryStream.filter( + predicate + ).map( + ReleaseUtil.ReleaseEntry::getReleaseKey + ).findFirst( + ).orElse( + "" + )); + } + @Override public BladeSettings getBladeSettings() throws IOException { File settingsBaseDir = _getSettingsBaseDir(); @@ -227,6 +261,14 @@ protected BladeTest(PrintStream out, PrintStream err, InputStream in) { super(out, err, in); } + private static Predicate _getProductGroupVersionPredicate(String productGroupVersion) { + return releaseEntry -> Objects.equals(releaseEntry.getProductGroupVersion(), productGroupVersion); + } + + private static Predicate _getProductPredicate(String product) { + return releaseEntry -> Objects.equals(releaseEntry.getProduct(), product); + } + private File _getSettingsBaseDir() { BaseArgs args = getArgs(); diff --git a/cli/src/test/java/com/liferay/blade/cli/TestUtil.java b/cli/src/test/java/com/liferay/blade/cli/TestUtil.java index f45922f50..400222847 100644 --- a/cli/src/test/java/com/liferay/blade/cli/TestUtil.java +++ b/cli/src/test/java/com/liferay/blade/cli/TestUtil.java @@ -39,6 +39,23 @@ */ public class TestUtil { + public static void appendGradleProperty(File workspaceDir, String key, String value) throws Exception { + File gradleProperties = new File(workspaceDir, "gradle.properties"); + + Assert.assertTrue(gradleProperties.exists()); + + String propertyString = String.format("%n%s=%s", key, value); + + Files.write(gradleProperties.toPath(), propertyString.getBytes(), StandardOpenOption.APPEND); + } + + public static void increaseGradleMemory(File workspaceDir) throws Exception { + + // Increase maximum memory to fix issue with some 7zip bundles + + appendGradleProperty(workspaceDir, "org.gradle.jvmargs", "-Xmx8g"); + } + public static void removeComments(String projectPath) throws Exception { File pomXMLFile = new File(projectPath, "/pom.xml"); diff --git a/cli/src/test/java/com/liferay/blade/cli/UtilTest.java b/cli/src/test/java/com/liferay/blade/cli/UtilTest.java index 49aa02557..c5a02286e 100644 --- a/cli/src/test/java/com/liferay/blade/cli/UtilTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/UtilTest.java @@ -110,7 +110,9 @@ public void testMigrateBladeSettings() throws Exception { File extensionsDir = temporaryFolder.newFolder(".blade", "extensions"); - String[] args = {"--base", rootWorkspaceDir.getAbsolutePath(), "init", "-f", "foo", "-v", "dxp-7.2-ga1"}; + String[] args = { + "--base", rootWorkspaceDir.getAbsolutePath(), "init", "-f", "foo", "-v", BladeTest.PRODUCT_VERSION_DXP_72 + }; File workspaceDirectory = new File(rootWorkspaceDir, "foo"); @@ -161,7 +163,9 @@ public void testNewBladeSettings() throws Exception { File extensionsDir = temporaryFolder.newFolder(".blade", "extensions"); - String[] args = {"--base", rootWorkspaceDir.getAbsolutePath(), "init", "-f", "foo", "-v", "dxp-7.2-ga1"}; + String[] args = { + "--base", rootWorkspaceDir.getAbsolutePath(), "init", "-f", "foo", "-v", BladeTest.PRODUCT_VERSION_DXP_72 + }; File workspaceDirectory = new File(rootWorkspaceDir, "foo"); diff --git a/cli/src/test/java/com/liferay/blade/cli/command/CreateCommandTest.java b/cli/src/test/java/com/liferay/blade/cli/command/CreateCommandTest.java index d43acab3c..30419c004 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/CreateCommandTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/CreateCommandTest.java @@ -710,7 +710,7 @@ public void testCreateSimulationPanelEntry() throws Exception { _contains(componentFile, ".*^public class SimulatorSimulationPanelApp.*extends BaseJSPPanelApp.*$"); - _contains(componentFile, ".*public void setServletContext.*$"); + _contains(componentFile, ".*private ServletContext _servletContext;.*$"); _checkFileExists(projectPath + "/build.gradle"); } @@ -2073,18 +2073,6 @@ public void testWrongTemplateTyping() throws Exception { @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); - private void _addDefaultModulesDir(File workspace) throws Exception { - File gradleProperties = new File(workspace, "gradle.properties"); - - Assert.assertTrue(gradleProperties.exists()); - - String configLine = - System.lineSeparator() + WorkspaceConstants.DEFAULT_MODULES_DIR_PROPERTY + "=" + - WorkspaceConstants.DEFAULT_MODULES_DIR; - - Files.write(gradleProperties.toPath(), configLine.getBytes(), StandardOpenOption.APPEND); - } - private File _checkFileDoesNotExists(String path) { File file = new File(path); @@ -2129,6 +2117,16 @@ private void _checkGradleBuildFilesInWarProject(String projectPath) throws Excep _checkFileDoesNotExists(projectPath + "/bnd.bnd"); } + private void _configureGradleProperties(File workspace) throws Exception { + + // Set default modules dir + + TestUtil.appendGradleProperty( + workspace, WorkspaceConstants.DEFAULT_MODULES_DIR_PROPERTY, WorkspaceConstants.DEFAULT_MODULES_DIR); + + TestUtil.increaseGradleMemory(workspace); + } + private void _contains(File file, String pattern) throws Exception { String content = FileUtil.read(file); @@ -2189,7 +2187,7 @@ private void _makeWorkspace(File workspace) throws Exception { _checkFileExists(gradlewFile.getAbsolutePath()); - _addDefaultModulesDir(workspace); + _configureGradleProperties(workspace); } private void _makeWorkspaceVersion(File workspace, String version) throws Exception { @@ -2199,7 +2197,7 @@ private void _makeWorkspaceVersion(File workspace, String version) throws Except TestUtil.runBlade(workspace, _extensionsDir, args); - _addDefaultModulesDir(workspace); + _configureGradleProperties(workspace); } private void _resolveProject(BuildTask buildTask, String projectPath) throws Exception { diff --git a/cli/src/test/java/com/liferay/blade/cli/command/InitCommandTest.java b/cli/src/test/java/com/liferay/blade/cli/command/InitCommandTest.java index e6bcabf47..3d21aab8c 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/InitCommandTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/InitCommandTest.java @@ -10,6 +10,7 @@ import com.liferay.blade.cli.GradleRunnerUtil; import com.liferay.blade.cli.TestUtil; import com.liferay.blade.cli.util.FileUtil; +import com.liferay.blade.cli.util.ReleaseUtil; import java.io.ByteArrayInputStream; import java.io.File; @@ -306,9 +307,9 @@ public void testInitCommandListAll() throws Exception { String output = bladeTestResults.getOutput(); - Assert.assertTrue(output, output.contains("dxp-7.2-sp6")); + Assert.assertTrue(output, output.contains("dxp-2023.q4.6")); - Assert.assertTrue(output, output.contains("dxp-7.2-sp1")); + Assert.assertTrue(output, output.contains("dxp-7.4-u110")); Assert.assertTrue(output, output.contains("portal-7.0-ga7")); } @@ -317,7 +318,7 @@ public void testInitCommandListAll() throws Exception { public void testInitCommandListMoreOptions() throws Exception { String[] args = {"--base", _workspaceDir.getPath(), "init", "testworkspace"}; - String responses = "more" + System.lineSeparator() + "dxp-7.2-sp2" + System.lineSeparator(); + String responses = "more" + System.lineSeparator() + "dxp-7.2-dxp-5" + System.lineSeparator(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(responses.getBytes()); @@ -326,7 +327,7 @@ public void testInitCommandListMoreOptions() throws Exception { String output = bladeTestResults.getOutput(); - Assert.assertTrue(output, output.contains("dxp-7.3-ep4")); + Assert.assertTrue(output, output.contains("dxp-7.3-u34")); } @Test @@ -347,7 +348,7 @@ public void testInitCommandListPromoted() throws Exception { String firstLine = lines.get(0); - Assert.assertTrue(firstLine, firstLine.contains("dxp-7.4-")); + Assert.assertEquals(firstLine, BladeTest.getFirstProductKey(ReleaseUtil.ReleaseEntry::isPromoted)); } @Test @@ -402,82 +403,24 @@ public void testInitLegacyProductKey() throws Exception { TestUtil.runBlade(_workspaceDir, _extensionsDir, args); } - @Test - public void testInitWithCommerceProduct206() throws Exception { - String[] args = {"--base", _workspaceDir.getPath(), "init", "-v", BladeTest.PRODUCT_VERSION_COMMERCE_206}; - - TestUtil.runBlade(_workspaceDir, _extensionsDir, args); - - Path gradlePropertiesPath = _workspacePath.resolve("gradle.properties"); - - String contents = new String(Files.readAllBytes(gradlePropertiesPath)); - - Assert.assertTrue(contents, contents.contains("liferay.workspace.product=commerce-2.0.6")); - } - - @Test - public void testInitWithCommerceProduct207() throws Exception { - String[] args = {"--base", _workspaceDir.getPath(), "init", "-v", BladeTest.PRODUCT_VERSION_COMMERCE_207}; - - TestUtil.runBlade(_workspaceDir, _extensionsDir, args); - - Path gradlePropertiesPath = _workspacePath.resolve("gradle.properties"); - - String contents = new String(Files.readAllBytes(gradlePropertiesPath)); - - Assert.assertTrue(contents, contents.contains("liferay.workspace.product=commerce-2.0.7-7.2")); - } - @Test public void testInitWithLiferayVersion70() throws Exception { - String[] args = {"--base", _workspaceDir.getPath(), "init", "-v", BladeTest.PRODUCT_VERSION_DXP_70}; - - TestUtil.runBlade(_workspaceDir, _extensionsDir, args); - - Path gradlePropertiesPath = _workspacePath.resolve("gradle.properties"); - - String contents = new String(Files.readAllBytes(gradlePropertiesPath)); - - Assert.assertTrue(contents, contents.contains("liferay.workspace.product=dxp-7.0-sp17")); + _testInitWithLiferayVersion(BladeTest.PRODUCT_VERSION_DXP_70); } @Test public void testInitWithLiferayVersion71() throws Exception { - String[] args = {"--base", _workspaceDir.getPath(), "init", "-v", BladeTest.PRODUCT_VERSION_DXP_71}; - - TestUtil.runBlade(_workspaceDir, _extensionsDir, args); - - Path gradlePropertiesPath = _workspacePath.resolve("gradle.properties"); - - String contents = new String(Files.readAllBytes(gradlePropertiesPath)); - - Assert.assertTrue(contents, contents.contains("liferay.workspace.product=dxp-7.1-sp7")); + _testInitWithLiferayVersion(BladeTest.PRODUCT_VERSION_DXP_71); } @Test public void testInitWithLiferayVersion72() throws Exception { - String[] args = {"--base", _workspaceDir.getPath(), "init", "-v", BladeTest.PRODUCT_VERSION_DXP_72}; - - TestUtil.runBlade(_workspaceDir, _extensionsDir, args); - - Path gradlePropertiesPath = _workspacePath.resolve("gradle.properties"); - - String contents = new String(Files.readAllBytes(gradlePropertiesPath)); - - Assert.assertTrue(contents, contents.contains("liferay.workspace.product=dxp-7.2-sp7")); + _testInitWithLiferayVersion(BladeTest.PRODUCT_VERSION_DXP_72); } @Test public void testInitWithLiferayVersion73() throws Exception { - String[] args = {"--base", _workspaceDir.getPath(), "init", "-v", BladeTest.PRODUCT_VERSION_PORTAL_73}; - - TestUtil.runBlade(_workspaceDir, _extensionsDir, args); - - Path gradlePropertiesPath = _workspacePath.resolve("gradle.properties"); - - String contents = new String(Files.readAllBytes(gradlePropertiesPath)); - - Assert.assertTrue(contents, contents.contains("liferay.workspace.product=portal-7.3-ga8")); + _testInitWithLiferayVersion(BladeTest.PRODUCT_VERSION_PORTAL_73); } @Test(expected = AssertionError.class) @@ -513,9 +456,7 @@ public void testInitWithNameWorkspaceDirectoryEmpty() throws Exception { String contents = new String(Files.readAllBytes(settingsGradlePath)); - boolean contentContainsVersion = contents.contains(_GRADLE_PLUGINS_WORKSPACE_VERSION); - - if (!contentContainsVersion) { + if (!contents.contains(_GRADLE_PLUGINS_WORKSPACE_VERSION)) { StringBuilder sb = new StringBuilder("Error checking com.liferay.gradle.plugins.workspace version."); sb.append(System.lineSeparator()); @@ -654,6 +595,18 @@ private void _makeSDK(File dir) throws Exception { Assert.assertTrue(Files.exists(buildCommonPluginXmlPath)); } + private void _testInitWithLiferayVersion(String liferayVersion) throws Exception { + String[] args = {"--base", _workspaceDir.getPath(), "init", "-v", liferayVersion}; + + TestUtil.runBlade(_workspaceDir, _extensionsDir, args); + + Path gradlePropertiesPath = _workspacePath.resolve("gradle.properties"); + + String contents = new String(Files.readAllBytes(gradlePropertiesPath)); + + Assert.assertTrue(contents, contents.contains(String.format("liferay.workspace.product=%s", liferayVersion))); + } + private void _verifyGradleBuild() throws Exception { _createBundle(); @@ -668,7 +621,7 @@ private void _verifyGradleBuild() throws Exception { GradleRunnerUtil.verifyBuildOutput(projectPath.toString(), "foo-1.0.0.jar"); } - private static final String _GRADLE_PLUGINS_WORKSPACE_VERSION = "9.0.12"; + private static final String _GRADLE_PLUGINS_WORKSPACE_VERSION = "10.0.3"; private File _extensionsDir = null; private File _workspaceDir = null; diff --git a/cli/src/test/java/com/liferay/blade/cli/command/JavaProcesses.java b/cli/src/test/java/com/liferay/blade/cli/command/JavaProcesses.java index 2202b35ab..bbeaba075 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/JavaProcesses.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/JavaProcesses.java @@ -179,10 +179,11 @@ public static void main(String[] args) { tomcatFilter ).findAny(); - System.out.println( - "tomcatProcess = " + - tomcatProcess.get( - ).getId()); + tomcatProcess.map( + JavaProcess::getId + ).ifPresent( + System.out::println + ); } public static int maxProcessId() { diff --git a/cli/src/test/java/com/liferay/blade/cli/command/SamplesCommandTest.java b/cli/src/test/java/com/liferay/blade/cli/command/SamplesCommandTest.java index 88174a77e..33746c28e 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/SamplesCommandTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/SamplesCommandTest.java @@ -22,6 +22,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -48,6 +49,7 @@ public void setUp() throws Exception { _extensionsDir = temporaryFolder.newFolder(".blade", "extensions"); } + @Ignore @Test public void testGetSample() throws Exception { File root = temporaryFolder.newFolder("samplesroot"); @@ -167,6 +169,7 @@ public void testGetSampleMaven72() throws Exception { Assert.assertTrue(content, content.contains("com.liferay.portal.kernel")); } + @Ignore @Test public void testGetSampleWithDependencies() throws Exception { File root = temporaryFolder.getRoot(); @@ -190,6 +193,7 @@ public void testGetSampleWithDependencies() throws Exception { TestUtil.verifyBuild(projectPath, "com.liferay.blade.rest-1.0.0.jar"); } + @Ignore @Test public void testGetSampleWithGradleWrapper() throws Exception { File root = temporaryFolder.getRoot(); @@ -268,6 +272,7 @@ public void testGetSampleWithGradleWrapperExisting() throws Exception { GradleRunnerUtil.verifyBuildOutput(projectDir.toString(), "com.liferay.blade.auth.failure-1.0.0.jar"); } + @Ignore @Test public void testGetSampleWithVersion70() throws Exception { File root = temporaryFolder.getRoot(); @@ -295,6 +300,7 @@ public void testGetSampleWithVersion70() throws Exception { TestUtil.verifyBuild(projectPath, "com.liferay.blade.jsp.portlet-1.0.0.jar"); } + @Ignore @Test public void testGetSampleWithVersion71() throws Exception { File root = temporaryFolder.getRoot(); diff --git a/cli/src/test/java/com/liferay/blade/cli/command/ServerStartCommandTest.java b/cli/src/test/java/com/liferay/blade/cli/command/ServerStartCommandTest.java index 91897a25f..cd8e273bd 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/ServerStartCommandTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/ServerStartCommandTest.java @@ -5,7 +5,6 @@ package com.liferay.blade.cli.command; -import com.liferay.blade.cli.BladeTest; import com.liferay.blade.cli.TestUtil; import com.liferay.blade.cli.util.FileUtil; @@ -500,11 +499,11 @@ private String[] _getDebugArgs(String[] serverStartArgs) { } private void _initBladeWorkspace() throws Exception { - String[] initArgs = { - "--base", _testWorkspacePath.toString(), "init", "-v", BladeTest.PRODUCT_VERSION_PORTAL_71 - }; + String[] initArgs = {"--base", _testWorkspacePath.toString(), "init", "-v", _LIFERAY_WORKSPACE_PRODUCT_KEY}; TestUtil.runBlade(_testWorkspacePath, _extensionsPath, initArgs); + + TestUtil.increaseGradleMemory(_testWorkspacePath.toFile()); } private void _initServerBundle(String... additionalArgs) throws Exception { @@ -733,6 +732,8 @@ private void _verifyWildflyBundlePath() { private static final String _LIFERAY_WORKSPACE_BUNDLE_WILDFLY = "liferay-ce-portal-wildfly-7.1.1-ga2-20181112144637000.tar.gz"; + private static final String _LIFERAY_WORKSPACE_PRODUCT_KEY = "portal-7.1-ga2"; + private int _debugPort = -1; private ExecutorService _executorService = Executors.newSingleThreadExecutor(); private Path _extensionsPath = null; diff --git a/cli/src/test/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidatorTest.java b/cli/src/test/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidatorTest.java index 9cec6d28c..2c3f78d12 100644 --- a/cli/src/test/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidatorTest.java +++ b/cli/src/test/java/com/liferay/blade/cli/command/validator/LiferayMoreVersionValidatorTest.java @@ -5,12 +5,9 @@ package com.liferay.blade.cli.command.validator; -import com.liferay.blade.cli.util.FileUtil; -import com.liferay.blade.cli.util.ProductKeyUtil; +import com.liferay.blade.cli.util.ReleaseUtil; -import java.util.ArrayList; import java.util.List; -import java.util.Scanner; import java.util.stream.Collectors; import org.junit.Assert; @@ -22,62 +19,26 @@ public class LiferayMoreVersionValidatorTest { @Test - public void testSort() throws Exception { + public void testGet() throws Exception { + List expectedReleaseKeys = ReleaseUtil.withReleaseEntriesStream( + releaseEntryStream -> releaseEntryStream.map( + ReleaseUtil.ReleaseEntry::getReleaseKey + ).collect( + Collectors.toList() + )); + LiferayMoreVersionValidator lmvv = new LiferayMoreVersionValidator(); List vals = lmvv.get(); - String first = vals.get(0); - - Assert.assertTrue(first, first.startsWith("dxp")); - - String second = vals.get(1); - - Assert.assertTrue(second, second.startsWith("dxp")); - - String last = vals.get(vals.size() - 1); - - Assert.assertTrue(last, last.startsWith("commerce")); - } - - @Test - public void testWithRandom() throws Exception { - List randomLines = new ArrayList<>(); - - try (Scanner scanner = new Scanner( - FileUtil.collect(LiferayMoreVersionValidatorTest.class.getResourceAsStream("random.txt")))) { - - while (scanner.hasNextLine()) { - randomLines.add(scanner.nextLine()); - } - } - - List sortedLines = new ArrayList<>(); + Assert.assertEquals(vals.toString(), expectedReleaseKeys.size(), vals.size()); - try (Scanner scanner = new Scanner( - FileUtil.collect(LiferayMoreVersionValidatorTest.class.getResourceAsStream("sorted.txt")))) { + for (int i = 0; i < expectedReleaseKeys.size(); i++) { + String actual = vals.get(i); + String expected = expectedReleaseKeys.get(i); - while (scanner.hasNextLine()) { - sortedLines.add(scanner.nextLine()); - } + Assert.assertEquals(expected, actual); } - - List sorted = randomLines.stream( - ).sorted( - ProductKeyUtil.comparator - ).collect( - Collectors.toList() - ); - - Assert.assertEquals( - sortedLines.stream( - ).collect( - Collectors.joining(System.lineSeparator()) - ), - sorted.stream( - ).collect( - Collectors.joining(System.lineSeparator()) - )); } } \ No newline at end of file diff --git a/cli/src/test/java/com/liferay/blade/cli/util/ProductKeyUtilTest.java b/cli/src/test/java/com/liferay/blade/cli/util/ProductKeyUtilTest.java deleted file mode 100644 index 0dc4c22da..000000000 --- a/cli/src/test/java/com/liferay/blade/cli/util/ProductKeyUtilTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com - * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 - */ - -package com.liferay.blade.cli.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author Gregory Amerson - * @author Drew Brokke - */ -public class ProductKeyUtilTest { - - @Test - public void testComparator() throws Exception { - List expectedKeys = Arrays.asList( - "dxp-2023.q3.2", "dxp-2023.q2.1", "dxp-2022.q3.1", "dxp-7.2-sp3", "dxp-7.2-sp2", "dxp-7.2-sp1", - "portal-7.3-ga1", "portal-7.1-ga2", "portal-7.1-ga1", "commerce-2.0.7-7.2", "commerce-2.0.7-7.1", - "commerce-2.0.6"); - - List actualKeys = new ArrayList<>(expectedKeys); - - actualKeys.sort(null); - - actualKeys.sort(ProductKeyUtil.comparator); - - Assert.assertEquals( - expectedKeys.stream( - ).collect( - Collectors.joining(System.lineSeparator()) - ), - actualKeys.stream( - ).collect( - Collectors.joining(System.lineSeparator()) - )); - } - -} \ No newline at end of file diff --git a/cli/src/test/resources/com/liferay/blade/cli/command/validator/random.txt b/cli/src/test/resources/com/liferay/blade/cli/command/validator/random.txt deleted file mode 100644 index 9c2c735f0..000000000 --- a/cli/src/test/resources/com/liferay/blade/cli/command/validator/random.txt +++ /dev/null @@ -1,59 +0,0 @@ -dxp-2023.q2.1 -dxp-7.0-sp8 -commerce-2.0.7-7.2 -dxp-7.0-sp10 -dxp-2023.q1.1 -portal-7.3-ga3 -dxp-7.1-sp2 -commerce-2.0.7-7.1 -portal-7.3-ga2 -dxp-2023.q2.2 -commerce-2.0.2 -dxp-7.0-sp5 -dxp-7.2-ga1 -dxp-7.0-sp13 -portal-7.2-ga1 -dxp-7.0-sp6 -dxp-7.2-sp1 -commerce-1.1.2 -commerce-1.1.3 -portal-7.1-ga4 -dxp-7.0-sp3 -portal-7.0-ga5 -dxp-2024.q1.10 -commerce-2.0.5 -commerce-2.0.6 -commerce-1.1.4 -dxp-7.0-sp11 -dxp-7.0-ga1 -portal-7.0-ga3 -dxp-7.0-sp12 -dxp-7.1-sp4 -portal-7.3-ga1 -commerce-1.0.2 -commerce-2.0.4 -commerce-2.0.1 -dxp-7.0-sp9 -dxp-2024.q1.2 -commerce-2.0.7 -portal-7.2-ga2 -commerce-1.1.6 -dxp-7.0-sp2 -dxp-7.1-sp3 -dxp-7.1-sp1 -commerce-1.1.0 -portal-7.1-ga2 -portal-7.0-ga7 -dxp-7.0-sp4 -commerce-1.1.5 -portal-7.0-ga4 -dxp-7.1-ga1 -dxp-7.0-sp7 -portal-7.1-ga3 -portal-7.0-ga2 -commerce-2.0.3 -commerce-2.0.0 -portal-7.0-ga6 -portal-7.1-ga1 -dxp-7.0-sp1 -commerce-1.1.1 \ No newline at end of file diff --git a/cli/src/test/resources/com/liferay/blade/cli/command/validator/sorted.txt b/cli/src/test/resources/com/liferay/blade/cli/command/validator/sorted.txt deleted file mode 100644 index add45002b..000000000 --- a/cli/src/test/resources/com/liferay/blade/cli/command/validator/sorted.txt +++ /dev/null @@ -1,59 +0,0 @@ -dxp-2024.q1.10 -dxp-2024.q1.2 -dxp-2023.q2.2 -dxp-2023.q2.1 -dxp-2023.q1.1 -dxp-7.2-sp1 -dxp-7.2-ga1 -dxp-7.1-sp4 -dxp-7.1-sp3 -dxp-7.1-sp2 -dxp-7.1-sp1 -dxp-7.1-ga1 -dxp-7.0-sp13 -dxp-7.0-sp12 -dxp-7.0-sp11 -dxp-7.0-sp10 -dxp-7.0-sp9 -dxp-7.0-sp8 -dxp-7.0-sp7 -dxp-7.0-sp6 -dxp-7.0-sp5 -dxp-7.0-sp4 -dxp-7.0-sp3 -dxp-7.0-sp2 -dxp-7.0-sp1 -dxp-7.0-ga1 -portal-7.3-ga3 -portal-7.3-ga2 -portal-7.3-ga1 -portal-7.2-ga2 -portal-7.2-ga1 -portal-7.1-ga4 -portal-7.1-ga3 -portal-7.1-ga2 -portal-7.1-ga1 -portal-7.0-ga7 -portal-7.0-ga6 -portal-7.0-ga5 -portal-7.0-ga4 -portal-7.0-ga3 -portal-7.0-ga2 -commerce-2.0.7-7.2 -commerce-2.0.7-7.1 -commerce-2.0.7 -commerce-2.0.6 -commerce-2.0.5 -commerce-2.0.4 -commerce-2.0.3 -commerce-2.0.2 -commerce-2.0.1 -commerce-2.0.0 -commerce-1.1.6 -commerce-1.1.5 -commerce-1.1.4 -commerce-1.1.3 -commerce-1.1.2 -commerce-1.1.1 -commerce-1.1.0 -commerce-1.0.2 \ No newline at end of file diff --git a/extensions/maven-profile/build.gradle b/extensions/maven-profile/build.gradle index e7caba951..d7349b4da 100644 --- a/extensions/maven-profile/build.gradle +++ b/extensions/maven-profile/build.gradle @@ -23,7 +23,7 @@ apply plugin: "maven-publish" dependencies { compileOnly group: "com.beust", name: "jcommander", version: "1.82" - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" + compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.134" compileOnly project(":cli") testImplementation gradleTestKit() diff --git a/extensions/project-templates-activator/build.gradle b/extensions/project-templates-activator/build.gradle index 104ef1a26..de9d318a0 100644 --- a/extensions/project-templates-activator/build.gradle +++ b/extensions/project-templates-activator/build.gradle @@ -21,7 +21,7 @@ apply plugin: "java" apply plugin: "maven-publish" dependencies { - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" + compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.134" compileOnly group: "org.apache.maven.archetype", name: "archetype-common", version: "2.4" compileOnly project(":cli") } diff --git a/extensions/project-templates-client-extension/bnd.bnd b/extensions/project-templates-client-extension/bnd.bnd deleted file mode 100644 index 11770c1f3..000000000 --- a/extensions/project-templates-client-extension/bnd.bnd +++ /dev/null @@ -1,9 +0,0 @@ -Bundle-Description: Creates a Client Extension project -Bundle-Name: Liferay Project Templates Client Extension -Bundle-SymbolicName: com.liferay.project.templates.client.extension -Bundle-Version: ${project.version} -Liferay-Versions: [7,8) --removeheaders:\ - Import-Package,\ - Private-Package,\ - Require-Capability \ No newline at end of file diff --git a/extensions/project-templates-client-extension/build.gradle b/extensions/project-templates-client-extension/build.gradle deleted file mode 100644 index f3efdf687..000000000 --- a/extensions/project-templates-client-extension/build.gradle +++ /dev/null @@ -1,62 +0,0 @@ -buildscript { - dependencies { - classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd.gradle", version: "5.3.0" - } - - repositories { - maven { - if (project.hasProperty("release")) { - url "https://repository.liferay.com/nexus/content/groups/public" - } - else { - url "https://repository-cdn.liferay.com/nexus/content/groups/public" - } - } - } -} - -apply plugin: "biz.aQute.bnd.builder" -apply plugin: "java-library" -apply plugin: "maven-publish" - -dependencies { - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" - compileOnly group: "org.apache.maven.archetype", name: "archetype-common", version: "2.4" - compileOnly project(":cli") - - testImplementation gradleTestKit() - testImplementation group: "junit", name: "junit", version: "4.13.1" - testImplementation project(":cli") - 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") -} - -publishing { - publications { - mavenProfileJar(MavenPublication) { - artifactId = jar.baseName - - from components.java - } - } -} - -test { - dependsOn jar - - doFirst { - systemProperty 'clientExtensionTemplateJarFile', jar.archivePath - } -} - -version = "1.0.6-SNAPSHOT" \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/ClientExtensionProjectTemplateCustomizer.java b/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/ClientExtensionProjectTemplateCustomizer.java deleted file mode 100644 index f9b511998..000000000 --- a/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/ClientExtensionProjectTemplateCustomizer.java +++ /dev/null @@ -1,189 +0,0 @@ -/** - * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com - * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 - */ - -package com.liferay.project.templates.client.extension.internal; - -import com.liferay.blade.cli.WorkspaceConstants; -import com.liferay.blade.cli.gradle.GradleWorkspaceProvider; -import com.liferay.blade.cli.util.BladeUtil; -import com.liferay.blade.cli.util.ProductInfo; -import com.liferay.project.templates.extensions.ProjectTemplateCustomizer; -import com.liferay.project.templates.extensions.ProjectTemplatesArgs; - -import java.io.File; -import java.io.IOException; - -import java.nio.file.Files; -import java.nio.file.Path; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import org.apache.maven.archetype.ArchetypeGenerationRequest; -import org.apache.maven.archetype.ArchetypeGenerationResult; - -import org.json.JSONObject; - -import org.jsoup.Jsoup; -import org.jsoup.parser.Parser; - -/** - * @author Gregory Amerson - */ -public class ClientExtensionProjectTemplateCustomizer implements ProjectTemplateCustomizer { - - public static Optional getExtensionMetadataFile(File destinationDir) throws IOException { - GradleWorkspaceProvider gradleWorkspaceProvider = new GradleWorkspaceProvider(); - - if (gradleWorkspaceProvider.isWorkspace(destinationDir)) { - File workspaceDir = gradleWorkspaceProvider.getWorkspaceDir(destinationDir); - - String product = gradleWorkspaceProvider.getProduct(workspaceDir); - - return Optional.ofNullable( - gradleWorkspaceProvider.getGradleProperties(workspaceDir) - ).map( - properties -> properties.getProperty(WorkspaceConstants.DEFAULT_WORKSPACE_PRODUCT_PROPERTY) - ).map( - ClientExtensionProjectTemplateCustomizer::_getTargetPlatformVersionFromProduct - ).map( - targetPlatformVersion -> - _BASE_BOM_URL + "release." + product + ".bom/" + targetPlatformVersion + "/release." + product + - ".bom-" + targetPlatformVersion + ".pom" - ).map( - ClientExtensionProjectTemplateCustomizer::_getCETAPIJarFromBom - ); - } - - return Optional.empty(); - } - - @Override - public String getTemplateName() { - return "client-extension"; - } - - @Override - public void onAfterGenerateProject( - ProjectTemplatesArgs projectTemplatesArgs, File destinationDir, - ArchetypeGenerationResult archetypeGenerationResult) - throws Exception { - } - - @Override - public void onBeforeGenerateProject( - ProjectTemplatesArgs projectTemplatesArgs, ArchetypeGenerationRequest archetypeGenerationRequest) - throws Exception { - - String projectName = projectTemplatesArgs.getName(); - - List args = new ArrayList<>(); - - args.add("generate"); - args.add("-i"); - args.add(projectName); - - ClientExtensionProjectTemplatesArgsExt clientExtensionTemplateExt = - (ClientExtensionProjectTemplatesArgsExt)projectTemplatesArgs.getProjectTemplatesArgsExt(); - - String extensionName = clientExtensionTemplateExt.getExtensionName(); - - if (extensionName != null) { - args.add("-n"); - args.add(extensionName); - } - - String extensionType = clientExtensionTemplateExt.getExtensionType(); - - if (extensionType != null) { - args.add("-t"); - args.add(extensionType); - } - - File destinationDir = projectTemplatesArgs.getDestinationDir(); - - Optional extensionMetadataFile = getExtensionMetadataFile(destinationDir); - - LXCUtil.run( - destinationDir.toPath(), args.toArray(new String[0]), - extensionMetadataFile.map( - value -> Collections.singletonMap("EXTENSION_METADATA_FILE", value) - ).orElse( - Collections.emptyMap() - ), - false); - } - - private static String _getCETAPIJarFromBom(String bomUrl) { - try { - String version = Jsoup.connect( - bomUrl - ).parser( - Parser.xmlParser() - ).get( - ).select( - "artifactId:contains(com.liferay.client.extension.type.api)" - ).last( - ).parent( - ).select( - "version" - ).last( - ).text(); - - return "https://repository-cdn.liferay.com/nexus/service/local/repositories/liferay-public-releases" + - "/content/com/liferay/com.liferay.client.extension.type.api/" + version + - "/com.liferay.client.extension.type.api-" + version + ".jar"; - } - catch (Exception exception) { - return null; - } - } - - @SuppressWarnings("unchecked") - private static String _getTargetPlatformVersionFromProduct(String productKey) { - try { - File userHomeDir = new File(System.getProperty("user.home")); - - userHomeDir = userHomeDir.getCanonicalFile(); - - Path userHomePath = userHomeDir.toPath(); - - Path productInfoPath = userHomePath.resolve(".liferay/workspace/.product_info.json"); - - if (!Files.exists(productInfoPath)) { - Map productInfos = BladeUtil.getProductInfos(); - - ProductInfo productInfo = new ProductInfo((Map)productInfos.get(productKey)); - - return productInfo.getTargetPlatformVersion(); - } - - JSONObject jsonObject = new JSONObject(new String(Files.readAllBytes(productInfoPath.normalize()))); - - return Optional.ofNullable( - jsonObject.get(productKey) - ).map( - JSONObject.class::cast - ).map( - info -> info.get("targetPlatformVersion") - ).map( - Object::toString - ).orElse( - null - ); - } - catch (Exception exception) { - } - - return null; - } - - private static final String _BASE_BOM_URL = - "https://repository.liferay.com/nexus/content/groups/public/com/liferay/portal/"; - -} \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/ClientExtensionProjectTemplatesArgsExt.java b/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/ClientExtensionProjectTemplatesArgsExt.java deleted file mode 100644 index a7709c047..000000000 --- a/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/ClientExtensionProjectTemplatesArgsExt.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com - * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 - */ - -package com.liferay.project.templates.client.extension.internal; - -import com.liferay.project.templates.extensions.ProjectTemplatesArgsExt; - -/** - * @author Gregory Amerson - */ -public class ClientExtensionProjectTemplatesArgsExt implements ProjectTemplatesArgsExt { - - public String getExtensionName() { - return _extensionName; - } - - public String getExtensionType() { - return _extensionType; - } - - @Override - public String getTemplateName() { - return "client-extension"; - } - - public void setExtensionName(String extensionName) { - _extensionName = extensionName; - } - - public void setExtensionType(String extensionType) { - _extensionType = extensionType; - } - - private String _extensionName = null; - private String _extensionType = null; - -} \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/LXCUtil.java b/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/LXCUtil.java deleted file mode 100644 index aa35dddba..000000000 --- a/extensions/project-templates-client-extension/src/main/java/com/liferay/project/templates/client/extension/internal/LXCUtil.java +++ /dev/null @@ -1,238 +0,0 @@ -/** - * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com - * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 - */ - -package com.liferay.project.templates.client.extension.internal; - -import com.liferay.blade.cli.util.BladeUtil; -import com.liferay.blade.cli.util.FileUtil; -import com.liferay.blade.cli.util.OSDetector; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import java.math.BigInteger; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.nio.file.attribute.PosixFilePermissions; - -import java.security.MessageDigest; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Stream; - -/** - * @author Gregory Amerson - */ -public class LXCUtil { - - public static Path downloadLxc() throws Exception { - Path bladeCachePath = BladeUtil.getBladeCachePath(); - - String lxcURL = _getLxcURL(); - - String lxcFileName = lxcURL.substring(lxcURL.lastIndexOf("/") + 1); - - Path lxcDownloadPath = bladeCachePath.resolve(lxcFileName); - - Path lxcDirPath = bladeCachePath.resolve("lxc"); - - String lxcChecksumURL = lxcURL + ".checksum"; - - String checksumFileName = lxcChecksumURL.substring(lxcChecksumURL.lastIndexOf("/") + 1); - - Path checksumDownloadPath = BladeUtil.downloadFile(lxcChecksumURL, bladeCachePath, checksumFileName); - - if (Files.exists(lxcDirPath) && Files.exists(checksumDownloadPath) && Files.exists(lxcDownloadPath) && - !_validChecksum(checksumDownloadPath, lxcDownloadPath)) { - - Files.delete(checksumDownloadPath); - Files.delete(lxcDownloadPath); - FileUtil.deleteDir(lxcDirPath); - } - - if (!Files.exists(lxcDirPath) || !_containsFiles(lxcDirPath) || !Files.exists(checksumDownloadPath) || - !Files.exists(lxcDownloadPath)) { - - Files.createDirectories(lxcDirPath); - - checksumDownloadPath = BladeUtil.downloadFile(lxcChecksumURL, bladeCachePath, checksumFileName); - - lxcDownloadPath = BladeUtil.downloadFile(lxcURL, bladeCachePath, lxcFileName); - - if (!_validChecksum(checksumDownloadPath, lxcDownloadPath)) { - Files.delete(checksumDownloadPath); - Files.delete(lxcDownloadPath); - FileUtil.deleteDir(lxcDirPath); - - throw new IOException("Downloaded checksum failed, please try again"); - } - - FileUtil.unpack(lxcDownloadPath, lxcDirPath, 1); - - if (OSDetector.isWindows()) { - Path lxcPath; - - try (Stream paths = Files.list(lxcDirPath)) { - Optional findFirst = paths.findFirst(); - - lxcPath = findFirst.get(); - } - - try (Stream paths = Files.list(lxcPath)) { - paths.forEach( - path -> { - try { - Files.move( - path, lxcDirPath.resolve(path.getFileName()), StandardCopyOption.REPLACE_EXISTING); - } - catch (IOException ioException) { - throw new RuntimeException(ioException); - } - }); - } - - Files.delete(lxcPath); - } - else { - Files.setPosixFilePermissions(lxcDirPath.resolve("lxc"), PosixFilePermissions.fromString("rwxrwxr--")); - Files.setPosixFilePermissions(lxcDirPath.resolve("lxc"), PosixFilePermissions.fromString("rwxrwxr--")); - } - } - - return lxcDirPath.resolve("lxc"); - } - - public static int run(Path dir, String[] args, Map env, boolean quiet) throws Exception { - Path lxcPath = downloadLxc(); - - ProcessBuilder processBuilder = new ProcessBuilder(); - - processBuilder.directory(dir.toFile()); - - List commands = new ArrayList<>(); - - if (OSDetector.isWindows()) { - commands.add("cmd.exe"); - commands.add("/c"); - commands.add(lxcPath.toString()); - - for (String arg : args) { - commands.add(arg); - } - } - else { - commands.add("sh"); - commands.add("-c"); - - StringBuilder command = new StringBuilder(); - - command.append("\""); - command.append(lxcPath.toString()); - command.append("\" "); - - for (String arg : args) { - command.append("\""); - command.append(arg); - command.append("\" "); - } - - commands.add(command.toString()); - } - - processBuilder.command(commands); - - if (!quiet) { - processBuilder.inheritIO(); - } - - if ((dir != null) && Files.exists(dir)) { - processBuilder.directory(dir.toFile()); - } - - env.forEach(processBuilder.environment()::put); - - Process process = processBuilder.start(); - - OutputStream outputStream = process.getOutputStream(); - - outputStream.close(); - - return process.waitFor(); - } - - private static boolean _containsFiles(Path path) throws Exception { - try (Stream files = Files.list(path)) { - if (files.count() > 0) { - return true; - } - - return false; - } - } - - private static String _createSha256(File file) throws Exception { - MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); - - try (InputStream fileInputStream = new FileInputStream(file)) { - byte[] buffer = new byte[8192]; - int read = 0; - - while (read != -1) { - read = fileInputStream.read(buffer); - - if (read > 0) { - messageDigest.update(buffer, 0, read); - } - } - } - - BigInteger bigInteger = new BigInteger(1, messageDigest.digest()); - - return bigInteger.toString(16); - } - - private static String _getLxcURL() { - StringBuilder sb = new StringBuilder(); - - sb.append("https://github.com/ipeychev/lxc-cli-release/releases/download/"); - sb.append(_lxcVersion); - sb.append("/lxc-"); - - String os = "linux"; - - if (OSDetector.isApple()) { - os = "macos"; - } - else if (OSDetector.isWindows()) { - os = "win"; - } - - sb.append(os); - sb.append(".tgz"); - - return sb.toString(); - } - - private static boolean _validChecksum(Path checksumPath, Path downloadPath) throws Exception { - String content = FileUtil.read(checksumPath.toFile()); - - String checksum = content.trim(); - - String sha256 = _createSha256(downloadPath.toFile()); - - return checksum.equals(sha256); - } - - private static String _lxcVersion = "0.0.6"; - -} \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/main/resources/META-INF/archetype-post-generate.groovy b/extensions/project-templates-client-extension/src/main/resources/META-INF/archetype-post-generate.groovy deleted file mode 100644 index eead1e6f5..000000000 --- a/extensions/project-templates-client-extension/src/main/resources/META-INF/archetype-post-generate.groovy +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2000-present Liferay, Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - */ - -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -Path projectPath = Paths.get(request.outputDirectory, request.artifactId) - -Path buildGradlePath = projectPath.resolve("build.gradle") - -Files.deleteIfExists buildGradlePath \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/main/resources/META-INF/maven/archetype-metadata.xml b/extensions/project-templates-client-extension/src/main/resources/META-INF/maven/archetype-metadata.xml deleted file mode 100644 index 92373f1a5..000000000 --- a/extensions/project-templates-client-extension/src/main/resources/META-INF/maven/archetype-metadata.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - .gitignore - - - - - - maven - - - - - \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/main/resources/META-INF/services/com.liferay.project.templates.extensions.ProjectTemplateCustomizer b/extensions/project-templates-client-extension/src/main/resources/META-INF/services/com.liferay.project.templates.extensions.ProjectTemplateCustomizer deleted file mode 100644 index 6265ae3b0..000000000 --- a/extensions/project-templates-client-extension/src/main/resources/META-INF/services/com.liferay.project.templates.extensions.ProjectTemplateCustomizer +++ /dev/null @@ -1 +0,0 @@ -com.liferay.project.templates.client.extension.internal.ClientExtensionProjectTemplateCustomizer \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/main/resources/META-INF/services/com.liferay.project.templates.extensions.ProjectTemplatesArgsExt b/extensions/project-templates-client-extension/src/main/resources/META-INF/services/com.liferay.project.templates.extensions.ProjectTemplatesArgsExt deleted file mode 100644 index 8ab254f7b..000000000 --- a/extensions/project-templates-client-extension/src/main/resources/META-INF/services/com.liferay.project.templates.extensions.ProjectTemplatesArgsExt +++ /dev/null @@ -1 +0,0 @@ -com.liferay.project.templates.client.extension.internal.ClientExtensionProjectTemplatesArgsExt \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/main/resources/archetype-resources/gitignore b/extensions/project-templates-client-extension/src/main/resources/archetype-resources/gitignore deleted file mode 100644 index ea3c529c7..000000000 --- a/extensions/project-templates-client-extension/src/main/resources/archetype-resources/gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.gradle/ -build/ -dist/ -target/ \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/main/resources/archetype-resources/pom.xml b/extensions/project-templates-client-extension/src/main/resources/archetype-resources/pom.xml deleted file mode 100644 index db0bb2e6d..000000000 --- a/extensions/project-templates-client-extension/src/main/resources/archetype-resources/pom.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - 4.0.0 - ${groupId} - ${artifactId} - ${version} - - \ No newline at end of file diff --git a/extensions/project-templates-client-extension/src/test/java/com/liferay/project/templates/client/extension/ClientExtensionProjectTemplateTest.java b/extensions/project-templates-client-extension/src/test/java/com/liferay/project/templates/client/extension/ClientExtensionProjectTemplateTest.java deleted file mode 100644 index 3bb4fdd76..000000000 --- a/extensions/project-templates-client-extension/src/test/java/com/liferay/project/templates/client/extension/ClientExtensionProjectTemplateTest.java +++ /dev/null @@ -1,208 +0,0 @@ -/** - * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com - * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 - */ - -package com.liferay.project.templates.client.extension; - -import com.liferay.blade.cli.BladeTest; -import com.liferay.blade.cli.TestUtil; -import com.liferay.blade.cli.util.FileUtil; -import com.liferay.project.templates.client.extension.internal.ClientExtensionProjectTemplateCustomizer; - -import java.io.File; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; - -import java.util.List; -import java.util.Optional; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -/** - * @author Gregory Amerson - */ -public class ClientExtensionProjectTemplateTest { - - @Before - public void setUp() throws Exception { - File extensionsDir = _getExtensionsDir(); - - _extensionsDirPath = extensionsDir.toPath(); - - File settingsDir = temporaryFolder.getRoot(); - - Path settingsDirPath = settingsDir.toPath(); - - BladeTest.BladeTestBuilder bladeTestBuilder = BladeTest.builder(); - - bladeTestBuilder.setSettingsDir(settingsDirPath); - - bladeTestBuilder.setExtensionsDir(_extensionsDirPath); - - _bladeTest = bladeTestBuilder.build(); - - _rootDir = temporaryFolder.getRoot(); - } - - @Test - public void testClientExtensionCustomElementProjectTemplate() throws Exception { - _setupTestExtensions(); - - File workspaceDir = new File(_rootDir, "workspace"); - - _makeWorkspace(workspaceDir); - - String[] args = { - "create", "--base", workspaceDir.getAbsolutePath(), "-t", "client-extension", "-d", - workspaceDir.getAbsolutePath(), "--extension-name", "test123", "--extension-type", "customElement", - "customelementtest" - }; - - _bladeTest.run(args); - - File projectDir = new File(workspaceDir, "customelementtest"); - - Assert.assertTrue("Expected project dir to exist " + projectDir, projectDir.exists()); - - File clientExtensionFile = new File(projectDir, "client-extension.yaml"); - - Assert.assertTrue( - "Expected client-extension.yaml file to exist " + clientExtensionFile, clientExtensionFile.exists()); - - String content = FileUtil.read(clientExtensionFile); - - Assert.assertTrue("Expected client-extension.yaml to contain test123\n" + content, content.contains("test123")); - } - - @Test - public void testClientExtensionMetadataURL() throws Exception { - _setupTestExtensions(); - - File workspaceDir = new File(_rootDir, "workspace"); - - _makeWorkspace(workspaceDir); - - String[] args = { - "create", "--base", workspaceDir.getAbsolutePath(), "-t", "client-extension", "-d", - workspaceDir.getAbsolutePath(), "--extension-name", "test456", "--extension-type", "themeCSS", "test456" - }; - - _bladeTest.run(args); - - File projectDir = new File(workspaceDir, "test456"); - - Assert.assertTrue("Expected project dir to exist " + projectDir, projectDir.exists()); - - File clientExtensionFile = new File(projectDir, "client-extension.yaml"); - - Assert.assertTrue( - "Expected client-extension.yaml file to exist " + clientExtensionFile, clientExtensionFile.exists()); - - List lines = Files.readAllLines(clientExtensionFile.toPath()); - - Assert.assertEquals(" clayURL: css/clay.css", lines.get(1)); - } - - @Test - public void testMetadataURLMissing() throws Exception { - _setupTestExtensions(); - - File workspaceDir = new File(_rootDir, "workspace"); - - _makeWorkspace(workspaceDir, "dxp-7.3-u10"); - - Optional extensionMetadataFile = ClientExtensionProjectTemplateCustomizer.getExtensionMetadataFile( - workspaceDir); - - Assert.assertFalse(extensionMetadataFile.isPresent()); - } - - @Test - public void testMetadataURLu29() throws Exception { - _setupTestExtensions(); - - File workspaceDir = new File(_rootDir, "workspace"); - - _makeWorkspace(workspaceDir, "dxp-7.4-u29"); - - Optional extensionMetadataFile = ClientExtensionProjectTemplateCustomizer.getExtensionMetadataFile( - workspaceDir); - - Assert.assertEquals( - "https://repository-cdn.liferay.com/nexus/service/local/repositories/liferay-public-releases/content/com" + - "/liferay/com.liferay.client.extension.type.api/4.0.0/com.liferay.client.extension.type.api-4.0.0.jar", - extensionMetadataFile.get()); - } - - @Test - public void testMetadataURLu38() throws Exception { - _setupTestExtensions(); - - File workspaceDir = new File(_rootDir, "workspace"); - - _makeWorkspace(workspaceDir); - - Optional extensionMetadataFile = ClientExtensionProjectTemplateCustomizer.getExtensionMetadataFile( - workspaceDir); - - Assert.assertEquals( - "https://repository-cdn.liferay.com/nexus/service/local/repositories/liferay-public-releases/content/com" + - "/liferay/com.liferay.client.extension.type.api/5.0.2/com.liferay.client.extension.type.api-5.0.2.jar", - extensionMetadataFile.get()); - } - - @Rule - public final TemporaryFolder temporaryFolder = new TemporaryFolder(); - - private File _getExtensionsDir() { - return new File(temporaryFolder.getRoot(), ".blade/extensions"); - } - - private void _makeWorkspace(File workspace) throws Exception { - _makeWorkspace(workspace, BladeTest.PRODUCT_VERSION_DXP_74); - } - - private void _makeWorkspace(File workspace, String productVersion) { - File parentFile = workspace.getParentFile(); - - String[] args = {"--base", parentFile.getPath(), "init", workspace.getName(), "-v", productVersion}; - - TestUtil.runBlade(workspace, _extensionsDirPath.toFile(), args); - } - - private void _setupTestExtension(Path extensionsPath, String jarPath) throws Exception { - File sampleJarFile = new File(jarPath); - - Assert.assertTrue(sampleJarFile.getAbsolutePath() + " does not exist.", sampleJarFile.exists()); - - Path sampleJarPath = extensionsPath.resolve(sampleJarFile.getName()); - - Files.copy(sampleJarFile.toPath(), sampleJarPath, StandardCopyOption.REPLACE_EXISTING); - - Assert.assertTrue(Files.exists(sampleJarPath)); - } - - private void _setupTestExtensions() throws Exception { - File extensionsDir = _getExtensionsDir(); - - extensionsDir.mkdirs(); - - Assert.assertTrue("Unable to create test extensions dir.", extensionsDir.exists()); - - Path extensionsPath = extensionsDir.toPath(); - - _setupTestExtension(extensionsPath, System.getProperty("clientExtensionTemplateJarFile")); - } - - private BladeTest _bladeTest; - private Path _extensionsDirPath; - private File _rootDir; - -} \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/bnd.bnd b/extensions/project-templates-content-targeting-report/bnd.bnd deleted file mode 100644 index 0e2dd9a31..000000000 --- a/extensions/project-templates-content-targeting-report/bnd.bnd +++ /dev/null @@ -1,9 +0,0 @@ -Bundle-Description: Creates a Liferay Audience Targeting report as a module project. -Bundle-Name: Liferay Project Templates Content Targeting Report -Bundle-SymbolicName: com.liferay.project.templates.content.targeting.report -Bundle-Version: ${project.version} -Liferay-Versions: [7,7.2) --removeheaders:\ - Import-Package,\ - Private-Package,\ - Require-Capability \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/build.gradle b/extensions/project-templates-content-targeting-report/build.gradle deleted file mode 100644 index 30fe708a1..000000000 --- a/extensions/project-templates-content-targeting-report/build.gradle +++ /dev/null @@ -1,62 +0,0 @@ -buildscript { - dependencies { - classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd.gradle", version: "5.3.0" - } - - repositories { - maven { - if (project.hasProperty("release")) { - url "https://repository.liferay.com/nexus/content/groups/public" - } - else { - url "https://repository-cdn.liferay.com/nexus/content/groups/public" - } - } - } -} - -apply plugin: "biz.aQute.bnd.builder" -apply plugin: "eclipse" -apply plugin: "java" -apply plugin: "maven-publish" - -dependencies { - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" - compileOnly group: "org.apache.maven.archetype", name: "archetype-common", version: "2.4" - compileOnly project(":cli") -} - -eclipse { - classpath { - file { - whenMerged { - entries.removeAll { - it.kind == 'src' && it.path == 'src/main/resources' - } - } - } - } -} - -compileJava{ - dependsOn(":cli:unzipPortal") - dependsOn(":cli:unzipManifest") -} - -jar{ - dependsOn(":cli:unzipPortal") - - archiveBaseName.set("com.liferay.project.templates.content.targeting.report") -} - -publishing { - publications { - mavenProfileJar(MavenPublication) { - artifactId = jar.baseName - - from components.java - } - } -} - -version = "1.0.20-SNAPSHOT" \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/META-INF/archetype-post-generate.groovy b/extensions/project-templates-content-targeting-report/src/main/resources/META-INF/archetype-post-generate.groovy deleted file mode 100644 index eead1e6f5..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/META-INF/archetype-post-generate.groovy +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2000-present Liferay, Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - */ - -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -Path projectPath = Paths.get(request.outputDirectory, request.artifactId) - -Path buildGradlePath = projectPath.resolve("build.gradle") - -Files.deleteIfExists buildGradlePath \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/META-INF/maven/archetype-metadata.xml b/extensions/project-templates-content-targeting-report/src/main/resources/META-INF/maven/archetype-metadata.xml deleted file mode 100644 index fbb41f28e..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/META-INF/maven/archetype-metadata.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - src/main/java - - **/*.java - - - - src/main/resources - - **/* - - - - - - .gitignore - bnd.bnd - build.gradle - - - - - - - - maven - - - - - - - \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/bnd.bnd b/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/bnd.bnd deleted file mode 100644 index 446ff1917..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/bnd.bnd +++ /dev/null @@ -1,14 +0,0 @@ -Bundle-Name: ${artifactId} -Bundle-SymbolicName: ${package} -Bundle-Version: ${version} -Web-ContextPath: /content-targeting-report-${artifactId} -#if (${buildType} != "gradle") -#if (${liferayVersion.startsWith("7.1")})-contract: JavaPortlet,JavaServlet -#end --jsp: *.jsp,*.jspf --metatype: * --plugin.jsp: com.liferay.ant.bnd.jsp.JspAnalyzerPlugin --plugin.metatype: com.liferay.ant.bnd.metatype.MetatypePlugin --plugin.resourcebundle: com.liferay.ant.bnd.resource.bundle.ResourceBundleLoaderAnalyzerPlugin --plugin.sass: com.liferay.ant.bnd.sass.SassAnalyzerPlugin --sass: *#end \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/build.gradle b/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/build.gradle deleted file mode 100644 index b4c45695e..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -dependencies { - compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib" -#if (${liferayVersion.startsWith("7.0")}) - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.analytics.api", version: "3.0.0" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.anonymous.users.api", version: "2.0.2" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.api", version: "4.0.0" -#elseif (${liferayVersion.startsWith("7.1")}) - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.analytics.api", version: "5.0.0" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.anonymous.users.api", version: "3.0.0" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.api", version: "5.0.0" -#end - compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel" - compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib" - compileOnly group: "javax.portlet", name: "portlet-api" - compileOnly (group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1") {force = true} - compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations" -} \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/gitignore b/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/gitignore deleted file mode 100644 index c19c17241..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.gradle/ -build/ -target/ \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/pom.xml b/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/pom.xml deleted file mode 100644 index 506f6e795..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/pom.xml +++ /dev/null @@ -1,189 +0,0 @@ - - - - 4.0.0 - ${groupId} - ${artifactId} - ${version} - -#if (${liferayVersion.startsWith("7.0")}) - 7.0.6-1 -#elseif (${liferayVersion.startsWith("7.1")}) - 7.1.3 -#elseif (${liferayVersion.startsWith("7.2")}) - 7.2.1 -#elseif (${liferayVersion.startsWith("7.3")}) - 7.3.1 -#end - UTF-8 - - - - - com.liferay.portal - release.portal.bom - ${liferay.bom.version} - pom - import - - - com.liferay.portal - release.portal.bom.compile.only - ${liferay.bom.version} - pom - import - - - com.liferay.portal - release.portal.bom.third.party - ${liferay.bom.version} - pom - import - - - - - - liferay-public - https://repository-cdn.liferay.com/nexus/content/groups/public/ - - - - - com.liferay - com.liferay.frontend.taglib - provided - -#if (${liferayVersion.startsWith("7.0")}) - - com.liferay.content-targeting - com.liferay.content.targeting.analytics.api - 3.0.0 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.anonymous.users.api - 2.0.2 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.api - 4.0.0 - provided - -#elseif (${liferayVersion.startsWith("7.1")}) - - com.liferay.content-targeting - com.liferay.content.targeting.analytics.api - 5.0.0 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.anonymous.users.api - 3.0.0 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.api - 5.0.0 - provided - -#end - - com.liferay.portal - com.liferay.portal.kernel - provided - - - com.liferay.portal - com.liferay.util.taglib - provided - - - javax.portlet - portlet-api - provided - - - javax.servlet - javax.servlet-api - provided - - - org.osgi - org.osgi.service.component.annotations - provided - - - - - - com.liferay - com.liferay.css.builder - 3.0.2 - - - generate-resources - - build - - - - - src/main/resources - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.2 - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - biz.aQute.bnd - bnd-maven-plugin - @biz.aQute.bnd.version@ - - - - bnd-process - - - - - - biz.aQute.bnd - biz.aQute.bndlib - @biz.aQute.bnd.version@ - - - com.liferay - com.liferay.ant.bnd - 3.5.0 - - - - - - \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/java/content/targeting/report/__className__Report.java b/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/java/content/targeting/report/__className__Report.java deleted file mode 100644 index a204824c8..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/java/content/targeting/report/__className__Report.java +++ /dev/null @@ -1,135 +0,0 @@ -package ${package}.content.targeting.report; - -import com.liferay.content.targeting.api.model.BaseJSPReport; -import com.liferay.content.targeting.api.model.Report; -import com.liferay.content.targeting.model.ReportInstance; -import com.liferay.content.targeting.model.UserSegment; -import com.liferay.content.targeting.service.ReportInstanceLocalService; -import com.liferay.portal.kernel.json.JSONException; -import com.liferay.portal.kernel.json.JSONFactoryUtil; -import com.liferay.portal.kernel.json.JSONObject; -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; -import com.liferay.portal.kernel.util.GetterUtil; -import com.liferay.portal.kernel.util.ParamUtil; - -import java.util.Date; -import java.util.Map; - -import javax.portlet.PortletRequest; -import javax.portlet.PortletResponse; - -import javax.servlet.ServletContext; - -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; -import org.osgi.service.component.annotations.Reference; - -/** - * @author ${author} - */ -@Component(immediate = true, service = Report.class) -public class ${className}Report extends BaseJSPReport { - - @Activate - @Override - public void activate() { - super.activate(); - } - - @Deactivate - @Override - public void deActivate() { - super.deActivate(); - } - - @Override - public String getReportType() { - return UserSegment.class.getName(); - } - - @Override - public boolean isInstantiable() { - return true; - } - - public String processEditReport( - PortletRequest portletRequest, PortletResponse portletResponse, - ReportInstance reportInstance) - throws Exception { - - JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); - - String setting1 = ParamUtil.getString(portletRequest, "setting1"); - - jsonObject.put("setting1", setting1); - - String setting2 = ParamUtil.getString(portletRequest, "setting2"); - - jsonObject.put("setting2", setting2); - - return jsonObject.toString(); - } - - @Override - @Reference( - target = "(osgi.web.symbolicname=${artifactId})", - unbind = "-" - ) - public void setServletContext(ServletContext servletContext) { - super.setServletContext(servletContext); - } - - @Override - public void updateReport(ReportInstance reportInstance) { - try { - if (reportInstance != null) { - reportInstance.setModifiedDate(new Date()); - - _reportInstanceLocalService.updateReportInstance( - reportInstance); - } - } - catch (Exception exception) { - _log.error("Unable to update report", e); - } - } - - @Override - protected void populateContext( - ReportInstance reportInstance, Map context) { - - String setting1 = null; - String setting2 = null; - - if (reportInstance != null) { - try { - JSONObject jsonObject = JSONFactoryUtil.createJSONObject( - reportInstance.getTypeSettings()); - - setting1 = jsonObject.getString("setting1"); - setting2 = jsonObject.getString("setting2"); - } - catch (JSONException jsone) { - } - } - - context.put("setting1", setting1); - context.put("setting2", setting2); - } - - @Override - protected void populateEditContext( - ReportInstance reportInstance, Map context) { - - populateContext(reportInstance, context); - } - - private static final Log _log = LogFactoryUtil.getLog( - ${className}Report.class); - - @Reference(unbind = "-") - private volatile ReportInstanceLocalService _reportInstanceLocalService; - -} \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/edit.jsp b/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/edit.jsp deleted file mode 100644 index 2e2ce3d28..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/edit.jsp +++ /dev/null @@ -1,34 +0,0 @@ -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> - -<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> - -<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@ -taglib uri="http://liferay.com/tld/frontend" prefix="liferay-frontend" %><%@ -taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@ -taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> - -<%@ page import="com.liferay.content.targeting.util.ContentTargetingUtil" %><%@ -page import="com.liferay.portal.kernel.util.GetterUtil" %> - -<%@ page import="java.util.Map" %><%@ -page import="java.util.List" %> - - - - - - - -<% -Map context = (Map)request.getAttribute("context"); -%> - - - - - - - - - - \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/view.jsp b/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/view.jsp deleted file mode 100644 index c45e3b95c..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/view.jsp +++ /dev/null @@ -1,39 +0,0 @@ -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> - -<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> - -<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@ -taglib uri="http://liferay.com/tld/frontend" prefix="liferay-frontend" %><%@ -taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@ -taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> - -<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %><%@ -page import="java.util.Map" %> - - - - - - - -<% -Map context = (Map)request.getAttribute("context"); -%> - -
-
-
- -
- - -

- Setting 1: <%= GetterUtil.getString(context.get("setting1")) %> -

- -

- Setting 2: <%= GetterUtil.getString(context.get("setting2")) %> -

-
-
-
\ No newline at end of file diff --git a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/resources/content/Language.properties b/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/resources/content/Language.properties deleted file mode 100644 index cbddde6bb..000000000 --- a/extensions/project-templates-content-targeting-report/src/main/resources/archetype-resources/src/main/resources/content/Language.properties +++ /dev/null @@ -1,6 +0,0 @@ -model.resource.${package}.content.targeting.report.${className}Report=${className} Report Name -model.resource.${package}.content.targeting.report.${className}Report.description=${className} Report Description -setting1=Setting 1 -setting2=Setting 2 -these-are-custom-settings-for-users-configuring-your-report=These are custom settings for users configuring your report. -your-data-should-be-displayed-here=Your data should be displayed here. \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/bnd.bnd b/extensions/project-templates-content-targeting-rule/bnd.bnd deleted file mode 100644 index 1f054db8d..000000000 --- a/extensions/project-templates-content-targeting-rule/bnd.bnd +++ /dev/null @@ -1,9 +0,0 @@ -Bundle-Description: Creates a Liferay Audience Targeting rule as a module project. -Bundle-Name: Liferay Project Templates Content Targeting Rule -Bundle-SymbolicName: com.liferay.project.templates.content.targeting.rule -Bundle-Version: ${project.version} -Liferay-Versions: [7,7.2) --removeheaders:\ - Import-Package,\ - Private-Package,\ - Require-Capability \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/build.gradle b/extensions/project-templates-content-targeting-rule/build.gradle deleted file mode 100644 index 716c4f846..000000000 --- a/extensions/project-templates-content-targeting-rule/build.gradle +++ /dev/null @@ -1,62 +0,0 @@ -buildscript { - dependencies { - classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd.gradle", version: "5.3.0" - } - - repositories { - maven { - if (project.hasProperty("release")) { - url "https://repository.liferay.com/nexus/content/groups/public" - } - else { - url "https://repository-cdn.liferay.com/nexus/content/groups/public" - } - } - } -} - -apply plugin: "biz.aQute.bnd.builder" -apply plugin: "eclipse" -apply plugin: "java" -apply plugin: "maven-publish" - -dependencies { - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" - compileOnly group: "org.apache.maven.archetype", name: "archetype-common", version: "2.4" - compileOnly project(":cli") -} - -eclipse { - classpath { - file { - whenMerged { - entries.removeAll { - it.kind == 'src' && it.path == 'src/main/resources' - } - } - } - } -} - -compileJava{ - dependsOn(":cli:unzipPortal") - dependsOn(":cli:unzipManifest") -} - -jar{ - dependsOn(":cli:unzipPortal") - - archiveBaseName.set("com.liferay.project.templates.content.targeting.rule") -} - -publishing { - publications { - mavenProfileJar(MavenPublication) { - artifactId = jar.baseName - - from components.java - } - } -} - -version = "1.0.20-SNAPSHOT" \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/src/main/resources/META-INF/archetype-post-generate.groovy b/extensions/project-templates-content-targeting-rule/src/main/resources/META-INF/archetype-post-generate.groovy deleted file mode 100644 index eead1e6f5..000000000 --- a/extensions/project-templates-content-targeting-rule/src/main/resources/META-INF/archetype-post-generate.groovy +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2000-present Liferay, Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - */ - -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -Path projectPath = Paths.get(request.outputDirectory, request.artifactId) - -Path buildGradlePath = projectPath.resolve("build.gradle") - -Files.deleteIfExists buildGradlePath \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/src/main/resources/META-INF/maven/archetype-metadata.xml b/extensions/project-templates-content-targeting-rule/src/main/resources/META-INF/maven/archetype-metadata.xml deleted file mode 100644 index ff69dc316..000000000 --- a/extensions/project-templates-content-targeting-rule/src/main/resources/META-INF/maven/archetype-metadata.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - src/main/java - - **/*.java - - - - src/main/resources - - **/* - - - - - - .gitignore - bnd.bnd - build.gradle - - - - - - - - maven - - - - - - - \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/bnd.bnd b/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/bnd.bnd deleted file mode 100644 index 29547d251..000000000 --- a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/bnd.bnd +++ /dev/null @@ -1,14 +0,0 @@ -Bundle-Name: ${artifactId} -Bundle-SymbolicName: ${package} -Bundle-Version: ${version} -Web-ContextPath: /content-targeting-rule-${artifactId} -#if (${buildType} != "gradle") -#if (${liferayVersion.startsWith("7.1")})-contract: JavaPortlet,JavaServlet -#end --jsp: *.jsp,*.jspf --metatype: * --plugin.jsp: com.liferay.ant.bnd.jsp.JspAnalyzerPlugin --plugin.metatype: com.liferay.ant.bnd.metatype.MetatypePlugin --plugin.resourcebundle: com.liferay.ant.bnd.resource.bundle.ResourceBundleLoaderAnalyzerPlugin --plugin.sass: com.liferay.ant.bnd.sass.SassAnalyzerPlugin --sass: *#end \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/build.gradle b/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/build.gradle deleted file mode 100644 index b4c45695e..000000000 --- a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -dependencies { - compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib" -#if (${liferayVersion.startsWith("7.0")}) - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.analytics.api", version: "3.0.0" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.anonymous.users.api", version: "2.0.2" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.api", version: "4.0.0" -#elseif (${liferayVersion.startsWith("7.1")}) - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.analytics.api", version: "5.0.0" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.anonymous.users.api", version: "3.0.0" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.api", version: "5.0.0" -#end - compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel" - compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib" - compileOnly group: "javax.portlet", name: "portlet-api" - compileOnly (group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1") {force = true} - compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations" -} \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/gitignore b/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/gitignore deleted file mode 100644 index c19c17241..000000000 --- a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.gradle/ -build/ -target/ \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/pom.xml b/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/pom.xml deleted file mode 100644 index 506f6e795..000000000 --- a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/pom.xml +++ /dev/null @@ -1,189 +0,0 @@ - - - - 4.0.0 - ${groupId} - ${artifactId} - ${version} - -#if (${liferayVersion.startsWith("7.0")}) - 7.0.6-1 -#elseif (${liferayVersion.startsWith("7.1")}) - 7.1.3 -#elseif (${liferayVersion.startsWith("7.2")}) - 7.2.1 -#elseif (${liferayVersion.startsWith("7.3")}) - 7.3.1 -#end - UTF-8 - - - - - com.liferay.portal - release.portal.bom - ${liferay.bom.version} - pom - import - - - com.liferay.portal - release.portal.bom.compile.only - ${liferay.bom.version} - pom - import - - - com.liferay.portal - release.portal.bom.third.party - ${liferay.bom.version} - pom - import - - - - - - liferay-public - https://repository-cdn.liferay.com/nexus/content/groups/public/ - - - - - com.liferay - com.liferay.frontend.taglib - provided - -#if (${liferayVersion.startsWith("7.0")}) - - com.liferay.content-targeting - com.liferay.content.targeting.analytics.api - 3.0.0 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.anonymous.users.api - 2.0.2 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.api - 4.0.0 - provided - -#elseif (${liferayVersion.startsWith("7.1")}) - - com.liferay.content-targeting - com.liferay.content.targeting.analytics.api - 5.0.0 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.anonymous.users.api - 3.0.0 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.api - 5.0.0 - provided - -#end - - com.liferay.portal - com.liferay.portal.kernel - provided - - - com.liferay.portal - com.liferay.util.taglib - provided - - - javax.portlet - portlet-api - provided - - - javax.servlet - javax.servlet-api - provided - - - org.osgi - org.osgi.service.component.annotations - provided - - - - - - com.liferay - com.liferay.css.builder - 3.0.2 - - - generate-resources - - build - - - - - src/main/resources - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.2 - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - biz.aQute.bnd - bnd-maven-plugin - @biz.aQute.bnd.version@ - - - - bnd-process - - - - - - biz.aQute.bnd - biz.aQute.bndlib - @biz.aQute.bnd.version@ - - - com.liferay - com.liferay.ant.bnd - 3.5.0 - - - - - - \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/src/main/java/content/targeting/rule/__className__Rule.java b/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/src/main/java/content/targeting/rule/__className__Rule.java deleted file mode 100644 index 99e287feb..000000000 --- a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/src/main/java/content/targeting/rule/__className__Rule.java +++ /dev/null @@ -1,158 +0,0 @@ -package ${package}.content.targeting.rule; - -import com.liferay.content.targeting.anonymous.users.model.AnonymousUser; -import com.liferay.content.targeting.api.model.BaseJSPRule; -import com.liferay.content.targeting.api.model.Rule; -import com.liferay.content.targeting.model.RuleInstance; -import com.liferay.content.targeting.rule.categories.SampleRuleCategory; -import com.liferay.portal.kernel.json.JSONException; -import com.liferay.portal.kernel.json.JSONFactoryUtil; -import com.liferay.portal.kernel.json.JSONObject; -import com.liferay.portal.kernel.language.LanguageUtil; -import com.liferay.portal.kernel.util.GetterUtil; -import com.liferay.portal.kernel.util.ResourceBundleUtil; - -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.portlet.PortletRequest; -import javax.portlet.PortletResponse; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; - -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; -import org.osgi.service.component.annotations.Reference; - -/** - * @author ${author} - */ -@Component(immediate = true, service = Rule.class) -public class ${className}Rule extends BaseJSPRule { - - @Activate - @Override - public void activate() { - super.activate(); - } - - @Deactivate - @Override - public void deActivate() { - super.deActivate(); - } - - @Override - public boolean evaluate( - HttpServletRequest httpServletRequest, RuleInstance ruleInstance, - AnonymousUser anonymousUser) - throws Exception { - - // You can obtain the rule configuration from the type settings - - String typeSettings = ruleInstance.getTypeSettings(); - - // Return true if the anonymous user matches this rule - - return _getMatches(typeSettings); - } - - @Override - public String getIcon() { - return "icon-puzzle-piece"; - } - - @Override - public String getRuleCategoryKey() { - - // Available category classes: BehaviourRuleCategory, - // SessionAttributesRuleCategory, SocialRuleCategory and - // UserAttributesRoleCategory - - return SampleRuleCategory.KEY; - } - - @Override - public String getSummary(RuleInstance ruleInstance, Locale locale) { - String typeSettings = ruleInstance.getTypeSettings(); - - boolean matches = _getMatches(typeSettings); - - ResourceBundle resourceBundle = ResourceBundleUtil.getBundle( - "content.Language", locale, getClass()); - - if (matches) { - return LanguageUtil.get( - resourceBundle, "the-user-always-matches-this-rule"); - } - else { - return LanguageUtil.get( - resourceBundle, "the-user-never-matches-this-rule"); - } - } - - @Override - public String processRule( - PortletRequest portletRequest, PortletResponse portletResponse, - String id, Map values) { - - JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); - - boolean matches = GetterUtil.getBoolean(values.get("matches")); - - jsonObject.put("matches", matches); - - return jsonObject.toString(); - } - - @Override - @Reference( - target = "(osgi.web.symbolicname=${package})", - unbind = "-" - ) - public void setServletContext(ServletContext servletContext) { - super.setServletContext(servletContext); - } - - @Override - protected void populateContext( - RuleInstance ruleInstance, Map context, - Map values) { - - boolean matches = false; - - if (!values.isEmpty()) { - - // Value from the request in case of an error - - matches = GetterUtil.getBoolean(values.get("matches")); - } - else if (ruleInstance != null) { - - // Value from the stored configuration - - String typeSettings = ruleInstance.getTypeSettings(); - - matches = _getMatches(typeSettings); - } - - context.put("matches", matches); - } - - private boolean _getMatches(String typeSettings) { - try { - JSONObject jsonObject = JSONFactoryUtil.createJSONObject( - typeSettings); - - return jsonObject.getBoolean("matches"); - } - catch (JSONException jsone) { - } - - return false; - } - -} \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/view.jsp b/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/view.jsp deleted file mode 100644 index 08930171d..000000000 --- a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/view.jsp +++ /dev/null @@ -1,23 +0,0 @@ -<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> - -<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@ -taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@ -taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> - -<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %> - -<%@ page import="java.util.Map" %> - - - - - -<% -Map context = (Map)request.getAttribute("context"); -%> - - - - - - \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/src/main/resources/content/Language.properties b/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/src/main/resources/content/Language.properties deleted file mode 100644 index 98907f86c..000000000 --- a/extensions/project-templates-content-targeting-rule/src/main/resources/archetype-resources/src/main/resources/content/Language.properties +++ /dev/null @@ -1,2 +0,0 @@ -model.resource.${package}.content.targeting.rule.${className}Rule=${className} Rule Name -model.resource.${package}.content.targeting.rule.${className}Rule.description=${className} Rule Description \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/bnd.bnd b/extensions/project-templates-content-targeting-tracking-action/bnd.bnd deleted file mode 100644 index ca2d0aae9..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/bnd.bnd +++ /dev/null @@ -1,9 +0,0 @@ -Bundle-Description: Creates a Liferay Audience Targeting metric as a module project. -Bundle-Name: Liferay Project Templates Content Targeting Tracking Action -Bundle-SymbolicName: com.liferay.project.templates.content.targeting.tracking.action -Bundle-Version: ${project.version} -Liferay-Versions: [7,7.2) --removeheaders:\ - Import-Package,\ - Private-Package,\ - Require-Capability \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/build.gradle b/extensions/project-templates-content-targeting-tracking-action/build.gradle deleted file mode 100644 index a68eadba9..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/build.gradle +++ /dev/null @@ -1,62 +0,0 @@ -buildscript { - dependencies { - classpath group: "biz.aQute.bnd", name: "biz.aQute.bnd.gradle", version: "5.3.0" - } - - repositories { - maven { - if (project.hasProperty("release")) { - url "https://repository.liferay.com/nexus/content/groups/public" - } - else { - url "https://repository-cdn.liferay.com/nexus/content/groups/public" - } - } - } -} - -apply plugin: "biz.aQute.bnd.builder" -apply plugin: "eclipse" -apply plugin: "java" -apply plugin: "maven-publish" - -dependencies { - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" - compileOnly group: "org.apache.maven.archetype", name: "archetype-common", version: "2.4" - compileOnly project(":cli") -} - -eclipse { - classpath { - file { - whenMerged { - entries.removeAll { - it.kind == 'src' && it.path == 'src/main/resources' - } - } - } - } -} - -compileJava{ - dependsOn(":cli:unzipPortal") - dependsOn(":cli:unzipManifest") -} - -jar{ - dependsOn(":cli:unzipPortal") - - archiveBaseName.set("com.liferay.project.templates.content.targeting.tracking.action") -} - -publishing { - publications { - mavenProfileJar(MavenPublication) { - artifactId = jar.baseName - - from components.java - } - } -} - -version = "1.0.20-SNAPSHOT" \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/META-INF/archetype-post-generate.groovy b/extensions/project-templates-content-targeting-tracking-action/src/main/resources/META-INF/archetype-post-generate.groovy deleted file mode 100644 index eead1e6f5..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/META-INF/archetype-post-generate.groovy +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2000-present Liferay, Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2.1 of the License, or (at your option) - * any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - */ - -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -Path projectPath = Paths.get(request.outputDirectory, request.artifactId) - -Path buildGradlePath = projectPath.resolve("build.gradle") - -Files.deleteIfExists buildGradlePath \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/META-INF/maven/archetype-metadata.xml b/extensions/project-templates-content-targeting-tracking-action/src/main/resources/META-INF/maven/archetype-metadata.xml deleted file mode 100644 index 885fc341b..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/META-INF/maven/archetype-metadata.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - src/main/java - - **/*.java - - - - src/main/resources - - **/* - - - - - - .gitignore - bnd.bnd - build.gradle - - - - - - - - maven - - - - - - - \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/bnd.bnd b/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/bnd.bnd deleted file mode 100644 index c82f751ad..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/bnd.bnd +++ /dev/null @@ -1,14 +0,0 @@ -Bundle-Name: ${artifactId} -Bundle-SymbolicName: ${package} -Bundle-Version: ${version} -Web-ContextPath: /content-targeting-tracking-action-${artifactId} -#if (${buildType} != "gradle") -#if (${liferayVersion.startsWith("7.1")})-contract: JavaPortlet,JavaServlet -#end --jsp: *.jsp,*.jspf --metatype: * --plugin.jsp: com.liferay.ant.bnd.jsp.JspAnalyzerPlugin --plugin.metatype: com.liferay.ant.bnd.metatype.MetatypePlugin --plugin.resourcebundle: com.liferay.ant.bnd.resource.bundle.ResourceBundleLoaderAnalyzerPlugin --plugin.sass: com.liferay.ant.bnd.sass.SassAnalyzerPlugin --sass: *#end \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/build.gradle b/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/build.gradle deleted file mode 100644 index b4c45695e..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -dependencies { - compileOnly group: "com.liferay", name: "com.liferay.frontend.taglib" -#if (${liferayVersion.startsWith("7.0")}) - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.analytics.api", version: "3.0.0" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.anonymous.users.api", version: "2.0.2" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.api", version: "4.0.0" -#elseif (${liferayVersion.startsWith("7.1")}) - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.analytics.api", version: "5.0.0" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.anonymous.users.api", version: "3.0.0" - compileOnly group: "com.liferay.content-targeting", name: "com.liferay.content.targeting.api", version: "5.0.0" -#end - compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel" - compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib" - compileOnly group: "javax.portlet", name: "portlet-api" - compileOnly (group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1") {force = true} - compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations" -} \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/gitignore b/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/gitignore deleted file mode 100644 index c19c17241..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.gradle/ -build/ -target/ \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/pom.xml b/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/pom.xml deleted file mode 100644 index 506f6e795..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/pom.xml +++ /dev/null @@ -1,189 +0,0 @@ - - - - 4.0.0 - ${groupId} - ${artifactId} - ${version} - -#if (${liferayVersion.startsWith("7.0")}) - 7.0.6-1 -#elseif (${liferayVersion.startsWith("7.1")}) - 7.1.3 -#elseif (${liferayVersion.startsWith("7.2")}) - 7.2.1 -#elseif (${liferayVersion.startsWith("7.3")}) - 7.3.1 -#end - UTF-8 - - - - - com.liferay.portal - release.portal.bom - ${liferay.bom.version} - pom - import - - - com.liferay.portal - release.portal.bom.compile.only - ${liferay.bom.version} - pom - import - - - com.liferay.portal - release.portal.bom.third.party - ${liferay.bom.version} - pom - import - - - - - - liferay-public - https://repository-cdn.liferay.com/nexus/content/groups/public/ - - - - - com.liferay - com.liferay.frontend.taglib - provided - -#if (${liferayVersion.startsWith("7.0")}) - - com.liferay.content-targeting - com.liferay.content.targeting.analytics.api - 3.0.0 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.anonymous.users.api - 2.0.2 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.api - 4.0.0 - provided - -#elseif (${liferayVersion.startsWith("7.1")}) - - com.liferay.content-targeting - com.liferay.content.targeting.analytics.api - 5.0.0 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.anonymous.users.api - 3.0.0 - provided - - - com.liferay.content-targeting - com.liferay.content.targeting.api - 5.0.0 - provided - -#end - - com.liferay.portal - com.liferay.portal.kernel - provided - - - com.liferay.portal - com.liferay.util.taglib - provided - - - javax.portlet - portlet-api - provided - - - javax.servlet - javax.servlet-api - provided - - - org.osgi - org.osgi.service.component.annotations - provided - - - - - - com.liferay - com.liferay.css.builder - 3.0.2 - - - generate-resources - - build - - - - - src/main/resources - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.2 - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - biz.aQute.bnd - bnd-maven-plugin - @biz.aQute.bnd.version@ - - - - bnd-process - - - - - - biz.aQute.bnd - biz.aQute.bndlib - @biz.aQute.bnd.version@ - - - com.liferay - com.liferay.ant.bnd - 3.5.0 - - - - - - \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/src/main/java/content/targeting/tracking/action/__className__TrackingAction.java b/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/src/main/java/content/targeting/tracking/action/__className__TrackingAction.java deleted file mode 100644 index 9b3183cc2..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/src/main/java/content/targeting/tracking/action/__className__TrackingAction.java +++ /dev/null @@ -1,108 +0,0 @@ -package ${package}.content.targeting.tracking.action; - -import com.liferay.content.targeting.api.model.BaseJSPTrackingAction; -import com.liferay.content.targeting.api.model.TrackingAction; -import com.liferay.content.targeting.exception.InvalidTrackingActionException; -import com.liferay.content.targeting.model.TrackingActionInstance; -import com.liferay.portal.kernel.language.LanguageUtil; -import com.liferay.portal.kernel.util.ListUtil; -import com.liferay.portal.kernel.util.StringPool; - -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import javax.portlet.PortletRequest; -import javax.portlet.PortletResponse; - -import javax.servlet.ServletContext; - -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; -import org.osgi.service.component.annotations.Reference; - -/** - * @author ${author} - */ -@Component(immediate = true, service = TrackingAction.class) -public class ${className}TrackingAction extends BaseJSPTrackingAction { - - @Activate - @Override - public void activate() { - super.activate(); - } - - @Deactivate - @Override - public void deActivate() { - super.deActivate(); - } - - @Override - public List getEventTypes() { - return ListUtil.fromArray(_EVENT_TYPES); - } - - @Override - public String getSummary( - TrackingActionInstance trackingActionInstance, Locale locale) { - - String summary = LanguageUtil.format( - locale, "metric-action-x-for-element-x", - new Object[] { - trackingActionInstance.getEventType(), - trackingActionInstance.getElementId() - }); - - return summary; - } - - @Override - public String processTrackingAction( - PortletRequest portletRequest, PortletResponse portletResponse, - String id, Map values) - throws InvalidTrackingActionException { - - return null; - } - - @Override - @Reference( - target = "(osgi.web.symbolicname=${package})", - unbind = "-" - ) - public void setServletContext(ServletContext servletContext) { - super.setServletContext(servletContext); - } - - @Override - protected void populateContext( - TrackingActionInstance trackingActionInstance, - Map context, Map values) { - - String alias = StringPool.BLANK; - String elementId = StringPool.BLANK; - String eventType = StringPool.BLANK; - - if (!values.isEmpty()) { - alias = values.get("alias"); - elementId = values.get("elementId"); - eventType = values.get("eventType"); - } - else if (trackingActionInstance != null) { - alias = trackingActionInstance.getAlias(); - elementId = trackingActionInstance.getElementId(); - eventType = trackingActionInstance.getEventType(); - } - - context.put("alias", alias); - context.put("elementId", elementId); - context.put("eventType", eventType); - context.put("eventTypes", getEventTypes()); - } - - private static final String[] _EVENT_TYPES = {"click"}; - -} \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/view.jsp b/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/view.jsp deleted file mode 100644 index c405dab2c..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/src/main/resources/META-INF/resources/view.jsp +++ /dev/null @@ -1,46 +0,0 @@ -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> - -<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> - -<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@ -taglib uri="http://liferay.com/tld/frontend" prefix="liferay-frontend" %><%@ -taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@ -taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> - -<%@ page import="com.liferay.content.targeting.util.ContentTargetingUtil" %><%@ -page import="com.liferay.portal.kernel.util.GetterUtil" %> - -<%@ page import="java.util.List" %><%@ -page import="java.util.Map" %> - - - - - - - -<% -Map context = (Map)request.getAttribute("context"); -%> - - - - - - - - - - - - <% - for (String eventType : (List)context.get("eventTypes")) { - %> - - - - <% - } - %> - - \ No newline at end of file diff --git a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/src/main/resources/content/Language.properties b/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/src/main/resources/content/Language.properties deleted file mode 100644 index 4bc1f9122..000000000 --- a/extensions/project-templates-content-targeting-tracking-action/src/main/resources/archetype-resources/src/main/resources/content/Language.properties +++ /dev/null @@ -1,2 +0,0 @@ -model.resource.${package}.content.targeting.tracking.action.${className}TrackingAction=${className} Tracking Action Name -model.resource.${package}.content.targeting.tracking.action.${className}TrackingAction.description=${className} Tracking Action Description \ No newline at end of file diff --git a/extensions/project-templates-freemarker-portlet/build.gradle b/extensions/project-templates-freemarker-portlet/build.gradle index ac80f0d1f..24695ab17 100644 --- a/extensions/project-templates-freemarker-portlet/build.gradle +++ b/extensions/project-templates-freemarker-portlet/build.gradle @@ -21,7 +21,7 @@ apply plugin: "java" apply plugin: "maven-publish" dependencies { - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" + compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.134" compileOnly group: "org.apache.maven.archetype", name: "archetype-common", version: "2.4" compileOnly project(":cli") } diff --git a/extensions/project-templates-js-theme/build.gradle b/extensions/project-templates-js-theme/build.gradle index 329a3c0a9..d7bd60f07 100644 --- a/extensions/project-templates-js-theme/build.gradle +++ b/extensions/project-templates-js-theme/build.gradle @@ -20,7 +20,7 @@ apply plugin: "java-library" apply plugin: "maven-publish" dependencies { - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" + compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.134" compileOnly group: "org.apache.maven.archetype", name: "archetype-common", version: "2.4" compileOnly project(":cli") diff --git a/extensions/project-templates-js-widget/build.gradle b/extensions/project-templates-js-widget/build.gradle index abce51f5e..f15ba18aa 100644 --- a/extensions/project-templates-js-widget/build.gradle +++ b/extensions/project-templates-js-widget/build.gradle @@ -20,7 +20,7 @@ apply plugin: "java-library" apply plugin: "maven-publish" dependencies { - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" + compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.134" compileOnly group: "org.apache.maven.archetype", name: "archetype-common", version: "2.4" compileOnly project(":cli") diff --git a/extensions/project-templates-social-bookmark/build.gradle b/extensions/project-templates-social-bookmark/build.gradle index 7e52c8578..83d34565e 100644 --- a/extensions/project-templates-social-bookmark/build.gradle +++ b/extensions/project-templates-social-bookmark/build.gradle @@ -21,7 +21,7 @@ apply plugin: "java" apply plugin: "maven-publish" dependencies { - compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.123" + compileOnly group: "com.liferay", name: "com.liferay.project.templates.extensions", version: "1.0.134" compileOnly group: "org.apache.maven.archetype", name: "archetype-common", version: "2.4" compileOnly project(":cli") } diff --git a/extensions/sample-template/src/test/java/com/liferay/project/templates/sample/SampleTemplatesTest.java b/extensions/sample-template/src/test/java/com/liferay/project/templates/sample/SampleTemplatesTest.java index cc3983a7f..770446eb5 100644 --- a/extensions/sample-template/src/test/java/com/liferay/project/templates/sample/SampleTemplatesTest.java +++ b/extensions/sample-template/src/test/java/com/liferay/project/templates/sample/SampleTemplatesTest.java @@ -142,7 +142,7 @@ private void _setupTestExtensions() throws Exception { _setupTestExtension(extensionsPath, System.getProperty("sampleTemplateJarFile")); } - private static final int _NUM_BUILTIN_TEMPLATES = 30; + private static final int _NUM_BUILTIN_TEMPLATES = 29; private BladeTest _bladeTest; private File _rootDir; diff --git a/publish.sh b/publish.sh index fc9ee595a..3d58080b9 100755 --- a/publish.sh +++ b/publish.sh @@ -90,15 +90,6 @@ fi # Publish the Activator Project Template ./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-activator:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$? -# Publish the Content Targeting Report Project Template -./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-content-targeting-report:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$? - -# Publish the Content Targeting Rule Project Template -./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-content-targeting-rule:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$? - -# Publish the Content Targeting Tracking Action Project Template -./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-content-targeting-tracking-action:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$? - # Publish the Freemarker Portlet Project Template ./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-freemarker-portlet:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt}; retcode=$? @@ -123,15 +114,6 @@ if [ "$retcode" != "0" ] || [ -z "$jsWidgetTemplatePublishCommand" ]; then exit 1 fi -# Publish the Client Extension Project Template -./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:project-templates-client-extension:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt} > /tmp/$timestamp/client-extension-template-publish-command.txt; retcode=$? -clientExtensionTemplatePublishCommand=$(cat /tmp/$timestamp/client-extension-template-publish-command.txt) - -if [ "$retcode" != "0" ] || [ -z "$clientExtensionTemplatePublishCommand" ]; then - echo Failed :extensions:project-templates-client-extension:publish - exit 1 -fi - # Publish the Maven Profile jar ./gradlew -q --no-daemon --console=plain $nexusOpt -P${releaseType} :extensions:maven-profile:publish -x :cli:bladeExtensionsVersions -x :cli:processResources --info ${scanOpt} > /tmp/$timestamp/maven-profile-publish-command.txt; retcode=$? mavenProfilePublishCommand=$(cat /tmp/$timestamp/maven-profile-publish-command.txt) diff --git a/run-tests.sh b/run-tests.sh index a6921ecbc..b16411d92 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -24,10 +24,6 @@ mv gradle-wrapper.properties.edited gradle/wrapper/gradle-wrapper.properties checkError -./gradlew --no-daemon :extensions:project-templates-client-extension:publishToMavenLocal -x :cli:bladeExtensionsVersions -x :cli:processResources --scan - -checkError - ./gradlew --no-daemon :extensions:project-templates-js-theme:publishToMavenLocal -x :cli:bladeExtensionsVersions -x :cli:processResources --scan checkError diff --git a/settings.gradle b/settings.gradle index 152ed3298..c1f3faf5a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,11 +13,7 @@ include "cli" include "extensions:bad-command" include "extensions:maven-profile" include "extensions:project-templates-activator" -include "extensions:project-templates-content-targeting-report" -include "extensions:project-templates-content-targeting-rule" -include "extensions:project-templates-content-targeting-tracking-action" include "extensions:project-templates-freemarker-portlet" -include "extensions:project-templates-client-extension" include "extensions:project-templates-js-theme" include "extensions:project-templates-js-widget" include "extensions:project-templates-social-bookmark" diff --git a/tests.zip b/tests.zip index 5f4270be7..f61863a9d 100644 Binary files a/tests.zip and b/tests.zip differ