Skip to content

Commit

Permalink
#179: Merge branch 'dev_eclipseplugin'
Browse files Browse the repository at this point in the history
  • Loading branch information
maybeec committed Jan 10, 2016
2 parents 2ba80c4 + 1a87417 commit 3681303
Show file tree
Hide file tree
Showing 30 changed files with 561 additions and 196 deletions.
2 changes: 1 addition & 1 deletion cobigen-eclipse/cobigen-eclipse-feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="cobigen-eclipse-feature"
label="CobiGen Eclipse Plug-in"
version="1.4.1"
version="1.4.2"
provider-name="Capgemini">

<description>
Expand Down
2 changes: 1 addition & 1 deletion cobigen-eclipse/cobigen-eclipse-feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>cobigen-eclipse-feature</artifactId>
<name>CobiGen - Eclipse Plug-In Feature</name>
<packaging>eclipse-feature</packaging>
<version>1.4.1</version>
<version>1.4.2</version>

<parent>
<groupId>com.capgemini</groupId>
Expand Down
2 changes: 1 addition & 1 deletion cobigen-eclipse/cobigen-eclipse-updatesite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.capgemini</groupId>
<artifactId>cobigen-eclipse-updatesite</artifactId>
<name>CobiGen - Eclipse Plug-In UpdateSite</name>
<version>1.4.1</version>
<version>1.4.2</version>
<packaging>eclipse-repository</packaging>

<parent>
Expand Down
2 changes: 1 addition & 1 deletion cobigen-eclipse/cobigen-eclipse/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CobiGen Eclipse Plug-In
Bundle-SymbolicName: cobigen-eclipse;singleton:=true
Bundle-Version: 1.4.1
Bundle-Version: 1.4.2
Bundle-Activator: com.capgemini.cobigen.eclipse.Activator
Bundle-Vendor: Capgemini
Require-Bundle: org.eclipse.ui;bundle-version="3.104.0",
Expand Down
2 changes: 1 addition & 1 deletion cobigen-eclipse/cobigen-eclipse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>cobigen-eclipse</artifactId>
<name>CobiGen - Eclipse Plug-In</name>
<packaging>eclipse-plugin</packaging>
<version>1.4.1</version>
<version>1.4.2</version>

<parent>
<groupId>com.capgemini</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ public void start(BundleContext context) throws Exception {
* @author mbrunnli (08.04.2013)
*/
public void startConfigurationProjectListener() {
LOG.info("Start configuration project listener");
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MDC.put(InfrastructureConstants.CORRELATION_ID, UUID.randomUUID().toString());
synchronized (configurationProjectListener) {
if (configurationProjectListenerStarted) {
return;
Expand All @@ -90,6 +92,7 @@ public void run() {
configurationProjectListenerStarted = true;
LOG.info("ResourceChangeListener for configuration project started.");
}
MDC.remove(InfrastructureConstants.CORRELATION_ID);
}
});
}
Expand All @@ -99,9 +102,11 @@ public void run() {
* @author mbrunnli (Jun 24, 2015)
*/
public void stopConfigurationListener() {
LOG.info("Stop configuration project listener");
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MDC.put(InfrastructureConstants.CORRELATION_ID, UUID.randomUUID().toString());
synchronized (configurationProjectListener) {
if (!configurationProjectListenerStarted) {
return;
Expand All @@ -110,6 +115,7 @@ public void run() {
configurationProjectListenerStarted = false;
LOG.info("ResourceChangeListener for configuration project stopped.");
}
MDC.remove(InfrastructureConstants.CORRELATION_ID);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.capgemini.cobigen.eclipse.common;

import org.eclipse.jface.operation.IRunnableWithProgress;

/**
* Abstract long running background job providing exception handling facilities.
* @author mbrunnli (Jan 10, 2016)
*/
public abstract class AbstractCobiGenJob implements IRunnableWithProgress {

/**
* Exception occurred during processing
*/
protected RuntimeException occurredException;

/**
* Returns the field 'occurredException'
* @return value of occurredException
* @author mbrunnli (Jan 10, 2016)
*/
public RuntimeException getOccurredException() {
return occurredException;
}

/**
* States whether an exception occurred during processing.
* @return <code>true</code> if an exception occurred, <code>false</code> otherwise.
* @author mbrunnli (Jan 10, 2016)
*/
public boolean isExceptionOccurred() {
return occurredException != null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.capgemini.cobigen.eclipse.common.exceptions;

/**
*
* @author mbrunnli (Jan 10, 2016)
*/
public class CobiGenEclipseRuntimeException extends RuntimeException {

/**
* Default serial version UID.
*/
private static final long serialVersionUID = 1L;

/**
* Creates a new {@link CobiGenEclipseRuntimeException} for the given message and cause.
* @param message
* error message
* @param cause
* of the exception
* @author mbrunnli (Jan 10, 2016)
*/
public CobiGenEclipseRuntimeException(String message, Throwable cause) {
super(message, cause);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,19 @@ public static IWorkbenchPage getActiveWorkbenchPage() {
* of the error or <code>null</code> if the error was not caused by any {@link Throwable}
* @author mbrunnli (Jun 23, 2015)
*/
public static void openErrorDialog(String dialogTitle, String message, Throwable cause) {
if (cause == null) {
MessageDialog.openError(Display.getDefault().getActiveShell(), dialogTitle, message);
} else {
ErrorDialog.openError(Display.getDefault().getActiveShell(), dialogTitle, message,
createMultiStatus(cause));
}
public static void openErrorDialog(final String dialogTitle, final String message, final Throwable cause) {

getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
if (cause == null) {
MessageDialog.openError(Display.getDefault().getActiveShell(), dialogTitle, message);
} else {
ErrorDialog.openError(Display.getDefault().getActiveShell(), dialogTitle, message,
createMultiStatus(cause));
}
}
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.capgemini.cobigen.eclipse.generator;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.UUID;

import org.apache.log4j.MDC;
import org.eclipse.core.runtime.IProgressMonitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.capgemini.cobigen.CobiGen;
import com.capgemini.cobigen.eclipse.common.AbstractCobiGenJob;
import com.capgemini.cobigen.eclipse.common.constants.InfrastructureConstants;
import com.capgemini.cobigen.extension.to.TemplateTo;
import com.google.common.collect.Lists;

/**
* Job implementation for processing long running operations of CobiGen off the ui thread.
* @author mbrunnli (Jan 10, 2016)
*/
public class AnalyzeInputJob extends AbstractCobiGenJob {

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

/**
* CobiGen API
*/
private CobiGen cobigen;

/**
* input objects to be analyzed
*/
private List<Object> inputs;

/**
* Determined matching templates
*/
private List<TemplateTo> resultMatchingTemplates = Lists.newArrayList();

/**
* States whether the generation input is a single non container input.
*/
private boolean resultSingleNonContainerInput;

/**
* Creates a new job for analyzing the inputs regarding matching templates etc.
* @param cobigen
* CobiGen instance
* @param inputs
* input objects to be analyzed
* @author mbrunnli (Jan 10, 2016)
*/
public AnalyzeInputJob(CobiGen cobigen, List<Object> inputs) {
this.cobigen = cobigen;
this.inputs = inputs;
}

/**
* {@inheritDoc}
* @author mbrunnli (Jan 10, 2016)
*/
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
MDC.put(InfrastructureConstants.CORRELATION_ID, UUID.randomUUID().toString());

try {
LOG.info("Determine matching templates...");
monitor.beginTask("Determine matching templates...", inputs.size() + 1);
for (Object input : inputs) {
resultMatchingTemplates.addAll(cobigen.getMatchingTemplates(input));
monitor.worked(1);
}
LOG.info("Determine if input is container...");
resultSingleNonContainerInput =
inputs.size() == 1 && !cobigen.combinesMultipleInputs(inputs.get(0));
monitor.done();
} catch (RuntimeException e) {
occurredException = e;
}

MDC.remove(InfrastructureConstants.CORRELATION_ID);
}

/**
* Returns the field 'resultMatchingTemplates'
* @return value of resultMatchingTemplates
* @author mbrunnli (Jan 10, 2016)
*/
public List<TemplateTo> getResultMatchingTemplates() {
return resultMatchingTemplates;
}

/**
* Returns the field 'resultSingleNonContainerInput'
* @return value of resultSingleNonContainerInput
* @author mbrunnli (Jan 10, 2016)
*/
public boolean isResultSingleNonContainerInput() {
return resultSingleNonContainerInput;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.capgemini.cobigen.eclipse.generator;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
Expand All @@ -12,12 +13,15 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.capgemini.cobigen.CobiGen;
import com.capgemini.cobigen.config.entity.Trigger;
import com.capgemini.cobigen.eclipse.common.exceptions.CobiGenEclipseRuntimeException;
import com.capgemini.cobigen.eclipse.common.exceptions.GeneratorProjectNotExistentException;
import com.capgemini.cobigen.eclipse.common.exceptions.InvalidInputException;
import com.capgemini.cobigen.eclipse.common.tools.PathUtil;
Expand Down Expand Up @@ -107,10 +111,12 @@ public CobiGenWrapper(List<Object> inputs) throws GeneratorProjectNotExistentExc
*/
public void setInput(Object input) {
if (input != null) {
LOG.info("Set new generator input. Calculating matching templates...");
initialized = true;
inputs = Lists.newArrayList(input);
matchingTemplates = cobiGen.getMatchingTemplates(input);
singleNonContainerInput = !cobiGen.combinesMultipleInputs(input);
LOG.info("Finished calculating matching templates.");
} else {
initialized = false;
inputs = null;
Expand All @@ -130,11 +136,31 @@ public void setInputs(List<Object> inputs) {
initialized = this.inputs != null && this.inputs.size() > 0;

if (initialized) {
LOG.info("Set new generator inputs. Calculating matching templates...");
matchingTemplates = Lists.newLinkedList();
for (Object input : this.inputs) {
matchingTemplates.addAll(cobiGen.getMatchingTemplates(input));

ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getDefault().getActiveShell());
AnalyzeInputJob job = new AnalyzeInputJob(cobiGen, inputs);
try {
dialog.run(true, false, job);
} catch (InvocationTargetException e) {
LOG.error("An internal error occured while invoking input analyzer job.", e);
throw new CobiGenEclipseRuntimeException(
"An internal error occured while invoking input analyzer job", e);
} catch (InterruptedException e) {
LOG.warn("The working thread doing the input analyzer job has been interrupted.", e);
throw new CobiGenEclipseRuntimeException(
"The working thread doing the input analyzer job has been interrupted", e);
}

// forward exception thrown in the processing thread if an exception occurred
if (job.isExceptionOccurred()) {
throw job.getOccurredException();
}
singleNonContainerInput = inputs.size() == 1 && !cobiGen.combinesMultipleInputs(inputs.get(0));

matchingTemplates = job.getResultMatchingTemplates();
singleNonContainerInput = job.isResultSingleNonContainerInput();
LOG.info("Finished analyzing generation input.");
} else {
inputs = null;
matchingTemplates = null;
Expand Down Expand Up @@ -366,8 +392,9 @@ public Set<IFile> getAllTargetFiles() {
}

Set<IFile> files = new HashSet<>();
boolean combinesMultipleInputs = cobiGen.combinesMultipleInputs(inputs.get(0));
for (TemplateTo t : getAllTemplates()) {
if (cobiGen.combinesMultipleInputs(inputs.get(0))) {
if (combinesMultipleInputs) {
List<Object> children = new JavaInputReader().getInputObjects(inputs.get(0), Charsets.UTF_8);
for (Object child : children) {
files.add(getGenerationTargetProject().getFile(t.resolveDestinationPath(child)));
Expand Down Expand Up @@ -420,7 +447,11 @@ public List<String> getMatchingTriggerIds(Object loadClass) {

/**
* Checks if the selected items are supported by one or more {@link Trigger}s, and if they are supported
* by the same {@link Trigger}s
* by the same {@link Trigger}s. Returns a boolean value, if all objects of the selection could be
* processed. If there are objects, which are not yet supported as inputs for generation, or the selection
* in composed of valid objects in an not yet supported way, an {@link InvalidInputException} will be
* thrown. Thus, getting a boolean value can be interpreted as
* "selection supported, but currently not matching trigger".
*
* @param selection
* the selection made
Expand Down
Loading

0 comments on commit 3681303

Please sign in to comment.