This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add paket-unity UPM mode [ATLAS-1273] (#96)
- Loading branch information
1 parent
bfd797f
commit 79d4391
Showing
12 changed files
with
353 additions
and
18 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
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
76 changes: 76 additions & 0 deletions
76
src/integrationTest/groovy/wooga/gradle/paket/unity/fixtures/PaketFixtures.groovy
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,76 @@ | ||
package wooga.gradle.paket.unity.fixtures | ||
|
||
import nebula.test.IntegrationSpec | ||
|
||
import java.nio.file.FileSystems | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.util.stream.Collectors | ||
|
||
class PaketFixtures implements PaketFixturesTrait { | ||
|
||
private IntegrationSpec spec | ||
|
||
PaketFixtures(IntegrationSpec spec) { | ||
this.spec = spec | ||
} | ||
|
||
@Override | ||
File getProjectDir() { | ||
return spec.projectDir | ||
} | ||
} | ||
|
||
trait PaketFixturesTrait { | ||
abstract File getProjectDir() | ||
|
||
File fakePaketPackage(String name, | ||
File baseDir = projectDir, | ||
File installedPackagesDir = new File(projectDir, "packages"), | ||
File unityDir = new File(projectDir, "unity")) { | ||
def dependencies = new File(projectDir, "paket.dependencies") | ||
dependencies << """ | ||
source https://nuget.org/api/v2 | ||
nuget ${name} | ||
""".stripIndent() | ||
|
||
def lockFile = new File(projectDir, "paket.lock") | ||
lockFile << """${name}""".stripIndent().trim() | ||
|
||
def referencesFile = new File(unityDir, "paket.unity3d.references") | ||
referencesFile.parentFile.mkdirs() | ||
referencesFile << "\n${name}".stripIndent().trim() | ||
|
||
def packageFolder = new File(installedPackagesDir, "$name") | ||
packageFolder.mkdirs() | ||
packageFolder.with { | ||
new File(it, "content/innerFolder").mkdirs() | ||
new File(it, "content/innerFolder/something.cs") << "CONTENT" | ||
} | ||
return packageFolder | ||
} | ||
|
||
Tuple2<File, File> fakeUPMPaketPackage(String name, | ||
File unityDir = new File(projectDir, "unity"), | ||
File installedPackagesDir = new File(projectDir, "packages"), | ||
File baseDir = projectDir) { | ||
def packageFolder = fakePaketPackage(name, baseDir, installedPackagesDir, unityDir) | ||
createMetafiles(packageFolder) | ||
new File(packageFolder, "content/innerFolder/package.json") << """{"name" : "com.something.${name.toLowerCase()}"}""" | ||
new File(packageFolder, "content/innerFolder/package.json.meta") << "META" | ||
return [packageFolder, new File(packageFolder, "content/innerFolder/package.json")] | ||
} | ||
|
||
List<File> createMetafiles(File baseFolder) { | ||
def metaCandidates = Files.walk(baseFolder.toPath()).map {it.toFile() } | ||
.filter { it != baseFolder } | ||
.filter {!it.name.endsWith(".meta") } | ||
|
||
def createdMetas = metaCandidates.map { new File(it.parentFile, "${it.name}.meta") } | ||
.filter {!it.exists() } | ||
.map {it << "META" } | ||
.collect(Collectors.toList()) | ||
|
||
return createdMetas | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
src/main/groovy/wooga/gradle/paket/unity/PaketUpmPackageSpec.groovy
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,68 @@ | ||
package wooga.gradle.paket.unity | ||
|
||
import com.wooga.gradle.BaseSpec | ||
import org.gradle.api.provider.MapProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Optional | ||
|
||
trait PaketUpmPackageSpec implements BaseSpec { | ||
|
||
private final MapProperty<String, Map<String, Object>> paketUpmPackageManifests = objects.mapProperty(String, Map) | ||
|
||
/** | ||
* Map [<paket_package_name>: <upm_manifest_contents>] that overrides the contents of generated package.json files in UPM package mode. | ||
*/ | ||
@Input | ||
@Optional | ||
MapProperty<String, Map<String, Object>> getPaketUpmPackageManifests() { | ||
return paketUpmPackageManifests | ||
} | ||
|
||
void setPaketUpmPackageManifests(Map paketUpmPackages) { | ||
this.paketUpmPackageManifests.set(paketUpmPackages) | ||
} | ||
|
||
void setPaketUpmPackageManifests(Provider<Map<String, String>> paketUpmPackages) { | ||
this.paketUpmPackageManifests.set(paketUpmPackages) | ||
} | ||
|
||
|
||
private final Property<Boolean> paketUpmPackageEnabled = objects.property(Boolean) | ||
|
||
/** | ||
* | ||
* Enables "UPM package mode" for paket. This mode searches for a folder with a 'package.json' in the paket project, | ||
* and installs the package in the 'Packages' folder, using the discovered folder as root. | ||
* <br> | ||
* Non-UPM compatible packages will be given a basic package.json file with a package name described in the | ||
* {@code paketUpmPackages} property. If a mapping is not found there, | ||
* a generic 'com.wooga.nuget.<paket-package-name>' name will be used. | ||
* <br> | ||
*/ | ||
void enablePaketUpmPackages() { | ||
paketUpmPackageEnabled.set(true) | ||
} | ||
|
||
/** | ||
* Enables/Disables "UPM package mode" for paket. See {@code PaketUpmPackageSpec::enablePaketUpmPackages} for more details. | ||
*/ | ||
@Input | ||
@Optional | ||
Property<Boolean> getPaketUpmPackageEnabled() { | ||
return paketUpmPackageEnabled | ||
} | ||
|
||
Property<Boolean> isPaketUpmPackageEnabled() { | ||
return paketUpmPackageEnabled | ||
} | ||
|
||
void setPaketUpmPackageEnabled(Boolean enablePaketUpmPackages) { | ||
this.paketUpmPackageEnabled.set(enablePaketUpmPackages) | ||
} | ||
|
||
void setPaketUpmPackageEnabled(Provider<Boolean> enablePaketUpmPackages) { | ||
this.paketUpmPackageEnabled.set(enablePaketUpmPackages) | ||
} | ||
} |
Oops, something went wrong.