Skip to content

Commit

Permalink
Remove needless log level checks
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Jul 7, 2022
1 parent c0c0a50 commit 50a7520
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 277 deletions.
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@
<version>3.4.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<!-- fix CVE-2021-29425 -->
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
<scope>runtime</scope>
</dependency>
<dependency>
<!-- this is to support use of Groovysh (Groovy jars don't include) -->
<groupId>org.fusesource.jansi</groupId>
Expand Down
72 changes: 18 additions & 54 deletions src/main/java/org/codehaus/gmavenplus/mojo/AbstractCompileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ public abstract class AbstractCompileMojo extends AbstractGroovySourcesMojo {
protected synchronized void doCompile(final Set<File> sources, final List classpath, final File compileOutputDirectory)
throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, MalformedURLException {
if (sources == null || sources.isEmpty()) {
if (getLog().isInfoEnabled()) {
getLog().info("No sources specified for compilation. Skipping.");
}
getLog().info("No sources specified for compilation. Skipping.");
return;
}

Expand All @@ -319,9 +317,7 @@ protected synchronized void doCompile(final Set<File> sources, final List classp
if (groovyVersionSupportsAction() && !skipBytecodeCheck) {
verifyGroovyVersionSupportsTargetBytecode();
} else {
if (getLog().isErrorEnabled()) {
getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support compilation. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping compiling.");
}
getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support compilation. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping compiling.");
return;
}

Expand All @@ -343,9 +339,7 @@ protected synchronized void doCompile(final Set<File> sources, final List classp

// log compiled classes
List classes = (List) invokeMethod(findMethod(compilationUnitClass, "getClasses"), compilationUnit);
if (getLog().isInfoEnabled()) {
getLog().info("Compiled " + classes.size() + " file" + (classes.size() != 1 ? "s" : "") + ".");
}
getLog().info("Compiled " + classes.size() + " file" + (classes.size() != 1 ? "s" : "") + ".");
}

private static String translateJavacTargetToTargetBytecode(String targetBytecode) {
Expand Down Expand Up @@ -380,14 +374,10 @@ protected Object setupCompilationUnit(final Set<File> sources, final Class<?> co
} else {
compilationUnit = invokeConstructor(findConstructor(compilationUnitClass, compilerConfigurationClass, CodeSource.class, groovyClassLoaderClass), compilerConfiguration, null, groovyClassLoader);
}
if (getLog().isDebugEnabled()) {
getLog().debug("Adding Groovy to compile:");
}
getLog().debug("Adding Groovy to compile:");
Method addSourceMethod = findMethod(compilationUnitClass, "addSource", File.class);
for (File source : sources) {
if (getLog().isDebugEnabled()) {
getLog().debug(" " + source);
}
getLog().debug(" " + source);
invokeMethod(addSourceMethod, compilationUnit, source);
}

Expand All @@ -410,13 +400,9 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
Object compilerConfiguration = invokeConstructor(findConstructor(compilerConfigurationClass));
if (configScript != null) {
if (!configScript.exists()) {
if (getLog().isWarnEnabled()) {
getLog().warn("Configuration script file (" + configScript.getAbsolutePath() + ") doesn't exist. Ignoring configScript parameter.");
}
getLog().warn("Configuration script file (" + configScript.getAbsolutePath() + ") doesn't exist. Ignoring configScript parameter.");
} else if (groovyOlderThan(GROOVY_2_1_0_BETA1)) {
if (getLog().isWarnEnabled()) {
getLog().warn("Requested to use configScript, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_1_0_BETA1 + " or newer). Ignoring configScript parameter.");
}
getLog().warn("Requested to use configScript, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_1_0_BETA1 + " or newer). Ignoring configScript parameter.");
} else {
Class<?> bindingClass = classWrangler.getClass("groovy.lang.Binding");
Class<?> importCustomizerClass = classWrangler.getClass("org.codehaus.groovy.control.customizers.ImportCustomizer");
Expand All @@ -430,9 +416,7 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
List compilationCustomizers = (List) invokeMethod(findMethod(compilerConfigurationClass, "getCompilationCustomizers"), shellCompilerConfiguration);
compilationCustomizers.add(importCustomizer);
Object shell = invokeConstructor(findConstructor(groovyShellClass, ClassLoader.class, bindingClass, compilerConfigurationClass), classWrangler.getClassLoader(), binding, shellCompilerConfiguration);
if (getLog().isDebugEnabled()) {
getLog().debug("Using configuration script " + configScript + " for compilation.");
}
getLog().debug("Using configuration script " + configScript + " for compilation.");
invokeMethod(findMethod(groovyShellClass, "evaluate", File.class), shell, configScript);
}
}
Expand All @@ -444,16 +428,12 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
if (previewFeatures) {
if (isJavaSupportPreviewFeatures()) {
if (groovyOlderThan(GROOVY_2_5_7) || (groovyAtLeast(GROOVY_2_6_0_ALPHA1) && groovyOlderThan(GROOVY_3_0_0_BETA1))) {
if (getLog().isWarnEnabled()) {
getLog().warn("Requested to use preview features, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_5_7 + "/" + GROOVY_3_0_0_BETA1 + " or newer. No 2.6 version is supported. Ignoring previewFeatures parameter.");
}
getLog().warn("Requested to use preview features, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_5_7 + "/" + GROOVY_3_0_0_BETA1 + " or newer. No 2.6 version is supported. Ignoring previewFeatures parameter.");
} else {
invokeMethod(findMethod(compilerConfigurationClass, "setPreviewFeatures", boolean.class), compilerConfiguration, previewFeatures);
}
} else {
if (getLog().isWarnEnabled()) {
getLog().warn("Requested to use to use preview features, but your Java version (" + getJavaVersionString() + ") doesn't support it. Ignoring previewFeatures parameter.");
}
getLog().warn("Requested to use to use preview features, but your Java version (" + getJavaVersionString() + ") doesn't support it. Ignoring previewFeatures parameter.");
}
}
if (sourceEncoding != null) {
Expand All @@ -467,51 +447,35 @@ protected Object setupCompilerConfiguration(final File compileOutputDirectory, f
Map<String, Boolean> optimizationOptions = (Map<String, Boolean>) invokeMethod(findMethod(compilerConfigurationClass, "getOptimizationOptions"), compilerConfiguration);
optimizationOptions.put("indy", true);
optimizationOptions.put("int", false);
if (getLog().isInfoEnabled()) {
getLog().info("invokedynamic enabled.");
}
getLog().info("invokedynamic enabled.");
} else {
if (getLog().isWarnEnabled()) {
getLog().warn("Requested to use to use invokedynamic, but your Java version (" + getJavaVersionString() + ") doesn't support it. Ignoring invokeDynamic parameter.");
}
getLog().warn("Requested to use to use invokedynamic, but your Java version (" + getJavaVersionString() + ") doesn't support it. Ignoring invokeDynamic parameter.");
}
} else {
if (getLog().isWarnEnabled()) {
getLog().warn("Requested to use invokedynamic, but your Groovy version doesn't support it (must use have indy classifier). Ignoring invokeDynamic parameter.");
}
getLog().warn("Requested to use invokedynamic, but your Groovy version doesn't support it (must use have indy classifier). Ignoring invokeDynamic parameter.");
}
} else {
if (getLog().isWarnEnabled()) {
getLog().warn("Requested to use invokeDynamic, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_0_0_BETA3 + " or newer). Ignoring invokeDynamic parameter.");
}
getLog().warn("Requested to use invokeDynamic, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_0_0_BETA3 + " or newer). Ignoring invokeDynamic parameter.");
}
}
if (parameters) {
if (groovyAtLeast(GROOVY_2_5_0_ALPHA1)) {
if (isJavaSupportParameters()) {
invokeMethod(findMethod(compilerConfigurationClass, "setParameters", boolean.class), compilerConfiguration, parameters);
} else {
if (getLog().isWarnEnabled()) {
getLog().warn("Requested to use to use parameters, but your Java version (" + getJavaVersionString() + ") doesn't support it. Ignoring parameters parameter.");
}
getLog().warn("Requested to use to use parameters, but your Java version (" + getJavaVersionString() + ") doesn't support it. Ignoring parameters parameter.");
}
} else {
if (getLog().isWarnEnabled()) {
getLog().warn("Requested to use parameters, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_5_0_ALPHA1 + " or newer). Ignoring parameters parameter.");
}
getLog().warn("Requested to use parameters, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_2_5_0_ALPHA1 + " or newer). Ignoring parameters parameter.");
}
}
if (groovyAtLeast(GROOVY_3_0_5)) {
if ((parallelParsing == null && groovyAtLeast(GROOVY_4_0_0_ALPHA1)) || (parallelParsing != null && parallelParsing)) {
Map<String, Boolean> optimizationOptions = (Map<String, Boolean>) invokeMethod(findMethod(compilerConfigurationClass, "getOptimizationOptions"), compilerConfiguration);
optimizationOptions.put("parallelParse", true);
if (getLog().isInfoEnabled()) {
getLog().info("Parallel parsing enabled.");
}
getLog().info("Parallel parsing enabled.");
} else {
if (getLog().isInfoEnabled()) {
getLog().info("Parallel parsing disabled.");
}
getLog().info("Parallel parsing disabled.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ public abstract class AbstractGenerateStubsMojo extends AbstractGroovyStubSource
*/
protected synchronized void doStubGeneration(final Set<File> stubSources, final List<?> classpath, final File outputDirectory) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException, MalformedURLException {
if (stubSources == null || stubSources.isEmpty()) {
if (getLog().isInfoEnabled()) {
getLog().info("No sources specified for stub generation. Skipping.");
}
getLog().info("No sources specified for stub generation. Skipping.");
return;
}

Expand All @@ -282,9 +280,7 @@ protected synchronized void doStubGeneration(final Set<File> stubSources, final
if (groovyVersionSupportsAction() && !skipBytecodeCheck) {
verifyGroovyVersionSupportsTargetBytecode();
} else {
if (getLog().isErrorEnabled()) {
getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support stub generation. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping stub generation.");
}
getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support stub generation. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping stub generation.");
return;
}

Expand Down Expand Up @@ -349,20 +345,14 @@ protected void addGroovySources(final Set<File> stubSources, final Class<?> comp
for (File stubSource : stubSources) {
scriptExtensions.add(FileUtils.getFileExtension(stubSource));
}
if (getLog().isDebugEnabled()) {
getLog().debug("Detected Groovy file extensions: " + scriptExtensions + ".");
}
getLog().debug("Detected Groovy file extensions: " + scriptExtensions + ".");
if (supportsSettingExtensions()) {
invokeMethod(findMethod(compilerConfigurationClass, "setScriptExtensions", Set.class), compilerConfiguration, scriptExtensions);
}
if (getLog().isDebugEnabled()) {
getLog().debug("Adding Groovy to generate stubs for:");
}
getLog().debug("Adding Groovy to generate stubs for:");
Method addSource = findMethod(javaStubCompilationUnitClass, "addSource", File.class);
for (File stubSource : stubSources) {
if (getLog().isDebugEnabled()) {
getLog().debug(" " + stubSource);
}
getLog().debug(" " + stubSource);
if (supportsSettingExtensions()) {
invokeMethod(addSource, javaStubCompilationUnit, stubSource);
} else {
Expand All @@ -388,9 +378,7 @@ protected boolean supportsSettingExtensions() {
*/
protected void logGeneratedStubs(File outputDirectory) {
Set<File> stubs = getStubs(outputDirectory);
if (getLog().isInfoEnabled()) {
getLog().info("Generated " + stubs.size() + " stub" + (stubs.size() != 1 ? "s" : "") + ".");
}
getLog().info("Generated " + stubs.size() + " stub" + (stubs.size() != 1 ? "s" : "") + ".");
}

/**
Expand All @@ -405,9 +393,7 @@ protected void resetStubModifiedDates(final Set<File> stubs) {
for (File stub : stubs) {
boolean success = stub.setLastModified(0L);
if (!success) {
if (getLog().isWarnEnabled()) {
getLog().warn("Unable to set modified time on stub " + stub.getAbsolutePath() + ".");
}
getLog().warn("Unable to set modified time on stub " + stub.getAbsolutePath() + ".");
}
}
}
Expand Down
Loading

0 comments on commit 50a7520

Please sign in to comment.