diff --git a/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/util/VersionUtil.java b/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/util/VersionUtil.java index a0a557621a..a7ac280f49 100644 --- a/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/util/VersionUtil.java +++ b/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/util/VersionUtil.java @@ -14,6 +14,8 @@ package com.liferay.ide.core.util; +import com.liferay.ide.core.workspace.WorkspaceConstants; + import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -27,6 +29,13 @@ public static String simplifyTargetPlatformVersion(String targetPlatformVersion) return null; } + Matcher dxpQuarterReleaseTargetplatformVersionMatcher = + WorkspaceConstants.dxpQuarterReleaseTargetplatformVersionPattern.matcher(targetPlatformVersion); + + if (dxpQuarterReleaseTargetplatformVersionMatcher.matches()) { + return "7.4"; + } + String[] segments = targetPlatformVersion.split("\\."); StringBuilder sb = new StringBuilder(); diff --git a/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/workspace/LiferayWorkspaceUtil.java b/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/workspace/LiferayWorkspaceUtil.java index b7ed448936..0d952b6a6f 100644 --- a/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/workspace/LiferayWorkspaceUtil.java +++ b/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/workspace/LiferayWorkspaceUtil.java @@ -235,6 +235,14 @@ public static String getLiferayWorkspaceProjectVersion() { if (CoreUtil.isNotNullOrEmpty(simplifiedTargetPlatformVersion)) { try { + Matcher dxpQuarterlyVersionMatcher = + WorkspaceConstants.dxpQuarterReleaseTargetplatformVersionPattern.matcher( + liferayWorkspaceProject.getTargetPlatformVersion()); + + if (dxpQuarterlyVersionMatcher.matches()) { + return "7.4"; + } + Version liferayVersion = new Version(simplifiedTargetPlatformVersion); return new String(liferayVersion.getMajor() + "." + liferayVersion.getMinor()); diff --git a/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/workspace/WorkspaceConstants.java b/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/workspace/WorkspaceConstants.java index 050b4b315a..6a65d94887 100644 --- a/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/workspace/WorkspaceConstants.java +++ b/tools/plugins/com.liferay.ide.core/src/com/liferay/ide/core/workspace/WorkspaceConstants.java @@ -14,6 +14,8 @@ package com.liferay.ide.core.workspace; +import java.util.regex.Pattern; + /** * @author Terry Jia */ @@ -80,4 +82,7 @@ public class WorkspaceConstants { public static final String WORKSPACE_PRODUCT_PROPERTY = "liferay.workspace.product"; + public static final Pattern dxpQuarterReleaseTargetplatformVersionPattern = Pattern.compile( + "(\\d{4})\\.q([1234])\\.(\\d+)(-(\\d+))?"); + } \ No newline at end of file diff --git a/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/BladeCLI.java b/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/BladeCLI.java index a05d92f7a0..de62454e24 100644 --- a/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/BladeCLI.java +++ b/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/BladeCLI.java @@ -184,7 +184,7 @@ private static String[] _execute(IPath bladeCLIPath, String args) throws BladeCL try { IProxyService proxyService = LiferayCore.getProxyService(); - URL downloadProductInfoUrl = new URL(_PRODUCT_INFO_URL); + URL downloadProductInfoUrl = new URL(_productInfoUrl); IProxyData[] proxyDatas = proxyService.select(downloadProductInfoUrl.toURI()); @@ -299,8 +299,7 @@ private static IPath _getBladeJarFromBundle(String jarName) throws IOException { return new Path(bladeJarBundleFile.getCanonicalPath()); } - private static final String _PRODUCT_INFO_URL = "https://releases.liferay.com/tools/workspace/.product_info.json"; - private static String _bladeJarName = null; + private static String _productInfoUrl = "https://releases.liferay.com/tools/workspace/.product_info.json"; } \ No newline at end of file diff --git a/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/HasWorkspaceLiferayVersionDefaultValueService.java b/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/HasWorkspaceLiferayVersionDefaultValueService.java index 622efc053f..9b2e946fa1 100644 --- a/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/HasWorkspaceLiferayVersionDefaultValueService.java +++ b/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/HasWorkspaceLiferayVersionDefaultValueService.java @@ -39,10 +39,9 @@ protected String compute() { } try { - String simplifiedVersion = VersionUtil.simplifyTargetPlatformVersion( - liferayWorkspaceProject.getTargetPlatformVersion()); + if (Version.isVersion( + VersionUtil.simplifyTargetPlatformVersion(liferayWorkspaceProject.getTargetPlatformVersion()))) { - if (Version.isVersion(simplifiedVersion)) { return Boolean.toString(true); } diff --git a/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/ProjectTemplateNameValidationService.java b/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/ProjectTemplateNameValidationService.java index 837ae811f4..84ecfb87f2 100644 --- a/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/ProjectTemplateNameValidationService.java +++ b/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/modules/ProjectTemplateNameValidationService.java @@ -25,6 +25,7 @@ import com.liferay.ide.core.util.StringUtil; import com.liferay.ide.core.util.VersionUtil; import com.liferay.ide.core.workspace.LiferayWorkspaceUtil; +import com.liferay.ide.core.workspace.WorkspaceConstants; import com.liferay.ide.project.core.NewLiferayProjectProvider; import com.liferay.ide.project.core.ProjectCore; @@ -40,6 +41,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.regex.Matcher; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -76,15 +78,24 @@ protected Status compute() { return retval; } - NewLiferayModuleProjectOp op = context(NewLiferayModuleProjectOp.class); - - String targetPlatformVersionString = VersionUtil.simplifyTargetPlatformVersion( + Matcher dxpQuarterlyVersionMatcher = WorkspaceConstants.dxpQuarterReleaseTargetplatformVersionPattern.matcher( liferayWorkspaceProject.getTargetPlatformVersion()); + if (dxpQuarterlyVersionMatcher.matches()) { + return retval; + } + + NewLiferayModuleProjectOp op = context(NewLiferayModuleProjectOp.class); + String liferayVersion = get(op.getLiferayVersion()); - if (CoreUtil.isNotNullOrEmpty(targetPlatformVersionString)) { - Version targetPlatformVersion = Version.parseVersion(targetPlatformVersionString); + String targetPlatformVersionString = liferayWorkspaceProject.getTargetPlatformVersion(); + + String simplifyTargetPlatformVersionString = VersionUtil.simplifyTargetPlatformVersion( + targetPlatformVersionString); + + if (CoreUtil.isNotNullOrEmpty(simplifyTargetPlatformVersionString)) { + Version targetPlatformVersion = Version.parseVersion(simplifyTargetPlatformVersionString); liferayVersion = new String(targetPlatformVersion.getMajor() + "." + targetPlatformVersion.getMinor()); } diff --git a/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/util/ProjectUtil.java b/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/util/ProjectUtil.java index 618c207f03..7bc46e7fae 100644 --- a/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/util/ProjectUtil.java +++ b/tools/plugins/com.liferay.ide.project.core/src/com/liferay/ide/project/core/util/ProjectUtil.java @@ -47,6 +47,7 @@ import com.liferay.ide.project.core.model.NewLiferayPluginProjectOp; import com.liferay.ide.project.core.model.PluginType; import com.liferay.ide.project.core.modules.BladeCLI; +import com.liferay.ide.project.core.modules.BladeCLIException; import com.liferay.ide.project.core.modules.BndProperties; import com.liferay.ide.project.core.modules.BndPropertiesValue; import com.liferay.ide.sdk.core.ISDKConstants; @@ -67,6 +68,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -78,6 +80,8 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.apache.commons.lang.WordUtils; @@ -144,8 +148,6 @@ @SuppressWarnings("restriction") public class ProjectUtil { - public static final String METADATA_FOLDER = ".metadata"; - public static void collectProjectsFromDirectory(List result, File location) { File[] children = location.listFiles(); @@ -240,7 +242,7 @@ else if (file.isFile() && dotProject.equals(file.getName())) { // no project description found, so recurse into sub-directories for (File file : contents) { - if (file.isDirectory() && !METADATA_FOLDER.equals(file.getName())) { + if (file.isDirectory() && !_METADATA_FOLDER.equals(file.getName())) { try { String canonicalPath = file.getCanonicalPath(); @@ -1060,16 +1062,57 @@ public static IFile getPortletXmlFile(IProject project) { } public static Map getProductInfos() { - try (JsonReader jsonReader = new JsonReader(Files.newBufferedReader(_workspaceCacheFile.toPath()))) { - Gson gson = new Gson(); + Gson gson = new Gson(); - TypeToken> typeToken = new TypeToken>() { - }; + TypeToken> typeToken = new TypeToken>() { + }; + if (Objects.nonNull(workspaceProductInfo)) { + _workspaceCacheFile = new File(workspaceProductInfo); + } + else { + _workspaceCacheFile = new File(System.getProperty("user.home"), _DEFAULT_WORKSPACE_CACHE_FILE); + } + + try (JsonReader jsonReader = new JsonReader(Files.newBufferedReader(_workspaceCacheFile.toPath()))) { return gson.fromJson(jsonReader, typeToken.getType()); } - catch (Exception ce) { - ProjectCore.logError("Cannot Find Product Info", ce); + catch (Exception exception) { + try { + IPath bladeCLIPath = BladeCLI.getBladeCLIPath(); + + if (Objects.isNull(bladeCLIPath)) { + return null; + } + + if (FileUtil.notExists(bladeCLIPath.toFile())) { + return null; + } + + try (ZipFile zipFile = new ZipFile(bladeCLIPath.toFile())) { + Enumeration entries = zipFile.entries(); + + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + + String entryName = entry.getName(); + + if (entryName.equals(".product_info.json")) { + try (InputStream resourceAsStream = zipFile.getInputStream(entry); + JsonReader jsonReader = new JsonReader(new InputStreamReader(resourceAsStream))) { + + return gson.fromJson(jsonReader, typeToken.getType()); + } + } + } + } + catch (Exception exception2) { + ProjectCore.logError("Cannot Find Product Info", exception2); + } + } + catch (BladeCLIException bladeException) { + ProjectCore.logError("Cannot Find blade jar", bladeException); + } } return null; @@ -2032,14 +2075,16 @@ private static boolean _isLiferayRuntimePluginClassPath(IClasspathEntry entry) { private static final String _DEFAULT_WORKSPACE_CACHE_FILE = ".liferay/workspace/.product_info.json"; + private static final String _METADATA_FOLDER = ".metadata"; + private static final SapphireContentAccessor _getter = new SapphireContentAccessor() { }; private static final Pattern _themeBuilderPlugin = Pattern.compile( ".*apply.*plugin.*:.*[\'\"]com\\.liferay\\.portal\\.tools\\.theme\\.builder[\'\"].*", Pattern.MULTILINE | Pattern.DOTALL); private static final Pattern _warPlugin = Pattern.compile(".*apply.*war.*", Pattern.MULTILINE | Pattern.DOTALL); - private static final File _workspaceCacheFile = new File( - System.getProperty("user.home"), _DEFAULT_WORKSPACE_CACHE_FILE); + private static File _workspaceCacheFile; + private static String workspaceProductInfo = System.getProperty("liferay.workspace.product.info"); private static class Msgs extends NLS { diff --git a/tools/plugins/com.liferay.ide.upgrade.problems.core/src/com/liferay/ide/upgrade/problems/core/internal/commands/SwitchToUseReleaseAPIDependencyCommand.java b/tools/plugins/com.liferay.ide.upgrade.problems.core/src/com/liferay/ide/upgrade/problems/core/internal/commands/SwitchToUseReleaseAPIDependencyCommand.java index 23a22df753..b3f1b2a8ac 100644 --- a/tools/plugins/com.liferay.ide.upgrade.problems.core/src/com/liferay/ide/upgrade/problems/core/internal/commands/SwitchToUseReleaseAPIDependencyCommand.java +++ b/tools/plugins/com.liferay.ide.upgrade.problems.core/src/com/liferay/ide/upgrade/problems/core/internal/commands/SwitchToUseReleaseAPIDependencyCommand.java @@ -41,6 +41,7 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.regex.Matcher; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -113,19 +114,30 @@ private List _getAllDependenciesArtifactIds() { return Collections.emptyList(); } - String productKey = gradleWorkspaceProject.getProperty(WorkspaceConstants.WORKSPACE_PRODUCT_PROPERTY, null); + String targetPlatformVersionProperty = gradleWorkspaceProject.getProperty( + WorkspaceConstants.TARGET_PLATFORM_VERSION_PROPERTY, null); - List allArtifactIds = new ArrayList<>(); - - String[] versionParts = simplifiedVersion.split("\\."); + Matcher dxpQuarterReleaseTargetplatformVersionMatcher = + WorkspaceConstants.dxpQuarterReleaseTargetplatformVersionPattern.matcher(targetPlatformVersionProperty); - if (productKey.startsWith("dxp")) { - simplifiedVersion = versionParts[0] + "." + versionParts[1] + "." + versionParts[2] + ".x"; + if (dxpQuarterReleaseTargetplatformVersionMatcher.matches()) { + simplifiedVersion = "7.4.13.x"; } - else if (productKey.startsWith("portal")) { - simplifiedVersion = versionParts[0] + "." + versionParts[1] + ".x"; + else { + String productKey = gradleWorkspaceProject.getProperty(WorkspaceConstants.WORKSPACE_PRODUCT_PROPERTY, null); + + String[] versionParts = simplifiedVersion.split("\\."); + + if (productKey.startsWith("dxp")) { + simplifiedVersion = versionParts[0] + "." + versionParts[1] + "." + versionParts[2] + ".x"; + } + else if (productKey.startsWith("portal")) { + simplifiedVersion = versionParts[0] + "." + versionParts[1] + ".x"; + } } + List allArtifactIds = new ArrayList<>(); + Class clazz = SwitchToUseReleaseAPIDependencyCommand.class; try (InputStream inputStream = clazz.getResourceAsStream("/release-api/" + simplifiedVersion + "-versions.txt");