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

Assume the maven wrapper is in the directory with the build file pom.xml #569

Merged
merged 1 commit into from
Nov 10, 2023
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 @@ -43,7 +43,11 @@ protected void executeLibertyAction(LibertyModule libertyModule) {
DebugModeHandler debugHandler = new DebugModeHandler();
String buildSettingsCmd;
try {
buildSettingsCmd = projectType.equals(Constants.LIBERTY_MAVEN_PROJECT) ? LibertyMavenUtil.getMavenSettingsCmd(project) : LibertyGradleUtil.getGradleSettingsCmd(project);
if(projectType.equals(Constants.LIBERTY_MAVEN_PROJECT)) {
buildSettingsCmd = LibertyMavenUtil.getMavenSettingsCmd(project, buildFile);
} else {
buildSettingsCmd = LibertyGradleUtil.getGradleSettingsCmd(project);
}
} catch (LibertyException ex) {
// in this case, the settings specified to mvn or gradle are invalid and an error was launched by getMavenSettingsCmd or getGradleSettingsCmd.
// Log a warning because a Logger.error creates an entry on "IDE Internal Errors", which we do not want.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ protected void executeLibertyAction(LibertyModule libertyModule) {
String projectType = libertyModule.getProjectType();
String startCmd;
try {
startCmd = projectType.equals(Constants.LIBERTY_MAVEN_PROJECT) ? LibertyMavenUtil.getMavenSettingsCmd(project) + Constants.LIBERTY_MAVEN_START_CONTAINER_CMD : LibertyGradleUtil.getGradleSettingsCmd(project) + Constants.LIBERTY_GRADLE_START_CONTAINER_CMD;
if(projectType.equals(Constants.LIBERTY_MAVEN_PROJECT)) {
startCmd = LibertyMavenUtil.getMavenSettingsCmd(project, buildFile) + Constants.LIBERTY_MAVEN_START_CONTAINER_CMD;
} else {
startCmd = LibertyGradleUtil.getGradleSettingsCmd(project) + Constants.LIBERTY_GRADLE_START_CONTAINER_CMD;
}
startCmd += libertyModule.getCustomStartParams();
} catch (LibertyException ex) {
// in this case, the settings specified to mvn or gradle are invalid and an error was launched by getMavenSettingsCmd or getGradleSettingsCmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*******************************************************************************/
package io.openliberty.tools.intellij.util;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.vfs.VirtualFile;
Expand All @@ -35,6 +36,7 @@
import org.apache.maven.artifact.versioning.ComparableVersion;

public class LibertyMavenUtil {
private static Logger LOGGER = Logger.getInstance(LibertyMavenUtil.class);

/**
* Return the project name given a pom.xml build file
Expand Down Expand Up @@ -199,12 +201,12 @@ private static boolean containerVersion(String version){
* @return String command to execute in the terminal or an exception to display
* @throws LibertyException
*/
public static String getMavenSettingsCmd(Project project) throws LibertyException {
public static String getMavenSettingsCmd(Project project, VirtualFile buildFile) throws LibertyException {
MavenGeneralSettings mavenSettings = MavenWorkspaceSettingsComponent.getInstance(project).getSettings().getGeneralSettings();
String mavenHome = mavenSettings.getMavenHome();
if (MavenServerManager.WRAPPED_MAVEN.equals(mavenHome)) {
// it is set to use the wrapper
return getLocalMavenWrapper(project);
return getLocalMavenWrapper(buildFile);
} else {
// try to use maven home path defined in the settings
return getCustomMavenPath(project, mavenHome);
Expand All @@ -214,19 +216,19 @@ public static String getMavenSettingsCmd(Project project) throws LibertyExceptio
/**
* Get the local wrapper path for Maven that is in the project level
*
* @param project liberty project
* @param buildFile the build file specified in the application project directory
* @return the Maven wrapper path to be executed or an exception to display
* @throws LibertyException
*/
private static String getLocalMavenWrapper(Project project) throws LibertyException {
private static String getLocalMavenWrapper(VirtualFile buildFile) throws LibertyException {
String mvnw = SystemInfo.isWindows ? ".\\mvnw.cmd" : "./mvnw";
File file = new File(project.getBasePath(), mvnw);
if (!file.exists()){
File wrapper = new File(buildFile.getParent().getPath(), mvnw);
if (!wrapper.exists()){
String translatedMessage = LocalizedResourceUtil.getMessage("maven.wrapper.does.not.exist");
throw new LibertyException("A Maven wrapper for the project could not be found. Make sure to configure a " +
"valid Maven wrapper or change the build preferences for Maven inside IntelliJ Maven preferences.", translatedMessage);
}
if (!file.canExecute()) {
if (!wrapper.canExecute()) {
String translatedMessage = LocalizedResourceUtil.getMessage("maven.wrapper.cannot.execute");
throw new LibertyException("Could not execute Maven wrapper because the process does not have permission to " +
"execute it. Consider giving executable permission for the Maven wrapper file or changing the build " +
Expand All @@ -249,6 +251,7 @@ private static String getCustomMavenPath(Project project, String customMavenHome
String translatedMessage = LocalizedResourceUtil.getMessage("maven.invalid.build.preference");
throw new LibertyException("Make sure to configure a valid path for Maven home path inside IntelliJ Maven preferences.", translatedMessage);
}

// When a custom maven is specified, IntelliJ settings force it to point to the root folder and consider the subfolders invalid,
// and consequently, it will return null. For this reason, we need to use ./bin/mvn in order to execute maven.
String maven = SystemInfo.isWindows ? "mvn.cmd" : "mvn";
Expand All @@ -261,7 +264,7 @@ private static String getCustomMavenPath(Project project, String customMavenHome
String mavenJdk = getMavenJdkPath(project);
String mavenPath = mavenHomeFile.getAbsolutePath();
String classworldsPath = LibertyMavenUtil.getMavenClassworldsJarPath(mavenPath);
File java = new File (new File(mavenJdk, "bin"), "java");
File java = new File (new File(mavenJdk, "bin"), "java"); // mavenJdk could be null, checked later
File classworldsConf = MavenUtil.getMavenConfFile(mavenHomeFile);

if (java.exists() && classworldsConf.exists() && classworldsPath != null && mavenJdk != null) {
Expand Down