Permalink
Browse files

Profiles - profile repository support / read profiles from Maven repos

  • Loading branch information...
1 parent f871dfd commit 0b1350c6249feb30ce46c3d99c5adda9ab6fae46 @graemerocher graemerocher committed Oct 3, 2015
Showing with 1,020 additions and 262 deletions.
  1. +7 −2 grails-bootstrap/src/main/groovy/grails/io/IOUtils.groovy
  2. +20 −0 grails-bootstrap/src/main/groovy/org/grails/io/support/SpringIOUtils.java
  3. +41 −0 grails-bootstrap/src/main/groovy/org/grails/io/support/StaticResourceLoader.java
  4. +1 −0 grails-gradle-model/src/main/groovy/org/grails/gradle/plugin/model/DefaultGrailsClasspath.groovy
  5. +11 −0 grails-gradle-model/src/main/groovy/org/grails/gradle/plugin/model/GrailsClasspath.groovy
  6. +49 −1 grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy
  7. +26 −15 grails-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy
  8. +15 −1 ...e-plugin/src/main/groovy/org/grails/gradle/plugin/model/GrailsClasspathToolingModelBuilder.groovy
  9. +16 −5 ...-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/profiles/GrailsProfileGradlePlugin.groovy
  10. +61 −0 ...-plugin/src/main/groovy/org/grails/gradle/plugin/profiles/GrailsProfilePublishGradlePlugin.groovy
  11. +5 −4 ...-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/profiles/tasks/ProfileCompilerTask.groovy
  12. +49 −21 ...lugin/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsCentralPublishGradlePlugin.groovy
  13. +4 −4 ...s-gradle-plugin/src/main/groovy/org/grails/gradle/plugin/publishing/GrailsPublishExtension.groovy
  14. +1 −0 ...le-plugin/src/main/resources/META-INF/gradle-plugins/org.grails.grails-profile-publish.properties
  15. +29 −9 grails-shell/src/main/groovy/org/grails/cli/GrailsCli.groovy
  16. +2 −2 grails-shell/src/main/groovy/org/grails/cli/gradle/cache/CachedGradleOperation.groovy
  17. +2 −0 grails-shell/src/main/groovy/org/grails/cli/gradle/cache/ListReadingCachedGradleOperation.groovy
  18. +65 −0 grails-shell/src/main/groovy/org/grails/cli/gradle/cache/MapReadingCachedGradleOperation.groovy
  19. +1 −1 grails-shell/src/main/groovy/org/grails/cli/gradle/commands/GradleCommand.groovy
  20. +6 −1 grails-shell/src/main/groovy/org/grails/cli/gradle/commands/ReadGradleTasks.groovy
  21. +215 −0 grails-shell/src/main/groovy/org/grails/cli/profile/AbstractProfile.groovy
  22. +16 −157 grails-shell/src/main/groovy/org/grails/cli/profile/DefaultProfile.groovy
  23. +22 −1 grails-shell/src/main/groovy/org/grails/cli/profile/Profile.java
  24. +3 −1 grails-shell/src/main/groovy/org/grails/cli/profile/ProfileRepository.groovy
  25. +22 −4 grails-shell/src/main/groovy/org/grails/cli/profile/commands/CreateAppCommand.groovy
  26. +13 −16 .../src/main/groovy/org/grails/cli/profile/commands/factory/FileSystemCommandResourceResolver.groovy
  27. +3 −2 ...ll/src/main/groovy/org/grails/cli/profile/commands/factory/ResourceResolvingCommandFactory.groovy
  28. +4 −4 grails-shell/src/main/groovy/org/grails/cli/profile/commands/templates/TemplateRendererImpl.groovy
  29. +9 −4 grails-shell/src/main/groovy/org/grails/cli/profile/git/GitProfileRepository.groovy
  30. +169 −0 grails-shell/src/main/groovy/org/grails/cli/profile/repository/AbstractJarProfileRepository.groovy
  31. +79 −0 grails-shell/src/main/groovy/org/grails/cli/profile/repository/MavenProfileRepository.groovy
  32. +40 −0 grails-shell/src/main/groovy/org/grails/cli/profile/repository/StaticJarProfileRepository.groovy
  33. +14 −7 grails-shell/src/main/groovy/org/grails/cli/profile/steps/RenderStep.groovy
@@ -94,8 +94,13 @@ class IOUtils extends SpringIOUtils {
* @return The JAR file
*/
static File findJarFile(Class targetClass) {
- def absolutePath = findClassResource(targetClass)?.getPath()
- if(absolutePath) {
+ def resource = findClassResource(targetClass)
+ findJarFile(resource)
+ }
+
+ static File findJarFile(URL resource) {
+ def absolutePath = resource?.getPath()
+ if (absolutePath) {
final jarPath = absolutePath.substring("file:".length(), absolutePath.lastIndexOf("!"))
new File(jarPath)
}
@@ -26,6 +26,7 @@
import javax.xml.parsers.SAXParserFactory;
import java.io.*;
import java.lang.reflect.Array;
+import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
@@ -40,6 +41,8 @@
* but also useful for application code.
*
* @author Juergen Hoeller
+ * @author Graeme Rocher
+ *
* @since 06.10.2003
*/
@SuppressWarnings("unchecked")
@@ -149,6 +152,23 @@ private static MessageDigest getMessageDigest(String algorithm) {
//---------------------------------------------------------------------
/**
+ * Copies all the resources for the given target directory. The base resource serves to calculate the relative path such that the
+ * directory structure is maintained
+ *
+ * @param base The base resource
+ * @param resources The resources to copy
+ * @param targetDir The target directory
+ */
+ public static void copyAll(Resource base, Resource[] resources, File targetDir) throws IOException {
+ final URL baseUrl = base.getURL();
+ for (Resource resource : resources) {
+ final InputStream input = resource.getInputStream();
+ final File target = new File(targetDir, resource.getURL().toString().substring(baseUrl.toString().length()));
+ copy(new BufferedInputStream(input), new BufferedOutputStream(new FileOutputStream(target)));
+ }
+ }
+
+ /**
* Copy the contents of the given input File to the given output File.
* @param in the file to copy from
* @param out the file to copy to
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 original authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.grails.io.support;
+
+
+/**
+ * Loads relative to a static base resource
+ *
+ * @author Graeme Rocher
+ * @since 3.1
+ */
+public class StaticResourceLoader implements ResourceLoader {
+
+ private Resource baseResource;
+
+ public StaticResourceLoader(Resource baseResource) {
+ this.baseResource = baseResource;
+ }
+
+ public Resource getResource(String location) {
+ return baseResource.createRelative(location);
+ }
+
+ public ClassLoader getClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+}
+
@@ -19,5 +19,6 @@ package org.grails.gradle.plugin.model
class DefaultGrailsClasspath implements GrailsClasspath {
private static final long serialVersionUID = 1L
List<URL> dependencies
+ List<URL> profileDependencies
String error
}
@@ -22,6 +22,17 @@ package org.grails.gradle.plugin.model
* this file is also in grails-shell project
*/
interface GrailsClasspath extends Serializable {
+ /**
+ * @return All Grails dependencies, pull from 'testRuntime' scope
+ */
List<URL> getDependencies()
+
+ /**
+ * @return The profile dependencies
+ */
+ List<URL> getProfileDependencies()
+ /**
+ * @return The error message if one occurred
+ */
String getError()
}
@@ -1,9 +1,25 @@
+/*
+ * Copyright 2015 original authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.grails.gradle.plugin.core
import grails.util.BuildSettings
import grails.util.Environment
import grails.util.GrailsNameUtils
import grails.util.Metadata
+import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import io.spring.gradle.dependencymanagement.DependencyManagementPlugin
import nebula.plugin.extraconfigurations.ProvidedBasePlugin
@@ -15,6 +31,7 @@ import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
+import org.gradle.api.artifacts.DependencyResolveDetails
import org.gradle.api.file.CopySpec
import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.tasks.JavaExec
@@ -36,8 +53,15 @@ import org.springframework.boot.gradle.SpringBootPluginExtension
import javax.inject.Inject
+/**
+ * The main Grails gradle plugin implementation
+ *
+ * @since 3.0
+ * @author Graeme Rocher
+ */
class GrailsGradlePlugin extends GroovyPlugin {
public static final String APPLICATION_CONTEXT_COMMAND_CLASS = "grails.dev.commands.ApplicationCommand"
+ public static final String PROFILE_CONFIGURATION = "profile"
List<Class<Plugin>> basePluginClasses = [ProvidedBasePlugin, IntegrationTestGradlePlugin]
List<String> excludedGrailsAppSourceDirs = ['migrations', 'assets']
List<String> grailsAppResourceDirs = ['views', 'i18n', 'conf']
@@ -52,6 +76,24 @@ class GrailsGradlePlugin extends GroovyPlugin {
void apply(Project project) {
super.apply(project)
+ def profileConfiguration = project.configurations.create(PROFILE_CONFIGURATION)
+
+ profileConfiguration.incoming.beforeResolve() {
+ if(!profileConfiguration.allDependencies) {
+ addDefaultProfile(project, profileConfiguration)
+ }
+ }
+
+ profileConfiguration.resolutionStrategy.eachDependency {
+ DependencyResolveDetails details = (DependencyResolveDetails)it
+ def group = details.requested.group ?: "org.grails.profiles"
+ def version = details.requested.version ?: BuildSettings.package.implementationVersion
+ details.useTarget(group: group, name:details.requested.name,version:version)
+ }
+
+
+
+
def springBoot = project.extensions.findByType(SpringBootPluginExtension)
if(!springBoot) {
project.plugins.apply(SpringBootPlugin)
@@ -92,6 +134,13 @@ class GrailsGradlePlugin extends GroovyPlugin {
createBuildPropertiesTask(project)
}
+ @CompileDynamic
+ void addDefaultProfile(Project project, Configuration profileConfig) {
+ project.dependencies {
+ profile ":${System.getProperty("grails.profile") ?: 'web'}:"
+ }
+ }
+
protected Task createBuildPropertiesTask(Project project) {
def buildInfoFile = project.file("${project.buildDir}/grails.build.info")
@@ -317,7 +366,6 @@ class GrailsGradlePlugin extends GroovyPlugin {
protected void enableFileWatch(Environment environment, Project project) {
if (environment.isReloadEnabled()) {
-// configureWatchPlugin(project)
project.configurations {
agent
@@ -1,19 +1,5 @@
-package org.grails.gradle.plugin.core
-
-import groovy.transform.CompileStatic
-import org.gradle.api.Project
-import org.gradle.api.Task
-import org.gradle.api.tasks.Copy
-import org.gradle.api.tasks.JavaExec
-import org.gradle.api.tasks.TaskContainer
-import org.gradle.api.tasks.bundling.Jar
-import org.gradle.language.jvm.tasks.ProcessResources
-import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
-
-import javax.inject.Inject
-
/*
- * Copyright 2014 original authors
+ * Copyright 2015 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +13,23 @@ import javax.inject.Inject
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.grails.gradle.plugin.core
+
+import groovy.transform.CompileDynamic
+import groovy.transform.CompileStatic
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.artifacts.Configuration
+import org.gradle.api.tasks.Copy
+import org.gradle.api.tasks.JavaExec
+import org.gradle.api.tasks.TaskContainer
+import org.gradle.api.tasks.bundling.Jar
+import org.gradle.language.jvm.tasks.ProcessResources
+import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
+
+import javax.inject.Inject
+
+
/**
* A Gradle plugin for Grails plugins
@@ -59,6 +62,14 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin {
}
+ @CompileDynamic
+ @Override
+ void addDefaultProfile(Project project, Configuration profileConfig) {
+ project.dependencies {
+ profile ":${System.getProperty("grails.profile") ?: 'web-plugin'}:"
+ }
+ }
+
@Override
protected Task createBuildPropertiesTask(Project project) {
// no-op
@@ -16,14 +16,18 @@
package org.grails.gradle.plugin.model
+import grails.util.BuildSettings
+import groovy.transform.CompileStatic
import org.gradle.api.Project
+import org.gradle.api.artifacts.DependencyResolveDetails
import org.gradle.api.artifacts.ResolveException
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.tooling.provider.model.ToolingModelBuilder
/**
* Builds the GrailsClasspath instance that contains the URLs of the resolved dependencies
*/
+@CompileStatic
class GrailsClasspathToolingModelBuilder implements ToolingModelBuilder {
@Override
boolean canBuild(String modelName) {
@@ -34,10 +38,20 @@ class GrailsClasspathToolingModelBuilder implements ToolingModelBuilder {
Object buildAll(String modelName, Project project) {
// testRuntime includes provided
try {
+
List<URL> runtimeDependencies = project.getConfigurations().getByName("testRuntime").getResolvedConfiguration().getResolvedArtifacts().collect { ResolvedArtifact artifact ->
artifact.getFile().toURI().toURL()
}
- new DefaultGrailsClasspath(dependencies: runtimeDependencies)
+
+ def grailsClasspath = new DefaultGrailsClasspath(dependencies: runtimeDependencies)
+
+ def profileConfiguration = project.getConfigurations().getByName("profile")
+ if(profileConfiguration != null) {
+ grailsClasspath.profileDependencies = profileConfiguration.getResolvedConfiguration().getResolvedArtifacts().collect() { ResolvedArtifact artifact ->
+ artifact.getFile().toURI().toURL()
+ }
+ }
+ return grailsClasspath
} catch (ResolveException e) {
new DefaultGrailsClasspath(error: e.message)
}
@@ -16,18 +16,13 @@
package org.grails.gradle.plugin.profiles
import grails.io.IOUtils
-import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.gradle.api.Project
-import org.gradle.api.artifacts.Dependency
import org.gradle.api.file.CopySpec
import org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectPublicationRegistry
import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact
import org.gradle.api.internal.java.JavaLibrary
import org.gradle.api.plugins.BasePlugin
-import org.gradle.api.publish.PublishingExtension
-import org.gradle.api.publish.maven.MavenPublication
-import org.gradle.api.publish.plugins.PublishingPlugin
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.bundling.Jar
import org.gradle.configuration.project.ProjectConfigurationActionContainer
@@ -107,6 +102,22 @@ class GrailsProfileGradlePlugin extends BasePlugin {
project.getComponents().add(new JavaLibrary(jarArtifact, profileConfiguration.getAllDependencies()));
}
+ project.tasks.create("sourcesJar", Jar) { Jar jar ->
+ jar.from(commandsDir)
+ if(profileYml.exists()) {
+ jar.from(profileYml)
+ }
+ jar.from(templatesDir) { CopySpec spec ->
+ spec.into("templates")
+ }
+ jar.from(skeletonsDir) { CopySpec spec ->
+ spec.into("skeleton")
+ }
+ jar.classifier = "sources"
+ jar.destinationDir = new File(project.buildDir, "libs")
+ jar.setDescription("Assembles a jar archive containing the profile sources.")
+ jar.setGroup(BUILD_GROUP)
+ }
project.tasks.findByName("assemble").dependsOn jarTask
}
Oops, something went wrong.

0 comments on commit 0b1350c

Please sign in to comment.