Search in sources :

Example 1 with FilterInfo

use of org.talend.utils.files.FilterInfo 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();
        }
    }
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) JavaJobExportReArchieveCreator(org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator) Property(org.talend.core.model.properties.Property) ZipToFile(org.talend.repository.ui.utils.ZipToFile) File(java.io.File) FilterInfo(org.talend.utils.files.FilterInfo) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with FilterInfo

use of org.talend.utils.files.FilterInfo in project tdi-studio-se by Talend.

the class BigDataJavaProcessor method extractArgumentSegments.

@Override
public List<String> extractArgumentSegments() {
    List<String> list = new ArrayList<>();
    list.add(ProcessorConstants.CMD_KEY_WORD_LIBJAR);
    StringBuffer libJars = new StringBuffer();
    Set<String> libNames = null;
    boolean isExport = isExportConfig() || isRunAsExport();
    if (process instanceof IProcess2) {
        if (isExport) {
            // In an export mode, all the dependencies and the routines/beans/udfs are packaged in the lib folder.
            libNames = JavaProcessorUtilities.extractLibNamesOnlyForMapperAndReducer((IProcess2) process);
        } else {
            // In the local mode, all the dependencies are packaged in the lib folder. The routines/beans/udfs are
            // not.
            // We will
            // handle them separetely.
            libNames = JavaProcessorUtilities.extractLibNamesOnlyForMapperAndReducerWithoutRoutines((IProcess2) process);
        }
    }
    File libDir = JavaProcessorUtilities.getJavaProjectLibFolder();
    File targetDir = new File(JavaProcessorUtilities.getTalendJavaProject().getTargetFolder().getLocationURI());
    //$NON-NLS-1$
    String libFolder = "";
    if (libDir != null) {
        libFolder = new Path(libDir.getAbsolutePath()).toPortableString();
    }
    // StringBuffer.
    if (libNames != null && libNames.size() > 0) {
        Iterator<String> itLibNames = libNames.iterator();
        while (itLibNames.hasNext()) {
            if (isExport) {
                // In an export mode, the path is relative to the working directory.
                libJars.append(getLibFolderInWorkingDir() + itLibNames.next()).append(',');
            } else {
                // In a local mode, the path is absolute.
                //$NON-NLS-1$
                libJars.append(libFolder + "/" + itLibNames.next()).append(',');
            }
        }
    }
    if (isExport) {
        // In an export mode, we add the job jar which is located in the current working directory
        //$NON-NLS-1$
        libJars.append("./" + makeupJobJarName());
    } else {
        // In a local mode,we must append the routines/beans/udfs jars which are located in the target directory.
        Set<FilterInfo> codeJars = new HashSet<>();
        codeJars.add(new FilterInfo(JavaUtils.ROUTINE_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX));
        codeJars.add(new FilterInfo(JavaUtils.BEANS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX));
        codeJars.add(new FilterInfo(JavaUtils.PIGUDFS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX));
        List<File> files = FileUtils.getAllFilesFromFolder(targetDir, codeJars);
        boolean routinesHaveBeenFound = false;
        for (File f : files) {
            if (!routinesHaveBeenFound && f.getName().startsWith(JavaUtils.ROUTINE_JAR_NAME)) {
                routinesHaveBeenFound = true;
            }
            //$NON-NLS-1$
            libJars.append(new Path(f.getAbsolutePath()).toPortableString() + ",");
        }
        // folder when the job is going to be running.
        if (!routinesHaveBeenFound) {
            File routinesJar = new File(//$NON-NLS-1$ //$NON-NLS-2$
            targetDir + "/" + JavaUtils.ROUTINE_JAR_NAME + "-" + PomUtil.getDefaultMavenVersion() + FileExtensions.JAR_FILE_SUFFIX);
            //$NON-NLS-1$
            libJars.append(new Path(routinesJar.getAbsolutePath()).toPortableString() + ",");
        }
        // ... and add the jar of the job itself also located in the target directory/
        if (targetDir != null) {
            //$NON-NLS-1$
            libJars.append(new Path(targetDir.getAbsolutePath()).toPortableString() + "/" + makeupJobJarName());
        }
    }
    list.add(libJars.toString());
    return list;
}
Also used : Path(org.eclipse.core.runtime.Path) ArrayList(java.util.ArrayList) IProcess2(org.talend.core.model.process.IProcess2) File(java.io.File) FilterInfo(org.talend.utils.files.FilterInfo) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)2 HashSet (java.util.HashSet)2 FilterInfo (org.talend.utils.files.FilterInfo)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Path (org.eclipse.core.runtime.Path)1 IProcess2 (org.talend.core.model.process.IProcess2)1 Property (org.talend.core.model.properties.Property)1 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)1 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)1 ZipToFile (org.talend.repository.ui.utils.ZipToFile)1 JavaJobExportReArchieveCreator (org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator)1