Skip to content

Commit d82c84b

Browse files
author
graeme
committed
fix for cannot get dependencyNames on null object problem(GRAILS-1986)
git-svn-id: https://svn.codehaus.org/grails/trunk@6275 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent 4ab7bc6 commit d82c84b

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

scripts/InstallPlugin.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU
2626
import groovy.xml.dom.DOMCategory
2727
import groovy.xml.MarkupBuilder
28+
import org.springframework.util.Assert
2829

2930
appName = ""
3031

@@ -158,6 +159,9 @@ target(installPlugin:"Implementation target") {
158159
Ant.delete(dir:"${pluginsBase}/${fullPluginName}")
159160
clean()
160161
def plugin = pluginManager.getFailedPlugin(pluginName)
162+
163+
Assert.notNull plugin, "Grails Bug: If the plugin wasn't loaded it should be in the failed plugins list, but is not. Please report the issue."
164+
161165
println "Failed to install plug-in [${fullPluginName}]. Missing depedencies: ${plugin.dependencyNames.inspect()}"
162166
event("PluginInstallFailed", [ "Plugin ${fullPluginName} failed to install"])
163167
}

src/commons/org/codehaus/groovy/grails/commons/GrailsClassUtils.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,21 +336,39 @@ public static String getScriptName(String name) {
336336
* @return A class name
337337
*/
338338
public static String getNameFromScript(String scriptName) {
339-
if(scriptName.indexOf('-') > -1) {
340-
StringBuffer buf = new StringBuffer();
341-
String[] tokens = scriptName.split("-");
342-
for (int i = 0; i < tokens.length; i++) {
343-
String token = tokens[i];
344-
buf.append(token.substring(0,1).toUpperCase())
345-
.append(token.substring(1));
346-
}
347-
return buf.toString();
348-
}
349-
else {
350-
return scriptName.substring(0,1).toUpperCase() + scriptName.substring(1);
351-
}
352-
353-
339+
return getClassNameForLowerCaseHyphenSeparatedName(scriptName);
340+
}
341+
342+
/**
343+
* Converts foo-bar into fooBar
344+
*
345+
* @param name The lower case hyphen separated name
346+
* @return The property name equivalent
347+
*/
348+
public static String getPropertyNameForLowerCaseHyphenSeparatedName(String name) {
349+
return getPropertyName(getClassNameForLowerCaseHyphenSeparatedName(name));
350+
}
351+
352+
/**
353+
* Converts foo-bar into FooBar
354+
*
355+
* @param name The lower case hyphen separated name
356+
* @return The class name equivalent
357+
*/
358+
private static String getClassNameForLowerCaseHyphenSeparatedName(String name) {
359+
if(name.indexOf('-') > -1) {
360+
StringBuffer buf = new StringBuffer();
361+
String[] tokens = name.split("-");
362+
for (int i = 0; i < tokens.length; i++) {
363+
String token = tokens[i];
364+
buf.append(token.substring(0,1).toUpperCase())
365+
.append(token.substring(1));
366+
}
367+
return buf.toString();
368+
}
369+
else {
370+
return name.substring(0,1).toUpperCase() + name.substring(1);
371+
}
354372
}
355373

356374
/**

src/commons/org/codehaus/groovy/grails/plugins/AbstractGrailsPluginManager.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,21 @@ public Resource[] getPluginResources() {
119119
return this.pluginResources;
120120
}
121121
public GrailsPlugin getGrailsPlugin(String name) {
122-
return (GrailsPlugin)this.plugins.get(name);
122+
if(name.indexOf('-') > -1) name = GrailsClassUtils.getPropertyNameForLowerCaseHyphenSeparatedName(name);
123+
return (GrailsPlugin)this.plugins.get(name);
123124
}
124125
public GrailsPlugin getGrailsPlugin(String name, Object version) {
125-
GrailsPlugin plugin = (GrailsPlugin)this.plugins.get(name);
126+
if(name.indexOf('-') > -1) name = GrailsClassUtils.getPropertyNameForLowerCaseHyphenSeparatedName(name);
127+
GrailsPlugin plugin = (GrailsPlugin)this.plugins.get(name);
126128
if(plugin != null) {
127129
if(GrailsPluginUtils.isValidVersion(plugin.getVersion(), version.toString()))
128130
return plugin;
129131
}
130132
return null;
131133
}
132134
public boolean hasGrailsPlugin(String name) {
133-
return this.plugins.containsKey(name);
135+
if(name.indexOf('-') > -1) name = GrailsClassUtils.getPropertyNameForLowerCaseHyphenSeparatedName(name);
136+
return this.plugins.containsKey(name);
134137
}
135138
public void doDynamicMethods() {
136139
checkInitialised();

src/commons/org/codehaus/groovy/grails/plugins/DefaultGrailsPluginManager.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,6 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
547547
}
548548
}
549549

550-
public boolean hasGrailsPlugin(String name) {
551-
return this.plugins.containsKey(name);
552-
}
553-
554550
public void setParentApplicationContext(ApplicationContext parent) {
555551
this.parentCtx = parent;
556552
}

0 commit comments

Comments
 (0)