use of org.eclipse.titan.designer.core.TITANBuilderResourceVisitor in project titan.EclipsePlug-ins by eclipse.
the class ExternalMakefileGenerator method createMakefileGeneratorCommand.
/**
* Creates the commandline command to be used to generate the Makefile for the passed project.
*
* @param project the project to generate the Makefile for
*/
public static List<String> createMakefileGeneratorCommand(final IProject project) {
final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, false, null);
final TITANBuilderResourceVisitor visitor = ProjectBasedBuilder.getProjectBasedBuilder(project).getResourceVisitor();
final Map<String, IFile> files = visitor.getFiles();
final Map<String, IFile> centralStorageFiles = visitor.getCentralStorageFiles();
final Map<String, IFile> referencedFiles = ProjectBasedBuilder.getProjectBasedBuilder(project).getFilesofReferencedProjects();
final List<String> command = new ArrayList<String>();
final IPreferencesService prefs = Platform.getPreferencesService();
final String pathOfTITAN = prefs.getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.TITAN_INSTALLATION_PATH, "", null);
final Path makefilegenPath = new Path(pathOfTITAN + File.separatorChar + BIN_DIRECTORY + File.separatorChar + MAKEFILEGENERATOR);
command.add(PathConverter.convert(makefilegenPath.toOSString(), reportDebugInformation, TITANDebugConsole.getConsole()));
final String decoratorParametersLong = TITANDecorator.propertiesAsParameters(project, true);
if (!EMPTY_STRING.equals(decoratorParametersLong)) {
final String[] parameters = decoratorParametersLong.split(" ");
for (int i = 0; i < parameters.length; i++) {
command.add(parameters[i]);
}
}
SymbolicLinkHandler.createSymlinks(project);
for (final String path : files.keySet()) {
command.add(APOSTROPHE + path + APOSTROPHE);
}
final IPath centralStorageDirectoryPath = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryPath(true);
final String centralStorageDirectory = centralStorageDirectoryPath.toOSString();
for (final String fileName : centralStorageFiles.keySet()) {
final IFile file = centralStorageFiles.get(fileName);
final IProject otherProject = file.getProject();
final IPath referencedCentralStorageDirectoryPath = ProjectBasedBuilder.getProjectBasedBuilder(otherProject).getWorkingDirectoryPath(true);
final String referencedCentralStorageDirectory = referencedCentralStorageDirectoryPath.toOSString();
final String relativePathToDirectory = PathUtil.getRelativePath(centralStorageDirectory, referencedCentralStorageDirectory);
final Path relativePath = new Path(relativePathToDirectory);
final String path = relativePath.append(fileName).toOSString();
command.add(APOSTROPHE + PathConverter.convert(path, reportDebugInformation, TITANDebugConsole.getConsole()) + APOSTROPHE);
}
final IPath workingDirectoryPath = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryPath(true);
final String workingDirectory = workingDirectoryPath.toOSString();
for (final String fileName : referencedFiles.keySet()) {
final IFile file = referencedFiles.get(fileName);
final IProject otherProject = file.getProject();
final IPath referencedWorkingDirectoryPath = ProjectBasedBuilder.getProjectBasedBuilder(otherProject).getWorkingDirectoryPath(true);
final String referencedWorkingDirectory = referencedWorkingDirectoryPath.toOSString();
final String relativePathToDirectory = PathUtil.getRelativePath(workingDirectory, referencedWorkingDirectory);
final Path relativePath = new Path(relativePathToDirectory);
final String path = relativePath.append(fileName).toOSString();
command.add(APOSTROPHE + PathConverter.convert(path, reportDebugInformation, TITANDebugConsole.getConsole()) + APOSTROPHE);
}
return command;
}
use of org.eclipse.titan.designer.core.TITANBuilderResourceVisitor in project titan.EclipsePlug-ins by eclipse.
the class GenerateBuilderInformation method generateInfoForProject.
private void generateInfoForProject(final IProject project) throws CoreException {
final boolean win32 = Platform.OS_WIN32.equals(Platform.getOS());
final boolean reportDebugInformation = Platform.getPreferencesService().getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, false, null);
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
ErrorReporter.logExceptionStackTrace(e);
return;
}
final DOMImplementation impl = builder.getDOMImplementation();
final Document document = impl.createDocument(null, "TITAN_External_Builder_Information", null);
final Element root = document.getDocumentElement();
root.setAttribute("version", "1.0");
String temp;
Node node;
final Element makefileSettings = document.createElement("Makefile_settings");
root.appendChild(makefileSettings);
for (int i = 0; i < MakefileCreationData.MAKEFILE_PROPERTIES.length; i++) {
try {
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, MakefileCreationData.MAKEFILE_PROPERTIES[i]));
node = document.createElement(MakefileCreationData.MAKEFILE_TAGS[i]);
node.appendChild(document.createTextNode(temp));
makefileSettings.appendChild(node);
} catch (CoreException ce) {
ErrorReporter.logExceptionStackTrace(ce);
}
}
final String projectLocationStr = project.getLocation().toOSString();
node = document.createElement("projectName");
node.appendChild(document.createTextNode(project.getName()));
makefileSettings.appendChild(node);
node = document.createElement("projectRoot");
node.appendChild(document.createTextNode(project.getLocationURI().toString()));
makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "workingDir"));
node = document.createElement("workingDirectory");
node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, projectLocationStr).toString()));
makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "targetExecutable"));
node = document.createElement("targetExecutable");
node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, projectLocationStr).toString()));
makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "makefileUpdateScript"));
node = document.createElement("MakefileScript");
node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, projectLocationStr).toString()));
makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "makefileFlags"));
node = document.createElement("MakefileFlags");
node.appendChild(document.createTextNode(temp));
makefileSettings.appendChild(node);
final Element projectsElement = document.createElement("ReferencedProjects");
root.appendChild(projectsElement);
final IProject[] referencedProjects = ProjectBasedBuilder.getProjectBasedBuilder(project).getReferencedProjects();
for (IProject tempProject : referencedProjects) {
final Element element = document.createElement("ReferencedProject");
element.setAttribute("name", tempProject.getName());
element.setAttribute("location", tempProject.getLocationURI().toString());
if (win32 && tempProject.getLocation() != null) {
final String converted = PathConverter.convert(tempProject.getLocation().toOSString(), reportDebugInformation, TITANDebugConsole.getConsole());
final Path path = new Path(converted);
element.setAttribute("cygwinPath", URIUtil.toURI(path).toString());
}
projectsElement.appendChild(element);
}
final Element filesElement = document.createElement("Files");
root.appendChild(filesElement);
final TITANBuilderResourceVisitor visitor = ProjectBasedBuilder.getProjectBasedBuilder(project).getResourceVisitor();
final Map<String, IFile> files = visitor.getFiles();
for (IFile file : files.values()) {
final Element element = document.createElement("File");
element.setAttribute("path", file.getLocationURI().toString());
if (win32 && file.getLocation() != null) {
final String fileLocation = file.getLocation().toOSString();
final String converted = PathConverter.convert(fileLocation, reportDebugInformation, TITANDebugConsole.getConsole());
if (!converted.equals(fileLocation)) {
final Path path = new Path(converted);
element.setAttribute("cygwinPath", URIUtil.toURI(path).toString());
}
}
element.setAttribute("relativePath", org.eclipse.core.runtime.URIUtil.makeRelative(file.getLocationURI(), project.getLocationURI()).toString());
filesElement.appendChild(element);
}
final Map<String, IFile> contralStorageFiles = visitor.getCentralStorageFiles();
for (IFile file : contralStorageFiles.values()) {
final Element element = document.createElement("File");
final String fileLocation = file.getLocation().toString();
element.setAttribute("path", fileLocation);
if (win32 && file.getLocation() != null) {
final String converted = PathConverter.convert(fileLocation, reportDebugInformation, TITANDebugConsole.getConsole());
if (!converted.equals(fileLocation)) {
final Path path = new Path(converted);
element.setAttribute("cygwinPath", URIUtil.toURI(path).toString());
}
}
element.setAttribute("relativePath", org.eclipse.core.runtime.URIUtil.makeRelative(file.getLocationURI(), project.getLocationURI()).toString());
element.setAttribute("centralStorage", "true");
filesElement.appendChild(element);
}
final Map<String, IFile> filesOfReferencedProjects = ProjectBasedBuilder.getProjectBasedBuilder(project).getFilesofReferencedProjects();
for (IFile file : filesOfReferencedProjects.values()) {
final Element element = document.createElement("File");
element.setAttribute("path", file.getLocationURI().toString());
if (win32 && file.getLocation() != null) {
final String fileLocation = file.getLocation().toOSString();
final String converted = PathConverter.convert(fileLocation, reportDebugInformation, TITANDebugConsole.getConsole());
if (!converted.equals(fileLocation)) {
final Path path = new Path(converted);
element.setAttribute("cygwinPath", URIUtil.toURI(path).toString());
}
}
element.setAttribute("relativePath", org.eclipse.core.runtime.URIUtil.makeRelative(file.getLocationURI(), project.getLocationURI()).toString());
element.setAttribute("fromProject", file.getProject().getName());
filesElement.appendChild(element);
}
ProjectFileHandler.indentNode(document, document.getDocumentElement(), 1);
System.setProperty(DOMImplementationRegistry.PROPERTY, DOM_IMPLEMENTATION_SOURCE);
DOMImplementationRegistry registry = null;
try {
registry = DOMImplementationRegistry.newInstance();
} catch (ClassNotFoundException ce) {
ErrorReporter.logExceptionStackTrace(ce);
return;
} catch (InstantiationException ie) {
ErrorReporter.logExceptionStackTrace(ie);
return;
} catch (IllegalAccessException iae) {
ErrorReporter.logExceptionStackTrace(iae);
return;
}
// Specifying "LS 3.0" in the features list ensures that the
// DOMImplementation
// object implements the load and save features of the DOM 3.0
// specification.
final DOMImplementation domImpl = registry.getDOMImplementation(LOAD_SAVE_VERSION);
final DOMImplementationLS domImplLS = (DOMImplementationLS) domImpl;
// If the mode is MODE_SYNCHRONOUS, the parse and parseURI
// methods of
// the LSParser
// object return the org.w3c.dom.Document object. If the mode is
// MODE_ASYNCHRONOUS,
// the parse and parseURI methods return null.
final LSParser parser = domImplLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, XML_SCHEMA);
final DOMConfiguration config = parser.getDomConfig();
final DOMErrorHandlerImpl errorHandler = new DOMErrorHandlerImpl();
config.setParameter("error-handler", errorHandler);
config.setParameter("validate", Boolean.TRUE);
config.setParameter("schema-type", XML_SCHEMA);
config.setParameter("validate-if-schema", Boolean.TRUE);
final LSSerializer dom3Writer = domImplLS.createLSSerializer();
final LSOutput output = domImplLS.createLSOutput();
final IFile propertiesFile = project.getFile('/' + "external_build_information.xml");
final File file = propertiesFile.getLocation().toFile();
StringWriter sw = null;
try {
propertiesFile.refreshLocal(IResource.DEPTH_ZERO, null);
sw = new StringWriter();
output.setCharacterStream(sw);
output.setEncoding("UTF-8");
dom3Writer.write(document, output);
final String temporaloutput = sw.getBuffer().toString();
// temporalStorage will hold the contents of the
// existing .TITAN_properties file
String temporalStorage = null;
if (propertiesFile.isAccessible() && file.exists() && file.canRead()) {
final InputStream is = propertiesFile.getContents(true);
final BufferedReader br = new BufferedReader(new InputStreamReader(is));
final StringBuilder sb = new StringBuilder();
boolean firstLine = true;
String line = br.readLine();
while (line != null) {
if (firstLine) {
firstLine = false;
} else {
sb.append('\n');
}
sb.append(line);
line = br.readLine();
}
temporalStorage = sb.toString();
br.close();
}
// one will be overwritten by the new one.
if (temporalStorage == null || !temporalStorage.equals(temporaloutput)) {
if (file.exists()) {
propertiesFile.setContents(new ByteArrayInputStream(temporaloutput.getBytes()), IResource.FORCE | IResource.KEEP_HISTORY, null);
} else {
propertiesFile.create(new ByteArrayInputStream(temporaloutput.getBytes()), IResource.FORCE, null);
}
try {
propertiesFile.refreshLocal(IResource.DEPTH_ZERO, null);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(e);
} finally {
if (sw != null) {
try {
sw.close();
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
}
}
Aggregations