use of com.devonfw.cobigen.api.to.IncrementTo in project cobigen by devonfw.
the class SelectFileLabelProvider method checkStateChanged.
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
synchronized (this.selectedIncrements) {
// Increments selection has been changed
if (event.getSource() instanceof CheckboxTreeViewer) {
CheckboxTreeViewer incrementSelector = (CheckboxTreeViewer) event.getSource();
CheckStateListener listener = new CheckStateListener(this.cobigenWrapper, null, this.batch);
listener.performCheckLogic(event, incrementSelector);
Set<Object> selectedElements = new HashSet<>(Arrays.asList(((CheckboxTreeViewer) event.getSource()).getCheckedElements()));
this.selectedIncrements.clear();
for (Object o : selectedElements) {
if (o instanceof IncrementTo) {
this.selectedIncrements.add((IncrementTo) o);
} else {
throw new CobiGenEclipseRuntimeException("Unexpected increment type '" + o.getClass().getCanonicalName() + "' !");
}
}
}
}
}
use of com.devonfw.cobigen.api.to.IncrementTo in project cobigen by devonfw.
the class GenerateMojo method collectIncrements.
/**
* Generates all increments for each input.
*
* @param cobiGen generator instance to be used for generation
* @param inputs to be used for generation
* @return the collected increments to be generated
* @throws MojoFailureException if the maven configuration does not match cobigen configuration (context.xml)
*/
private List<GenerableArtifact> collectIncrements(CobiGen cobiGen, List<Object> inputs) throws MojoFailureException {
List<GenerableArtifact> generableArtifacts = new ArrayList<>();
if (this.increments != null && !this.increments.isEmpty()) {
if (this.increments.contains(ALL)) {
if (this.increments.size() > 1) {
throw new MojoFailureException("You specified the 'ALL' increment to generate all available increments next to another increment, which was most probably not intended.");
}
for (Object input : inputs) {
generableArtifacts.addAll(cobiGen.getMatchingIncrements(input));
}
} else {
for (Object input : inputs) {
List<IncrementTo> matchingIncrements = cobiGen.getMatchingIncrements(input);
List<String> configuredIncrements = new LinkedList<>(this.increments);
for (IncrementTo increment : matchingIncrements) {
if (this.increments.contains(increment.getId())) {
generableArtifacts.add(increment);
configuredIncrements.remove(increment.getId());
}
}
// error handling for increments not found
if (!configuredIncrements.isEmpty()) {
throw new MojoFailureException("Increments with ids '" + configuredIncrements + "' not matched for input '" + getStringRepresentation(input) + "' by provided CobiGen configuration.");
}
}
}
}
return generableArtifacts;
}
use of com.devonfw.cobigen.api.to.IncrementTo in project cobigen by devonfw.
the class VelocityTemplateEngineIntegrationTest method testBasicGeneration.
/**
* Tests a basic generation integrated with cobigen-core
*
* @throws Exception test fails
*/
@Test
public void testBasicGeneration() throws Exception {
CobiGen cobigen = CobiGenFactory.create(new File("src/test/resources/systemtest").toURI());
Object input = cobigen.read(new File("src/test/java/com/devonfw/cobigen/tempeng/velocity/systemtest/testobjects/Input.java").toPath(), Charset.forName("UTF-8"), getClass().getClassLoader());
List<IncrementTo> increments = cobigen.getMatchingIncrements(input);
assertThat(increments).hasSize(1);
assertThat(increments.get(0).getTemplates()).hasSize(1);
File targetFolder = this.tempFolderRule.newFolder("cobigen-");
GenerationReportTo report = cobigen.generate(Input.class, increments.get(0), targetFolder.toPath());
assertThat(report).isSuccessful();
assertThat(targetFolder.toPath().resolve("velocityTest.txt")).exists().hasContent("String,int,");
}
use of com.devonfw.cobigen.api.to.IncrementTo in project cobigen by devonfw.
the class ConfigurationInterpreterImpl method convertIncrements.
/**
* Converts a {@link List} of {@link Increment}s with their parent {@link Trigger} to a {@link List} of
* {@link IncrementTo}s
*
* @param increments the {@link List} of {@link Increment}s
* @param trigger the parent {@link Trigger}
* @param matchingTriggerIds the {@link List} of matching trigger Id
* @return the {@link List} of {@link IncrementTo}s
*/
// TODO create ToConverter
private List<IncrementTo> convertIncrements(List<Increment> increments, Trigger trigger, List<String> matchingTriggerIds) {
List<IncrementTo> incrementTos = Lists.newLinkedList();
for (Increment increment : increments) {
String triggerId = increment.getTrigger().getId();
if (!triggerId.equals(trigger.getId())) {
// Check if the external trigger also matches
if (!matchingTriggerIds.contains(triggerId)) {
// Abort generation
throw new InvalidConfigurationException("An external incrementRef to " + increment.getTrigger().getId() + "::" + increment.getName() + " is referenced from " + trigger.getId() + " but its trigger does not match");
}
}
List<TemplateTo> templates = Lists.newLinkedList();
for (Template template : increment.getTemplates()) {
templates.add(new TemplateTo(template.getName(), template.getMergeStrategy(), triggerId));
}
incrementTos.add(new IncrementTo(increment.getName(), increment.getDescription(), triggerId, templates, convertIncrements(increment.getDependentIncrements(), trigger, matchingTriggerIds)));
}
return incrementTos;
}
Aggregations