Skip to content

Commit

Permalink
Add project description diff (gh-1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbo-indeed committed Oct 28, 2019
1 parent 99b0a4b commit cf482ae
Show file tree
Hide file tree
Showing 16 changed files with 866 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ public class MutableProjectDescription implements ProjectDescription {

private String baseDirectory;

public MutableProjectDescription() {
super();
}

protected MutableProjectDescription(final MutableProjectDescription source) {
super();
setPlatformVersion(source.getPlatformVersion());
setBuildSystem(source.getBuildSystem());
setPackaging(source.getPackaging());
setLanguage(source.getLanguage());
source.getRequestedDependencies().forEach(this::addDependency);
setGroupId(source.getGroupId());
setArtifactId(source.getArtifactId());
setVersion(source.getVersion());
setName(source.getName());
setDescription(source.getDescription());
setApplicationName(source.getApplicationName());
setPackageName(source.getPackageName());
setBaseDirectory(source.getBaseDirectory());
}

@Override
public MutableProjectDescription createCopy() {
return new MutableProjectDescription(this);
}

@Override
public Version getPlatformVersion() {
return this.platformVersion;
}
Expand All @@ -69,6 +96,7 @@ public void setPlatformVersion(Version platformVersion) {
this.platformVersion = platformVersion;
}

@Override
public BuildSystem getBuildSystem() {
return this.buildSystem;
}
Expand All @@ -77,6 +105,7 @@ public void setBuildSystem(BuildSystem buildSystem) {
this.buildSystem = buildSystem;
}

@Override
public Packaging getPackaging() {
return this.packaging;
}
Expand All @@ -85,6 +114,7 @@ public void setPackaging(Packaging packaging) {
this.packaging = packaging;
}

@Override
public Language getLanguage() {
return this.language;
}
Expand All @@ -101,10 +131,12 @@ public Dependency addDependency(String id, Dependency.Builder<?> builder) {
return addDependency(id, builder.build());
}

@Override
public Map<String, Dependency> getRequestedDependencies() {
return Collections.unmodifiableMap(this.requestedDependencies);
}

@Override
public String getGroupId() {
return this.groupId;
}
Expand All @@ -113,6 +145,7 @@ public void setGroupId(String groupId) {
this.groupId = groupId;
}

@Override
public String getArtifactId() {
return this.artifactId;
}
Expand All @@ -121,6 +154,7 @@ public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}

@Override
public String getVersion() {
return this.version;
}
Expand All @@ -129,6 +163,7 @@ public void setVersion(String version) {
this.version = version;
}

@Override
public String getName() {
return this.name;
}
Expand All @@ -137,6 +172,7 @@ public void setName(String name) {
this.name = name;
}

@Override
public String getDescription() {
return this.description;
}
Expand All @@ -145,6 +181,7 @@ public void setDescription(String description) {
this.description = description;
}

@Override
public String getApplicationName() {
return this.applicationName;
}
Expand All @@ -153,6 +190,7 @@ public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}

@Override
public String getPackageName() {
if (StringUtils.hasText(this.packageName)) {
return this.packageName;
Expand All @@ -167,6 +205,7 @@ public void setPackageName(String packageName) {
this.packageName = packageName;
}

@Override
public String getBaseDirectory() {
return this.baseDirectory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,15 @@ public interface ProjectDescription {
*/
String getBaseDirectory();

/**
* ProjectDescription implementations should implement this to create a copy of
* themselves. However, the default implementation throws
* UnsupportedOperationException.
* @return never
* @throws UnsupportedOperationException always
*/
default ProjectDescription createCopy() {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

import io.spring.initializr.generator.project.diff.DefaultProjectDescriptionDiffFactory;
import io.spring.initializr.generator.project.diff.ProjectDescriptionDiff;
import io.spring.initializr.generator.project.diff.ProjectDescriptionDiffFactory;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportSelector;
Expand Down Expand Up @@ -119,9 +123,20 @@ public <T> T generate(ProjectDescription description, ProjectAssetGenerator<T> p

private Supplier<ProjectDescription> resolve(ProjectDescription description, ProjectGenerationContext context) {
return () -> {

if (description instanceof MutableProjectDescription) {

final MutableProjectDescription mutableProjectDesc = (MutableProjectDescription) description;

// Find the diff factory and use it to create and register a diff bean
final ProjectDescriptionDiffFactory diffFactory = context
.getBeanProvider(ProjectDescriptionDiffFactory.class)
.getIfAvailable(() -> new DefaultProjectDescriptionDiffFactory());
final ProjectDescriptionDiff diff = diffFactory.create(mutableProjectDesc);
context.registerBean(ProjectDescriptionDiff.class, () -> diff);

context.getBeanProvider(ProjectDescriptionCustomizer.class).orderedStream()
.forEach((customizer) -> customizer.customize((MutableProjectDescription) description));
.forEach((customizer) -> customizer.customize(mutableProjectDesc));
}
return description;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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
*
* https://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.generator.project.diff;

import io.spring.initializr.generator.project.ProjectDescription;

/**
* A default {@link ProjectDescriptionDiffFactory} implementation that creates default
* {@link ProjectDescriptionDiff} instances.
*
* @author Chris Bono
*/
public class DefaultProjectDescriptionDiffFactory implements ProjectDescriptionDiffFactory<ProjectDescription> {

@Override
public ProjectDescriptionDiff create(final ProjectDescription description) {
return new ProjectDescriptionDiff(description);
}

}
Loading

0 comments on commit cf482ae

Please sign in to comment.