Skip to content

Commit

Permalink
Grails Shell: Apply IDEA Groovy and Java Code Style
Browse files Browse the repository at this point in the history
Fixes violations for Checkstyle and Codenarc check
  • Loading branch information
rainboyan committed Mar 26, 2023
1 parent 175b0bc commit e38de56
Show file tree
Hide file tree
Showing 60 changed files with 3,362 additions and 3,325 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.control.customizers.ImportCustomizer;

import org.grails.cli.compiler.dependencies.GrailsDependenciesDependencyManagement;
import grails.util.Environment;

import org.grails.cli.compiler.AstUtils;
import org.grails.cli.compiler.CompilerAutoConfiguration;
import org.grails.cli.compiler.DependencyCustomizer;
import org.grails.cli.compiler.GroovyCompilerConfiguration;
import org.grails.cli.compiler.autoconfigure.SpringMvcCompilerAutoConfiguration;
import org.grails.cli.compiler.dependencies.Dependency;
import org.grails.cli.compiler.dependencies.DependencyManagement;
import org.grails.cli.compiler.dependencies.GrailsDependenciesDependencyManagement;
import org.grails.cli.compiler.grape.DependencyResolutionContext;

import grails.util.Environment;

/**
* A {@link org.grails.cli.compiler.CompilerAutoConfiguration} for Grails Micro Service applications
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 the original author or authors.
* Copyright 2014-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,12 +19,13 @@ import groovy.transform.CompileStatic
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.control.CompilationFailedException
import org.codehaus.groovy.control.customizers.ImportCustomizer

import grails.util.Environment

import org.grails.cli.compiler.AstUtils
import org.grails.cli.compiler.CompilerAutoConfiguration
import org.grails.cli.compiler.DependencyCustomizer

import grails.util.Environment

/**
* @author Graeme Rocher
* @since 3.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.grails.cli.boot;

import java.lang.reflect.Constructor;
Expand All @@ -29,58 +28,60 @@
* separate ClassLoader from the application code.
*
* @author Andy Wilkinson
* @since 1.2.0
* @see System#getProperty(String)
* @see System#getenv(String)
* @since 2022.1.0
*/
public class SpringApplicationLauncher {

private static final String DEFAULT_SPRING_APPLICATION_CLASS = "grails.boot.Grails";
private static final String DEFAULT_SPRING_APPLICATION_CLASS = "grails.boot.Grails";

private final ClassLoader classLoader;
private final ClassLoader classLoader;

/**
* Creates a new launcher that will use the given {@code classLoader} to load the
* configured {@code SpringApplication} class.
* @param classLoader the {@code ClassLoader} to use
*/
public SpringApplicationLauncher(ClassLoader classLoader) {
this.classLoader = classLoader;
}
/**
* Creates a new launcher that will use the given {@code classLoader} to load the
* configured {@code SpringApplication} class.
*
* @param classLoader the {@code ClassLoader} to use
*/
public SpringApplicationLauncher(ClassLoader classLoader) {
this.classLoader = classLoader;
}

/**
* Launches the application created using the given {@code sources}. The application
* is launched with the given {@code args}.
* @param sources the sources for the application
* @param args the args for the application
* @return the application's {@code ApplicationContext}
* @throws Exception if the launch fails
*/
public Object launch(Class<?>[] sources, String[] args) throws Exception {
Map<String, Object> defaultProperties = new HashMap<>();
defaultProperties.put("spring.groovy.template.check-template-location", "false");
Class<?> applicationClass = Class.forName(getSpringApplicationClassName(), false, this.classLoader);
Constructor<?> constructor = applicationClass.getDeclaredConstructor(Class[].class);
constructor.setAccessible(true);
Object application = constructor.newInstance((Object) sources);
applicationClass.getMethod("setDefaultProperties", Map.class).invoke(application, defaultProperties);
Method method = applicationClass.getMethod("run", String[].class);
return method.invoke(application, (Object) args);
}
/**
* Launches the application created using the given {@code sources}. The application
* is launched with the given {@code args}.
*
* @param sources the sources for the application
* @param args the args for the application
* @return the application's {@code ApplicationContext}
* @throws Exception if the launch fails
*/
public Object launch(Class<?>[] sources, String[] args) throws Exception {
Map<String, Object> defaultProperties = new HashMap<>();
defaultProperties.put("spring.groovy.template.check-template-location", "false");
Class<?> applicationClass = Class.forName(getSpringApplicationClassName(), false, this.classLoader);
Constructor<?> constructor = applicationClass.getDeclaredConstructor(Class[].class);
constructor.setAccessible(true);
Object application = constructor.newInstance((Object) sources);
applicationClass.getMethod("setDefaultProperties", Map.class).invoke(application, defaultProperties);
Method method = applicationClass.getMethod("run", String[].class);
return method.invoke(application, (Object) args);
}

private String getSpringApplicationClassName() {
String className = System.getProperty("spring.application.class.name");
if (className == null) {
className = getEnvironmentVariable("SPRING_APPLICATION_CLASS_NAME");
}
if (className == null) {
className = DEFAULT_SPRING_APPLICATION_CLASS;
}
return className;
}
private String getSpringApplicationClassName() {
String className = System.getProperty("spring.application.class.name");
if (className == null) {
className = getEnvironmentVariable("SPRING_APPLICATION_CLASS_NAME");
}
if (className == null) {
className = DEFAULT_SPRING_APPLICATION_CLASS;
}
return className;
}

protected String getEnvironmentVariable(String name) {
return System.getenv(name);
}
protected String getEnvironmentVariable(String name) {
return System.getenv(name);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.grails.cli.boot;

import java.io.IOException;
Expand All @@ -30,55 +29,55 @@
* {@link SpringBootServletInitializer} for CLI packaged WAR files.
*
* @author Phillip Webb
* @since 1.3.0
* @since 2022.1.0
*/
public class SpringApplicationWebApplicationInitializer extends SpringBootServletInitializer {

/**
* The entry containing the source class.
*/
public static final String SOURCE_ENTRY = "Spring-Application-Source-Classes";
/**
* The entry containing the source class.
*/
public static final String SOURCE_ENTRY = "Spring-Application-Source-Classes";

private String[] sources;
private String[] sources;

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
try {
this.sources = getSources(servletContext);
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
super.onStartup(servletContext);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
try {
this.sources = getSources(servletContext);
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
super.onStartup(servletContext);
}

private String[] getSources(ServletContext servletContext) throws IOException {
Manifest manifest = getManifest(servletContext);
if (manifest == null) {
throw new IllegalStateException("Unable to read manifest");
}
String sources = manifest.getMainAttributes().getValue(SOURCE_ENTRY);
return sources.split(",");
}
private String[] getSources(ServletContext servletContext) throws IOException {
Manifest manifest = getManifest(servletContext);
if (manifest == null) {
throw new IllegalStateException("Unable to read manifest");
}
String sources = manifest.getMainAttributes().getValue(SOURCE_ENTRY);
return sources.split(",");
}

private Manifest getManifest(ServletContext servletContext) throws IOException {
InputStream stream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF");
return (stream != null) ? new Manifest(stream) : null;
}
private Manifest getManifest(ServletContext servletContext) throws IOException {
InputStream stream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF");
return (stream != null) ? new Manifest(stream) : null;
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Class<?>[] sourceClasses = new Class<?>[this.sources.length];
for (int i = 0; i < this.sources.length; i++) {
sourceClasses[i] = Class.forName(this.sources[i], false, classLoader);
}
return builder.sources(sourceClasses).properties("spring.groovy.template.check-template-location=false");
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Class<?>[] sourceClasses = new Class<?>[this.sources.length];
for (int i = 0; i < this.sources.length; i++) {
sourceClasses[i] = Class.forName(this.sources[i], false, classLoader);
}
return builder.sources(sourceClasses).properties("spring.groovy.template.check-template-location=false");
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}

}
Loading

0 comments on commit e38de56

Please sign in to comment.