Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/runtime exec #21

Merged
merged 30 commits into from May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eaf1ced
Adding Runtime.exec
ricardobna Apr 17, 2020
d5523b1
FileInputChannel implementation
ricardobna Apr 20, 2020
dac3e84
Creating FileInputStream and and returning the Proccess with it
ricardobna Apr 20, 2020
2230ac2
Fixing stream to use byte array instead of ByteBuffer on java side
ricardobna Apr 22, 2020
7188664
Reverting wrong change on last commit
ricardobna Apr 22, 2020
a797028
Binding OutputStream and ErrorStream
ricardobna Apr 22, 2020
82f57c4
Set file descriptors to the value returned from cpproc_forkAndExec
ricardobna Apr 23, 2020
09a9370
OutputStream and ErrorStream
ricardobna Apr 23, 2020
ea6fe82
Added files to Makefile
acmlira Apr 23, 2020
98c97f4
Calling cpproc_forAndExec with correct values
ricardobna Apr 23, 2020
d403ad8
Fixing malloc and strings
ricardobna Apr 23, 2020
e88f2b7
Testing with filePath NULL
ricardobna Apr 23, 2020
23c65e6
Runtime.exec working without path.
ricardobna Apr 24, 2020
309f0bb
Updating Runtime interface and adding filePath to Runtime.c
ricardobna Apr 24, 2020
920a6da
Forgotten chdir
acmlira Apr 24, 2020
3136bfd
Adding exitValue, waitFor and destroy.
ricardobna Apr 27, 2020
0e0dbc2
Cleaning up some code and adding exceptions to error cases.
ricardobna Apr 28, 2020
09667ac
Changing memory allocation to heap on Runtime and fixing some exceptions
ricardobna Apr 29, 2020
cb957fd
Added Runtime stuff to Linux ARM build
acmlira Apr 29, 2020
6b1490c
Removing not used java classes and adding licenses.
ricardobna May 14, 2020
9546bbb
Removing more unused code from c
ricardobna May 14, 2020
934f8b9
Update TotalCrossSDK/src/main/java/jdkcompat/nio/channels/FileChannel…
ricardobna May 18, 2020
8eb230b
Adding exception to reads with error value on return and changing byt…
ricardobna May 18, 2020
77f87bd
Removing FileChannelImpl from NativeMethods.txt
ricardobna May 18, 2020
aeaa0b6
FIxing format
ricardobna May 19, 2020
85cb187
Removing leftover from ByteBuffer support
ricardobna May 19, 2020
098ed70
Update TotalCrossVM/src/nm/lang/Runtime.c
flsobral May 19, 2020
5602211
Apply suggestions from code review
flsobral May 19, 2020
21366e1
Apply suggestions from code review
flsobral May 19, 2020
ba804b2
Adding exception to windows, android and iOS and adding the file to C…
ricardobna May 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions TotalCrossSDK/src/main/java/jdkcompat/io/FileInputStream4D.java
@@ -0,0 +1,47 @@
// Copyright (C) 2000-2013 SuperWaba Ltda.
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda.
//
// SPDX-License-Identifier: LGPL-2.1-only

package jdkcompat.io;

import java.io.IOException;
import java.io.InputStream;

import jdkcompat.nio.channels.FileChannelImpl4D;


public class FileInputStream4D extends InputStream {
FileChannelImpl4D fileChannel;

FileInputStream4D(FileChannelImpl4D fileChannel) {
this.fileChannel = fileChannel;
}

@Override
public int read() throws IOException {
return fileChannel.read();
}

@Override
public int read(byte[] dst) throws IOException {
return fileChannel.read(dst, 0, dst.length);
}

@Override
public int read(byte[] dsts, int offset, int length) throws IOException {
return fileChannel.read(dsts, offset, length);
}

@Override
public void close() throws IOException {
fileChannel.close();
}

@Override
public int available() throws IOException {
return fileChannel.available();
}


}
31 changes: 31 additions & 0 deletions TotalCrossSDK/src/main/java/jdkcompat/io/FileOutputStream4D.java
@@ -0,0 +1,31 @@
// Copyright (C) 2000-2013 SuperWaba Ltda.
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda.
//
// SPDX-License-Identifier: LGPL-2.1-only

package jdkcompat.io;

import java.io.IOException;
import java.io.OutputStream;

import jdkcompat.nio.channels.FileChannelImpl4D;

public class FileOutputStream4D extends OutputStream {

FileChannelImpl4D fileChannel;

FileOutputStream4D(FileChannelImpl4D fileChannel) {
this.fileChannel = fileChannel;
}

@Override
public void write(int b) throws IOException {

}

@Override
public void write(byte[] b, int off, int len) throws IOException {
fileChannel.write(b, off, len);
}

}
@@ -0,0 +1,17 @@
// Copyright (C) 2000-2013 SuperWaba Ltda.
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda.
//
// SPDX-License-Identifier: LGPL-2.1-only

package jdkcompat.lang;

public class IllegalThreadStateException4D extends IllegalArgumentException {

public IllegalThreadStateException4D() {

}

public IllegalThreadStateException4D(String s) {
super(s);
}
}
35 changes: 35 additions & 0 deletions TotalCrossSDK/src/main/java/jdkcompat/lang/Process4D.java
@@ -0,0 +1,35 @@
// Copyright (C) 2000-2013 SuperWaba Ltda.
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda.
//
// SPDX-License-Identifier: LGPL-2.1-only

package jdkcompat.lang;

import java.io.InputStream;
import java.io.OutputStream;

public abstract class Process4D {

boolean isAlive;

public abstract void destroy();

public Process4D destroyForcibly() {
return this;
}

public abstract int exitValue();

public abstract InputStream getErrorStream();

public abstract InputStream getInputStream();

public abstract OutputStream getOutputStream();

public boolean isAlive() {
return isAlive;
}

public abstract int waitFor();

}
42 changes: 42 additions & 0 deletions TotalCrossSDK/src/main/java/jdkcompat/lang/ProcessImpl4D.java
@@ -0,0 +1,42 @@
// Copyright (C) 2000-2013 SuperWaba Ltda.
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda.
//
// SPDX-License-Identifier: LGPL-2.1-only

package jdkcompat.lang;

import java.io.InputStream;
import java.io.OutputStream;

public class ProcessImpl4D extends Process {

InputStream inputStream;
OutputStream outputStream;
InputStream errorStream;
int pid;

@Override
native public void destroy();

@Override
native public int exitValue();

@Override
public InputStream getErrorStream() {
return this.errorStream;
}

@Override
public InputStream getInputStream() {
return this.inputStream;
}

@Override
public OutputStream getOutputStream() {
return this.outputStream;
}

@Override
native public int waitFor();

}
55 changes: 55 additions & 0 deletions TotalCrossSDK/src/main/java/jdkcompat/lang/Runtime4D.java
@@ -0,0 +1,55 @@
// Copyright (C) 2000-2013 SuperWaba Ltda.
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda.
//
// SPDX-License-Identifier: LGPL-2.1-only

package jdkcompat.lang;

import java.io.File;
import java.util.ArrayList;

import totalcross.sys.Convert;

public class Runtime4D {

private static Runtime4D instance;

private Runtime4D() {

}

public static Runtime4D getRuntime() {
if(instance == null) {
instance = new Runtime4D();
}
return instance;
}

native private Process exec(String[] cmdarray, String[] envp, String dirPath);

public Process exec(String[] cmdarray, String[] envp, File dir) {
return exec(cmdarray, envp, dir.getPath());
}

public Process exec(String[] cmdarray, String[] envp) {
String dirPath = null;
return exec(cmdarray, envp, dirPath);
}

public Process exec(String[] cmdarray) {
return exec(cmdarray, null);
}

public Process exec(String command, String[] envp, File dir) {
return exec(Convert.tokenizeString(command, ' '), envp, dir.getPath());
}

public Process exec(String command, String[] envp) {
String dirPath = null;
return exec(Convert.tokenizeString(command, ' '), envp, dirPath);
}

public Process exec(String command) {
return exec(command, null);
}
}
@@ -0,0 +1,13 @@
// Copyright (C) 2000-2013 SuperWaba Ltda.
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda.
//
// SPDX-License-Identifier: LGPL-2.1-only

package jdkcompat.nio.channels;

import java.io.Closeable;

public abstract class FileChannel4D implements Closeable{


}
@@ -0,0 +1,140 @@
// Copyright (C) 2000-2013 SuperWaba Ltda.
// Copyright (C) 2014-2020 TotalCross Global Mobile Platform Ltda.
//
// SPDX-License-Identifier: LGPL-2.1-only

package jdkcompat.nio.channels;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;

public class FileChannelImpl4D extends FileChannel {

private int nfd = -1;

FileChannelImpl4D(int fd) {
this.nfd = fd;
}

FileChannelImpl4D() {

}

native public int read() throws IOException;

public int available() {
return 0;
}

@Override
public int read(ByteBuffer dst) throws IOException {
return 0;
}

native public int read(byte[] dst, int offset, int length) throws IOException;

@Override
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
// TODO Auto-generated method stub
return 0;
}


native public int write(byte[] src, int offset, int length) throws IOException;

@Override
public int write(ByteBuffer src) throws IOException {
// TODO Auto-generated method stub
return 0;
}

@Override
public long write(ByteBuffer[] srcs, int offset, int length) throws IOException {
// TODO Auto-generated method stub
return 0;
}

@Override
public long position() throws IOException {
// TODO Auto-generated method stub
return 0;
}

@Override
public FileChannel position(long newPosition) throws IOException {
// TODO Auto-generated method stub
return null;
}

@Override
public long size() throws IOException {
// TODO Auto-generated method stub
return 0;
}

@Override
public FileChannel truncate(long size) throws IOException {
// TODO Auto-generated method stub
return null;
}

@Override
public void force(boolean metaData) throws IOException {
// TODO Auto-generated method stub

}

@Override
public long transferTo(long position, long count, WritableByteChannel target) throws IOException {
// TODO Auto-generated method stub
return 0;
}

@Override
public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException {
// TODO Auto-generated method stub
return 0;
}

@Override
public int read(ByteBuffer dst, long position) throws IOException {
// TODO Auto-generated method stub
return 0;
}

@Override
public int write(ByteBuffer src, long position) throws IOException {
// TODO Auto-generated method stub
return 0;
}

@Override
public MappedByteBuffer map(MapMode mode, long position, long size) throws IOException {
// TODO Auto-generated method stub
return null;
}

@Override
public FileLock lock(long position, long size, boolean shared) throws IOException {
// TODO Auto-generated method stub
return null;
}

@Override
public FileLock tryLock(long position, long size, boolean shared) throws IOException {
// TODO Auto-generated method stub
return null;
}

@Override
protected void implCloseChannel() throws IOException {
// TODO Auto-generated method stub

}

}