Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use separate formatter for Elixir >= 1.4.0
Use a seperate formatter, one GenEvent-based and one GenServer-based, depending on whether the SDK is >= 1.4.0 as that's when GenEvent was deprecated and GenServer was preferred.
- Loading branch information
1 parent
a5548e1
commit b0e8f9a
Showing
8 changed files
with
505 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Originally based on https://github.com/lixhq/teamcity-exunit-formatter, but it did not work for parallel tests: IDEA | ||
# does not honor flowId, so needed to use the nodeId/parentNodeIde system | ||
# | ||
# nodeId and parentNodeId system is documented in | ||
# https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000389550/comments/115000330464 | ||
defmodule TeamCityExUnitFormatter do | ||
@moduledoc false | ||
|
||
use GenEvent | ||
|
||
# Functions | ||
|
||
## GenEvent Callbacks | ||
|
||
def handle_event(event, state) do | ||
updated_state = TeamCityExUnitFormatting.put_event(state, event) | ||
|
||
{:ok, updated_state} | ||
end | ||
|
||
def init(opts), do: {:ok, TeamCityExUnitFormatting.new(opts)} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule TeamCityExUnitFormatter do | ||
@moduledoc false | ||
|
||
use GenServer | ||
|
||
# Functions | ||
|
||
## GenServer Callbacks | ||
|
||
def handle_cast(event, state) do | ||
updated_state = TeamCityExUnitFormatting.put_event(state, event) | ||
|
||
{:noreply, updated_state} | ||
end | ||
|
||
def init(opts), do: {:ok, TeamCityExUnitFormatting.new(opts)} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,73 @@ | ||
package org.elixir_lang.exunit; | ||
|
||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.projectRoots.Sdk; | ||
import com.intellij.openapi.roots.ProjectRootManager; | ||
import com.intellij.openapi.util.io.FileUtil; | ||
import com.intellij.util.ResourceUtil; | ||
import com.intellij.util.io.URLUtil; | ||
import org.elixir_lang.sdk.ElixirSdkRelease; | ||
import org.elixir_lang.sdk.ElixirSdkType; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.*; | ||
import java.net.URL; | ||
|
||
public class ElixirModules { | ||
private static final String FORMATTER_FILE_NAME = "team_city_ex_unit_formatter.ex"; | ||
private static final String MIX_TASK_FILE_NAME = "test_with_formatter.ex"; | ||
private static final String FORMATTER_FILE_NAME = "team_city_ex_unit_formatter.ex"; | ||
private static final String FORMATTING_FILE_NAME = "team_city_ex_unit_formatting.ex"; | ||
private static final String MIX_TASK_FILE_NAME = "test_with_formatter.ex"; | ||
|
||
private ElixirModules() { | ||
} | ||
private ElixirModules() { | ||
} | ||
|
||
private static File putFile(@NotNull String relativePath, @NotNull File directory) throws IOException { | ||
URL moduleUrl = ResourceUtil.getResource(ElixirModules.class, "/exunit", relativePath); | ||
|
||
if (moduleUrl == null) { | ||
throw new IOException("Failed to locate Elixir module " + relativePath); | ||
} | ||
|
||
try (BufferedInputStream inputStream = new BufferedInputStream(URLUtil.openStream(moduleUrl))) { | ||
File file = new File(directory, relativePath); | ||
file.getParentFile().mkdirs(); | ||
|
||
private static File putFile(@NotNull String fileName, @NotNull File directory) throws IOException { | ||
URL moduleUrl = ResourceUtil.getResource(ElixirModules.class, "/exunit", fileName); | ||
if (moduleUrl == null) { | ||
throw new IOException("Failed to locate Elixir module " + fileName); | ||
try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file))) { | ||
FileUtil.copy(inputStream, outputStream); | ||
return file; | ||
} | ||
} | ||
} | ||
|
||
BufferedInputStream inputStream = new BufferedInputStream(URLUtil.openStream(moduleUrl)); | ||
File file = new File(directory, fileName); | ||
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); | ||
try { | ||
FileUtil.copy(inputStream, outputStream); | ||
return file; | ||
} finally { | ||
inputStream.close(); | ||
outputStream.close(); | ||
public static File putFormatterTo(@NotNull File directory, @Nullable Project project) throws IOException { | ||
Sdk sdk = null; | ||
|
||
if (project != null) { | ||
sdk = ProjectRootManager.getInstance(project).getProjectSdk(); | ||
} | ||
|
||
return putFormatterTo(directory, sdk); | ||
} | ||
} | ||
|
||
public static File putFormatterTo(@NotNull File directory) throws IOException { | ||
return putFile(FORMATTER_FILE_NAME, directory); | ||
} | ||
private static File putFormatterTo(@NotNull File directory, @Nullable Sdk sdk) throws IOException { | ||
String versionDirectory = "1.4.0"; | ||
|
||
ElixirSdkRelease release = ElixirSdkType.getRelease(sdk); | ||
|
||
public static File putMixTaskTo(@NotNull File directory) throws IOException { | ||
return putFile(MIX_TASK_FILE_NAME, directory); | ||
} | ||
if (release != null && release.compareTo(ElixirSdkRelease.V_1_4) < 0) { | ||
versionDirectory = "1.1.0"; | ||
} | ||
|
||
String source = versionDirectory + "/" + FORMATTER_FILE_NAME; | ||
return putFile(source, directory); | ||
} | ||
|
||
public static File putFormattingTo(@NotNull File directory) throws IOException { | ||
return putFile(FORMATTING_FILE_NAME, directory); | ||
} | ||
|
||
public static File putMixTaskTo(@NotNull File directory) throws IOException { | ||
return putFile(MIX_TASK_FILE_NAME, directory); | ||
} | ||
} |
Oops, something went wrong.