Search in sources :

Example 6 with IncrementTo

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();
}
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) AbstractApiTest(com.devonfw.cobigen.systemtest.common.AbstractApiTest) Test(org.junit.Test)

Example 7 with IncrementTo

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

Example 8 with IncrementTo

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;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) ComparableIncrement(com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo)

Example 9 with IncrementTo

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;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) HashSet(java.util.HashSet) Set(java.util.Set) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo)

Example 10 with IncrementTo

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;
}
Also used : IncrementTo(com.devonfw.cobigen.api.to.IncrementTo) HashSet(java.util.HashSet) Set(java.util.Set) ComparableIncrement(com.devonfw.cobigen.eclipse.generator.entity.ComparableIncrement) TemplateTo(com.devonfw.cobigen.api.to.TemplateTo)

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