Skip to content

Commit

Permalink
devonfw#1509 taking the import of template-sets into Eclipse either b…
Browse files Browse the repository at this point in the history
…efore or after the adapt command into consideration
  • Loading branch information
Cedric Betom committed Jan 31, 2023
1 parent e26f0aa commit 02d03d6
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.nio.file.Path;

import org.apache.commons.io.FileUtils;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -68,7 +69,10 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
this.tmpMavenProjectRule.updateProject();

EclipseCobiGenUtils.runAndCaptureUpdateTemplates(bot);
/**
* TODO Before the templates are made available online, the update (download) command cannot be tested.
*/
// EclipseCobiGenUtils.runAndCaptureUpdateTemplates(bot);
EclipseCobiGenUtils.runAndCaptureAdaptTemplates(bot);
EclipseUtils.updateMavenProject(bot, ResourceConstants.CONFIG_PROJECT_NAME);

Expand Down Expand Up @@ -101,7 +105,14 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
@Test
public void testAdaptTemplatesAndGenerate() throws Exception {

Path devTemplatesPath = new File(
AdaptTemplatesTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile()
.getParentFile().toPath().resolve("cobigen-templates").resolve("crud-openapi-java-server-app")
.resolve("target").resolve("crud-openapi-java-server-app-2021.12.007-SNAPSHOT.jar");

File tmpProject = this.tempFolder.newFolder("playground", "project");
File downloaded = this.tempFolder.newFolder("playground", "project", "template-sets", "downloaded");
FileUtils.copyFileToDirectory(devTemplatesPath.toFile(), downloaded);
withEnvironmentVariable("COBIGEN_HOME", tmpProject.toPath().toString())
.execute(() -> testBasicOpenAPIGenerationWithAdaptTemplates());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public class ResourceConstants {
*/
public static final String CONFIG_PROJECT_NAME = "CobiGen_Templates";

/**
* Generator Configuration Project Name of template-sets
*/
public static final String TEMPLATE_SETS_CONFIG_PROJECT_NAME = "template-sets";

}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static File getTemplatesDirectory() {
*
* @return the templateDirectory
*/
private static File getTemplateSetDirectory() {
public static File getTemplateSetDirectory() {

return CobiGenPaths.getTemplateSetsFolderPath().toFile();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,52 +53,68 @@ public Object execute(ExecutionEvent event) throws ExecutionException {

MDC.put(InfrastructureConstants.CORRELATION_ID, UUID.randomUUID().toString());
IProject generatorProj = ResourcesPlugin.getWorkspace().getRoot().getProject(ResourceConstants.CONFIG_PROJECT_NAME);
IProject generatorProjOfTempltesSets = ResourcesPlugin.getWorkspace().getRoot()
.getProject(ResourceConstants.TEMPLATE_SETS_CONFIG_PROJECT_NAME);

if (generatorProj.exists()) {
MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Info!", null,
"CobiGen_Templates folder is already imported, click on Update templates button to update with latest. ",
MessageDialog.INFORMATION, new String[] { "Ok" }, 1);
dialog.setBlockOnOpen(true);
dialog.open();
if (generatorProjOfTempltesSets.exists()) {

// 1. TODO import project, do not adapt(no need to extract the jar files)
}

else if (ResourcesPluginUtil.getTemplateSetDirectory().exists()) {
// 2.TODO donwloaded exists? first adapt the jar file (files), then import project to eclipse
// 3. TODO downloaded does not exists? update command must be executed. then go to 2.
// (step 3 can be ignored for now until the new template-sets are deployed online.)
//
} else {
MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Warning!", null,
"Clicking on ok button will override existing CobiGen_Templates in workspace.", MessageDialog.WARNING,
new String[] { "Ok", "Cancel" }, 1);
dialog.setBlockOnOpen(true);
int result = dialog.open();

if (result == 0) {
try {
String fileName = ResourcesPluginUtil.getJarPath(true);
if (fileName.equals("")) {
result = createUpdateTemplatesDialog();
if (result == 1) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning",
"Templates have not been found, please download them!");
throw new NullPointerException("Templates have not been found!");
} else {
fileName = ResourcesPluginUtil.downloadJar(true);
}
if (generatorProj.exists()) {
MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Info!", null,
"CobiGen_Templates folder is already imported, click on Update templates button to update with latest. ",
MessageDialog.INFORMATION, new String[] { "Ok" }, 1);
dialog.setBlockOnOpen(true);
dialog.open();
} else {

MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Warning!", null,
"Clicking on ok button will override existing CobiGen_Templates in workspace.", MessageDialog.WARNING,
new String[] { "Ok", "Cancel" }, 1);
dialog.setBlockOnOpen(true);
int result = dialog.open();

if (result == 0) {
try {
String fileName = ResourcesPluginUtil.getJarPath(true);
if (fileName.equals("")) {
result = createUpdateTemplatesDialog();
if (result == 1) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning",
"Templates have not been found, please download them!");
throw new NullPointerException("Templates have not been found!");
} else {
fileName = ResourcesPluginUtil.downloadJar(true);
}

}
ResourcesPluginUtil.processJar(fileName);

importProjectIntoWorkspace();
dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Information", null,
"CobiGen_Templates folder is imported sucessfully", MessageDialog.INFORMATION, new String[] { "Ok" },
1);
dialog.setBlockOnOpen(true);
dialog.open();
} catch (MalformedURLException e) {
LOG.error("An exception with download url of maven central", e);
PlatformUIUtil.openErrorDialog("An exception with download url of maven central", e);
} catch (IOException e) {
LOG.error("An exception occurred while writing Jar files to .metadata folder", e);
PlatformUIUtil.openErrorDialog("An exception occurred while writing Jar files to .metadata folder", e);
} catch (Throwable e) {
ExceptionHandler.handle(e, HandlerUtil.getActiveShell(event));
}
ResourcesPluginUtil.processJar(fileName);

importProjectIntoWorkspace();
dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Information", null,
"CobiGen_Templates folder is imported sucessfully", MessageDialog.INFORMATION, new String[] { "Ok" }, 1);
dialog.setBlockOnOpen(true);
dialog.open();
} catch (MalformedURLException e) {
LOG.error("An exception with download url of maven central", e);
PlatformUIUtil.openErrorDialog("An exception with download url of maven central", e);
} catch (IOException e) {
LOG.error("An exception occurred while writing Jar files to .metadata folder", e);
PlatformUIUtil.openErrorDialog("An exception occurred while writing Jar files to .metadata folder", e);
} catch (Throwable e) {
ExceptionHandler.handle(e, HandlerUtil.getActiveShell(event));
}
MDC.remove(InfrastructureConstants.CORRELATION_ID);
}
MDC.remove(InfrastructureConstants.CORRELATION_ID);
}
return null;

Expand Down

0 comments on commit 02d03d6

Please sign in to comment.