1452: Implement a GUI for StatMan Algorithms Importer
Task-Url: https://support.d4science.org/issues/1452 File jar now include package folder git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@122439 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e4840279ab
commit
bfb2a97bf1
|
@ -113,11 +113,13 @@ public class ExplorerProjectPanel extends ContentPanel {
|
||||||
break;
|
break;
|
||||||
case OPEN:
|
case OPEN:
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
case SAVE:
|
|
||||||
case ADD_RESOURCE:
|
case ADD_RESOURCE:
|
||||||
case DELETE_RESOURCE:
|
case DELETE_RESOURCE:
|
||||||
create(event);
|
create(event);
|
||||||
break;
|
break;
|
||||||
|
case SAVE:
|
||||||
|
reloadWSResourceExplorerPanel();
|
||||||
|
break;
|
||||||
case MAIN_CODE_SET:
|
case MAIN_CODE_SET:
|
||||||
reloadWSResourceExplorerPanel();
|
reloadWSResourceExplorerPanel();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class InfoGenerator {
|
||||||
+ project.getInputData().getProjectInfo()
|
+ project.getInputData().getProjectInfo()
|
||||||
.getAlgorithmNameToUpper());
|
.getAlgorithmNameToUpper());
|
||||||
infos.add("Class Name: org.gcube.dataanalysis.executor.rscripts."+ project.getInputData().getProjectInfo()
|
infos.add("Class Name: org.gcube.dataanalysis.executor.rscripts."+ project.getInputData().getProjectInfo()
|
||||||
.getAlgorithmNameToUpper());
|
.getAlgorithmNameToClassName());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
infos.add("Algorithm Name: ");
|
infos.add("Algorithm Name: ");
|
||||||
|
|
|
@ -4,7 +4,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.ProcessBuilder.Redirect;
|
import java.lang.ProcessBuilder.Redirect;
|
||||||
import java.nio.file.DirectoryStream;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
@ -302,43 +301,90 @@ public class ProjectBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createProjectJarFile() throws StatAlgoImporterServiceException {
|
private void createProjectJarFile() throws StatAlgoImporterServiceException {
|
||||||
|
|
||||||
|
FilesStorage storage = new FilesStorage();
|
||||||
|
|
||||||
|
Path tempDirectory;
|
||||||
try {
|
try {
|
||||||
FilesStorage storage = new FilesStorage();
|
tempDirectory = Files.createTempDirectory("StatAlgorithmsJar");
|
||||||
|
|
||||||
Path tempDirectory = Files.createTempDirectory("StatAlgorithmsJar");
|
|
||||||
logger.debug("TempDir: " + tempDirectory);
|
|
||||||
Path ecologicalEngineJar = new File(tempDirectory.toFile(),
|
|
||||||
ECOLOGICAL_ENGINE_JAR).toPath();
|
|
||||||
storage.downloadInputFile(ECOLOGICAL_ENGINE_JAR_URL,
|
|
||||||
ecologicalEngineJar);
|
|
||||||
Path ecologicalEngineSmartExecutorJar = new File(
|
|
||||||
tempDirectory.toFile(),
|
|
||||||
ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR).toPath();
|
|
||||||
storage.downloadInputFile(ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR_URL,
|
|
||||||
ecologicalEngineSmartExecutorJar);
|
|
||||||
Path algorithmTempFile = new File(tempDirectory.toFile(), project
|
|
||||||
.getInputData().getProjectInfo()
|
|
||||||
.getAlgorithmNameToClassName()
|
|
||||||
+ ALGORITHM_EXTENTION).toPath();
|
|
||||||
Files.copy(algorithmJava, algorithmTempFile);
|
|
||||||
Path infoTempFile = new File(tempDirectory.toFile(), INFO_NAME
|
|
||||||
+ INFO_EXTENTION).toPath();
|
|
||||||
Files.copy(infoTXT, infoTempFile);
|
|
||||||
|
|
||||||
createClassFile(tempDirectory);
|
|
||||||
createJarFile(tempDirectory, infoTempFile);
|
|
||||||
copyJarOnWorkspace(tempDirectory);
|
|
||||||
FileUtils.cleanDirectory(tempDirectory.toFile());
|
|
||||||
FileUtils.deleteDirectory(tempDirectory.toFile());
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error("Error creating temporal directory: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
|
logger.debug("TempDir: " + tempDirectory);
|
||||||
|
|
||||||
|
File packageHome = new File(tempDirectory.toAbsolutePath().toString()
|
||||||
|
+ File.separator + "org" + File.separator + "gcube"
|
||||||
|
+ File.separator + "dataanalysis" + File.separator + "executor"
|
||||||
|
+ File.separator + "rscripts");
|
||||||
|
packageHome.mkdirs();
|
||||||
|
Path packageHomeDir = packageHome.toPath();
|
||||||
|
|
||||||
|
Path ecologicalEngineJar = new File(tempDirectory.toFile(),
|
||||||
|
ECOLOGICAL_ENGINE_JAR).toPath();
|
||||||
|
storage.downloadInputFile(ECOLOGICAL_ENGINE_JAR_URL,
|
||||||
|
ecologicalEngineJar);
|
||||||
|
Path ecologicalEngineSmartExecutorJar = new File(
|
||||||
|
tempDirectory.toFile(), ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR)
|
||||||
|
.toPath();
|
||||||
|
storage.downloadInputFile(ECOLOGICAL_ENGINE_SMART_EXECUTOR_JAR_URL,
|
||||||
|
ecologicalEngineSmartExecutorJar);
|
||||||
|
|
||||||
|
Path algorithmTempFile = new File(packageHomeDir.toFile(), project
|
||||||
|
.getInputData().getProjectInfo().getAlgorithmNameToClassName()
|
||||||
|
+ ALGORITHM_EXTENTION).toPath();
|
||||||
|
try {
|
||||||
|
Files.copy(algorithmJava, algorithmTempFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Error in alogrithm java copy in package directory: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path infoTempFile = new File(tempDirectory.toFile(), INFO_NAME
|
||||||
|
+ INFO_EXTENTION).toPath();
|
||||||
|
try {
|
||||||
|
Files.copy(infoTXT, infoTempFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Error in info copy in temp directory: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
|
||||||
|
createClassFile(tempDirectory, packageHomeDir);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.delete(algorithmTempFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Error in delete java file in package directory: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
|
||||||
|
createJarFile(tempDirectory, infoTempFile);
|
||||||
|
copyJarOnWorkspace(tempDirectory);
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileUtils.cleanDirectory(tempDirectory.toFile());
|
||||||
|
FileUtils.deleteDirectory(tempDirectory.toFile());
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Error in delete temp directory: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyJarOnWorkspace(Path tempDirectory)
|
private void copyJarOnWorkspace(Path tempDirectory)
|
||||||
|
@ -387,15 +433,17 @@ public class ProjectBuilder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createClassFile(Path tempDirectory)
|
private void createClassFile(Path tempDirectory, Path packageHome)
|
||||||
throws StatAlgoImporterServiceException {
|
throws StatAlgoImporterServiceException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder("javac", "-cp",
|
ProcessBuilder pb = new ProcessBuilder("javac", "-cp",
|
||||||
tempDirectory.toAbsolutePath().toString() + "/*", project
|
tempDirectory.toAbsolutePath().toString() + "/*",
|
||||||
.getInputData().getProjectInfo()
|
packageHome.toAbsolutePath().toString()
|
||||||
.getAlgorithmNameToClassName()
|
+ File.separator
|
||||||
|
+ project.getInputData().getProjectInfo()
|
||||||
|
.getAlgorithmNameToClassName()
|
||||||
+ ALGORITHM_EXTENTION);
|
+ ALGORITHM_EXTENTION);
|
||||||
pb.directory(tempDirectory.toFile());
|
pb.directory(tempDirectory.toFile());
|
||||||
Path logTXT = new File(tempDirectory.toFile(), LOG_TXT).toPath();
|
Path logTXT = new File(tempDirectory.toFile(), LOG_TXT).toPath();
|
||||||
|
@ -428,14 +476,16 @@ public class ProjectBuilder {
|
||||||
.getAlgorithmNameToClassName()
|
.getAlgorithmNameToClassName()
|
||||||
+ JAR_EXTENTION);
|
+ JAR_EXTENTION);
|
||||||
|
|
||||||
DirectoryStream<Path> directoryStream = Files
|
/*
|
||||||
.newDirectoryStream(tempDirectory);
|
* DirectoryStream<Path> directoryStream = Files
|
||||||
for (Path path : directoryStream) {
|
* .newDirectoryStream(tempDirectory); for (Path path :
|
||||||
if (path.toString().endsWith(".class"))
|
* directoryStream) { if (path.toString().endsWith(".class"))
|
||||||
commands.add(path.getFileName().toString());
|
* commands.add(path.getFileName().toString());
|
||||||
|
*
|
||||||
}
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
|
commands.add("org");
|
||||||
commands.add(infoTempFile.getFileName().toString());
|
commands.add(infoTempFile.getFileName().toString());
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(commands);
|
ProcessBuilder pb = new ProcessBuilder(commands);
|
||||||
|
|
Loading…
Reference in New Issue