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;
|
||||
case OPEN:
|
||||
case UPDATE:
|
||||
case SAVE:
|
||||
case ADD_RESOURCE:
|
||||
case DELETE_RESOURCE:
|
||||
create(event);
|
||||
break;
|
||||
case SAVE:
|
||||
reloadWSResourceExplorerPanel();
|
||||
break;
|
||||
case MAIN_CODE_SET:
|
||||
reloadWSResourceExplorerPanel();
|
||||
break;
|
||||
|
|
|
@ -68,7 +68,7 @@ public class InfoGenerator {
|
|||
+ project.getInputData().getProjectInfo()
|
||||
.getAlgorithmNameToUpper());
|
||||
infos.add("Class Name: org.gcube.dataanalysis.executor.rscripts."+ project.getInputData().getProjectInfo()
|
||||
.getAlgorithmNameToUpper());
|
||||
.getAlgorithmNameToClassName());
|
||||
|
||||
} else {
|
||||
infos.add("Algorithm Name: ");
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -302,43 +301,90 @@ public class ProjectBuilder {
|
|||
}
|
||||
|
||||
private void createProjectJarFile() throws StatAlgoImporterServiceException {
|
||||
|
||||
FilesStorage storage = new FilesStorage();
|
||||
|
||||
Path tempDirectory;
|
||||
try {
|
||||
FilesStorage storage = new FilesStorage();
|
||||
|
||||
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;
|
||||
|
||||
tempDirectory = Files.createTempDirectory("StatAlgorithmsJar");
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
logger.error("Error creating temporal directory: "
|
||||
+ e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
|
||||
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)
|
||||
|
@ -387,15 +433,17 @@ public class ProjectBuilder {
|
|||
|
||||
}
|
||||
|
||||
private void createClassFile(Path tempDirectory)
|
||||
private void createClassFile(Path tempDirectory, Path packageHome)
|
||||
throws StatAlgoImporterServiceException {
|
||||
|
||||
try {
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder("javac", "-cp",
|
||||
tempDirectory.toAbsolutePath().toString() + "/*", project
|
||||
.getInputData().getProjectInfo()
|
||||
.getAlgorithmNameToClassName()
|
||||
tempDirectory.toAbsolutePath().toString() + "/*",
|
||||
packageHome.toAbsolutePath().toString()
|
||||
+ File.separator
|
||||
+ project.getInputData().getProjectInfo()
|
||||
.getAlgorithmNameToClassName()
|
||||
+ ALGORITHM_EXTENTION);
|
||||
pb.directory(tempDirectory.toFile());
|
||||
Path logTXT = new File(tempDirectory.toFile(), LOG_TXT).toPath();
|
||||
|
@ -428,14 +476,16 @@ public class ProjectBuilder {
|
|||
.getAlgorithmNameToClassName()
|
||||
+ JAR_EXTENTION);
|
||||
|
||||
DirectoryStream<Path> directoryStream = Files
|
||||
.newDirectoryStream(tempDirectory);
|
||||
for (Path path : directoryStream) {
|
||||
if (path.toString().endsWith(".class"))
|
||||
commands.add(path.getFileName().toString());
|
||||
|
||||
}
|
||||
/*
|
||||
* DirectoryStream<Path> directoryStream = Files
|
||||
* .newDirectoryStream(tempDirectory); for (Path path :
|
||||
* directoryStream) { if (path.toString().endsWith(".class"))
|
||||
* commands.add(path.getFileName().toString());
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
commands.add("org");
|
||||
commands.add(infoTempFile.getFileName().toString());
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(commands);
|
||||
|
|
Loading…
Reference in New Issue