Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1465 custom template location documentation #1545

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.devonfw.cobigen.eclipse.test;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants;
import com.devonfw.cobigen.eclipse.test.common.SystemTest;
import com.devonfw.cobigen.eclipse.test.common.utils.EclipseCobiGenUtils;
import com.devonfw.cobigen.eclipse.test.common.utils.EclipseUtils;

/**
* Test suite for exception handling issues.
*/
@RunWith(SWTBotJunit4ClassRunner.class)
public class ExceptionHandlingTest extends SystemTest {

/** Root path of the Test Resources */
private static final String resourcesRootPath = "src/main/resources/ExceptionHandlingTest/";

/**
* Setup workbench appropriately for tests
*
* @throws Exception test fails
*/
@BeforeClass
public static void setupClass() throws Exception {

EclipseUtils.cleanWorkspace(bot, true);
// import the configuration project for this test
EclipseUtils.importExistingGeneralProject(bot, new File(resourcesRootPath + "templates").getAbsolutePath());
EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME);
}

/**
* Tests for a conflict of old and new templates configuration and proper error message dialog
*
* @throws Exception Test fails
*/
@Test
@Ignore
public void testConflictWithTemplateTypesDisplaysErrorDialog() throws Exception {

// create a new temporary java project and copy java class used as an input for CobiGen
String testProjectName = "TestInputProj";
IJavaProject project = this.tmpMavenProjectRule.createProject(testProjectName);
FileUtils.copyFile(new File(resourcesRootPath + "input/PlainInput.java"),
project.getUnderlyingResource().getLocation().append("src/main/java/main/PlainInput.java").toFile());
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
this.tmpMavenProjectRule.updateProject();

// expand the new file in the package explorer
SWTBotView view = bot.viewById(JavaUI.ID_PACKAGES);
SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjectName, "src/main/java", "main",
"PlainInput.java");
javaClassItem.select();

// execute CobiGen
EclipseCobiGenUtils.processCobiGenWithExpectedError(bot, javaClassItem, "Invalid context configuration!");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ public static void processCobiGen(SWTWorkbenchBot bot, SWTBotTreeItem input, Str
processCobiGen(bot, input, DEFAULT_TIMEOUT, increments);
}

/**
* Tries a Generate process with an expected error title.
*
* @param bot the {@link SWTWorkbenchBot} of the test
* @param input input of CobiGen to be selected
* @param expectedErrorTitle String of expected error title
* @throws Exception test fails
*/
public static void processCobiGenWithExpectedError(SWTWorkbenchBot bot, SWTBotTreeItem input,
String expectedErrorTitle) throws Exception {

processCobiGenWithExpectedError(bot, input, DEFAULT_TIMEOUT, expectedErrorTitle);
}

/**
* Expands multi layer nodes of following format: node1>node2>finalNode
*
Expand Down Expand Up @@ -109,6 +123,31 @@ public static void processCobiGen(SWTWorkbenchBot bot, SWTBotTreeItem input, int
finishButton.click();
}

/**
* Tries a Generate process with an expected error title.
*
* @param bot the {@link SWTWorkbenchBot} of the test
* @param input input of CobiGen to be selected
* @param defaultTimeout timeout to be overwritten
* @param expectedErrorTitle String of expected error title
* @throws Exception test fails
*/
public static void processCobiGenWithExpectedError(SWTWorkbenchBot bot, SWTBotTreeItem input, int defaultTimeout,
String expectedErrorTitle) throws Exception {

// Open generation wizard with new file as Input
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
bot.waitUntil(new AllJobsAreFinished(), defaultTimeout); // build might take some time
input.contextMenu("CobiGen").menu("Generate...").click();
bot.waitUntil(new AnyShellIsActive(expectedErrorTitle), defaultTimeout);

takeScreenshot(bot, "InvalidConfigurationDialog");

SWTBotButton finishButton = bot.button(IDialogConstants.OK_LABEL);
bot.waitUntil(widgetIsEnabled(bot.button()));
finishButton.click();
}

/**
* Checks the CobiGen HealthCheck and takes screenshots of it.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static void cleanWorkspace(SWTWorkbenchBot bot, boolean cleanCobiGenConfi
}
break;
} catch (Exception e) {
LOG.debug("An error occured while trying to delete project: {}", projectName);
LOG.debug("An error occured while trying to delete project: {}", projectName, e);
Thread.sleep(500);
if (i == maxRetries) {
LOG.debug("Not able to cleanup the workspace after: {} retries", maxRetries);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main;

public class PlainInput {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CobiGen_Templates</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is for logback classic. The file contains the configuration
for sl4j logging -->
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- defines the level of logging -->
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>

<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.devonfw.cobigen</groupId>
<artifactId>templates-oasp</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>CobiGen OASP Templates</name>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<contextConfiguration xmlns="http://capgemini.com/devonfw/cobigen/ContextConfiguration" version="2.1">
<trigger id="test" type="java">
<matcher type="fqn" value=".*">
</matcher>
</trigger>
</contextConfiguration>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<contextConfiguration xmlns="http://capgemini.com/devonfw/cobigen/ContextConfiguration" version="2.1">
<trigger id="test" type="java">
<matcher type="fqn" value=".*">
</matcher>
</trigger>
</contextConfiguration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<templatesConfiguration xmlns="http://capgemini.com/devonfw/cobigen/TemplatesConfiguration" version="2.1">
<templates>
<template name="t1" destinationPath="TestOutput.txt" templateFile="TestOutput.txt.ftl"/>
</templates>
<increments>
<increment name="i1" description="increment1">
<templateRef ref="t1"/>
</increment>
</increments>
</templatesConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.LoggerFactory;

import com.devonfw.cobigen.api.exception.CobiGenRuntimeException;
import com.devonfw.cobigen.api.exception.ConfigurationConflictException;
import com.devonfw.cobigen.api.exception.InvalidConfigurationException;
import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants;
import com.devonfw.cobigen.eclipse.common.exceptions.GeneratorCreationException;
Expand Down Expand Up @@ -36,6 +37,8 @@ public static void handle(Throwable e, Shell activeShell) {
} else if (InvalidConfigurationException.class.isAssignableFrom(e.getClass())) {
LOG.warn("Invalid configuration.", e);
openInvalidConfigurationErrorDialog((InvalidConfigurationException) e);
} else if (ConfigurationConflictException.class.isAssignableFrom(e.getClass())) {
openInvalidConfigurationErrorDialog((ConfigurationConflictException) e);
} else if (GeneratorProjectNotExistentException.class.isAssignableFrom(e.getClass())) {
LOG.error(
"The project '{}' containing the configuration and templates is currently not existent. Please create one or check it out from SVN as stated in the user documentation.",
Expand All @@ -56,6 +59,7 @@ public static void handle(Throwable e, Shell activeShell) {
LOG.error("An unexpected exception occurred!", e);
PlatformUIUtil.openErrorDialog("An unexpected exception occurred!", e);
}

}

/**
Expand All @@ -74,18 +78,21 @@ private static Shell getShell(Shell activeShell) {
*/
private static void openInvalidConfigurationErrorDialog(InvalidConfigurationException e) {

MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Invalid context configuration!",
null,
"Any context/templates configuration has been changed into an invalid state "
+ "OR is simply outdated, if you recently updated CobiGen. "
+ "For further investigation and automatic upgrade options start CobiGen's Health Check."
+ "\n\nOriginal error message: " + e.getMessage(),
MessageDialog.ERROR, new String[] { "Health Check", "OK" }, 1);
dialog.setBlockOnOpen(true);
PlatformUIUtil.getWorkbench().getDisplay().syncExec(() -> {
MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Invalid context configuration!",
null,
"Any context/templates configuration has been changed into an invalid state "
+ "OR is simply outdated, if you recently updated CobiGen. "
+ "For further investigation and automatic upgrade options start CobiGen's Health Check."
+ "\n\nOriginal error message: " + e.getMessage(),
MessageDialog.ERROR, new String[] { "Health Check", "OK" }, 1);
dialog.setBlockOnOpen(true);

int result = dialog.open();
if (result == 0) {
new HealthCheckDialog().execute();
}
int result = dialog.open();
if (result == 0) {
new HealthCheckDialog().execute();
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,14 @@ public static IWorkbenchPage getActiveWorkbenchPage() {
*/
public static void openErrorDialog(final String message, final Throwable cause) {

getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {

if (cause == null) {
MessageDialog.openError(Display.getDefault().getActiveShell(), CobiGenDialogConstants.DIALOG_TITLE_ERROR,
message);
} else {
LinkErrorDialog.openError(Display.getDefault().getActiveShell(), CobiGenDialogConstants.DIALOG_TITLE_ERROR,
message, createMultiStatus(cause));
}
getWorkbench().getDisplay().syncExec(() -> {

if (cause == null) {
MessageDialog.openError(Display.getDefault().getActiveShell(), CobiGenDialogConstants.DIALOG_TITLE_ERROR,
message);
} else {
LinkErrorDialog.openError(Display.getDefault().getActiveShell(), CobiGenDialogConstants.DIALOG_TITLE_ERROR,
message, createMultiStatus(cause));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.devonfw.cobigen.api.HealthCheck;
import com.devonfw.cobigen.api.constants.BackupPolicy;
import com.devonfw.cobigen.api.constants.ConfigurationConstants;
import com.devonfw.cobigen.api.exception.ConfigurationConflictException;
import com.devonfw.cobigen.api.exception.InvalidConfigurationException;
import com.devonfw.cobigen.api.to.HealthCheckReport;
import com.devonfw.cobigen.api.util.CobiGenPaths;
Expand Down Expand Up @@ -106,6 +107,11 @@ public void execute() {
+ "=> Please import the configuration project into your workspace as stated in the "
+ "documentation of CobiGen or in the one of your project.";
PlatformUIUtil.openErrorDialog(healthyCheckMessage, null);
} catch (ConfigurationConflictException e) {
healthyCheckMessage = "An unexpected error occurred! Templates were in a conflicted state.";
healthyCheckMessage += "\n\nNo automatic upgrade of the context configuration possible.";
PlatformUIUtil.openErrorDialog(healthyCheckMessage, e);
LOG.error(healthyCheckMessage, e);
} catch (InvalidConfigurationException e) {
// Won't be reached anymore
healthyCheckMessage = firstStep + "OK.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
monitor.beginTask("Searching valid triggers...", 1);
if (!generator.isValidInput(monitor)) {
LOG.info("No matching Trigger. Exiting generate command.");
PlatformUIUtil.getWorkbench().getDisplay()
.syncExec(() -> MessageDialog.openInformation(HandlerUtil.getActiveShell(this.event), "No matching Trigger!",
PlatformUIUtil.getWorkbench().getDisplay().syncExec(
() -> MessageDialog.openInformation(HandlerUtil.getActiveShell(this.event), "No matching Trigger!",
"Your current selection is not valid as input for any generation purpose. "
+ "Please find the specification of valid inputs in the context configuration ('"
+ ResourceConstants.CONFIG_PROJECT_NAME + "/context.xml')."));
Expand Down
2 changes: 1 addition & 1 deletion cobigen-eclipse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<properties>
<tycho-repo.url>https://oss.sonatype.org/content/groups/public/</tycho-repo.url>
<eclipse-repository>http://download.eclipse.org/releases/photon</eclipse-repository>
<eclipse-repository>https://download.eclipse.org/releases/photon</eclipse-repository>
</properties>

<modules>
Expand Down
Loading