Search in sources :

Example 11 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class TransTestFactory method generateTestTransformationError.

public static TransMeta generateTestTransformationError(VariableSpace parent, StepMetaInterface oneMeta, String oneStepname) {
    TransMeta previewMeta = new TransMeta(parent);
    if (parent == null) {
        parent = new Variables();
    }
    // First the injector step...
    StepMeta zero = getInjectorStepMeta();
    previewMeta.addStep(zero);
    // Then the middle step to test...
    // 
    StepMeta one = new StepMeta(registry.getPluginId(StepPluginType.class, oneMeta), oneStepname, oneMeta);
    one.setLocation(150, 50);
    one.setDraw(true);
    previewMeta.addStep(one);
    // Then we add the dummy step to read the results from
    StepMeta two = getReadStepMeta();
    previewMeta.addStep(two);
    // error handling step
    StepMeta err = getReadStepMeta(ERROR_STEPNAME);
    previewMeta.addStep(err);
    // Add the hops between the 3 steps.
    TransHopMeta zeroOne = new TransHopMeta(zero, one);
    previewMeta.addTransHop(zeroOne);
    TransHopMeta oneTwo = new TransHopMeta(one, two);
    previewMeta.addTransHop(oneTwo);
    StepErrorMeta errMeta = new StepErrorMeta(parent, one, err);
    errMeta.setEnabled(true);
    errMeta.setNrErrorsValuename(NUMBER_ERRORS_FIELD);
    errMeta.setErrorDescriptionsValuename(ERROR_DESC_FIELD);
    errMeta.setErrorFieldsValuename(ERROR_FIELD_VALUE);
    errMeta.setErrorCodesValuename(ERROR_CODE_VALUE);
    one.setStepErrorMeta(errMeta);
    TransHopMeta oneErr = new TransHopMeta(one, err);
    previewMeta.addTransHop(oneErr);
    return previewMeta;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta)

Example 12 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class MessagesSourceCrawler method crawl.

public void crawl() throws Exception {
    for (final String sourceDirectory : sourceDirectories) {
        FileObject folder = KettleVFS.getFileObject(sourceDirectory);
        FileObject[] javaFiles = folder.findFiles(new FileSelector() {

            @Override
            public boolean traverseDescendents(FileSelectInfo info) throws Exception {
                return true;
            }

            @Override
            public boolean includeFile(FileSelectInfo info) throws Exception {
                return info.getFile().getName().getExtension().equals("java");
            }
        });
        for (FileObject javaFile : javaFiles) {
            /**
             * We don't want the Messages.java files, there is nothing in there for us.
             */
            boolean skip = false;
            for (String filename : filesToAvoid) {
                if (javaFile.getName().getBaseName().equals(filename)) {
                    skip = true;
                }
            }
            if (skip) {
                // don't process this file.
                continue;
            }
            // For each of these files we look for keys...
            // 
            lookForOccurrencesInFile(sourceDirectory, javaFile);
        }
    }
    // 
    for (SourceCrawlerXMLFolder xmlFolder : xmlFolders) {
        String[] xmlDirs = { xmlFolder.getFolder() };
        String[] xmlMasks = { xmlFolder.getWildcard() };
        String[] xmlReq = { "N" };
        // search sub-folders too
        boolean[] xmlSubdirs = { true };
        FileInputList xulFileInputList = FileInputList.createFileList(new Variables(), xmlDirs, xmlMasks, xmlReq, xmlSubdirs);
        for (FileObject fileObject : xulFileInputList.getFiles()) {
            try {
                Document doc = XMLHandler.loadXMLFile(fileObject);
                // 
                for (SourceCrawlerXMLElement xmlElement : xmlFolder.getElements()) {
                    addLabelOccurrences(xmlFolder.getDefaultSourceFolder(), fileObject, doc.getElementsByTagName(xmlElement.getSearchElement()), xmlFolder.getKeyPrefix(), xmlElement.getKeyTag(), xmlElement.getKeyAttribute(), xmlFolder.getDefaultPackage(), xmlFolder.getPackageExceptions());
                }
            } catch (KettleXMLException e) {
                log.logError("Unable to open XUL / XML document: " + fileObject);
            }
        }
    }
}
Also used : FileSelector(org.apache.commons.vfs2.FileSelector) Document(org.w3c.dom.Document) FileSelectInfo(org.apache.commons.vfs2.FileSelectInfo) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) IOException(java.io.IOException) Variables(org.pentaho.di.core.variables.Variables) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) FileObject(org.apache.commons.vfs2.FileObject) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 13 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class EnvUtil method applyKettleProperties.

public static void applyKettleProperties(Map<?, ?> kettleProperties, boolean override) {
    Variables variables = new Variables();
    for (Object key : kettleProperties.keySet()) {
        String variable = (String) key;
        String value = variables.environmentSubstitute((String) kettleProperties.get(key));
        variables.setVariable(variable, value);
    }
    Properties systemProperties = System.getProperties();
    // 
    for (String variable : variables.listVariables()) {
        String value = variables.getVariable(variable);
        // 
        if (variable.equals(Const.KETTLE_PLUGIN_CLASSES) || variable.equals(Const.KETTLE_PLUGIN_PACKAGES)) {
            String jvmValue = System.getProperty(variable);
            if (!Utils.isEmpty(jvmValue)) {
                if (!Utils.isEmpty(value)) {
                    value += "," + jvmValue;
                } else {
                    value = jvmValue;
                }
            }
        } else {
            if (!override && systemProperties.containsKey(variable)) {
                continue;
            }
        }
        System.setProperty(variable, value);
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Properties(java.util.Properties)

Example 14 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class KettleVFS method reset.

public void reset() {
    defaultVariableSpace = new Variables();
    defaultVariableSpace.initializeVariablesFrom(null);
    fsm.close();
    try {
        fsm.setFilesCache(new WeakRefFilesCache());
        fsm.init();
    } catch (FileSystemException ignored) {
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) FileSystemException(org.apache.commons.vfs2.FileSystemException) WeakRefFilesCache(org.apache.commons.vfs2.cache.WeakRefFilesCache)

Example 15 with Variables

use of org.pentaho.di.core.variables.Variables in project pentaho-kettle by pentaho.

the class UtilsTest method testResolvePasswordVariable.

@Test
public void testResolvePasswordVariable() {
    String passwordKey = "PASS_VAR";
    String passwordVar = "${" + passwordKey + "}";
    String passwordValue = "password";
    Variables vars = new Variables();
    vars.setVariable(passwordKey, passwordValue);
    // resolvePassword gets variable
    assertSame(passwordValue, Utils.resolvePassword(vars, passwordVar).intern());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Test(org.junit.Test)

Aggregations

Variables (org.pentaho.di.core.variables.Variables)119 Test (org.junit.Test)67 TransMeta (org.pentaho.di.trans.TransMeta)31 ArrayList (java.util.ArrayList)25 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)20 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)20 StepMeta (org.pentaho.di.trans.step.StepMeta)18 RowMeta (org.pentaho.di.core.row.RowMeta)17 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)16 VariableSpace (org.pentaho.di.core.variables.VariableSpace)14 Repository (org.pentaho.di.repository.Repository)12 TableView (org.pentaho.di.ui.core.widget.TableView)10 FormAttachment (org.eclipse.swt.layout.FormAttachment)9 FormData (org.eclipse.swt.layout.FormData)9 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)9 Label (org.eclipse.swt.widgets.Label)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)7