Skip to content

Commit

Permalink
completely disable install-plugin and print appropriate message so th…
Browse files Browse the repository at this point in the history
…e user can take action
  • Loading branch information
graemerocher committed Mar 20, 2013
1 parent b7ee766 commit de491d1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ final class PluginResolveEngine {
dependencyManager.createCopy(settings)
}

void renderInstallInfo(String pluginName, Writer writer) {
final text = new URL("http://grails.org/api/v1.0/plugin/$pluginName?format=xml").getText(connectTimeout: 500, readTimeout: 3000)
def xml = new XmlSlurper().parseText(text)

writer << """
Since Grails 2.3, it is no longer possible to install plugins using the install-plugin command.
Plugins must be declared in the grails-app/conf/BuildConfig.groovy file.
Example:
grails.project.dependency.resolution = {
...
plugins {
compile ":$pluginName:${xml.version.text()}"
}
}
"""
}
/**
* Renders plugin info to the target writer
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,32 @@ import grails.util.BuildSettings
import spock.lang.Ignore
import spock.lang.Specification

@Ignore
//@Ignore
class PluginResolveEngineSpec extends Specification {

def "Test install-plugin no longer valid message"() {
given:"An instance of the resolve engine"
def resolveEngine = systemUnderTest()

when:"We resolve the 'feeds' plugin"
def sw = new StringWriter()
resolveEngine.renderInstallInfo("feeds", sw)
def info = sw.toString()

then:"The correct metadata is obtained"
info == '''
Since Grails 2.3, it is no longer possible to install plugins using the install-plugin command.
Plugins must be declared in the grails-app/conf/BuildConfig.groovy file.
Example:
grails.project.dependency.resolution = {
...
plugins {
compile ":feeds:1.5"
}
}
'''
}
def "Test that plugin-info obtains relevant plugin information in a plugin exists"() {
given:"An instance of the resolve engine"
def resolveEngine = systemUnderTest()
Expand Down
33 changes: 28 additions & 5 deletions scripts/InstallPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@
*
* @since 0.4
*/
import org.codehaus.groovy.grails.resolve.PluginResolveEngine

includeTargets << grailsScript("_GrailsPlugins")

def displayPluginInfo = { pluginName ->

def settings = grailsSettings
def pluginResolveEngine = new PluginResolveEngine(settings.dependencyManager, settings)
def sw = new StringWriter()
pluginXml = pluginResolveEngine.renderInstallInfo(pluginName, sw)
grailsConsole.warn sw.toString()
}


target(installPlugin:"Installs a plug-in for the given URL or name and version") {
depends(checkVersion, parseArguments, configureProxy)
grailsConsole.warn 'The install-plugin command is deprecated and \
Expand All @@ -47,19 +59,30 @@ See http://grails.org/doc/2.2.x/guide/conf.html#pluginDependencies.'
def pluginFile = new File(pluginArgs[0])
def urlPattern = ~"^[a-zA-Z][a-zA-Z0-9\\-\\.\\+]*://"
if (pluginArgs[0] =~ urlPattern) {
def url = new URL(pluginArgs[0])
installed = doInstallPluginFromURL(url)
grailsConsole.warn """
Since Grails 2.3, it is no longer possible to install plugins directly via a URL.
Upload the plugin to a Maven-compatible repository and declare the dependency in grails-app/conf/BuildConfig.groovy.
"""
}
else if (pluginFile.exists() && pluginFile.name.startsWith("grails-") && pluginFile.name.endsWith(".zip")) {
installed = doInstallPluginZip(pluginFile)
grailsConsole.warn """
Since Grails 2.3, it is no longer possible to install plugins directly from the file sytem.
If you wish to use local plugins then run 'maven-install' in the plugin directory to install the plugin into your local Maven cache.
Then inside your application's grails-app/conf/BuildConfig.groovy file declare the dependency and it will be resolved from you Maven cache.
If you make a change to the plugin simply run 'maven-install' in the directory of the plugin project again and the change will be picked up by the application (if the plugin version ends with -SNAPSHOT)
"""

}
else {
// The first argument is the plugin name, the second
// (if provided) is the plugin version.
installed = doInstallPlugin(pluginArgs[0], pluginArgs[1])
displayPluginInfo(pluginArgs[0])
}

event("StatusFinal", [installed ? "Plugin installed." : 'Plugin not installed.'])
}
else {
event("StatusError", [ ERROR_MESSAGE])
Expand Down

0 comments on commit de491d1

Please sign in to comment.