Skip to content

Commit

Permalink
Merge pull request #25 from bioclipse/bug3427
Browse files Browse the repository at this point in the history
Fixes for bug 3427
  • Loading branch information
goglepox committed Jan 23, 2013
2 parents d3206e9 + af95872 commit 24f4be8
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 4 deletions.
Expand Up @@ -12,9 +12,23 @@
******************************************************************************/
package net.bioclipse.scripting.ui.tests;

import static org.junit.Assert.*;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.junit.Assert;
import org.junit.Test;

import net.bioclipse.core.MockIFile;
Expand Down Expand Up @@ -74,4 +88,51 @@ public void testExecuteFile() {
).extension( "js" );
console.executeFile(file);
}

@Test
public void testExecute() throws Exception {
final IFile file1 = new MockIFile(
new ByteArrayInputStream("i = 5;".getBytes())
).extension( "js" );
final IFile file2 = new MockIFile(
new ByteArrayInputStream("i = 5;".getBytes())
).extension( "js" );
console.executeFile(file1);
console.execute( file1 );
console.execute( new ArrayList<IFile>() {{add(file1); add(file2);}} );

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("TEST");
project.create(new NullProgressMonitor());
project.open(new NullProgressMonitor());
String filePath = "/TEST/testFile99883423427.js";
final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(
new Path(filePath)
);
Job job = new Job("test") {
@Override
protected IStatus run( IProgressMonitor monitor ) {
try {
file.create( new ByteArrayInputStream(
"i = 5;".getBytes()), true, monitor );
} catch ( CoreException e ) {
fail( e.getMessage() );
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
job.setRule( file );
job.schedule();
job.join();

final IFile savedFile = ResourcesPlugin.getWorkspace()
.getRoot()
.getFile( new Path(filePath) );

console.execute( new ArrayList<String>() {{
add(file.getFullPath().toString());
add(file.getFullPath().toString());
}} );
}
}
Expand Up @@ -12,6 +12,8 @@
******************************************************************************/
package net.bioclipse.scripting.ui.business;

import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;

Expand All @@ -21,6 +23,7 @@
import net.bioclipse.core.TestClasses;
import net.bioclipse.core.TestMethods;
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.core.util.IJavaScriptConsolePrinterChannel;

/**
Expand Down Expand Up @@ -58,14 +61,34 @@ public interface IJsConsoleManager extends IBioclipseManager,
@TestMethods("testEval")
public String eval(String command);

@Recorded
@TestMethods("testExecute")
public void execute(IFile file);

@Recorded
@TestMethods("testExecute")
@PublishedMethod( params="String file",
methodSummary="Runs a js script file.")
public void execute(String file);

@Recorded
@TestMethods("testExecute")
@PublishedMethod( params="List files",
methodSummary="Runs a js script file.")
public void execute(List<?> files) throws BioclipseException;

@Recorded
@TestMethods("testExecuteFile")
@Deprecated
public void executeFile(IFile file);

@Recorded
@PublishedMethod(params="String filePath",
methodSummary="Runs a js script file.")
@PublishedMethod(
params="String filePath",
methodSummary="Runs a js script file. Marked for removal. " +
"Use js.execute instead." )
@TestMethods("testExecuteFile")
@Deprecated
public void executeFile(String filePath);

public void printError( Throwable t );
Expand Down
Expand Up @@ -12,6 +12,11 @@
******************************************************************************/
package net.bioclipse.scripting.ui.business;

import java.util.ArrayList;
import java.util.List;

import net.bioclipse.core.ResourcePathTransformer;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.scripting.Activator;
import net.bioclipse.scripting.Hook;
Expand Down Expand Up @@ -92,8 +97,8 @@ public void run( Object result ) {
);
return evalResult[0];
}

public void executeFile( final IFile file ) {
public void execute( final IFile file ) {
Job job = new Job("JavaScript execution") {
@Override
protected IStatus run(final IProgressMonitor monitor) {
Expand Down Expand Up @@ -152,9 +157,35 @@ public void run() {
}
};
job.schedule();

}

@Deprecated
public void executeFile( final IFile file ) {
execute(file);
}

public void printError( Throwable t ) {
print( getJsConsoleView().getErrorMessage( t ) );
}

public void execute( List<?> files ) throws BioclipseException {
int i = 0;
for ( Object o : files) {
if ( o instanceof IFile ) {
execute( (IFile)o );
}
else if ( o instanceof String ) {
execute( ResourcePathTransformer.getInstance()
.transform( (String)o ) );
}
else {
throw new BioclipseException(
"List of files given to the js.execute method contained " +
"an element at index " + i + " which could not be " +
"identified as a file. The element was: " + o.toString() );
}
i++;
}
}
}

0 comments on commit 24f4be8

Please sign in to comment.