use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class InternalMakefileGenerator method generateMakefile.
/**
* Generates the Makefile for the project provided.
*
* @param project the project for which the Makefile should be
* generated.
*/
public void generateMakefile(final IProject project) {
if (Cygwin.isMissingInOSWin32()) {
ErrorReporter.logError(MISSING_CYGWIN);
return;
}
boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, false, null);
this.project = project;
this.projectLocation = project.getLocation().toOSString();
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
// If not yet analyzed do it now (this will also analyze all
// referenced projects.)
projectSourceParser.makefileCreatingAnalyzeAll();
try {
setParameters();
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
return;
}
boolean centralStorage = false;
try {
MakefileGeneratorVisitor visitor = new MakefileGeneratorVisitor(this, project);
project.accept(visitor);
centralStorage = !visitor.getCentralStorages().isEmpty();
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
return;
}
List<IProject> reachableProjects = ProjectBasedBuilder.getProjectBasedBuilder(project).getAllReachableProjects();
boolean foundClosedProject = false;
for (IProject reachableProject : reachableProjects) {
if (!reachableProject.isAccessible()) {
final StringBuilder builder = new StringBuilder("The project `" + reachableProject.getName() + "' (reachable from project `" + project.getName() + "') is not accessible.");
final IProject[] referencingProjects = reachableProject.getReferencingProjects();
if (referencingProjects != null && referencingProjects.length > 0) {
builder.append(" The project `").append(reachableProject.getName()).append("' is referenced directly by");
for (IProject referencingProject : referencingProjects) {
builder.append(" `").append(referencingProject.getName()).append('\'');
}
}
ErrorReporter.logError(builder.toString());
foundClosedProject = true;
} else if (!reachableProject.equals(project)) {
centralStorage = true;
try {
reachableProject.accept(new MakefileGeneratorVisitor(this, reachableProject));
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
return;
}
}
}
if (foundClosedProject) {
ErrorReporter.parallelErrorDisplayInMessageDialog("Error during Makefile generation", "A makefile can not be generated for project " + project.getName() + "\n" + "Some of the projects referenced by it are not accessible.\n" + "Please check the error log for more details.");
return;
}
try {
codeSplittingMode = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, MakefileCreationData.CODE_SPLITTING_PROPERTY));
if (codeSplittingMode == null || GeneralConstants.NONE.equals(codeSplittingMode)) {
codeSplittingMode = GeneralConstants.NONE;
} else if (!GeneralConstants.TYPE.equals(codeSplittingMode)) {
try {
Integer.parseInt(codeSplittingMode);
} catch (NumberFormatException ex) {
ErrorReporter.logExceptionStackTrace(ex);
codeSplittingMode = GeneralConstants.NONE;
}
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
return;
}
// Add the Makefile to the other files, as it will belong there
// once we create it
OtherFileStruct otherFile = new OtherFileStruct(null, null, "Makefile");
otherFiles.add(otherFile);
if (!useAbsolutePathNames) {
convertDirsToRelative();
}
convertDirectories();
if (checkSpecialCharacters()) {
// generation must stop
return;
}
checkNamingConvention();
sortFiles();
StringBuilder contents = new StringBuilder();
contents.append("# This Makefile was generated by the TITAN Designer eclipse plug-in\n");
contents.append("# of the TTCN-3 Test executor version ").append(GeneralConstants.VERSION_STRING).append('\n');
contents.append("# for (").append(System.getProperty("user.name")).append('@');
try {
contents.append(InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
contents.append("unknown");
}
contents.append(") on ").append(new Date()).append("\n\n");
contents.append("# ").append(GeneralConstants.COPYRIGHT_STRING).append('\n');
contents.append('\n');
contents.append("# The following make commands are available:\n");
contents.append("# - make, make all ");
if (library) {
contents.append("Builds the library archive: '" + getLibraryName() + "'.\n");
} else {
contents.append("Builds the executable test suite.\n");
}
contents.append("# - make archive Archives all source files.\n");
contents.append("# - make check Checks the semantics of TTCN-3 and ASN.1 modules.\n");
contents.append("# - make clean Removes all generated files.\n");
contents.append("# - make port Generates port skeletons.\n");
contents.append("# - make compile Translates TTCN-3 and ASN.1 modules to C++.\n");
contents.append("# - make dep Creates/updates dependency list.\n");
contents.append("# - make executable Builds the executable test suite.\n");
contents.append("# - make library Builds the library archive: '" + getLibraryName() + "'.\n");
contents.append("# - make objects Builds the object files without linking the executable.\n");
if (dynamicLinking) {
contents.append("# - make shared_objects Builds the shared object files without linking the executable.\n");
}
if (preprocess) {
contents.append("# - make preprocess Preprocess TTCN-3 files.\n");
}
if (centralStorage) {
contents.append("# WARNING! This Makefile uses pre-compiled files from the following directories:\n");
for (BaseDirectoryStruct dir : baseDirectories) {
contents.append("# ").append(dir.name()).append('\n');
}
contents.append("# The executable tests will be consistent only if all directories use\n");
contents.append("# the same platform and the same version of TTCN-3 Test Executor and\n");
contents.append("# C++ compiler with the same command line switches.\n\n");
}
if (gnuMake) {
contents.append("# WARNING! This Makefile can be used with GNU make only.\n");
contents.append("# Other versions of make may report syntax errors in it.\n\n");
contents.append("#\n");
contents.append("# Do NOT touch this line...\n");
contents.append("#\n");
contents.append(".PHONY: all");
if (dynamicLinking) {
contents.append(" shared_objects");
}
contents.append(" executable library objects check port clean dep archive");
if (preprocess) {
contents.append(" preprocess");
}
contents.append("\n\n");
if (incrementalDependencyRefresh) {
contents.append(".SUFFIXES: .d\n\n");
}
}
contents.append("#\n");
contents.append("# Set these variables...\n");
contents.append("#\n");
contents.append('\n');
contents.append("# The path of your TTCN-3 Test Executor installation:\n");
contents.append("# Uncomment this line to override the environment variable.\n");
contents.append("# TTCN3_DIR =\n");
String platform = Platform.getOS();
String platformString = null;
if (Platform.OS_LINUX.equals(platform)) {
platformString = "LINUX";
} else if (Platform.OS_WIN32.equals(platform)) {
platformString = "WIN32";
} else if (Platform.OS_SOLARIS.equals(platform)) {
platformString = "SOLARIS";
// FIXME implement precise platform string
}
if (useCrossCompilation) {
contents.append("# TTCN3_TARGET_DIR = $(TTCN3_DIR)\n\n");
contents.append("# Your platform: (SOLARIS, SOLARIS8, LINUX, FREEBSD or WIN32)\n");
contents.append("PLATFORM = ").append(platformString).append("\n\n");
contents.append("# The path of your toolchain including the target triplet:\n");
contents.append("CROSSTOOL_DIR =\n\n");
contents.append("# Your C++ compiler:\n");
contents.append("# (if you change the platform, you may need to change the compiler)\n");
contents.append("CXX = g++\n\n");
} else {
contents.append('\n');
contents.append("# Your platform: (SOLARIS, SOLARIS8, LINUX, FREEBSD or WIN32)\n");
contents.append("PLATFORM = ").append(platformString).append("\n\n");
contents.append("# Your C++ compiler:\n");
contents.append("# (if you change the platform, you may need to change the compiler)\n");
String compilerName = CCompilerOptionsData.getCompilerName(project);
if (compilerName == null || compilerName.length() == 0) {
ErrorReporter.parallelErrorDisplayInMessageDialog("Errors detected during Makefile generation", "The C/C++ compiler tool is not set for the project " + project.getName() + " using g++ as default.");
compilerName = "g++";
}
contents.append("CXX = ").append(compilerName).append("\n\n");
}
if (incrementalDependencyRefresh) {
contents.append("# Flags for dependency generation\n");
// -xM1 for SunPro
contents.append("CXXDEPFLAGS := -MM\n\n");
}
if (preprocess) {
contents.append("# C preprocessor used for TTCN-3 files:\n");
String preprocessorName = TTCN3PreprocessorOptionsData.getPreprocessorName(project);
if (preprocessorName == null || preprocessorName.length() == 0) {
ErrorReporter.parallelErrorDisplayInMessageDialog("Errors detected during Makefile generation", "The preprocessor tool is not set for the project " + project.getName() + " using cpp as default.");
preprocessorName = "cpp";
}
contents.append("CPP = ").append(preprocessorName).append("\n\n");
}
contents.append("# Flags for the C++ preprocessor (and makedepend as well):\n");
contents.append("CPPFLAGS = -D$(PLATFORM) -I. -I$(TTCN3_DIR)/include");
if (useRuntime2) {
contents.append(" -DTITAN_RUNTIME_2");
}
MessageConsole debugConsole = TITANDebugConsole.getConsole();
for (IProject reachableProject : reachableProjects) {
String[] optionList = PreprocessorIncludedOptionsData.getPreprocessorIncludes(reachableProject);
if (optionList.length > 0) {
IPath location = reachableProject.getLocation();
if (location == null) {
ErrorReporter.logError("The project `" + reachableProject.getName() + "' is not located in the local file system. The extra include directories set for it will not be generated into the Makefile");
} else {
String tempProjectLocation = location.toOSString();
for (String temp : optionList) {
temp = TITANPathUtilities.resolvePathURIForMakefile(temp, tempProjectLocation, reportDebugInformation, debugConsole);
contents.append(" -I").append(temp);
}
}
}
}
for (IProject reachableProject : reachableProjects) {
String[] optionList = PreprocessorSymbolsOptionsData.getPreprocessorDefines(reachableProject);
for (String option : optionList) {
contents.append(" -D").append(option);
}
}
for (IProject reachableProject : reachableProjects) {
String[] optionList = PreprocessorSymbolsOptionsData.getPreprocessorUndefines(reachableProject);
for (String option : optionList) {
contents.append(" -U").append(option);
}
}
for (BaseDirectoryStruct dir : baseDirectories) {
contents.append(" -I").append(dir.name());
}
if (!usingSymbolicLinks) {
for (BaseDirectoryStruct dir : additionallyIncludedFolders) {
contents.append(" -I").append(dir.name());
}
}
contents.append("\n\n");
if (preprocess) {
contents.append("# Flags for preprocessing TTCN-3 files:\n");
contents.append("CPPFLAGS_TTCN3 = -I.");
for (BaseDirectoryStruct dir : baseDirectories) {
contents.append(" -I").append(dir.name());
}
if (!usingSymbolicLinks) {
for (BaseDirectoryStruct dir : additionallyIncludedFolders) {
contents.append(" -I").append(dir.name());
}
}
for (IProject reachableProject : reachableProjects) {
String[] optionList = PreprocessorIncludedOptionsData.getTTCN3PreprocessorIncludes(reachableProject);
if (optionList.length > 0) {
IPath location = reachableProject.getLocation();
if (location == null) {
ErrorReporter.logError("The project `" + reachableProject.getName() + "' is not located in the local file system. The extra preprocessor include directories set for it will not be generated into the Makefile");
} else {
String tempProjectLocation = location.toOSString();
for (String option : optionList) {
option = TITANPathUtilities.resolvePathURIForMakefile(option, tempProjectLocation, reportDebugInformation, debugConsole);
contents.append(" -I").append(option);
}
}
}
}
for (IProject reachableProject : reachableProjects) {
String[] optionList = PreprocessorSymbolsOptionsData.getTTCN3PreprocessorDefines(reachableProject);
for (String option : optionList) {
contents.append(" -D").append(option);
}
}
for (IProject reachableProject : reachableProjects) {
String[] optionList = PreprocessorSymbolsOptionsData.getTTCN3PreprocessorUndefines(reachableProject);
for (String option : optionList) {
contents.append(" -U").append(option);
}
}
contents.append("\n\n");
}
contents.append("# Flags for the C++ compiler:\n");
contents.append("CXXFLAGS = -Wall").append(COptimalizationOptionsData.getCxxOptimizationFlags(project));
if (dynamicLinking) {
// The extra space is not necessary here, hence the
// previous
// append() will add one to the end, but be consistent.
contents.append(" -fPIC");
}
contents.append("\n\n");
contents.append("# Flags for the linker:\n");
contents.append("LDFLAGS = ").append(useCrossCompilation ? "-L$(CROSSTOOL_DIR)/lib " : "");
contents.append(LinkerFlagsOptionsData.getLinkerFlags(project));
if (dynamicLinking) {
contents.append(" -fPIC");
}
contents.append("\n\n");
contents.append("ifeq ($(PLATFORM), WIN32)\n");
contents.append("# Silence linker warnings.\n");
contents.append("LDFLAGS += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc\n");
contents.append("endif\n\n");
contents.append("# Utility to create library files\n");
contents.append("AR = ar\n");
contents.append("ARFLAGS = \n\n");
contents.append("# Flags for the TTCN-3 and ASN.1 compiler:\n");
contents.append("# ").append(TITANFlagsOptionsData.getTITANFlagComments(project, useRuntime2)).append('\n');
contents.append("COMPILER_FLAGS = ").append(TITANFlagsOptionsData.getTITANFlags(project, useRuntime2)).append("\n\n");
contents.append("# Execution mode: ");
contents.append(useRuntime2 ? "function" : "load").append(" test runtime in ");
contents.append(singleMode ? "single" : "parallel").append(" mode");
contents.append(dynamicLinking ? " with dynamic linking" : "").append('\n');
contents.append("TTCN3_LIB = ttcn3");
if (useRuntime2) {
contents.append("-rt2");
}
if (!singleMode) {
contents.append("-parallel");
}
if (dynamicLinking) {
contents.append("-dynamic");
}
contents.append("\n\n");
contents.append("# The path of your OpenSSL installation:\n");
contents.append("# If you do not have your own one, leave it unchanged.\n");
String ttcn3Lib = useCrossCompilation ? "TARGET_" : "";
boolean externalLibrariesDisabled = LinkerLibrariesOptionsData.getExternalFoldersDisabled(project);
if (externalLibrariesDisabled) {
contents.append("# OPENSSL_DIR = $(TTCN3_").append(ttcn3Lib).append("DIR)\n\n");
} else {
contents.append("OPENSSL_DIR = $(TTCN3_").append(ttcn3Lib).append("DIR)\n\n");
}
contents.append("# The path of your libxml2 installation:\n");
contents.append("# If you do not have your own one, leave it unchanged.\n");
if (externalLibrariesDisabled) {
contents.append("# XMLDIR = $(TTCN3_").append(ttcn3Lib).append("DIR)\n\n");
} else {
contents.append("XMLDIR = $(TTCN3_").append(ttcn3Lib).append("DIR)\n\n");
}
contents.append("# Directory to store the archived source files:\n");
if (!gnuMake) {
contents.append("# Note: you can set any directory except ./archive\n");
}
contents.append("ARCHIVE_DIR = backup\n\n");
contents.append("#\n");
contents.append("# You may change these variables. Add your files if necessary...\n");
contents.append("#\n\n");
contents.append("# TTCN-3 modules of this project:\n");
contents.append("TTCN3_MODULES =");
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() == null || !centralStorage) {
if (usingSymbolicLinks) {
contents.append(' ').append(module.fileName());
} else {
contents.append(' ').append(module.getOriginalLocation());
}
}
}
if (preprocess) {
contents.append("\n\n");
contents.append("# TTCN-3 modules to preprocess:\n");
contents.append("TTCN3_PP_MODULES =");
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() == null || !centralStorage) {
if (usingSymbolicLinks) {
contents.append(' ').append(module.fileName());
} else {
contents.append(' ').append(module.getOriginalLocation());
}
}
}
}
if (centralStorage) {
contents.append("\n\n");
contents.append("# TTCN-3 modules used from central project(s):\n");
contents.append("BASE_TTCN3_MODULES =");
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() != null) {
if (allProjectsUseSymbolicLinks) {
contents.append(' ').append(module.fileName());
} else {
contents.append(' ').append(module.getOriginalLocation());
}
}
}
if (preprocess) {
contents.append("\n\n");
contents.append("# TTCN-3 modules to preprocess used from central project(s):\n");
contents.append("BASE_TTCN3_PP_MODULES =");
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() != null) {
if (allProjectsUseSymbolicLinks) {
contents.append(' ').append(module.fileName());
} else {
contents.append(' ').append(module.getOriginalLocation());
}
}
}
}
}
if (preprocess) {
contents.append("\n\n");
contents.append("# Files to include in TTCN-3 preprocessed modules:\n");
contents.append("TTCN3_INCLUDES =");
for (TTCN3IncludeFileStruct temp : ttcn3IncludeFiles) {
if (usingSymbolicLinks) {
contents.append(' ').append(temp.getWorkspaceLocation());
} else {
contents.append(' ').append(temp.getOriginalLocation());
}
}
}
contents.append("\n\n");
contents.append("# ASN.1 modules of this project:\n");
contents.append("ASN1_MODULES =");
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() == null || !centralStorage) {
if (usingSymbolicLinks) {
contents.append(' ').append(module.fileName());
} else {
contents.append(' ').append(module.getOriginalLocation());
}
}
}
if (centralStorage) {
contents.append("\n\n");
contents.append("# ASN.1 modules used from central project(s):\n");
contents.append("BASE_ASN1_MODULES =");
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() != null) {
if (allProjectsUseSymbolicLinks) {
contents.append(' ').append(module.fileName());
} else {
contents.append(' ').append(module.getOriginalLocation());
}
}
}
}
if (preprocess) {
contents.append("\n\n");
contents.append("# TTCN-3 source files generated by the C preprocessor:\n");
contents.append("PREPROCESSED_TTCN3_MODULES =");
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.preprocessedName(false));
}
}
if (centralStorage) {
contents.append("\n\n");
contents.append("# TTCN-3 files generated by the CPP used from central project(s):\n");
contents.append("BASE_PREPROCESSED_TTCN3_MODULES =");
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.preprocessedName(true));
}
}
}
}
contents.append("\n\n");
contents.append("# C++ source & header files generated from the TTCN-3 & ASN.1 ");
contents.append("modules of\n");
contents.append("# this project:\n");
contents.append("GENERATED_SOURCES =");
if (gnuMake && ttcn3ModulesRegular && allProjectsUseSymbolicLinks) {
contents.append(" $(TTCN3_MODULES:.ttcn=.cc)");
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(getSplittedFilenames(module, false));
}
}
}
if (preprocess) {
contents.append(" $(TTCN3_PP_MODULES:.ttcnpp=.cc)");
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(getSplittedFilenames(module, false));
}
}
}
}
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "cc"));
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
contents.append(getSplittedFilenames(module, false));
}
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "cc"));
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
contents.append(getSplittedFilenames(module, false));
}
}
}
}
}
if (gnuMake && asn1ModulesRegular && allProjectsUseSymbolicLinks) {
contents.append(" $(ASN1_MODULES:.asn=.cc)");
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(getSplittedFilenames(module, false));
}
}
}
} else {
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "cc"));
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
contents.append(getSplittedFilenames(module, false));
}
}
}
}
contents.append("\nGENERATED_HEADERS =");
if (gnuMake) {
// the makefile that would cause weird behavior.
if (getSplittingMode().equals(GeneralConstants.NUMBER) || getSplittingMode().equals(GeneralConstants.TYPE)) {
if (ttcn3ModulesRegular) {
contents.append(" $(TTCN3_MODULES:.ttcn=.hh)");
if (preprocess) {
contents.append(" $(TTCN3_PP_MODULES:.ttcnpp=.hh)");
}
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "hh"));
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "hh"));
}
}
}
}
if (asn1ModulesRegular) {
contents.append(" $(ASN1_MODULES:.asn=.hh)");
} else {
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "hh"));
}
}
}
} else {
// Generate normally
contents.append(" $(GENERATED_SOURCES:.cc=.hh)");
}
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "hh"));
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "hh"));
}
}
}
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "hh"));
}
}
}
if (centralStorage) {
contents.append("\n\n");
contents.append("# C++ source & header files generated from the TTCN-3 & ASN.1 ");
contents.append("modules of\n");
contents.append("# central project(s):\n");
contents.append("BASE_GENERATED_SOURCES =");
if (gnuMake && baseTTCN3ModulesRegular && allProjectsUseSymbolicLinks) {
contents.append(" $(BASE_TTCN3_MODULES:.ttcn=.cc)");
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() != null) {
contents.append(getSplittedFilenames(module, false));
}
}
}
if (preprocess) {
contents.append(" $(BASE_TTCN3_PP_MODULES:.ttcnpp=.cc)");
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() != null) {
contents.append(getSplittedFilenames(module, false));
}
}
}
}
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "cc"));
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
contents.append(getSplittedFilenames(module, true));
}
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "cc"));
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
contents.append(getSplittedFilenames(module, true));
}
}
}
}
}
if (gnuMake && baseASN1ModulesRegular && allProjectsUseSymbolicLinks) {
contents.append(" $(BASE_ASN1_MODULES:.asn=.cc)");
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() != null) {
contents.append(getSplittedFilenames(module, false));
}
}
}
} else {
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "cc"));
if (!GeneralConstants.NONE.equals(codeSplittingMode)) {
contents.append(getSplittedFilenames(module, true));
}
}
}
}
contents.append("\nBASE_GENERATED_HEADERS =");
if (gnuMake) {
// the makefile that would cause weird behavior.
if (getSplittingMode().equals(GeneralConstants.NUMBER) || getSplittingMode().equals(GeneralConstants.TYPE)) {
if (ttcn3ModulesRegular) {
contents.append(" $(BASE_TTCN3_MODULES:.ttcn=.hh)");
if (preprocess) {
contents.append(" $(BASE_TTCN3_PP_MODULES:.ttcnpp=.hh)");
}
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "hh"));
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "hh"));
}
}
}
}
if (asn1ModulesRegular) {
contents.append(" $(BASE_ASN1_MODULES:.asn=.hh)");
} else {
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "hh"));
}
}
}
} else {
// Generate normally
contents.append(" $(BASE_GENERATED_SOURCES:.cc=.hh)");
}
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "hh"));
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "hh"));
}
}
}
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "hh"));
}
}
}
}
contents.append("\n\n");
contents.append("# C/C++ Source & header files of Test Ports, external functions ");
contents.append("and\n");
contents.append("# other modules:\n");
contents.append("USER_SOURCES =");
for (UserStruct user : userFiles) {
if (user.getDirectory() == null || !centralStorage) {
if (!usingSymbolicLinks && user.getOriginalSourceLocation() != null) {
contents.append(' ').append(user.getOriginalSourceLocation());
} else {
contents.append(' ').append(user.sourceName());
}
}
}
contents.append("\nUSER_HEADERS =");
if (gnuMake && userHeadersRegular) {
contents.append(" $(USER_SOURCES:.cc=.hh)");
} else {
for (UserStruct user : userFiles) {
if (user.getDirectory() == null || !centralStorage) {
if (!usingSymbolicLinks && user.getOriginalHeaderLocation() != null) {
contents.append(' ').append(user.getOriginalHeaderLocation());
} else {
contents.append(' ').append(user.headerName());
}
}
}
}
if (centralStorage) {
contents.append("\n\n");
contents.append("# C/C++ Source & header files of Test Ports, external functions ");
contents.append("and\n");
contents.append("# other modules used from central project(s):\n");
contents.append("BASE_USER_SOURCES =");
for (UserStruct user : userFiles) {
if (user.getDirectory() != null) {
contents.append(' ').append(user.sourceName());
}
}
contents.append("\nBASE_USER_HEADERS =");
if (gnuMake && baseUserHeadersRegular) {
contents.append(" $(BASE_USER_SOURCES:.cc=.hh)");
} else {
for (UserStruct user : userFiles) {
if (user.getDirectory() != null) {
contents.append(' ').append(user.headerName());
}
}
}
}
contents.append("\n\n");
contents.append("# Object files of this project that are needed for the executable ");
contents.append("test suite:\n");
contents.append("OBJECTS = $(GENERATED_OBJECTS) $(USER_OBJECTS)\n\n");
contents.append("GENERATED_OBJECTS =");
if (gnuMake) {
contents.append(" $(GENERATED_SOURCES:.cc=.o)");
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "o"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(false, "o", "_seq"));
contents.append(' ').append(module.generatedName(false, "o", "_seqof"));
contents.append(' ').append(module.generatedName(false, "o", "_set"));
contents.append(' ').append(module.generatedName(false, "o", "_setof"));
contents.append(' ').append(module.generatedName(false, "o", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(false, "o", "_part_" + i));
}
}
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "o"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(false, "o", "_seq"));
contents.append(' ').append(module.generatedName(false, "o", "_seqof"));
contents.append(' ').append(module.generatedName(false, "o", "_set"));
contents.append(' ').append(module.generatedName(false, "o", "_setof"));
contents.append(' ').append(module.generatedName(false, "o", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(false, "o", "_part_" + i));
}
}
}
}
}
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "o"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(false, "o", "_seq"));
contents.append(' ').append(module.generatedName(false, "o", "_seqof"));
contents.append(' ').append(module.generatedName(false, "o", "_set"));
contents.append(' ').append(module.generatedName(false, "o", "_setof"));
contents.append(' ').append(module.generatedName(false, "o", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(false, "o", "_part_" + i));
}
}
}
}
}
contents.append("\n\nUSER_OBJECTS =");
if (gnuMake && userSourcesRegular && usingSymbolicLinks) {
contents.append(" $(USER_SOURCES:.cc=.o)");
} else {
StringBuilder objectName;
for (UserStruct user : userFiles) {
if (user.getDirectory() == null || !centralStorage) {
objectName = user.objectName();
if (objectName != null) {
contents.append(' ').append(objectName);
}
}
}
}
if (dynamicLinking) {
contents.append("\n\n");
contents.append("# Shared object files of this project that are needed for the executable ");
contents.append("test suite:\n");
contents.append("SHARED_OBJECTS =");
if (gnuMake) {
contents.append(" $(GENERATED_SOURCES:.cc=.so)");
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "so"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(false, "so", "_seq"));
contents.append(' ').append(module.generatedName(false, "so", "_seqof"));
contents.append(' ').append(module.generatedName(false, "so", "_set"));
contents.append(' ').append(module.generatedName(false, "so", "_setof"));
contents.append(' ').append(module.generatedName(false, "so", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(false, "so", "_part_" + i));
}
}
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "so"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(false, "so", "_seq"));
contents.append(' ').append(module.generatedName(false, "so", "_seqof"));
contents.append(' ').append(module.generatedName(false, "so", "_set"));
contents.append(' ').append(module.generatedName(false, "so", "_setof"));
contents.append(' ').append(module.generatedName(false, "so", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(false, "so", "_part_" + i));
}
}
}
}
}
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() == null || !centralStorage) {
contents.append(' ').append(module.generatedName(false, "so"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(false, "so", "_seq"));
contents.append(' ').append(module.generatedName(false, "so", "_seqof"));
contents.append(' ').append(module.generatedName(false, "so", "_set"));
contents.append(' ').append(module.generatedName(false, "so", "_setof"));
contents.append(' ').append(module.generatedName(false, "so", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(false, "so", "_part_" + i));
}
}
}
}
}
if (gnuMake && userSourcesRegular) {
contents.append(" $(USER_SOURCES:.cc=.so)");
} else {
StringBuilder sharedObjectName;
for (UserStruct user : userFiles) {
if (user.getDirectory() == null || !centralStorage) {
sharedObjectName = user.specialName("so");
if (sharedObjectName != null) {
contents.append(' ').append(sharedObjectName);
}
}
}
}
}
if (centralStorage) {
contents.append("\n\n");
contents.append("# Object files of central project(s) that are needed for the ");
contents.append("executable test suite:\n");
contents.append("BASE_OBJECTS =");
if (gnuMake) {
contents.append(" $(BASE_GENERATED_SOURCES:.cc=.o)");
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "o"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(true, "o", "_seq"));
contents.append(' ').append(module.generatedName(true, "o", "_seqof"));
contents.append(' ').append(module.generatedName(true, "o", "_set"));
contents.append(' ').append(module.generatedName(true, "o", "_setof"));
contents.append(' ').append(module.generatedName(true, "o", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(true, "o", "_part_" + i));
}
}
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "o"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(true, "o", "_seq"));
contents.append(' ').append(module.generatedName(true, "o", "_seqof"));
contents.append(' ').append(module.generatedName(true, "o", "_set"));
contents.append(' ').append(module.generatedName(true, "o", "_setof"));
contents.append(' ').append(module.generatedName(true, "o", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(true, "o", "_part_" + i));
}
}
}
}
}
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "o"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(true, "o", "_seq"));
contents.append(' ').append(module.generatedName(true, "o", "_seqof"));
contents.append(' ').append(module.generatedName(true, "o", "_set"));
contents.append(' ').append(module.generatedName(true, "o", "_setof"));
contents.append(' ').append(module.generatedName(true, "o", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(true, "o", "_part_" + i));
}
}
}
}
}
if (gnuMake && baseUserSourcesRegular) {
contents.append(" $(BASE_USER_SOURCES:.cc=.o)");
} else {
StringBuilder objectName;
for (UserStruct user : userFiles) {
if (user.getDirectory() != null) {
objectName = user.objectName();
if (objectName != null) {
contents.append(' ').append(objectName);
}
}
}
}
if (dynamicLinking) {
contents.append("\n\n");
contents.append("# Shared object files of central project(s) that are needed for the ");
contents.append("executable test suite:\n");
contents.append("BASE_SHARED_OBJECTS =");
if (gnuMake) {
contents.append(" $(BASE_GENERATED_SOURCES:.cc=.so)");
} else {
for (ModuleStruct module : ttcn3Modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "so"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(true, "so", "_seq"));
contents.append(' ').append(module.generatedName(true, "so", "_seqof"));
contents.append(' ').append(module.generatedName(true, "so", "_set"));
contents.append(' ').append(module.generatedName(true, "so", "_setof"));
contents.append(' ').append(module.generatedName(true, "so", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(true, "so", "_part_" + i));
}
}
}
}
if (preprocess) {
for (ModuleStruct module : ttcnppModules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "so"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(true, "so", "_seq"));
contents.append(' ').append(module.generatedName(true, "so", "_seqof"));
contents.append(' ').append(module.generatedName(true, "so", "_set"));
contents.append(' ').append(module.generatedName(true, "so", "_setof"));
contents.append(' ').append(module.generatedName(true, "so", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(true, "so", "_part_" + i));
}
}
}
}
}
for (ModuleStruct module : asn1modules) {
if (module.getDirectory() != null) {
contents.append(' ').append(module.generatedName(true, "so"));
if (GeneralConstants.TYPE.equals(codeSplittingMode)) {
contents.append(' ').append(module.generatedName(true, "so", "_seq"));
contents.append(' ').append(module.generatedName(true, "so", "_seqof"));
contents.append(' ').append(module.generatedName(true, "so", "_set"));
contents.append(' ').append(module.generatedName(true, "so", "_setof"));
contents.append(' ').append(module.generatedName(true, "so", "_union"));
} else if (GeneralConstants.NONE.equals(codeSplittingMode)) {
} else {
int n_slices = Integer.parseInt(codeSplittingMode);
for (int i = 1; i < n_slices; i++) {
contents.append(' ').append(module.generatedName(true, "so", "_part_" + i));
}
}
}
}
}
if (gnuMake && baseUserSourcesRegular) {
contents.append(" $(BASE_USER_SOURCES:.cc=.so)");
} else {
StringBuilder sharedObjectName;
for (UserStruct user : userFiles) {
if (user.getDirectory() != null) {
sharedObjectName = user.specialName("so");
if (sharedObjectName != null) {
contents.append(' ').append(sharedObjectName);
}
}
}
}
}
}
if (incrementalDependencyRefresh) {
contents.append("\n\n");
contents.append("# Dependency files of this project that are needed for the executable test suite:\n");
contents.append("DEPFILES =");
contents.append(" $(USER_OBJECTS:.o=.d) $(GENERATED_OBJECTS:.o=.d)");
// USER_OBJECTS is first because GNU make processes
// included makefiles backwards.
// This ensures that the compiler is run and cc/hh files
// are created
// before the dep.files of USE_SOURCES are created.
}
contents.append("\n\n");
contents.append("# Other files of the project (Makefile, configuration files, etc.)\n");
contents.append("# that will be added to the archived source files:\n");
contents.append("OTHER_FILES =");
for (OtherFileStruct file : otherFiles) {
if (!usingSymbolicLinks && file.getOriginalLocation() != null) {
contents.append(' ').append(file.getOriginalLocation());
} else {
contents.append(' ').append(file.name(workingDirectory, useAbsolutePathNames));
}
}
contents.append("\n\n");
contents.append("# The name of the executable test suite:\n");
contents.append("EXECUTABLE = ").append(etsName).append('\n');
contents.append("LIBRARY = " + getLibraryName() + '\n');
contents.append("\nTARGET = " + (library ? "$(LIBRARY)" : "$(EXECUTABLE)"));
String zlib = useCrossCompilation ? "-lz" : "";
String rmCommand = gnuMake ? "$(RM)" : "rm -f";
contents.append("\n\n");
contents.append("#\n");
contents.append("# Do not modify these unless you know what you are doing...\n");
contents.append("# Platform specific additional libraries:\n");
contents.append("#\n");
contents.append("SOLARIS_LIBS = -lsocket -lnsl -lxml2 ").append(zlib);
if (USAGE_STATS) {
contents.append(" -lresolv");
}
for (IProject reachableProject : reachableProjects) {
String[] optionList = PlatformSpecificLibrariesOptionsData.getPlatformSpecificLibraries(reachableProject, "Solaris");
for (String option : optionList) {
contents.append(" -l").append(option);
}
}
contents.append('\n');
contents.append("SOLARIS8_LIBS = -lsocket -lnsl -lxml2 ").append(zlib);
if (USAGE_STATS) {
contents.append(" -lresolv");
}
for (IProject reachableProject : reachableProjects) {
String[] optionList = PlatformSpecificLibrariesOptionsData.getPlatformSpecificLibraries(reachableProject, "Solaris8");
for (String option : optionList) {
contents.append(" -l").append(option);
}
}
contents.append('\n');
contents.append("LINUX_LIBS = -lxml2 ").append(zlib);
if (USAGE_STATS) {
contents.append(" -lpthread -lrt");
}
for (IProject reachableProject : reachableProjects) {
String[] optionList = PlatformSpecificLibrariesOptionsData.getPlatformSpecificLibraries(reachableProject, "Linux");
for (String option : optionList) {
contents.append(" -l").append(option);
}
}
contents.append('\n');
contents.append("FREEBSD_LIBS = -lxml2 ").append(zlib);
for (IProject reachableProject : reachableProjects) {
String[] optionList = PlatformSpecificLibrariesOptionsData.getPlatformSpecificLibraries(reachableProject, "FreeBSD");
for (String option : optionList) {
contents.append(" -l").append(option);
}
}
contents.append('\n');
contents.append("WIN32_LIBS = -lxml2 ").append(zlib);
for (IProject reachableProject : reachableProjects) {
String[] optionList = PlatformSpecificLibrariesOptionsData.getPlatformSpecificLibraries(reachableProject, "Win32");
for (String option : optionList) {
contents.append(" -l").append(option);
}
}
contents.append("\n\n");
contents.append("#\n");
contents.append("# Rules for building the executable...\n");
contents.append("#\n\n");
contents.append("all: $(TARGET) ;\n\n");
contents.append("executable: $(EXECUTABLE) ;\n\n");
contents.append("library: $(LIBRARY) ;\n\n");
contents.append("objects: $(OBJECTS) compile;\n\n");
if (dynamicLinking) {
contents.append("shared_objects: $(SHARED_OBJECTS) ;\n\n");
}
final StringBuilder allObjects = new StringBuilder();
if (dynamicLinking) {
allObjects.append("$(SHARED_OBJECTS)");
if (centralStorage) {
allObjects.append(" $(BASE_SHARED_OBJECTS)");
}
} else {
allObjects.append("$(OBJECTS)");
if (centralStorage) {
allObjects.append(" $(BASE_OBJECTS)");
}
}
appendExecutableTarget(contents, allObjects.toString(), externalLibrariesDisabled);
contents.append("$(LIBRARY): " + allObjects + '\n');
if (dynamicLinking) {
contents.append("\t$(CXX) -shared -o $@ " + allObjects + "\n\n");
} else {
contents.append("\t$(AR) -r $(ARFLAGS) $(LIBRARY) " + allObjects + "\n\n");
}
if (dynamicLinking) {
contents.append("%.so: %.o\n");
contents.append("\t$(CXX) -shared -o $@ $<\n\n");
}
if (!usingSymbolicLinks) {
StringBuilder objectName;
for (UserStruct user : userFiles) {
objectName = user.objectName();
if (objectName != null) {
contents.append(objectName + " : ");
if (user.getOriginalSourceLocation() != null) {
contents.append(' ').append(user.getOriginalSourceLocation());
} else {
contents.append(' ').append(user.sourceName());
}
contents.append('\n');
contents.append("\t$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<\n\n");
}
}
}
contents.append(".cc.o .c.o:\n");
contents.append("\t$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<\n\n");
if (incrementalDependencyRefresh) {
if (!usingSymbolicLinks) {
StringBuilder depName;
for (UserStruct user : userFiles) {
depName = user.specialName("d");
if (depName != null) {
contents.append(depName + " : ");
if (user.getOriginalSourceLocation() != null) {
contents.append(' ').append(user.getOriginalSourceLocation());
} else {
contents.append(' ').append(user.sourceName());
}
contents.append('\n');
contents.append("\t@echo Creating dependency file for '$<'; set -e; \\\n");
contents.append("\t$(CXX) $(CXXDEPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< \\\n");
contents.append("\t| sed 's/\\($*\\)\\.o[ :]*/\\1.o $@ : /g' > $@; \\\n");
contents.append("\t[ -s $@ ] || rm -f $@\n\n");
}
}
}
contents.append(".cc.d .c.d:\n");
contents.append("\t@echo Creating dependency file for '$<'; set -e; \\\n");
contents.append("\t$(CXX) $(CXXDEPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< \\\n");
contents.append("\t| sed 's/\\($*\\)\\.o[ :]*/\\1.o $@ : /g' > $@; \\\n");
contents.append("\t[ -s $@ ] || rm -f $@\n\n");
/*
* "set -e" causes bash to exit the script if any
* statement returns nonzero (failure). The sed line
* transforms the first line of the dependency from
* "x.o: x.cc" to "x.o x.d: x.cc", making the dependency
* file depend on the source and headers. [ -s x.d ]
* checks that the generated dependency is not empty;
* otherwise it gets deleted.
*/
}
if (preprocess) {
if (!usingSymbolicLinks) {
StringBuilder depName;
for (ModuleStruct module : ttcnppModules) {
depName = module.preprocessedName(true);
if (depName != null) {
contents.append(depName + " : ");
if (module.getOriginalLocation() != null) {
contents.append(' ').append(module.getOriginalLocation());
} else {
contents.append(' ').append(module.getFileName());
}
contents.append(" $(TTCN3_INCLUDES) \n");
contents.append("\t$(CPP) -x c -nostdinc $(CPPFLAGS_TTCN3) $< $@\n\n");
}
}
}
contents.append("%.ttcn: %.ttcnpp $(TTCN3_INCLUDES)\n");
contents.append("\t$(CPP) -x c -nostdinc $(CPPFLAGS_TTCN3) $< $@\n\n");
contents.append("preprocess: $(PREPROCESSED_TTCN3_MODULES) ;\n\n");
}
if (centralStorage) {
boolean isFirst = true;
contents.append("$(GENERATED_SOURCES) $(GENERATED_HEADERS): compile-all compile");
for (BaseDirectoryStruct dir : baseDirectories) {
if (dir.isHasModules()) {
if (isFirst) {
contents.append(" \\\n");
isFirst = false;
} else {
contents.append(' ');
}
if (!".".equals(dir.name())) {
contents.append(dir.name()).append("/compile");
}
}
}
if (preprocess) {
contents.append('\n');
contents.append("\t@if [ ! -f $@ ]; then ").append(rmCommand).append(" compile-all; $(MAKE) compile-all; fi\n");
contents.append('\n');
contents.append("check: $(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("$(PREPROCESSED_TTCN3_MODULES) $(BASE_PREPROCESSED_TTCN3_MODULES) ");
contents.append("\\\n");
contents.append("$(ASN1_MODULES) $(BASE_ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler -s $(COMPILER_FLAGS) ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("\\\n");
contents.append("\t$(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("\t$(PREPROCESSED_TTCN3_MODULES) ");
contents.append("$(BASE_PREPROCESSED_TTCN3_MODULES) \\\n");
contents.append("\t$(ASN1_MODULES) $(BASE_ASN1_MODULES)");
}
contents.append("\n\n");
contents.append("port: $(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("$(PREPROCESSED_TTCN3_MODULES) $(BASE_PREPROCESSED_TTCN3_MODULES) ");
contents.append("\\\n");
contents.append("$(ASN1_MODULES) $(BASE_ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler -t $(COMPILER_FLAGS) ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("\\\n");
contents.append("\t$(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("\t$(PREPROCESSED_TTCN3_MODULES) ");
contents.append("$(BASE_PREPROCESSED_TTCN3_MODULES)");
}
contents.append("\n\n");
contents.append("compile: $(TTCN3_MODULES) $(PREPROCESSED_TTCN3_MODULES) ");
contents.append("$(ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler $(COMPILER_FLAGS) \\\n");
contents.append("\t$(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("\t$(PREPROCESSED_TTCN3_MODULES) ");
contents.append("$(BASE_PREPROCESSED_TTCN3_MODULES) \\\n");
contents.append("\t$(ASN1_MODULES) $(BASE_ASN1_MODULES) - $?\n");
contents.append("\ttouch $@\n");
contents.append('\n');
contents.append("compile-all: $(BASE_TTCN3_MODULES) ");
contents.append("$(BASE_PREPROCESSED_TTCN3_MODULES) \\\n");
contents.append("$(BASE_ASN1_MODULES)\n");
contents.append("\t$(MAKE) preprocess\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler $(COMPILER_FLAGS) \\\n");
contents.append("\t$(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("\t$(PREPROCESSED_TTCN3_MODULES) $(BASE_PREPROCESSED_TTCN3_MODULES) ");
contents.append("\\\n");
contents.append("\t$(ASN1_MODULES) $(BASE_ASN1_MODULES) \\\n");
contents.append("\t- $(TTCN3_MODULES) $(PREPROCESSED_TTCN3_MODULES) $(ASN1_MODULES)\n");
contents.append("\ttouch $@ compile\n\n");
} else {
contents.append('\n');
contents.append("\t@if [ ! -f $@ ]; then ").append(rmCommand).append(" compile-all; $(MAKE) compile-all; fi\n");
contents.append('\n');
contents.append("check: $(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("$(ASN1_MODULES) $(BASE_ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler -s $(COMPILER_FLAGS) ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("\\\n");
contents.append("\t$(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("\t$(ASN1_MODULES) $(BASE_ASN1_MODULES)");
}
contents.append("\n\n");
contents.append("port: $(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("$(ASN1_MODULES) $(BASE_ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler -t $(COMPILER_FLAGS) ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("\\\n");
contents.append("\t$(TTCN3_MODULES) $(BASE_TTCN3_MODULES)");
}
contents.append("\n\n");
contents.append("compile: $(TTCN3_MODULES) $(ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler $(COMPILER_FLAGS) \\\n");
contents.append("\t$(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("\t$(ASN1_MODULES) $(BASE_ASN1_MODULES) \\\n");
contents.append("\t- $?\n");
contents.append("\ttouch $@\n");
contents.append('\n');
contents.append("compile-all: $(BASE_TTCN3_MODULES) $(BASE_ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler $(COMPILER_FLAGS) \\\n");
contents.append("\t$(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
contents.append("\t$(ASN1_MODULES) $(BASE_ASN1_MODULES) \\\n");
contents.append("\t- $(TTCN3_MODULES) $(ASN1_MODULES)\n");
contents.append("\ttouch $@ compile\n\n");
}
for (BaseDirectoryStruct dir : baseDirectories) {
if (dir.isHasModules() && !".".equals(dir.name().toString())) {
contents.append(dir.name()).append("/compile:");
if (allProjectsUseSymbolicLinks) {
for (ModuleStruct module : ttcn3Modules) {
String dirName = module.getDirectory();
if (dirName != null && dir.getDirectoryName().equals(dirName)) {
contents.append(' ').append(dir.name()).append('/').append(module.getFileName());
}
}
for (ModuleStruct module : ttcnppModules) {
String dirName = module.getDirectory();
if (dirName != null && dir.getDirectoryName().equals(dirName)) {
contents.append(' ').append(dir.name()).append('/').append(module.getFileName());
}
}
for (ModuleStruct module : asn1modules) {
String dirName = module.getDirectory();
if (dirName != null && dir.getDirectoryName().equals(dirName)) {
contents.append(' ').append(dir.name()).append('/').append(module.getFileName());
}
}
} else {
for (ModuleStruct module : ttcn3Modules) {
String dirName = module.getDirectory();
if (dirName != null && dir.getDirectoryName().equals(dirName)) {
contents.append(' ').append(module.getOriginalLocation());
}
}
for (ModuleStruct module : ttcnppModules) {
String dirName = module.getDirectory();
if (dirName != null && dir.getDirectoryName().equals(dirName)) {
contents.append(' ').append(module.getOriginalLocation());
}
}
for (ModuleStruct module : asn1modules) {
String dirName = module.getDirectory();
if (dirName != null && dir.getDirectoryName().equals(dirName)) {
contents.append(' ').append(module.getOriginalLocation());
}
}
}
contents.append('\n');
contents.append("\t@echo 'Central directory ").append(dir.originalName()).append(" is not up-to-date!'\n");
contents.append("\t@exit 2\n\n");
}
}
contents.append("browserdata.dat: $(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
if (preprocess) {
contents.append("$(PREPROCESSED_TTCN3_MODULES) ");
contents.append("$(BASE_PREPROCESSED_TTCN3_MODULES) \\\n");
}
contents.append("$(ASN1_MODULES) $(BASE_ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler -B -s $(COMPILER_FLAGS) ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("\\\n");
contents.append("\t$(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
if (preprocess) {
contents.append("\t$(PREPROCESSED_TTCN3_MODULES) ");
contents.append("$(BASE_PREPROCESSED_TTCN3_MODULES) \\\n");
}
contents.append("\t$(BASE_ASN1_MODULES) $(ASN1_MODULES)");
}
contents.append("\n\n");
} else {
contents.append("$(GENERATED_SOURCES) $(GENERATED_HEADERS): compile\n");
contents.append("\t@if [ ! -f $@ ]; then ").append(rmCommand).append(" compile; $(MAKE) compile; fi\n\n");
contents.append("check: $(TTCN3_MODULES) ");
if (preprocess) {
contents.append("$(PREPROCESSED_TTCN3_MODULES) ");
}
contents.append("$(ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler -s $(COMPILER_FLAGS) ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("\\\n");
contents.append("\t$(TTCN3_MODULES) $(PREPROCESSED_TTCN3_MODULES) $(ASN1_MODULES)");
}
contents.append("\n\n");
contents.append("port: $(TTCN3_MODULES) ");
if (preprocess) {
contents.append("$(PREPROCESSED_TTCN3_MODULES) ");
}
contents.append("$(ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler -t $(COMPILER_FLAGS) ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("\\\n");
contents.append("\t$(TTCN3_MODULES) $(PREPROCESSED_TTCN3_MODULES)");
}
contents.append("\n\n");
contents.append("compile: $(TTCN3_MODULES) ");
if (preprocess) {
contents.append("$(PREPROCESSED_TTCN3_MODULES) ");
}
contents.append("$(ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler $(COMPILER_FLAGS) ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("\\\n");
contents.append("\t$(TTCN3_MODULES) ");
if (preprocess) {
contents.append("$(PREPROCESSED_TTCN3_MODULES) ");
}
contents.append("$(ASN1_MODULES)");
}
contents.append(" - $?\n");
contents.append("\ttouch $@\n");
contents.append('\n');
contents.append("browserdata.dat: $(TTCN3_MODULES) ");
if (preprocess) {
contents.append("$(PREPROCESSED_TTCN3_MODULES) ");
}
contents.append("$(ASN1_MODULES)\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler -B -s $(COMPILER_FLAGS) ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("\\\n");
contents.append("\t$(TTCN3_MODULES) ");
if (preprocess) {
contents.append("$(PREPROCESSED_TTCN3_MODULES) ");
}
contents.append("$(ASN1_MODULES)");
}
contents.append("\n\n");
}
contents.append("clean:\n");
contents.append("\t-").append(rmCommand).append(" $(EXECUTABLE) $(OBJECTS) $(LIBRARY) $(GENERATED_HEADERS)");
if (incrementalDependencyRefresh) {
contents.append(" $(DEPFILES)");
}
contents.append(" \\\n");
contents.append("\t$(GENERATED_SOURCES) ");
if (dynamicLinking) {
contents.append("$(SHARED_OBJECTS) ");
}
if (preprocess) {
contents.append("$(PREPROCESSED_TTCN3_MODULES) ");
}
contents.append("compile");
if (centralStorage) {
contents.append(" compile-all");
}
contents.append(" \\\n");
contents.append("\tbrowserdata.dat tags *.log");
if (incrementalDependencyRefresh) {
contents.append(" $(DEPFILES)");
}
contents.append("\n\n");
contents.append("dep: $(GENERATED_SOURCES) $(USER_SOURCES)");
if (incrementalDependencyRefresh) {
// nothing to do for "dep" as such
contents.append(" $(DEPFILES) ;\n\n");
contents.append("ifeq ($(filter clean check port compile archive,$(MAKECMDGOALS)),)\n");
if (preprocess) {
// Prevent nasty infinite make loop
contents.append("ifeq ($(findstring preprocess,$(MAKECMDGOALS)),)\n");
}
contents.append("-include $(DEPFILES)\n");
if (preprocess) {
contents.append("endif\n");
}
contents.append("endif\n\n");
} else {
contents.append("\n\tmakedepend $(CPPFLAGS) -DMAKEDEPEND_RUN ");
if (gnuMake) {
contents.append("$^");
} else {
contents.append("$(GENERATED_SOURCES) $(USER_SOURCES)");
}
}
contents.append("\n\n");
contents.append("archive:\n");
contents.append("\tmkdir -p $(ARCHIVE_DIR)\n");
contents.append("\ttar -cvhf - ");
if (centralStorage) {
contents.append("$(TTCN3_MODULES) $(BASE_TTCN3_MODULES) \\\n");
if (preprocess) {
contents.append("\t$(TTCN3_PP_MODULES) $(BASE_TTCN3_PP_MODULES) ");
contents.append("$(TTCN3_INCLUDES)\\\n");
}
contents.append("\t$(ASN1_MODULES) $(BASE_ASN1_MODULES) \\\n");
contents.append("\t$(USER_HEADERS) $(BASE_USER_HEADERS) \\\n");
contents.append("\t$(USER_SOURCES) $(BASE_USER_SOURCES)");
} else {
contents.append("$(TTCN3_MODULES) ");
if (preprocess) {
contents.append("$(TTCN3_PP_MODULES) \\\n");
contents.append("\t$(TTCN3_INCLUDES) ");
}
contents.append("$(ASN1_MODULES) \\\n");
contents.append("\t$(USER_HEADERS) $(USER_SOURCES)");
}
contents.append(" $(OTHER_FILES) \\\n");
contents.append("\t| gzip >$(ARCHIVE_DIR)/`basename $(TARGET) .exe`-");
contents.append("`date '+%y%m%d-%H%M'`.tgz\n\n");
contents.append("diag:\n");
contents.append("\t$(TTCN3_DIR)/bin/compiler -v 2>&1\n");
contents.append("\t$(TTCN3_DIR)/bin/mctr_cli -v 2>&1\n");
contents.append("\t$(CXX) -v 2>&1\n");
if (!dynamicLinking) {
contents.append("\t$(AR) -V 2>&1\n");
}
contents.append("\t@echo TTCN3_DIR=$(TTCN3_DIR)\n");
contents.append("\t@echo OPENSSL_DIR=$(OPENSSL_DIR)\n");
contents.append("\t@echo XMLDIR=$(XMLDIR)\n");
contents.append("\t@echo PLATFORM=$(PLATFORM)\n\n");
contents.append("#\n");
contents.append("# Add your rules here if necessary...\n");
contents.append("#\n\n");
String makefileName = "Makefile";
try {
if (project.getLocation().isPrefixOf(workingDirectoryPath)) {
int matchingSegments = project.getLocation().matchingFirstSegments(workingDirectoryPath);
IPath samplePath = workingDirectoryPath.removeFirstSegments(matchingSegments);
IFolder folder = project.getFolder(samplePath);
if (!folder.isAccessible()) {
ResourceUtils.refreshResources(Arrays.asList(folder));
}
IFile sampleMakefile = project.getFile(samplePath.append("/" + makefileName));
sampleMakefile.refreshLocal(0, null);
if (sampleMakefile.exists()) {
sampleMakefile.setContents(new ByteArrayInputStream(contents.toString().getBytes()), IResource.FORCE | IResource.KEEP_HISTORY, null);
} else {
sampleMakefile.create(new ByteArrayInputStream(contents.toString().getBytes()), IResource.FORCE, null);
}
ResourceUtils.refreshResources(Arrays.asList(sampleMakefile));
sampleMakefile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
} else {
IPath makefilepath = workingDirectoryPath.append(makefileName);
BufferedOutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(makefilepath.toOSString()));
out.write(contents.toString().getBytes());
} catch (FileNotFoundException e) {
ErrorReporter.logExceptionStackTrace(e);
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
} finally {
IOUtils.closeQuietly(out);
}
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class InternalMakefileGenerator method addASN1Module.
/**
* Adds a file to the list of ASN.1 files.
* <p/>
* The directory of the file must always point to a working directory,
* or a central storage directory.
*
* @param file the file to be added.
* @param directory in which this file can be found (null if the working
* directory of the actual project)
*/
public void addASN1Module(final IFile file, final String directory) {
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
String moduleName = parser.containedModuleName(file);
if (moduleName == null) {
if (file.isSynchronized(IResource.DEPTH_ZERO)) {
ErrorReporter.logWarning("file " + file.getFullPath().toOSString() + " is out-of sync with the file system");
} else {
ErrorReporter.logWarning("file " + file.getFullPath().toOSString() + " even tough it has asn extension is added as on other file since the on-the-fly analyzer was not able to find a valid module inside");
}
addOtherFiles(file, directory);
return;
}
final IPath location = file.getLocation();
String originalLocation;
if (location == null) {
originalLocation = directory + File.separatorChar + file.getName();
} else {
originalLocation = location.toOSString();
}
final Identifier identifier = new Identifier(Identifier_type.ID_NAME, moduleName);
final ModuleStruct module = new ModuleStruct(directory, originalLocation, file.getName(), identifier.getAsnName());
String prefix = file.getName();
prefix = prefix.replace('_', '-');
module.setRegular(location != null && "asn".equals(file.getFileExtension()) && prefix.equals(moduleName + ".asn"));
asn1modules.add(module);
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class ImportSelectionDialog method findReferenceInProject.
/**
* Try to find the declaration of the reference in any module of the
* project.
* <p>
* If exactly one declaration is found, then its location is returned. If
* multiple modules contain a valid declaration of the reference, then a
* dialog is displayed to the user to choose one. If none found, or the user
* cancels the dialog, <code>null</code> is returned.
* </p>
*
* @param reference
* The (missing) reference we are searching for.
* @param project
* The project in which we search the declaration.
* @return The location of the declaration, if uniquely found,
* <code>null</code> otherwise.
*/
public static Location findReferenceInProject(final Reference reference, final IProject project) {
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
final List<DeclarationCollectionHelper> collected = new ArrayList<DeclarationCollectionHelper>();
final Identifier identifier = reference.getId();
for (final String moduleName : projectSourceParser.getKnownModuleNames()) {
final Module m = projectSourceParser.getModuleByName(moduleName);
if (m != null && m.getAssignments().hasLocalAssignmentWithID(CompilationTimeStamp.getBaseTimestamp(), identifier)) {
Assignment assignment = m.getAssignments().getLocalAssignmentByID(CompilationTimeStamp.getBaseTimestamp(), identifier);
if (assignment != null) {
collected.add(new DeclarationCollectionHelper(assignment.getProposalDescription(), assignment.getIdentifier().getLocation(), assignment));
}
}
}
Location loc = null;
if (collected.size() > 1) {
final List<String> files = new ArrayList<String>();
for (final DeclarationCollectionHelper c : collected) {
files.add(c.location.getFile().getName());
}
TITANDebugConsole.println("Multiple possible imports for " + reference.getDisplayName() + ": " + files.toString());
final ImportSelectionDialog dialog = new ImportSelectionDialog(reference, collected, reference.getLocation().getFile());
Display.getDefault().syncExec(dialog);
loc = dialog.getSelected();
} else if (collected.size() == 1) {
DeclarationCollectionHelper declaration = collected.get(0);
loc = declaration.location;
TITANDebugConsole.println("Exactly one module for " + reference.getDisplayName() + " is found: " + loc.getFile().getName());
} else {
TITANDebugConsole.println("No imports for " + reference.getDisplayName() + " is found");
}
return loc;
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class ImportSelectionDialog method organizeImportsEdit.
/**
* Organize the imports according to the global preferences. If set,
* <ul>
* <li>Add imports necessary for missing references,</li>
* <li>Remove unused imports,</li>
* <li>Sort the import statements.</li>
* </ul>
* <p>
* These changes are not applied in the function, just collected in a
* <link>MultiTextEdit</link>, which is then returned.
* </p>
* TODO: notice and handle ambiguous references
*
* @param module
* The module which import statements are to organize.
* @param document
* The document that contains the module.
*
* @return The edit, which contains the proper changes.
*/
private static MultiTextEdit organizeImportsEdit(final TTCN3Module module, final IDocument document) throws BadLocationException {
final IProject prj = module.getProject();
final String doc = document.get();
final MultiTextEdit insertEdit = new MultiTextEdit();
final MultiTextEdit removeEdit = new MultiTextEdit();
final List<ImportText> newImports = new ArrayList<ImportText>();
final List<ImportText> importsKept = new ArrayList<ImportText>();
boolean needSorting = false;
if (addImports) {
// register the new needed imports
final Set<String> importNamesAdded = new HashSet<String>();
for (final Reference ref : module.getMissingReferences()) {
final Location missLoc = findReferenceInProject(ref, prj);
if (missLoc != null) {
final IFile file = (IFile) missLoc.getFile();
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
final Module addMod = parser.containedModule(file);
final String importName = addMod.getIdentifier().getTtcnName();
if (!importNamesAdded.contains(importName)) {
final StringBuilder impText = new StringBuilder("import from ").append(importName).append(" all;");
// if (importChangeMethod.equals(OrganizeImportPreferencePage.COMMENT_THEM)) {
impText.append(" // Added automatically to resolve ").append(ref.getDisplayName());
// }
newImports.add(new ImportText(importName, impText.toString() + NEWLINE));
importNamesAdded.add(importName);
if (reportDebug) {
final StringBuilder sb = new StringBuilder("For ").append(ref.getDisplayName()).append(": ");
sb.append(impText.toString());
TITANDebugConsole.println(sb.toString());
}
}
}
}
if (sortImports && !newImports.isEmpty()) {
needSorting = true;
}
}
if (!needSorting && sortImports) {
// are the imports already sorted ?
final List<ImportModule> oldImports = module.getImports();
for (int size = oldImports.size(), i = 0; i < size - 1 && !needSorting; i++) {
if (oldImports.get(i).getName().compareTo(oldImports.get(i + 1).getName()) > 0) {
needSorting = true;
}
if (oldImports.get(i).getLocation().getOffset() > oldImports.get(i + 1).getLocation().getOffset()) {
needSorting = true;
}
}
if (!needSorting && oldImports.size() > 1) {
// are the import strictly before the definitions ?
final int lastImportOffset = oldImports.get(oldImports.size() - 1).getLocation().getOffset();
final Definitions defs = module.getAssignmentsScope();
if (defs.getNofAssignments() > 0 && !oldImports.isEmpty()) {
for (int i = 0, size = defs.getNofAssignments(); i < size; ++i) {
final int temp = defs.getAssignmentByIndex(i).getLocation().getOffset();
if (temp < lastImportOffset) {
needSorting = true;
}
}
}
}
}
if (needSorting || removeImports) {
// remove the imports not needed, or every if sorting is required
for (final ImportModule m : module.getImports()) {
final Location delImp = m.getLocation();
final IRegion startLineRegion = document.getLineInformationOfOffset(delImp.getOffset());
final IRegion endLineRegion = document.getLineInformationOfOffset(delImp.getEndOffset());
final String delimeter = document.getLineDelimiter(document.getLineOfOffset(delImp.getEndOffset()));
final int delLength = delimeter == null ? 0 : delimeter.length();
if (needSorting || (removeImports && !m.getUsedForImportation())) {
if (reportDebug) {
final MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
TITANDebugConsole.println("Removing " + "'" + doc.substring(startLineRegion.getOffset(), endLineRegion.getOffset() + endLineRegion.getLength() + delLength) + "'", stream);
TITANDebugConsole.println("From " + startLineRegion.getOffset() + " till " + ((endLineRegion.getOffset() - startLineRegion.getOffset()) + endLineRegion.getLength() + delLength), stream);
}
/*if (importChangeMethod.equals(OrganizeImportPreferencePage.COMMENT_THEM)) {
removeEdit.addChild(new InsertEdit(m.getLocation().getOffset(), "/*"));
// hack to handle the semicolon
removeEdit.addChild(new InsertEdit(m.getLocation().getEndOffset() + 1, ""));
} else {*/
removeEdit.addChild(new DeleteEdit(startLineRegion.getOffset(), (endLineRegion.getOffset() - startLineRegion.getOffset()) + endLineRegion.getLength() + delLength));
// }
}
if (needSorting && (!removeImports || m.getUsedForImportation())) {
importsKept.add(new ImportText(m.getName(), doc.substring(startLineRegion.getOffset(), endLineRegion.getOffset() + endLineRegion.getLength() + delLength)));
}
}
}
if (!newImports.isEmpty() || (sortImports && needSorting)) {
// always insert at the beginning of the file
final int line = document.getLineOfOffset(module.getAssignmentsScope().getLocation().getOffset());
final IRegion lineRegion = document.getLineInformation(line);
final String delimeter = document.getLineDelimiter(line);
final int delimeterLength = delimeter == null ? 0 : delimeter.length();
final int startPos = lineRegion.getOffset() + lineRegion.getLength() + delimeterLength;
if (sortImports) {
if (needSorting || !newImports.isEmpty()) {
final List<ImportText> results = new ArrayList<ImportText>();
results.addAll(importsKept);
results.addAll(newImports);
Collections.sort(results);
for (final ImportText i : results) {
insertEdit.addChild(new InsertEdit(startPos, i.getText()));
}
}
} else {
Collections.sort(newImports);
for (final ImportText i : newImports) {
insertEdit.addChild(new InsertEdit(startPos, i.getText()));
}
}
}
final MultiTextEdit resultEdit = new MultiTextEdit();
if (insertEdit.hasChildren()) {
resultEdit.addChild(insertEdit);
}
if (removeEdit.hasChildren()) {
resultEdit.addChild(removeEdit);
}
return resultEdit;
}
use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.
the class ImportSelectionDialog method createFileChange.
private Change createFileChange(final IFile toVisit) {
if (toVisit == null) {
return null;
}
final String designerId = ProductConstants.PRODUCT_ID_DESIGNER;
final String displayDebugInfo = org.eclipse.titan.designer.preferences.PreferenceConstants.DISPLAYDEBUGINFORMATION;
reportDebug = Platform.getPreferencesService().getBoolean(designerId, displayDebugInfo, false, null);
final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(toVisit.getProject());
final Module module = sourceParser.containedModule(toVisit);
if (module == null || !(module instanceof TTCN3Module)) {
return null;
}
final TextFileChange tfc = new TextFileChange(toVisit.getName(), toVisit);
IDocument doc;
final TTCN3Module tModule = (TTCN3Module) module;
try {
doc = tfc.getCurrentDocument(null);
final MultiTextEdit resultEdit = organizeImportsEdit(tModule, doc);
if (!resultEdit.hasChildren()) {
return null;
}
tfc.setEdit(resultEdit);
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace("Error while organizing imports", e);
} catch (CoreException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return tfc;
}
Aggregations