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

INTELLIJ-288 Add support for Quarterly Releases in IntelliJ plugin #303

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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.liferay.ide.idea.util.CoreUtil;
import com.liferay.ide.idea.util.IntellijUtil;
import com.liferay.ide.idea.util.LiferayWorkspaceSupport;
import com.liferay.release.util.ReleaseEntry;

import java.io.File;

Expand Down Expand Up @@ -176,71 +177,69 @@ public void setupRootModel(@NotNull ModifiableRootModel modifiableRootModel) {

VirtualFile moduleParentDir = moduleDir.getParent();

StringBuilder sb = new StringBuilder();
List<String> args = new ArrayList<>();

sb.append("create ");
sb.append("-d \"");
sb.append(moduleParentDir.getPath());
sb.append("\" ");
sb.append("--base \"");
sb.append(project.getProjectFilePath());
sb.append("\" ");
args.add("create");

args.add("-d");
args.add(BladeCLI.quote(moduleParentDir.getPath()));

args.add("--base");
args.add(BladeCLI.quote(project.getProjectFilePath()));

String typeId = liferayProjectType.getId();

if (Objects.equals(typeId, LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) {
sb.append("-b ");
sb.append("maven ");
args.add("-b");
args.add("maven");
}

String targetPlatformVersion = LiferayWorkspaceSupport.getTargetPlatformVersion(project);

if (targetPlatformVersion != null) {
sb.append("-v ");
sb.append(targetPlatformVersion);
args.add("-v");
args.add(targetPlatformVersion);
}

ReleaseEntry releaseEntry = LiferayWorkspaceSupport.getReleaseEntry("portal", targetPlatformVersion);

if (releaseEntry != null) {
args.add("--liferay-product");
args.add(releaseEntry.getProduct());
}

sb.append(" ");
sb.append("-t ");
sb.append(_type);
sb.append(" ");
args.add("-t");
args.add(_type);

if (!CoreUtil.isNullOrEmpty(_className)) {
sb.append("-c ");
sb.append(_className);
sb.append(" ");
args.add("-c");
args.add(_className);
}

if (!CoreUtil.isNullOrEmpty(_packageName)) {
sb.append("-p ");
sb.append(_packageName);
sb.append(" ");
args.add("-p");
args.add(_packageName);
}

if (_type.equals("theme-contributor")) {
sb.append("-C ");
args.add("-C");

if (!CoreUtil.isNullOrEmpty(_contributorType)) {
sb.append(_contributorType);
args.add(_contributorType);
}
else {
sb.append(moduleDir.getName());
args.add(moduleDir.getName());
}

sb.append(" ");
}

if ((_type.equals("service") || _type.equals("service-wrapper")) && !CoreUtil.isNullOrEmpty(_serviceName)) {
sb.append("-s ");
sb.append(_serviceName);
sb.append(" ");
args.add("-s");
args.add(_serviceName);
}

sb.append("\"");
sb.append(moduleDir.getName());
sb.append("\" ");
args.add(BladeCLI.quote(moduleDir.getName()));

BladeCLI.execute(project, sb.toString());
BladeCLI.execute(project, args);

modifiableRootModel.addContentEntry(moduleDir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import java.nio.file.Path;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Stream;
Expand Down Expand Up @@ -179,35 +181,39 @@ public boolean validate() throws com.intellij.openapi.options.ConfigurationExcep
}

protected void initWorkspace(Project project) {
StringBuilder sb = new StringBuilder();
List<String> args = new ArrayList<>();

sb.append("--base ");
sb.append("\"");
sb.append(project.getBasePath());
sb.append("\" ");
sb.append("init ");
sb.append("-v ");
args.add("--base");
args.add(BladeCLI.quote(project.getBasePath()));
args.add("init");
args.add("-v");

if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) {
sb.append(_targetPlatform);
args.add(_targetPlatform);
}
else if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_GRADLE_WORKSPACE)) {
sb.append(_productVersion);
args.add(_productVersion);
}

sb.append(" ");
sb.append("-f ");
ReleaseEntry releaseEntry = LiferayWorkspaceSupport.getReleaseEntry("portal", _targetPlatform);

if (releaseEntry != null) {
args.add("--liferay-product");
args.add(releaseEntry.getProduct());
}

args.add("-f");

if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) {
sb.append("-b ");
sb.append("maven");
args.add("-b");
args.add("maven");
}

PropertiesComponent component = PropertiesComponent.getInstance(project);

component.setValue(WorkspaceConstants.WIZARD_LIFERAY_VERSION_FIELD, _liferayProductGroupVersion);

BladeCLI.executeWithLatestBlade(sb.toString());
BladeCLI.executeWithLatestBlade(args);

if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_GRADLE_WORKSPACE)) {
try {
Expand Down Expand Up @@ -235,8 +241,6 @@ else if (_liferayProjectType.equals(LiferayProjectType.LIFERAY_MAVEN_WORKSPACE))

properties.setProperty(WorkspaceConstants.WORKSPACE_BOM_VERSION, _targetPlatform);

ReleaseEntry releaseEntry = LiferayWorkspaceSupport.getReleaseEntry("portal", _targetPlatform);

if (Objects.nonNull(releaseEntry)) {
properties.setProperty(WorkspaceConstants.BUNDLE_URL_PROPERTY, releaseEntry.getBundleURL());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,26 @@ private VirtualFile _createAndGetContentEntry() {

private void _createProject(VirtualFile projectRoot, Project project) {
VirtualFile virtualFile = projectRoot.getParent();
StringBuilder sb = new StringBuilder();

sb.append("create -d \"");
sb.append(virtualFile.getPath());
sb.append("\" ");
sb.append("--base \"");
sb.append(project.getBasePath());
sb.append("\" -t ");
sb.append("modules-ext ");
sb.append("-m ");
sb.append(_originalModuleName);

List<String> args = new ArrayList<>();

args.add("create -d");
args.add(BladeCLI.quote(virtualFile.getPath()));
args.add("--base");
args.add(BladeCLI.quote(project.getBasePath()));
args.add("-t");
args.add("modules-ext");
args.add("-m");
args.add(_originalModuleName);

if (Objects.nonNull(project) && !LiferayWorkspaceSupport.isFlexibleLiferayWorkspace(project)) {
sb.append(" -M ");
sb.append(_originalModuleVersion);
args.add("-M");
args.add(_originalModuleVersion);
}

sb.append(" ");
sb.append("\"");
sb.append(projectRoot.getName());
sb.append("\"");
args.add(BladeCLI.quote(projectRoot.getName()));

BladeCLI.execute(project, sb.toString());
BladeCLI.execute(project, args);
}

private void _refreshProject(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.liferay.ide.idea.util.CoreUtil;
import com.liferay.ide.idea.util.IntellijUtil;
import com.liferay.ide.idea.util.LiferayWorkspaceSupport;
import com.liferay.release.util.ReleaseEntry;

import java.io.File;

Expand Down Expand Up @@ -187,55 +188,55 @@ private VirtualFile _createAndGetContentEntry() {

private void _createProject(VirtualFile projectRoot, Project project, String typeId) {
VirtualFile virtualFile = projectRoot.getParent();
StringBuilder sb = new StringBuilder();

sb.append("create -d \"");
sb.append(virtualFile.getPath());
sb.append("\"");
sb.append(" ");
List<String> args = new ArrayList<>();

if (Objects.equals(typeId, LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) {
sb.append("-b ");
sb.append("maven ");
args.add("create -d");
args.add(BladeCLI.quote(virtualFile.getPath()));

String targetPlatformVersion = LiferayWorkspaceSupport.getTargetPlatformVersion(project);

String targetPlatformVersion = LiferayWorkspaceSupport.getTargetPlatformVersion(project);
if (Objects.equals(typeId, LiferayProjectType.LIFERAY_MAVEN_WORKSPACE)) {
args.add("-b");
args.add("maven");

if (targetPlatformVersion != null) {
sb.append("-v ");
sb.append(targetPlatformVersion);
sb.append(" ");
args.add("-v");
args.add(targetPlatformVersion);
}
}
else {
sb.append("-v ");
sb.append(_liferayProductGroupVersion);
sb.append(" ");
args.add("-v");
args.add(_liferayProductGroupVersion);
}

if (targetPlatformVersion != null) {
ReleaseEntry releaseEntry = LiferayWorkspaceSupport.getReleaseEntry("portal", targetPlatformVersion);

if (releaseEntry != null) {
args.add("--liferay-product");
args.add(releaseEntry.getProduct());
}
}

sb.append("--base \"");
sb.append(project.getBasePath());
sb.append("\" -t ");
sb.append("spring-mvc-portlet ");
sb.append("\"");
sb.append(projectRoot.getName());
sb.append("\"");
sb.append(" ");
sb.append("--framework ");
sb.append(_framework);
sb.append(" ");
sb.append("--framework-dependencies ");
sb.append(_frameworkDependencies);
sb.append(" ");
sb.append("--view-type ");
sb.append(_viewType);
args.add("--base");
args.add(BladeCLI.quote(project.getBasePath()));
args.add("-t");
args.add("spring-mvc-portlet");
args.add(BladeCLI.quote(projectRoot.getName()));
args.add("--framework");
args.add(_framework);
args.add("--framework-dependencies");
args.add(_frameworkDependencies);
args.add("--view-type");
args.add(_viewType);

if (!CoreUtil.isNullOrEmpty(_packageName)) {
sb.append(" ");
sb.append("-p ");
sb.append(_packageName);
args.add("-p");
args.add(_packageName);
}

BladeCLI.execute(project, sb.toString());
BladeCLI.execute(project, args);
}

private void _refreshProject(Project project) {
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/liferay/ide/idea/util/BladeCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.nio.file.Files;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
Expand All @@ -41,6 +43,10 @@ public class BladeCLI {

public static final String BLADE_LATEST = "blade-latest.jar";

public static String[] execute(File bladeJar, Collection<String> args) {
return execute(bladeJar, String.join(" ", args));
}

public static String[] execute(File bladeJar, String args) {
Project project = new Project();
Java javaTask = new Java();
Expand Down Expand Up @@ -149,11 +155,11 @@ else if (hasErrors) {
return lines.toArray(new String[0]);
}

public static String[] execute(com.intellij.openapi.project.Project liferayProject, String args) {
public static String[] execute(com.intellij.openapi.project.Project liferayProject, Collection<String> args) {
return execute(getBladeJar(getBladeJarVersion(liferayProject)), args);
}

public static String[] executeWithLatestBlade(String args) {
public static String[] executeWithLatestBlade(Collection<String> args) {
return execute(getBladeJar(BLADE_LATEST), args);
}

Expand Down Expand Up @@ -220,7 +226,7 @@ public static synchronized String getBladeJarVersion(com.intellij.openapi.projec
public static synchronized String[] getProjectTemplates(com.intellij.openapi.project.Project liferayProject) {
List<String> templateNames = new ArrayList<>();

String[] executeResult = execute(liferayProject, "create -l");
String[] executeResult = execute(liferayProject, Arrays.asList("create", "-l"));

for (String name : executeResult) {
String trimmedName = name.trim();
Expand All @@ -236,6 +242,10 @@ public static synchronized String[] getProjectTemplates(com.intellij.openapi.pro
return templateNames.toArray(new String[0]);
}

public static String quote(String s) {
return "\"" + s + "\"";
}

private static String _getBladeVersion(InputStream inputStream) {
try (ZipInputStream zipInput = new ZipInputStream(inputStream)) {
ZipEntry zipEntry;
Expand Down
Loading
Loading