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 # All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0 # are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at # which accompanies this distribution, and is available at
......
...@@ -28,6 +28,8 @@ Export-Package: org.eclipse.titan.common, ...@@ -28,6 +28,8 @@ Export-Package: org.eclipse.titan.common,
org.eclipse.titan.common.path, org.eclipse.titan.common.path,
org.eclipse.titan.common.product, org.eclipse.titan.common.product,
org.eclipse.titan.common.utils, org.eclipse.titan.common.utils,
org.eclipse.titan.common.utils.environment,
org.eclipse.titan.common.utils.preferences org.eclipse.titan.common.utils.preferences
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.eclipse.titan.designer.consoles
...@@ -13,18 +13,17 @@ import java.util.Map; ...@@ -13,18 +13,17 @@ import java.util.Map;
import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IPathVariableManager; import org.eclipse.core.resources.IPathVariableManager;
import org.eclipse.core.resources.ResourcesPlugin; 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.debug.core.DebugPlugin;
import org.eclipse.titan.common.logging.ErrorReporter; import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.common.utils.environment.EnvironmentVariableResolver; import org.eclipse.titan.common.utils.environment.EnvironmentVariableResolver;
import org.eclipse.titan.common.utils.environment.EnvironmentVariableResolver.VariableNotFoundException; import org.eclipse.titan.common.utils.environment.EnvironmentVariableResolver.VariableNotFoundException;
import org.eclipse.titan.designer.consoles.TITANDebugConsole;
/** /**
* Utility class to resolve eclipse paths. * Utility class to resolve eclipse paths.
* *
* @author Kristof Szabados * @author Kristof Szabados
* */ */
public final class TITANPathUtilities { public final class TITANPathUtilities {
private TITANPathUtilities() { private TITANPathUtilities() {
...@@ -32,17 +31,44 @@ public final class TITANPathUtilities { ...@@ -32,17 +31,44 @@ public final class TITANPathUtilities {
} }
/** /**
* Resolves the provided uri relative to the provided base uri. * Resolves the provided URI relative to the base URI Environment variables
* Environment variables and path variables will be resolved * 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 pathToBeResolved
* the path to be resolved.
* @param basePath * @param basePath
* the full path to which the resolvable one might be * @return the resolved string
* relative to. */
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.
* *
* @return the resolved uri. * @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) { public static URI resolvePath(final String pathToBeResolved, final URI basePath) {
Map<?, ?> envVariables; Map<?, ?> envVariables;
if (DebugPlugin.getDefault() != null) { if (DebugPlugin.getDefault() != null) {
...@@ -51,18 +77,17 @@ public final class TITANPathUtilities { ...@@ -51,18 +77,17 @@ public final class TITANPathUtilities {
envVariables = null; envVariables = null;
} }
String tmp2 = null; String tmp2 = null;
try { try {
final String tmp1 = EnvironmentVariableResolver.eclipseStyle().resolve(pathToBeResolved, envVariables); final String tmp1 = EnvironmentVariableResolver.eclipseStyle().resolve(pathToBeResolved, envVariables);
tmp2 = EnvironmentVariableResolver.unixStyle().resolveIgnoreErrors(tmp1, envVariables); tmp2 = EnvironmentVariableResolver.unixStyle().resolveIgnoreErrors(tmp1, envVariables);
} catch(VariableNotFoundException e){ } catch (VariableNotFoundException e) {
ErrorReporter.logError("There was an error while resolving `" + pathToBeResolved + "'"); ErrorReporter.logError("There was an error while resolving `" + pathToBeResolved + "'");
return null; return null;
} }
final IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); 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); uri = pathVariableManager.resolveURI(uri);
if (basePath != null && uri != null && !uri.isAbsolute()) { if (basePath != null && uri != null && !uri.isAbsolute()) {
...@@ -71,7 +96,7 @@ public final class TITANPathUtilities { ...@@ -71,7 +96,7 @@ public final class TITANPathUtilities {
if (temp != null) { if (temp != null) {
uri = URIUtil.toURI(temp); uri = URIUtil.toURI(temp);
} }
} }
return uri; return uri;
} }
...@@ -80,13 +105,13 @@ public final class TITANPathUtilities { ...@@ -80,13 +105,13 @@ public final class TITANPathUtilities {
* Resolves the provided path relative to the provided base path. * Resolves the provided path relative to the provided base path.
* *
* @param pathToBeResolved * @param pathToBeResolved
* the path to be resolved. * the path to be resolved.
* @param basePath * @param basePath
* the full path to which the resolvable one might be * the full path to which the resolvable one might be relative
* relative to. * to.
* *
* @return the resolved path. * @return the resolved path.
* */ */
public static URI resolvePathURI(final String pathToBeResolved, final String basePath) { public static URI resolvePathURI(final String pathToBeResolved, final String basePath) {
final DebugPlugin debugPlugin = DebugPlugin.getDefault(); final DebugPlugin debugPlugin = DebugPlugin.getDefault();
...@@ -97,34 +122,39 @@ public final class TITANPathUtilities { ...@@ -97,34 +122,39 @@ public final class TITANPathUtilities {
} }
final Map<?, ?> envVariables = debugPlugin.getLaunchManager().getNativeEnvironmentCasePreserved(); 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 * @param pathToBeResolved
* the path to be resolved. * the path to be resolved.
* @param basePath * @param basePath
* the full path to which the resolvable one might be * the full path to which the resolvable one might be relative
* relative to. * to.
* *
* @return the resolved path. * @return the resolved path.
* */ */
private static URI resolvePathURI(final String pathToBeResolved, final String basePath, final Map<?, ?> envVariables, private static URI resolvePathURI(final String pathToBeResolved, final String basePath,
final IPathVariableManager pathVariableManager) { final Map<?, ?> envVariables, final IPathVariableManager pathVariableManager) {
String tmp2 = null; String tmp2 = null;
try { try {
final String tmp1 = EnvironmentVariableResolver.eclipseStyle().resolve(pathToBeResolved, envVariables); final String tmp1 = EnvironmentVariableResolver.eclipseStyle().resolve(pathToBeResolved, envVariables);
tmp2 = EnvironmentVariableResolver.unixStyle().resolve(tmp1, envVariables); //In case of error, it throws exception tmp2 = EnvironmentVariableResolver.unixStyle().resolve(tmp1, envVariables); // In case of error,
} catch(VariableNotFoundException e){ // it throws exception
ErrorReporter.logWarning("There was an error while resolving `" + pathToBeResolved + "'"); //this is a normal behavior } catch (VariableNotFoundException e) {
ErrorReporter.logWarning("There was an error while resolving `" + pathToBeResolved + "'"); // this is a normal behavior
return null; return null;
} }
URI uri = URIUtil.toURI(tmp2); URI uri = URIUtil.toURI(tmp2);
URI resolvedURI = pathVariableManager.resolveURI(uri); URI resolvedURI = pathVariableManager.resolveURI(uri);
if (basePath != null && !"".equals(basePath) && !resolvedURI.isAbsolute()) { if (basePath != null && !"".equals(basePath) && !resolvedURI.isAbsolute()) {
final String temp = PathUtil.getAbsolutePath(basePath, tmp2); final String temp = PathUtil.getAbsolutePath(basePath, tmp2);
if (temp != null) { if (temp != null) {
...@@ -135,35 +165,4 @@ public final class TITANPathUtilities { ...@@ -135,35 +165,4 @@ public final class TITANPathUtilities {
return resolvedURI; 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 { ...@@ -66,6 +66,23 @@ public class EnvironmentVariableResolver {
return builder.toString(); 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 static class VariableNotFoundException extends Exception {
public VariableNotFoundException(final String variableName) { public VariableNotFoundException(final String variableName) {
super("Variable " + variableName + " cannot be resolved."); super("Variable " + variableName + " cannot be resolved.");
......
...@@ -139,28 +139,27 @@ public final class GenerateBuilderInformation extends AbstractHandler implements ...@@ -139,28 +139,27 @@ public final class GenerateBuilderInformation extends AbstractHandler implements
} }
node = document.createElement("projectName"); node = document.createElement("projectName");
node.appendChild(document.createTextNode(project.getName())); node.appendChild(document.createTextNode(project.getName()));
makefileSettings.appendChild(node); makefileSettings.appendChild(node);
node = document.createElement("projectRoot"); node = document.createElement("projectRoot");
node.appendChild(document.createTextNode(project.getLocationURI().toString())); node.appendChild(document.createTextNode(project.getLocationURI().toString()));
makefileSettings.appendChild(node); makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "workingDir")); temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "workingDir"));
node = document.createElement("workingDirectory"); node = document.createElement("workingDirectory");
// temp = TITANPathUtilities.resolvePath(temp,
// project.getLocation().toOSString()).toOSString();
node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString()).toString())); node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString()).toString()));
makefileSettings.appendChild(node); makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "targetExecutable")); temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "targetExecutable"));
node = document.createElement("targetExecutable"); node = document.createElement("targetExecutable");
// temp = TITANPathUtilities.resolvePath(temp,
// project.getLocation().toOSString()).toOSString();
node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString()).toString())); node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString()).toString()));
makefileSettings.appendChild(node); makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "makefileUpdateScript")); temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "makefileUpdateScript"));
node = document.createElement("MakefileScript"); node = document.createElement("MakefileScript");
// temp = TITANPathUtilities.resolvePath(temp,
// project.getLocation().toOSString()).toOSString();
node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString()).toString())); node.appendChild(document.createTextNode(TITANPathUtilities.resolvePathURI(temp, project.getLocation().toOSString()).toString()));
makefileSettings.appendChild(node); makefileSettings.appendChild(node);
temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "makefileFlags")); temp = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "makefileFlags"));
node = document.createElement("MakefileFlags"); node = document.createElement("MakefileFlags");
node.appendChild(document.createTextNode(temp)); node.appendChild(document.createTextNode(temp));
......
...@@ -14,7 +14,6 @@ import java.io.FileNotFoundException; ...@@ -14,7 +14,6 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -22,7 +21,6 @@ import java.util.Collections; ...@@ -22,7 +21,6 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
...@@ -781,12 +779,8 @@ public final class InternalMakefileGenerator { ...@@ -781,12 +779,8 @@ public final class InternalMakefileGenerator {
} else { } else {
String tempProjectLocation = location.toOSString(); String tempProjectLocation = location.toOSString();
for (String temp : optionList) { for (String temp : optionList) {
URI uri = TITANPathUtilities.resolvePathURI(temp, tempProjectLocation); temp = TITANPathUtilities.resolvePathURIForMakefile(temp, tempProjectLocation, reportDebugInformation);
if(uri != null) { contents.append(" -I").append(temp);
temp = PathConverter.convert(URIUtil.toPath(uri).toOSString(), reportDebugInformation,
TITANDebugConsole.getConsole());
contents.append(" -I").append(temp);
}
} }
} }
} }
...@@ -837,8 +831,7 @@ public final class InternalMakefileGenerator { ...@@ -837,8 +831,7 @@ public final class InternalMakefileGenerator {
} else { } else {
String tempProjectLocation = location.toOSString(); String tempProjectLocation = location.toOSString();
for (String option : optionList) { for (String option : optionList) {
URI uri = TITANPathUtilities.resolvePathURI(option, tempProjectLocation); option = TITANPathUtilities.resolvePathURIForMakefile(option, tempProjectLocation, reportDebugInformation);
option = PathConverter.convert(URIUtil.toPath(uri).toOSString(), true, TITANDebugConsole.getConsole());
contents.append(" -I").append(option); contents.append(" -I").append(option);
} }
} }
...@@ -2114,9 +2107,7 @@ public final class InternalMakefileGenerator { ...@@ -2114,9 +2107,7 @@ public final class InternalMakefileGenerator {
} else { } else {
String tempProjectLocation = location.toOSString(); String tempProjectLocation = location.toOSString();
for (String option : optionList) { for (String option : optionList) {
URI uri = TITANPathUtilities.resolvePathURI(option, tempProjectLocation); option = TITANPathUtilities.resolvePathURIForMakefile(option, tempProjectLocation,reportDebugInformation);
option = PathConverter.convert(URIUtil.toPath(uri).toOSString(), reportDebugInformation,
TITANDebugConsole.getConsole());
contents.append(' ').append(option); contents.append(' ').append(option);
} }
} }
...@@ -2140,10 +2131,7 @@ public final class InternalMakefileGenerator { ...@@ -2140,10 +2131,7 @@ public final class InternalMakefileGenerator {
} else { } else {
String tempProjectLocation = location.toOSString(); String tempProjectLocation = location.toOSString();
for (String temp : optionList) { for (String temp : optionList) {
URI uri = TITANPathUtilities.resolvePathURI(temp, tempProjectLocation); temp = TITANPathUtilities.resolvePathURIForMakefile(temp, tempProjectLocation, reportDebugInformation);
if(uri!=null) {
temp = PathConverter.convert(URIUtil.toPath(uri).toOSString(), true, TITANDebugConsole.getConsole());
}
contents.append(" -L").append(temp); contents.append(" -L").append(temp);
} }
} }
...@@ -2248,8 +2236,7 @@ public final class InternalMakefileGenerator { ...@@ -2248,8 +2236,7 @@ public final class InternalMakefileGenerator {
String temp = ResourceUtils.getPersistentProperty(project, ProjectBuildPropertyData.QUALIFIER, MakefileCreationData.TARGET_EXECUTABLE_PROPERTY); String temp = ResourceUtils.getPersistentProperty(project, ProjectBuildPropertyData.QUALIFIER, MakefileCreationData.TARGET_EXECUTABLE_PROPERTY);
if (temp != null && temp.trim().length() > 0) { if (temp != null && temp.trim().length() > 0) {
URI resolvedURI = TITANPathUtilities.resolvePathURI(temp, projectLocation); etsName = TITANPathUtilities.resolvePathURIForMakefile(temp, projectLocation, reportDebugInformation);
etsName = PathConverter.convert(URIUtil.toPath(resolvedURI).toOSString(), reportDebugInformation, TITANDebugConsole.getConsole());
} else { } else {
temp = project.getName(); temp = project.getName();
if (Platform.OS_WIN32.equals(Platform.getOS())) { 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