1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

improve error handling in order to determine why some unit tests are failing on overnight build

This commit is contained in:
Andrew Ferguson 2007-06-18 12:50:24 +00:00
parent eecd9b3834
commit 38595a611f
13 changed files with 129 additions and 97 deletions

View file

@ -21,7 +21,7 @@ import junit.framework.TestSuite;
* @since 4.0
*/
public class AllTemplateEngineTests extends TestSuite{
public class AllTemplateEngineTests extends TestSuite {
public static void main(String[] args) {
junit.swingui.TestRunner.run(AllTemplateEngineTests.class);

View file

@ -13,11 +13,10 @@ package org.eclipse.cdt.core.tests.templateengine;
import java.io.File;
import java.util.Map;
import junit.framework.TestCase;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.templateengine.TemplateCore;
import org.eclipse.cdt.core.templateengine.TemplateEngine;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@ -28,7 +27,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
public class TestProcesses extends TestCase {
public class TestProcesses extends BaseTestCase {
private static final String workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toOSString();
private static final String PROJECT_NAME = "TemplateEngineTestsProject"; //$NON-NLS-1$

View file

@ -15,16 +15,15 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
import org.eclipse.cdt.core.templateengine.SharedDefaults;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
/**
* Executes all the test cases of SharedDefaults backend functionality
*/
public class TestSharedDefaults extends TestCase {
public class TestSharedDefaults extends BaseTestCase {
private SharedDefaults sharedDefaults;
/*

View file

@ -10,14 +10,13 @@
*******************************************************************************/
package org.eclipse.cdt.core.tests.templateengine;
import junit.framework.TestCase;
import org.eclipse.cdt.core.templateengine.TemplateCore;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
/**
* Test the functionality of Tempalte Class.
*/
public class TestTemplateCore extends TestCase {
public class TestTemplateCore extends BaseTestCase {
public TemplateCore[] templates = null;

View file

@ -10,14 +10,13 @@
*******************************************************************************/
package org.eclipse.cdt.core.tests.templateengine;
import junit.framework.TestCase;
import org.eclipse.cdt.core.templateengine.TemplateEngine;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
/**
* Test the functionality of TemplateEngine.
*/
public class TestTemplateEngine extends TestCase {
public class TestTemplateEngine extends BaseTestCase {
TemplateEngine templateEngine = null;

View file

@ -13,16 +13,15 @@ package org.eclipse.cdt.core.tests.templateengine;
import java.util.Iterator;
import java.util.Map;
import junit.framework.TestCase;
import org.eclipse.cdt.core.templateengine.TemplateCore;
import org.eclipse.cdt.core.templateengine.TemplateDescriptor;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
/**
* Test the functionality of the ValueStore class.
*/
public class TestValueStore extends TestCase {
public class TestValueStore extends BaseTestCase {
/**

View file

@ -11,6 +11,8 @@
package org.eclipse.cdt.core.templateengine;
import java.io.IOException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
@ -20,15 +22,12 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.cdt.core.templateengine.process.TemplateProcessHandler;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.xml.sax.SAXException;
/**
@ -66,17 +65,19 @@ public class TemplateCore {
private boolean fireDirtyEvents;
/**
* Constructor
*
* @param templateInfo
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
* @param templateInfo may not be null
* @throws TemplateInitializationException
*/
protected TemplateCore(TemplateInfo templateInfo) throws IOException, SAXException, ParserConfigurationException {
protected TemplateCore(TemplateInfo templateInfo) throws TemplateInitializationException {
this.templateInfo = templateInfo;
templateDescriptor = new TemplateDescriptor(TemplateEngineHelper.getTemplateResourceURL(templateInfo.getPluginId(), templateInfo.getTemplatePath()), templateInfo.getPluginId());
URL descriptorURL;
try {
descriptorURL= TemplateEngineHelper.getTemplateResourceURL(templateInfo.getPluginId(), templateInfo.getTemplatePath());
} catch(IOException ioe) {
String msg= MessageFormat.format(TemplateEngineMessages.getString("TemplateCore.InitFailed"), new Object[]{templateInfo.getTemplatePath()}); //$NON-NLS-1$
throw new TemplateInitializationException(msg);
}
templateDescriptor = new TemplateDescriptor(descriptorURL, templateInfo.getPluginId());
valueStore = new ValueStore/*<String, String>*/(this);
valueStore.putAll(templateDescriptor.getTemplateDefaults(templateDescriptor.getRootElement()));
valueStore.putAll(TemplateEngine.getDefault().getSharedDefaults());
@ -221,14 +222,10 @@ public class TemplateCore {
* Gets the Template
*
* @param templateInfo
* @throws IOException
* @throws ProcessFailureException
* @throws SAXException
* @throws ParserConfigurationException
*
* @throws TemplateInitializationException
* @since 4.0
*/
public static TemplateCore getTemplate(TemplateInfo templateInfo) throws IOException, ProcessFailureException, SAXException, ParserConfigurationException {
public static TemplateCore getTemplate(TemplateInfo templateInfo) throws TemplateInitializationException {
synchronized (templateCache) {
TemplateCore template = (TemplateCore) templateCache.get(templateInfo);
if (template == null) {

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.core.templateengine;
import java.io.IOException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -46,15 +47,22 @@ public class TemplateDescriptor {
/**
* Constructor which construct the Document based the URL
* @param descriptorURL
* @throws SAXException
* @throws IOException
* @throws ParserConfigurationException
* @throws TemplateInitializationException
*/
public TemplateDescriptor(URL descriptorURL, String id) throws SAXException, IOException, ParserConfigurationException {
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(descriptorURL.openStream());
rootElement = document.getDocumentElement();
persistVector = new ArrayList/*<String>*/();
pluginId = id;
public TemplateDescriptor(URL descriptorURL, String pluginId) throws TemplateInitializationException {
String msg= MessageFormat.format(TemplateEngineMessages.getString("TemplateCore.InitFailed"), new Object[]{descriptorURL}); //$NON-NLS-1$
try {
this.document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(descriptorURL.openStream());
} catch(ParserConfigurationException pce) {
throw new TemplateInitializationException(msg, pce);
} catch(IOException ioe) {
throw new TemplateInitializationException(msg, ioe);
} catch(SAXException se) {
throw new TemplateInitializationException(msg, se);
}
this.rootElement = document.getDocumentElement();
this.persistVector = new ArrayList/*<String>*/();
this.pluginId = pluginId;
}
/**

View file

@ -66,46 +66,54 @@ public class TemplateEngine {
}
/**
* get All the templates, no filtering is done.
*
* @return
* Returns all the TemplateCore objects, no filtering is done.
*/
public TemplateCore[] getTemplates() {
TemplateInfo[] templateInfoArray = getTemplateInfos();
List/*<Template>*/ templatesList = new ArrayList/*<Template>*/();
List/*<TemplateCore>*/ tcores = new ArrayList/*<TemplateCore>*/();
for (int i=0; i<templateInfoArray.length; i++) {
TemplateInfo info = templateInfoArray[i];
try {
templatesList.add(TemplateCore.getTemplate(info));
} catch (Exception e) {
tcores.add(TemplateCore.getTemplate(info));
} catch (TemplateInitializationException e) {
CCorePlugin.log(e);
}
}
return (TemplateCore[]) templatesList.toArray(new TemplateCore[templatesList.size()]);
return (TemplateCore[]) tcores.toArray(new TemplateCore[tcores.size()]);
}
/**
* This method will be called by Contianer UIs (Wizard, PropertyPage,
* PreferencePage). Create a Template instance, update the ValueStore, with
* SharedDefaults. This method calls the getTemplate(URL), after getting URL
* for the given String TemplateDescriptor.
*
* @param StringTemplateDescriptor,
* TemplateDescriptor name.
* @throws IOException
* Returns the TemplateCore for the first template defined for the specified parameters, or null
* if no such definition exists, or if there is an error initializing the template (the error will
* be logged).
* @param projectType may not be null
* @param toolChain may be null to indicate no tool-chain filtering
* @param usageFilter a regex in java.util.regex.Pattern format, may be null to indicate no filtering
* @see java.util.regex.Pattern
* @return
*/
public TemplateCore getFirstTemplate(String projectType, String toolChain, String usageFilter) {
TemplateInfo[] infos= getTemplateInfos(projectType, toolChain, usageFilter);
if(infos.length>0) {
try {
return TemplateCore.getTemplate(infos[0]);
} catch(TemplateInitializationException tie) {
CCorePlugin.log(tie);
}
}
return null;
}
/**
* Equivalent to calling the overloaded version of getFirstTemplate with null arguments for
* toolChain and usageFilter.
* @see TemplateEngine#getFirstTemplate(String, String, String)
* @return the first TemplateCore object registered, or null if this does not exist
*/
public TemplateCore getFirstTemplate(String projectType) {
return getFirstTemplate(projectType, null, null);
}
public TemplateCore getFirstTemplate(String projectType, String toolChain, String usageFilter) {
try {
return TemplateCore.getTemplate(getTemplateInfos(projectType, toolChain, usageFilter)[0]);
} catch (Exception e) {
// ignore
}
return null;
}
/**
* This method will be called by Contianer UIs (Wizard, PropertyPage,
* PreferencePage). Create a Template instance, update the ValueStore, with
@ -119,7 +127,8 @@ public class TemplateEngine {
TemplateInfo info = templateInfoArray[i];
try {
templatesList.add(TemplateCore.getTemplate(info));
} catch (Exception e) {
} catch (TemplateInitializationException tie) {
CCorePlugin.log(tie);
}
}
return (TemplateCore[]) templatesList.toArray(new TemplateCore[templatesList.size()]);
@ -273,6 +282,11 @@ public class TemplateEngine {
/**
* Gets an array of template info objects matching the criteria passed as params.
* @param projectType may not be null
* @param toolChain may be null to indicate no tool-chain
* @param usageFilter a usage string which is matched against the filter from the template, may be null
* to indicate no usage filtering
* @return an array of template infos (never null)
*/
public TemplateInfo[] getTemplateInfos(String projectType, String toolChain, String usageFilter) {
List/*<TemplateInfo>*/ templateInfoList = (List/*<TemplateInfo*/) templateInfoMap.get(projectType.trim());
@ -315,6 +329,10 @@ public class TemplateEngine {
return getTemplateInfos(projectType, null, null);
}
/**
* Returns all TemplateInfo objects known to the TemplateEngine
* @return
*/
public TemplateInfo[] getTemplateInfos() {
List/*<TemplateInfo>*/ infoList = new ArrayList/*<TemplateInfo>*/();
for (Iterator i = templateInfoMap.values().iterator(); i.hasNext();) {

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Limited and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.templateengine;
/**
* Represents an exception in initializing a template. Typically this will be caused
* by an I/O or XML parsing failure.
*/
public class TemplateInitializationException extends Exception {
private static final long serialVersionUID = -8138820172406447119L;
public TemplateInitializationException() {
super();
}
public TemplateInitializationException(String message) {
super(message);
}
public TemplateInitializationException(String message, Throwable cause) {
super(message);
initCause(cause);
}
}

View file

@ -10,6 +10,7 @@
###############################################################################
TemplateEngine.internalError=Internal Error:
TemplateCore.InitFailed=Failed to initialize: {0}
TemplateEngine.templateEngine=Template Engine
ProjectCreatedActions.InsufficientInformation=Insufficient information to create new project

View file

@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.ui.templateengine;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
@ -18,8 +17,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@ -28,12 +25,12 @@ import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.ui.IWorkbenchWizard;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import org.eclipse.cdt.core.templateengine.TemplateCore;
import org.eclipse.cdt.core.templateengine.TemplateDescriptor;
import org.eclipse.cdt.core.templateengine.TemplateEngine;
import org.eclipse.cdt.core.templateengine.TemplateInfo;
import org.eclipse.cdt.core.templateengine.TemplateInitializationException;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.templateengine.pages.UIPagesProvider;
@ -56,7 +53,7 @@ public class Template extends TemplateCore {
private UIPagesProvider uiPagesProvider;
private Map/*<String, UIWizardPage>*/ pageMap;
public Template(TemplateInfo templateInfo) throws IOException, ProcessFailureException, SAXException, ParserConfigurationException {
public Template(TemplateInfo templateInfo) throws TemplateInitializationException {
super(templateInfo);
templateDescriptor = getTemplateDescriptor();
uiElementTreeBuilderManager = new UIElementTreeBuilderManager(new UIElementTreeBuilderHelper(templateDescriptor, templateInfo));

View file

@ -13,10 +13,10 @@ package org.eclipse.cdt.ui.templateengine;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.templateengine.TemplateCore;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.templateengine.TemplateEngine;
import org.eclipse.cdt.core.templateengine.TemplateInfo;
import org.eclipse.cdt.core.templateengine.TemplateInitializationException;
/**
* TemplateEngine is implemented as a Singleton. TemplateEngine is responsible for
@ -30,7 +30,7 @@ public class TemplateEngineUI {
/**
* static reference to the Singleton TemplateEngine instance.
*/
private static TemplateEngineUI TEMPLATE_ENGINE_UI = new TemplateEngineUI();
private static final TemplateEngineUI TEMPLATE_ENGINE_UI = new TemplateEngineUI();
private TemplateEngineUI() {
}
@ -39,25 +39,6 @@ public class TemplateEngineUI {
return TEMPLATE_ENGINE_UI;
}
/**
* This method will be called by Contianer UIs (Wizard, PropertyPage,
* PreferencePage). Create a Template instance, update the ValueStore, with
* SharedDefaults. This method calls the getTemplate(URL), after getting URL
* for the given String TemplateDescriptor.
*/
public TemplateCore getFirstTemplate(String projectType) {
return getFirstTemplate(projectType, null, null);
}
public TemplateCore getFirstTemplate(String projectType, String toolChain, String usageFilter) {
try {
return new Template(TemplateEngine.getDefault().getTemplateInfos(projectType, toolChain, usageFilter)[0]);
} catch (Exception e) {
// ignore
}
return null;
}
public Template[] getTemplates(String projectType, String toolChain, String usageFilter) {
TemplateInfo[] templateInfoArray = TemplateEngine.getDefault().getTemplateInfos(projectType, toolChain, usageFilter);
List/*<Template>*/ templatesList = new ArrayList/*<Template>*/();
@ -65,7 +46,8 @@ public class TemplateEngineUI {
TemplateInfo info = templateInfoArray[i];
try {
templatesList.add(new Template(info));
} catch (Exception e) {
} catch (TemplateInitializationException tie) {
CCorePlugin.log(tie);
}
}
return (Template[]) templatesList.toArray(new Template[templatesList.size()]);
@ -80,7 +62,7 @@ public class TemplateEngineUI {
}
/**
* get All the templates, no filtering is done.
* Returns all the templates, no filtering is done.
*/
public Template[] getTemplates() {
TemplateInfo[] templateInfoArray = TemplateEngine.getDefault().getTemplateInfos();
@ -88,7 +70,8 @@ public class TemplateEngineUI {
for (int i=0; i<templateInfoArray.length; i++) {
try {
templatesList.add(new Template(templateInfoArray[i]));
} catch (Exception e) {
} catch (TemplateInitializationException tie) {
CCorePlugin.log(tie);
}
}