Skip to content

Commit

Permalink
Merge pull request grails#13848 from codeconsole/7.0.x-delete-mimetyp…
Browse files Browse the repository at this point in the history
…es-plugin

Remove deprecated mimetypes which are overriding MimeTypesConfiguration
  • Loading branch information
codeconsole authored Nov 18, 2024
2 parents 2a0b7d2 + 9dbb74f commit 25a0737
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 158 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
import org.grails.web.mime.DefaultMimeTypeResolver
import org.grails.web.mime.DefaultMimeUtility
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
Expand All @@ -43,12 +42,10 @@ import org.springframework.context.annotation.Primary
class MimeTypesConfiguration {

private final GrailsApplication grailsApplication
private final ApplicationContext applicationContext
private final List<MimeTypeProvider> mimeTypeProviders

MimeTypesConfiguration(GrailsApplication grailsApplication, List<MimeTypeProvider> mimeTypeProviders) {
this.grailsApplication = grailsApplication
this.applicationContext = grailsApplication.getMainContext()
this.mimeTypeProviders = mimeTypeProviders
}

Expand Down Expand Up @@ -86,7 +83,7 @@ class MimeTypesConfiguration {

final List<MimeTypeProvider> mimeTypeProviders = this.mimeTypeProviders
processProviders(mimes, mimeTypeProviders)
final Map<String, MimeTypeProvider> childTypes = applicationContext.getBeansOfType(MimeTypeProvider.class)
final Map<String, MimeTypeProvider> childTypes = grailsApplication.mainContext.getBeansOfType(MimeTypeProvider.class)
processProviders(mimes, childTypes.values())
mimeTypes = mimes.toArray(new MimeType[0])
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@ import grails.util.GrailsUtil
*
* @author Graeme Rocher
* @since 1.0
* @deprecated Use {@link MimeTypesConfiguration} instead
*/
@Deprecated
class MimeTypesGrailsPlugin extends AbstractMimeTypesGrailsPlugin {
class MimeTypesGrailsPlugin {

def version = GrailsUtil.getGrailsVersion()
def dependsOn = [core:version, controllers:version]
def observe = ['controllers']

@Override
Closure doWithSpring() {
return super.doWithSpring()
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package grails.web.mime

import grails.core.DefaultGrailsApplication
import org.grails.plugins.web.mime.MimeTypesFactoryBean
import grails.spring.BeanBuilder
import org.grails.plugins.web.mime.MimeTypesConfiguration
import org.grails.web.mime.DefaultMimeUtility
import org.springframework.context.ApplicationContext
import spock.lang.Specification

/**
Expand All @@ -26,10 +28,15 @@ class MimeUtilitySpec extends Specification {
multipartForm: 'multipart/form-data'
]

final factory = new MimeTypesFactoryBean(grailsApplication: ga)
def bb = new BeanBuilder()
bb.beans {
grailsApplication = ga
mimeConfiguration(MimeTypesConfiguration, ga, [])
}
ga.setApplicationContext(bb.createApplicationContext())

def mimeTypes = factory.getObject()
return new DefaultMimeUtility(mimeTypes)
MimeTypesConfiguration mimeTypesConfiguration = ga.mainContext.getBean(MimeTypesConfiguration)
return new DefaultMimeUtility(mimeTypesConfiguration.mimeTypes())
}

void "Test get mime by extension method"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import grails.web.mime.MimeType
import org.grails.config.PropertySourcesConfig
import org.grails.core.lifecycle.ShutdownOperations
import org.grails.plugins.web.mime.MimeTypesConfiguration
import org.grails.plugins.web.mime.MimeTypesFactoryBean
import org.grails.web.mime.DefaultMimeUtility
import org.springframework.context.ApplicationContext
import org.springframework.context.support.GenericApplicationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import grails.persistence.Entity
import grails.rest.Linkable
import grails.rest.Resource
import grails.rest.render.Renderer
import grails.spring.BeanBuilder
import grails.util.GrailsWebMockUtil
import grails.web.CamelCaseUrlConverter
import grails.web.mapping.LinkGenerator
Expand All @@ -15,13 +16,15 @@ import grails.web.mime.MimeType
import org.grails.config.PropertySourcesConfig
import org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext
import org.grails.datastore.mapping.model.MappingContext
import org.grails.plugins.web.mime.MimeTypesFactoryBean
import org.grails.plugins.web.mime.MimeTypesConfiguration
import org.grails.support.MockApplicationContext
import org.grails.web.mapping.DefaultLinkGenerator
import org.grails.web.mapping.DefaultUrlMappingEvaluator
import org.grails.web.mapping.DefaultUrlMappingsHolder
import org.grails.web.mime.DefaultMimeUtility
import org.grails.web.servlet.mvc.GrailsWebRequest
import org.springframework.context.ApplicationContext
import org.springframework.context.support.GenericApplicationContext
import org.springframework.core.env.MapPropertySource
import org.springframework.core.env.MutablePropertySources
import org.springframework.mock.web.MockHttpServletRequest
Expand Down Expand Up @@ -89,11 +92,19 @@ abstract class BaseDomainClassRendererSpec extends Specification {
return new PropertySourcesConfig(propertySources)
}

protected static MimeType[] buildMimeTypes(application) {
def mimeTypesFactory = new MimeTypesFactoryBean()
mimeTypesFactory.grailsApplication = application
def mimeTypes = mimeTypesFactory.getObject()
return mimeTypes
private MimeType[] buildMimeTypes(application) {
final def mainContext = new GenericApplicationContext()
mainContext.refresh()
application.setApplicationContext(mainContext)

def bb = new BeanBuilder()
bb.beans {
grailsApplication = application
mimeConfiguration(MimeTypesConfiguration, application, [])
}
final ApplicationContext context = bb.createApplicationContext()
final MimeTypesConfiguration mimeTypesConfiguration = context.getBean(MimeTypesConfiguration)
mimeTypesConfiguration.mimeTypes()
}

protected static String toCompactXml(String xml) {
Expand Down

0 comments on commit 25a0737

Please sign in to comment.