use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.
the class BDJobReArchieveCreator method create.
public void create(File file, boolean isExport) {
if (file == null || !file.exists() || (isExport && !file.isFile()) || fatherProcessItem == null) {
return;
}
// check
if (!isMRWithHDInsight() && !isFatJar()) {
return;
}
Property property = processItem.getProperty();
Property fatherProperty = fatherProcessItem.getProperty();
String label = property.getLabel();
String fatherLabel = fatherProperty.getLabel();
String version = property.getVersion();
JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(file.getAbsolutePath(), label);
String jobJarName = JavaResourcesHelper.getJobJarName(property.getLabel(), property.getVersion()) + FileExtensions.JAR_FILE_SUFFIX;
try {
if (isExport) {
// If we are in an export context, we first unzip the archive, then we modify the jar.
// create temp folders.
// clean temp folder
creator.deleteTempFiles();
//$NON-NLS-1$ //$NON-NLS-2$
File zipTmpFolder = new File(creator.getTmpFolder(), "zip-" + label + "_" + version);
//$NON-NLS-1$ //$NON-NLS-2$
File jarTmpFolder = new File(creator.getTmpFolder(), "jar-" + label + "_" + version);
zipTmpFolder.mkdirs();
jarTmpFolder.mkdirs();
// unzip the files.
FilesUtils.unzip(file.getAbsolutePath(), zipTmpFolder.getAbsolutePath());
// same the the job pom assembly for package.
File originalJarFile = new File(zipTmpFolder, fatherLabel + '/' + jobJarName);
modifyJar(originalJarFile, jarTmpFolder, creator, jobJarName, zipTmpFolder, property);
ZipToFile.zipFile(zipTmpFolder.getAbsolutePath(), file.getAbsolutePath());
} else {
// If we are in a local context, we just have to modify the jar.
// clean temp folder
creator.deleteTempFiles();
//$NON-NLS-1$ //$NON-NLS-2$
File jarTmpFolder = new File(creator.getTmpFolder(), "jar-" + label + "_" + version);
jarTmpFolder.mkdirs();
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
File targetFolder = new File(talendProcessJavaProject.getTargetFolder().getLocationURI());
// In a local mode, the routines/beans/udfs jars are not in the lib folder. We then copy them.
// Copy routines and rename it to match the
// "JavaUtils.ROUTINE_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX" name
Set<FilterInfo> codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.ROUTINE_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.ROUTINE_JAR_NAME + //$NON-NLS-1$
FileExtensions.JAR_FILE_SUFFIX));
}
// Copy beans and rename it to match the "JavaUtils.BEANS_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX"
// name
codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.BEANS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.BEANS_JAR_NAME + //$NON-NLS-1$
FileExtensions.JAR_FILE_SUFFIX));
}
// Copy udfs and rename it to match the
// "JavaUtils.PIGUDFS_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX"
// name
codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.PIGUDFS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.PIGUDFS_JAR_NAME + //$NON-NLS-1$
FileExtensions.JAR_FILE_SUFFIX));
}
modifyJar(new File(file, jobJarName), jarTmpFolder, creator, jobJarName, talendProcessJavaProject.getLibFolder().getParent().getLocation().toFile(), property);
} else {
//$NON-NLS-1$
CommonExceptionHandler.log("Unable to update the job jar because the RunProcessService is not registered.");
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
// when debug, keep the files first. because when build again. will do clean also.
if (!CommonsPlugin.isDebugMode()) {
creator.deleteTempFiles();
}
}
}
use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method getLog4jFiles.
/**
* Gets required java jars.
*
* @param process
*
* @param boolean1
* @return
*/
protected List<URL> getLog4jFiles() {
List<URL> list = new ArrayList<URL>();
if (Log4jUtil.isEnable() && Boolean.parseBoolean(Log4jPrefsSettingManager.getInstance().getValueOfPreNode(Log4jPrefsConstants.LOG4J_ENABLE_NODE)) && GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
try {
ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
if (talendProcessJavaProject != null) {
IFolder resourcesFolder = talendProcessJavaProject.getResourcesFolder();
IFile log4jFile = resourcesFolder.getFile(Log4jPrefsConstants.LOG4J_FILE_NAME);
if (log4jFile.exists()) {
list.add(FileLocator.toFileURL(log4jFile.getLocationURI().toURL()));
}
}
} catch (MalformedURLException e) {
ExceptionHandler.process(e);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
return list;
}
use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method addXmlMapping.
protected void addXmlMapping(ExportFileResource resource, boolean needSource) {
try {
boolean hasDynamicMetadata = false;
if (resource.getItem() instanceof ProcessItem) {
List<JobInfo> list = new ArrayList<JobInfo>();
hasDynamicMetadata = LastGenerationInfo.getInstance().isUseDynamic(resource.getItem().getProperty().getId(), resource.getItem().getProperty().getVersion());
}
if (hasDynamicMetadata) {
needMappingInSystemRoutine = true;
if (needSource) {
IRunProcessService service = CorePlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return;
}
// for db mapping xml
IFolder xmlMappingFolder = talendProcessJavaProject.getResourcesFolder().getFolder(JavaUtils.JAVA_XML_MAPPING);
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICoreService.class)) {
ICoreService coreService = (ICoreService) GlobalServiceRegister.getDefault().getService(ICoreService.class);
coreService.synchronizeMapptingXML();
coreService.syncLog4jSettings();
}
List<URL> xmlMappingFileUrls = new ArrayList<URL>();
if (xmlMappingFolder.exists()) {
for (IResource fileResource : xmlMappingFolder.members()) {
if (XmlUtil.isXMLFile(fileResource.getName())) {
xmlMappingFileUrls.add(fileResource.getLocationURI().toURL());
}
}
resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + JavaUtils.JAVA_XML_MAPPING, xmlMappingFileUrls);
}
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method addDependenciesSourceCode.
protected void addDependenciesSourceCode(ExportFileResource[] process, ExportFileResource resource, boolean needSource) {
if (!needSource) {
return;
}
try {
// get different routines.
IRunProcessService service = CorePlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IFolder systemRoutineFolder = srcFolder.getFolder(SYSTEM_ROUTINES_PATH);
List<URL> systemRoutinesFileUrls = new ArrayList<URL>();
if (systemRoutineFolder.exists()) {
for (IResource fileResource : systemRoutineFolder.members()) {
if (fileResource instanceof IFile && ((IFile) fileResource).getFileExtension().equals(ECodeLanguage.JAVA.getExtension())) {
systemRoutinesFileUrls.add(fileResource.getLocationURI().toURL());
}
}
resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + SYSTEM_ROUTINES_PATH, systemRoutinesFileUrls);
}
// bug TDI-8647
// empty and re-use it
systemRoutinesFileUrls.clear();
systemRoutineFolder = srcFolder.getFolder(SYSTEM_ROUTINES_PATH + PATH_SEPARATOR + JavaUtils.JAVA_SYSTEM_ROUTINES_API_DIRECTORY);
if (systemRoutineFolder.exists()) {
for (IResource fileResource : systemRoutineFolder.members()) {
if (fileResource instanceof IFile && ((IFile) fileResource).getFileExtension().equals(ECodeLanguage.JAVA.getExtension())) {
systemRoutinesFileUrls.add(fileResource.getLocationURI().toURL());
}
}
resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + SYSTEM_ROUTINES_PATH + PATH_SEPARATOR + JavaUtils.JAVA_SYSTEM_ROUTINES_API_DIRECTORY, systemRoutinesFileUrls);
}
// add for routines
boolean useBeans = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
if (camelService.isInstanceofCamel(process[0].getItem())) {
useBeans = true;
}
}
addRoutinesSourceCodes(process, resource, talendProcessJavaProject, useBeans);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method addLog4jXmlToRes.
protected void addLog4jXmlToRes(ExportFileResource libResource) {
List<URL> list = new ArrayList<URL>();
if (Log4jPrefsSettingManager.getInstance().isLog4jEnable() && GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
try {
ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
if (talendProcessJavaProject != null) {
IFolder resourcesFolder = talendProcessJavaProject.getResourcesFolder();
IFile log4jFile = resourcesFolder.getFile(Log4jPrefsConstants.LOG4J_FILE_NAME);
if (log4jFile.exists()) {
list.add(log4jFile.getLocationURI().toURL());
}
}
} catch (MalformedURLException e) {
ExceptionHandler.process(e);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
libResource.addResources(list);
}
Aggregations