Skip to content

Commit 0a0fdc8

Browse files
committed
Add more Javadoc
1 parent fac510e commit 0a0fdc8

5 files changed

Lines changed: 61 additions & 3 deletions

File tree

src/main/kotlin/com/github/gradle/node/NodeExtension.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,19 @@ open class NodeExtension(project: Project) {
110110
}
111111

112112
companion object {
113+
/**
114+
* Extension name in Gradle
115+
*/
113116
const val NAME = "node"
117+
118+
/**
119+
* Default version of Node to download if none is set
120+
*/
114121
const val DEFAULT_NODE_VERSION = "14.15.4"
122+
123+
/**
124+
* Default version of npm to download if none is set
125+
*/
115126
const val DEFAULT_NPM_VERSION = "6.14.10"
116127

117128
@JvmStatic

src/main/kotlin/com/github/gradle/node/exec/ExecRunner.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ fun computeWorkingDir(nodeProjectDir: DirectoryProperty, execConfiguration: Exec
3434
return workingDir
3535
}
3636

37+
/**
38+
* Basic execution runner that runs a given ExecConfiguration.
39+
*
40+
* Specific implementations likely use the same configuration but may assign
41+
* different meaning to its values.
42+
*/
3743
class ExecRunner {
3844
fun execute(projectHelper: ProjectApiHelper, extension: NodeExtension, execConfiguration: ExecConfiguration) {
3945
projectHelper.exec {

src/main/kotlin/com/github/gradle/node/npm/proxy/NpmProxy.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class NpmProxy {
2222
"NPM_CONFIG_PROXY", "NPM_CONFIG_HTTPS-PROXY", "NPM_CONFIG_HTTPS_PROXY", "NPM_CONFIG_NOPROXY"
2323
)
2424

25+
/**
26+
* Creates a map of environment variables with proxy settings.
27+
*
28+
* Will return an empty map if none are set.
29+
*/
2530
fun computeNpmProxyEnvironmentVariables(): Map<String, String> {
2631
val proxyEnvironmentVariables = computeProxyUrlEnvironmentVariables()
2732
if (proxyEnvironmentVariables.isNotEmpty()) {
@@ -31,9 +36,7 @@ class NpmProxy {
3136
}
3237

3338
/**
34-
* Helper function for deciding whether to set proxy settings or not.
35-
*
36-
* If you make use of
39+
* Helper function for deciding whether proxy settings need to be set or not.
3740
*/
3841
fun shouldConfigureProxy(env: Map<String, String>, settings: ProxySettings): Boolean {
3942
if (settings == ProxySettings.FORCED) {

src/main/kotlin/com/github/gradle/node/util/ProjectApiHelper.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ interface ProjectApiHelper {
4343
fun exec(action: Action<ExecSpec>): ExecResult
4444
}
4545

46+
/**
47+
* Used in Gradle 6.6 and newer.
48+
*/
4649
open class DefaultProjectApiHelper @Inject constructor(
4750
private val factory: ObjectFactory,
4851
private val execOperations: ExecOperations,
@@ -74,6 +77,9 @@ open class DefaultProjectApiHelper @Inject constructor(
7477
}
7578
}
7679

80+
/**
81+
* Used to support Gradle versions older than 6.6
82+
*/
7783
open class LegacyProjectApiHelper(private val project: Project) : ProjectApiHelper {
7884

7985
override fun fileTree(directory: Directory): ConfigurableFileTree {

src/main/kotlin/com/github/gradle/node/variant/VariantComputer.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import org.gradle.api.provider.Provider
1010
open class VariantComputer @JvmOverloads constructor(
1111
private val platformHelper: PlatformHelper = PlatformHelper.INSTANCE
1212
) {
13+
/**
14+
* Get the expected directory for a given node version.
15+
*
16+
* Essentially: workingDir/node-v$version-$osName-$osArch
17+
*/
1318
fun computeNodeDir(nodeExtension: NodeExtension): Provider<Directory> {
1419
return zip(nodeExtension.workDir, nodeExtension.version).map { (workDir, version) ->
1520
val osName = platformHelper.osName
@@ -19,8 +24,14 @@ open class VariantComputer @JvmOverloads constructor(
1924
}
2025
}
2126

27+
/**
28+
* Get the expected node binary directory, taking Windows specifics into account.
29+
*/
2230
fun computeNodeBinDir(nodeDirProvider: Provider<Directory>) = computeProductBinDir(nodeDirProvider)
2331

32+
/**
33+
* Get the expected node binary name, node.exe on Windows and node everywhere else.
34+
*/
2435
fun computeNodeExec(nodeExtension: NodeExtension, nodeBinDirProvider: Provider<Directory>): Provider<String> {
2536
return zip(nodeExtension.download, nodeBinDirProvider).map {
2637
val (download, nodeBinDir) = it
@@ -31,6 +42,9 @@ open class VariantComputer @JvmOverloads constructor(
3142
}
3243
}
3344

45+
/**
46+
* Get the expected directory for a given npm version.
47+
*/
3448
fun computeNpmDir(nodeExtension: NodeExtension, nodeDirProvider: Provider<Directory>): Provider<Directory> {
3549
return zip(nodeExtension.npmVersion, nodeExtension.npmWorkDir, nodeDirProvider).map {
3650
val (npmVersion, npmWorkDir, nodeDir) = it
@@ -41,8 +55,16 @@ open class VariantComputer @JvmOverloads constructor(
4155
}
4256
}
4357

58+
/**
59+
* Get the expected npm binary directory, taking Windows specifics into account.
60+
*/
4461
fun computeNpmBinDir(npmDirProvider: Provider<Directory>) = computeProductBinDir(npmDirProvider)
4562

63+
/**
64+
* Get the expected node binary name, npm.cmd on Windows and npm everywhere else.
65+
*
66+
* Can be overridden by setting npmCommand.
67+
*/
4668
fun computeNpmExec(nodeExtension: NodeExtension, npmBinDirProvider: Provider<Directory>): Provider<String> {
4769
return zip(nodeExtension.download, nodeExtension.npmCommand, npmBinDirProvider).map {
4870
val (download, npmCommand, npmBinDir) = it
@@ -60,6 +82,11 @@ open class VariantComputer @JvmOverloads constructor(
6082
}
6183
}
6284

85+
/**
86+
* Get the expected node binary name, npx.cmd on Windows and npx everywhere else.
87+
*
88+
* Can be overridden by setting npxCommand.
89+
*/
6390
fun computeNpxExec(nodeExtension: NodeExtension, npmBinDirProvider: Provider<Directory>): Provider<String> {
6491
return zip(nodeExtension.download, nodeExtension.npxCommand, npmBinDirProvider).map {
6592
val (download, npxCommand, npmBinDir) = it
@@ -96,6 +123,11 @@ open class VariantComputer @JvmOverloads constructor(
96123
private fun computeProductBinDir(productDirProvider: Provider<Directory>) =
97124
if (platformHelper.isWindows) productDirProvider else productDirProvider.map { it.dir("bin") }
98125

126+
/**
127+
* Get the node archive name in Gradle dependency format, using zip for Windows and tar.gz everywhere else.
128+
*
129+
* Essentially: org.nodejs:node:$version:$osName-$osArch@tar.gz
130+
*/
99131
fun computeNodeArchiveDependency(nodeExtension: NodeExtension): Provider<String> {
100132
val osName = platformHelper.osName
101133
val osArch = platformHelper.osArch

0 commit comments

Comments
 (0)