Skip to content

Commit bc4dbd6

Browse files
author
Karl Rieb
committed
Add back legacy stone generation task to gradle build since multi-project builds don't support nested buildSrc.
1 parent a2de9ed commit bc4dbd6

File tree

5 files changed

+164
-34
lines changed

5 files changed

+164
-34
lines changed

buildSrc/src/main/groovy/com/dropbox/stone/gradle/StoneTask.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ public class StoneTask extends DefaultTask {
243243

244244
void generateStoneSourcesForSpecs(Iterable<ClientSpec> specs, OutputStream log) {
245245
project.exec {
246-
environment([PYTHONPATH: getStoneDir().absolutePath])
246+
environment PYTHONPATH: getStoneDir().absolutePath
247247
standardOutput = log
248-
commandLine("python3", "-m", "stone.cli")
248+
commandLine "python3", "-m", "stone.cli"
249249
args "--clean-build"
250250

251251
for (String namespace : getWhitelistedNamespaces()) {

export-generated

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ IGNORE_PATTERNS = [
2323
'/diff-generated-sources',
2424
'/release.gradle', # public repo should not include signing and release information
2525
'/stone.gradle',
26+
'/stone_legacy.gradle', # required by dbapp-android integration until stone-gradle-plugin is public
2627
'/proguard', # ProGuard tests are mostly for release testing
2728
]
2829

generator/java.stoneg.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,8 +2607,9 @@ def generate(self, api):
26072607
26082608
This is called by stone.cli.
26092609
"""
2610-
print(self.args)
26112610
client_specs = [ClientSpec.from_spec_str(s) for s in self.args.client_spec]
2611+
if not client_specs:
2612+
raise Exception("Must specify at least one client to generate")
26122613
ctx = GeneratorContext(self, api, client_specs)
26132614
for client_spec in client_specs:
26142615
JavaCodeGenerationInstance(ctx).generate(client_spec)
@@ -2735,7 +2736,7 @@ def generate_client(self):
27352736
self.importer.generate_imports()
27362737

27372738
out('')
2738-
self.doc.generate_javadoc(self.ctx.client_javadoc)
2739+
self.doc.generate_javadoc(self.ctx.client_javadoc or "")
27392740
with self.g.block('public class %s' % client_class.name):
27402741
out('protected final DbxRawClientV2 _client;')
27412742
out('')

stone.gradle

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
1-
apply plugin: 'stone'
1+
/*
2+
* Disabled until plugin can be stand-alone and used by dbapp-android.
3+
*
4+
* Gradle does not allow nested buildSrc directories for multi-project builds. This means we lose our plugin in the dbapp-android integration.
5+
*/
6+
apply plugin: 'java'
27

3-
stone {
4-
stoneDir "stone"
5-
generatorDir "generator"
6-
}
8+
if (rootProject.equals(project)) {
9+
apply plugin: 'stone'
710

8-
generateStone {
9-
packageName "com.dropbox.core.v2"
10-
routeFilter "alpha_group=null and beta_group=null"
11+
stone {
12+
stoneDir "stone"
13+
generatorDir "generator"
14+
}
1115

12-
clients {
13-
DbxClientV2Base {
14-
javadoc 'Base class for user auth clients.'
15-
routesClassNameFormat "DbxUser%sRequests"
16-
routeFilter 'auth="user" or auth="noauth"'
17-
}
18-
DbxTeamClientV2Base {
19-
javadoc 'Base class for team auth clients.'
20-
routesClassNameFormat "DbxTeam%sRequests"
21-
routeFilter 'auth="team"'
22-
}
23-
DbxAppClientV2Base {
24-
javadoc 'Base class for app auth clients.'
25-
routesClassNameFormat "DbxApp%sRequests"
26-
routeFilter 'auth="app"'
16+
generateStone {
17+
packageName "com.dropbox.core.v2"
18+
routeFilter "alpha_group=null and beta_group=null"
19+
20+
clients {
21+
DbxClientV2Base {
22+
javadoc 'Base class for user auth clients.'
23+
routesClassNameFormat "DbxUser%sRequests"
24+
routeFilter 'auth="user" or auth="noauth"'
25+
}
26+
DbxTeamClientV2Base {
27+
javadoc 'Base class for team auth clients.'
28+
routesClassNameFormat "DbxTeam%sRequests"
29+
routeFilter 'auth="team"'
30+
}
31+
DbxAppClientV2Base {
32+
javadoc 'Base class for app auth clients.'
33+
routesClassNameFormat "DbxApp%sRequests"
34+
routeFilter 'auth="app"'
35+
}
2736
}
2837
}
29-
}
3038

31-
generateTestStone {
32-
packageName "com.dropbox.core.stone"
39+
generateTestStone {
40+
packageName "com.dropbox.core.stone"
41+
keepUnused true
3342

34-
clients {
35-
StoneTestClient {
36-
keepUnused true
43+
clients {
44+
StoneTestClient {}
3745
}
3846
}
39-
}
4047

48+
} else {
49+
apply from: "stone_legacy.gradle"
50+
}

stone_legacy.gradle

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
class StoneConfig {
3+
String packageName = 'com.dropbox.stone'
4+
String routeFilter = null
5+
boolean keepUnused = false
6+
List<ClientSpec> clients = []
7+
}
8+
9+
class ClientSpec {
10+
String name = 'StoneClient'
11+
String javadoc = ''
12+
String routesClassNameFormat = ''
13+
String routeFilter = ''
14+
15+
String getSpecString() {
16+
return "${name}:${javadoc}:${routesClassNameFormat}:${routeFilter}"
17+
}
18+
}
19+
20+
project.sourceSets.all { SourceSet sourceSet ->
21+
def taskName = "main".equals(sourceSet.name) ? "generateStone" : "generate${sourceSet.name.capitalize()}Stone"
22+
task "${taskName}" {
23+
description "Generate Stone Java source files for ${sourceSet.name}."
24+
25+
ext {
26+
config = new StoneConfig()
27+
generatorDir = 'generator'
28+
stoneDir = 'stone'
29+
specDir = project.properties.get('com.dropbox.api.specDir', "src/${sourceSet.name}/stone")
30+
outputDir = "${project.buildDir}/generated/source/stone/${sourceSet.name}"
31+
}
32+
33+
def specFiles = fileTree(dir: specDir, include: '**/*.stone')
34+
35+
inputs.dir { project.fileTree(dir: generatorDir, exclude: '**/*.pyc') }
36+
inputs.sourceDir { specFiles }
37+
inputs.property "config", { new groovy.json.JsonBuilder(config).toString() }
38+
outputs.dir { outputDir }
39+
40+
doLast {
41+
def generatorFile = fileTree(dir: generatorDir, include: '**/*stoneg.py').getSingleFile()
42+
def srcOutputDir = new File(outputDir, "src")
43+
def logFile = new File(outputDir, "log/stone.log")
44+
45+
srcOutputDir.mkdirs()
46+
logFile.parentFile.mkdirs()
47+
48+
project.exec {
49+
standardOutput = new FileOutputStream(logFile)
50+
commandLine "python3", "-m", "stone.cli"
51+
52+
environment PYTHONPATH: file(stoneDir).absolutePath
53+
args "--clean-build"
54+
if (config.routeFilter != null) {
55+
args "--filter-by-route-attr", config.routeFilter
56+
}
57+
args generatorFile.absolutePath
58+
args new File(outputDir, "src").absolutePath
59+
args specFiles.getFiles()
60+
args "--"
61+
args "--package", config.packageName
62+
if (config.keepUnused) {
63+
args "--keep-unused"
64+
}
65+
66+
for (ClientSpec client : config.clients) {
67+
args "--client-spec", client.specString
68+
}
69+
}
70+
}
71+
}
72+
73+
sourceSet.java.srcDir project.tasks."${taskName}".outputDir
74+
Task compile = project.tasks.getByName(sourceSet.getCompileTaskName("java"))
75+
compile.dependsOn project.tasks."${taskName}"
76+
}
77+
78+
79+
generateStone {
80+
config = new StoneConfig(
81+
packageName: 'com.dropbox.core.v2',
82+
routeFilter: 'alpha_group=null and beta_group=null',
83+
84+
clients: [
85+
new ClientSpec(
86+
name: 'DbxClientV2Base',
87+
javadoc: 'Base class for user auth clients.',
88+
routesClassNameFormat: "DbxUser%sRequests",
89+
routeFilter: 'auth="user" or auth="noauth"',
90+
),
91+
new ClientSpec(
92+
name: 'DbxTeamClientV2Base',
93+
javadoc: 'Base class for team auth clients.',
94+
routesClassNameFormat: 'DbxTeam%sRequests',
95+
routeFilter: 'auth="team"',
96+
),
97+
new ClientSpec(
98+
name: 'DbxAppClientV2Base',
99+
javadoc: 'Base class for app auth clients.',
100+
routesClassNameFormat: "DbxApp%sRequests",
101+
routeFilter: 'auth="app"',
102+
)
103+
],
104+
)
105+
}
106+
107+
generateTestStone {
108+
config = new StoneConfig(
109+
packageName: 'com.dropbox.core.stone',
110+
keepUnused: true,
111+
112+
clients: [
113+
new ClientSpec(
114+
name: 'StoneTestClient',
115+
)
116+
],
117+
)
118+
}

0 commit comments

Comments
 (0)