Skip to content

Commit 2b20930

Browse files
committed
Support configuration of executable files and binary file extensions in profiles
1 parent a832497 commit 2b20930

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

grails-shell/src/main/groovy/org/grails/cli/profile/AbstractProfile.groovy

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ abstract class AbstractProfile implements Profile {
5757
protected List<String> buildPlugins = []
5858
protected List<String> buildExcludes = []
5959
protected List<String> skeletonExcludes = []
60+
protected List<String> binaryExtensions = []
61+
protected List<String> executablePatterns = []
6062
protected final List<Command> internalCommands = []
6163
protected List<String> buildMerge = null
6264
protected List<Feature> features = []
@@ -203,14 +205,36 @@ abstract class AbstractProfile implements Profile {
203205
this.buildMerge = (List<String>)navigableConfig.get("build.merge", null)
204206
this.parentTargetFolder = (String)navigableConfig.get("skeleton.parent.target", null)
205207
this.skeletonExcludes = (List<String>)navigableConfig.get("skeleton.excludes", [])
208+
this.binaryExtensions = (Set<String>)navigableConfig.get("skeleton.binaryExtensions", [])
209+
this.executablePatterns = (Set<String>)navigableConfig.get("skeleton.executable", [])
206210
}
207211

208212
String getDescription() {
209-
return description
213+
description
210214
}
211215

212216
String getInstructions() {
213-
return instructions
217+
instructions
218+
}
219+
220+
Set<String> getBinaryExtensions() {
221+
Set<String> calculatedBinaryExtensions = []
222+
def parents = getExtends()
223+
for(profile in parents) {
224+
calculatedBinaryExtensions.addAll(profile.binaryExtensions)
225+
}
226+
calculatedBinaryExtensions.addAll(binaryExtensions)
227+
return calculatedBinaryExtensions
228+
}
229+
230+
Set<String> getExecutablePatterns() {
231+
Set<String> calculatedExecutablePatterns = []
232+
def parents = getExtends()
233+
for(profile in parents) {
234+
calculatedExecutablePatterns.addAll(profile.executablePatterns)
235+
}
236+
calculatedExecutablePatterns.addAll(executablePatterns)
237+
return calculatedExecutablePatterns
214238
}
215239

216240
@Override

grails-shell/src/main/groovy/org/grails/cli/profile/Profile.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
import org.grails.io.support.Resource;
2222

2323
import java.io.File;
24-
import java.util.Collection;
2524
import java.util.List;
26-
import java.util.Map;
25+
import java.util.Set;
2726

2827
/**
2928
* A Profile defines an active code generation and command execution policy. For example the "web" profile allows
@@ -51,6 +50,15 @@ public interface Profile {
5150
*/
5251
String getDescription();
5352

53+
/**
54+
* @return The list of file extensions which should be treated as binary
55+
*/
56+
Set<String> getBinaryExtensions();
57+
58+
/**
59+
* @return The list of file patterns which should be executable in the resulting application
60+
*/
61+
Set<String> getExecutablePatterns();
5462

5563
/**
5664
* @return Text to display after an application has been created with the profile

grails-shell/src/main/groovy/org/grails/cli/profile/commands/CreateAppCommand.groovy

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
6767
String groupname
6868
String defaultpackagename
6969
File targetDirectory
70-
List<String> binaryFileExtensions = ['png','gif','jpg','jpeg','ico','icns','pdf','zip','jar','class']
7170

7271
CommandDescription description = new CommandDescription(name, "Creates an application", "create-app [NAME] --profile=web")
7372

@@ -276,7 +275,7 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
276275
appendFeatureFiles(skeletonDir)
277276

278277
if(skeletonDir.exists()) {
279-
copySrcToTarget(ant, skeletonDir, ['**/' + APPLICATION_YML])
278+
copySrcToTarget(ant, skeletonDir, ['**/' + APPLICATION_YML], profileInstance.binaryExtensions)
280279
}
281280
}
282281

@@ -583,8 +582,7 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
583582
def tmpDir = unzipProfile(ant, skeletonResource)
584583
skeletonDir = new File(tmpDir, "META-INF/grails-profile/skeleton")
585584
}
586-
copySrcToTarget(ant, skeletonDir, excludes)
587-
585+
copySrcToTarget(ant, skeletonDir, excludes, profile.binaryExtensions)
588586

589587
Set<File> sourceBuildGradles = findAllFilesByName(skeletonDir, BUILD_GRADLE)
590588

@@ -610,12 +608,11 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
610608
}
611609
}
612610

613-
ant.chmod(dir: targetDirectory, includes: "**/gradlew*", perm: 'u+x')
614-
ant.chmod(dir: targetDirectory, includes: "**/grailsw*", perm: 'u+x')
611+
ant.chmod(dir: targetDirectory, includes: profile.executablePatterns.join(' '), perm: 'u+x')
615612
}
616613

617614
@CompileDynamic
618-
protected void copySrcToTarget(GrailsConsoleAntBuilder ant, File srcDir, List excludes) {
615+
protected void copySrcToTarget(GrailsConsoleAntBuilder ant, File srcDir, List excludes, Set<String> binaryFileExtensions) {
619616
ant.copy(todir: targetDirectory, overwrite: true, encoding: 'UTF-8') {
620617
fileSet(dir: srcDir, casesensitive: false) {
621618
exclude(name: '**/.gitkeep')

0 commit comments

Comments
 (0)