Skip to content

Commit cd7aaed

Browse files
committed
Merge branch '2.1.x' into 2.2.x
Conflicts: grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/resolve/PluginInstallEngine.groovy
2 parents bd22ee3 + cc9c50f commit cd7aaed

File tree

4 files changed

+58
-32
lines changed

4 files changed

+58
-32
lines changed

grails-bootstrap/src/main/groovy/org/codehaus/groovy/grails/resolve/PluginInstallEngine.groovy

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,18 @@ class PluginInstallEngine {
221221
* avoid errors about not being able to find the src folders AFTER
222222
* the plugin has been uninstalled.
223223
*/
224-
if (!inlinePlugins.find { it.key.endsWith(name) } ) {
225-
installPluginZipInternal name, version, zipFile, false, false, true
226-
} else {
227-
// Remove the plugin to prevent duplicate class compile errors with inline version.
228-
uninstallPlugin name, version
229-
}
224+
if(!inlinePlugins.find {
225+
def pluginName = it.key.toString()
226+
if (pluginName.contains(':')) {
227+
pluginName = pluginName.split(':')[-1]
228+
}
229+
return pluginName.equals(name)
230+
} ) {
231+
installPluginZipInternal name, version, zipFile, false, false, true
232+
} else {
233+
// Remove the plugin to prevent duplicate class compile errors with inline version.
234+
uninstallPlugin name, version
235+
}
230236
}
231237

232238
/**
@@ -410,22 +416,28 @@ class PluginInstallEngine {
410416
*/
411417
protected boolean checkExistingPluginInstall(String name, version, File pluginZip, boolean isResolve = true) {
412418
Resource currentInstall = pluginSettings.getPluginDirForName(name)
413-
def inlinePlugins = settings.config.grails.plugin.location
414-
415-
if (!currentInstall?.exists()) {
416-
return false
417-
}
418-
419-
/*
420-
* If the plugin to be installed is currently configured to be inline,
421-
* do not install it. This is because we want to use the inline over
422-
* the modified dependency artifact. The comparison to find the inline
423-
* plugin uses "endsWith", as inline plugins can be declared with a full
424-
* vector in settings.groovy (i.e. 'com.mycompany:my-plugin")
425-
*/
426-
if (inlinePlugins.find { it.key.endsWith(name) } ) {
427-
return true
428-
}
419+
def inlinePlugins = settings.config.grails.plugin.location
420+
421+
if (!currentInstall?.exists()) {
422+
return false
423+
}
424+
425+
/*
426+
* If the plugin to be installed is currently configured to be inline,
427+
* do not install it. This is because we want to use the inline over
428+
* the modified dependency artifact. The comparison to find the inline
429+
* plugin uses "endsWith", as inline plugins can be declared with a full
430+
* vector in settings.groovy (i.e. 'com.mycompany:my-plugin")
431+
*/
432+
if( inlinePlugins.find {
433+
def pluginName = it.key.toString()
434+
if (pluginName.contains(':')) {
435+
pluginName = pluginName.split(':')[-1]
436+
}
437+
return pluginName.equals(name)
438+
} ) {
439+
return true
440+
}
429441

430442
PluginBuildSettings pluginSettings = pluginSettings
431443
def pluginDir = currentInstall.file.canonicalFile

grails-core/src/main/groovy/org/codehaus/groovy/grails/compiler/DirectoryWatcher.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class DirectoryWatcher extends Thread {
4040
private List<FileChangeListener> listeners = new ArrayList<FileChangeListener>();
4141

4242
private Map<File, Long> lastModifiedMap = new ConcurrentHashMap<File, Long>();
43+
private Map<File, Collection<String>> directoryToExtensionsMap = new ConcurrentHashMap<File, Collection<String>>();
4344
private Map<File, Long> directoryWatch = new ConcurrentHashMap<File, Long>();
4445
private boolean active = true;
4546
private long sleepTime = 3000;
@@ -91,9 +92,20 @@ public void addWatchFile(File fileToWatch) {
9192
* @param fileExtensions The extensions
9293
*/
9394
public void addWatchDirectory(File dir, List<String> fileExtensions) {
95+
trackDirectoryExtensions(dir, fileExtensions);
9496
cacheFilesForDirectory(dir, fileExtensions, false);
9597
}
9698

99+
protected void trackDirectoryExtensions(File dir, List<String> fileExtensions) {
100+
Collection<String> existingExtensions = directoryToExtensionsMap.get(dir);
101+
if(existingExtensions == null) {
102+
directoryToExtensionsMap.put(dir, fileExtensions);
103+
}
104+
else {
105+
existingExtensions.addAll(fileExtensions);
106+
}
107+
}
108+
97109
/**
98110
* Adds a directory to watch for the given file and extensions.
99111
*
@@ -109,6 +121,7 @@ public void addWatchDirectory(File dir, String extension) {
109121
else {
110122
fileExtensions.add(extension);
111123
}
124+
trackDirectoryExtensions(dir, fileExtensions);
112125
cacheFilesForDirectory(dir, fileExtensions, false);
113126
}
114127

@@ -168,6 +181,10 @@ private void checkForNewFiles() {
168181
final Long currentTimestamp = directoryWatch.get(directory);
169182

170183
if (currentTimestamp < directory.lastModified()) {
184+
Collection<String> extensions = directoryToExtensionsMap.get(directory);
185+
if(extensions == null) {
186+
extensions = this.extensions;
187+
}
171188
cacheFilesForDirectory(directory, extensions, true);
172189
}
173190
}

grails-core/src/main/groovy/org/codehaus/groovy/grails/compiler/injection/DefaultGrailsDomainClassInjector.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@
3030
import org.codehaus.groovy.ast.MethodNode;
3131
import org.codehaus.groovy.ast.Parameter;
3232
import org.codehaus.groovy.ast.PropertyNode;
33-
import org.codehaus.groovy.ast.expr.ClassExpression;
34-
import org.codehaus.groovy.ast.expr.ConstantExpression;
35-
import org.codehaus.groovy.ast.expr.Expression;
36-
import org.codehaus.groovy.ast.expr.GStringExpression;
37-
import org.codehaus.groovy.ast.expr.ListExpression;
38-
import org.codehaus.groovy.ast.expr.MapEntryExpression;
39-
import org.codehaus.groovy.ast.expr.MapExpression;
40-
import org.codehaus.groovy.ast.expr.VariableExpression;
33+
import org.codehaus.groovy.ast.expr.*;
4134
import org.codehaus.groovy.ast.stmt.ReturnStatement;
4235
import org.codehaus.groovy.ast.stmt.Statement;
4336
import org.codehaus.groovy.classgen.GeneratorContext;
@@ -192,9 +185,10 @@ private void injectToStringMethod(ClassNode classNode) {
192185
classNode, "toString", classesWithInjectedToString);
193186

194187
if (!hasToString && !isEnum(classNode)) {
195-
GStringExpression ge = new GStringExpression(classNode.getName() + " : ${id}");
188+
GStringExpression ge = new GStringExpression(classNode.getName() + " : ${id ? id : '(unsaved)'}");
196189
ge.addString(new ConstantExpression(classNode.getName() + " : "));
197-
ge.addValue(new VariableExpression("id"));
190+
VariableExpression idVariable = new VariableExpression("id");
191+
ge.addValue(new TernaryExpression(new BooleanExpression(idVariable), idVariable, new ConstantExpression("(unsaved)")));
198192
Statement s = new ReturnStatement(ge);
199193
MethodNode mn = new MethodNode("toString", Modifier.PUBLIC, new ClassNode(String.class), new Parameter[0], new ClassNode[0], s);
200194
classNode.addMethod(mn);

grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/DomainClassGrailsPluginTests.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class Parent2 {
7070

7171
void testToString() {
7272
def instance = appCtx.getBean("ChildDomainClass").newInstance()
73+
74+
assertEquals('Child : (unsaved)', instance.toString())
75+
7376
instance.id = 1
7477
assertEquals('Child : 1', instance.toString())
7578

0 commit comments

Comments
 (0)