Search in sources :

Example 11 with IncrementTo

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() + "' !");
                }
            }
        }
    }
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) CobiGenEclipseRuntimeException(com.devonfw.cobigen.eclipse.common.exceptions.CobiGenEclipseRuntimeException) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CheckStateListener(com.devonfw.cobigen.eclipse.wizard.common.control.CheckStateListener) HashSet(java.util.HashSet)

Example 12 with IncrementTo

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;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) GenerableArtifact(com.devonfw.cobigen.api.to.GenerableArtifact) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) LinkedList(java.util.LinkedList)

Example 13 with IncrementTo

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,");
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) GenerationReportTo(com.devonfw.cobigen.api.to.GenerationReportTo) CobiGen(com.devonfw.cobigen.api.CobiGen) File(java.io.File) Test(org.junit.Test)

Example 14 with IncrementTo

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;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) Increment(com.devonfw.cobigen.impl.config.entity.Increment) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo) InvalidConfigurationException(com.devonfw.cobigen.api.exception.InvalidConfigurationException) Template(com.devonfw.cobigen.impl.config.entity.Template)

Aggregations

IncrementTo (com.devonfw.cobigen.api.to.IncrementTo)14 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)8 CobiGen (com.devonfw.cobigen.api.CobiGen)5 File (java.io.File)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Test (org.junit.Test)4 GenerableArtifact (com.devonfw.cobigen.api.to.GenerableArtifact)3 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)3 ComparableIncrement (com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement)3 AbstractApiTest (com.devonfw.cobigen.systemtest.common.AbstractApiTest)3 ArrayList (java.util.ArrayList)2 Cached (com.devonfw.cobigen.api.annotation.Cached)1 InputReaderException (com.devonfw.cobigen.api.exception.InputReaderException)1 InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)1 MavenUtil (com.devonfw.cobigen.api.util.MavenUtil)1 Tuple (com.devonfw.cobigen.api.util.Tuple)1 CobiGenCLI (com.devonfw.cobigen.cli.CobiGenCLI)1 MessagesConstants (com.devonfw.cobigen.cli.constants.MessagesConstants)1 UserAbortException (com.devonfw.cobigen.cli.exceptions.UserAbortException)1