[Esbox-commits] r118 - in trunk/org.indt.esbox.core/src/org/indt/esbox/core: . env
raul at garage.maemo.org
raul at garage.maemo.org
Mon Oct 15 02:09:18 EEST 2007
Author: raul
Date: 2007-10-15 02:09:18 +0300 (Mon, 15 Oct 2007)
New Revision: 118
Added:
trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/
trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxContributedEnvironment.java
trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxDescriptionStatus.java
trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxEnvironmentVariableManager.java
trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxExceptionFactory.java
trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxStorableEnvironment.java
trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/EsboxStorableEnvironmentLoader.java
trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ScratchboxEnvironmentReader.java
trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ScratchboxEnvironmentSupplier.java
Log:
environmen classes to set variables in Sbox.
Added: trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxContributedEnvironment.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxContributedEnvironment.java (rev 0)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxContributedEnvironment.java 2007-10-14 23:09:18 UTC (rev 118)
@@ -0,0 +1,136 @@
+package org.indt.esbox.core.env;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.cdt.core.envvar.IContributedEnvironment;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.internal.core.envvar.DefaultEnvironmentContextInfo;
+import org.eclipse.cdt.internal.core.envvar.EnvVarCollector;
+import org.eclipse.cdt.internal.core.envvar.EnvVarDescriptor;
+import org.eclipse.cdt.internal.core.envvar.ICoreEnvironmentVariableSupplier;
+import org.eclipse.cdt.internal.core.envvar.IEnvironmentContextInfo;
+
+public class ESboxContributedEnvironment implements IContributedEnvironment {
+
+ private ESboxEnvironmentVariableManager fMngr;
+ public ESboxContributedEnvironment(ESboxEnvironmentVariableManager mngr){
+ fMngr = mngr;
+ }
+ private class ContributedEnvContextInfo extends DefaultEnvironmentContextInfo {
+ private IEnvironmentContextInfo fBaseInfo;
+ private ICoreEnvironmentVariableSupplier fSuppliers[];
+
+/* public ContributedEnvContextInfo(Object context,
+ ICoreEnvironmentVariableSupplier[] suppliers) {
+ super(context, suppliers);
+ }
+*/
+ public ContributedEnvContextInfo(IEnvironmentContextInfo info) {
+ super(info.getContext());
+ fBaseInfo = info;
+ }
+
+ public ICoreEnvironmentVariableSupplier[] getSuppliers() {
+ if(fSuppliers == null){
+ ICoreEnvironmentVariableSupplier[] suppliers = fBaseInfo.getSuppliers();
+ int i = 0;
+ for(; i < suppliers.length; i++){
+ if(suppliers[i] == ESboxEnvironmentVariableManager.fScratchboxSupplier){
+ break;
+ }
+ }
+
+ if(i != suppliers.length){
+ ICoreEnvironmentVariableSupplier tmp[] = new ICoreEnvironmentVariableSupplier[suppliers.length - 1];
+ if(i != 0)
+ System.arraycopy(suppliers, 0, tmp, 0, i);
+ if(i != tmp.length)
+ System.arraycopy(suppliers, i+1, tmp, i, tmp.length - i);
+ suppliers = tmp;
+ }
+
+ fSuppliers = suppliers;
+ }
+ return fSuppliers;
+ }
+
+ public IEnvironmentContextInfo getNext() {
+ IEnvironmentContextInfo baseNext = fBaseInfo.getNext();
+ if(baseNext != null)
+ return new ContributedEnvContextInfo(baseNext);
+ return null;
+ }
+ }
+
+ public IEnvironmentContextInfo getContextInfo(Object context){
+ return new ContributedEnvContextInfo(fMngr.getDefaultContextInfo(context));
+ }
+
+ public IEnvironmentVariable[] getVariables(ICConfigurationDescription des){
+ EnvVarCollector cr = ESboxEnvironmentVariableManager.getVariables(getContextInfo(des), true);
+ if(cr != null){
+ EnvVarDescriptor collected[] = cr.toArray(true);
+ List vars = new ArrayList(collected.length);
+ IEnvironmentVariable var;
+ IEnvironmentContextInfo info = new DefaultEnvironmentContextInfo(des);//getContextInfo(des);
+ for(int i = 0; i < collected.length; i++){
+ var = collected[i];
+ var = ESboxEnvironmentVariableManager.getVariable(var.getName(), info, true);
+ if(var != null)
+ vars.add(var);
+ }
+ return (EnvVarDescriptor[])vars.toArray(new EnvVarDescriptor[vars.size()]);
+ }
+ return new EnvVarDescriptor[0];
+ }
+
+ public IEnvironmentVariable getVariable(String name, ICConfigurationDescription des){
+ EnvVarDescriptor varDes = ESboxEnvironmentVariableManager.getVariable(name, getContextInfo(des), true);
+ if(varDes != null)
+ return ESboxEnvironmentVariableManager.getVariable(name, new DefaultEnvironmentContextInfo(des), true);
+ return null;
+ }
+
+ public boolean appendEnvironment(ICConfigurationDescription des){
+ return ESboxEnvironmentVariableManager.fUserSupplier.appendContributedEnvironment(des);
+ }
+
+ public void setAppendEnvironment(boolean append, ICConfigurationDescription des){
+ ESboxEnvironmentVariableManager.fUserSupplier.setAppendContributedEnvironment(append, des);
+ }
+
+ public IEnvironmentVariable addVariable(String name,
+ String value,
+ int op,
+ String delimiter,
+ ICConfigurationDescription des){
+ return new EnvVarDescriptor(
+ ESboxEnvironmentVariableManager.fUserSupplier.createVariable(name, value, op, delimiter, des),
+ null,
+ -1,
+ ESboxEnvironmentVariableManager.fUserSupplier);
+ }
+
+ public IEnvironmentVariable removeVariable(String name, ICConfigurationDescription des){
+ return ESboxEnvironmentVariableManager.fUserSupplier.deleteVariable(name, des);
+ }
+
+ public void restoreDefaults(ICConfigurationDescription des){
+ ESboxEnvironmentVariableManager.fUserSupplier.restoreDefaults(des);
+ }
+
+ public boolean isUserVariable(ICConfigurationDescription des, IEnvironmentVariable var){
+ if(var instanceof EnvVarDescriptor)
+ return ((EnvVarDescriptor)var).getSupplier() == ESboxEnvironmentVariableManager.fUserSupplier;
+ return false;
+ }
+
+ public void serialize(ICProjectDescription des){
+ ESboxEnvironmentVariableManager.fUserSupplier.storeProjectEnvironment(des, false);
+ }
+
+
+}
Added: trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxDescriptionStatus.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxDescriptionStatus.java (rev 0)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxDescriptionStatus.java 2007-10-14 23:09:18 UTC (rev 118)
@@ -0,0 +1,22 @@
+package org.indt.esbox.core.env;
+
+import org.eclipse.core.runtime.Status;
+import org.indt.esbox.core.CoreActivator;
+
+public class ESboxDescriptionStatus extends Status {
+
+ public ESboxDescriptionStatus(String message) {
+ this(message, null);
+ }
+ public ESboxDescriptionStatus(String message, Throwable exception) {
+ this(OK, message, exception);
+ }
+
+ public ESboxDescriptionStatus(Throwable exception) {
+ this(exception.getLocalizedMessage(), exception);
+ }
+
+ public ESboxDescriptionStatus(int code, String message, Throwable exception) {
+ super(ERROR, CoreActivator.PLUGIN_ID, code, message, exception);
+ }
+}
Added: trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxEnvironmentVariableManager.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxEnvironmentVariableManager.java (rev 0)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxEnvironmentVariableManager.java 2007-10-14 23:09:18 UTC (rev 118)
@@ -0,0 +1,418 @@
+package org.indt.esbox.core.env;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
+import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
+import org.eclipse.cdt.core.envvar.EnvirinmentVariable;
+import org.eclipse.cdt.core.envvar.IContributedEnvironment;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.internal.core.cdtvariables.DefaultVariableContextInfo;
+import org.eclipse.cdt.internal.core.cdtvariables.EnvironmentVariableSupplier;
+import org.eclipse.cdt.internal.core.cdtvariables.ICoreVariableContextInfo;
+import org.eclipse.cdt.internal.core.envvar.BuildSustemEnvironmentSupplier;
+import org.eclipse.cdt.internal.core.envvar.ContributedEnvironment;
+import org.eclipse.cdt.internal.core.envvar.DefaultEnvironmentContextInfo;
+import org.eclipse.cdt.internal.core.envvar.EclipseEnvironmentSupplier;
+import org.eclipse.cdt.internal.core.envvar.EnvVarCollector;
+import org.eclipse.cdt.internal.core.envvar.EnvVarDescriptor;
+import org.eclipse.cdt.internal.core.envvar.ICoreEnvironmentVariableSupplier;
+import org.eclipse.cdt.internal.core.envvar.IEnvironmentContextInfo;
+import org.eclipse.cdt.internal.core.envvar.UserDefinedEnvironmentSupplier;
+import org.eclipse.cdt.utils.cdtvariables.ICdtVariableSupplier;
+import org.eclipse.cdt.utils.cdtvariables.IVariableContextInfo;
+import org.eclipse.cdt.utils.cdtvariables.IVariableSubstitutor;
+import org.eclipse.cdt.utils.cdtvariables.SupplierBasedCdtVariableSubstitutor;
+import org.eclipse.cdt.utils.envvar.EnvVarOperationProcessor;
+
+public class ESboxEnvironmentVariableManager implements
+ IEnvironmentVariableManager {
+
+ private static final String DELIMITER_WIN32 = ";"; //$NON-NLS-1$
+ private static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$
+
+ private static ESboxEnvironmentVariableManager fInstance = null;
+
+ private EnvVarVariableSubstitutor fVariableSubstitutor;
+
+ public static final UserDefinedEnvironmentSupplier fUserSupplier = new UserDefinedEnvironmentSupplier();
+ public static final BuildSustemEnvironmentSupplier fExternalSupplier = new BuildSustemEnvironmentSupplier();
+ public static final ScratchboxEnvironmentSupplier fScratchboxSupplier = new ScratchboxEnvironmentSupplier();
+
+ private ESboxContributedEnvironment fContributedEnvironment;
+
+ public class EnvVarVariableSubstitutor extends SupplierBasedCdtVariableSubstitutor {
+ private String fDefaultDelimiter;
+/* public EnvVarMacroSubstitutor(int contextType, Object contextData, String inexistentMacroValue, String listDelimiter){
+ super(contextType,contextData,inexistentMacroValue,listDelimiter);
+ fDefaultDelimiter = listDelimiter;
+ }
+*/
+ public EnvVarVariableSubstitutor(IVariableContextInfo contextInfo, String inexistentMacroValue, String listDelimiter){
+ super(contextInfo, inexistentMacroValue, listDelimiter, null ,inexistentMacroValue);
+ fDefaultDelimiter = listDelimiter;
+ }
+
+ public IEnvironmentVariable resolveVariable(EnvVarDescriptor var) throws CdtVariableException {
+ String value;
+ if(var == null || (value = var.getValue()) == null || value.length() == 0 || var.getOperation() == IEnvironmentVariable.ENVVAR_REMOVE)
+ return var;
+
+ String listDelimiter = var.getDelimiter();
+ if(listDelimiter == null)
+ listDelimiter = fDefaultDelimiter;
+ setListDelimiter(listDelimiter);
+ ICdtVariable macro = EnvironmentVariableSupplier.getInstance().createBuildMacro(var);
+ IVariableContextInfo varMacroInfo = getVarMacroContextInfo(var);
+ int varSupplierNum = getVarMacroSupplierNum(var,varMacroInfo);
+ value = resolveToString(new MacroDescriptor(macro,varMacroInfo,varSupplierNum));
+ removeResolvedMacro(var.getName());
+ return new EnvirinmentVariable(var.getName(),value,var.getOperation(),var.getDelimiter());
+ }
+
+ protected IVariableContextInfo getVarMacroContextInfo(EnvVarDescriptor var){
+ IEnvironmentContextInfo info = var.getContextInfo();
+ if(info != null)
+ return getMacroContextInfoForContext(info.getContext());
+ return null;
+ }
+
+ protected int getVarMacroSupplierNum(EnvVarDescriptor var, IVariableContextInfo varMacroInfo){
+ int varSupplierNum = -1;
+ ICdtVariableSupplier macroSuppliers[] = varMacroInfo.getSuppliers();
+ for(int i = 0; i < macroSuppliers.length; i++){
+ if(macroSuppliers[i] instanceof EnvironmentVariableSupplier){
+ varSupplierNum = i;
+ break;
+ }
+ }
+ return varSupplierNum;
+ }
+ }
+
+ protected ESboxEnvironmentVariableManager(){
+ fContributedEnvironment = new ESboxContributedEnvironment(this);
+ }
+
+ public static ESboxEnvironmentVariableManager getDefault(){
+ if(fInstance == null)
+ fInstance = new ESboxEnvironmentVariableManager();
+ return fInstance;
+ }
+
+ /*
+ * returns a variable of a given name or null
+ * the context information is taken from the contextInfo passed
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.IContextInfo
+ */
+ public static EnvVarDescriptor getVariable(String variableName,
+ IEnvironmentContextInfo contextInfo, boolean includeParentLevels){
+
+ if(contextInfo == null)
+ return null;
+ if((variableName = EnvVarOperationProcessor.normalizeName(variableName)) == null) //$NON-NLS-1$
+ return null;
+
+
+ IEnvironmentContextInfo infos[] = getAllContextInfos(contextInfo);
+
+ if(!includeParentLevels){
+ ICoreEnvironmentVariableSupplier suppliers[] = infos[0].getSuppliers();
+ boolean bVarFound = false;
+ for(int i = 0; i < suppliers.length; i++){
+ if(suppliers[i].getVariable(variableName,infos[0].getContext()) != null){
+ bVarFound = true;
+ break;
+ }
+ }
+ if(!bVarFound)
+ return null;
+ }
+
+ IEnvironmentVariable variable = null;
+ IEnvironmentContextInfo varContextInfo = null;
+ int varSupplierNum = -1;
+ ICoreEnvironmentVariableSupplier varSupplier = null;
+
+ for(int i = infos.length-1 ; i >=0 ; i-- ) {
+ IEnvironmentContextInfo info = infos[i];
+ ICoreEnvironmentVariableSupplier suppliers[] = info.getSuppliers();
+
+ for(int j = suppliers.length-1 ; j >= 0 ; j-- ) {
+ ICoreEnvironmentVariableSupplier supplier = suppliers[j];
+ IEnvironmentVariable var = supplier.getVariable(variableName,info.getContext());
+
+ if(var == null)
+ continue;
+
+ varContextInfo = info;
+ varSupplierNum = j;
+ varSupplier = supplier;
+
+ if(variable == null)
+ variable = var;
+ else
+ variable = EnvVarOperationProcessor.performOperation(variable,var);
+ }
+ }
+
+ if(variable != null){
+// if(variable.getOperation() == IEnvironmentVariable.ENVVAR_REMOVE)
+// return null;
+ return new EnvVarDescriptor(variable,varContextInfo,varSupplierNum,varSupplier);
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getVariable()
+ */
+ public IEnvironmentVariable getVariable(String variableName,
+ ICConfigurationDescription cfg, boolean resolveMacros) {
+ if(variableName == null || "".equals(variableName)) //$NON-NLS-1$
+ return null;
+
+ IEnvironmentContextInfo info = getContextInfo(cfg);
+ EnvVarDescriptor var = getVariable(variableName,info,true);
+
+ if(var != null && var.getOperation() != IEnvironmentVariable.ENVVAR_REMOVE){
+ return resolveMacros ? calculateResolvedVariable(var,info) : var;
+ }
+ return null;
+ }
+
+ IEnvironmentContextInfo getDefaultContextInfo(Object level){
+ DefaultEnvironmentContextInfo info = new DefaultEnvironmentContextInfo(level);
+ if(info.getSuppliers() == null)
+ return null;
+ return info;
+ }
+
+ /*
+ * returns the context info that should be used for the given level
+ * or null if the the given level is not supported
+ */
+ public IEnvironmentContextInfo getContextInfo(Object level){
+ if(level instanceof ICConfigurationDescription)
+ return fContributedEnvironment.appendEnvironment((ICConfigurationDescription)level) ?
+ getDefaultContextInfo(level) : fContributedEnvironment.getContextInfo(level);
+ return getDefaultContextInfo(level);
+ }
+
+ /*
+ * returns a list of defined variables.
+ * the context information is taken from the contextInfo passed
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.IContextInfo
+ */
+ public static EnvVarCollector getVariables(IEnvironmentContextInfo contextInfo,
+ boolean includeParentLevels) {
+ if(contextInfo == null)
+ return null;
+
+ IEnvironmentContextInfo infos[] = getAllContextInfos(contextInfo);
+ HashSet set = null;
+
+ if(!includeParentLevels){
+ ICoreEnvironmentVariableSupplier suppliers[] = infos[0].getSuppliers();
+ set = new HashSet();
+ for(int i = 0; i < suppliers.length; i++){
+ IEnvironmentVariable vars[] = suppliers[i].getVariables(infos[0].getContext());
+ if(vars != null){
+ for(int j = 0; j < vars.length; j++){
+ String name = EnvVarOperationProcessor.normalizeName(vars[j].
+ getName());
+ if(name != null)
+ set.add(name);
+ }
+ }
+ if(!suppliers[i].appendEnvironment(infos[0].getContext()))
+ break;
+ }
+ if(set.size() == 0)
+ return new EnvVarCollector();
+ }
+
+ EnvVarCollector envVarSet = new EnvVarCollector();
+
+ for(int i = infos.length-1 ; i >=0 ; i-- ) {
+ IEnvironmentContextInfo info = infos[i];
+ ICoreEnvironmentVariableSupplier suppliers[] = info.getSuppliers();
+
+ for(int j = suppliers.length-1 ; j >= 0 ; j-- ) {
+ ICoreEnvironmentVariableSupplier supplier = suppliers[j];
+ if(!supplier.appendEnvironment(info.getContext())){
+ envVarSet.clear();
+ }
+
+ IEnvironmentVariable vars[] = null;
+ if(set != null){
+ List varList = new ArrayList();
+ Iterator iter = set.iterator();
+
+ while(iter.hasNext()){
+ IEnvironmentVariable var = supplier.getVariable((String)iter.next(),info.getContext());
+ if(var != null)
+ varList.add(var);
+ }
+ vars = (IEnvironmentVariable[])varList.toArray(new IEnvironmentVariable[varList.size()]);
+ }
+ else{
+ vars = supplier.getVariables(info.getContext());
+ }
+ envVarSet.add(vars,info,j, supplier);
+ }
+ }
+
+ return envVarSet;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getVariables()
+ */
+ public IEnvironmentVariable[] getVariables(ICConfigurationDescription cfg, boolean resolveMacros) {
+
+
+ IEnvironmentContextInfo info = getContextInfo(cfg);
+ EnvVarCollector varSet = getVariables(info,true);
+
+ EnvVarDescriptor vars[] = varSet != null ? varSet.toArray(false) : null;
+
+ if(vars != null){
+ if(!resolveMacros)
+ return vars;
+
+ IEnvironmentVariable resolved[] = new IEnvironmentVariable[vars.length];
+ for(int i = 0; i < vars.length; i++)
+ resolved[i] = calculateResolvedVariable(vars[i], info);
+ return resolved;
+ }
+ return new EnvVarDescriptor[0];
+ }
+
+ /*
+ * returns an array of the IContextInfo that holds the context informations
+ * starting from the one passed to this method and including all subsequent parents
+ */
+ public static IEnvironmentContextInfo[] getAllContextInfos(IEnvironmentContextInfo contextInfo){
+ if(contextInfo == null)
+ return null;
+
+ List list = new ArrayList();
+
+ list.add(contextInfo);
+
+ while((contextInfo = contextInfo.getNext()) != null)
+ list.add(contextInfo);
+
+ return (IEnvironmentContextInfo[])list.toArray(new IEnvironmentContextInfo[list.size()]);
+ }
+
+ private boolean isWin32(){
+ String os = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
+ if (os.startsWith("windows ")) //$NON-NLS-1$
+ return true;
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getDefaultDelimiter()
+ */
+ public String getDefaultDelimiter() {
+ return isWin32() ? DELIMITER_WIN32 : DELIMITER_UNIX;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#isVariableCaseSensitive()
+ */
+ public boolean isVariableCaseSensitive() {
+ return !isWin32();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getSuppliers()
+ */
+ public ICoreEnvironmentVariableSupplier[] getSuppliers(Object level) {
+ IEnvironmentContextInfo info = getContextInfo(level);
+ if(info != null)
+ return info.getSuppliers();
+ return null;
+ }
+
+ /*
+ * returns true if the first passed contextInfo is the child of the second one
+ */
+ public boolean checkParentContextRelation(IEnvironmentContextInfo child, IEnvironmentContextInfo parent){
+ if(child == null || parent == null)
+ return false;
+
+ IEnvironmentContextInfo enumInfo = child;
+ do{
+ if(parent.getContext() == enumInfo.getContext())
+ return true;
+ }while((enumInfo = enumInfo.getNext()) != null);
+ return false;
+ }
+
+ public IEnvironmentVariable calculateResolvedVariable(EnvVarDescriptor des, IEnvironmentContextInfo info){
+ if(des == null || info == null)
+ return null;
+
+ return calculateResolvedVariable(des,getVariableSubstitutor(getMacroContextInfoForContext(info.getContext()),""," ")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public IEnvironmentVariable calculateResolvedVariable(EnvVarDescriptor des, IVariableSubstitutor sub){
+ if(des == null)
+ return null;
+ IEnvironmentVariable var = des;
+
+ try{
+ if(sub instanceof EnvVarVariableSubstitutor)
+ var = ((EnvVarVariableSubstitutor)sub).resolveVariable(des);
+ else if(des.getOperation() != IEnvironmentVariable.ENVVAR_REMOVE){
+ String name = des.getName();
+ var = new EnvirinmentVariable(name,sub.resolveToString(name),des.getOperation(),des.getDelimiter());
+ }
+ } catch (CdtVariableException e){
+ }
+ return var;
+
+ }
+
+ protected int getMacroContextTypeFromContext(Object context){
+ if(context instanceof ICConfigurationDescription)
+ return ICoreVariableContextInfo.CONTEXT_CONFIGURATION;
+ else
+ return ICoreVariableContextInfo.CONTEXT_WORKSPACE;
+ }
+
+ public ICoreVariableContextInfo getMacroContextInfoForContext(Object context){
+ return new DefaultVariableContextInfo(getMacroContextTypeFromContext(context),context);
+ }
+
+ public IVariableSubstitutor getVariableSubstitutor(IVariableContextInfo info, String inexistentMacroValue, String listDelimiter){
+ if(fVariableSubstitutor == null)
+ fVariableSubstitutor = new EnvVarVariableSubstitutor(info,inexistentMacroValue,listDelimiter);
+ else {
+ try {
+ fVariableSubstitutor.setMacroContextInfo(info);
+ fVariableSubstitutor.setInexistentMacroValue(inexistentMacroValue);
+ fVariableSubstitutor.setListDelimiter(listDelimiter);
+ } catch (CdtVariableException e){
+ fVariableSubstitutor = new EnvVarVariableSubstitutor(info,inexistentMacroValue,listDelimiter);
+ }
+ }
+ return fVariableSubstitutor;
+ }
+
+ public IContributedEnvironment getContributedEnvironment() {
+ return fContributedEnvironment;
+ }
+
+
+
+}
Added: trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxExceptionFactory.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxExceptionFactory.java (rev 0)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxExceptionFactory.java 2007-10-14 23:09:18 UTC (rev 118)
@@ -0,0 +1,23 @@
+package org.indt.esbox.core.env;
+
+import org.eclipse.cdt.core.settings.model.WriteAccessException;
+import org.eclipse.core.runtime.CoreException;
+
+public class ESboxExceptionFactory {
+ public static WriteAccessException createIsReadOnlyException(){
+ return new WriteAccessException();
+ }
+
+ public static CoreException createCoreException(String message){
+ return new CoreException(new ESboxDescriptionStatus(message));
+ }
+
+ public static CoreException createCoreException(Throwable e){
+ return new CoreException(new ESboxDescriptionStatus(e));
+ }
+
+ public static CoreException createCoreException(String message, Exception exception){
+ return new CoreException(new ESboxDescriptionStatus(message, exception));
+ }
+
+}
Added: trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxStorableEnvironment.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxStorableEnvironment.java (rev 0)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ESboxStorableEnvironment.java 2007-10-14 23:09:18 UTC (rev 118)
@@ -0,0 +1,290 @@
+package org.indt.esbox.core.env;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
+import org.eclipse.cdt.core.settings.model.ICStorageElement;
+import org.eclipse.cdt.utils.envvar.StorableEnvVar;
+
+public class ESboxStorableEnvironment {
+ public static final String ENVIRONMENT_ELEMENT_NAME = "environment"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_APPEND = "append"; //$NON-NLS-1$
+ private static final boolean DEFAULT_APPEND = true;
+ private HashMap fVariables;
+ private boolean fIsDirty = false;
+ private boolean fIsChanged = false;
+ private boolean fIsReadOnly;
+ private boolean fAppend = DEFAULT_APPEND;
+ private boolean fAppendContributedEnv = DEFAULT_APPEND;
+
+ private Map getMap(){
+ if(fVariables == null)
+ fVariables = new HashMap();
+ return fVariables;
+ }
+
+ public ESboxStorableEnvironment(IEnvironmentVariable variables[], boolean isReadOnly) {
+ setVariales(variables);
+ fIsReadOnly = isReadOnly;
+ }
+
+ public ESboxStorableEnvironment(boolean isReadOnly) {
+ fIsReadOnly = isReadOnly;
+ }
+
+ public ESboxStorableEnvironment(ESboxStorableEnvironment env, boolean isReadOnly) {
+ if(env.fVariables != null)
+ fVariables = (HashMap)env.fVariables.clone();
+ fAppend = env.fAppend;
+ fIsReadOnly = isReadOnly;
+ fIsDirty = env.isDirty();
+ }
+
+ public ESboxStorableEnvironment(ICStorageElement element, boolean isReadOnly) {
+ load(element);
+ fIsReadOnly = isReadOnly;
+ }
+
+ private void load(ICStorageElement element){
+ ICStorageElement children[] = element.getChildren();
+ for (int i = 0; i < children.length; ++i) {
+ ICStorageElement node = children[i];
+ if (node.getName().equals(StorableEnvVar.VARIABLE_ELEMENT_NAME)) {
+ addVariable(new StorableEnvVar(node));
+ }
+ }
+
+ String append = element.getAttribute(ATTRIBUTE_APPEND);
+ fAppend = append != null ? Boolean.valueOf(element.getAttribute(ATTRIBUTE_APPEND)).booleanValue()
+ : true;
+ fIsDirty = false;
+ fIsChanged = false;
+ }
+
+ public void serialize(ICStorageElement element){
+ element.setAttribute(ATTRIBUTE_APPEND, Boolean.valueOf(fAppend).toString());
+ if(fVariables != null){
+ Iterator iter = fVariables.values().iterator();
+ while(iter.hasNext()){
+ StorableEnvVar var = (StorableEnvVar)iter.next();
+ ICStorageElement varEl = element.createChild(StorableEnvVar.VARIABLE_ELEMENT_NAME);
+ var.serialize(varEl);
+ }
+ }
+ fIsDirty = false;
+ }
+
+ private void addVariable(IEnvironmentVariable var){
+ String name = var.getName();
+ if(name == null)
+ return;
+ IEnvironmentVariableManager provider = ESboxEnvironmentVariableManager.getDefault();
+ if(!provider.isVariableCaseSensitive())
+ name = name.toUpperCase();
+
+ getMap().put(name,var);
+ }
+
+ public IEnvironmentVariable createVariable(String name, String value, int op, String delimiter){
+ if(fIsReadOnly)
+ throw ESboxExceptionFactory.createIsReadOnlyException();
+
+ if(name == null || "".equals(name = name.trim())) //$NON-NLS-1$
+ return null;
+
+ IEnvironmentVariable var = checkVariable(name,value,op,delimiter);
+ if(var == null){
+ var = new StorableEnvVar(name, value, op, delimiter);
+ addVariable(var);
+ fIsDirty = true;
+ fIsChanged = true;
+ }
+ return var;
+ }
+
+ public IEnvironmentVariable createVariable(String name){
+ return createVariable(name,null,IEnvironmentVariable.ENVVAR_REPLACE,null);
+ }
+
+ public IEnvironmentVariable createVariable(String name, String value){
+ return createVariable(name,value,IEnvironmentVariable.ENVVAR_REPLACE,null);
+ }
+
+ public IEnvironmentVariable createVariable(String name, String value, String delimiter){
+ if(fIsReadOnly)
+ throw ESboxExceptionFactory.createIsReadOnlyException();
+ return createVariable(name,value,IEnvironmentVariable.ENVVAR_REPLACE,delimiter);
+ }
+
+ public IEnvironmentVariable checkVariable(String name, String value, int op, String delimiter){
+ IEnvironmentVariable var = getVariable(name);
+ if(var != null
+ && checkStrings(var.getValue(),value)
+ && var.getOperation() == op
+ && checkStrings(var.getDelimiter(),delimiter))
+ return var;
+ return null;
+ }
+
+ private boolean checkStrings(String str1, String str2){
+ if(str1 != null &&
+ str1.equals(str2))
+ return true;
+ return str1 == str2;
+ }
+
+ /**
+ * Returns the "dirty" state of the environment.
+ * If the dirty state is <code>true</code>, that means that the environment
+ * is out of synch with the repository and the environment needs to be serialized.
+ * <br><br>
+ * The dirty state is automatically set to <code>false</code> when the environment is serialized
+ * by calling the serialize() method
+ * @return boolean
+ */
+ public boolean isDirty(){
+ return fIsDirty;
+ }
+
+ /**
+ * sets the "dirty" state of the environment
+ * @param dirty represents the new state
+ */
+ public void setDirty(boolean dirty){
+ fIsDirty = dirty;
+ }
+
+ /**
+ * Returns the "change" state of the environment.
+ * The "change" state represents whether the environment was changed or not.
+ * This state is not reset when the serialize() method is called
+ * Users can use this state to monitor whether the environment was changed or not.
+ * This state can be reset to <code>false</code> only by calling the setChanged(false) method
+ * @return boolean
+ */
+ public boolean isChanged(){
+ return fIsChanged;
+ }
+
+ /**
+ * sets the "change" state of the environment
+ * @param changed represents the new "change" state
+ */
+ public void setChanged(boolean changed){
+ if(fIsReadOnly)
+ throw ESboxExceptionFactory.createIsReadOnlyException();
+ fIsChanged = changed;
+ }
+
+ public IEnvironmentVariable getVariable(String name){
+ if(name == null || "".equals(name = name.trim())) //$NON-NLS-1$
+ return null;
+ IEnvironmentVariableManager provider = ESboxEnvironmentVariableManager.getDefault();
+ if(!provider.isVariableCaseSensitive())
+ name = name.toUpperCase();
+
+ return (IEnvironmentVariable)getMap().get(name);
+ }
+
+ public void setVariales(IEnvironmentVariable vars[]){
+ if(fIsReadOnly)
+ throw ESboxExceptionFactory.createIsReadOnlyException();
+ if(vars == null || vars.length == 0)
+ deleteAll();
+ else{
+ if (getMap().size() != 0) {
+ Iterator iter = getMap().values().iterator();
+ while(iter.hasNext()){
+ IEnvironmentVariable v = (IEnvironmentVariable)iter.next();
+ int i;
+ for(i = 0 ; i < vars.length; i++){
+ if(v.getName().equals(vars[i].getName()))
+ break;
+ }
+ if(i == vars.length)
+ deleteVariable(v.getName());
+ }
+ }
+ createVriables(vars);
+ }
+ }
+
+ public void createVriables(IEnvironmentVariable vars[]){
+ if(fIsReadOnly)
+ throw ESboxExceptionFactory.createIsReadOnlyException();
+ for(int i = 0; i < vars.length; i++)
+ createVariable(vars[i].getName(),
+ vars[i].getValue(),
+ vars[i].getOperation(),
+ vars[i].getDelimiter());
+ }
+
+ public IEnvironmentVariable[] getVariables(){
+ Collection vars = getMap().values();
+
+ return (IEnvironmentVariable[])vars.toArray(new IEnvironmentVariable[vars.size()]);
+ }
+
+ public IEnvironmentVariable deleteVariable(String name){
+ if(fIsReadOnly)
+ throw ESboxExceptionFactory.createIsReadOnlyException();
+ if(name == null || "".equals(name = name.trim())) //$NON-NLS-1$
+ return null;
+ IEnvironmentVariableManager provider = ESboxEnvironmentVariableManager.getDefault();
+ if(!provider.isVariableCaseSensitive())
+ name = name.toUpperCase();
+
+ IEnvironmentVariable var = (IEnvironmentVariable)getMap().remove(name);
+ if(var != null){
+ fIsDirty = true;
+ fIsChanged = true;
+ }
+
+ return var;
+ }
+
+ public boolean deleteAll(){
+ if(fIsReadOnly)
+ throw ESboxExceptionFactory.createIsReadOnlyException();
+ Map map = getMap();
+ if(map.size() > 0){
+ fIsDirty = true;
+ fIsChanged = true;
+ map.clear();
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean isReadOnly(){
+ return fIsReadOnly;
+ }
+
+ public boolean appendEnvironment(){
+ return fAppend;
+ }
+
+ public void setAppendEnvironment(boolean append){
+ fAppend = append;
+ }
+
+ public boolean appendContributedEnvironment(){
+ return fAppendContributedEnv;
+ }
+
+ public void setAppendContributedEnvironment(boolean append){
+ fAppendContributedEnv = append;
+ }
+
+ public void restoreDefaults(){
+ deleteAll();
+ fAppend = DEFAULT_APPEND;
+ fAppendContributedEnv = DEFAULT_APPEND;
+ }
+
+}
Added: trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/EsboxStorableEnvironmentLoader.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/EsboxStorableEnvironmentLoader.java (rev 0)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/EsboxStorableEnvironmentLoader.java 2007-10-14 23:09:18 UTC (rev 118)
@@ -0,0 +1,211 @@
+package org.indt.esbox.core.env;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.cdt.core.settings.model.util.XmlStorageElement;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.indt.esbox.core.CoreActivator;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public abstract class EsboxStorableEnvironmentLoader {
+ /**
+ * this interface represents the preference node and the preference name
+ * that are used for holding the environment data
+ *
+ */
+ public interface ISerializeInfo{
+ Preferences getNode();
+
+ String getPrefName();
+ }
+
+ /**
+ * this method should return the ISerializeInfo representing the information
+ * of where the variable should be stored and loaded
+ * If the given context is not supported this method should return null
+ *
+ * @param context
+ * @return
+ */
+ protected abstract ISerializeInfo getSerializeInfo(Object context);
+
+ /*
+ * loads the stored environment for the given context
+ */
+ protected ESboxStorableEnvironment loadEnvironment(Object context, boolean readOnly){
+ ISerializeInfo serializeInfo = getSerializeInfo(context);
+ if(serializeInfo == null)
+ return null;
+
+ InputStream stream = loadInputStream(serializeInfo.getNode(),serializeInfo.getPrefName());
+ if(stream == null)
+ return new ESboxStorableEnvironment(readOnly);
+ return loadEnvironmentFromStream(stream, readOnly);
+ }
+
+ /*
+ * stores the given environment
+ */
+ protected void storeEnvironment(ESboxStorableEnvironment env, Object context, boolean force, boolean flush) throws CoreException{
+ if(!env.isDirty() && !force)
+ return;
+
+ ISerializeInfo serializeInfo = getSerializeInfo(context);
+ if(serializeInfo == null)
+ return;
+
+ ByteArrayOutputStream stream = storeEnvironmentToStream(env);
+ if(stream == null)
+ return;
+ storeOutputStream(stream,serializeInfo.getNode(),serializeInfo.getPrefName(), flush);
+
+ env.setDirty(false);
+ }
+
+ private ESboxStorableEnvironment loadEnvironmentFromStream(InputStream stream, boolean readOnly){
+ try{
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ InputSource inputSource = new InputSource(stream);
+ Document document = parser.parse(inputSource);
+ Element el = document.getDocumentElement();
+ XmlStorageElement rootElement = new XmlStorageElement(el);
+
+ if(!ESboxStorableEnvironment.ENVIRONMENT_ELEMENT_NAME.equals(rootElement.getName()))
+ return null;
+
+ return new ESboxStorableEnvironment(rootElement, readOnly);
+ }
+ catch(ParserConfigurationException e){
+
+ }
+ catch(SAXException e){
+
+ }
+ catch(IOException e){
+
+ }
+
+ return null;
+ }
+
+ private ByteArrayOutputStream storeEnvironmentToStream(ESboxStorableEnvironment env) throws CoreException{
+ try{
+ DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder= factory.newDocumentBuilder();
+ Document document= builder.newDocument();
+
+ Element el = document.createElement(ESboxStorableEnvironment.ENVIRONMENT_ELEMENT_NAME);
+ document.appendChild(el);
+ XmlStorageElement rootElement = new XmlStorageElement(el);
+ env.serialize(rootElement);
+
+ Transformer transformer=TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ DOMSource source = new DOMSource(document);
+
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(stream);
+
+ transformer.transform(source, result);
+ return stream;
+ }
+ catch(ParserConfigurationException e){
+ throw new CoreException(new Status(IStatus.ERROR,
+ CoreActivator.PLUGIN_ID,
+ -1,
+ e.getMessage(),
+ e));
+ }
+ catch(TransformerConfigurationException e){
+ throw new CoreException(new Status(IStatus.ERROR,
+ CoreActivator.PLUGIN_ID,
+ -1,
+ e.getMessage(),
+ e));
+ }
+ catch(TransformerException e){
+ throw new CoreException(new Status(IStatus.ERROR,
+ CoreActivator.PLUGIN_ID,
+ -1,
+ e.getMessage(),
+ e));
+ }
+ }
+
+ private InputStream loadInputStream(Preferences node, String key){
+ if(node == null || key == null)
+ return null;
+
+ String value = node.get(key,null);
+ if(value == null || value.length() == 0)
+ return null;
+
+ byte[] bytes;
+ try {
+ bytes = value.getBytes("UTF-8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ bytes = value.getBytes();
+ }
+
+ return new ByteArrayInputStream(bytes);
+ }
+
+ private void storeOutputStream(ByteArrayOutputStream stream, Preferences node, String key, boolean flush) throws CoreException{
+ if(stream == null || node == null || key == null)
+ throw new CoreException(new Status(IStatus.ERROR,
+ CoreActivator.PLUGIN_ID,
+ -1,
+ //TODO:ManagedMakeMessages.getResourceString(
+ "StorableEnvironmentLoader.storeOutputStream.wrong.arguments"
+ //)
+ , //$NON-NLS-1$
+ null));
+ byte[] bytes= stream.toByteArray();
+
+ String val = null;
+ try {
+ val= new String(bytes, "UTF-8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ val= new String(bytes);
+ }
+
+ node.put(key,val);
+
+ if(flush){
+ try{
+ node.flush();
+ }
+ catch(BackingStoreException e){
+ throw new CoreException(new Status(IStatus.ERROR,
+ CoreActivator.PLUGIN_ID,
+ -1,
+ e.getMessage(),
+ e));
+ }
+ }
+ }
+}
Added: trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ScratchboxEnvironmentReader.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ScratchboxEnvironmentReader.java (rev 0)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ScratchboxEnvironmentReader.java 2007-10-14 23:09:18 UTC (rev 118)
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2007 INdT.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+package org.indt.esbox.core.env;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.eclipse.cdt.utils.spawner.ProcessFactory;
+import org.eclipse.core.runtime.Preferences;
+import org.indt.esbox.core.CoreActivator;
+import org.indt.esbox.core.ESboxPreferenceConstants;
+import org.indt.esbox.core.ErrorLogger;
+
+/**
+ *
+ */
+public class ScratchboxEnvironmentReader {
+
+ private static ScratchboxEnvironmentReader singleton = null;
+ private Properties envVars;
+ private Vector rawVars;
+
+ private ScratchboxEnvironmentReader() {
+ envVars = null;
+ rawVars = null;
+ }
+
+ public synchronized static ScratchboxEnvironmentReader getInstance() {
+ if(singleton == null)
+ singleton = new ScratchboxEnvironmentReader();
+ return singleton;
+ }
+
+ public Properties getEnvVars() {
+ if (null != envVars)
+ return (Properties) envVars.clone();
+ Process p = null;
+ envVars = new Properties();
+ rawVars = new Vector(32);
+ String[] command = createCommandArray("env");
+ InputStream in = null;
+ String charSet = null;
+ try {
+ p = ProcessFactory.getFactory().exec(command);
+ in = p.getInputStream();
+ BufferedReader br;
+ if(charSet == null)
+ br = new BufferedReader(new InputStreamReader(in));
+ else
+ br = new BufferedReader(new InputStreamReader(in, charSet));
+ String line;
+ while ((line = br.readLine()) != null) {
+ rawVars.add(line);
+ int idx = line.indexOf('=');
+ if (idx != -1) {
+ String key = line.substring(0, idx);
+ String value = line.substring(idx + 1);
+ envVars.setProperty(key, value);
+ } else {
+ envVars.setProperty(line, ""); //$NON-NLS-1$
+ }
+ }
+ } catch (Exception e) {
+ ErrorLogger errorLogger = CoreActivator.getDefault().getErrorLogger();
+ errorLogger.logAndShowError("Scratchbox error", e);
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException e) {
+ }
+ try {
+ if (p != null)
+ p.waitFor();
+ } catch (InterruptedException e) {
+ }
+ }
+ rawVars.trimToSize();
+ return (Properties)envVars.clone();
+ }
+
+ /**
+ *
+ * @return
+ */
+ private String[] createCommandArray(String command) {
+ String cmd[] = new String[3];
+ Preferences preferences = CoreActivator.getDefault().getPluginPreferences();
+ String commandInSbox = preferences.getString(ESboxPreferenceConstants.LOGIN_COMMAND.toString());
+
+ commandInSbox = commandInSbox.replaceAll("\\$\\{COMMAND\\}", command);
+ commandInSbox = commandInSbox.replaceAll("\\$\\{DIRECTORY\\}", ".");
+ commandInSbox = commandInSbox.replaceAll("\\$\\{ARGS\\}", "");
+
+ cmd[0] = "/bin/sh";
+ cmd[1] = "-c";
+ cmd[2] = commandInSbox;
+ return cmd;
+ }
+
+
+ /**
+ *
+ * @param key
+ * @return
+ */
+ public String getEnvVar(String key) {
+ Properties p = getEnvVars();
+ return p.getProperty(key);
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String[] getRawEnvVars() {
+ getEnvVars();
+ return (String[]) rawVars.toArray(new String[0]);
+ }
+}
+
Added: trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ScratchboxEnvironmentSupplier.java
===================================================================
--- trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ScratchboxEnvironmentSupplier.java (rev 0)
+++ trunk/org.indt.esbox.core/src/org/indt/esbox/core/env/ScratchboxEnvironmentSupplier.java 2007-10-14 23:09:18 UTC (rev 118)
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2007 INdT.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raul Herbster (raul at embedded.ufcg.edu.br) (UFCG) - initial API and implementation
+ *******************************************************************************/
+package org.indt.esbox.core.env;
+
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
+import org.eclipse.cdt.managedbuilder.internal.envvar.BuildEnvVar;
+
+/**
+ *
+ */
+public class ScratchboxEnvironmentSupplier implements IEnvironmentVariableSupplier {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariable(java.lang.String, java.lang.Object)
+ */
+ public IBuildEnvironmentVariable getVariable(String name, Object context) {
+ if(context == null){
+ String value = ScratchboxEnvironmentReader.getInstance().getEnvVar(name);
+ if(value == null)
+ return null;
+ return new BuildEnvVar(name,value,IBuildEnvironmentVariable.ENVVAR_REPLACE,null);
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariables(java.lang.Object)
+ */
+ public IBuildEnvironmentVariable[] getVariables(Object context) {
+ if(context == null) {
+ Properties values = ScratchboxEnvironmentReader.getInstance().getEnvVars();
+ if(values == null)
+ return null;
+
+ IBuildEnvironmentVariable variables[] = new IBuildEnvironmentVariable[values.size()];
+ Enumeration en = values.propertyNames();
+ for( int i = 0; i < variables.length ; i++){
+ String name = (String)en.nextElement();
+ String value = values.getProperty(name);
+ variables[i] = new BuildEnvVar(name,value,IBuildEnvironmentVariable.ENVVAR_REPLACE,null);
+ }
+ return variables;
+ }
+ return null;
+ }
+
+}
More information about the Esbox-commits
mailing list