Skip to content

Commit 22553ff

Browse files
committed
Add factory for configuration file format selection
1 parent 33d915d commit 22553ff

File tree

10 files changed

+285
-0
lines changed

10 files changed

+285
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.initializr.generator.configuration.format;
18+
19+
public interface ConfigurationFileFormat {
20+
21+
/**
22+
* Return the id of the packaging.
23+
* @return the id
24+
*/
25+
String id();
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.initializr.generator.configuration.format;
18+
19+
/**
20+
* A factory for creating a {@link ConfigurationFileFormat}.
21+
*
22+
* @author Sijun Yang
23+
*/
24+
public interface ConfigurationFileFormatFactory {
25+
26+
/**
27+
* Creates and returns a {@link ConfigurationFileFormat} for the given id. If the
28+
* factory does not recognise the given {@code id}, {@code null} should be returned.
29+
* @param id the id of the configuration file format
30+
* @return the configuration file format or {@code null}
31+
*/
32+
ConfigurationFileFormat createConfigurationFileFormat(String id);
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Configuration file format abstraction.
19+
*/
20+
package io.spring.initializr.generator.configuration.format;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.initializr.generator.configuration.format.properties;
18+
19+
import io.spring.initializr.generator.configuration.format.ConfigurationFileFormat;
20+
21+
/**
22+
* Properties {@link ConfigurationFileFormat}.
23+
*
24+
* @author Sijun Yang
25+
*/
26+
public final class PropertiesFormat implements ConfigurationFileFormat {
27+
28+
/**
29+
* Properties {@link ConfigurationFileFormat} identifier.
30+
*/
31+
public static final String ID = "properties";
32+
33+
@Override
34+
public String id() {
35+
return ID;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return id();
41+
}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.initializr.generator.configuration.format.properties;
18+
19+
import io.spring.initializr.generator.configuration.format.ConfigurationFileFormat;
20+
import io.spring.initializr.generator.configuration.format.ConfigurationFileFormatFactory;
21+
22+
/**
23+
* {@link ConfigurationFileFormat Factory} for {@link PropertiesFormat}.
24+
*
25+
* @author Sijun Yang
26+
*/
27+
class PropertiesFormatFactory implements ConfigurationFileFormatFactory {
28+
29+
@Override
30+
public ConfigurationFileFormat createConfigurationFileFormat(String id) {
31+
if (PropertiesFormat.ID.equals(id)) {
32+
return new PropertiesFormat();
33+
}
34+
return null;
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Properties configuration file format.
19+
*/
20+
package io.spring.initializr.generator.configuration.format.properties;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.initializr.generator.configuration.format.yaml;
18+
19+
import io.spring.initializr.generator.configuration.format.ConfigurationFileFormat;
20+
21+
/**
22+
* YAML {@link ConfigurationFileFormat}.
23+
*
24+
* @author Sijun Yang
25+
*/
26+
public final class YamlFormat implements ConfigurationFileFormat {
27+
28+
/**
29+
* YAML {@link ConfigurationFileFormat} identifier.
30+
*/
31+
public static final String ID = "yml";
32+
33+
@Override
34+
public String id() {
35+
return ID;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return id();
41+
}
42+
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.initializr.generator.configuration.format.yaml;
18+
19+
import io.spring.initializr.generator.configuration.format.ConfigurationFileFormat;
20+
import io.spring.initializr.generator.configuration.format.ConfigurationFileFormatFactory;
21+
22+
/**
23+
* {@link ConfigurationFileFormat Factory} for {@link YamlFormat}.
24+
*
25+
* @author Sijun Yang
26+
*/
27+
class YamlFormatFactory implements ConfigurationFileFormatFactory {
28+
29+
@Override
30+
public ConfigurationFileFormat createConfigurationFileFormat(String id) {
31+
if (YamlFormat.ID.equals(id)) {
32+
return new YamlFormat();
33+
}
34+
return null;
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* YAML configuration file format.
19+
*/
20+
package io.spring.initializr.generator.configuration.format.yaml;

initializr-generator/src/main/resources/META-INF/spring.factories

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ io.spring.initializr.generator.language.kotlin.KotlinLanguageFactory
1010
io.spring.initializr.generator.packaging.PackagingFactory=\
1111
io.spring.initializr.generator.packaging.jar.JarPackagingFactory,\
1212
io.spring.initializr.generator.packaging.war.WarPackagingFactory
13+
14+
io.spring.initializr.generator.configuration.format.ConfigurationFileFormatFactory=\
15+
io.spring.initializr.generator.configuration.format.properties.PropertiesFormatFactory,\
16+
io.spring.initializr.generator.configuration.format.yaml.YamlFormatFactory

0 commit comments

Comments
 (0)