Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Issue #11
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcasters committed Dec 15, 2018
1 parent 6338fd4 commit 79c2aa1
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@


<groupId>kettle-environment</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</project>
18 changes: 15 additions & 3 deletions src/main/java/org/kettle/env/environment/EnvironmentDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import org.pentaho.di.ui.core.gui.GUIResource;
import org.pentaho.di.ui.core.gui.WindowProperty;
import org.pentaho.di.ui.core.widget.ColumnInfo;
import org.pentaho.di.ui.core.widget.ComboVar;
import org.pentaho.di.ui.core.widget.TableView;
import org.pentaho.di.ui.core.widget.TextVar;
import org.pentaho.di.ui.trans.step.BaseStepDialog;
import org.pentaho.metastore.persist.MetaStoreFactory;

import java.util.List;

public class EnvironmentDialog extends Dialog {
private static Class<?> PKG = EnvironmentsDialog.class; // for i18n purposes, needed by Translator2!!

Expand All @@ -47,7 +50,7 @@ public class EnvironmentDialog extends Dialog {
private TextVar wEnvironmentHome;
private TextVar wKettleHomeFolder;
private TextVar wMetaStoreBaseFolder;
private TextVar wSpoonGitProject;
private ComboVar wSpoonGitProject;
private TextVar wUnitTestsBasePath;
private TextVar wDataSetCsvFolder;
private Button wEnforceHomeExecution;
Expand Down Expand Up @@ -98,6 +101,14 @@ public boolean open() {
wCancel.setText( BaseMessages.getString( PKG, "System.Button.Cancel" ) );
wCancel.addListener( SWT.Selection, event -> cancel() );

String[] gitRepoNames;
try {
gitRepoNames = EnvironmentUtil.getGitRepositoryNames().toArray(new String[0]);
} catch(Exception e) {
e.printStackTrace();
gitRepoNames = new String[] {"---Unable to load---"};
}

// Buttons go at the bottom of the dialog
//
BaseStepDialog.positionBottomButtons( shell, new Button[] { wOK, wCancel }, margin * 3, null );
Expand Down Expand Up @@ -267,8 +278,9 @@ public boolean open() {
fdlSpoonGitProject.right = new FormAttachment( middle, 0 );
fdlSpoonGitProject.top = new FormAttachment( lastControl, margin );
wlSpoonGitProject.setLayoutData( fdlSpoonGitProject );
wSpoonGitProject = new TextVar( space, shell, SWT.SINGLE | SWT.BORDER | SWT.LEFT );
props.setLook( wSpoonGitProject );
wSpoonGitProject = new ComboVar( space, shell, SWT.SINGLE | SWT.BORDER | SWT.LEFT );
// props.setLook( wSpoonGitProject );
wSpoonGitProject.setItems( gitRepoNames );
FormData fdSpoonGitProject = new FormData();
fdSpoonGitProject.left = new FormAttachment( middle, margin );
fdSpoonGitProject.right = new FormAttachment( 100, 0 );
Expand Down
82 changes: 79 additions & 3 deletions src/main/java/org/kettle/env/util/EnvironmentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.KettleLogStore;
import org.pentaho.di.core.logging.LogChannelInterface;
import org.pentaho.di.core.plugins.PluginInterface;
import org.pentaho.di.core.plugins.PluginRegistry;
import org.pentaho.di.core.util.EnvUtil;
import org.pentaho.di.core.variables.VariableSpace;
import org.pentaho.di.core.variables.Variables;
import org.pentaho.di.core.vfs.KettleVFS;
import org.pentaho.di.metastore.MetaStoreConst;
import org.pentaho.di.ui.spoon.Spoon;
import org.pentaho.di.ui.spoon.SpoonPerspective;
import org.pentaho.di.ui.spoon.SpoonPerspectiveManager;
import org.pentaho.di.ui.spoon.SpoonPluginType;
import org.pentaho.metastore.api.IMetaStore;
import org.pentaho.metastore.api.exceptions.MetaStoreException;
import org.pentaho.metastore.stores.delegate.DelegatingMetaStore;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class EnvironmentUtil {

public static final String VARIABLE_ENVIRONMENT_HOME = "ENVIRONMENT_HOME";
Expand Down Expand Up @@ -68,14 +79,79 @@ public static void enableEnvironment( Environment environment, DelegatingMetaSto
delegatingMetaStore.setActiveMetaStoreName( metaStore.getName() );
}
}

loadSpoonGitRepository( environment );


}

/**
* Finally, if we're running in Spoon and if the
* GitSpoonPlugin is loaded, load the specified repo
*
* @param environment
*/
public static void loadSpoonGitRepository( Environment environment ) throws KettleException {
Spoon spoon = Spoon.getInstance();
if ( spoon == null ) {
return;
}

PluginInterface gitSpoonPlugin = PluginRegistry.getInstance().getPlugin( SpoonPluginType.class, "GitSpoonPlugin" );
if ( gitSpoonPlugin == null ) {
return;
}

String repoName = environment.getSpoonGitProject();
if ( StringUtils.isEmpty( repoName ) ) {
return;
}

VariableSpace space = new Variables();
space.initializeVariablesFrom( null );

String realRepoName = space.environmentSubstitute( repoName );
try {
SpoonPerspectiveManager perspectiveManager = SpoonPerspectiveManager.getInstance();
for ( SpoonPerspective spoonPerspective : perspectiveManager.getPerspectives() ) {
if ( spoonPerspective.getId().equals( "010-git" ) ) {

// This is the one!
Method loadRepoMethod = spoonPerspective.getClass().getMethod( "openRepository", String.class );
loadRepoMethod.invoke( spoonPerspective, realRepoName );

break;
}
}
} catch ( Exception e ) {
throw new KettleException( "Unable to load git repository", e );
}

}

public static List<String> getGitRepositoryNames() throws KettleException {
SpoonPerspectiveManager perspectiveManager = SpoonPerspectiveManager.getInstance();
for ( SpoonPerspective spoonPerspective : perspectiveManager.getPerspectives() ) {
if ( spoonPerspective.getId().equals( "010-git" ) ) {

// This is the one!
try {
Method getRepoNamesMethod = spoonPerspective.getClass().getMethod( "getRepoNames", new Class<?>[] {} );
return (List<String>) getRepoNamesMethod.invoke( spoonPerspective, new Object[] {} );
} catch ( Exception e ) {
throw new KettleException( "Unable to list Git Repository names", e );
}
}
}
return new ArrayList<>();
}

public static void validateFileInEnvironment( LogChannelInterface log, String transFilename, Environment environment, VariableSpace space ) throws KettleException, FileSystemException {
if ( StringUtils.isNotEmpty( transFilename ) ) {
// See that this filename is located under the environment home folder
//
String environmentHome = space.environmentSubstitute( environment.getEnvironmentHomeFolder() );
log.logBasic( "Validation against environment home : "+environmentHome );
log.logBasic( "Validation against environment home : " + environmentHome );

FileObject envHome = KettleVFS.getFileObject( environmentHome );
FileObject transFile = KettleVFS.getFileObject( transFilename );
Expand All @@ -92,12 +168,12 @@ private static boolean isInSubDirectory( FileObject file, FileObject directory )

// Same?
if ( filePath.equals( directoryPath ) ) {
System.out.println( "Found "+filePath+" in directory "+directoryPath );
System.out.println( "Found " + filePath + " in directory " + directoryPath );
return true;
}

FileObject parent = file.getParent();
if ( parent!=null && isInSubDirectory( parent, directory ) ) {
if ( parent != null && isInSubDirectory( parent, directory ) ) {
return true;
}
return false;
Expand Down

0 comments on commit 79c2aa1

Please sign in to comment.