Skip to content

Commit

Permalink
#1213 Merge branch 'dev_core' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeec committed Sep 13, 2020
2 parents 9f6d291 + 31caa74 commit c6cb445
Show file tree
Hide file tree
Showing 32 changed files with 628 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,10 @@ public interface InputInterpreter {
*/
public List<Object> resolveContainers(Object input);

/**
* Reads the content at a path via a fitting {@link InputReader} and returns a CobiGen compliant input
* @param type
* of the input to be read. Is used to resolve a fitting InputReader
* @param path
* the {@link Path} to the object. Can also point to a folder
* @param inputCharset
* of the input to be used
* @param additionalArguments
* depending on the InputReader implementation
* @return Object that is a valid input
* @throws InputReaderException
* if the Path cannot be read
* @throws IllegalArgumentException
* if the provided additional arguments do not suffice the used InputReader
*/
public Object read(String type, Path path, Charset inputCharset, Object... additionalArguments)
throws InputReaderException;

/**
* Reads the content at a path via the first fitting {@link InputReader} and returns a CobiGen compliant
* input
* input. Supports at least one EXTERNAL input reader with the same isMostLikelyReadable criteria than an
* INTERNAL input reader.
* @param path
* the {@link Path} to the object. Can also point to a folder
* @param inputCharset
Expand All @@ -62,19 +44,4 @@ public Object read(String type, Path path, Charset inputCharset, Object... addit
*/
public Object read(Path path, Charset inputCharset, Object... additionalArguments) throws InputReaderException;

/**
* Try to determine, whether the input file is readable by the plug-ins parser. If false is returned by
* the method, it is not assured, that the read method is not called at all. In case of the situation,
* that no plug-in is most likely to read the input, CobiGen will try every input reader to read the
* input. Please be aware, that this method should be kept highly performant. It does not have to be an
* exact result.
* @param path
* the file {@link Path}.
* @param type
* of the input to be read. Is used to resolve a fitting InputReader
* @return true, if it is most likely, that the file can be read by this input reader's read method<br>
* false, if the reader is most likely not able to read the file.
*/
public boolean isMostLikelyReadable(String type, Path path);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.devonfw.cobigen.api.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotation allowing activation criteria for a plug-in
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Inherited
public @interface Activation {

/**
* @return the file extensions for which the plug-in should be activated respectively for which the
* plug-in provides an input reader. The file extension should be noted by the extension only
* without dot or asterix, i.e. { 'html', 'xhtml' }
*/
String[] byFileExtension() default {};

/**
* @return whether this plug-in can read a folder as input.
*/
boolean byFolder() default false;

/**
* @return the merge strategies provided by this plug-in, which will cause the plug-in lazily to be loaded
* just in case a merge strategy is requested which is provided by this plug-in
*/
String[] byMergeStrategy() default {};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.devonfw.cobigen.api.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Name of an extension
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Inherited
public @interface Name {

/** Name of the plug-in */
String value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.devonfw.cobigen.api.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.devonfw.cobigen.api.extension.Priority;
import com.devonfw.cobigen.api.extension.TriggerInterpreter;

/**
* The priority to take into account when try reading an input. This annotation is meant to be set on
* {@link TriggerInterpreter} classes
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Inherited
public @interface ReaderPriority {

/** The input readers priority */
Priority value() default Priority.LOW;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class ConfigurationConstants {
/** Resource folder containing templates */
public static final String TEMPLATE_RESOURCE_FOLDER = "src/main/templates";

/** Resource folder containing merge schemas */
public static final String MERGE_SCHEMA_RESOURCE_FOLDER = "src/main/resources/mergeSchemas";

/** Delimiter splitting the template folder and value of references in templates.xml files */
public static final String REFERENCE_DELIMITER = "::";
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.devonfw.cobigen.api.extension;

import java.nio.file.Path;
import java.util.List;

import com.devonfw.cobigen.api.annotation.ExceptionFacade;
import com.devonfw.cobigen.api.exception.NotYetSupportedException;

/**
* This interface should be inherited for all plug-ins to extend the generators logic by additional
Expand All @@ -18,6 +20,18 @@ public interface GeneratorPluginActivator {
*/
public List<Merger> bindMerger();

/**
* This function should be called by a plugin if the path to the template root was changed
* @param path
* Path to project root folder
*
* @throws NotYetSupportedException
* if not implemented yet
*/
default void setProjectRoot(@SuppressWarnings("unused") Path path) {
// do nothing
}

/**
* This function should return all {@link TriggerInterpreter} implementations, which should be provided by
* this plug-in implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.devonfw.cobigen.api.annotation.ExceptionFacade;
import com.devonfw.cobigen.api.exception.InputReaderException;

Expand All @@ -16,6 +19,9 @@
@ExceptionFacade
public interface InputReader {

/** Logger instance. */
public static final Logger LOG = LoggerFactory.getLogger(InputReader.class);

/**
* This function will be called if matching triggers or matching templates should be retrieved for a given
* input object
Expand Down Expand Up @@ -92,8 +98,6 @@ public interface InputReader {
* @return true, if it is most likely, that the file can be read by this input reader's read method<br>
* false, if the reader is most likely not able to read the file.
*/
@SuppressWarnings("unused")
default public boolean isMostLikelyReadable(Path path) {
return false;
}
public boolean isMostLikelyReadable(Path path);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.devonfw.cobigen.api.extension;

/**
* Priorities an input reader is ranked with in case
* {@link InputReader#isMostLikelyReadable(java.nio.file.Path)} is returning true for multiple plug-ins
* available.
*/
public enum Priority {

/** Standard devonfw plug-ins + meta-language readers (i.e. XML) */
LOW((byte) 3),

/** For example language specific readers like specific XML languages */
MEDIUM((byte) 2),

/** Highest priority for custom use cases */
HIGH((byte) 1);

/** The rank */
private byte rank;

/**
* @param rank
* the rank
*/
private Priority(byte rank) {
this.rank = rank;
}

/**
* @return the rank for sorting the priorities
*/
public byte getRank() {
return rank;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
@ExceptionFacade
public interface TextTemplateEngine {

/**
* Returns the identifying name of the template engine.
* @return name of the template engine
*/
public String getName();

/**
* The return value is considered for automatically retrieving file names from templates within a
* template-scan. The template file ending will be eliminated (if exists) from a template's file name to
Expand Down
4 changes: 2 additions & 2 deletions cobigen/cobigen-core-parent/cobigen-core-systemtest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tempeng-freemarker</artifactId>
<version>2.0.0</version>
<version>7.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>javaplugin</artifactId>
<version>2.0.0</version>
<version>7.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Test;

import com.devonfw.cobigen.api.CobiGen;
import com.devonfw.cobigen.api.extension.GeneratorPluginActivator;
import com.devonfw.cobigen.api.extension.InputReader;
import com.devonfw.cobigen.api.extension.MatcherInterpreter;
import com.devonfw.cobigen.api.extension.TriggerInterpreter;
Expand Down Expand Up @@ -134,6 +135,7 @@ public String toString() {
};

// Pre-processing: Mocking
GeneratorPluginActivator activator = mock(GeneratorPluginActivator.class);
TriggerInterpreter triggerInterpreter = mock(TriggerInterpreter.class);
MatcherInterpreter matcher = mock(MatcherInterpreter.class);
InputReader inputReader = mock(InputReader.class);
Expand Down Expand Up @@ -164,7 +166,7 @@ public String toString() {
.thenReturn(ImmutableMap.<String, String> builder().put("rootPackage", "com.devonfw")
.put("entityName", "Test").build());

PluginRegistry.registerTriggerInterpreter(triggerInterpreter);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);

return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import org.junit.Assert;
import org.junit.Test;

import com.devonfw.cobigen.systemtest.common.AbstractApiTest;
import com.devonfw.cobigen.test.matchers.MatcherToMatcher;
import com.devonfw.cobigen.test.matchers.VariableAssignmentToMatcher;
import com.devonfw.cobigen.api.CobiGen;
import com.devonfw.cobigen.api.extension.GeneratorPluginActivator;
import com.devonfw.cobigen.api.extension.InputReader;
import com.devonfw.cobigen.api.extension.MatcherInterpreter;
import com.devonfw.cobigen.api.extension.TriggerInterpreter;
Expand All @@ -34,6 +32,9 @@
import com.devonfw.cobigen.impl.CobiGenFactory;
import com.devonfw.cobigen.impl.config.entity.ContainerMatcher;
import com.devonfw.cobigen.impl.extension.PluginRegistry;
import com.devonfw.cobigen.systemtest.common.AbstractApiTest;
import com.devonfw.cobigen.test.matchers.MatcherToMatcher;
import com.devonfw.cobigen.test.matchers.VariableAssignmentToMatcher;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;

Expand Down Expand Up @@ -211,6 +212,7 @@ public String toString() {
};

// Pre-processing: Mocking
GeneratorPluginActivator activator = mock(GeneratorPluginActivator.class);
TriggerInterpreter triggerInterpreter = mock(TriggerInterpreter.class);
MatcherInterpreter matcher = mock(MatcherInterpreter.class);
InputReader inputReader = mock(InputReader.class);
Expand Down Expand Up @@ -242,7 +244,7 @@ public String toString() {
when(matcher.matches(argThat(new MatcherToMatcher(equalTo("not"), ANY, sameInstance(child2)))))
.thenReturn(false);

PluginRegistry.registerTriggerInterpreter(triggerInterpreter);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);

// create CobiGen instance
File templatesFolder = new File(testFileRootPath + "selectiveContainerGeneration");
Expand Down Expand Up @@ -303,6 +305,7 @@ public String toString() {
};

// Pre-processing: Mocking
GeneratorPluginActivator activator = mock(GeneratorPluginActivator.class);
TriggerInterpreter triggerInterpreter = mock(TriggerInterpreter.class);
MatcherInterpreter matcher = mock(MatcherInterpreter.class);
InputReader inputReader = mock(InputReader.class);
Expand Down Expand Up @@ -345,7 +348,7 @@ public String toString() {
.thenReturn(ImmutableMap.<String, String> builder().put("rootPackage", "com.devonfw")
.put("entityName", "Test").build());

PluginRegistry.registerTriggerInterpreter(triggerInterpreter);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);

return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.devonfw.cobigen.api.CobiGen;
import com.devonfw.cobigen.api.exception.InvalidConfigurationException;
import com.devonfw.cobigen.api.extension.GeneratorPluginActivator;
import com.devonfw.cobigen.api.extension.InputReader;
import com.devonfw.cobigen.api.extension.MatcherInterpreter;
import com.devonfw.cobigen.api.extension.TriggerInterpreter;
Expand Down Expand Up @@ -150,6 +151,7 @@ public String toString() {
};

// Pre-processing: Mocking
GeneratorPluginActivator activator = mock(GeneratorPluginActivator.class);
TriggerInterpreter triggerInterpreter = mock(TriggerInterpreter.class);
MatcherInterpreter matcher = mock(MatcherInterpreter.class);
InputReader inputReader = mock(InputReader.class);
Expand All @@ -166,7 +168,7 @@ public String toString() {
variables.put("contextVar", "contextValue");
when(matcher.resolveVariables(any(MatcherTo.class), any(List.class))).thenReturn(variables);

PluginRegistry.registerTriggerInterpreter(triggerInterpreter);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);

// further setup
File folder = tmpFolder.newFolder();
Expand Down Expand Up @@ -200,6 +202,7 @@ public String toString() {
};

// Pre-processing: Mocking
GeneratorPluginActivator activator = mock(GeneratorPluginActivator.class);
TriggerInterpreter triggerInterpreter = mock(TriggerInterpreter.class);
MatcherInterpreter matcher = mock(MatcherInterpreter.class);
InputReader inputReader = mock(InputReader.class);
Expand All @@ -216,7 +219,7 @@ public String toString() {
variables.put("contextVar", "contextValue");
when(matcher.resolveVariables(any(MatcherTo.class), any(List.class))).thenReturn(variables);

PluginRegistry.registerTriggerInterpreter(triggerInterpreter);
PluginRegistry.registerTriggerInterpreter(triggerInterpreter, activator);

// further setup
File folder = tmpFolder.newFolder();
Expand Down
Loading

0 comments on commit c6cb445

Please sign in to comment.