Commit ce8b2c61 authored by balaskoa's avatar balaskoa
Browse files

Bug fix: Bug 505795 - Makefile contains [UNRESOLVED_PATH_VAR] which cause make error


Signed-off-by: default avatarbalaskoa <jeno.balasko@ericsson.com>
parent 816acfe1
###############################################################################
# Copyright (c) 2000-2015 Ericsson Telecom AB
# Copyright (c) 2000-2016 Ericsson Telecom AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
......
......@@ -28,6 +28,8 @@ Export-Package: org.eclipse.titan.common,
org.eclipse.titan.common.path,
org.eclipse.titan.common.product,
org.eclipse.titan.common.utils,
org.eclipse.titan.common.utils.environment,
org.eclipse.titan.common.utils.preferences
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.eclipse.titan.designer.consoles
......@@ -13,18 +13,17 @@ import java.util.Map;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IPathVariableManager;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.common.utils.environment.EnvironmentVariableResolver;
import org.eclipse.titan.common.utils.environment.EnvironmentVariableResolver.VariableNotFoundException;
import org.eclipse.titan.designer.consoles.TITANDebugConsole;
/**
* Utility class to resolve eclipse paths.
*
* @author Kristof Szabados
* */
*/
public final class TITANPathUtilities {
private TITANPathUtilities() {
......@@ -32,17 +31,44 @@ public final class TITANPathUtilities {
}
/**
* Resolves the provided uri relative to the provided base uri.
* Environment variables and path variables will be resolved
* Resolves the provided URI relative to the base URI Environment variables
* and path variables will be resolved if it is possible for all. If all
* variable can be resolved and the path is not absolute then the path will
* be prefixed with the basePath If there is any unresolved variable then
* the pathToBeResolved will not resolved but Unresolved path variables of
* form "[VAR]" will be replaced with "${VAR}. This way the return value of
* this function always can be used to build a Makefile content. This last
* feature is the extra related to resolvePathURI
*
* @param pathToBeResolved
* @param basePath
* @return the resolved string
*/
public static String resolvePathURIForMakefile(final String pathToBeResolved, final String basePath,
final boolean reportDebugInformation) {
URI uri = resolvePathURI(pathToBeResolved, basePath);
if (uri != null) {
return PathConverter.convert(URIUtil.toPath(uri).toOSString(), reportDebugInformation,
TITANDebugConsole.getConsole());
} else {
return EnvironmentVariableResolver.eclipseStyle().replaceEnvVarsWithUnixEnvVars(pathToBeResolved);
}
}
/**
* Resolves the provided uri relative to the provided base uri. Environment
* variables and path variables will be resolved
*
* @param pathToBeResolved
* the path to be resolved.
* @param basePath
* the full path to which the resolvable one might be
* relative to.
* the full path to which the resolvable one might be relative
* to.
*
* @return the resolved uri.
* */
//TODO: call resolvePathURI, it is the same functionality!!!
*/
// TODO: call resolvePathURI, it is the same functionality!!!
public static URI resolvePath(final String pathToBeResolved, final URI basePath) {
Map<?, ?> envVariables;
if (DebugPlugin.getDefault() != null) {
......@@ -51,18 +77,17 @@ public final class TITANPathUtilities {
envVariables = null;
}
String tmp2 = null;
try {
final String tmp1 = EnvironmentVariableResolver.eclipseStyle().resolve(pathToBeResolved, envVariables);
tmp2 = EnvironmentVariableResolver.unixStyle().resolveIgnoreErrors(tmp1, envVariables);
} catch(VariableNotFoundException e){
} catch (VariableNotFoundException e) {
ErrorReporter.logError("There was an error while resolving `" + pathToBeResolved + "'");
return null;
}
final IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
URI uri = URIUtil.toURI(tmp2);//the trailing dots are removed but later corrected
URI uri = URIUtil.toURI(tmp2);// the trailing dots are removed but later corrected
uri = pathVariableManager.resolveURI(uri);
if (basePath != null && uri != null && !uri.isAbsolute()) {
......@@ -82,11 +107,11 @@ public final class TITANPathUtilities {
* @param pathToBeResolved
* the path to be resolved.
* @param basePath
* the full path to which the resolvable one might be
* relative to.
* the full path to which the resolvable one might be relative
* to.
*
* @return the resolved path.
* */
*/
public static URI resolvePathURI(final String pathToBeResolved, final String basePath) {
final DebugPlugin debugPlugin = DebugPlugin.getDefault();
......@@ -97,28 +122,33 @@ public final class TITANPathUtilities {
}
final Map<?, ?> envVariables = debugPlugin.getLaunchManager().getNativeEnvironmentCasePreserved();
return resolvePathURI(pathToBeResolved, basePath, envVariables, ResourcesPlugin.getWorkspace().getPathVariableManager());
return resolvePathURI(pathToBeResolved, basePath, envVariables,
ResourcesPlugin.getWorkspace().getPathVariableManager());
}
/**
* Resolves the provided path relative to the provided base path.
* Resolves the provided path relative to the provided base path. If the
* pathToBeConverted is absolute or the basePath is null or empty string,
* the basePath is not used
*
* @param pathToBeResolved
* the path to be resolved.
* @param basePath
* the full path to which the resolvable one might be
* relative to.
* the full path to which the resolvable one might be relative
* to.
*
* @return the resolved path.
* */
private static URI resolvePathURI(final String pathToBeResolved, final String basePath, final Map<?, ?> envVariables,
final IPathVariableManager pathVariableManager) {
*/
private static URI resolvePathURI(final String pathToBeResolved, final String basePath,
final Map<?, ?> envVariables, final IPathVariableManager pathVariableManager) {
String tmp2 = null;
try {
final String tmp1 = EnvironmentVariableResolver.eclipseStyle().resolve(pathToBeResolved, envVariables);
tmp2 = EnvironmentVariableResolver.unixStyle().resolve(tmp1, envVariables); //In case of error, it throws exception
} catch(VariableNotFoundException e){
ErrorReporter.logWarning("There was an error while resolving `" + pathToBeResolved + "'"); //this is a normal behavior
tmp2 = EnvironmentVariableResolver.unixStyle().resolve(tmp1, envVariables); // In case of error,
// it throws exception
} catch (VariableNotFoundException e) {
ErrorReporter.logWarning("There was an error while resolving `" + pathToBeResolved + "'"); // this is a normal behavior
return null;
}
......@@ -135,35 +165,4 @@ public final class TITANPathUtilities {
return resolvedURI;
}
/**
* Converts the provided uri relative to the provided base uri
* Environment variables and path variables will not be resolved.
* If the pathToBeConverted is absolute or the basePath is null, the basePath is not used
* @deprecated
* @param pathToBeConverted
* the path to be resolved.
* @param basePath
* the absolute URI with schema part and absolute path
* relative to.
*
* @return the resolved uri.
* */
//not used, TODO: remove it! use resolvePath(String,String)
@Deprecated
public static URI convertToAbsoluteURI(final String pathToBeConverted, final String basePath) {
return convertToAbsoluteURI(pathToBeConverted, URIUtil.toURI(basePath));
}
//not used, TODO: remove it!, use resovePath(String,URI)
@Deprecated
public static URI convertToAbsoluteURI(final String pathToBeConverted, final URI basePath) {
final IPath tmp = new Path(pathToBeConverted);
if( basePath != null && tmp != null && !tmp.isAbsolute()) {
final URI convertedURI = org.eclipse.core.runtime.URIUtil.append(basePath, pathToBeConverted);
if(convertedURI != null) {
return convertedURI;
}
}
return URIUtil.toURI(tmp); //!! wrong if basePath == null && !tmp.isAbsolute() because ../ will be removed !!
}
}
......@@ -66,6 +66,23 @@ public class EnvironmentVariableResolver {
return builder.toString();
}
//prerequisite: eclipseStyle resolver is created
public String replaceEnvVarsWithUnixEnvVars(final String original) {
final Matcher matcher = pattern.matcher(original);
final StringBuffer builder = new StringBuffer(original.length());
boolean result2 = matcher.find();
while (result2) {
final String keyWithStartEnd = matcher.group();
final String key = keyWithStartEnd.substring(variableStart.length(), keyWithStartEnd.length() - 1);
final String result3 = "\\$\\{" + key + "\\}";
matcher.appendReplacement(builder, result3);
result2 = matcher.find();
}
matcher.appendTail(builder);
return builder.toString();
}
public static class VariableNotFoundException extends Exception {
public VariableNotFoundException(final String variableName) {
super("Variable " + variableName + " cannot be resolved.");
......
......@@ -139,28 +139,27 @@ public final class GenerateBuilderInformation extends AbstractHandler implements
}
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");
// temp = TITANPathUtilities.resolvePath(temp,
// project.getLocation().toOSString()).toOSString();
node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString()).toString()));
makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "targetExecutable"));
node = document.createElement("targetExecutable");
// temp = TITANPathUtilities.resolvePath(temp,
// project.getLocation().toOSString()).toOSString();
node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString()).toString()));
makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "makefileUpdateScript"));
node = document.createElement("MakefileScript");
// temp = TITANPathUtilities.resolvePath(temp,
// project.getLocation().toOSString()).toOSString();
node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString()).toString()));
makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "makefileFlags"));
node = document.createElement("MakefileFlags");
node.appendChild(document.createTextNode(temp));
......
......@@ -14,7 +14,6 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -22,7 +21,6 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
......@@ -781,16 +779,12 @@ public final class InternalMakefileGenerator {
} else {
String tempProjectLocation = location.toOSString();
for (String temp : optionList) {
URI uri = TITANPathUtilities.resolvePathURI(temp, tempProjectLocation);
if(uri != null) {
temp = PathConverter.convert(URIUtil.toPath(uri).toOSString(), reportDebugInformation,
TITANDebugConsole.getConsole());
temp = TITANPathUtilities.resolvePathURIForMakefile(temp, tempProjectLocation, reportDebugInformation);
contents.append(" -I").append(temp);
}
}
}
}
}
for (IProject reachableProject : reachableProjects) {
String[] optionList = PreprocessorSymbolsOptionsData.getPreprocessorDefines(reachableProject);
for (String option : optionList) {
......@@ -837,8 +831,7 @@ public final class InternalMakefileGenerator {
} else {
String tempProjectLocation = location.toOSString();
for (String option : optionList) {
URI uri = TITANPathUtilities.resolvePathURI(option, tempProjectLocation);
option = PathConverter.convert(URIUtil.toPath(uri).toOSString(), true, TITANDebugConsole.getConsole());
option = TITANPathUtilities.resolvePathURIForMakefile(option, tempProjectLocation, reportDebugInformation);
contents.append(" -I").append(option);
}
}
......@@ -2114,9 +2107,7 @@ public final class InternalMakefileGenerator {
} else {
String tempProjectLocation = location.toOSString();
for (String option : optionList) {
URI uri = TITANPathUtilities.resolvePathURI(option, tempProjectLocation);
option = PathConverter.convert(URIUtil.toPath(uri).toOSString(), reportDebugInformation,
TITANDebugConsole.getConsole());
option = TITANPathUtilities.resolvePathURIForMakefile(option, tempProjectLocation,reportDebugInformation);
contents.append(' ').append(option);
}
}
......@@ -2140,10 +2131,7 @@ public final class InternalMakefileGenerator {
} else {
String tempProjectLocation = location.toOSString();
for (String temp : optionList) {
URI uri = TITANPathUtilities.resolvePathURI(temp, tempProjectLocation);
if(uri!=null) {
temp = PathConverter.convert(URIUtil.toPath(uri).toOSString(), true, TITANDebugConsole.getConsole());
}
temp = TITANPathUtilities.resolvePathURIForMakefile(temp, tempProjectLocation, reportDebugInformation);
contents.append(" -L").append(temp);
}
}
......@@ -2248,8 +2236,7 @@ public final class InternalMakefileGenerator {
String temp = ResourceUtils.getPersistentProperty(project, ProjectBuildPropertyData.QUALIFIER, MakefileCreationData.TARGET_EXECUTABLE_PROPERTY);
if (temp != null && temp.trim().length() > 0) {
URI resolvedURI = TITANPathUtilities.resolvePathURI(temp, projectLocation);
etsName = PathConverter.convert(URIUtil.toPath(resolvedURI).toOSString(), reportDebugInformation, TITANDebugConsole.getConsole());
etsName = TITANPathUtilities.resolvePathURIForMakefile(temp, projectLocation, reportDebugInformation);
} else {
temp = project.getName();
if (Platform.OS_WIN32.equals(Platform.getOS())) {
......
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