mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-15 23:13:30 +08:00
Remove unused ProjectResourceLocator
This commit is contained in:
parent
cd3b274112
commit
d5580cd985
@ -805,9 +805,6 @@ expiration settings accordingly.
|
||||
|`initializr.dependency-metadata`
|
||||
|Cache dependency-specific metadata.
|
||||
|
||||
|`initializr.project-resources`
|
||||
|Cache resources that are used to generate projects.
|
||||
|
||||
|`initializr.templates`
|
||||
|Cache templates that are used to generate projects.
|
||||
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Locate project resources.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ProjectResourceLocator {
|
||||
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
/**
|
||||
* Return the binary content of the resource at the specified location.
|
||||
* @param location a resource location
|
||||
* @return the content of the resource
|
||||
*/
|
||||
@Cacheable("initializr.project-resources")
|
||||
public byte[] getBinaryResource(String location) {
|
||||
try (InputStream stream = getInputStream(location)) {
|
||||
return StreamUtils.copyToByteArray(stream);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Cannot get resource", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the textual content of the resource at the specified location.
|
||||
* @param location a resource location
|
||||
* @return the content of the resource
|
||||
*/
|
||||
@Cacheable("initializr.project-resources")
|
||||
public String getTextResource(String location) {
|
||||
try (InputStream stream = getInputStream(location)) {
|
||||
return StreamUtils.copyToString(stream, UTF_8);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Cannot get resource", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream getInputStream(String location) throws IOException {
|
||||
URL url = ResourceUtils.getURL(location);
|
||||
return url.openStream();
|
||||
}
|
||||
|
||||
}
|
@ -33,7 +33,6 @@ import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.metadata.InitializrMetadataBuilder;
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
import io.spring.initializr.metadata.InitializrProperties;
|
||||
import io.spring.initializr.web.ProjectResourceLocator;
|
||||
import io.spring.initializr.web.project.MainController;
|
||||
import io.spring.initializr.web.project.ProjectGenerationInvoker;
|
||||
import io.spring.initializr.web.project.ProjectRequestToDescriptionConverter;
|
||||
@ -107,12 +106,6 @@ public class InitializrAutoConfiguration {
|
||||
return new NoOpCache("templates");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ProjectResourceLocator projectResourceLocator() {
|
||||
return new ProjectResourceLocator();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(InitializrMetadataProvider.class)
|
||||
public InitializrMetadataProvider initializrMetadataProvider(
|
||||
|
@ -19,7 +19,6 @@ package io.spring.initializr.web.autoconfigure;
|
||||
import io.spring.initializr.generator.io.template.TemplateRenderer;
|
||||
import io.spring.initializr.metadata.DependencyMetadataProvider;
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
import io.spring.initializr.web.ProjectResourceLocator;
|
||||
import io.spring.initializr.web.project.MainController;
|
||||
import io.spring.initializr.web.project.ProjectGenerationInvoker;
|
||||
import io.spring.initializr.web.project.ProjectRequestToDescriptionConverter;
|
||||
@ -74,22 +73,6 @@ class InitializrAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigRegistersProjectResourceLocator() {
|
||||
this.contextRunner.run((context) -> assertThat(context)
|
||||
.hasSingleBean(ProjectResourceLocator.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigWhenProjectResourceLocatorBeanPresentDoesNotRegisterProjectResourceLocator() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(CustomProjectResourceLocatorConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(ProjectResourceLocator.class);
|
||||
assertThat(context).hasBean("testProjectResourceLocator");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfigRegistersInitializrMetadataProvider() {
|
||||
this.contextRunner.run((context) -> assertThat(context)
|
||||
@ -201,16 +184,6 @@ class InitializrAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomProjectResourceLocatorConfiguration {
|
||||
|
||||
@Bean
|
||||
public ProjectResourceLocator testProjectResourceLocator() {
|
||||
return Mockito.mock(ProjectResourceLocator.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomInitializrMetadataProviderConfiguration {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user