Java Code Examples for org.pentaho.di.core.Const#isWindows()

The following examples show how to use org.pentaho.di.core.Const#isWindows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static String getExplanation( String zipFilename, String launchFile,
  ResourceExportInterface resourceExportInterface ) {

  String commandString = "";
  if ( Const.isWindows() ) {
    if ( resourceExportInterface instanceof TransMeta ) {
      commandString += "Pan.bat /file:\"";
    } else {
      commandString += "Kitchen.bat /file:\"";
    }
  } else {
    if ( resourceExportInterface instanceof TransMeta ) {
      commandString += "sh pan.sh -file='";
    } else {
      commandString += "sh kitchen.sh -file='";
    }
  }
  commandString += launchFile;
  if ( Const.isWindows() ) {
    commandString += "\"";
  } else {
    commandString += "'";
  }

  String message =
    BaseMessages.getString(
      PKG, "ResourceUtil.ExportResourcesExplanation", zipFilename, commandString, launchFile, Const.CR );
  return message;
}
 
Example 2
Source File: JobEntryShell.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private FileObject createTemporaryShellFile( FileObject tempFile, String fileContent ) throws Exception {
  // Create a unique new temporary filename in the working directory, put the script in there
  // Set the permissions to execute and then run it...
  //
  if ( tempFile != null && fileContent != null ) {
    try {
      // flag indicates if current OS is Windows or not
      boolean isWindows = Const.isWindows();
      if ( !isWindows ) {
        fileContent = replaceWinEOL( fileContent );
      }
      tempFile.createFile();
      OutputStream outputStream = tempFile.getContent().getOutputStream();
      outputStream.write( fileContent.getBytes() );
      outputStream.close();
      if ( !isWindows ) {
        String tempFilename = KettleVFS.getFilename( tempFile );
        // Now we have to make this file executable...
        // On Unix-like systems this is done using the command "/bin/chmod +x filename"
        //
        ProcessBuilder procBuilder = new ProcessBuilder( "chmod", "+x", tempFilename );
        Process proc = procBuilder.start();
        // Eat/log stderr/stdout all messages in a different thread...
        StreamLogger errorLogger = new StreamLogger( log, proc.getErrorStream(), toString() + " (stderr)" );
        StreamLogger outputLogger = new StreamLogger( log, proc.getInputStream(), toString() + " (stdout)" );
        new Thread( errorLogger ).start();
        new Thread( outputLogger ).start();
        proc.waitFor();
      }

    } catch ( Exception e ) {
      throw new Exception( "Unable to create temporary file to execute script", e );
    }
  }
  return tempFile;
}
 
Example 3
Source File: CommandLineOption.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * @return the usage description
 *
 */
public String getUsageDescription() {
  String optionStart = "  -";
  String optionDelim = " = ";

  if ( Const.isWindows() ) {
    optionStart = "  /";
    optionDelim = " : ";
  }

  return optionStart + Const.rightPad( option, 14 ) + optionDelim + description;
}
 
Example 4
Source File: JobEntryEvalLoadSaveTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String getTestObject() {
  String lineTerminator = Const.isWindows() ? "\n" : Const.CR;
  StringBuilder text = new StringBuilder();
  int lines = new Random().nextInt( 10 ) + 1;
  for ( int i = 0; i < lines; i++ ) {
    text.append( super.getTestObject() );
    if ( i + 1 < lines ) {
      text.append( lineTerminator );
    }
  }
  return text.toString();
}
 
Example 5
Source File: LoadFileInputTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupBeforeClass() throws KettleException {
  if ( Const.isWindows() ) {
    wasEncoding = System.getProperty( "file.encoding" );
    fiddleWithDefaultCharset( "utf8" );
  }
  KettleClientEnvironment.init();
}
 
Example 6
Source File: JobEntryJobDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public JobEntryInterface open() {
  Shell parent = getParent();
  display = parent.getDisplay();

  shell = new Shell( parent, props.getJobsDialogStyle() );
  props.setLook( shell );
  JobDialog.setShellImage( shell, jobEntry );

  backupChanged = jobEntry.hasChanged();

  createElements();

  // Detect [X] or ALT-F4 or something that kills this window...
  shell.addShellListener( new ShellAdapter() {
    public void shellClosed( ShellEvent e ) {
      cancel();
    }
  } );

  getData();
  setActive();

  BaseStepDialog.setSize( shell );

  int width = 750;
  int height = Const.isWindows() ? 730 : 718;

  shell.setSize( width, height );
  shell.open();
  while ( !shell.isDisposed() ) {
    if ( !display.readAndDispatch() ) {
      display.sleep();
    }
  }
  return jobEntry;
}
 
Example 7
Source File: JobEntryJobDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void selectJob( ProviderFilterType providerFilterType ) {
  SelectionAdapterFileDialogTextVar
    selectionAdapterFileDialogTextVar = new SelectionAdapterFileDialogTextVar( log, wPath, jobMeta,
      new SelectionAdapterOptions( SelectionOperation.FILE,
      new FilterType[] { FilterType.KJB, FilterType.XML, FilterType.ALL }, FilterType.KJB,
      new ProviderFilterType[] { providerFilterType } ) );
  selectionAdapterFileDialogTextVar.widgetSelected( null );
  if ( wPath.getText() != null && Const.isWindows() ) {
    wPath.setText( wPath.getText().replace( '\\', '/' ) );
  }
}
 
Example 8
Source File: JobEntryTransDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public JobEntryInterface open() {
  Shell parent = getParent();
  display = parent.getDisplay();

  shell = new Shell( parent, props.getJobsDialogStyle() );
  props.setLook( shell );
  JobDialog.setShellImage( shell, jobEntry );

  backupChanged = jobEntry.hasChanged();

  createElements();

  // Detect [X] or ALT-F4 or something that kills this window...
  shell.addShellListener( new ShellAdapter() {
    public void shellClosed( ShellEvent e ) {
      cancel();
    }
  } );

  getData();
  setActive();

  BaseStepDialog.setSize( shell );

  int width = 750;
  int height = Const.isWindows() ? 730 : 720;

  shell.setSize( width, height );
  shell.open();
  while ( !shell.isDisposed() ) {
    if ( !display.readAndDispatch() ) {
      display.sleep();
    }
  }
  return jobEntry;
}
 
Example 9
Source File: JobEntryTransDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void selectTransformation( ProviderFilterType providerFilterType ) {
  SelectionAdapterFileDialogTextVar selectionAdapterFileDialogTextVar =
    new SelectionAdapterFileDialogTextVar( log, wPath, jobMeta, new SelectionAdapterOptions(
      SelectionOperation.FILE, new FilterType[] { FilterType.KTR, FilterType.XML, FilterType.ALL }, FilterType.KTR,
      new ProviderFilterType[] { providerFilterType } ) );
  selectionAdapterFileDialogTextVar.widgetSelected( null );
  if ( wPath.getText() != null && Const.isWindows() ) {
    wPath.setText( wPath.getText().replace( '\\', '/' ) );
  }
}
 
Example 10
Source File: SpoonTabsDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Rename the tabs
 */
public void renameTabs() {
  List<TabMapEntry> list = new ArrayList<TabMapEntry>( tabMap );
  for ( TabMapEntry entry : list ) {
    if ( entry.getTabItem().isDisposed() ) {
      // this should not be in the map, get rid of it.
      tabMap.remove( entry.getObjectName() );
      continue;
    }

    // TabItem before = entry.getTabItem();
    // PDI-1683: need to get the String here, otherwise using only the "before" instance below, the reference gets
    // changed and result is always the same
    // String beforeText=before.getText();
    //
    Object managedObject = entry.getObject().getManagedObject();
    if ( managedObject != null ) {
      if ( entry.getObject() instanceof AbstractGraph ) {
        AbstractMeta meta = (AbstractMeta) managedObject;
        String tabText = makeTabName( meta, entry.isShowingLocation() );
        entry.getTabItem().setText( tabText );
        String toolTipText = BaseMessages.getString( PKG, "Spoon.TabTrans.Tooltip", tabText );
        if ( entry.getObject() instanceof JobGraph ) {
          toolTipText = BaseMessages.getString( PKG, "Spoon.TabJob.Tooltip", tabText );
        }
        if ( Const.isWindows() && !Utils.isEmpty( meta.getFilename() ) ) {
          toolTipText += Const.CR + Const.CR + meta.getFilename();
        }
        entry.getTabItem().setToolTipText( toolTipText );
      }
    }
  }
  spoon.setShellText();
}
 
Example 11
Source File: SelectionAdapterFileDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static String replaceCurrentDir( String path, String parentPath ) {
  if ( !Utils.isEmpty( path ) && !Utils.isEmpty( parentPath ) && path.startsWith( parentPath ) ) {
    path = path.replace( parentPath, "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}" );

    // Ensure the path is uniform for windows. Path's using the internal variable need to use forward slash
    if ( Const.isWindows() ) {
      path = path.replace( '\\', '/' );
    }

  }
  return path;
}
 
Example 12
Source File: JobEntryPing.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private boolean classicPing( String hostname, int nrpackets ) {
  boolean retval = false;
  try {
    String lignePing = "";
    String CmdPing = "ping ";
    if ( Const.isWindows() ) {
      CmdPing += hostname + " " + Windows_CHAR + " " + nrpackets;
    } else {
      CmdPing += hostname + " " + NIX_CHAR + " " + nrpackets;
    }

    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobPing.NbrPackets.Label", "" + nrpackets ) );
      logDetailed( BaseMessages.getString( PKG, "JobPing.ExecClassicPing.Label", CmdPing ) );
    }
    Process processPing = Runtime.getRuntime().exec( CmdPing );
    try {
      processPing.waitFor();
    } catch ( InterruptedException e ) {
      logDetailed( BaseMessages.getString( PKG, "JobPing.ClassicPingInterrupted" ) );
    }
    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobPing.Gettingresponse.Label", hostname ) );
    }
    // Get ping response
    BufferedReader br = new BufferedReader( new InputStreamReader( processPing.getInputStream() ) );

    // Read response lines
    while ( ( lignePing = br.readLine() ) != null ) {
      if ( log.isDetailed() ) {
        logDetailed( lignePing );
      }
    }
    // We succeed only when 0% lost of data
    if ( processPing.exitValue() == 0 ) {
      retval = true;
    }
  } catch ( IOException ex ) {
    logError( BaseMessages.getString( PKG, "JobPing.Error.Label" ) + ex.getMessage() );
  }
  return retval;
}
 
Example 13
Source File: TableView.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void optWidth( boolean header, int nrLines ) {
  for ( int c = 0; c < table.getColumnCount(); c++ ) {
    TableColumn tc = table.getColumn( c );
    int max = 0;
    if ( header ) {
      max = TableView.dummyGC.textExtent( tc.getText(), SWT.DRAW_TAB | SWT.DRAW_DELIMITER ).x;

      // Check if the column has a sorted mark set. In that case, we need the
      // header to be a bit wider...
      //
      if ( c == sortfield && sortable ) {
        max += 15;
      }
    }
    Set<String> columnStrings = new HashSet<String>();

    boolean haveToGetTexts = false;
    if ( c > 0 ) {
      final ColumnInfo column = columns[c - 1];
      if ( column != null ) {
        switch ( column.getType() ) {
          case ColumnInfo.COLUMN_TYPE_TEXT:
            haveToGetTexts = true;
            break;
          case ColumnInfo.COLUMN_TYPE_CCOMBO:
          case ColumnInfo.COLUMN_TYPE_FORMAT:
            haveToGetTexts = true;
            if ( column.getComboValues() != null ) {
              for ( String comboValue : columns[c - 1].getComboValues() ) {
                columnStrings.add( comboValue );
              }
            }
            break;
          case ColumnInfo.COLUMN_TYPE_BUTTON:
            columnStrings.add( column.getButtonText() );
            break;
          default:
            break;

        }
      }
    } else {
      haveToGetTexts = true;
    }

    if ( haveToGetTexts ) {
      for ( int r = 0; r < table.getItemCount() && ( r < nrLines || nrLines <= 0 ); r++ ) {
        TableItem ti = table.getItem( r );
        if ( ti != null ) {
          columnStrings.add( ti.getText( c ) );
        }
      }
    }

    for ( String str : columnStrings ) {
      int len = TableView.dummyGC.textExtent( str == null ? "" : str, SWT.DRAW_TAB | SWT.DRAW_DELIMITER ).x;
      if ( len > max ) {
        max = len;
      }
    }

    try {
      int extra = 15;
      if ( Const.isWindows() || Const.isLinux() ) {
        extra += 15;
      }

      if ( tc.getWidth() != max + extra ) {
        if ( c > 0 ) {
          if ( columns[c - 1].getWidth() == -1 ) {
            tc.setWidth( max + extra );
          } else {
            tc.setWidth( columns[c - 1].getWidth() );
          }
        }
      }
    } catch ( Exception e ) {
      // Ignore errors
    }
  }
  if ( table.isListening( SWT.Resize ) ) {
    Event resizeEvent = new Event();
    resizeEvent.widget = table;
    resizeEvent.type = SWT.Resize;
    resizeEvent.display = getDisplay();
    resizeEvent.setBounds( table.getBounds() );
    table.notifyListeners( SWT.Resize, resizeEvent );
  }
  unEdit();
}