Skip to content

Commit

Permalink
[BACKLOG-41094] - changes to use a Bowl for all VFS operations
Browse files Browse the repository at this point in the history
  • Loading branch information
abryant-hv committed Sep 11, 2024
1 parent 0fc708d commit c9f1e71
Show file tree
Hide file tree
Showing 710 changed files with 4,154 additions and 2,824 deletions.
5 changes: 3 additions & 2 deletions core/src/main/java/org/pentaho/di/core/ResultFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2021 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2002-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -25,6 +25,7 @@
import java.util.Date;

import org.apache.commons.vfs2.FileObject;
import org.pentaho.di.core.bowl.DefaultBowl;
import org.pentaho.di.core.exception.KettleFileException;
import org.pentaho.di.core.row.value.ValueMetaDate;
import org.pentaho.di.core.row.value.ValueMetaString;
Expand Down Expand Up @@ -291,7 +292,7 @@ public String getXML() {
public ResultFile( Node node ) throws KettleFileException {
try {
type = getType( XMLHandler.getTagValue( node, "type" ) );
file = KettleVFS.getFileObject( XMLHandler.getTagValue( node, "file" ) );
file = KettleVFS.getInstance( DefaultBowl.getInstance() ).getFileObject( XMLHandler.getTagValue( node, "file" ) );
originParent = XMLHandler.getTagValue( node, "parentorigin" );
origin = XMLHandler.getTagValue( node, "origin" );
comment = XMLHandler.getTagValue( node, "comment" );
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/org/pentaho/di/core/database/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2023 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2002-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -58,6 +58,7 @@

import org.apache.commons.lang.StringUtils;
import org.apache.commons.vfs2.FileObject;
import org.pentaho.di.core.bowl.Bowl;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.plugins.PluginTypeListener;
import org.pentaho.di.core.row.value.ValueMetaPluginType;
Expand Down Expand Up @@ -5025,15 +5026,16 @@ public void setNrExecutedCommits( int nrExecutedCommits ) {
* @throws KettleDatabaseException in case anything goes wrong.
* @sendSinglestatement send one statement
*/
public Result execStatementsFromFile( String filename, boolean sendSinglestatement ) throws KettleException {
public Result execStatementsFromFile( Bowl bowl, String filename, boolean sendSinglestatement )
throws KettleException {
FileObject sqlFile = null;
InputStream is = null;
InputStreamReader bis = null;
try {
if ( Utils.isEmpty( filename ) ) {
throw new KettleException( "Filename is missing!" );
}
sqlFile = KettleVFS.getFileObject( filename );
sqlFile = KettleVFS.getInstance( bowl ).getFileObject( filename );
if ( !sqlFile.exists() ) {
throw new KettleException( "We can not find file [" + filename + "]!" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2017 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2002-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -26,6 +26,7 @@
import java.util.List;

import org.apache.commons.vfs2.FileObject;
import org.pentaho.di.core.bowl.DefaultBowl;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.vfs.KettleVFS;
Expand Down Expand Up @@ -71,10 +72,10 @@ public FileLoggingEventListener( String logChannelId, String filename, boolean a
this.layout = new KettleLogLayout( true );
this.exception = null;

file = KettleVFS.getFileObject( filename );
file = KettleVFS.getInstance( DefaultBowl.getInstance() ).getFileObject( filename );
outputStream = null;
try {
outputStream = KettleVFS.getOutputStream( file, append );
outputStream = KettleVFS.getInstance( DefaultBowl.getInstance() ).getOutputStream( file, append );
} catch ( Exception e ) {
throw new KettleException(
"Unable to create a logging event listener to write to file '" + filename + "'", e );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2022 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2022-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -29,6 +29,7 @@
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LogEvent;
import org.pentaho.di.core.bowl.DefaultBowl;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.vfs.KettleVFS;

Expand All @@ -45,13 +46,13 @@ public class Log4jFileAppender implements Appender {
public Log4jFileAppender(FileObject file ) throws IOException {
this.file = file;

fileOutputStream = KettleVFS.getOutputStream( file, false );
fileOutputStream = KettleVFS.getInstance( DefaultBowl.getInstance() ).getOutputStream( file, false );
}

public Log4jFileAppender(FileObject file, boolean append ) throws IOException {
this.file = file;

fileOutputStream = KettleVFS.getOutputStream( file, append );
fileOutputStream = KettleVFS.getInstance( DefaultBowl.getInstance() ).getOutputStream( file, append );
}

public void addFilter( Filter filter ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2019 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2002-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -45,6 +45,7 @@
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSelectInfo;
import org.apache.commons.vfs2.FileSelector;
import org.pentaho.di.core.bowl.DefaultBowl;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.util.Utils;
Expand Down Expand Up @@ -432,7 +433,7 @@ protected List<FileObject> findPluginFiles( String folder, final String regex )

List<FileObject> list = new ArrayList<>();
try {
FileObject folderObject = KettleVFS.getFileObject( folder );
FileObject folderObject = KettleVFS.getInstance( DefaultBowl.getInstance() ).getFileObject( folder );
FileObject[] files = folderObject.findFiles( new FileSelector() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2018 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2002-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand All @@ -27,6 +27,7 @@
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSelectInfo;
import org.apache.commons.vfs2.FileSelector;
import org.pentaho.di.core.bowl.DefaultBowl;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleFileException;
import org.pentaho.di.core.util.EnvUtil;
Expand Down Expand Up @@ -122,7 +123,7 @@ public FileObject[] findJarFiles( final boolean includeLibJars ) throws KettleFi
try {
// Find all the jar files in this folder...
//
FileObject folderObject = KettleVFS.getFileObject( this.getFolder() );
FileObject folderObject = KettleVFS.getInstance( DefaultBowl.getInstance() ).getFileObject( this.getFolder() );

return folderObject.findFiles( new FileSelector() {
@Override
Expand Down
56 changes: 30 additions & 26 deletions core/src/main/java/org/pentaho/di/core/row/ValueDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2022 by Hitachi Vantara : http://www.pentaho.com
* Copyright (C) 2002-2024 by Hitachi Vantara : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -33,6 +33,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.pentaho.di.core.bowl.Bowl;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleFileNotFoundException;
import org.pentaho.di.core.exception.KettleValueException;
Expand Down Expand Up @@ -377,10 +378,10 @@ public static long stringLen( ValueMetaInterface metaA, Object dataA ) {
* @deprecated Use {@link ValueDataUtil#createChecksum(ValueMetaInterface, Object, String, boolean)} instead
*/
@Deprecated
public static String createChecksum( ValueMetaInterface metaA, Object dataA, String type ) {
public static String createChecksum( Bowl bowl, ValueMetaInterface metaA, Object dataA, String type ) {
String checksum = null;
try {
checksum = createChecksum( metaA, dataA, type, false );
checksum = createChecksum( bowl, metaA, dataA, type, false );
} catch ( KettleFileNotFoundException e ) {
// Ignore
}
Expand All @@ -400,7 +401,8 @@ public static String createChecksum( ValueMetaInterface metaA, Object dataA, Str
* @return File's checksum
* @throws KettleFileNotFoundException
*/
public static String createChecksum( ValueMetaInterface metaA, Object dataA, String type, boolean failIfNoFile )
public static String createChecksum( Bowl bowl, ValueMetaInterface metaA, Object dataA, String type,
boolean failIfNoFile )
throws KettleFileNotFoundException {
if ( dataA == null ) {
return null;
Expand All @@ -410,7 +412,7 @@ public static String createChecksum( ValueMetaInterface metaA, Object dataA, Str
FileObject file = null;
InputStream in = null;
try {
file = KettleVFS.getFileObject( dataA.toString() );
file = KettleVFS.getInstance( bowl ).getFileObject( dataA.toString() );
throwsErrorOnFileNotFound( file );
in = KettleVFS.getInputStream( file );
int bytes = in.available();
Expand Down Expand Up @@ -444,10 +446,10 @@ public static String createChecksum( ValueMetaInterface metaA, Object dataA, Str
* @deprecated Use {@link ValueDataUtil#checksumCRC32(ValueMetaInterface, Object, boolean)} instead
*/
@Deprecated
public static Long ChecksumCRC32( ValueMetaInterface metaA, Object dataA ) {
public static Long ChecksumCRC32( Bowl bowl, ValueMetaInterface metaA, Object dataA ) {
long checksum = 0;
try {
checksum = checksumCRC32( metaA, dataA, false );
checksum = checksumCRC32( bowl, metaA, dataA, false );
} catch ( KettleFileNotFoundException e ) {
// Ignore
}
Expand All @@ -465,7 +467,7 @@ public static Long ChecksumCRC32( ValueMetaInterface metaA, Object dataA ) {
* @return File's CRC32 checksum
* @throws KettleFileNotFoundException
*/
public static Long checksumCRC32( ValueMetaInterface metaA, Object dataA, boolean failIfNoFile )
public static Long checksumCRC32( Bowl bowl, ValueMetaInterface metaA, Object dataA, boolean failIfNoFile )
throws KettleFileNotFoundException {
long checksum = 0;

Expand All @@ -476,7 +478,7 @@ public static Long checksumCRC32( ValueMetaInterface metaA, Object dataA, boolea
FileObject file = null;
CheckedInputStream cis = null;
try {
file = KettleVFS.getFileObject( dataA.toString() );
file = KettleVFS.getInstance( bowl ).getFileObject( dataA.toString() );
throwsErrorOnFileNotFound( file );
cis = null;

Expand Down Expand Up @@ -508,10 +510,10 @@ public static Long checksumCRC32( ValueMetaInterface metaA, Object dataA, boolea
* @deprecated Use {@link ValueDataUtil#checksumAdler32(ValueMetaInterface, Object, boolean)} instead
*/
@Deprecated
public static Long ChecksumAdler32( ValueMetaInterface metaA, Object dataA ) {
public static Long ChecksumAdler32( Bowl bowl, ValueMetaInterface metaA, Object dataA ) {
long checksum = 0;
try {
checksum = checksumAdler32( metaA, dataA, false );
checksum = checksumAdler32( bowl, metaA, dataA, false );
} catch ( KettleFileNotFoundException e ) {
// Ignore
}
Expand All @@ -529,7 +531,7 @@ public static Long ChecksumAdler32( ValueMetaInterface metaA, Object dataA ) {
* @return File's Adler32 checksum
* @throws KettleFileNotFoundException
*/
public static Long checksumAdler32( ValueMetaInterface metaA, Object dataA, boolean failIfNoFile )
public static Long checksumAdler32( Bowl bowl, ValueMetaInterface metaA, Object dataA, boolean failIfNoFile )
throws KettleFileNotFoundException {
long checksum = 0;

Expand All @@ -540,7 +542,7 @@ public static Long checksumAdler32( ValueMetaInterface metaA, Object dataA, bool
FileObject file = null;
CheckedInputStream cis = null;
try {
file = KettleVFS.getFileObject( dataA.toString() );
file = KettleVFS.getInstance( bowl ).getFileObject( dataA.toString() );
throwsErrorOnFileNotFound( file );
cis = null;

Expand Down Expand Up @@ -671,10 +673,11 @@ public static Object sum( ValueMetaInterface metaA, Object dataA, ValueMetaInter
* @deprecated Use {@link ValueDataUtil#loadFileContentInBinary(ValueMetaInterface, Object, boolean)} instead
*/
@Deprecated
public static Object loadFileContentInBinary( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {
public static Object loadFileContentInBinary( Bowl bowl, ValueMetaInterface metaA, Object dataA )
throws KettleValueException {
Object content = null;
try {
content = loadFileContentInBinary( metaA, dataA, true );
content = loadFileContentInBinary( bowl, metaA, dataA, true );
} catch ( KettleFileNotFoundException e ) {
throw new KettleValueException();
}
Expand All @@ -693,8 +696,8 @@ public static Object loadFileContentInBinary( ValueMetaInterface metaA, Object d
* @throws KettleValueException
* @throws KettleFileNotFoundException
*/
public static byte[] loadFileContentInBinary( ValueMetaInterface metaA, Object dataA, boolean failIfNoFile )
throws KettleValueException, KettleFileNotFoundException {
public static byte[] loadFileContentInBinary( Bowl bowl, ValueMetaInterface metaA, Object dataA,
boolean failIfNoFile ) throws KettleValueException, KettleFileNotFoundException {
if ( dataA == null ) {
return null;
}
Expand All @@ -704,7 +707,7 @@ public static byte[] loadFileContentInBinary( ValueMetaInterface metaA, Object d
InputStream is = null;

try {
file = KettleVFS.getFileObject( dataA.toString() );
file = KettleVFS.getInstance( bowl ).getFileObject( dataA.toString() );
throwsErrorOnFileNotFound( file );
is = KettleVFS.getInputStream( file );
int fileSize = (int) file.getContent().getSize();
Expand Down Expand Up @@ -2123,10 +2126,10 @@ public static final boolean onlySpaces( String str ) {
* @deprecated Use {@link ValueDataUtil#isXMLFileWellFormed(ValueMetaInterface, Object, boolean)} instead
*/
@Deprecated
public static boolean isXMLFileWellFormed( ValueMetaInterface metaA, Object dataA ) {
public static boolean isXMLFileWellFormed( Bowl bowl, ValueMetaInterface metaA, Object dataA ) {
boolean xmlWellFormed = false;
try {
xmlWellFormed = isXMLFileWellFormed( metaA, dataA, false );
xmlWellFormed = isXMLFileWellFormed( bowl, metaA, dataA, false );
} catch ( KettleFileNotFoundException e ) {
// Ignore
}
Expand All @@ -2145,7 +2148,7 @@ public static boolean isXMLFileWellFormed( ValueMetaInterface metaA, Object data
* @return true if the file is well formed.
* @throws KettleFileNotFoundException
*/
public static boolean isXMLFileWellFormed( ValueMetaInterface metaA, Object dataA, boolean failIfNoFile )
public static boolean isXMLFileWellFormed( Bowl bowl, ValueMetaInterface metaA, Object dataA, boolean failIfNoFile )
throws KettleFileNotFoundException {
if ( dataA == null ) {
return false;
Expand All @@ -2154,7 +2157,7 @@ public static boolean isXMLFileWellFormed( ValueMetaInterface metaA, Object data
String filename = dataA.toString();
FileObject file = null;
try {
file = KettleVFS.getFileObject( filename );
file = KettleVFS.getInstance( bowl ).getFileObject( filename );
throwsErrorOnFileNotFound( file );
return XMLCheck.isXMLFileWellFormed( file );
} catch ( KettleFileNotFoundException e ) {
Expand Down Expand Up @@ -2202,10 +2205,11 @@ public static boolean isXMLWellFormed( ValueMetaInterface metaA, Object dataA )
* @deprecated Use {@link ValueDataUtil#getFileEncoding(ValueMetaInterface, Object, boolean)} instead
*/
@Deprecated
public static String getFileEncoding( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {
public static String getFileEncoding( Bowl bowl, ValueMetaInterface metaA, Object dataA )
throws KettleValueException {
String encoding = null;
try {
encoding = getFileEncoding( metaA, dataA, true );
encoding = getFileEncoding( bowl, metaA, dataA, true );
} catch ( KettleFileNotFoundException e ) {
throw new KettleValueException();
}
Expand All @@ -2225,7 +2229,7 @@ public static String getFileEncoding( ValueMetaInterface metaA, Object dataA ) t
* @throws KettleFileNotFoundException
* @throws KettleValueException
*/
public static String getFileEncoding( ValueMetaInterface metaA, Object dataA, boolean failIfNoFile )
public static String getFileEncoding( Bowl bowl, ValueMetaInterface metaA, Object dataA, boolean failIfNoFile )
throws KettleValueException, KettleFileNotFoundException {
if ( dataA == null ) {
return null;
Expand All @@ -2234,7 +2238,7 @@ public static String getFileEncoding( ValueMetaInterface metaA, Object dataA, bo
String encoding = null;
FileObject file = null;
try {
file = KettleVFS.getFileObject( metaA.getString( dataA ) );
file = KettleVFS.getInstance( bowl ).getFileObject( metaA.getString( dataA ) );
throwsErrorOnFileNotFound( file );
encoding = CharsetToolkit.guessEncodingName( file );
} catch ( KettleFileNotFoundException e ) {
Expand Down
Loading

0 comments on commit c9f1e71

Please sign in to comment.