Skip to content

Commit

Permalink
devonfw#1454 added artifact cache folder
Browse files Browse the repository at this point in the history
added simple template set artifact cache folder and constant
adjusted installTemplateSet GUI test
  • Loading branch information
jan-vcapgemini committed Mar 14, 2023
1 parent b871dba commit 1fc60d6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,6 @@ public class ConfigurationConstants {
*/
public static final String CONFIG_PROPERTY_TEMPLATE_SETS_DEFAULT_VERSION = "2021.12.007";

public static final String TEMPLATE_SET_ARTIFACT_CACHE_FOLDER = "template-set-list";

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devonfw.cobigen.retriever;

import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -9,6 +10,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
import com.devonfw.cobigen.api.exception.CobiGenRuntimeException;
import com.devonfw.cobigen.api.util.CobiGenPaths;
import com.devonfw.cobigen.impl.config.entity.io.TemplateSetConfiguration;
import com.devonfw.cobigen.impl.config.reader.TemplateSetConfigurationReader;
import com.devonfw.cobigen.retriever.mavensearch.MavenSearchArtifactRetriever;
import com.devonfw.cobigen.retriever.reader.TemplateSetArtifactReader;
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
Expand Down Expand Up @@ -89,6 +95,34 @@ public static List<TemplateSet> retrieveTemplateSetData(List<Path> templateSetFi
return templateSetList;
}

/**
* Retrieves a list of {@link TemplateSetConfiguration} from the template-set-list folder
*
* @return List of {@link TemplateSetConfiguration}
*/
public static List<TemplateSetConfiguration> retrieveArtifactsFromCobiGen() {

Path templateSetFolder = CobiGenPaths.getTemplateSetsFolderPath();

Path artifactCacheFolder = templateSetFolder.resolve(ConfigurationConstants.TEMPLATE_SET_ARTIFACT_CACHE_FOLDER);

List<TemplateSetConfiguration> templateSetConfigurations = new ArrayList<>();
if (Files.exists(artifactCacheFolder)) {
for (File file : artifactCacheFolder.toFile().listFiles()) {
TemplateSetConfigurationReader reader = new TemplateSetConfigurationReader();
reader.readConfiguration(file.toPath());

TemplateSetConfiguration templateSetConfiguration = reader.getTemplateSetConfiguration();
templateSetConfigurations.add(templateSetConfiguration);
}
} else {
throw new CobiGenRuntimeException("No artifact cache folder found, cancelling!");
}

return templateSetConfigurations;

}

/**
* Helper method to retrieve maven artifact download URLs
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;

import org.junit.Rule;
import org.junit.Test;
Expand All @@ -14,7 +17,7 @@

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
import com.devonfw.cobigen.impl.config.entity.io.TemplateSetConfiguration;
import com.devonfw.cobigen.impl.config.reader.TemplateSetConfigurationReader;
import com.devonfw.cobigen.retriever.ArtifactRetriever;

import javafx.collections.FXCollections;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -59,21 +62,22 @@ public void testInstallTemplateSet() throws Exception {
ConfigurationConstants.DOWNLOADED_FOLDER);

// simulate template-set-list folder for downloaded template-set.xml files to be used in GUI
this.tmpFolder.newFolder("UserHome", "template-set-list");
File artifactCacheFolder = this.tmpFolder.newFolder("UserHome", "template-sets", "template-set-list");

Path templateSetXmlFile = TEST_FILE_ROOT_PATH.resolve("crud-java-server-app-2021.12.007-template-set.xml");
Files.copy(templateSetXmlFile,
artifactCacheFolder.toPath().resolve("crud-java-server-app-2021.12.007-template-set.xml"),
StandardCopyOption.REPLACE_EXISTING);

// initialize template set reader
TemplateSetConfigurationReader reader = new TemplateSetConfigurationReader();

// read template set xml file/files
reader.readConfiguration(templateSetXmlFile);

TemplateSetConfiguration templateSetConfiguration = reader.getTemplateSetConfiguration();
withEnvironmentVariable(ConfigurationConstants.CONFIG_ENV_HOME, userHome.getAbsolutePath()).execute(() -> {
List<TemplateSetConfiguration> templateSetConfigurations = ArtifactRetriever.retrieveArtifactsFromCobiGen();

// pass TemplateSetConfiguration to GUI
this.templateSetObservableList = FXCollections.observableArrayList();
this.templateSetObservableList.addAll(templateSetConfiguration);
// pass TemplateSetConfigurations to GUI
this.templateSetObservableList = FXCollections.observableArrayList();
for (TemplateSetConfiguration configuration : templateSetConfigurations) {
this.templateSetObservableList.addAll(configuration);
}
});

this.searchResultsView.setItems(this.templateSetObservableList);

Expand Down

0 comments on commit 1fc60d6

Please sign in to comment.