Skip to content

Commit

Permalink
#237 Merge branch 'dev_javaplugin'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
maybeec committed Dec 13, 2016
2 parents a6fee8a + 0af89e6 commit 7bd0fcd
Show file tree
Hide file tree
Showing 44 changed files with 1,100 additions and 1,204 deletions.
12 changes: 9 additions & 3 deletions cobigen/cobigen-javaplugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>cobigen-javaplugin</artifactId>
<name>CobiGen - Java Plug-in</name>
<version>1.3.2</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<parent>
Expand All @@ -17,9 +17,15 @@
<dependency>
<groupId>com.capgemini</groupId>
<artifactId>cobigen-core</artifactId>
<version>2.0.0</version>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>com.capgemini</groupId>
<artifactId>cobigen-core-test</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>

<!-- QDox for Java parsing -->
<dependency>
<groupId>com.thoughtworks.qdox</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,29 @@

import java.util.List;

import com.capgemini.cobigen.extension.IGeneratorPluginActivator;
import com.capgemini.cobigen.extension.IMerger;
import com.capgemini.cobigen.extension.ITriggerInterpreter;
import com.capgemini.cobigen.api.extension.GeneratorPluginActivator;
import com.capgemini.cobigen.api.extension.Merger;
import com.capgemini.cobigen.api.extension.TriggerInterpreter;
import com.capgemini.cobigen.impl.PluginRegistry;
import com.capgemini.cobigen.javaplugin.merger.JavaMerger;
import com.google.common.collect.Lists;

/**
*
* @author mbrunnli (06.04.2014)
* Plug-in activator to be registered to the {@link PluginRegistry} of CobiGen by any client.
*/
public class JavaPluginActivator implements IGeneratorPluginActivator {
public class JavaPluginActivator implements GeneratorPluginActivator {

/**
* {@inheritDoc}
* @author mbrunnli (06.04.2014)
*/
@Override
public List<IMerger> bindMerger() {
List<IMerger> merger = Lists.newLinkedList();
public List<Merger> bindMerger() {
List<Merger> merger = Lists.newLinkedList();
merger.add(new JavaMerger("javamerge", false));
merger.add(new JavaMerger("javamerge_override", true));
return merger;
}

/**
* {@inheritDoc}
* @author mbrunnli (08.04.2014)
*/
@Override
public List<ITriggerInterpreter> bindTriggerInterpreter() {
return Lists.<ITriggerInterpreter> newArrayList(new JavaTriggerInterpreter("java"));
public List<TriggerInterpreter> bindTriggerInterpreter() {
return Lists.<TriggerInterpreter> newArrayList(new JavaTriggerInterpreter("java"));
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.capgemini.cobigen.javaplugin;

import com.capgemini.cobigen.extension.IInputReader;
import com.capgemini.cobigen.extension.IMatcher;
import com.capgemini.cobigen.extension.ITriggerInterpreter;
import com.capgemini.cobigen.api.extension.InputReader;
import com.capgemini.cobigen.api.extension.MatcherInterpreter;
import com.capgemini.cobigen.api.extension.TriggerInterpreter;
import com.capgemini.cobigen.javaplugin.inputreader.JavaInputReader;
import com.capgemini.cobigen.javaplugin.matcher.JavaMatcher;

/**
* {@link ITriggerInterpreter} implementation of a Java Interpreter
* @author mbrunnli (08.04.2014)
* {@link TriggerInterpreter} implementation of a Java Interpreter
*/
public class JavaTriggerInterpreter implements ITriggerInterpreter {
public class JavaTriggerInterpreter implements TriggerInterpreter {

/**
* {@link ITriggerInterpreter} type to be registered
* {@link TriggerInterpreter} type to be registered
*/
public String type;

Expand All @@ -27,30 +26,18 @@ public JavaTriggerInterpreter(String type) {
this.type = type;
}

/**
* {@inheritDoc}
* @author mbrunnli (08.04.2014)
*/
@Override
public String getType() {
return type;
}

/**
* {@inheritDoc}
* @author mbrunnli (08.04.2014)
*/
@Override
public IInputReader getInputReader() {
public InputReader getInputReader() {
return new JavaInputReader();
}

/**
* {@inheritDoc}
* @author mbrunnli (08.04.2014)
*/
@Override
public IMatcher getMatcher() {
public MatcherInterpreter getMatcher() {
return new JavaMatcher();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.capgemini.cobigen.extension.IInputReader;
import com.capgemini.cobigen.extension.InputReaderV13;
import com.capgemini.cobigen.api.extension.InputReader;
import com.capgemini.cobigen.javaplugin.inputreader.to.PackageFolder;
import com.capgemini.cobigen.javaplugin.merger.libextension.ModifyableClassLibraryBuilder;
import com.capgemini.cobigen.javaplugin.util.freemarkerutil.IsAbstractMethod;
Expand All @@ -30,23 +29,18 @@
import com.thoughtworks.qdox.model.JavaSource;

/**
* Extension for the {@link IInputReader} Interface of the CobiGen, to be able to read Java classes into
* Extension for the {@link InputReader} Interface of the CobiGen, to be able to read Java classes into
* FreeMarker models
*
* @author mbrunnli (15.10.2013)
*/
public class JavaInputReader implements InputReaderV13 {
public class JavaInputReader implements InputReader {

/**
* Logger instance
*/
private static final Logger LOG = LoggerFactory.getLogger(JavaInputReader.class);

/**
* {@inheritDoc}
*
* @author mbrunnli (08.04.2014)
*/
@Override
public boolean isValidInput(Object input) {

Expand All @@ -57,13 +51,13 @@ public boolean isValidInput(Object input) {
Object[] inputArr = (Object[]) input;
if (inputArr.length == 2) {
if (inputArr[0] instanceof JavaClass && inputArr[1] instanceof Class<?>) {
if (((JavaClass) inputArr[0]).getFullyQualifiedName().equals(
((Class<?>) inputArr[1]).getCanonicalName())) {
if (((JavaClass) inputArr[0]).getFullyQualifiedName()
.equals(((Class<?>) inputArr[1]).getCanonicalName())) {
return true;
}
} else if (inputArr[0] instanceof Class<?> && inputArr[1] instanceof JavaClass) {
if (((Class<?>) inputArr[0]).getCanonicalName().equals(
((JavaClass) inputArr[1]).getFullyQualifiedName())) {
if (((Class<?>) inputArr[0]).getCanonicalName()
.equals(((JavaClass) inputArr[1]).getFullyQualifiedName())) {
return true;
}
}
Expand All @@ -72,11 +66,6 @@ public boolean isValidInput(Object input) {
return false;
}

/**
* {@inheritDoc}
*
* @author mbrunnli (15.10.2013)
*/
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> createModel(Object o) {
Expand All @@ -103,11 +92,6 @@ public Map<String, Object> createModel(Object o) {
return null;
}

/**
* {@inheritDoc}
*
* @author mbrunnli (03.06.2014)
*/
@Override
public boolean combinesMultipleInputObjects(Object input) {

Expand All @@ -117,19 +101,11 @@ public boolean combinesMultipleInputObjects(Object input) {
return false;
}

/**
* {@inheritDoc}
* @author mbrunnli (03.06.2014)
*/
@Override
public List<Object> getInputObjects(Object input, Charset inputCharset) {
return getInputObjects(input, inputCharset, false);
}

/**
* {@inheritDoc}
* @author mbrunnli (19.01.2015)
*/
@Override
public List<Object> getInputObjectsRecursively(Object input, Charset inputCharset) {
return getInputObjects(input, inputCharset, true);
Expand Down Expand Up @@ -192,8 +168,8 @@ public List<Object> getInputObjects(Object input, Charset inputCharset, boolean
}
}
} catch (IOException e) {
LOG.error("The file {} could not be parsed as a java class", f.getAbsolutePath()
.toString(), e);
LOG.error("The file {} could not be parsed as a java class",
f.getAbsolutePath().toString(), e);
}

}
Expand All @@ -214,22 +190,25 @@ public List<Object> getInputObjects(Object input, Charset inputCharset, boolean
private List<File> retrieveAllJavaSourceFiles(File packageFolder, boolean recursively) {

List<File> files = new LinkedList<>();
List<File> isDirectory = new LinkedList<>();
if (packageFolder.isDirectory()) {
for (File f : packageFolder.listFiles()) {
if (f.isDirectory() && recursively) {
files.addAll(retrieveAllJavaSourceFiles(f, recursively));
} else if (f.isFile() && f.getName().endsWith(".java")) {
if (f.isFile() && f.getName().endsWith(".java")) {
files.add(f);
} else if (f.isDirectory()) {
isDirectory.add(f);
}
}
if (recursively) {
for (File dir : isDirectory) {
files.addAll(retrieveAllJavaSourceFiles(dir, recursively));
}
}
}
return files;

}

/**
* {@inheritDoc}
* @author fkreis (22.10.2014)
*/
@Override
public Map<String, Object> getTemplateMethods(Object input) {

Expand Down Expand Up @@ -293,7 +272,6 @@ public Map<String, Object> getTemplateMethods(Object input) {
* model created by reflection to be merged
* @return the merged model. Due to implementation restrictions a {@link Map} of {@link String} to
* {@link Object}
* @author mbrunnli (17.11.2014)
*/
@SuppressWarnings("unchecked")
private Object mergeModelsRecursively(Object parsedModel, Object reflectionModel) {
Expand Down Expand Up @@ -329,11 +307,11 @@ private Object mergeModelsRecursively(Object parsedModel, Object reflectionModel
}
return mergedModel;
}
// Case: List<Map<String, Object>> available in attributes and methods
// Case: List<Map<String, Object>> available in fields and methods
else if (parsedModel instanceof List && reflectionModel instanceof List) {
if (!((List<?>) parsedModel).isEmpty() && ((List<?>) parsedModel).get(0) instanceof Map
|| !((List<?>) reflectionModel).isEmpty()
&& ((List<?>) reflectionModel).get(0) instanceof Map) {
&& ((List<?>) reflectionModel).get(0) instanceof Map) {
List<Map<String, Object>> model1List =
Lists.newLinkedList((List<Map<String, Object>>) parsedModel);
List<Map<String, Object>> model2List =
Expand All @@ -350,8 +328,8 @@ else if (parsedModel instanceof List && reflectionModel instanceof List) {
Map<String, Object> model2Entry = model2ListIt.next();
// valid merging for fields and methods
if (model1Entry.get(ModelConstant.NAME) != null) {
if (model1Entry.get(ModelConstant.NAME).equals(
model2Entry.get(ModelConstant.NAME))) {
if (model1Entry.get(ModelConstant.NAME)
.equals(model2Entry.get(ModelConstant.NAME))) {
mergedModel.add(mergeModelsRecursively(model1Entry, model2Entry));

// remove both entries as they have been matched and recursively merged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public class ModelConstant {
/**
* Root element for java model ({@link Map}&lt;{@link String}, {@link Object}&gt;)
*/
public static final String ROOT = "pojo";
public static final String MODEL_ROOT = "pojo";

/**
* Package name of the input class ({@link String})
*/
/** Raw class object providing any reflection interaction. ({@link Class}) */
public static final String CLASS_OBJECT = "classObject";

/** Package name of the input class ({@link String}) */
public static final String PACKAGE = "package";

/**
Expand Down
Loading

0 comments on commit 7bd0fcd

Please sign in to comment.