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

Use Gradle jdk to run MOE build #8

Merged
merged 13 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
247 changes: 117 additions & 130 deletions src/main/java/org/moe/idea/MOESdkPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,18 @@

package org.moe.idea;

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.module.impl.scopes.ModuleWithDependenciesScope;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import org.moe.common.utils.ProjectUtil;
import org.moe.gradle.model.MOESdkProperties;
import org.moe.idea.model.GradleModuleModel;
import org.moe.idea.sdk.MOESdkType;
import org.moe.idea.utils.ModuleUtils;
import org.moe.idea.utils.logger.LoggerFactory;
import res.MOEIcons;
import res.MOEText;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

public class MOESdkPlugin {

Expand All @@ -50,78 +37,78 @@ public static String getResourcesFolderName() {
return "resources";
}

public static String getSdkRootPath(Module module) {
// Read sdk property using facet
MOESdkProperties sdkProperties = GradleModuleModel.getSdkProperties(module);
if (sdkProperties != null) {
return sdkProperties.getHome();
}

// For compatible with old Gradle plugin
final Properties properties = ProjectUtil
.retrievePropertiesFromGradle(new File(ModuleUtils.getModulePath(module)), ProjectUtil.SDK_PROPERTIES_TASK, MOESdkType.getJavaHome(module));

String sdkPath = properties.getProperty(ProjectUtil.SDK_PATH_KEY);

if (sdkPath == null || sdkPath.isEmpty()) {
Messages.showMessageDialog(MOEText.get("Invalid.SDK.Path"), "Error", MOEIcons.MOELogo);
}

return sdkPath;
}

public static void getMOESdk(Module module) {
MOESdkType.getMOESdk(module);
}

public static List<File> getSdkJavaLibraries(String sdkPath) {
List<File> jars = new ArrayList<File>();

List<File> files = getSdkJars(sdkPath);

for (File file : files) {
if (!file.getName().endsWith("-dex.jar") &&
!file.getName().endsWith("-javadoc.jar")) {
jars.add(file);
}
}

return jars;
}

public static List<File> getSdkJavaDocs(String sdkPath) {
List<File> jars = new ArrayList<File>();

List<File> files = getSdkJars(sdkPath);

for (File file : files) {
if (file.getName().endsWith("-javadoc.jar")) {
jars.add(file);
}
}

return jars;
}

private static List<File> getSdkJars(String sdkPath) {
List<File> jars = new ArrayList<File>();

File libsDir = new File(sdkPath, "sdk");

File[] files = libsDir.listFiles();

if(files == null) {
return jars;
}

for (File file : files) {
if (file.getName().endsWith(".jar")) {
jars.add(file);
}
}

return jars;
}
// public static String getSdkRootPath(Module module) {
// // Read sdk property using facet
// MOESdkProperties sdkProperties = GradleModuleModel.getSdkProperties(module);
// if (sdkProperties != null) {
// return sdkProperties.getHome();
// }
//
// // For compatible with old Gradle plugin
// final Properties properties = ProjectUtil
// .retrievePropertiesFromGradle(new File(ModuleUtils.getModulePath(module)), ProjectUtil.SDK_PROPERTIES_TASK, MOESdkType.getJavaHome(module));
//
// String sdkPath = properties.getProperty(ProjectUtil.SDK_PATH_KEY);
//
// if (sdkPath == null || sdkPath.isEmpty()) {
// Messages.showMessageDialog(MOEText.get("Invalid.SDK.Path"), "Error", MOEIcons.MOELogo);
// }
//
// return sdkPath;
// }
//
// public static void getMOESdk(Module module) {
// MOESdkType.getMOESdk(module);
// }
//
// public static List<File> getSdkJavaLibraries(String sdkPath) {
// List<File> jars = new ArrayList<File>();
//
// List<File> files = getSdkJars(sdkPath);
//
// for (File file : files) {
// if (!file.getName().endsWith("-dex.jar") &&
// !file.getName().endsWith("-javadoc.jar")) {
// jars.add(file);
// }
// }
//
// return jars;
// }
//
// public static List<File> getSdkJavaDocs(String sdkPath) {
// List<File> jars = new ArrayList<File>();
//
// List<File> files = getSdkJars(sdkPath);
//
// for (File file : files) {
// if (file.getName().endsWith("-javadoc.jar")) {
// jars.add(file);
// }
// }
//
// return jars;
// }
//
// private static List<File> getSdkJars(String sdkPath) {
// List<File> jars = new ArrayList<File>();
//
// File libsDir = new File(sdkPath, "sdk");
//
// File[] files = libsDir.listFiles();
//
// if(files == null) {
// return jars;
// }
//
// for (File file : files) {
// if (file.getName().endsWith(".jar")) {
// jars.add(file);
// }
// }
//
// return jars;
// }


public static Collection<Module> getMoeModules(Project project) {
Expand Down Expand Up @@ -173,31 +160,31 @@ public static boolean isValidMoeModule(Module module, boolean isMOEApp) {
return false;
}

public static boolean isMoeJarsInModule(Module module) {
if (module == null) {
return false;
}
if (module.isDisposed()) {
LOG.info("Invalid MOE module, already disposed (" + module.getName() + ")");
return false;
}

ModuleWithDependenciesScope libraries = (ModuleWithDependenciesScope) module.getModuleWithLibrariesScope();
Collection<VirtualFile> roots = libraries.getRoots();

boolean coreFound = false;
boolean iosFound = false;
for (VirtualFile vf : roots) {
String name = vf.getName();
coreFound = coreFound ? coreFound : name.equals("moe-core.jar");
iosFound = iosFound ? iosFound : name.equals("moe-ios.jar");
if (coreFound & iosFound) {
return true;
}
}

return false;
}
// public static boolean isMoeJarsInModule(Module module) {
Noisyfox marked this conversation as resolved.
Show resolved Hide resolved
// if (module == null) {
// return false;
// }
// if (module.isDisposed()) {
// LOG.info("Invalid MOE module, already disposed (" + module.getName() + ")");
// return false;
// }
//
// ModuleWithDependenciesScope libraries = (ModuleWithDependenciesScope) module.getModuleWithLibrariesScope();
// Collection<VirtualFile> roots = libraries.getRoots();
//
// boolean coreFound = false;
// boolean iosFound = false;
// for (VirtualFile vf : roots) {
// String name = vf.getName();
// coreFound = coreFound ? coreFound : name.equals("moe-core.jar");
// iosFound = iosFound ? iosFound : name.equals("moe-ios.jar");
// if (coreFound & iosFound) {
// return true;
// }
// }
//
// return false;
// }

public static Module findModuleForFile(Project project, VirtualFile file) {

Expand All @@ -222,24 +209,24 @@ public static Module findModuleForFile(Project project, VirtualFile file) {
return module;
}

public static String getXcodeBuildSymPath(String modulePath) {
String symPath = modulePath + File.separator + "build" + File.separator + "moe" + File.separator + "xcodebuild" + File.separator +"sym";
return symPath;
}

public static String getPluginVersion() {
String version = "0.0.0.0";

PluginId pluginId = PluginManager.getPluginByClassName(MOESdkPlugin.class.getCanonicalName());

if(pluginId != null) {
IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId);

if(plugin != null) {
version = plugin.getVersion();
}
}

return version;
}
// public static String getXcodeBuildSymPath(String modulePath) {
// String symPath = modulePath + File.separator + "build" + File.separator + "moe" + File.separator + "xcodebuild" + File.separator +"sym";
// return symPath;
// }
//
// public static String getPluginVersion() {
// String version = "0.0.0.0";
//
// PluginId pluginId = PluginManager.getPluginByClassName(MOESdkPlugin.class.getCanonicalName());
//
// if(pluginId != null) {
// IdeaPluginDescriptor plugin = PluginManager.getPlugin(pluginId);
//
// if(plugin != null) {
// version = plugin.getVersion();
// }
// }
//
// return version;
// }
}
4 changes: 2 additions & 2 deletions src/main/java/org/moe/idea/actions/MOEOpenXcodeAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.moe.common.utils.ProjectUtil;
import org.moe.gradle.model.MOEXcodeProperties;
import org.moe.idea.MOESdkPlugin;
import org.moe.idea.compiler.MOEGradleRunner;
import org.moe.idea.model.GradleModuleModel;
import org.moe.idea.sdk.MOESdkType;
import org.moe.idea.utils.ModuleUtils;

import java.io.File;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void actionPerformed(final AnActionEvent anActionEvent) {
final File modulePath = new File(ModuleUtils.getModulePath(module));
File javaHome;
try {
javaHome = MOESdkType.requireJavaHome(module);
javaHome = MOEGradleRunner.requireGradleJavaHome(module);
} catch (IOException e) {
Messages.showErrorDialog(e.getMessage(), "Open Xcode Project");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.moe.common.utils.ProjectUtil;
import org.moe.gradle.model.MOEXcodeProperties;
import org.moe.idea.MOESdkPlugin;
import org.moe.idea.compiler.MOEGradleRunner;
import org.moe.idea.model.GradleModuleModel;
import org.moe.idea.sdk.MOESdkType;
import org.moe.idea.utils.ModuleUtils;

import java.io.File;
Expand All @@ -60,7 +60,7 @@ public void actionPerformed(final AnActionEvent anActionEvent) {
final File modulePath = new File(ModuleUtils.getModulePath(module));
File javaHome;
try {
javaHome = MOESdkType.requireJavaHome(module);
javaHome = MOEGradleRunner.requireGradleJavaHome(module);
} catch (IOException e) {
Messages.showErrorDialog(e.getMessage(), "Open Xcode Project");
return;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/moe/idea/binding/GeneratorRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.moe.common.exec.GradleExec;
import org.moe.common.exec.IKillListener;
import org.moe.document.pbxproj.ProjectException;
import org.moe.idea.sdk.MOESdkType;
import org.moe.idea.compiler.MOEGradleRunner;
import org.moe.idea.ui.MOEToolWindow;
import org.moe.idea.utils.ModuleUtils;

Expand Down Expand Up @@ -102,7 +102,7 @@ private void runInternal(final ProgressIndicator progress) throws ProjectExcepti

progress.setFraction(0.2);

GradleExec exec = new GradleExec(moduleFile, MOESdkType.requireJavaHome(module));
GradleExec exec = new GradleExec(moduleFile, MOEGradleRunner.requireGradleJavaHome(module));

exec.getArguments().add("moeNatJGen");
exec.getArguments().add("-Draw-binding-output");
Expand Down
Loading