Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPD-32781 Update Blade CLI to use Project Templates with greater version ranges #338

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Private-Package:\
com.fasterxml.jackson.*,\
\
com.liferay.blade.gradle.tooling,\
com.liferay.release.util,\
com.liferay.release.util.internal,\
com.liferay.release.util.internal.util,\
com.liferay.release.util.internal.constants,\
\
groovy.json,\
\
Expand Down
3 changes: 2 additions & 1 deletion cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ 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.295"
api group: "com.liferay", name: "com.liferay.project.templates", version: "5.0.296"
api group: "com.liferay", name: "com.liferay.release.util", version: "1.0.0"
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"
Expand Down
10 changes: 6 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 @@ -32,7 +32,7 @@
import com.liferay.blade.cli.util.ProcessesUtil;
import com.liferay.blade.cli.util.Prompter;
import com.liferay.blade.cli.util.ReleaseUtil;
import com.liferay.blade.cli.util.ResourceUtil;
import com.liferay.release.util.ReleaseEntry;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -408,13 +408,15 @@ public void printUsage(String command, String message) {
public void run(String[] args) throws Exception {
try {
if (ArrayUtil.contains(args, "--trace")) {
ResourceUtil.setTrace(true);

// TODO restore ability to get more logging

}

if (ArrayUtil.contains(args, "--refresh-releases")) {
System.out.println("Checking for new releases...");

ReleaseUtil.populateReleases(0);
ReleaseUtil.initialize(0);
}

_removeOutDatedTempDir();
Expand Down Expand Up @@ -880,7 +882,7 @@ private Map<String, String> _buildMavenPossibleValuesMap(
for (int x = 1; it.hasNext(); x++) {
String option = it.next();

ReleaseUtil.ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(option);
ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(option);

optionsMap.put(String.valueOf(x), releaseEntry.getTargetPlatformVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.liferay.project.templates.extensions.ProjectTemplatesArgs;
import com.liferay.project.templates.extensions.util.Validator;
import com.liferay.project.templates.extensions.util.VersionUtil;
import com.liferay.release.util.ReleaseEntry;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -1158,8 +1159,8 @@ private List<String> _getReleaseApirtifactIds() {

String productKey = productKeyOpt.get();

String targetPlatformVersion = ReleaseUtil.withReleaseEntry(
productKey, ReleaseUtil.ReleaseEntry::getTargetPlatformVersion);
String targetPlatformVersion = ReleaseUtil.getFromReleaseEntry(
productKey, ReleaseEntry::getTargetPlatformVersion);

if (targetPlatformVersion == null) {
return Collections.emptyList();
Expand Down
23 changes: 13 additions & 10 deletions cli/src/main/java/com/liferay/blade/cli/command/CreateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
import com.liferay.blade.cli.WorkspaceProvider;
import com.liferay.blade.cli.gradle.GradleWorkspaceProvider;
import com.liferay.blade.cli.util.BladeUtil;
import com.liferay.blade.cli.util.ReleaseUtil;
import com.liferay.blade.cli.util.StringUtil;
import com.liferay.project.templates.ProjectTemplates;
import com.liferay.project.templates.extensions.ProjectTemplatesArgs;
import com.liferay.project.templates.extensions.ProjectTemplatesArgsExt;
import com.liferay.project.templates.extensions.util.ProjectTemplatesUtil;
import com.liferay.project.templates.extensions.util.VersionUtil;
import com.liferay.release.util.ReleaseEntry;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -353,7 +354,9 @@ protected ProjectTemplatesArgs getProjectTemplateArgs(
throw new IOException("Cannot determine Liferay Version. Please enter a valid value for Liferay Version.");
}

projectTemplatesArgs.setLiferayVersion(liferayVersion.get());
ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(liferayVersion.get());

projectTemplatesArgs.setLiferayVersion(releaseEntry.getTargetPlatformVersion());

projectTemplatesArgs.setName(name);
projectTemplatesArgs.setPackageName(createArgs.getPackageName());
Expand Down Expand Up @@ -472,10 +475,6 @@ 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)) {

Expand All @@ -487,14 +486,18 @@ private String _checkTemplateVersionRange(File templateFile, ProjectTemplatesArg

VersionRange versionRange = new VersionRange(versionRangeValue);

String liferayVersionString = String.format(
"%s.%s", VersionUtil.getMajorVersion(versionString), VersionUtil.getMinorVersion(versionString));
if (!versionRange.includes(
Version.parseVersion(
versionString.replaceAll(
"[a-z]", ""
).replaceAll(
"-", "."
)))) {

if (!versionRange.includes(Version.parseVersion(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);
projectTemplatesArgs.getTemplate(), versionRange, versionString);
}
}
catch (Exception exception) {
Expand Down
45 changes: 5 additions & 40 deletions cli/src/main/java/com/liferay/blade/cli/command/InitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.liferay.project.templates.ProjectTemplates;
import com.liferay.project.templates.extensions.ProjectTemplatesArgs;
import com.liferay.project.templates.extensions.util.FileUtil;
import com.liferay.release.util.ReleaseEntry;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -31,7 +32,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;

Expand All @@ -54,11 +54,11 @@ public void execute() throws Exception {
InitArgs initArgs = getArgs();

if (initArgs.isList()) {
ReleaseUtil.releaseEntriesStream(
ReleaseUtil.getReleaseEntryStream(
).filter(
releaseEntry -> initArgs.isAll() || releaseEntry.isPromoted()
).map(
ReleaseUtil.ReleaseEntry::getReleaseKey
ReleaseEntry::getReleaseKey
).forEach(
bladeCLI::out
);
Expand Down Expand Up @@ -191,17 +191,15 @@ public void execute() throws Exception {

projectTemplatesArgs.setGradle(!mavenBuild);

Optional<ReleaseUtil.ReleaseEntry> releaseEntryOptional = _getDefaultReleaseEntry(
ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(
initArgs.getLiferayProduct(), initArgs.getLiferayVersion());

if (!releaseEntryOptional.isPresent()) {
if (releaseEntry == null) {
_addError("Unable to get product info for selected version " + initArgs.getLiferayVersion());

return;
}

ReleaseUtil.ReleaseEntry releaseEntry = releaseEntryOptional.get();

String workspaceProductKey = releaseEntry.getReleaseKey();

if (!mavenBuild && _legacyProductKeys.contains(workspaceProductKey)) {
Expand Down Expand Up @@ -290,39 +288,6 @@ private void _addError(String msg) {
getBladeCLI().addErrors("init", Collections.singleton(msg));
}

private Optional<ReleaseUtil.ReleaseEntry> _getDefaultReleaseEntry(String liferayProduct, String liferayVersion) {
ReleaseUtil.ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(liferayVersion);

if (releaseEntry.getReleaseKey() != null) {
return Optional.of(releaseEntry);
}

Optional<ReleaseUtil.ReleaseEntry> defaultVersion = ReleaseUtil.withReleaseEntriesStream(
stream -> stream.filter(
releaseEntry1 -> Objects.equals(releaseEntry1.getProduct(), liferayProduct)
).filter(
releaseEntry1 -> Objects.equals(releaseEntry1.getTargetPlatformVersion(), liferayVersion)
).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()) {
defaultVersion = ReleaseUtil.withReleaseEntriesStream(
stream -> stream.filter(
releaseEntry1 -> Objects.equals(releaseEntry1.getTargetPlatformVersion(), liferayVersion)
).findFirst());
}

return defaultVersion;
}

private boolean _isPluginsSDK(File dir) {
if ((dir == null) || !dir.exists() || !dir.isDirectory()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.liferay.blade.cli.command.validator;

import com.liferay.blade.cli.util.ReleaseUtil;
import com.liferay.release.util.ReleaseEntry;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -19,14 +20,14 @@ public class LiferayDefaultVersionValidator extends LiferayMoreVersionValidator

@Override
public List<String> get() {
return ReleaseUtil.withReleaseEntriesStream(
stream -> stream.filter(
ReleaseUtil.ReleaseEntry::isPromoted
).map(
ReleaseUtil.ReleaseEntry::getReleaseKey
).collect(
Collectors.toList()
));
return ReleaseUtil.getReleaseEntryStream(
).filter(
ReleaseEntry::isPromoted
).map(
ReleaseEntry::getReleaseKey
).collect(
Collectors.toList()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.beust.jcommander.ParameterException;

import com.liferay.blade.cli.util.ReleaseUtil;
import com.liferay.release.util.ReleaseEntry;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -19,17 +20,17 @@ public class LiferayMoreVersionValidator implements ValidatorSupplier {

@Override
public List<String> get() {
return ReleaseUtil.withReleaseEntriesStream(
stream -> stream.map(
ReleaseUtil.ReleaseEntry::getReleaseKey
).collect(
Collectors.toList()
));
return ReleaseUtil.getReleaseEntryStream(
).map(
ReleaseEntry::getReleaseKey
).collect(
Collectors.toList()
);
}

@Override
public void validate(String name, String value) throws ParameterException {
ReleaseUtil.ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(value);
ReleaseEntry releaseEntry = ReleaseUtil.getReleaseEntry(value);

if (releaseEntry == null) {
throw new ParameterException(value + " is not a valid value.");
Expand Down
Loading
Loading