Skip to content

Commit ae568c7

Browse files
sgammonmelodicore
authored andcommitted
feat: resolve elide from user path
feat: use compiler path if specified (overrides) feat: resolve `elide` from user path chore: cleanups in readme/sample project chore: move compiler ID to new constants file Signed-off-by: Sam Gammon <sam@elide.dev>
1 parent 1005bc0 commit ae568c7

6 files changed

Lines changed: 90 additions & 21 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Configuring Elide as your `javac` compiler:
4242
Properties needed:
4343
```xml
4444
<properties>
45-
<maven.compiler.executable>/path/to/elide</maven.compiler.executable>
4645
<maven.compiler.source>24</maven.compiler.source>
4746
<maven.compiler.target>24</maven.compiler.target>
4847
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

sample/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,3 @@ code to build, and the `pom.xml` is configured to use Elide.
2424
</plugins>
2525
</build>
2626
```
27-
28-
Properties needed:
29-
```xml
30-
<properties>
31-
<maven.compiler.executable>/path/to/elide</maven.compiler.executable>
32-
<maven.compiler.source>24</maven.compiler.source>
33-
<maven.compiler.target>24</maven.compiler.target>
34-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35-
</properties>
36-
```

sample/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<version>1</version>
66

77
<properties>
8-
<maven.compiler.executable>/home/sam/bin/elide</maven.compiler.executable>
98
<maven.compiler.source>24</maven.compiler.source>
109
<maven.compiler.target>24</maven.compiler.target>
1110
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2024-2025 Elide Technologies, Inc.
3+
*
4+
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
*
7+
* https://opensource.org/license/mit/
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations under the License.
12+
*/
13+
package dev.elide.maven.compiler
14+
15+
/**
16+
* Constant ID used by the Elide compiler shim.
17+
*/
18+
public const val ELIDE_COMPILER: String = "elide"

src/main/kotlin/dev/elide/maven/compiler/ElideJavacCompiler.kt

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* Copyright (c) 2024-2025 Elide Technologies, Inc.
3+
*
4+
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
*
7+
* https://opensource.org/license/mit/
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations under the License.
12+
*/
113
package dev.elide.maven.compiler
214

315
import org.codehaus.plexus.compiler.*
@@ -9,13 +21,18 @@ import java.io.IOException
921
import java.util.LinkedList
1022
import javax.inject.Named
1123
import javax.inject.Singleton
24+
import kotlin.io.path.absolutePathString
1225

1326
/**
14-
* @author Lauri "datafox" Heino
27+
* Implements a Java compiler bridge from Maven to Elide.
28+
*
29+
* @author Lauri Heino <datafox>
30+
* @author Sam Gammon <sgammon>
31+
* @since 1.0.0
1532
*/
16-
@Named("elide")
33+
@Named(ELIDE_COMPILER)
1734
@Singleton
18-
open class ElideJavacCompiler() : AbstractCompiler(
35+
public open class ElideJavacCompiler() : AbstractCompiler(
1936
CompilerOutputStyle.ONE_OUTPUT_FILE_PER_INPUT_FILE,
2037
".java",
2138
".class",
@@ -63,10 +80,10 @@ open class ElideJavacCompiler() : AbstractCompiler(
6380
return CompilerResult(returnCode == 0, messages)
6481
}
6582

66-
private fun getElideExecutable(config: CompilerConfiguration): String {
67-
if (config.executable != null && config.executable.isNotBlank()) return config.executable
68-
return "elide"
69-
}
83+
private fun getElideExecutable(config: CompilerConfiguration): String = when (val executable = config.executable) {
84+
null -> ElideLocator.locate()?.absolutePathString()
85+
else -> executable
86+
} ?: "elide"
7087

7188
override fun createCommandLine(config: CompilerConfiguration): Array<String> {
7289
return buildElideArgs(config, getSourceFiles(config)).toTypedArray()
@@ -176,9 +193,9 @@ open class ElideJavacCompiler() : AbstractCompiler(
176193
}
177194

178195
@Throws(IOException::class)
179-
fun parseOutput(exitCode: Int, input: List<String>): List<CompilerMessage> {
196+
private fun parseOutput(exitCode: Int, input: List<String>): List<CompilerMessage> {
180197
//very lazy for now
181198
val kind = if(exitCode == 0) CompilerMessage.Kind.NOTE else CompilerMessage.Kind.ERROR
182199
return input.map { CompilerMessage(it, kind) }
183200
}
184-
}
201+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2024-2025 Elide Technologies, Inc.
3+
*
4+
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
*
7+
* https://opensource.org/license/mit/
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
* License for the specific language governing permissions and limitations under the License.
12+
*/
13+
package dev.elide.maven.compiler
14+
15+
import java.io.File
16+
import java.nio.file.Path
17+
import java.nio.file.Paths
18+
19+
/**
20+
* Locates the Elide binary via the user's PATH.
21+
*
22+
* @author Sam Gammon <sgammon>
23+
* @since 1.0.0
24+
*/
25+
object ElideLocator {
26+
// Checks if a path is a valid binary.
27+
private fun isValidElideBinary(path: Path): Boolean {
28+
return path.toFile().exists() && path.toFile().isFile && path.toFile().canExecute()
29+
}
30+
31+
/**
32+
* Attempts to locate the Elide binary in the user's PATH.
33+
*
34+
* @return The path to the Elide binary, or null if not found.
35+
*/
36+
fun locate(): Path? {
37+
val path = System.getenv("PATH") ?: ""
38+
for (pathCandidate in path.split(File.separatorChar)) {
39+
val candidate = Paths.get(pathCandidate, "elide")
40+
if (isValidElideBinary(candidate)) {
41+
return candidate
42+
}
43+
}
44+
return null
45+
}
46+
}

0 commit comments

Comments
 (0)