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

Feature/haxe tests #131

Merged
merged 5 commits into from
Mar 3, 2015
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 common/src/com/intellij/plugins/haxe/config/HaxeTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public String getTargetFileNameWithExtension(String fileName) {
this.description = description;
}

public String getFlag() {
return flag;
}

public String getCompilerFlag() {
return "-" + flag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public interface CompilationContext {

String getModuleName();

String getCompilationClass();
String getOutputFileName();
Boolean getIsTestBuild();

void errorHandler(String message);

void log(String message);
Expand All @@ -75,6 +79,8 @@ public interface CompilationContext {

void handleOutput(String[] lines);

HaxeTarget getHaxeTarget();

String getModuleDirPath();
}

Expand All @@ -84,8 +90,8 @@ public static boolean compile(final CompilationContext context) {
context.log("Module " + context.getModuleName() + " is excluded from compilation.");
return true;
}
final String mainClass = settings.getMainClass();
final String fileName = settings.getOutputFileName();
final String mainClass = context.getCompilationClass();
final String fileName = context.getOutputFileName();

if (settings.isUseUserPropertiesToBuild()) {
if (mainClass == null || mainClass.length() == 0) {
Expand All @@ -98,7 +104,7 @@ public static boolean compile(final CompilationContext context) {
}
}

final HaxeTarget target = settings.getHaxeTarget();
final HaxeTarget target = context.getHaxeTarget();
final NMETarget nmeTarget = settings.getNmeTarget();
final OpenFLTarget openFLTarget = settings.getOpenFLTarget();

Expand Down Expand Up @@ -164,7 +170,7 @@ else if (settings.isUseHxmlToBuild()) {
if (endIndex > 0) {
workingPath = hxmlPath.substring(0, endIndex);
}
if (context.isDebug() && settings.getHaxeTarget() == HaxeTarget.FLASH) {
if (context.isDebug() && context.getHaxeTarget() == HaxeTarget.FLASH) {
commandLine.add("-D");
commandLine.add("fdb");
commandLine.add("-debug");
Expand Down Expand Up @@ -225,7 +231,7 @@ public void processTerminated(ProcessEvent event) {
private static void setupUserProperties(List<String> commandLine, CompilationContext context) {
final HaxeModuleSettingsBase settings = context.getModuleSettings();
commandLine.add("-main");
commandLine.add(settings.getMainClass());
commandLine.add(context.getCompilationClass());

final StringTokenizer argumentsTokenizer = new StringTokenizer(settings.getArguments());
while (argumentsTokenizer.hasMoreTokens()) {
Expand All @@ -235,7 +241,7 @@ private static void setupUserProperties(List<String> commandLine, CompilationCon
if (context.isDebug()) {
commandLine.add("-debug");
}
if (settings.getHaxeTarget() == HaxeTarget.FLASH && context.isDebug()) {
if (context.getHaxeTarget() == HaxeTarget.FLASH && context.isDebug()) {
commandLine.add("-D");
commandLine.add("fdb");
}
Expand All @@ -245,8 +251,8 @@ private static void setupUserProperties(List<String> commandLine, CompilationCon
commandLine.add(sourceRoot);
}

commandLine.add(settings.getHaxeTarget().getCompilerFlag());
commandLine.add(settings.getOutputFileName());
commandLine.add(context.getHaxeTarget().getCompilerFlag());
commandLine.add(context.getOutputFileName());
}

private static void setupNME(List<String> commandLine, CompilationContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.plugins.haxe.HaxeCommonBundle;
import com.intellij.plugins.haxe.compilation.HaxeCompilerError;
import com.intellij.plugins.haxe.config.HaxeTarget;
import com.intellij.plugins.haxe.module.HaxeModuleSettingsBase;
import com.intellij.plugins.haxe.util.HaxeCommonCompilerUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.apache.velocity.texen.util.FileUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -133,6 +135,21 @@ public String getModuleName() {
return module.getName();
}

@Override
public String getCompilationClass() {
return getModuleSettings().getMainClass();
}

@Override
public String getOutputFileName() {
return getModuleSettings().getOutputFileName();
}

@Override
public Boolean getIsTestBuild() {
return false;
}

@Override
public void errorHandler(String message) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, message));
Expand Down Expand Up @@ -205,6 +222,11 @@ public void handleOutput(String[] lines) {
}*/
}

@Override
public HaxeTarget getHaxeTarget() {
return getModuleSettings().getHaxeTarget();
}

@Override
public String getModuleDirPath() {
return getWorkingDirectoryPath();
Expand Down
2 changes: 2 additions & 0 deletions src/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
<!-- HXML END -->

<programRunner implementation="com.intellij.plugins.haxe.runner.HaxeRunner"/>
<programRunner implementation="com.intellij.plugins.haxe.tests.runner.HaxeTestsRunner"/>

<lang.parserDefinition language="Haxe" implementationClass="com.intellij.plugins.haxe.lang.parser.HaxeParserDefinition"/>
<lang.formatter language="Haxe" implementationClass="com.intellij.plugins.haxe.ide.formatter.HaxeFormattingModelBuilder"/>
Expand Down Expand Up @@ -310,6 +311,7 @@
<completion.contributor language="HXML" implementationClass="com.intellij.plugins.haxe.ide.HXMLCompilerArgumentsCompletionContributor"/>

<configurationType implementation="com.intellij.plugins.haxe.runner.HaxeRunConfigurationType"/>
<configurationType implementation="com.intellij.plugins.haxe.tests.runner.HaxeTestsRunConfigurationType"/>

<moduleService serviceInterface="com.intellij.plugins.haxe.ide.module.HaxeModuleSettings"
serviceImplementation="com.intellij.plugins.haxe.ide.module.HaxeModuleSettings"/>
Expand Down
8 changes: 7 additions & 1 deletion src/com/intellij/plugins/haxe/HaxeBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,10 @@ haxe.openfl.xmlproject=OpenFL Project XML \:
# HXML syntax support
hxml.language.id = HXML
hxml.file.type.name = HXML
hxml.file.type.description = Haxe Build Files
hxml.file.type.description = Haxe Build Files

# HAXE tests

haxe.tests.runner.configuration.name=Haxe Tests
haxe.tests.run.module=&Module\:
haxe.tests.run.runner.class=&Runner Class\:
101 changes: 72 additions & 29 deletions src/com/intellij/plugins/haxe/compilation/HaxeCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,39 @@

import com.intellij.compiler.options.CompileStepBeforeRun;
import com.intellij.execution.ExecutorRegistry;
import com.intellij.execution.configurations.ModuleBasedConfiguration;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunConfigurationModule;
import com.intellij.execution.executors.DefaultDebugExecutor;
import com.intellij.openapi.compiler.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkAdditionalData;
import com.intellij.openapi.roots.CompilerModuleExtension;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.OrderEnumerator;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.openapi.vcs.FileStatusManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.plugins.haxe.HaxeBundle;
import com.intellij.plugins.haxe.HaxeFileType;
import com.intellij.plugins.haxe.config.HaxeTarget;
import com.intellij.plugins.haxe.config.sdk.HaxeSdkAdditionalDataBase;
import com.intellij.plugins.haxe.ide.module.HaxeModuleSettings;
import com.intellij.plugins.haxe.ide.module.HaxeModuleType;
import com.intellij.plugins.haxe.module.HaxeModuleSettingsBase;
import com.intellij.plugins.haxe.runner.HaxeApplicationConfiguration;
import com.intellij.plugins.haxe.runner.debugger.HaxeDebugRunner;
import com.intellij.plugins.haxe.tests.runner.HaxeTestsConfiguration;
import com.intellij.plugins.haxe.util.HaxeCommonCompilerUtil;
import com.intellij.psi.search.FileTypeIndex;
import com.intellij.util.PathUtil;

import com.intellij.util.containers.HashMap;
import com.intellij.util.containers.HashSet;
import org.jetbrains.annotations.NotNull;

import java.io.DataInput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

public class HaxeCompiler implements SourceProcessingCompiler {
private static final Logger LOG = Logger.getInstance("#com.intellij.plugins.haxe.compilation.HaxeCompiler");
Expand All @@ -83,7 +77,7 @@ public boolean validateConfiguration(CompileScope scope) {
@Override
public ProcessingItem[] getProcessingItems(CompileContext context) {
final List<ProcessingItem> itemList = new ArrayList<ProcessingItem>();
for (final Module module : getModulesToCompile(context.getCompileScope() /*, context.getProject() */ )) {
for (final Module module : getModulesToCompile(context.getCompileScope() /*, context.getProject() */)) {
itemList.add(new MyProcessingItem(module));
}
return itemList.toArray(new ProcessingItem[itemList.size()]);
Expand Down Expand Up @@ -125,23 +119,27 @@ private static List<Module> getModulesToCompile(final CompileScope scope /*, fin
@Override
public ProcessingItem[] process(CompileContext context, ProcessingItem[] items) {
final RunConfiguration runConfiguration = CompileStepBeforeRun.getRunConfiguration(context.getCompileScope());
if (runConfiguration instanceof HaxeApplicationConfiguration) {
return run(context, items, (HaxeApplicationConfiguration)runConfiguration);
if (runConfiguration instanceof ModuleBasedConfiguration) {
return run(context, items, (ModuleBasedConfiguration)runConfiguration);
}
return make(context, items);
}

private static ProcessingItem[] run(CompileContext context,
ProcessingItem[] items,
HaxeApplicationConfiguration haxeApplicationConfiguration) {
final Module module = haxeApplicationConfiguration.getConfigurationModule().getModule();
ModuleBasedConfiguration configuration) {
final Module module = configuration.getConfigurationModule().getModule();
if (module == null) {
context.addMessage(CompilerMessageCategory.ERROR,
HaxeBundle.message("no.module.for.run.configuration", haxeApplicationConfiguration.getName()), null, -1, -1);
HaxeBundle.message("no.module.for.run.configuration", configuration.getName()), null, -1, -1);
return ProcessingItem.EMPTY_ARRAY;
}
if (compileModule(context, module)) {
final int index = findProcessingItemIndexByModule(items, haxeApplicationConfiguration.getConfigurationModule());
HaxeCommonCompilerUtil.CompilationContext compilationContext = createCompilationContext(context, module, configuration);



if (compileModule(context, compilationContext)) {
final int index = findProcessingItemIndexByModule(items, configuration.getConfigurationModule());
if (index != -1) {
return new ProcessingItem[]{items[index]};
}
Expand All @@ -156,31 +154,54 @@ private static ProcessingItem[] make(CompileContext context, ProcessingItem[] it
continue;
}
final MyProcessingItem myProcessingItem = (MyProcessingItem)processingItem;
if (compileModule(context, myProcessingItem.myModule)) {
if (compileModule(context, createCompilationContext(context, myProcessingItem.myModule, null))) {
result.add(processingItem);
}
}
return result.toArray(new ProcessingItem[result.size()]);
}

private static boolean compileModule(final CompileContext context, @NotNull final Module module) {
private static boolean compileModule(final CompileContext context, @NotNull final HaxeCommonCompilerUtil.CompilationContext compilationContext) {

/*
if ((skipBuildMap.get(module) != null) && (skipBuildMap.get(module).booleanValue())) {
return false;
}
*/


boolean compiled = HaxeCommonCompilerUtil.compile(compilationContext);

if (!compiled) {
context.addMessage(CompilerMessageCategory.ERROR, "Compilation failed", null, 0, 0);
}

return compiled;
}

private static HaxeCommonCompilerUtil.CompilationContext createCompilationContext(final CompileContext context,
final Module module,
ModuleBasedConfiguration configuration) {

final HaxeModuleSettings settings = HaxeModuleSettings.getInstance(module);
final boolean isDebug = ExecutorRegistry.getInstance()
.isStarting(context.getProject(), DefaultDebugExecutor.EXECUTOR_ID, HaxeDebugRunner.HAXE_DEBUG_RUNNER_ID);
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
final Sdk sdk = moduleRootManager.getSdk();
if (sdk == null) {
context.addMessage(CompilerMessageCategory.ERROR, HaxeBundle.message("no.sdk.for.module", module.getName()), null, -1, -1);
return false;
return null;
}

HaxeTestsConfiguration haxeTestsConfiguration = null;

if(configuration != null && configuration instanceof HaxeTestsConfiguration) {
haxeTestsConfiguration = (HaxeTestsConfiguration)configuration;
}
boolean compiled = HaxeCommonCompilerUtil.compile(new HaxeCommonCompilerUtil.CompilationContext() {

final HaxeTestsConfiguration finalHaxeTestsConfiguration = haxeTestsConfiguration;

return new HaxeCommonCompilerUtil.CompilationContext() {
private String myErrorRoot;

@NotNull
Expand All @@ -194,6 +215,21 @@ public String getModuleName() {
return module.getName();
}

@Override
public String getCompilationClass() {
return getIsTestBuild() ? finalHaxeTestsConfiguration.getRunnerClass() : getModuleSettings().getMainClass();
}

@Override
public String getOutputFileName() {
return getFileNameWithCurrentExtension(getModuleSettings().getOutputFileName());
}

@Override
public Boolean getIsTestBuild() {
return finalHaxeTestsConfiguration != null;
}

@Override
public void errorHandler(String message) {
context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
Expand Down Expand Up @@ -260,16 +296,23 @@ public void handleOutput(String[] lines) {
}

@Override
public String getModuleDirPath() {
return PathUtil.getParentPath(module.getModuleFilePath());
public HaxeTarget getHaxeTarget() {
//actually only neko target is supported for tests
return getIsTestBuild() ? HaxeTarget.NEKO : getModuleSettings().getHaxeTarget();
}
});

if (!compiled) {
context.addMessage(CompilerMessageCategory.ERROR, "Compilation failed", null, 0, 0);
}
private String getFileNameWithCurrentExtension(String fileName) {
if (getHaxeTarget() != null) {
return getHaxeTarget().getTargetFileNameWithExtension(FileUtil.getNameWithoutExtension(fileName));
}
return fileName;
}

return compiled;
@Override
public String getModuleDirPath() {
return PathUtil.getParentPath(module.getModuleFilePath());
}
};
}

private static int findProcessingItemIndexByModule(ProcessingItem[] items, RunConfigurationModule moduleConfiguration) {
Expand Down
Loading