Skip to content

Commit

Permalink
Merge pull request #346 from phantomjinx/TEIIDDES-2156
Browse files Browse the repository at this point in the history
TEIIDDES-2156: Ensures eclipse builder is not stopped by runtime excepti...
  • Loading branch information
blafond committed May 15, 2014
2 parents adcf0ff + 1c78c6e commit fc2ae6a
Show file tree
Hide file tree
Showing 38 changed files with 762 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,4 @@ Assertion.contains_Collection=ASSERTION FAILED: expected collection to contain v
Assertion.contains_Map=ASSERTION FAILED: expected map to contain key, but it did not

ReflectionHelper.errorConstructing=Unable to create a ReflectionHelper instance with a null target class.
OperationUtil.performErrMsg=An operation failure occurred.
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,18 @@ public static File copy(final File fromFile, final File destDirectory, final boo
/**
* @param source
* @param destination
* @throws Exception
*/
public static void copy(final File source, final OutputStream destination) {
public static void copy(final File source, final OutputStream destination) throws Exception {
OperationUtil.perform(new UnreliableCopy(source, destination));
}

/**
* @param source
* @param destination
* @throws Exception
*/
public static void copy(final InputStream source, final File destination) {
public static void copy(final InputStream source, final File destination) throws Exception {
OperationUtil.perform(new UnreliableCopy(source, destination));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.teiid.core.designer.util;

import org.teiid.core.designer.CoreModelerPlugin;

/**
*
Expand All @@ -16,7 +15,7 @@
*/
public final class OperationUtil {

public static <T> T perform( final ReturningUnreliable<T> unreliable ) {
public static <T> T perform( final ReturningUnreliable<T> unreliable ) throws Exception {
Throwable significantError = null;
try {
return unreliable.tryToDo();
Expand All @@ -29,12 +28,14 @@ public static <T> T perform( final ReturningUnreliable<T> unreliable ) {
} catch (final Throwable error) {
if (significantError == null) significantError = error;
}
if (significantError != null) throw CoreModelerPlugin.toRuntimeException(significantError);

if (significantError != null)
throw new Exception(significantError);
}
return null; // Unreachable
}

public static void perform( final Unreliable unreliable ) {
public static void perform( final Unreliable unreliable ) throws Exception {
Throwable significantError = null;
try {
unreliable.tryToDo();
Expand All @@ -47,8 +48,10 @@ public static void perform( final Unreliable unreliable ) {
} catch (final Throwable error) {
if (significantError == null) significantError = error;
}
if (significantError != null) throw CoreModelerPlugin.toRuntimeException(significantError);
}

if (significantError != null)
throw new Exception(significantError);
}

private OperationUtil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.io.File;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import org.teiid.core.designer.util.FileUtils.UnreliableCopy;

/**
Expand All @@ -22,7 +21,7 @@ public final class ZipUtil {

public static void copy( final File source,
final ZipEntry entry,
final ZipOutputStream destination ) {
final ZipOutputStream destination ) throws Exception {
OperationUtil.perform(new UnreliableCopy(source, destination) {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package org.teiid.designer.advisor.ui.dialogs;

import java.util.Properties;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -44,6 +43,7 @@
import org.teiid.designer.ui.common.widget.Label;
import org.teiid.designer.ui.explorer.ModelExplorerContentProvider;
import org.teiid.designer.ui.explorer.ModelExplorerLabelProvider;
import org.teiid.designer.ui.util.ErrorHandler;
import org.teiid.designer.ui.viewsupport.DesignerProperties;
import org.teiid.designer.ui.viewsupport.ModelWorkspaceDialog;
import org.teiid.designer.ui.viewsupport.SingleProjectFilter;
Expand Down Expand Up @@ -206,13 +206,20 @@ private void updateState() {
setErrorMessage(Messages.GenerateRestWarDialog_noVdbError);
return;
}

if( !GenerateRestWarAction.isRestWarVdb((IFile)this.selectedVdb) ) {
getButton(OK).setEnabled(false);
setErrorMessage(Messages.GenerateRestWarDialog_noRestProceduresInVdbError);
return;
}


boolean restWarVdb = false;
try {
restWarVdb = GenerateRestWarAction.isRestWarVdb((IFile)this.selectedVdb);
} catch (Exception ex) {
ErrorHandler.toExceptionDialog(ex);
restWarVdb = false;
}

if (!restWarVdb) {
getButton(OK).setEnabled(false);
setErrorMessage(Messages.GenerateRestWarDialog_noRestProceduresInVdbError);
return;
}

getButton(OK).setEnabled(true);
setErrorMessage(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean preProcess(RefactorType refactorType, IResource refactoredResourc
}

@Override
public void postProcess(RefactorType refactorType, IResource refactoredResource) {
public void postProcess(RefactorType refactorType, IResource refactoredResource) throws Exception {
// Nothing to do
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public enum RefactorType {
*
* @param refactorType
* @param refactoredResource
* @throws Exception
*/
void postProcess(RefactorType refactorType, final IResource refactoredResource);
void postProcess(RefactorType refactorType, final IResource refactoredResource) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ public static boolean preProcess(RefactorType refactorType, final IResource refa
/**
* @param refactorType type of refactoring
* @param refactoredResource the refactored resource
* @throws Exception
*/
public static void postProcess(RefactorType refactorType, final IResource refactoredResource) {
public static void postProcess(RefactorType refactorType, final IResource refactoredResource) throws Exception {
if( !handlersLoaded ) {
loadExtensions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
Expand Down Expand Up @@ -54,7 +53,7 @@ public class DdlImportDifferencesPage extends WizardPage implements IPersistentW

private static final int PANEL_GRID_SPAN = 3;

private final DdlImporter importer;
final DdlImporter importer;
private Composite stackPanel;
private Composite differencesPanel;
private Composite parseErrorPanel;
Expand Down Expand Up @@ -211,75 +210,97 @@ public void setVisible( final boolean visible ) {
super.setVisible(visible);

// If the page is being shown, import the DDL and generate the difference report
if(visible) {
// Perform the DDL Import
try {
new ProgressMonitorDialog(getShell()).run(true, true, new IRunnableWithProgress() {

@Override
public void run( final IProgressMonitor monitor ) {
monitor.beginTask(DdlImporterUiI18n.IMPORTING_DDL_MSG, 100);
importer.importDdl(monitor, 100);
monitor.done();
}
});
} catch (Exception ex) {
DdlImporterUiPlugin.UTIL.log(IStatus.ERROR,ex,DdlImporterUiI18n.DIFFERENCE_PAGE_DDLIMPORT_ERROR_MSG);
importer.addProgressMessage(DdlImporterUiI18n.DIFFERENCE_PAGE_DDLIMPORT_ERROR_MSG);
}

// Hard Failure (eg parse error) will show the error page
if(importer.hasParseError()) {
this.stackLayout.topControl = parseErrorPanel;
this.setTitle(DdlImporterUiI18n.DIFFERENCE_PAGE_PARSE_ERROR_TITLE);

this.ddlContentsArea.setText(importer.getDdlString());
String parseErrorMessage = importer.getParseErrorMessage();
// Get the offSet of the error if set
int offset = importer.getParseErrorIndex();
// Highlight the problem line if possible
if(offset>-1) {
StyledText styledText = ddlContentsArea.getTextWidget();
int line = styledText.getLineAtOffset(offset);
if(line>-1) {
int startIndx = styledText.getOffsetAtLine(line);
int endIndx = styledText.getOffsetAtLine(line+1);
styledText.setSelection(startIndx, endIndx);
}
}
String msg = I18n.format(DdlImporterUiI18n.DIFFERENCE_PAGE_PARSE_ERROR_MSG,parseErrorMessage);
setErrorMessage(msg);

importer.undoImport();
// Show differences page
} else {
this.stackLayout.topControl = differencesPanel;
this.setTitle(DdlImporterUiI18n.DIFFERENCE_PAGE_TITLE);

// Set the checkbox tree roots (create,delete,update)
List<OperationList> rootList = new ArrayList<OperationList>();
DifferenceReport diffReport = this.importer.getDifferenceReport();
if(diffReport!=null) {
OperationList createObjs = this.importer.getDifferenceReport().getObjectsToCreate();
OperationList deleteObjs = this.importer.getDifferenceReport().getObjectsToDelete();
OperationList updateObjs = this.importer.getDifferenceReport().getObjectsToUpdate();
if(!createObjs.getList().isEmpty()) rootList.add(createObjs);
if(!deleteObjs.getList().isEmpty()) rootList.add(deleteObjs);
if(!updateObjs.getList().isEmpty()) rootList.add(updateObjs);
}
this.treeViewer.setInput(rootList);
this.treeViewer.expandToLevel(2);
this.setAllNodesSelected(true);

List<String> progressMessages = this.importer.getAllMessages();
messagesList.setItems(progressMessages.toArray(new String[progressMessages.size()]));

validate();
}

this.stackPanel.layout();
if(! visible)
return;

// Perform the DDL Import
final Exception importException[] = new Exception[1];
try {
new ProgressMonitorDialog(getShell()).run(true, true, new IRunnableWithProgress() {

@Override
public void run(final IProgressMonitor monitor) {
monitor.beginTask(DdlImporterUiI18n.IMPORTING_DDL_MSG, 100);
try {
importer.importDdl(monitor, 100);
} catch (Exception ex) {
importException[0] = ex;
}
monitor.done();
}
});

if (importException[0] != null)
throw importException[0];

} catch (Exception ex) {
String msg = I18n.format(DdlImporterUiI18n.DIFFERENCE_PAGE_DDLIMPORT_ERROR_MSG, ex.getLocalizedMessage());
DdlImporterUiPlugin.UTIL.log(IStatus.ERROR, ex, msg);
importer.addProgressMessage(msg);
}

// Hard Failure (eg parse error) will show the error page
if (importException[0] != null || importer.hasParseError()) {
String title = null;
String msg = null;
this.stackLayout.topControl = parseErrorPanel;
this.ddlContentsArea.setText(importer.getDdlString());

if (importException[0] != null) {
title = DdlImporterUiI18n.DIFFERENCE_PAGE_GENERAL_ERROR_TITLE;
msg = I18n.format(DdlImporterUiI18n.DIFFERENCE_PAGE_DDLIMPORT_ERROR_MSG, importException[0].getLocalizedMessage());

} else if (importer.hasParseError()) {
title = DdlImporterUiI18n.DIFFERENCE_PAGE_PARSE_ERROR_TITLE;
String parseErrorMessage = importer.getParseErrorMessage();
// Get the offSet of the error if set
int offset = importer.getParseErrorIndex();
// Highlight the problem line if possible
if (offset > -1) {
StyledText styledText = ddlContentsArea.getTextWidget();
int line = styledText.getLineAtOffset(offset);
if (line > -1) {
int startIndx = styledText.getOffsetAtLine(line);
int endIndx = styledText.getOffsetAtLine(line + 1);
styledText.setSelection(startIndx, endIndx);
}
}
msg = I18n.format(DdlImporterUiI18n.DIFFERENCE_PAGE_PARSE_ERROR_MSG, parseErrorMessage);
}

setErrorMessage(msg);
importer.undoImport();
this.setTitle(title);
// Show differences page
} else {
this.stackLayout.topControl = differencesPanel;
this.setTitle(DdlImporterUiI18n.DIFFERENCE_PAGE_TITLE);

// Set the checkbox tree roots (create,delete,update)
List<OperationList> rootList = new ArrayList<OperationList>();
DifferenceReport diffReport = this.importer.getDifferenceReport();
if (diffReport != null) {
OperationList createObjs = this.importer.getDifferenceReport().getObjectsToCreate();
OperationList deleteObjs = this.importer.getDifferenceReport().getObjectsToDelete();
OperationList updateObjs = this.importer.getDifferenceReport().getObjectsToUpdate();
if (!createObjs.getList().isEmpty())
rootList.add(createObjs);
if (!deleteObjs.getList().isEmpty())
rootList.add(deleteObjs);
if (!updateObjs.getList().isEmpty())
rootList.add(updateObjs);
}
this.treeViewer.setInput(rootList);
this.treeViewer.expandToLevel(2);
this.setAllNodesSelected(true);

List<String> progressMessages = this.importer.getAllMessages();
messagesList.setItems(progressMessages.toArray(new String[progressMessages.size()]));

validate();
}

this.stackPanel.layout();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class DdlImporterUiI18n {
static final String DIFFERENCE_PAGE_IMPORT_TREE_GROUP_TITLE = i18n("differencePage.importTreeGroupTitle"); //$NON-NLS-1$
static final String DIFFERENCE_PAGE_IMPORT_MESSAGES_GROUP_TITLE = i18n("differencePage.importMessagesGroupTitle"); //$NON-NLS-1$
static final String DIFFERENCE_PAGE_PARSE_ERROR_DDL_GROUP_TITLE = i18n("differencePage.parseErrorDDLGroupTitle"); //$NON-NLS-1$
static final String DIFFERENCE_PAGE_GENERAL_ERROR_TITLE = i18n("differencePage.generalErrorTitle"); //$NON-NLS-1$
static final String DIFFERENCE_PAGE_PARSE_ERROR_TITLE = i18n("differencePage.parseErrorTitle"); //$NON-NLS-1$
static final String DIFFERENCE_PAGE_DDLIMPORT_ERROR_MSG = i18n("differencePage.ddlImportErrorMsg"); //$NON-NLS-1$
static final String DIFFERENCE_PAGE_PARSE_ERROR_MSG = i18n("differencePage.parseErrorMsg"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ differencePage.description = Select the items to apply, then click 'Finish'.
differencePage.importTreeGroupTitle = Items for Import
differencePage.importMessagesGroupTitle = Import Messages
differencePage.parseErrorDDLGroupTitle = DDL Contents
differencePage.generalErrorTitle = DDL Failed to Import
differencePage.parseErrorTitle = DDL Failed to Parse
differencePage.ddlImportErrorMsg = Error encountered while importing the DDL
differencePage.parseErrorMsg = The DDL failed to parse with message: "{0}". \n - The problem line is highlighted below (if found).
differencePage.ddlImportErrorMsg = Error encountered while importing the DDL\: "{0}"
differencePage.createListLabel = Objects to Create
differencePage.deleteListLabel = Objects to Delete
differencePage.updateListLabel = Objects to Update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.io.File;
import java.io.FileReader;
import java.util.List;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -85,8 +84,9 @@ public String ddlFileName() {
/**
* @param monitor
* @param totalWork
* @throws Exception
*/
public void importDdl(final IProgressMonitor monitor, final int totalWork ) {
public void importDdl(final IProgressMonitor monitor, final int totalWork ) throws Exception {
OperationUtil.perform(new Unreliable() {

private FileReader reader = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ static boolean shouldAutoCreateDataSource() {
PreferenceConstants.AUTO_CREATE_DATA_SOURCE_DEFAULT);
}

private static void createVdbDataSource(Object vdbOrVdbFile, String displayName, String jndiName) {
private void createVdbDataSource(Object vdbOrVdbFile, String displayName, String jndiName) throws Exception {
Vdb vdb = ((vdbOrVdbFile instanceof IFile) ? new Vdb((IFile) vdbOrVdbFile, null) : (Vdb) vdbOrVdbFile);
ITeiidServer teiidServer = getServerManager().getDefaultServer();
String vdbName = vdb.getFile().getFullPath().removeFileExtension().lastSegment();
Expand Down

0 comments on commit fc2ae6a

Please sign in to comment.