Skip to content

Commit

Permalink
BLADE-742 fix maven workspace init error
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjhy committed Feb 11, 2024
1 parent 02c24ba commit a24e758
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 130 deletions.
8 changes: 7 additions & 1 deletion cli/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Bundle-Version: ${project.version}.${tstamp}
JPM-Command: blade
Main-Class: com.liferay.blade.cli.BladeCLI
Private-Package:\
aQute.bnd.header;-split-package:=merge-first,\
aQute.bnd.maven;-split-package:=merge-first,\
aQute.bnd.osgi;-split-package:=merge-first,\
aQute.bnd.service;-split-package:=merge-first,\
Expand All @@ -18,6 +17,13 @@ Private-Package:\
\
aQute.service.reporter;-split-package:=merge-first,\
\
com.google.gson,\
com.google.gson.stream,\
com.google.gson.internal.bind,\
com.google.gson.internal,\
com.google.gson.reflect,\
com.google.gson.internal.sql,\
\
com.liferay.blade.gradle.tooling,\
\
groovy.json,\
Expand Down
4 changes: 3 additions & 1 deletion cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ createWrapperZip {

dependencies {
api group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "5.3.0"
api group: "com.google.code.gson", name: "gson", version: "2.9.0"
api group: "com.liferay", name: "com.liferay.gogo.shell.client", version: "1.0.0"
api group: "com.liferay", name: "com.liferay.project.templates", version: "5.0.283"
api group: "commons-io", name: "commons-io", version: "2.7"
Expand Down Expand Up @@ -111,7 +112,7 @@ dependencies {
api name: "org.objectweb.asm.tree-6.0.0"
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.blade.extensions.maven.profile", version: "1.0.40-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"
Expand Down Expand Up @@ -213,6 +214,7 @@ if (project.hasProperty("release") || project.hasProperty("snapshots")) {
}

repositories {
mavenLocal()
flatDir {
dirs "${rootProject.projectDir}/libs"
}
Expand Down
8 changes: 4 additions & 4 deletions cli/src/main/java/com/liferay/blade/cli/BladeCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
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.ReleaseInfo;
import com.liferay.blade.cli.util.ProductKeyInfo;
import com.liferay.blade.cli.util.Prompter;
import com.liferay.blade.cli.util.ReleaseInfo;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -100,7 +100,7 @@ public static Map<String, BaseCommand<? extends BaseArgs>> getCommandMapByClassL

boolean profileNameIsPresent = false;

if ((profileName != null) && (profileName.length() > 0)) {
if ((profileName != null) && !profileName.isEmpty()) {
profileNameIsPresent = true;
}

Expand Down Expand Up @@ -863,15 +863,15 @@ private Map<String, String> _buildMavenPossibleValuesMap(

Iterator<String> it = options.iterator();

Map<String, Object> releasesInfos = BladeUtil.getReleasesInfos(true, error());
Map<String, Object> releaseKeyInfos = BladeUtil.getReleaseKeyInfos(true, error());

Map<String, String> optionsMap = new LinkedHashMap<>();

for (int x = 1; it.hasNext(); x++) {
String option = it.next();

ProductKeyInfo productKeyInfo = new ProductKeyInfo(
option, (Map<String, String>)releasesInfos.get(option));
option, (Map<String, String>)releaseKeyInfos.get(option));

ReleaseInfo releaseInfo = new ReleaseInfo(
productKeyInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
* @author David Truong
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public BaseCommand(BladeCLI blade, T args) {
_args = args;
}

public void commandPostAction() throws Exception {
}

public abstract void execute() throws Exception;

public T getArgs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ protected ProjectTemplatesArgs getProjectTemplateArgs(

ReleaseInfo releaseInfo = BladeUtil.getReleaseInfo(liferayVersion.get());

if (releaseInfo.getProductKey().isQuarterly() && product.isPresent() && Objects.equals(product.get(), "dxp")) {
if (releaseInfo.getProductKey(
).isQuarterly() && product.isPresent() && Objects.equals(product.get(), "dxp")) {

String projectTemplate = projectTemplatesArgs.getTemplate();

switch (projectTemplate) {
Expand Down Expand Up @@ -496,7 +498,9 @@ private String _checkTemplateVersionRange(File templateFile, ProjectTemplatesArg

ReleaseInfo releaseInfo = BladeUtil.getReleaseInfo(versionString);

if (releaseInfo.getProductKey().isPromoted()) {
if (releaseInfo.getProductKey(
).isPromoted()) {

return "";
}

Expand Down
76 changes: 32 additions & 44 deletions cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.liferay.blade.cli.BladeCLI;
import com.liferay.blade.cli.BladeSettings;
import com.liferay.blade.cli.WorkspaceConstants;
import com.liferay.blade.cli.WorkspaceProvider;
import com.liferay.blade.cli.gradle.GradleExec;
import com.liferay.blade.cli.util.BladeUtil;
Expand All @@ -18,10 +17,9 @@
import com.liferay.project.templates.extensions.ProjectTemplatesArgs;
import com.liferay.project.templates.extensions.util.FileUtil;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import java.nio.file.FileVisitResult;
import java.nio.file.Files;
Expand All @@ -37,7 +35,6 @@
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;

/**
* @author Gregory Amerson
Expand All @@ -51,7 +48,6 @@ public InitCommand() {
}

@Override
@SuppressWarnings("unchecked")
public void execute() throws Exception {
BladeCLI bladeCLI = getBladeCLI();

Expand Down Expand Up @@ -134,7 +130,7 @@ public void execute() throws Exception {

_trace("Found Plugins SDK, moving contents to new subdirectory and initing workspace.");

Path tempDir = Files.createTempDirectory("orignal-sdk");
Path tempDir = Files.createTempDirectory("original-sdk");

temp = tempDir.toFile();

Expand Down Expand Up @@ -193,7 +189,7 @@ public void execute() throws Exception {
String liferayVersion;
String workspaceProductKey;

Map<String, Object> releasesInfos = BladeUtil.getReleasesInfos(initArgs.isTrace(), bladeCLI.error());
Map<String, Object> releasesInfos = BladeUtil.getReleaseKeyInfos(initArgs.isTrace(), bladeCLI.error());

if (!mavenBuild) {
workspaceProductKey = _getDefaultProductKey(initArgs);
Expand All @@ -216,13 +212,13 @@ public void execute() throws Exception {

ReleaseInfo releaseInfo = BladeUtil.getReleaseInfo(workspaceProductKey);

String targetPlatformVersion = releaseInfo.getTargetPlatformVersion();
if (releaseInfo.getProductKey(
).isQuarterly()) {

if (releaseInfo.getProductKey().isQuarterly()) {
liferayVersion = "7.4";
}
else {
Version normalTargetPlatformVersion = _makeCompatibleVersion(targetPlatformVersion);
Version normalTargetPlatformVersion = _makeCompatibleVersion(releaseInfo.getTargetPlatformVersion());

liferayVersion =
normalTargetPlatformVersion.getMajor() + "." + normalTargetPlatformVersion.getMinor() + "." +
Expand All @@ -232,15 +228,23 @@ public void execute() throws Exception {
else {
workspaceProductKey = _setProductAndVersionForMaven(releasesInfos, initArgs);

Object productInfoObject = releasesInfos.get(workspaceProductKey);

if (productInfoObject == null) {
_addError("Unable to get product info for selected version " + workspaceProductKey);

return;
}

liferayVersion = initArgs.getLiferayVersion();
}

Object productInfoObject = releasesInfos.get(workspaceProductKey);
ReleaseInfo releaseInfo = BladeUtil.getReleaseInfo(workspaceProductKey);

if (productInfoObject == null) {
_addError("Unable to get product info for selected version " + workspaceProductKey);
if (releaseInfo.getProductKey(
).isQuarterly()) {

return;
liferayVersion = "7.4";
}
}

if (Objects.equals(initArgs.getLiferayProduct(), "commerce")) {
Expand Down Expand Up @@ -318,6 +322,8 @@ public void execute() throws Exception {
settings.setProfileName(profileName);

settings.save();

commandPostAction();
}

@Override
Expand All @@ -329,7 +335,7 @@ private void _addError(String msg) {
getBladeCLI().addErrors("init", Collections.singleton(msg));
}

private String _getDefaultProductKey(InitArgs initArgs) throws Exception {
private String _getDefaultProductKey(InitArgs initArgs) {
String liferayVersion = initArgs.getLiferayVersion();

if (liferayVersion.startsWith("portal") || liferayVersion.startsWith("dxp") ||
Expand All @@ -345,21 +351,17 @@ private String _getDefaultProductKey(InitArgs initArgs) throws Exception {
value -> value.startsWith(initArgs.getLiferayProduct() + "-" + initArgs.getLiferayVersion())
).findFirst();

if (!defaultVersion.isPresent()) {
return initArgs.getLiferayVersion();
}

return defaultVersion.get();
return defaultVersion.orElseGet(initArgs::getLiferayVersion);
}

private boolean _isPluginsSDK(File dir) {
if ((dir == null) || !dir.exists() || !dir.isDirectory()) {
return false;
}

List<String> names = Arrays.asList(dir.list());
List<String> names = Arrays.asList(Objects.requireNonNull(dir.list()));

if ((names != null) && names.contains("portlets") && names.contains("hooks") && names.contains("layouttpl") &&
if (names.contains("portlets") && names.contains("hooks") && names.contains("layouttpl") &&
names.contains("themes") && names.contains("build.properties") && names.contains("build.xml") &&
names.contains("build-common.xml") && names.contains("build-common-plugin.xml")) {

Expand All @@ -377,11 +379,7 @@ private boolean _isPluginsSDK70(File dir) {
File buildProperties = new File(dir, "build.properties");
Properties properties = new Properties();

InputStream in = null;

try {
in = new FileInputStream(buildProperties);

try (BufferedReader in = Files.newBufferedReader(buildProperties.toPath())) {
properties.load(in);

String sdkVersionValue = (String)properties.get("lp.version");
Expand All @@ -392,23 +390,14 @@ private boolean _isPluginsSDK70(File dir) {
}
catch (Exception exception) {
}
finally {
if (in != null) {
try {
in.close();
}
catch (Exception exception) {
}
}
}

return false;
}

private Version _makeCompatibleVersion(String targetPlatformVersion) {
int dash = targetPlatformVersion.indexOf("-");

Version productTargetPlatformVersion = null;
Version productTargetPlatformVersion;

if (dash != -1) {
productTargetPlatformVersion = Version.parseVersion(targetPlatformVersion.substring(0, dash));
Expand Down Expand Up @@ -489,8 +478,7 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttribu
});
}

@SuppressWarnings("unchecked")
private String _setProductAndVersionForMaven(Map<String, Object> productInfos, InitArgs initArgs) throws Exception {
private String _setProductAndVersionForMaven(Map<String, Object> releaseInfos, InitArgs initArgs) throws Exception {
String possibleProductKey = _getDefaultProductKey(initArgs);

if (possibleProductKey.startsWith("portal") || possibleProductKey.startsWith("dxp") ||
Expand All @@ -507,15 +495,15 @@ private String _setProductAndVersionForMaven(Map<String, Object> productInfos, I
return possibleProductKey;
}

for (Map.Entry<String, Object> entryKey : productInfos.entrySet()) {
for (Map.Entry<String, Object> entryKey : releaseInfos.entrySet()) {
ReleaseInfo releaseInfo = BladeUtil.getReleaseInfo(entryKey.getKey());

if (Objects.equals(possibleProductKey, releaseInfo.getTargetPlatformVersion())) {
possibleProductKey = entryKey.getKey();

String[] productKeyValues = possibleProductKey.split("-");

initArgs.setLiferayProduct(productKeyValues[0]);
initArgs.setLiferayProduct(
releaseInfo.getProductKey(
).getProduct());

return possibleProductKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ else if (dockerImageProperty.contains("dxp")) {
}
}
else {
Map<String, ProductKeyInfo> workspaceProductTargetPlatformVersions = BladeUtil.getWorkspaceProductTargetPlatformVersions(false);
Map<String, ProductKeyInfo> workspaceProductTargetPlatformVersions =
BladeUtil.getWorkspaceProductTargetPlatformVersions(false);

ProductKeyInfo productKeyInfo = workspaceProductTargetPlatformVersions.get(targetPlatformVersion);

Expand Down
Loading

0 comments on commit a24e758

Please sign in to comment.