1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Initial check-in for the build environment, macros and "isSupported" tests provided by Krasilnikov Oleg

This commit is contained in:
Mikhail Sennikovsky 2005-06-09 10:50:28 +00:00
parent 2e56e1ed70
commit 300ac375d9
6 changed files with 2056 additions and 4 deletions

View file

@ -3589,5 +3589,246 @@
</toolChain>
</configuration>
</projectType>
<!--
Project type for testing Environment variables and Macros features
Note: toolchains are cut and cannot be used for real compilation.
-->
<projectType
id="cdt.managedbuild.target.testenv.exe"
isAbstract="false"
isTest="true"
name="testenv.exe"
projectEnvironmentSupplier="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
projectMacroSupplier="org.eclipse.cdt.managedbuilder.core.tests.TestMacro">
<configuration
name="One"
id="cdt.managedbuild.config.testenv.exe.debug"
cleanCommand="rm -rf"
errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser">
<toolChain
archList="all"
configurationEnvironmentSupplier="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
configurationMacroSupplier="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
id="cdt.managedbuild.toolchain.testenv.exe.debug"
isToolChainSupported="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
name="Dbg ToolChain"
osList="solaris,linux,hpux,aix,qnx"
scannerConfigDiscoveryProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
<targetPlatform
id="cdt.managedbuild.target.testenv.platform.exe.debug"
name="Dbg Platform"
binaryParser="org.eclipse.cdt.core.ELF;org.eclipse.cdt.core.PE"
osList="solaris,linux,hpux,aix,qnx"
archList="all">
</targetPlatform>
<builder
id="cdt.managedbuild.target.testenv.builder.exe.debug"
name="Dbg Builder"
command="make"
arguments="-k"
variableFormat="@="
isVariableCaseSensitive="false"
reservedMacroNames="PATH"
buildfileGenerator="org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator">
</builder>
<tool
id="cdt.managedbuild.tool.testenv.c.compiler.exe.debug"
superClass="cdt.managedbuild.tool.testgnu.c.compiler">
<option
id="macro.test.string"
defaultValue="000"
superClass="gnu.c.compiler.option30.optimization.flags"
value="111"
valueType="string">
</option>
<option
valueType="stringList"
name="ass"
superClass="gnu.cpp.compiler.option30.preprocessor.undef"
id="macro.test.list">
<listOptionValue value="x"/>
<listOptionValue value="y"/>
<listOptionValue value="z"/>
</option>
<envVarBuildPath
pathType="buildpathInclude"
variableList="CFGI,CFG0,PRJI">
</envVarBuildPath>
<envVarBuildPath
pathType="buildpathLibrary"
variableList="CFGL,PRJL">
</envVarBuildPath>
</tool>
<tool
id="cdt.managedbuild.tool.testenv.cpp.compiler.exe.debug"
superClass="cdt.managedbuild.tool.testgnu.cpp.compiler">
</tool>
</toolChain>
</configuration>
<configuration
name="Two"
id="cdt.managedbuild.config.testenv.exe.release"
cleanCommand="rm -rf"
errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser">
<toolChain
archList="all"
configurationMacroSupplier="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
id="cdt.managedbuild.toolchain.testenv.exe.release"
isToolChainSupported="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
name="Rel ToolChain"
osList="solaris,linux,hpux,aix,qnx"
scannerConfigDiscoveryProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
<targetPlatform
id="cdt.managedbuild.target.testenv.platform.exe.release"
name="Rel Platform"
binaryParser="org.eclipse.cdt.core.ELF;org.eclipse.cdt.core.PE"
osList="solaris,linux,hpux,aix,qnx"
archList="all">
</targetPlatform>
<builder
id="cdt.managedbuild.target.testenv.builder.exe.release"
name="Rel Builder"
command="make"
isVariableCaseSensitive="true"
macroInputFileNameValue="$(notdir $&lt;)"
macroInputFileExtValue="$(suffix $(notdir $&lt;))"
macroInputFileBaseNameValue="$(basename $(notdir $&lt;))"
macroInputFileRelPathValue="$&lt;"
macroInputDirRelPathValue="$(dir $&lt;)"
macroOutputFileNameValue="$(notdir $@)"
macroOutputFileExtValue="$(suffix $(notdir $@))"
macroOutputFileBaseNameValue="$(basename $(notdir $@))"
macroOutputFileRelPathValue="$@"
macroOutputDirRelPathValue="$(dir $@)"
arguments="-k">
</builder>
<tool
id="cdt.managedbuild.tool.testenv.c.compiler.exe.release"
superClass="cdt.managedbuild.tool.testgnu.c.compiler">
<envVarBuildPath
pathType="buildpathInclude"
variableList="CFGI,CFG1,PRJI">
</envVarBuildPath>
<envVarBuildPath
pathType="buildpathLibrary"
variableList="CFGL,PRJL">
</envVarBuildPath>
</tool>
</toolChain>
</configuration>
<configuration
name="Three"
id="cdt.managedbuild.config.testenv.exe.xz"
cleanCommand="rm -rf">
<toolChain
configurationMacroSupplier="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
id="cdt.managedbuild.toolchain.testenv.exe.xz"
isToolChainSupported="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
name="Three ToolChain"
scannerConfigDiscoveryProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
<targetPlatform
id="cdt.managedbuild.target.testenv.platform.exe.xz"
name="xz Platform">
</targetPlatform>
<builder
id="cdt.managedbuild.target.testenv.builder.exe.xz"
name="XZ Builder"
command="make"
isVariableCaseSensitive="false"
variableFormat="@="
reservedMacroNameSupplier="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
arguments="-k">
</builder>
<tool
id="cdt.managedbuild.tool.testenv.c.compiler.exe.xz"
superClass="cdt.managedbuild.tool.testgnu.c.compiler">
</tool>
</toolChain>
</configuration>
<configuration
name="Four"
id="cdt.managedbuild.config.testenv.exe.min">
<toolChain
id="cdt.managedbuild.toolchain.testenv.exe.min"
isToolChainSupported="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
name="Three ToolChain">
<targetPlatform
id="cdt.managedbuild.target.testenv.platform.exe.min"
name="Rel Platform">
</targetPlatform>
<builder
id="cdt.managedbuild.target.testenv.builder.exe.min"
name="Min Builder"
command="make"
isVariableCaseSensitive="true"
variableFormat="@=">
</builder>
<tool
id="cdt.managedbuild.tool.testenv.c.compiler.exe.min"
superClass="cdt.managedbuild.tool.testgnu.c.compiler">
</tool>
</toolChain>
</configuration>
<configuration
name="Five"
id="cdt.managedbuild.config.testenv.exe.five"
cleanCommand="rm -rf"
errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser">
<toolChain
archList="all"
configurationEnvironmentSupplier="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
configurationMacroSupplier="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
id="cdt.managedbuild.toolchain.testenv.exe.five"
isToolChainSupported="org.eclipse.cdt.managedbuilder.core.tests.TestMacro"
name="Dbg ToolChain"
osList="solaris,linux,hpux,aix,qnx"
scannerConfigDiscoveryProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
<targetPlatform
id="cdt.managedbuild.target.testenv.platform.exe.five"
name="Dbg Platform"
binaryParser="org.eclipse.cdt.core.ELF;org.eclipse.cdt.core.PE"
osList="solaris,linux,hpux,aix,qnx"
archList="all">
</targetPlatform>
<builder
id="cdt.managedbuild.target.testenv.builder.exe.five"
name="Dbg Builder"
command="make"
arguments="-k"
variableFormat="@="
isVariableCaseSensitive="false"
reservedMacroNames="PATH"
buildfileGenerator="org.eclipse.cdt.managedbuilder.core.tests.TestMacro">
</builder>
<tool
id="cdt.managedbuild.tool.testenv.c.compiler.exe.five"
superClass="cdt.managedbuild.tool.testgnu.c.compiler">
<option
id="macro.test.string1"
defaultValue="000"
superClass="gnu.c.compiler.option30.optimization.flags"
value="111"
valueType="string">
</option>
<option
valueType="stringList"
name="ass"
superClass="gnu.cpp.compiler.option30.preprocessor.undef"
id="macro.test.list1">
<listOptionValue value="x"/>
<listOptionValue value="y"/>
<listOptionValue value="z"/>
</option>
</tool>
<tool
id="cdt.managedbuild.tool.testenv.cpp.compiler.exe.five"
superClass="cdt.managedbuild.tool.testgnu.cpp.compiler">
</tool>
</toolChain>
</configuration>
</projectType>
</extension>
</plugin>

View file

@ -10,19 +10,22 @@
**********************************************************************/
package org.eclipse.cdt.managedbuilder.tests.suite;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCoreTests_SharedToolOptions;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCoreTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCoreTests20;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildCoreTests_SharedToolOptions;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildEnvironmentTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildMacrosTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedBuildTCSupportedTest;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedCommandLineGeneratorTest;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedProject21MakefileTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedProject30MakefileTests;
import org.eclipse.cdt.managedbuilder.core.tests.ManagedProjectUpdateTests;
import org.eclipse.cdt.managedbuilder.core.tests.ResourceBuildCoreTests;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
*
*/
@ -49,6 +52,9 @@ public class AllManagedBuildTests {
suite.addTest(ManagedProject21MakefileTests.suite());
suite.addTest(ManagedProject30MakefileTests.suite());
suite.addTest(ManagedBuildCoreTests_SharedToolOptions.suite());
suite.addTest(ManagedBuildEnvironmentTests.suite());
suite.addTest(ManagedBuildMacrosTests.suite());
suite.addTest(ManagedBuildTCSupportedTest.suite());
//$JUnit-END$
return suite;
}

View file

@ -0,0 +1,599 @@
/**********************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentBuildPathsChangeListener;
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
import org.eclipse.cdt.managedbuilder.internal.envvar.UserDefinedEnvironmentSupplier;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IncrementalProjectBuilder;
/**
*
* */
public class ManagedBuildEnvironmentTests extends TestCase {
final private String REQUIRED_TYPE = "cdt.managedbuild.target.testgnu.exe"; //$NON-NLS-1$
// test variable names
final private String NAME_CWD = "CWD"; //$NON-NLS-1$
final private String NAME_PWD = "PWD"; //$NON-NLS-1$
final private String NAME_CMN = "COMMON"; //$NON-NLS-1$
final private String NAME_WSP = "WSP"; //$NON-NLS-1$
final private String NAME_PRJI = "PRJI"; //$NON-NLS-1$
final private String NAME_PRJL = "PRJL"; //$NON-NLS-1$
final private String NAME_CFGI = "CFGI"; //$NON-NLS-1$
final private String NAME_CFGL = "CFGL"; //$NON-NLS-1$
final private String NAME_CFGX = "CFGX"; //$NON-NLS-1$
final private String NAME_CFG = "CFG"; //$NON-NLS-1$
final private String NAME_REM1 = "REMTST1";//$NON-NLS-1$
final private String NAME_REM2 = "REMTST2";//$NON-NLS-1$
// test variable values
final private String VAL_CWDPWD = "CWD_&_PWD_should not be changed"; //$NON-NLS-1$
final private String VAL_DUMMY1 = "/a/b/c"; //$NON-NLS-1$
final private String VAL_DUMMY2 = "/d/e/f"; //$NON-NLS-1$
final private String VAL_PRO_INC = "/project/inc"; //$NON-NLS-1$
final private String VAL_PRO_LIB = "/project/lib"; //$NON-NLS-1$
final private String LISTENER_DATA = "O1T1O1O2T2T1O1T1O2T2"; //$NON-NLS-1$
// delimiters
final private String DEL_WIN = ";"; //$NON-NLS-1$
final private String DEL_UNIX = ":"; //$NON-NLS-1$
IEnvironmentVariableProvider envProvider = null;
IWorkspace worksp = null;
IProject proj = null;
IManagedProject mproj = null;
String listenerResult = ""; //$NON-NLS-1$
IEnvironmentBuildPathsChangeListener listener = new IEnvironmentBuildPathsChangeListener(){
public void buildPathsChanged(IConfiguration configuration, int buildPathType){
listenerResult = listenerResult + configuration.getName().charAt(0) + buildPathType;
}
};
public ManagedBuildEnvironmentTests() { super(); }
public ManagedBuildEnvironmentTests(String name) { super(name); }
public static Test suite() {
TestSuite suite = new TestSuite(ManagedBuildEnvironmentTests.class.getName());
suite.addTest(new ManagedBuildEnvironmentTests("testEnvNotDef")); //$NON-NLS-1$
suite.addTest(new ManagedBuildEnvironmentTests("testEnvUpper")); //$NON-NLS-1$
suite.addTest(new ManagedBuildEnvironmentTests("testEnvAppend")); //$NON-NLS-1$
suite.addTest(new ManagedBuildEnvironmentTests("testEnvCWDPWD")); //$NON-NLS-1$
suite.addTest(new ManagedBuildEnvironmentTests("testEnvSuppliers")); //$NON-NLS-1$
suite.addTest(new ManagedBuildEnvironmentTests("testEnvGetPath")); //$NON-NLS-1$
suite.addTest(new ManagedBuildEnvironmentTests("testEnvSubscribe")); //$NON-NLS-1$
suite.addTest(new ManagedBuildEnvironmentTests("testEnvGetParams")); //$NON-NLS-1$
suite.addTest(new ManagedBuildEnvironmentTests("testEnvRemove")); //$NON-NLS-1$
suite.addTest(new ManagedBuildEnvironmentTests("testEnvProvider")); //$NON-NLS-1$
return suite;
}
// Checking behaviour when vars are not defined (except system)
public void testEnvNotDef(){
doInit();
assertNotNull("System vars", envProvider.getVariables(null, true, false)); //$NON-NLS-1$
assertNotNull("Worksp. vars", envProvider.getVariables(worksp, true, false)); //$NON-NLS-1$
assertNotNull("Project vars", envProvider.getVariables(mproj, true, false)); //$NON-NLS-1$
IConfiguration[] cfgs = mproj.getConfigurations();
for (int k=0; k<cfgs.length; k++) {
assertNotNull("Project vars["+k+"]", //$NON-NLS-1$ //$NON-NLS-2$
envProvider.getVariables(cfgs[k], true, false));
}
}
/**
* testEnvUpper - check uplevel variables
* In each context, up-level vars should be returned
*/
public void testEnvUpper(){
doInit();
addTestVariables();
IBuildEnvironmentVariable[] a = envProvider.getVariables(null, true, false);
IBuildEnvironmentVariable[] b = envProvider.getVariables(worksp, true, false);
assertTrue(varListContainNames(a, b));
IBuildEnvironmentVariable[] c = envProvider.getVariables(mproj, true, false);
assertTrue(varListContainNames(b, c));
IConfiguration[] cfgs = mproj.getConfigurations();
for (int k=0; k<cfgs.length; k++) {
IBuildEnvironmentVariable[] d = envProvider.getVariables(cfgs[k], true, false);
assertTrue(varListContainNames(c, d));
}
}
/**
*
*
*/
public void testEnvAppend(){
doInit();
IBuildEnvironmentVariable a = envProvider.getVariable(NAME_CMN, worksp, true, false);
assertEquals(NAME_WSP, a.getValue());
assertNotNull(a = envProvider.getVariable(NAME_CMN, mproj, true, false));
assertEquals(NAME_WSP+DEL_UNIX+NAME_PRJI, a.getValue());
IConfiguration cfg = mproj.getConfigurations()[0];
assertNotNull(a = envProvider.getVariable(NAME_CMN, cfg, true, false));
assertEquals(NAME_WSP+DEL_UNIX+NAME_PRJI+DEL_UNIX+NAME_CFGI, a.getValue());
}
/**
*
*
*/
public void testEnvCWDPWD(){
doInit();
IConfiguration cfg = mproj.getConfigurations()[0];
// CWD/PWD vars should NOT be overwritten anywhere
assertNull(envProvider.getVariable(NAME_CWD, worksp, true, false));
assertNull(envProvider.getVariable(NAME_CWD, mproj, true, false));
IBuildEnvironmentVariable a = envProvider.getVariable(NAME_CWD, cfg, true, false);
assertNotNull(a);
if (VAL_CWDPWD.equals(a.getValue())) fail("CWD should not be rewritten !"); //$NON-NLS-1$
assertNull(envProvider.getVariable(NAME_PWD, worksp, true, false));
assertNull(envProvider.getVariable(NAME_PWD, mproj, true, false));
a = envProvider.getVariable(NAME_PWD, cfg, true, false);
assertNotNull(a);
if (VAL_CWDPWD.equals(a.getValue())) fail("PWD should not be rewritten !"); //$NON-NLS-1$
// try to delete: should fail
UserDefinedEnvironmentSupplier usup = getSupplier(cfg, cfg.getName());
assertNull(usup.deleteVariable(NAME_CWD, cfg));
assertNull(usup.deleteVariable(NAME_PWD, cfg));
assertNotNull(envProvider.getVariable(NAME_CWD, cfg, true, false));
assertNotNull(envProvider.getVariable(NAME_PWD, cfg, true, false));
}
public void testEnvSuppliers() {
doInit();
IEnvironmentVariableSupplier[] arrSupSys = envProvider.getSuppliers(null);
assertEquals("System suppliers count not equal to 1", arrSupSys.length, 1); //$NON-NLS-1$
IBuildEnvironmentVariable[] a = arrSupSys[0].getVariables(null);
assertNotNull(a);
IBuildEnvironmentVariable[] b = envProvider.getVariables(null, false, false);
assertTrue(varListContainNames(a, b));
assertTrue(varListContainNames(b, a));
IEnvironmentVariableSupplier[] arrSupWrk = envProvider.getSuppliers(worksp);
assertEquals("Workspace suppliers count not equal to 1", arrSupWrk.length, 1); //$NON-NLS-1$
a = arrSupWrk[0].getVariables(worksp);
assertNotNull(a);
b = envProvider.getVariables(worksp, false, false);
assertTrue(varListContainNames(a, b));
assertTrue(varListContainNames(b, a));
IEnvironmentVariableSupplier[] arrSupPro = envProvider.getSuppliers(mproj);
assertEquals("Project suppliers count not equal to 2", arrSupPro.length, 2); //$NON-NLS-1$
b = envProvider.getVariables(mproj, false, false);
for (int k=0; k<arrSupPro.length; k++ ) {
assertTrue(varListContainNames(arrSupPro[k].getVariables(mproj), b));
}
IConfiguration[] configs = mproj.getConfigurations();
for (int j=0; j<configs.length; j++) {
b = envProvider.getVariables(configs[j], false, false);
IEnvironmentVariableSupplier[] arrSupCfg = envProvider.getSuppliers(configs[j]);
assertEquals("Configuration suppliers count not equal to 3", arrSupCfg.length, 3); //$NON-NLS-1$
for (int k=0; k<arrSupCfg.length; k++ ) {
assertTrue(varListContainNames(arrSupCfg[k].getVariables(configs[j]), b));
}
}
}
/*
* plugin.xml contents:
<projectType id="cdt.managedbuild.target.testgnu.exe">
...
<configuration name="Dbg"
...
<tool
...
<envVarBuildPath
pathType="buildpathInclude"
variableList="CFGI,CFG0,PRJI">
</envVarBuildPath>
<envVarBuildPath
pathType="buildpathLibrary"
variableList="CFGL,PRJL">
</envVarBuildPath>
...
<configuration name="Rel"
...
<tool
...
<envVarBuildPath
pathType="buildpathInclude"
variableList="CFGI,CFG1,PRJI">
</envVarBuildPath>
<envVarBuildPath
pathType="buildpathLibrary"
variableList="CFGL,PRJL">
</envVarBuildPath>
*/
public void testEnvGetPath(){
doInit();
IConfiguration[] configs = mproj.getConfigurations();
for (int i=0; i<2; i++) { // only 2 first configs are affected
String[] val_inc = {"/config/include/"+i, "/config"+i+"/include", VAL_PRO_INC}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] val_lib = {"/config/lib/"+i, VAL_PRO_LIB}; //$NON-NLS-1$
String[] s1, s2, s3;
s1 = envProvider.getBuildPaths(configs[i], 1); // include
s2 = envProvider.getBuildPaths(configs[i], 2); // library
s3 = envProvider.getBuildPaths(configs[i], 0); // unknown
assertNotNull("Include path is null", s1); //$NON-NLS-1$
assertNotNull("Library path is null", s2); //$NON-NLS-1$
assertNotNull("Bad path type returns null", s3); //$NON-NLS-1$
assertEquals("Include path should contain 3 entries !", s1.length, 3); //$NON-NLS-1$
assertEquals("Library path should contain 2 entries !", s2.length, 2); //$NON-NLS-1$
assertEquals("Request with bad path type should return 0 entries !", s3.length, 0); //$NON-NLS-1$
compareStringLists(configs[i].getName()+"-include", s1, val_inc); //$NON-NLS-1$
compareStringLists(configs[i].getName()+"-library", s2, val_lib); //$NON-NLS-1$
}
}
public void testEnvSubscribe(){
doInit();
IConfiguration[] configs = mproj.getConfigurations();
IConfiguration cfg = configs[0];
UserDefinedEnvironmentSupplier usup = getSupplier(cfg, cfg.getName());
assertNotNull(usup);
try {
usup.deleteVariable(NAME_CFGI,configs[0]);
usup.deleteVariable(NAME_CFGI,configs[1]);
usup.deleteVariable(NAME_CFG+"0",configs[0]);
usup.deleteVariable(NAME_CFG+"1",configs[0]);
usup.deleteVariable(NAME_CFG+"0",configs[1]);
usup.deleteVariable(NAME_CFG+"1",configs[1]);
usup.deleteVariable(NAME_CFGL,configs[0]);
usup.deleteVariable(NAME_CFGL,configs[1]);
usup.deleteVariable(NAME_PRJI,mproj);
usup.deleteVariable(NAME_PRJL,mproj);
usup.deleteVariable(NAME_CFGX,mproj);
listenerResult = ""; //$NON-NLS-1$
envProvider.subscribe(listener);
// should affect config Deb
usup.createVariable(NAME_CFGI,VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[0]);
assertEquals("Step 1", listenerResult, LISTENER_DATA.substring(0,2)); //$NON-NLS-1$
// should affect config Rel
usup.createVariable(NAME_CFGI,VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[1]);
assertEquals("Step 2", listenerResult, LISTENER_DATA.substring(0,4)); //$NON-NLS-1$
// should affect config Deb
usup.createVariable(NAME_CFG+"0",VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[0]); //$NON-NLS-1$
assertEquals("Step 3", listenerResult, LISTENER_DATA.substring(0,6)); //$NON-NLS-1$
// should not affect anything - variable not in path of cfg 0
usup.createVariable(NAME_CFG+"1",VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[0]); //$NON-NLS-1$
assertEquals("Step 4", listenerResult, LISTENER_DATA.substring(0,6)); //$NON-NLS-1$
// should affect config Deb
usup.createVariable(NAME_CFGL,VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[0]);
assertEquals("Step 5", listenerResult, LISTENER_DATA.substring(0,8)); //$NON-NLS-1$
// should affect config Rel
usup.createVariable(NAME_CFGL,VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[1]);
assertEquals("Step 6", listenerResult, LISTENER_DATA.substring(0,10)); //$NON-NLS-1$
// should not affect anything - variable not in path of cfg 1
usup.createVariable(NAME_CFG+"0",VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[1]); //$NON-NLS-1$
assertEquals("Step 7", listenerResult, LISTENER_DATA.substring(0,10)); //$NON-NLS-1$
// should affect config Rel
usup.createVariable(NAME_CFG+"1",VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[1]); //$NON-NLS-1$
assertEquals("Step 8", listenerResult, LISTENER_DATA.substring(0,12)); //$NON-NLS-1$
// should affect both configurations
usup.createVariable(NAME_PRJI,VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, mproj);
assertEquals("Step 9", listenerResult, LISTENER_DATA.substring(0,16)); //$NON-NLS-1$
// should affect both configurations
usup.createVariable(NAME_PRJL,VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, mproj);
assertEquals("Step 10", listenerResult, LISTENER_DATA); //$NON-NLS-1$
// should not affect anything - no changes
usup.createVariable(NAME_PRJL,VAL_DUMMY2,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, mproj);
assertEquals("Step 11", listenerResult, LISTENER_DATA); //$NON-NLS-1$
// should not affect anything - variable not in path
usup.createVariable(NAME_CFGX,VAL_DUMMY2, IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, mproj);
assertEquals("Step 12", listenerResult, LISTENER_DATA); //$NON-NLS-1$
envProvider.unsubscribe(listener);
// should NOT affect anything - subscription cancelled
usup.createVariable(NAME_PRJI,VAL_DUMMY1,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, mproj);
usup.createVariable(NAME_CFGI,VAL_DUMMY1,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[0]);
usup.createVariable(NAME_CFGI,VAL_DUMMY1,IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, configs[1]);
assertEquals("Step 13", listenerResult, LISTENER_DATA); //$NON-NLS-1$
} catch (Exception e) {
fail("Failed to create configuration vars !"); //$NON-NLS-1$
}
}
/**
*
*
*/
public void testEnvGetParams(){
doInit();
IEnvironmentVariableProvider envProvider = ManagedBuildManager.getEnvironmentVariableProvider();
IBuildEnvironmentVariable x = null;
IBuildEnvironmentVariable y = null;
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(envProvider.getDefaultDelimiter(), DEL_WIN);
assertFalse(envProvider.isVariableCaseSensitive());
// these var instances are different although contents is equal.
x = envProvider.getVariable("PATH", mproj, true, false);
assertNotNull(x);
y = envProvider.getVariable("path", mproj, true, false);
assertNotNull(y);
assertEquals(x.getName(), y.getName());
assertEquals(x.getValue(), y.getValue());
} else {
assertEquals(envProvider.getDefaultDelimiter(), DEL_UNIX);
assertTrue(envProvider.isVariableCaseSensitive());
// "path" is different var (may absent);
x = envProvider.getVariable("PATH", mproj, true, false);
assertNotNull(x);
y = envProvider.getVariable("path", mproj, true, false);
if (y != null) {
assertFalse(x.getName().equals(y.getName()));
}
}
}
/**
*
*
*/
public void testEnvRemove(){
doInit();
IEnvironmentVariableProvider env = ManagedBuildManager.getEnvironmentVariableProvider();
UserDefinedEnvironmentSupplier usup = null;
// create vars for removal tests
assertNotNull(usup = getSupplier(worksp, "Workspace")); //$NON-NLS-1$
try {
assertNotNull(usup.createVariable(NAME_REM1, VAL_DUMMY1, IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, worksp));
assertNotNull(usup.createVariable(NAME_REM2, VAL_DUMMY1, IBuildEnvironmentVariable.ENVVAR_REPLACE, DEL_UNIX, worksp));
} catch (Exception e) { fail(e.getLocalizedMessage()); }
assertNotNull(usup = getSupplier(mproj, "Project")); //$NON-NLS-1$
try {
assertNotNull(usup.createVariable(NAME_REM1, VAL_DUMMY2, IBuildEnvironmentVariable.ENVVAR_REMOVE, DEL_UNIX, mproj));
assertNotNull(usup.createVariable(NAME_REM2, VAL_DUMMY2, IBuildEnvironmentVariable.ENVVAR_APPEND, DEL_UNIX, mproj));
} catch (Exception e) { fail(e.getLocalizedMessage()); }
IConfiguration cfg = mproj.getConfigurations()[0];
assertNotNull(usup = getSupplier(cfg, "Configuration 0")); //$NON-NLS-1$
try {
assertNotNull(usup.createVariable(NAME_REM1, VAL_CWDPWD, IBuildEnvironmentVariable.ENVVAR_REMOVE, DEL_UNIX, cfg));
assertNotNull(usup.createVariable(NAME_REM2, VAL_CWDPWD, IBuildEnvironmentVariable.ENVVAR_REMOVE, DEL_UNIX, cfg));
} catch (Exception e) { fail(e.getLocalizedMessage()); }
// Check vars presence/absence on different levels
IBuildEnvironmentVariable a = env.getVariable(NAME_REM1, worksp, true, false);
IBuildEnvironmentVariable b = env.getVariable(NAME_REM2, worksp, true, false);
assertNotNull(a);
assertNotNull(b);
a = env.getVariable(NAME_REM1, mproj, true, false);
b = env.getVariable(NAME_REM2, mproj, true, false);
assertNull(a);
assertNotNull(b);
assertEquals(b.getValue(), VAL_DUMMY1 + DEL_UNIX + VAL_DUMMY2);
a = env.getVariable(NAME_REM1, cfg, true, false);
b = env.getVariable(NAME_REM2, cfg, true, false);
assertNull(a);
assertNull(b);
}
/**
* testEnvProvider() -
*/
public void testEnvProvider() {
doInit();
IBuildEnvironmentVariable a = envProvider.getVariable(TestMacro.PRJ_VAR, mproj, true, false);
assertNotNull(a);
assertEquals(TestMacro.PRJ_VAR + mproj.getName(), a.getValue());
IConfiguration[] cfgs = mproj.getConfigurations();
a = envProvider.getVariable(TestMacro.CFG_VAR, cfgs[0], true, false);
assertNotNull(a);
assertEquals(TestMacro.CFG_VAR + cfgs[0].getName(), a.getValue());
// no provider for another configurations
a = envProvider.getVariable(TestMacro.CFG_VAR, cfgs[1], true, false);
assertNull(a);
// combination user-defined and provided variables
UserDefinedEnvironmentSupplier usup = getSupplier(cfgs[0], cfgs[0].getName());
usup.createVariable(TestMacro.PRJ_VAR, VAL_DUMMY1, IBuildEnvironmentVariable.ENVVAR_PREPEND, DEL_UNIX, cfgs[0]);
a = envProvider.getVariable(TestMacro.PRJ_VAR, cfgs[0], true, false);
assertNotNull(a);
assertEquals(VAL_DUMMY1+DEL_UNIX+TestMacro.PRJ_VAR+mproj.getName(), a.getValue());
}
/**
* This test is not used iun suite. It just prints variabes
*/
public void testEnvPrint(){
doInit();
printVar("s-Var", envProvider.getVariables(null, false, false)); //$NON-NLS-1$
printVar("w-Var", envProvider.getVariables(worksp, false, false)); //$NON-NLS-1$
printVar("p-Var", envProvider.getVariables(mproj, false, false)); //$NON-NLS-1$
IConfiguration[] cfgs = mproj.getConfigurations();
for (int k=0; k<cfgs.length; k++) {
printVar("c[" + k + "]-Var", envProvider.getVariables(cfgs[k], false, false)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
// Create all required user variables
public static UserDefinedEnvironmentSupplier getSupplier(Object obj, String objName) {
IEnvironmentVariableSupplier[] arrSup = null;
arrSup = ManagedBuildManager.getEnvironmentVariableProvider().getSuppliers(obj);
for (int i=0; i<arrSup.length; i++ ) {
if (arrSup[i] instanceof UserDefinedEnvironmentSupplier) {
return (UserDefinedEnvironmentSupplier) arrSup[i];
}
}
fail("Cannot access user variable supplier for " + objName); //$NON-NLS-1$
return null;
}
/**
*
*
* Note: CWD and PWD vars are not allowed to be added/changed
*/
private void addTestVariables() {
final int STD_MODE = IBuildEnvironmentVariable.ENVVAR_REPLACE;
UserDefinedEnvironmentSupplier usup = null;
usup = getSupplier(worksp, "Workspace"); //$NON-NLS-1$
try {
if (usup != null) {
assertNotNull(usup.createVariable(NAME_CMN, NAME_WSP, IBuildEnvironmentVariable.ENVVAR_APPEND, DEL_UNIX, worksp));
assertNotNull(usup.createVariable(NAME_WSP,VAL_DUMMY1, STD_MODE, DEL_UNIX, worksp));
assertNull(usup.createVariable(NAME_CWD,VAL_CWDPWD, STD_MODE, DEL_UNIX, worksp));
assertNull(usup.createVariable(NAME_PWD,VAL_CWDPWD, STD_MODE, DEL_UNIX, worksp));
}
} catch (Exception e) {
fail("Failed to create workspace vars " + e.getLocalizedMessage()); //$NON-NLS-1$
}
usup = getSupplier(mproj, "Project"); //$NON-NLS-1$
try {
if (usup != null) {
assertNotNull(usup.createVariable(NAME_CMN, NAME_PRJI, IBuildEnvironmentVariable.ENVVAR_APPEND, DEL_UNIX, mproj));
assertNotNull(usup.createVariable(NAME_PRJI,VAL_PRO_INC, STD_MODE, DEL_UNIX, mproj));
assertNotNull(usup.createVariable(NAME_PRJL,VAL_PRO_LIB, STD_MODE, DEL_UNIX, mproj));
assertNull(usup.createVariable(NAME_CWD, VAL_CWDPWD, STD_MODE, DEL_UNIX, mproj));
assertNull(usup.createVariable(NAME_PWD, VAL_CWDPWD, STD_MODE, DEL_UNIX, mproj));
}
} catch (Exception e) {
fail("Failed to create project vars " + e.getLocalizedMessage()); //$NON-NLS-1$
}
IConfiguration[] configs = mproj.getConfigurations();
for (int i = 0; i < 2; i++) { // only 2 first configs are affected
IConfiguration cfg = configs[i];
usup = getSupplier(cfg, "Configuration " + cfg.getName()); //$NON-NLS-1$
try {
if (usup != null) {
assertNotNull(usup.createVariable(NAME_CMN, NAME_CFGI, IBuildEnvironmentVariable.ENVVAR_APPEND, DEL_UNIX, cfg));
assertNotNull(usup.createVariable(NAME_CFGI, "/config/include/"+i, STD_MODE, DEL_UNIX, cfg)); //$NON-NLS-1$
assertNotNull(usup.createVariable(NAME_CFG+i,"/config"+i+"/include",STD_MODE, DEL_UNIX, cfg)); //$NON-NLS-1$ //$NON-NLS-2$
assertNotNull(usup.createVariable(NAME_CFGL, "/config/lib/"+i, STD_MODE, DEL_UNIX, cfg)); //$NON-NLS-1$
assertNotNull(usup.createVariable(NAME_CFGX, "/config/unused", STD_MODE, DEL_UNIX, cfg)); //$NON-NLS-1$
assertNull(usup.createVariable(NAME_CWD, VAL_CWDPWD, STD_MODE, DEL_UNIX, cfg));
assertNull(usup.createVariable(NAME_PWD, VAL_CWDPWD, STD_MODE, DEL_UNIX, cfg));
}
} catch (Exception e) {
fail("Failed to create configuration vars for <" + cfg.getName() + "> - "+ e.getLocalizedMessage()); //$NON-NLS-1$ //$NON-NLS-2$
}
}
try {
proj.build(IncrementalProjectBuilder.FULL_BUILD, null);
} catch (Exception e) {}
}
private void doInit() {
envProvider = ManagedBuildManager.getEnvironmentVariableProvider();
assertNotNull(envProvider);
ManagedBuildMacrosTests.createManagedProject("Merde"); //$NON-NLS-1$
proj = ManagedBuildMacrosTests.proj;
assertNotNull(proj);
mproj = ManagedBuildMacrosTests.mproj;
assertNotNull(mproj);
worksp = proj.getWorkspace();
assertNotNull(worksp);
}
/*
* Print contents of env.var array, with given header.
*/
private void printVar(String head, IBuildEnvironmentVariable[] vars) {
if (vars != null) {
if (vars.length > 0) {
for (int i=0; i < vars.length; i++) {
System.out.println(head + "[" + i + "] " + //$NON-NLS-1$ //$NON-NLS-2$
vars[i].getName() + " = " + //$NON-NLS-1$
vars[i].getValue() + " / " + //$NON-NLS-1$
vars[i].getOperation() + vars[i].getDelimiter());
}
} else { System.out.println(head + ": array is empty"); } //$NON-NLS-1$
} else { System.out.println(head + ": array is null"); } //$NON-NLS-1$
}
/*
* check that ALL variables from list "a" have correspondence
* in list "b"
* empty list or null are treated as corresponding to anything
*/
private boolean varListContainNames(IBuildEnvironmentVariable[] a, IBuildEnvironmentVariable[] b) {
if (a == null) return true;
else if (a.length == 0) return true;
else if (b == null) return false;
for (int i=0; i<a.length; i++) {
boolean found = false;
for (int j=0; j<b.length; j++) {
if (a[i].getName().equals(b[j].getName())) {
found = true;
break;
}
}
if (!found) return false;
}
return true;
}
/**
*
* @param head
* @param a
* @param b
*/
private void compareStringLists(String head, String[] a, String[] b) {
long mask =0;
long finalmask = Math.round(Math.pow(2,b.length) - 1);
for (int k=0; k<a.length; k++) {
boolean found = false;
for (int m=0; m<b.length; m++) {
if (a[k].equals(b[m])) {
mask |= 1 << m;
found = true;
break;
}
}
assertTrue(found);
}
assertEquals(mask, finalmask);
}
}

View file

@ -0,0 +1,889 @@
/**********************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
import org.eclipse.cdt.managedbuilder.internal.envvar.UserDefinedEnvironmentSupplier;
import org.eclipse.cdt.managedbuilder.internal.macros.FileContextData;
import org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData;
import org.eclipse.cdt.managedbuilder.internal.macros.UserDefinedMacroSupplier;
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacro;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroSupplier;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
public class ManagedBuildMacrosTests extends TestCase {
static IProject proj = null;
static IManagedProject mproj = null;
IConfiguration[] cfgs = null;
IBuildMacroProvider mp = null;
IWorkspace worksp = null;
boolean windows = false;
boolean print = false; // allows to print most of macros on console
boolean flag = false; // uplevel flag for getMacro/getMacros methods
IBuildMacroSupplier[] ms = null;
public static int functionCalled = 0;
public static final int GET_ONE_PROJECT = 1;
public static final int GET_MANY_PROJECT = 2;
public static final int GET_ONE_CONFIG = 4;
public static final int GET_MANY_CONFIG = 8;
public static final int RESERVED_NAME = 16;
static final String UNKNOWN = "<HZ>"; //$NON-NLS-1$
static final String LISTSEP = "|"; //$NON-NLS-1$
static final String TEST = "TEST"; //$NON-NLS-1$
static final String[] TST = {"DUMMY", "FILETEST", //$NON-NLS-1$ //$NON-NLS-2$
"OPTTEST", "CFGTEST", "PRJTEST", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"WSPTEST", "INSTEST", "ENVTEST"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// used for options testing
final String OPT_IDS = "macro.test.string"; //$NON-NLS-1$
final String OPT_IDL = "macro.test.list"; //$NON-NLS-1$
final String INC_DEF = "${IncludeDefaults}";//$NON-NLS-1$
public ManagedBuildMacrosTests() { super(); }
public ManagedBuildMacrosTests(String name) { super(name); }
public static Test suite() {
TestSuite suite = new TestSuite(ManagedBuildMacrosTests.class.getName());
//$JUnit-BEGIN$
suite.addTest(new ManagedBuildMacrosTests("testMacroConf"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroEEnv"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroInst"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroProj"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroWrks"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroOptS"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroOptL"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroFile"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroContext"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroResolve"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroResolveExceptions"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroResolveLoop"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroResolveMake"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroResolveCase"));//$NON-NLS-1$
suite.addTest(new ManagedBuildMacrosTests("testMacroSave"));//$NON-NLS-1$
//$JUnit-END$
return suite;
}
/**
* testMacroConf()
*/
public void testMacroConf(){
doInit();
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]);
assertNotNull(ms);
assertEquals(ms.length, 4);
assertTrue(addMacro(TEST, IBuildMacro.VALUE_TEXT, TST[IBuildMacroProvider.CONTEXT_CONFIGURATION],
IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]));
functionCalled = 0;
String[] a = printMacros(mp.getMacros(IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0], flag), "Configuration"); //$NON-NLS-1$
assertEquals(GET_MANY_CONFIG, functionCalled);
String[] b = {"ConfigName", "BuildArtifactFileExt", //$NON-NLS-1$ //$NON-NLS-2$
"BuildArtifactFileBaseName", "TargetArchList", //$NON-NLS-1$ //$NON-NLS-2$
"TargetOsList", "BuildArtifactFileName", //$NON-NLS-1$ //$NON-NLS-2$
"PWD", "CWD", "ConfigDescription", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
TEST, "NEW_FOR_CFG" }; //$NON-NLS-1$
assertTrue(arrayContains(b, a));
}
/**
* testMacroEEnv()
*/
public void testMacroEEnv(){
doInit();
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_ECLIPSEENV, null);
assertNotNull(ms);
assertEquals(ms.length, 1);
assertFalse(addMacro(TEST, IBuildMacro.VALUE_TEXT, TST[IBuildMacroProvider.CONTEXT_ECLIPSEENV],
IBuildMacroProvider.CONTEXT_ECLIPSEENV, null));
String[] a = printMacros(mp.getMacros(IBuildMacroProvider.CONTEXT_ECLIPSEENV, null, flag), "EclipseEnv"); //$NON-NLS-1$
String[] b = {"PATH", "USERNAME"}; //$NON-NLS-1$ //$NON-NLS-2$
assertTrue(arrayContains(b, a));
}
/**
* testMacroInst()
*/
public void testMacroInst(){
doInit();
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_INSTALLATIONS, null);
assertNotNull(ms);
assertEquals(ms.length, 1);
assertFalse(addMacro(TEST, IBuildMacro.VALUE_TEXT, TST[IBuildMacroProvider.CONTEXT_INSTALLATIONS],
IBuildMacroProvider.CONTEXT_INSTALLATIONS, null));
String[] a = printMacros(mp.getMacros(IBuildMacroProvider.CONTEXT_INSTALLATIONS, null, flag), "Installations "); //$NON-NLS-1$
String[] b = {"HostArchName", "MBSVersion", //$NON-NLS-1$ //$NON-NLS-2$
"EclipseVersion", "HostOsName", "CDTVersion"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertTrue(arrayContains(b, a));
}
/**
* testMacroProj()
*/
public void testMacroProj(){
doInit();
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_PROJECT, mproj);
assertNotNull(ms);
assertEquals(ms.length, 4);
assertTrue(addMacro(TEST, IBuildMacro.VALUE_TEXT, TST[IBuildMacroProvider.CONTEXT_PROJECT],
IBuildMacroProvider.CONTEXT_PROJECT, mproj));
functionCalled = 0;
String[] a = printMacros(mp.getMacros(IBuildMacroProvider.CONTEXT_PROJECT, mproj, flag), "Project "); //$NON-NLS-1$
assertEquals(GET_MANY_PROJECT, functionCalled);
String[] b = {"ProjDirPath", "ProjName", //$NON-NLS-1$ //$NON-NLS-2$
TEST, "NEW_FOR_PRJ"}; //$NON-NLS-1$
assertTrue(arrayContains(b, a));
}
/**
* testMacroWrks()
*/
public void testMacroWrks(){
doInit();
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_WORKSPACE, worksp);
assertNotNull(ms);
assertEquals(ms.length, 5);
assertTrue(addMacro(TEST, IBuildMacro.VALUE_TEXT, TST[IBuildMacroProvider.CONTEXT_WORKSPACE],
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp));
String[] a = printMacros(mp.getMacros(IBuildMacroProvider.CONTEXT_WORKSPACE, worksp, flag), "Workspace "); //$NON-NLS-1$
String[] b = {"DirectoryDelimiter", "WorkspaceDirPath", //$NON-NLS-1$ //$NON-NLS-2$
"PathDelimiter", TEST}; //$NON-NLS-1$
assertTrue(arrayContains(b, a));
}
/**
* testMacroOptn()
*/
public void testMacroOptS(){
doInit();
IToolChain tc = cfgs[0].getToolChain();
ITool t = cfgs[0].getTools()[0];
IOption opt = t.getOptionById(OPT_IDS);
assertNotNull(opt);
// standard check of suppliers # and attempt to add macro (should fail)
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(opt,tc));
assertNotNull(ms);
assertEquals(ms.length, 1);
assertFalse(addMacro(TEST, IBuildMacro.VALUE_TEXT, TST[IBuildMacroProvider.CONTEXT_OPTION], IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(opt,t)));
// modify value and check that macros is resolved
try {
opt = cfgs[0].setOption(t, opt, "222 " + INC_DEF); //$NON-NLS-1$
String a = mp.resolveValue(opt.getStringValue(), UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(opt,tc));
assertEquals(a, "222 111"); //$NON-NLS-1$
} catch (BuildMacroException e) { fail(e.getLocalizedMessage()); }
catch (BuildException e) { fail(e.getLocalizedMessage()); }
// Create resource configuration
IResourceConfiguration rc = cfgs[0].createResourceConfiguration(getFile());
assertNotNull(rc);
IOption ropt = rc.getTools()[0].getOptionById(OPT_IDS);
try {
ropt = rc.setOption(rc.getTools()[0], ropt, "333 " + INC_DEF); //$NON-NLS-1$
String a = mp.resolveValue(ropt.getStringValue(), UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(opt,tc));
assertEquals(a, "333 111"); //$NON-NLS-1$
} catch (Exception e) { fail(e.getLocalizedMessage()); }
}
public void testMacroOptL(){
doInit();
IToolChain tc = cfgs[0].getToolChain();
ITool t = cfgs[0].getTools()[0];
IOption opt = t.getOptionById(OPT_IDL);
OptionContextData ocd = new OptionContextData(opt,tc);
assertNotNull(opt);
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_OPTION, ocd);
assertNotNull(ms);
assertEquals(ms.length, 1);
try {
String[] set0 = opt.getStringListValue();
assertNotNull(set0);
final String[] set1 = {"new a", "test=${TEST}", INC_DEF, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"${PATH}", "PRJ=${NEW_FOR_PRJ}", "LIST=" + INC_DEF};//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] res1 = {"new a", "test=CFGTEST", "x", "y", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"z", ":", "PRJ=<HZ>", "LIST=x|y|z"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
try {
res1[5] = mp.resolveValue("${PATH}",UNKNOWN,LISTSEP,IBuildMacroProvider.CONTEXT_OPTION, ocd); //$NON-NLS-1$
} catch (BuildMacroException e) { fail(e.getLocalizedMessage()); }
opt = cfgs[0].setOption(t, opt, set1);
assertNotNull(opt);
ArrayList ar = new ArrayList(1);
for (int i=0; i<set1.length; i++) {
try {
String[] aus = mp.resolveStringListValue(set1[i], UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_OPTION, new OptionContextData(opt,tc));
if (aus == null) continue;
for (int j=0; j<aus.length; j++) ar.add(aus[j]);
} catch (BuildMacroException e) { fail(e.getLocalizedMessage()); }
}
String[] res = (String[])ar.toArray(new String[0]);
assertEquals(res.length, res1.length);
for (int i=0; i<res.length; i++) assertEquals(res[i], res1[i]);
} catch (BuildException e) { fail(e.getLocalizedMessage()); }
}
/**
* testMacroFile()
*/
public void testMacroFile(){
final String EIN = "ein.c"; //$NON-NLS-1$
final String AUS = "aus.o"; //$NON-NLS-1$
final String UP2W = "..\\..\\"; //$NON-NLS-1$
final String UP2U = "../../"; //$NON-NLS-1$
final String KLMN = "\\k\\l\\m\\n\\o\\p\\"; //$NON-NLS-1$
final String[] names =
{"InputFileName", "InputFileExt", "InputFileBaseName", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"InputFileRelPath", "InputDirRelPath", //$NON-NLS-1$ //$NON-NLS-2$
"OutputFileName", "OutputFileExt", "OutputFileBaseName",//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"OutputFileRelPath", "OutputDirRelPath"}; //$NON-NLS-1$ //$NON-NLS-2$
String[] values0wAbs =
{"a.f77", "f77", "a", "\\xz\\a.f77", "\\xz\\", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"b.exe", "exe", "b", "\\tmp\\b.exe", "\\tmp\\"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
final String[] values0wRel =
{EIN, "c", "ein", UP2W+EIN, UP2W, //$NON-NLS-1$ //$NON-NLS-2$
AUS, "o", "aus", UP2W+AUS, UP2W}; //$NON-NLS-1$ //$NON-NLS-2$
final String[] values0u =
{EIN, "c", "ein", UP2U+EIN, UP2U, //$NON-NLS-1$ //$NON-NLS-2$
AUS, "o", "aus", UP2U+AUS, UP2U}; //$NON-NLS-1$ //$NON-NLS-2$
final String[] values1 =
{"$(notdir $<)", "$(suffix $(notdir $<))", //$NON-NLS-1$ //$NON-NLS-2$
"$(basename $(notdir $<))", "$<", "$(dir $<)", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"$(notdir $@)", "$(suffix $(notdir $@))", //$NON-NLS-1$ //$NON-NLS-2$
"$(basename $(notdir $@))", "$@", "$(dir $@)"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileContextData fd = null;
doInit();
ITool t = cfgs[0].getTools()[0];
assertNotNull(t);
IOption opt = t.getOptionById(OPT_IDS);
String dir=null;
try {
dir = mp.getMacro("WorkspaceDirPath", IBuildMacroProvider.CONTEXT_WORKSPACE, worksp, flag).getStringValue(); //$NON-NLS-1$
} catch (BuildMacroException e) { fail(e.getLocalizedMessage()); }
IPath p = (new Path(dir)).addTrailingSeparator();
if (windows) {
// check behaviour in case of different disks usage
// config #4 has changed BuilderMakeFileGenerator, #0 has standard one
IBuildEnvironmentVariable cwdvar = ManagedBuildManager.getEnvironmentVariableProvider().getVariable("CWD", cfgs[0], false, true); //$NON-NLS-1$
String dev0 = Path.fromOSString(cwdvar.getValue()).getDevice().toUpperCase();
String dev1 = (dev0.startsWith("C")) ? "D:" : "C:"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
values0wAbs[3] = dev1 + values0wAbs[3];
values0wAbs[4] = dev1 + values0wAbs[4];
values0wAbs[8] = dev1 + values0wAbs[8];
values0wAbs[9] = dev1 + values0wAbs[9];
fd = new FileContextData(new Path(values0wAbs[3]), new Path(values0wAbs[8]),opt,cfgs[0].getToolChain());
for (int i=0; i<names.length; i++)
try {
assertEquals(values0wAbs[i], mp.getMacro(names[i], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
} catch (BuildMacroException e) { fail(e.getLocalizedMessage()); }
// check that relative path are reported OK
fd = new FileContextData(p.append(EIN), p.append(AUS),opt,cfgs[0].getToolChain());
for (int i=0; i<names.length; i++)
try {
assertEquals(values0wRel[i], mp.getMacro(names[i], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
} catch (BuildMacroException e) { fail(e.getLocalizedMessage()); }
//TODO:
// check paths using changed BuilderMakeFileGenerator in cfg "Five"
/*
int index = 4;
ManagedBuildManager.setDefaultConfiguration(proj, cfgs[index]);
OptionContextData op = new OptionContextData(cfgs[index].getTools()[0].getOptions()[0], cfgs[index].getToolChain());
String p0 = dev0 + KLMN;
fd = new FileContextData(new Path(p0+EIN), new Path(p0+AUS), op);
assertNotNull(fd);
//TODO: the same dir, upper dir, lower dir
try {
TestMacro.topBuildDir = Path.fromOSString(p0);
assertEquals(p0+EIN, mp.getMacro(names[3], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
assertEquals(p0, mp.getMacro(names[4], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
assertEquals(p0+AUS, mp.getMacro(names[8], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
assertEquals(p0, mp.getMacro(names[9], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
// p0 = Path.fromOSString(p0).removeLastSegments(2).addTrailingSeparator().toOSString();
// p0 = dev0+KLMN+"x\\";
// TestMacro.topBuildDir = Path.fromOSString(p0);
assertEquals(p0+EIN, mp.getMacro(names[3], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
assertEquals(p0, mp.getMacro(names[4], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
assertEquals(p0+AUS, mp.getMacro(names[8], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
assertEquals(p0, mp.getMacro(names[9], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
} catch (BuildMacroException e) { fail(e.getLocalizedMessage()); }
// */
} else {
// check relative path only
fd = new FileContextData(p.append(EIN), p.append(AUS),opt,cfgs[0].getToolChain());
for (int i=0; i<names.length; i++)
try {
assertEquals(values0u[i], mp.getMacro(names[i], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
} catch (BuildMacroException e) { fail(e.getLocalizedMessage()); }
}
// check supplier's parameters
assertNotNull(fd);
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_FILE, fd);
assertNotNull(ms);
assertEquals(ms.length, 1);
assertFalse(addMacro(TEST, IBuildMacro.VALUE_TEXT,
TST[IBuildMacroProvider.CONTEXT_FILE], IBuildMacroProvider.CONTEXT_FILE, fd));
// For config #3, macros should contain lines specified in plugin.xml
opt = cfgs[3].getTools()[0].getOptions()[0];
fd = new FileContextData(p.append(EIN), p.append(AUS),opt,cfgs[1].getToolChain());
for (int i=0; i<names.length; i++)
try {
assertEquals(values1[i], mp.getMacro(names[i], IBuildMacroProvider.CONTEXT_FILE, fd, flag).getStringValue());
} catch (BuildMacroException e) { fail(e.getLocalizedMessage()); }
}
/**
* testMacroContext()
*/
public void testMacroContext(){
doInit();
IBuildMacro mcfg = mp.getMacro(TEST, IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0], true);
IBuildMacro mprj = mp.getMacro(TEST, IBuildMacroProvider.CONTEXT_PROJECT, mproj, true);
IBuildMacro mwsp = mp.getMacro(TEST, IBuildMacroProvider.CONTEXT_WORKSPACE, worksp, true);
assertNotNull(mcfg);
assertNotNull(mprj);
assertNotNull(mwsp);
try {
assertEquals(mcfg.getStringValue(), TST[IBuildMacroProvider.CONTEXT_CONFIGURATION]);
assertEquals(mprj.getStringValue(), TST[IBuildMacroProvider.CONTEXT_PROJECT]);
assertEquals(mwsp.getStringValue(), TST[IBuildMacroProvider.CONTEXT_WORKSPACE]);
} catch (BuildMacroException e) {
fail(e.getLocalizedMessage());
}
}
/**
* testMacroResolve()
*/
public void testMacroResolve(){
doInit();
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_WORKSPACE, worksp);
assertNotNull(ms);
String[] lst = {"SCHEISE", "MERDE", "SHIT"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertTrue(addMacro("LST", IBuildMacro.VALUE_TEXT_LIST, lst, //$NON-NLS-1$
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp));
assertTrue(addMacro("ONE", IBuildMacro.VALUE_TEXT, "EIN", //$NON-NLS-1$ //$NON-NLS-2$
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp));
//
assertTrue(addMacro("L1", IBuildMacro.VALUE_TEXT, "nested L1-${L2}-L1", //$NON-NLS-1$ //$NON-NLS-2$
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp));
assertTrue(addMacro("L2", IBuildMacro.VALUE_TEXT, "L2-${L3}-L2", //$NON-NLS-1$ //$NON-NLS-2$
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp));
assertTrue(addMacro("L3", IBuildMacro.VALUE_TEXT, "L3-${L4}-L3", //$NON-NLS-1$ //$NON-NLS-2$
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp));
assertTrue(addMacro("L4", IBuildMacro.VALUE_TEXT, "L4", //$NON-NLS-1$ //$NON-NLS-2$
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp));
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_PROJECT, mproj);
assertNotNull(ms);
assertTrue(addMacro("TWO", IBuildMacro.VALUE_TEXT, "ZWEI", //$NON-NLS-1$ //$NON-NLS-2$
IBuildMacroProvider.CONTEXT_PROJECT, mproj));
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]);
assertNotNull(ms);
assertTrue(addMacro("three", IBuildMacro.VALUE_TEXT, "DREI", //$NON-NLS-1$ //$NON-NLS-2$
IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]));
// check normal workflow
try {
final String pattern = "${ONE} - ${TWO} - ${three} -> ${LST}"; //$NON-NLS-1$
String a = mp.resolveValue(pattern, UNKNOWN, LISTSEP,
IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]);
String b = mp.resolveValue(pattern, UNKNOWN, LISTSEP,
IBuildMacroProvider.CONTEXT_PROJECT, mproj);
String c = mp.resolveValue(pattern, UNKNOWN, LISTSEP,
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp);
String d = mp.resolveValue("${L1}", UNKNOWN, LISTSEP, //$NON-NLS-1$
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp);
String e = mp.resolveValue("${one} - ${Two} - ${THREE} -> ${lst}", UNKNOWN, LISTSEP, //$NON-NLS-1$
IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]);
assertEquals(a, "EIN - ZWEI - DREI -> SCHEISE|MERDE|SHIT"); //$NON-NLS-1$
assertEquals(b, "EIN - ZWEI - <HZ> -> SCHEISE|MERDE|SHIT"); //$NON-NLS-1$
assertEquals(c, "EIN - <HZ> - <HZ> -> SCHEISE|MERDE|SHIT"); //$NON-NLS-1$
assertEquals(d, "nested L1-L2-L3-L4-L3-L2-L1"); //$NON-NLS-1$
assertEquals(e, "<HZ> - <HZ> - <HZ> -> <HZ>"); //$NON-NLS-1$
} catch (BuildMacroException e) {
fail("Exception while resolving: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
}
/**
* testMacroResolveExceptions()
*/
public void testMacroResolveExceptions () {
doInit();
boolean exceptionRaised = false;
try { // ZERO is undefined macro
String a = mp.resolveValue("${ONE} - ${ZERO}", null, null, //$NON-NLS-1$
IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]);
} catch (BuildMacroException e) {
exceptionRaised = true;
}
assertTrue("Exception not raised for undefined macro", exceptionRaised); //$NON-NLS-1$
exceptionRaised = false;
try { // delimiter is undefined for list
String a = mp.resolveValue("${LST}", null, null, //$NON-NLS-1$
IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]);
} catch (BuildMacroException e) {
exceptionRaised = true;
}
assertTrue("Exception not raised for undefined delimiter", exceptionRaised); //$NON-NLS-1$
}
/**
* testMacroResolveLoop()
*/
public void testMacroResolveLoop() {
doInit();
int ctx = IBuildMacroProvider.CONTEXT_WORKSPACE;
Object obj = worksp;
ms = mp.getSuppliers(ctx, obj);
assertNotNull(ms);
// check state before macros added (should be OK)
try {
mp.checkIntegrity(ctx, obj);
} catch (BuildMacroException e) {
fail("Macros integrity check is failed"); //$NON-NLS-1$
}
// create macro which references to undefined macro
assertTrue(addMacro("B1", IBuildMacro.VALUE_TEXT, "B1-${B2}", ctx, obj)); //$NON-NLS-1$ //$NON-NLS-2$
rmMacro("B2", ctx, obj); // usually it does not exist, but to be sure... //$NON-NLS-1$
// check state after macro added (should be exception)
try {
mp.checkIntegrity(ctx, obj);
fail("Macros misintegrity (ref to undefined) is not detected"); //$NON-NLS-1$
} catch (BuildMacroException e) {}
// create "dead loop" of nested macros
assertTrue(addMacro("B2", IBuildMacro.VALUE_TEXT, "B2-${B3}", ctx, obj)); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue(addMacro("B3", IBuildMacro.VALUE_TEXT, "B3-${B1}", ctx, obj)); //$NON-NLS-1$ //$NON-NLS-2$
// check state after macros added (should be exception)
try {
mp.checkIntegrity(ctx, obj);
fail("Macros misintegrity (dead loop) is not detected"); //$NON-NLS-1$
} catch (BuildMacroException e) {}
// remove "dead loop" of nested macros
assertTrue(rmMacro("B1", ctx, obj)); //$NON-NLS-1$
assertTrue(rmMacro("B2", ctx, obj)); //$NON-NLS-1$
assertTrue(rmMacro("B3", ctx, obj)); //$NON-NLS-1$
// check state after macros removed (should be OK)
try {
mp.checkIntegrity(ctx, obj);
} catch (BuildMacroException e) {
fail("Macros integrity check is failed " + e.getLocalizedMessage()); //$NON-NLS-1$
}
}
/**
* testMacroResolveMake()
*/
public void testMacroResolveMake(){
final String p1 = "USERNAME: "; //$NON-NLS-1$
final String p2 = "${USERNAME} "; //$NON-NLS-1$
final String p3 = "PATH: "; //$NON-NLS-1$
final String p4 = "${PATH} "; //$NON-NLS-1$
final String p5 = "HostOsName: ${HostOsName} WorkspaceDirPath: ${WorkspaceDirPath}"; //$NON-NLS-1$
final String ein1 = p1 + p2 + p3;
final String ein2 = p4 + p5;
final String ein = ein1 + ein2;
final String aus1 = "@USERNAME "; //$NON-NLS-1$
final String aus2 = "@PATH "; //$NON-NLS-1$
doInit();
// Config #0 contains "variableFormat" macro = "@=". Result: 2 first macros NOT resolved
try {
functionCalled = 0;
String a = mp.resolveValueToMakefileFormat(ein, UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]);
String b = p1 + aus1 + p3 + mp.resolveValue(ein2, UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[0]);
assertEquals(a, b); // Env var names should not be resolved but converted to Makefile format
a = mp.resolveValueToMakefileFormat(ein, UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_PROJECT, mproj);
assertEquals(a, b); // Project context should return the same as default configuration
} catch (BuildMacroException e) {
fail(e.getLocalizedMessage());
}
// Config #1 does not contain "variableFormat" macro. Result: all macros resolved.
try {
String a = mp.resolveValue(ein, UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[1]);
String b = mp.resolveValueToMakefileFormat(ein, UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[1]);
assertEquals(a, b);
} catch (BuildMacroException e) {
fail(e.getLocalizedMessage());
}
// check that "isReservedName" was not called before
assertEquals(functionCalled & RESERVED_NAME, 0);
// Config #2 contains "...Supplier" macro. Result: PATH unresolved, USERNAME resolved.
try {
String a = mp.resolveValue(p1 + p2, UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[2]);
String b = mp.resolveValue(p5, UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[2]);
a = a + p3 + aus2 + b; // USERNAME: xxx PATH: @PATH HostOsName: xxx ...
b = mp.resolveValueToMakefileFormat(ein, UNKNOWN, LISTSEP, IBuildMacroProvider.CONTEXT_CONFIGURATION, cfgs[2]);
assertEquals(a, b);
// check that "isReservedName" has been called
assertEquals(functionCalled & RESERVED_NAME, RESERVED_NAME);
} catch (BuildMacroException e) {
fail(e.getLocalizedMessage());
}
}
/**
* testMacroResolveCase()
*/
public void testMacroResolveCase(){
doInit();
addVars();
final String winOut1 = "@CASETEST uppercase uppercase uppercase"; //$NON-NLS-1$
final String winOut2 = "@CASETEST @CASETEST @CASETEST @CASETEST"; //$NON-NLS-1$
final String unixOut1 = "@CASETEST capitalize lowercase upper2low"; //$NON-NLS-1$
final String unixOut2 = "@CASETEST @CaseTest @casetest @CaSeTeSt"; //$NON-NLS-1$
final String ein = "${CASETEST} ${CaseTest} ${casetest} ${CaSeTeSt}"; //$NON-NLS-1$
final int ctx = IBuildMacroProvider.CONTEXT_CONFIGURATION;
String a=null, b=null;
try {
// Config #0 contains isVariableCaseSensitive = false
a = mp.resolveValueToMakefileFormat(ein, UNKNOWN, LISTSEP, ctx, cfgs[0]);
// Config #3 contains isVariableCaseSensitive = true
b = mp.resolveValueToMakefileFormat(ein, UNKNOWN, LISTSEP, ctx, cfgs[3]);
} catch (BuildMacroException e) {
fail(e.getLocalizedMessage());
}
if (windows) {
assertEquals(a, winOut1);
assertEquals(b, winOut2);
} else { // linux
assertEquals(a, unixOut1);
assertEquals(b, unixOut2);
}
}
/**
* testMacroSave()
*/
public void testMacroSave(){
final String TO_SAVE_P = "TO_SAVE_P"; //$NON-NLS-1$
final String TO_SAVE_W = "TO_SAVE_W"; //$NON-NLS-1$
doInit();
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_PROJECT, mproj);
assertNotNull(ms);
assertTrue(addMacro(TO_SAVE_P, IBuildMacro.VALUE_TEXT, TO_SAVE_P,
IBuildMacroProvider.CONTEXT_PROJECT, mproj));
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_WORKSPACE, worksp);
assertNotNull(ms);
assertTrue(addMacro(TO_SAVE_W, IBuildMacro.VALUE_TEXT, TO_SAVE_W,
IBuildMacroProvider.CONTEXT_WORKSPACE, worksp));
try {
proj.close(null);
proj.open(null);
} catch (CoreException e) {
fail("Failed on project close/open: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_PROJECT, mproj);
assertNotNull(ms);
String[] a = printMacros(mp.getMacros(IBuildMacroProvider.CONTEXT_PROJECT, mproj, flag), TO_SAVE_P);
String[] b1 = {TO_SAVE_P};
assertTrue(arrayContains(b1, a));
ms = mp.getSuppliers(IBuildMacroProvider.CONTEXT_WORKSPACE, worksp);
assertNotNull(ms);
a = printMacros(mp.getMacros(IBuildMacroProvider.CONTEXT_WORKSPACE, worksp, flag), TO_SAVE_W);
String[] b2 = {TO_SAVE_W};
assertTrue(arrayContains(b2, a));
}
/*
* Below are service methods
*/
//TODO: comments for all methods
// returns a list of macro's NAMES (not values).
private String[] printMacros(IBuildMacro[] vars, String head) {
ArrayList ar = new ArrayList(0);
if (vars != null) {
if (vars.length > 0) {
for (int i=0; i < vars.length; i++) {
try {
ar.add(vars[i].getName());
if (!print) continue;
if ((vars[i].getMacroValueType() % 2) == 1) // not-list
//if (vars[i] instanceof EclipseVarMacro) {
if (vars[i].getName().endsWith("prompt")) { //$NON-NLS-1$
System.out.println(head + "[" + i + "] " + //$NON-NLS-1$ //$NON-NLS-2$
vars[i].getName() + " = <UNREACHABLE>"); //$NON-NLS-1$
} else {
System.out.println(head + "[" + i + "] " + //$NON-NLS-1$ //$NON-NLS-2$
vars[i].getName() + " = " + vars[i].getStringValue()); //$NON-NLS-1$
}
else {
System.out.println(head + "[" + i + "] " + //$NON-NLS-1$ //$NON-NLS-2$
vars[i].getName() + ":"); //$NON-NLS-1$
String[] m = vars[i].getStringListValue();
printStrings(m, " "); //$NON-NLS-1$
}
} catch (Exception e) {}
}
} else { if (print) System.out.println(head + ": array is empty"); } //$NON-NLS-1$
} else { if (print) System.out.println(head + ": array is null"); } //$NON-NLS-1$
return (String[])ar.toArray(new String[0]);
}
private void printStrings(String[] vars, String head) {
if (!print) return;
if (vars != null) {
if (vars.length > 0) {
for (int j=0; j<vars.length; j++) System.out.println(head + vars[j]);
} else { System.out.println(head + ": array is empty"); } //$NON-NLS-1$
} else { System.out.println(head + ": array is null"); } //$NON-NLS-1$
}
/* Create new project or get existing one
*
* Sets "proj" "mproj" class variables
*/
static void createManagedProject(String name) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
proj = root.getProject(name);
if (proj.exists()) {
mproj = ManagedBuildManager.getBuildInfo(proj).getManagedProject();
} else {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceDescription workspaceDesc = workspace.getDescription();
workspaceDesc.setAutoBuilding(false);
try {
workspace.setDescription(workspaceDesc);
proj = CCorePlugin.getDefault().createCProject(workspace.newProjectDescription(proj.getName()),
proj, new NullProgressMonitor(), MakeCorePlugin.MAKE_PROJECT_ID);
// add ManagedBuildNature
IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(proj);
info.setValid(true);
ManagedCProjectNature.addManagedNature(proj, null);
ManagedCProjectNature.addManagedBuilder(proj, null);
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(proj, true);
desc.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID);
desc.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, ManagedBuildManager.INTERFACE_IDENTITY);
desc.saveProjectData();
} catch (CoreException e) {
fail("Cannot create project: " + e.getLocalizedMessage()); //$NON-NLS-1$
}
// Call this function just to avoid init problems in getProjectType();
IProjectType[] projTypes = ManagedBuildManager.getDefinedProjectTypes();
IProjectType projType = ManagedBuildManager.getProjectType("cdt.managedbuild.target.testenv.exe"); //$NON-NLS-1$
assertNotNull(projType);
try {
mproj = ManagedBuildManager.createManagedProject(proj, projType);
} catch (BuildException e) {}
ManagedBuildManager.setNewProjectVersion(proj);
IConfiguration[] cfgs = projType.getConfigurations();
IConfiguration defcfg = cfgs.length > 0 ? mproj.createConfiguration(cfgs[0], projType.getId() + ".0") : null; //$NON-NLS-1$
for (int i = 1; i < cfgs.length; ++i) { // sic ! from 1
mproj.createConfiguration(cfgs[i], projType.getId() + "." + i); //$NON-NLS-1$
}
ManagedBuildManager.setDefaultConfiguration(proj, defcfg);
}
// open project w/o progress monitor; no action performed if it's opened
try {
proj.open(null);
} catch (CoreException e) {}
}
/**
* doInit() - call it at the beginning of every test
*
*/
private void doInit() {
createManagedProject("Test"); //$NON-NLS-1$
assertNotNull(proj);
assertNotNull(mproj);
worksp = proj.getWorkspace();
assertNotNull(worksp);
mp = ManagedBuildManager.getBuildMacroProvider();
assertNotNull(mp);
cfgs = mproj.getConfigurations();
assertNotNull(cfgs);
windows = System.getProperty("os.name").toLowerCase().startsWith("windows"); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* arrayContains
* check that ALL variables from list a have correspondence in list b
* @param a
* @param b
* @return
*/
private boolean arrayContains(String[] a, String[] b) {
assertNotNull(a);
assertNotNull(b);
for (int i=0; i<a.length; i++) {
boolean found = false;
for (int j=0; j<b.length; j++) {
if (a[i].equals(b[j])) {
found = true;
break;
}
}
if (!found) return false;
}
return true;
}
/**
* addMacro
* @param name
* @param type
* @param value
* @param context
* @param obj
* @return
*/
private boolean addMacro(String name, int type, String value, int context, Object obj) {
assertNotNull(ms);
for(int i=0; i<ms.length; i++) {
if (ms[i] instanceof UserDefinedMacroSupplier) {
return (((UserDefinedMacroSupplier)ms[i]).createMacro(name,type,value,context,obj) != null);
}
}
return false;
}
/**
* addMacro
* @param name
* @param type
* @param value
* @param context
* @param obj
* @return
*/
private boolean addMacro(String name, int type, String[] value, int context, Object obj) {
assertNotNull(ms);
for(int i=0; i<ms.length; i++) {
if (ms[i] instanceof UserDefinedMacroSupplier) {
return (((UserDefinedMacroSupplier)ms[i]).createMacro(name,type,value,context,obj) != null);
}
}
return false;
}
/**
* rmMacro
* @param name - name of macro
* @param context
* @param obj
* @return
*/
private boolean rmMacro(String name, int context, Object obj) {
assertNotNull(ms);
for(int i=0; i<ms.length; i++) {
if (ms[i] instanceof UserDefinedMacroSupplier) {
return (((UserDefinedMacroSupplier)ms[i]).deleteMacro(name,context,obj) != null);
}
}
return false;
}
/*
* addVars() - adds macros for testMacroResolveCase
*/
private void addVars() {
int app = IBuildEnvironmentVariable.ENVVAR_APPEND;
String del = ""; //$NON-NLS-1$
UserDefinedEnvironmentSupplier usup = null;
usup = ManagedBuildEnvironmentTests.getSupplier(worksp, "Workspace"); //$NON-NLS-1$
if (usup != null) {
try {
usup.createVariable("casetest","lowercase", app, del, worksp ); //$NON-NLS-1$ //$NON-NLS-2$
usup.createVariable("CaseTest","capitalize", app, del, worksp ); //$NON-NLS-1$ //$NON-NLS-2$
usup.createVariable("CaSeTeSt","upper2low", app, del, worksp ); //$NON-NLS-1$ //$NON-NLS-2$
usup.createVariable("CASETEST","uppercase", app, del, worksp ); //$NON-NLS-1$ //$NON-NLS-2$
} catch (Exception e) {
fail("Failed to create workspace vars " + e.getLocalizedMessage()); //$NON-NLS-1$
}
}
}
/*
* getFile() - open or creates sample file in current project
*/
private IFile getFile() {
final String FILENAME = "main.c"; //$NON-NLS-1$
final String FILETEXT = "int main(){\n return 0;\n}"; //$NON-NLS-1$
IFile f = proj.getProject().getFile(FILENAME);
if ( !f.exists() )
try {
f.create( new ByteArrayInputStream(FILETEXT.getBytes() ), false, null );
} catch (CoreException e) { fail(e.getLocalizedMessage()); }
return f;
}
}

View file

@ -0,0 +1,77 @@
/**********************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
/**
*
* */
public class ManagedBuildTCSupportedTest extends TestCase {
public ManagedBuildTCSupportedTest() { super(); }
public ManagedBuildTCSupportedTest(String name) { super(name); }
public static Test suite() {
TestSuite suite = new TestSuite(ManagedBuildTCSupportedTest.class.getName());
suite.addTest(new ManagedBuildTCSupportedTest("testIsSupported")); //$NON-NLS-1$
return suite;
}
/**
* testIsSupported() -
*/
public void testIsSupported() {
ManagedBuildMacrosTests.createManagedProject("Merde"); //$NON-NLS-1$
IManagedProject mproj = ManagedBuildMacrosTests.mproj;
assertNotNull(mproj);
IProjectType pt = mproj.getProjectType();
assertNotNull(pt);
IConfiguration[] cfgs = mproj.getConfigurations();
assertNotNull(cfgs);
IToolChain tc = cfgs[0].getToolChain();
assertNotNull(tc);
// all 4 toolchains are not supported now
for (int i=0; i<cfgs.length; i++)
TestMacro.supported[i] = false;
for (int i=0; i< cfgs.length; i++) {
assertFalse(cfgs[i].getToolChain().isSupported());
assertFalse(cfgs[i].isSupported());
}
// so project type should be not supported
assertFalse(pt.isSupported());
// 1 of 4 toolChains made supported
TestMacro.supported[0] = true;
assertTrue(tc.isSupported());
assertTrue(cfgs[0].isSupported());
for (int i=1; i< cfgs.length; i++)
assertFalse(cfgs[i].isSupported());
assertTrue(pt.isSupported());
// all 4 toolchains are supported now
for (int i=0; i<cfgs.length; i++)
TestMacro.supported[i] = true;
for (int i=0; i<4; i++)
assertTrue(cfgs[i].isSupported());
assertFalse(cfgs[4].isSupported());
assertTrue(pt.isSupported());
}
}

View file

@ -0,0 +1,240 @@
/**********************************************************************
* Copyright (c) 2005 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedIsToolChainSupported;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
import org.eclipse.cdt.managedbuilder.envvar.IProjectEnvironmentVariableSupplier;
import org.eclipse.cdt.managedbuilder.internal.envvar.BuildEnvVar;
import org.eclipse.cdt.managedbuilder.internal.macros.BuildMacro;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacro;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier;
import org.eclipse.cdt.managedbuilder.macros.IProjectBuildMacroSupplier;
import org.eclipse.cdt.managedbuilder.macros.IReservedMacroNameSupplier;
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.PluginVersionIdentifier;
/**
*
*/
/**
*
*
*/
public class TestMacro implements
IConfigurationBuildMacroSupplier,
IProjectBuildMacroSupplier,
IReservedMacroNameSupplier,
IConfigurationEnvironmentVariableSupplier,
IProjectEnvironmentVariableSupplier,
IManagedIsToolChainSupported,
IManagedBuilderMakefileGenerator
{
public static boolean supported[] = {false, false, false, false, false};
public static IPath topBuildDir = null;
public static String CFG_VAR = "CFG_PROVIDER_VAR"; //$NON-NLS-1$
public static String PRJ_VAR = "PRJ_PROVIDER_VAR"; //$NON-NLS-1$
// IConfigurationBuildMacroSupplier
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier#getMacro(java.lang.String, org.eclipse.cdt.managedbuilder.core.IConfiguration, org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider)
*/
public IBuildMacro getMacro(String macroName, IConfiguration configuration,
IBuildMacroProvider provider) {
ManagedBuildMacrosTests.functionCalled |= ManagedBuildMacrosTests.GET_ONE_CONFIG;
IBuildMacro ms = null;
if (!(provider instanceof TestMacro)) {
ms = provider.getMacro(macroName,
IBuildMacroProvider.CONTEXT_CONFIGURATION,
configuration, false);
}
return ms;
}
public IBuildMacro getMacro(String macroName, IManagedProject mproj,
IBuildMacroProvider provider) {
ManagedBuildMacrosTests.functionCalled |= ManagedBuildMacrosTests.GET_ONE_PROJECT;
IBuildMacro ms = null;
if (!(provider instanceof TestMacro)) {
ms = provider.getMacro(macroName,
IBuildMacroProvider.CONTEXT_PROJECT,
mproj, false);
}
return ms;
}
// IProjectBuildMacroSupplier
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.macros.IConfigurationBuildMacroSupplier#getMacros(org.eclipse.cdt.managedbuilder.core.IConfiguration, org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider)
*/
public IBuildMacro[] getMacros(IConfiguration configuration,
IBuildMacroProvider provider) {
ManagedBuildMacrosTests.functionCalled |= ManagedBuildMacrosTests.GET_MANY_CONFIG;
IBuildMacro[] ms = null;
if (!(provider instanceof TestMacro)) {
ms = provider.getMacros(IBuildMacroProvider.CONTEXT_CONFIGURATION, configuration, false);
IBuildMacro[] newms = null;
if (ms != null && ms.length > 0) {
newms = new BuildMacro[ms.length + 1];
System.arraycopy(ms, 0, newms, 0, ms.length);
} else {
newms = new BuildMacro[1];
}
newms[ms.length] = new BuildMacro("NEW_FOR_CFG", 1, "NewMacrosForConfigContext"); //$NON-NLS-1$ //$NON-NLS-2$
return newms;
}
return null;
}
/**
*
*/
public IBuildMacro[] getMacros(IManagedProject mproj,
IBuildMacroProvider provider) {
ManagedBuildMacrosTests.functionCalled |= ManagedBuildMacrosTests.GET_MANY_PROJECT;
IBuildMacro[] ms = null;
if (!(provider instanceof TestMacro)) {
ms = provider.getMacros(IBuildMacroProvider.CONTEXT_PROJECT, mproj, false);
IBuildMacro[] newms = null;
if (ms != null && ms.length > 0) {
newms = new BuildMacro[ms.length + 1];
System.arraycopy(ms, 0, newms, 0, ms.length);
} else {
newms = new BuildMacro[1];
}
newms[newms.length - 1] = new BuildMacro("NEW_FOR_PRJ", 1, "NewMacrosForProjectContext"); //$NON-NLS-1$ //$NON-NLS-2$
return newms;
}
return null;
}
// IReservedMacroNameSupplier
/**
*
*/
public boolean isReservedName(String macroName, IConfiguration configuration) {
ManagedBuildMacrosTests.functionCalled |= ManagedBuildMacrosTests.RESERVED_NAME;
if (macroName.equalsIgnoreCase("USERNAME")) return true; //$NON-NLS-1$
return false;
}
// IConfigurationEnvironmentVariableSupplier
/**
*
*/
public IBuildEnvironmentVariable getVariable(String variableName,
IConfiguration configuration,
IEnvironmentVariableProvider provider) {
if (CFG_VAR.equals(variableName)) {
return new BuildEnvVar(CFG_VAR, CFG_VAR + configuration.getName());
} else
return null;
}
/**
*
*/
public IBuildEnvironmentVariable[] getVariables (IConfiguration configuration,
IEnvironmentVariableProvider provider) {
IBuildEnvironmentVariable v = getVariable(CFG_VAR, configuration, provider);
if (v != null) {
IBuildEnvironmentVariable[] vs = new IBuildEnvironmentVariable[1];
vs[0] = v;
return(vs);
} else
return null;
}
// IProjectEnvironmentVariableSupplier
/**
*
*/
public IBuildEnvironmentVariable getVariable(String variableName,
IManagedProject project,
IEnvironmentVariableProvider provider) {
if (PRJ_VAR.equals(variableName)) {
return new BuildEnvVar(PRJ_VAR, PRJ_VAR + project.getName());
} else
return null;
}
/**
*
*/
public IBuildEnvironmentVariable[] getVariables (IManagedProject project,
IEnvironmentVariableProvider provider) {
IBuildEnvironmentVariable v = getVariable(PRJ_VAR, project, provider);
if (v != null) {
IBuildEnvironmentVariable[] vs = new IBuildEnvironmentVariable[1];
vs[0] = v;
return(vs);
} else
return null;
}
// IManagedIsToolChainSupported
/**
*
*/
public boolean isSupported(IToolChain toolChain,
PluginVersionIdentifier version,
String instance) {
if ("One".equals(toolChain.getParent().getName())) return supported[0]; //$NON-NLS-1$
if ("Two".equals(toolChain.getParent().getName())) return supported[1]; //$NON-NLS-1$
if ("Three".equals(toolChain.getParent().getName())) return supported[2]; //$NON-NLS-1$
if ("Four".equals(toolChain.getParent().getName())) return supported[3]; //$NON-NLS-1$
return false;
}
// IManagedBuilderMakefileGenerator
/**
*/
public IPath getBuildWorkingDir() {
// System.out.println("---- getBuildWorkingDir: " + topBuildDir);
return topBuildDir;
}
public void generateDependencies() {}
public MultiStatus generateMakefiles(IResourceDelta delta) { return null; }
public String getMakefileName() {return "test_instead_make"; } //$NON-NLS-1$
public void initialize(IProject project, IManagedBuildInfo info, IProgressMonitor monitor) {
// System.out.println("---- init: " + topBuildDir);
}
public boolean isGeneratedResource(IResource resource) { return false; }
public void regenerateDependencies(boolean force) {}
public MultiStatus regenerateMakefiles() { return null; }
}