Commit 84417ca9 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Fixed syntax/semantic check to use compiler flags even if project root is not selected (#484)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 0c52f3f6
......@@ -12,11 +12,15 @@ import java.util.List;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.common.path.PathConverter;
import org.eclipse.titan.designer.consoles.TITANConsole;
......@@ -30,11 +34,14 @@ import org.eclipse.titan.designer.productUtilities.ProductConstants;
import org.eclipse.titan.designer.properties.data.MakefileCreationData;
import org.eclipse.titan.designer.properties.data.ProjectBuildPropertyData;
import org.eclipse.titan.designer.properties.data.TITANFlagsOptionsData;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
/**
* This action invokes the semantic checking of the selected files.
*
* @author Kristof Szabados
* @author Miklos Magyari
*/
public final class CheckSemantic extends ExternalTitanAction {
private static final String JOB_TITLE = "Semantic check";
......@@ -104,22 +111,28 @@ public final class CheckSemantic extends ExternalTitanAction {
command.add(PathConverter.convert(getCompilerPath().toOSString(), reportDebugInformation, output));
TITANDebugConsole.println(output);
boolean useRuntime2 = false;
try {
if ("true".equals(project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.FUNCTIONTESTRUNTIME_PROPERTY)))) {
useRuntime2 = true;
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while reading persistent property", e);
}
// If a single project is selected used than use it's attributes used to generate the Makefile, otherwise use the general preferences.
if (singleSelectedProject == null) {
TITANConsole.println("Using the general preferences to do the external semantic check");
command.add('-' + SEMANTIC_CHECK_FLAG + getTITANActionFlags());
final IProject proj = getSelectionProject();
if (proj != null) {
final String flags = TITANFlagsOptionsData.getTITANFlags(proj, useRuntime2);
command.add(" " + flags);
}
} else {
TITANConsole.println("Using the project properties to do the external semantic check");
boolean useRuntime2 = false;
try {
if ("true".equals(project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER,
MakefileCreationData.FUNCTIONTESTRUNTIME_PROPERTY)))) {
useRuntime2 = true;
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("Error while reading persistent property", e);
}
final String flags = TITANFlagsOptionsData.getTITANFlags(singleSelectedProject, useRuntime2);
command.add('-' + SEMANTIC_CHECK_FLAG + " " + flags);
}
......
......@@ -12,6 +12,7 @@ import java.util.List;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
......@@ -24,11 +25,13 @@ import org.eclipse.titan.designer.license.LicenseValidator;
import org.eclipse.titan.designer.preferences.PreferenceConstantValues;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.titan.designer.productUtilities.ProductConstants;
import org.eclipse.titan.designer.properties.data.TITANFlagsOptionsData;
/**
* This action invokes the syntactic checking of the selected files.
*
* @author Kristof Szabados
* @author Miklos Magyari
*/
public final class CheckSyntax extends ExternalTitanAction {
private static final String JOB_TITLE = "Syntax check";
......@@ -98,6 +101,11 @@ public final class CheckSyntax extends ExternalTitanAction {
final StringBuilder output = new StringBuilder();
command.add(PathConverter.convert(getCompilerPath().toOSString(), reportDebugInformation, output));
TITANDebugConsole.println(output);
final IProject proj = getSelectionProject();
if (proj != null) {
final String flags = TITANFlagsOptionsData.getTITANFlags(proj, false);
command.add(" " + flags);
}
command.add('-' + SYNTAX_CHECK_FLAG + getTITANActionFlags());
for (final String filePath : files.keySet()) {
command.add('\'' + filePath + '\'');
......
......@@ -20,12 +20,15 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.GeneralConstants;
import org.eclipse.titan.designer.commonFilters.ResourceExclusionHelper;
......@@ -41,6 +44,7 @@ import org.eclipse.ui.PlatformUI;
* This action invokes an external TITAN job on a selection of files.
*
* @author Kristof Szabados
* @author Miklos Magyari
*/
public abstract class ExternalTitanAction extends AbstractHandler implements IWorkbenchWindowActionDelegate {
public static final String EXECUTION_FAILED = "execution failed";
......@@ -301,6 +305,23 @@ public abstract class ExternalTitanAction extends AbstractHandler implements IWo
protected String getExtensionPattern() {
return ".*";
}
/**
* Gets the project root of the currently selected item(s)
* @return
*/
protected IProject getSelectionProject() {
final IWorkbenchPage iwPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
selection = iwPage.getSelection();
if (selection instanceof TreeSelection) {
TreeSelection treeSelection = (TreeSelection)selection;
TreePath[] treePaths = treeSelection.getPaths();
TreePath treePath = treePaths[0];
Object projSegmentObj = treePath.getFirstSegment();
return (IProject) ((IAdaptable) projSegmentObj).getAdapter(IProject.class);
}
return null;
}
/**
* This method tells the action what the user has selected.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment