Skip to content

Commit b0d5f75

Browse files
authored
Merge pull request graceframework#1135 from rainboyan/refactor-core-api
Refactor the core API of the framework Closes graceframeworkgh-1136
2 parents 83faa05 + 8331326 commit b0d5f75

File tree

216 files changed

+7122
-3812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+7122
-3812
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ subprojects { project ->
267267
if (project.name == 'grace-dependencies') return
268268
if (project.name == 'grace-bom') return
269269

270-
jar{
270+
jar {
271271
manifest.mainAttributes(
272272
"Built-By": System.properties['user.name'],
273273
"Created-By": System.properties['java.vm.version'] + " (" + System.properties['java.vm.vendor'] + ")",

grace-api/src/main/groovy/grails/core/ArtefactHandlerAdapter.java

Lines changed: 0 additions & 215 deletions
This file was deleted.

grace-boot/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
api libs.spring.web
2020

2121
compileOnly libs.jsr305
22+
compileOnly libs.spring.boot.devtools
2223

2324
testImplementation project(":grace-plugin-controllers")
2425
testImplementation project(":grace-test")

grace-boot/src/main/groovy/grails/boot/Grails.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@
1515
*/
1616
package grails.boot;
1717

18+
import java.util.Arrays;
19+
import java.util.LinkedHashSet;
20+
1821
import org.springframework.boot.SpringApplication;
22+
import org.springframework.context.ApplicationContext;
1923
import org.springframework.context.ConfigurableApplicationContext;
24+
import org.springframework.context.support.AbstractApplicationContext;
2025
import org.springframework.core.env.ConfigurableEnvironment;
2126
import org.springframework.core.io.ClassPathResource;
2227
import org.springframework.core.io.ResourceLoader;
@@ -81,6 +86,14 @@ protected void configureBanner(Environment environment) {
8186
}
8287
}
8388

89+
@Override
90+
protected void load(ApplicationContext context, Object[] sources) {
91+
super.load(context, sources);
92+
if (context instanceof AbstractApplicationContext) {
93+
((AbstractApplicationContext) context).getBeanFactory().registerSingleton("PRIMARY_SOURCES", new LinkedHashSet<>(Arrays.asList(sources)));
94+
}
95+
}
96+
8497
/**
8598
* Static helper that can be used to run a {@link Grails} from the
8699
* specified source using default settings.

grace-boot/src/main/groovy/grails/boot/config/GrailsApplicationPostProcessor.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2024 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
import java.util.Arrays;
1919
import java.util.Collection;
2020
import java.util.Collections;
21+
import java.util.LinkedHashSet;
2122
import java.util.List;
2223
import java.util.Map;
2324
import java.util.Set;
@@ -146,7 +147,7 @@ protected final void initializeGrailsApplication(ApplicationContext applicationC
146147
Environment.setInitializing(true);
147148
this.grailsApplication.setApplicationContext(applicationContext);
148149
this.grailsApplication.setMainContext(applicationContext);
149-
this.classes = loadArtefactClasses();
150+
this.classes = loadArtefactClasses(applicationContext);
150151
this.classes.stream().filter(GrailsPluginArtefactHandler::isGrailsPlugin)
151152
.forEach(this.pluginManager::addUserPlugin);
152153
customizePluginManager(this.pluginManager);
@@ -180,17 +181,29 @@ protected void performGrailsInitializationSequence() {
180181
this.classes.forEach(this.grailsApplication::addArtefact);
181182
}
182183

183-
protected Set<Class<?>> loadArtefactClasses() {
184+
protected Set<Class<?>> loadArtefactClasses(ApplicationContext applicationContext) {
184185
StartupStep artefactStep = this.applicationStartup.start("grails.application.artefact-classes.loaded");
185-
GrailsComponentScanner scanner = new GrailsComponentScanner(this.applicationContext, this.applicationStartup);
186-
Set<Class<?>> classes;
186+
GrailsComponentScanner scanner = new GrailsComponentScanner(applicationContext, this.applicationStartup);
187+
Set<Class<?>> classes = new LinkedHashSet<>();
187188
try {
188-
classes = scanner.scan(Artefact.class);
189+
classes.addAll(scanner.scan(Artefact.class));
189190
}
190191
catch (ClassNotFoundException ignored) {
191-
classes = Collections.emptySet();
192192
}
193-
193+
if (applicationContext.containsBean("PRIMARY_SOURCES")) {
194+
Object primarySourcesBean = applicationContext.getBean("PRIMARY_SOURCES");
195+
try {
196+
if (primarySourcesBean instanceof Set<?>) {
197+
for (Object source : (Set<?>) primarySourcesBean) {
198+
if (source instanceof Class<?>) {
199+
classes.add((Class<?>) source);
200+
}
201+
}
202+
}
203+
}
204+
catch (Exception ignored) {
205+
}
206+
}
194207
artefactStep.tag("classCount", String.valueOf(classes.size())).end();
195208
return classes;
196209
}

0 commit comments

Comments
 (0)