Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,36 @@ private void loadDelayedPlugins() {
delayedLoadPlugins.add(plugin);
} else {
failedPlugins.put(plugin.getName(), plugin);
LOG.error(
"ERROR: Plugin [{}] cannot be loaded because its dependencies [{}}] cannot be resolved",
plugin.getName(),
plugin.getDependsOnNames()
);
logUnresolvedDependencies(plugin);
}
}
}
}

private void logUnresolvedDependencies(PluginInfo plugin) {
var unresolvedDependencies = new ArrayList<String>();
for (var name : plugin.getDependsOnNames()) {
var requiredVersion = plugin.getMetadata().getDependentVersion(name);
var dependency = findPlugin(name);
if (dependency == null) {
unresolvedDependencies.add(
"dependency [" + name + "] with required version [" + requiredVersion + "] is missing"
);
} else if (!GrailsVersionUtils.isValidVersion(dependency.getPluginVersion(), requiredVersion)) {
unresolvedDependencies.add(
"dependency [" + name + "] has version [" + dependency.getPluginVersion() +
"] but requires [" + requiredVersion + "]"
);
}
}
LOG.warn(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree on this being a warning, there is a legitimate configuration issue. This should be an error message

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this at ERROR rather than WARN.

Unresolved dependencies already put the plugin in failedPlugins; that is a load failure, and the previous code logged it with LOG.error. A clearer message is welcome, but the severity should stay ERROR so it isn’t lost when WARN is filtered.

"Grails plug-in [{}] with version [{}] cannot be loaded: {}",
plugin.getName(),
plugin.getPluginVersion(),
String.join("; ", unresolvedDependencies)
);
}
Comment on lines +427 to +460

/**
* Checks whether the first plugin is dependent on the second plugin.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,53 @@ class RepeatedProbeGrailsPlugin {
cleanup:
System.setErr(originalErr)
}

def 'reports every missing or incompatible plugin dependency at WARN'() {
given: 'a discovery bean with one available and one unresolved plugin'
def gcl = new GroovyClassLoader()
def availableDependencyClass = gcl.parseClass('''
class AvailableDependencyGrailsPlugin {
def version = "1.0.0"
}
''')
def unresolvedDependenciesClass = gcl.parseClass('''
class UnresolvedDependenciesGrailsPlugin {
def version = "4.0.0"
def dependsOn = [missingDependency: "1.0.0", availableDependency: "2.0.0"]
}
''')
def discovery = new DefaultPluginDiscovery(
[availableDependencyClass, unresolvedDependenciesClass] as Class<?>[]
)
discovery.loadPluginsFromClasspath = false

and: 'standard error is captured to observe slf4j-simple output'
def originalErr = System.err
def captured = new ByteArrayOutputStream()
System.setErr(new PrintStream(captured, true))

when: 'the public discovery API initializes the plugin set'
discovery.init(new StandardEnvironment())

then: 'the unresolved plugin remains failed and is not loaded'
discovery.hasFailedPlugin('unresolvedDependencies')
!discovery.hasPlugin('unresolvedDependencies')
discovery.getPluginsInLoadOrder()*.name == ['availableDependency']

and: 'one concise warning identifies the failed plugin and every unresolved dependency'
def warnings = captured.toString().readLines().findAll { it.contains('unresolvedDependencies') }
warnings.size() == 1
warnings[0].contains('WARN')
warnings[0].contains('Grails plug-in [unresolvedDependencies] with version [4.0.0] cannot be loaded')
warnings[0].contains('dependency [missingDependency] with required version [1.0.0] is missing')
warnings[0].contains('dependency [availableDependency] has version [1.0.0] but requires [2.0.0]')

and: 'normal verbosity does not include a stack trace'
!captured.toString().contains('at org.apache.grails.core.plugins.DefaultPluginDiscovery')

cleanup:
System.setErr(originalErr)
}
}

// Test fixture plugin classes for GrailsPluginDiscoverySpec
Expand Down
Loading