use of com.devonfw.cobigen.api.to.IncrementTo in project cobigen by devonfw.
the class TransactionalGenerationTest method testNoPartialApplicationOfGeneration.
/**
* Tests, whether no partial generation will be applied to the target if generation fails in between.
*
* @throws Throwable test fails
*/
@Test
public void testNoPartialApplicationOfGeneration() throws Throwable {
// arrange
Object generationInput = PluginMockFactory.createSimpleJavaConfigurationMock();
File targetRoot = this.tmpFolder.newFolder();
CobiGen cobigen = CobiGenFactory.create(new File(testFileRootPath + "templates").toURI());
List<IncrementTo> matchingIncrements = cobigen.getMatchingIncrements(generationInput);
// act
GenerationReportTo report = cobigen.generate(generationInput, matchingIncrements, targetRoot.toPath());
// assert
assertThat(report.isSuccessful()).isFalse();
assertThat(new File(targetRoot, "valid.txt")).doesNotExist();
assertThat(new File(targetRoot, "invalid.txt")).doesNotExist();
}
use of com.devonfw.cobigen.api.to.IncrementTo in project cobigen by devonfw.
the class ContainerMatcherTest method testGetAllIncrements.
/**
* Tests whether the increments can be correctly retrieved for container matchers
*
* @throws Exception test fails
*/
@Test
public void testGetAllIncrements() throws Exception {
// Mocking
Object containerInput = createTestDataAndConfigureMock(true, true);
// pre-processing
File templatesFolder = new File(testFileRootPath + "templates");
CobiGen target = CobiGenFactory.create(templatesFolder.toURI());
// Execution
List<IncrementTo> increments = target.getMatchingIncrements(containerInput);
// Verification
Assert.assertNotNull(increments);
Assert.assertTrue(increments.size() > 0);
}
use of com.devonfw.cobigen.api.to.IncrementTo in project cobigen by devonfw.
the class CobiGenWrapper method getAllIncrements.
/**
* @return all available increments
*/
public ComparableIncrement[] getAllIncrements() {
Set<ComparableIncrement> result = Sets.newHashSet();
List<IncrementTo> matchingIncrements = Lists.newLinkedList();
if (this.inputs != null && this.inputs.size() != 0) {
for (Object input : this.cobiGen.resolveContainers(this.inputs.get(0))) {
matchingIncrements.addAll(this.cobiGen.getMatchingIncrements(input));
}
}
// convert to comparable increments
for (IncrementTo increment : matchingIncrements) {
result.add(new ComparableIncrement(increment.getId(), increment.getDescription(), increment.getTriggerId(), increment.getTemplates(), increment.getDependentIncrements()));
}
// add "all" increment, which should include all possible templates
ComparableIncrement all = new ComparableIncrement(ALL_INCREMENT_ID, ALL_INCREMENT_NAME, null, Lists.<TemplateTo>newLinkedList(), Lists.<IncrementTo>newLinkedList());
for (TemplateTo t : this.matchingTemplates) {
all.addTemplate(t);
}
result.add(all);
ComparableIncrement[] array = result.toArray(new ComparableIncrement[0]);
Arrays.sort(array);
LOG.debug("Available Increments: {}", result);
return array;
}
use of com.devonfw.cobigen.api.to.IncrementTo in project cobigen by devonfw.
the class CobiGenWrapper method getTemplateDestinationPaths.
/**
* Returns the set of all workspace relative destination paths for the templates of the given
* {@link ComparableIncrement} mapped to the correlated {@link TemplateTo}. This is done for the
* {@link #getCurrentRepresentingInput() current representing input}.
*
* @param <T> {@link IncrementTo} or any sub type
* @param increments {@link IncrementTo Increments} the template destination paths should be retrieved for
* @param input input for path resolution
* @return the mapping of destination paths to its templates
*/
private <T extends IncrementTo> Map<String, Set<TemplateTo>> getTemplateDestinationPaths(Collection<T> increments, Object input) {
List<IncrementTo> matchingIncrements = this.cobiGen.getMatchingIncrements(input);
boolean cachingEnabled = input == getCurrentRepresentingInput();
Map<String, Set<TemplateTo>> result = Maps.newHashMap();
for (IncrementTo increment : increments) {
if (increment.getId().equals(ALL_INCREMENT_ID)) {
continue;
}
// check cache
if (cachingEnabled) {
Map<String, Set<TemplateTo>> cachedTemplatePaths = this.incrementToTemplateWorkspacePathsCache.get(increment);
if (cachedTemplatePaths != null) {
MapUtils.deepMapAddAll(result, cachedTemplatePaths);
continue;
}
}
// Now we need to check whether the input matches the increment
boolean inputNotMatchesIncrement = true;
for (IncrementTo inc : matchingIncrements) {
// If at least one triggerID is present, then the input is valid for this increment
if (inc.getTriggerId().equals(increment.getTriggerId())) {
inputNotMatchesIncrement = false;
break;
}
}
// If it does not match, we should not keep the execution for this increment
if (inputNotMatchesIncrement) {
continue;
}
// process normal
Map<String, Set<TemplateTo>> thisIncrementResult = Maps.newHashMap();
for (TemplateTo template : increment.getTemplates()) {
String path = resolveWorkspaceDependentTemplateDestinationPath(template, input);
MapUtils.deepMapAdd(thisIncrementResult, path, template);
}
if (cachingEnabled) {
this.incrementToTemplateWorkspacePathsCache.put(increment, thisIncrementResult);
}
MapUtils.deepMapAddAll(result, thisIncrementResult);
}
return result;
}
use of com.devonfw.cobigen.api.to.IncrementTo in project cobigen by devonfw.
the class CobiGenWrapper method getMergeableFiles.
/**
* Returns project dependent paths of all resources which are marked to be mergeable (just of
* {@link #getCurrentRepresentingInput()})
*
* @param increments to be considered
* @return The set of all mergeable project dependent file paths
*/
public Set<String> getMergeableFiles(Collection<IncrementTo> increments) {
if (increments.contains(new ComparableIncrement(ALL_INCREMENT_ID, ALL_INCREMENT_NAME, null, Lists.<TemplateTo>newLinkedList(), Lists.<IncrementTo>newLinkedList()))) {
increments = this.cobiGen.getMatchingIncrements(getCurrentRepresentingInput());
}
Set<String> mergeablePaths = Sets.newHashSet();
Map<String, Set<TemplateTo>> templateDestinationPaths = getTemplateDestinationPaths(increments);
for (Entry<String, Set<TemplateTo>> entry : templateDestinationPaths.entrySet()) {
if (isMergableFile(entry.getValue())) {
mergeablePaths.add(entry.getKey());
}
}
return mergeablePaths;
}
Aggregations