Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to Grails Shell #12060

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions grails-bom/profiles.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
rest-api=5.0.0.RC1
base=5.0.0.RC3
base=5.0.0-SNAPSHOT
web=5.0.0.RC1
react=5.0.0.RC1
vue=5.0.0.RC1
plugin=5.0.0.RC1
plugin=5.0.0-SNAPSHOT
profile=5.0.0.RC2
rest-api-plugin=5.0.0.RC1
web-plugin=4.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.types.LogLevel;
Expand Down Expand Up @@ -50,7 +51,7 @@ protected static Project createAntProject() {
final Project project = new Project();

final ProjectHelper helper = ProjectHelper.getProjectHelper();
project.addReference(ProjectHelper.PROJECTHELPER_REFERENCE, helper);
project.addReference(MagicNames.REFID_PROJECT_HELPER, helper);
helper.getImportStack().addElement("AntBuilder"); // import checks that stack is not empty

addGrailsConsoleBuildListener(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DefaultFeature implements Feature {
final NavigableMap configuration = new NavigableMap()
final List<Dependency> dependencies = []
final List<String> buildPlugins
final List<String> buildRepositories

DefaultFeature(Profile profile, String name, Resource location) {
this.profile = profile
Expand All @@ -68,6 +69,7 @@ class DefaultFeature implements Feature {
}
}
this.buildPlugins = (List<String>)configuration.get("build.plugins", [])
this.buildRepositories = (List<String>) configuration.get("build.repositories", [])
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ interface Feature {
*/
List<String> getBuildPlugins()

/**
* @return The build repositories url
*/
List<String> getBuildRepositories()

/**
* @return The configuration for the feature
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ import org.eclipse.aether.graph.Dependency
import org.grails.build.logging.GrailsConsoleAntBuilder
import org.grails.build.parsing.CommandLine
import org.grails.cli.GrailsCli
import org.grails.cli.profile.*
import org.grails.cli.profile.CommandDescription
import org.grails.cli.profile.ExecutionContext
import org.grails.cli.profile.Feature
import org.grails.cli.profile.Profile
import org.grails.cli.profile.ProfileRepository
import org.grails.cli.profile.ProfileRepositoryAware
import org.grails.cli.profile.commands.io.GradleDependency
import org.grails.cli.profile.repository.MavenProfileRepository
import org.grails.io.support.FileSystemResource
import org.grails.io.support.Resource

import java.nio.file.*
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.SimpleFileVisitor
import java.nio.file.attribute.BasicFileAttributes

/**
Expand All @@ -55,6 +64,7 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos

protected static final String APPLICATION_YML = "application.yml"
protected static final String BUILD_GRADLE = "build.gradle"
protected static final String GRADLE_PROPERTIES = "gradle.properties"
public static final String UNZIP_PROFILE_TEMP_DIR = "tempgrailsapp"

ProfileRepository profileRepository
Expand Down Expand Up @@ -154,6 +164,7 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
protected void appendFeatureFiles(File skeletonDir) {
def ymlFiles = findAllFilesByName(skeletonDir, APPLICATION_YML)
def buildGradleFiles = findAllFilesByName(skeletonDir, BUILD_GRADLE)
def gradlePropertiesFiles = findAllFilesByName(skeletonDir, GRADLE_PROPERTIES)

ymlFiles.each { File newYml ->
File oldYml = new File(getDestinationDirectory(newYml), APPLICATION_YML)
Expand All @@ -169,6 +180,15 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
File destFile = new File(getDestinationDirectory(srcFile), BUILD_GRADLE)
destFile.text = destFile.getText(ENCODING) + System.lineSeparator() + srcFile.getText(ENCODING)
}

gradlePropertiesFiles.each { File srcFile->
File destFile = new File(getDestinationDirectory(srcFile), GRADLE_PROPERTIES)
if (!destFile.exists()) {
destFile.createNewFile()
}
destFile.append(srcFile.getText(ENCODING))
// destFile.text = destFile.getText(ENCODING) + srcFile.getText(ENCODING)
}
}

protected void buildTargetFolders(Profile profile, Map<Profile, File> targetDir, File projectDir) {
Expand Down Expand Up @@ -411,7 +431,11 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
.unique()
.join(ln)

def buildRepositories = profile.buildRepositories.collect(repositoryUrl.curry(8)).unique().join(ln)
def buildRepositories = profile.buildRepositories
for (Feature f in features) {
buildRepositories.addAll(f.getBuildRepositories())
}
buildRepositories = buildRepositories.collect(repositoryUrl.curry(8)).unique().join(ln)

buildDependencies = buildDependencies.collect() { Dependency dep ->
String artifactStr = resolveArtifactString(dep)
Expand Down Expand Up @@ -609,16 +633,16 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
Set<File> sourceBuildGradles = findAllFilesByName(skeletonDir, BUILD_GRADLE)

sourceBuildGradles.each { File srcFile ->
File srcDir = srcFile.parentFile
File destDir = getDestinationDirectory(srcFile)
File destFile = new File(destDir, BUILD_GRADLE)
final File srcDir = srcFile.parentFile
final File destDir = getDestinationDirectory(srcFile)
final File destFile = new File(destDir, BUILD_GRADLE)

ant.copy(file:"${srcDir}/.gitignore", todir: destDir, failonerror:false)

if (!destFile.exists()) {
ant.copy file:srcFile, tofile:destFile
} else if (buildMergeProfileNames.contains(participatingProfile.name)) {
def concatFile = "${destDir}/concat.gradle"
def concatFile = "${destDir}/concat-build.gradle"
ant.move(file:destFile, tofile: concatFile)
ant.concat([destfile: destFile, fixlastline: true], {
path {
Expand All @@ -630,6 +654,27 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
}
}

Set<File> sourceGradleProperties = findAllFilesByName(skeletonDir, GRADLE_PROPERTIES)

sourceGradleProperties.each { File srcFile ->
File destDir = getDestinationDirectory(srcFile)
File destFile = new File(destDir, GRADLE_PROPERTIES)

if (!destFile.exists()) {
ant.copy file: srcFile, tofile: destFile
} else {
def concatGradlePropertiesFile = "${destDir}/concat-gradle.properties"
ant.move(file: destFile, tofile: concatGradlePropertiesFile)
ant.concat([destfile: destFile, fixlastline: true], {
path {
pathelement location: concatGradlePropertiesFile
pathelement location: srcFile
}
})
ant.delete(file: concatGradlePropertiesFile, failonerror: false)
}
}

ant.chmod(dir: targetDirectory, includes: profile.executablePatterns.join(' '), perm: 'u+x')

// Cleanup temporal directories
Expand All @@ -646,6 +691,7 @@ class CreateAppCommand extends ArgumentCompletingCommand implements ProfileRepos
exclude name: exc
}
exclude name: "**/"+BUILD_GRADLE
exclude name: "**/"+GRADLE_PROPERTIES
binaryFileExtensions.each { ext ->
exclude(name: "**/*.${ext}")
}
Expand Down