Skip to content

Commit

Permalink
fixed download by properties
Browse files Browse the repository at this point in the history
made sure that template set jars only get downloaded when template-sets.installed was set
renamed fields of ConfigurationProperties
  • Loading branch information
jan-vcapgemini committed Mar 31, 2023
1 parent 27dced6 commit 07e7ad8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ public static CobiGen create(URI configFileOrFolder, boolean allowMonolithicConf
// install Template Sets defined in .properties file
if (configurationHolder.isTemplateSetConfiguration()) {
ConfigurationProperties config = configurationHolder.getConfigurationProperties();
Path templatesLocation = configurationHolder.getConfigurationPath();
List<String> downloadUrls = ArtifactRetriever.retrieveTemplateSetJarDownloadURLs(config.getGroupIds(),
config.getMavenCoordinates());
for (String downloadUrl : downloadUrls) {
TemplatesJarUtil.downloadJarFromURL(downloadUrl, templatesLocation);
// if installed template sets property was not empty, install found template sets
if (!config.getTemplateSetsInstalled().isEmpty()) {
Path templatesLocation = configurationHolder.getConfigurationPath();
List<String> downloadUrls = ArtifactRetriever.retrieveTemplateSetJarDownloadURLs(config.getGroupIds(),
config.getTemplateSetsInstalled());
for (String downloadUrl : downloadUrls) {
TemplatesJarUtil.downloadJarFromURL(downloadUrl, templatesLocation);
}
}
}
return createBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.devonfw.cobigen.api.util.MavenCoordinate;

/**
* Data wrapper for configuration Properties. The properties are groupIds, hideTemplates and allowSnapshots
*
* Data wrapper for configuration Properties. The properties are groupIds, hideTemplates, allowSnapshots and
* templateSetsInstalled
*/
public class ConfigurationProperties {

Expand All @@ -16,27 +16,27 @@ public class ConfigurationProperties {
/** allow snapshots of template-sets */
private boolean allowSnapshots;

/** List of mavenCoordinates for the template sets that should be installed at cobigen startup */
private List<MavenCoordinate> templatesInstalled;
/** List of mavenCoordinates for the template sets that should be installed at CobiGen startup */
private List<MavenCoordinate> templateSetsInstalled;

/** variable to hide very specific template sets or versions of template sets */
private List<MavenCoordinate> hideTemplates;
private List<MavenCoordinate> hideTemplateSets;

/**
* The constructor. load properties from a given source
* The constructor. Loads properties from a given source
*
* @param groupIds groupID from key template-sets.groupIds
* @param allowSnapshots from key template-sets.allow-snapshot
* @param hideTemplates from key template-set.hide
* @param mavenCoordinates list of mavenCoordinate that define the templates that should be installed
* @param templateSetsInstalled list of mavenCoordinate that define the templates sets that should be installed
*/
public ConfigurationProperties(List<String> groupIds, boolean allowSnapshots, List<MavenCoordinate> hideTemplates,
List<MavenCoordinate> mavenCoordinates) {
List<MavenCoordinate> templateSetsInstalled) {

this.groupIds = groupIds;
this.allowSnapshots = allowSnapshots;
this.hideTemplates = hideTemplates;
this.templatesInstalled = mavenCoordinates;
this.hideTemplateSets = hideTemplates;
this.templateSetsInstalled = templateSetsInstalled;
}

/**
Expand Down Expand Up @@ -82,41 +82,41 @@ public void setAllowSnapshots(boolean allowSnapshots) {
/**
* Returns a list of the saved templates to be hidden
*
* @return hideTemplates
* @return hideTemplateSets
*/
public List<MavenCoordinate> getHideTemplates() {
public List<MavenCoordinate> getHideTemplateSets() {

return this.hideTemplates;
return this.hideTemplateSets;
}

/**
* Sets a list of the HideTemplate from a source
*
* @param hideTemplates new value of {@link #gethideTemplates}.
* @param hideTemplateSets new value of {@link #gethideTemplateSets}.
*/
public void setHideTemplates(List<MavenCoordinate> hideTemplates) {
public void setHideTemplateSets(List<MavenCoordinate> hideTemplateSets) {

this.hideTemplates = hideTemplates;
this.hideTemplateSets = hideTemplateSets;
}

/**
* Returns a list of maven coordinates for the download of template sets
*
* @return maven coordinates
*/
public List<MavenCoordinate> getMavenCoordinates() {
public List<MavenCoordinate> getTemplateSetsInstalled() {

return this.templatesInstalled;
return this.templateSetsInstalled;
}

/**
* Set a list of templates that should be installed at startup
* Set a list of template sets that should be installed at startup
*
* @param mavenCoordinates new value of {@link #getmavenCoordinates}.
* @param templateSetsInstalled new value of {@link #getTemplateSetsInstalled}.
*/
public void setMavenCoordinates(List<MavenCoordinate> mavenCoordinates) {
public void setTemplateSetsInstalled(List<MavenCoordinate> templateSetsInstalled) {

this.templatesInstalled = mavenCoordinates;
this.templateSetsInstalled = templateSetsInstalled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void emptyConfigurationTest() throws IOException {
ConfigurationProperties conf = ConfigurationFinder.retrieveCobiGenProperties(emptyConfiguration);

assertThat(conf.getGroupIds()).contains(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_DEFAULT_GROUPID);
assertThat(conf.getHideTemplates()).isEmpty();
assertThat(conf.getHideTemplateSets()).isEmpty();
assertThat(conf.isAllowSnapshots()).isFalse();
}

Expand All @@ -67,9 +67,9 @@ public void validConfigurationTest() throws IOException {
assertThat(conf.getGroupIds()).containsSequence("devonfw-cobigen-bla", "abcd", "blablob",
ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_DEFAULT_GROUPID);
assertThat(conf.isAllowSnapshots()).isTrue();
assertThat(conf.getHideTemplates().get(0).getArtifactId().equals("com.devonfw"));
assertThat(conf.getHideTemplates().get(0).getGroupId().equals("test-artifact"));
assertThat(conf.getHideTemplates().get(0).getVersion().equals("3.2.1-SNAPSHOT"));
assertThat(conf.getHideTemplateSets().get(0).getArtifactId().equals("com.devonfw"));
assertThat(conf.getHideTemplateSets().get(0).getGroupId().equals("test-artifact"));
assertThat(conf.getHideTemplateSets().get(0).getVersion().equals("3.2.1-SNAPSHOT"));
}

/**
Expand All @@ -85,8 +85,8 @@ public void invalidInputConfigurationTest() throws IOException {
.get("src/test/resources/testdata/unittest/config/properties/invalidConfigProperties/config.properties");
ConfigurationProperties conf = ConfigurationFinder.retrieveCobiGenProperties(validConfiguration);

assertTrue(conf.getHideTemplates().isEmpty());
assertTrue(conf.getMavenCoordinates().isEmpty());
assertTrue(conf.getHideTemplateSets().isEmpty());
assertTrue(conf.getTemplateSetsInstalled().isEmpty());
}

/**
Expand All @@ -103,7 +103,7 @@ public void invalidPathTest() throws IOException {
ConfigurationProperties conf = ConfigurationFinder.retrieveCobiGenProperties(invalidPath);

assertThat(conf.getGroupIds()).contains(ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_DEFAULT_GROUPID);
assertThat(conf.getHideTemplates()).isEmpty();
assertThat(conf.getHideTemplateSets()).isEmpty();
assertThat(conf.isAllowSnapshots()).isFalse();
}

Expand Down

0 comments on commit 07e7ad8

Please sign in to comment.