Search in sources :

Example 56 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class BuildJobHandler method addDQDependencies.

private void addDQDependencies(IFolder parentFolder, List<Item> items) throws Exception {
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQItemService.class)) {
        ITDQItemService tdqItemService = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
        for (Item item : items) {
            if (tdqItemService != null && tdqItemService.hasProcessItemDependencies(Arrays.asList(new Item[] { item }))) {
                setNeedItemDependencies(true);
                // add .Talend.definition file
                //$NON-NLS-1$
                String defIdxFolderName = "TDQ_Libraries";
                //$NON-NLS-1$
                String defIdxFileName = ".Talend.definition";
                Project pro = getProject(processItem);
                IFolder itemsProjectFolder = parentFolder.getFolder(pro.getTechnicalLabel().toLowerCase());
                File itemsFolderDir = new File(parentFolder.getLocation().toFile().getAbsolutePath());
                IProject project = ReponsitoryContextBridge.getRootProject();
                String defIdxRelativePath = defIdxFolderName + PATH_SEPARATOR + defIdxFileName;
                IFile defIdxFile = project.getFile(defIdxRelativePath);
                if (defIdxFile.exists()) {
                    File defIdxFileSource = new File(project.getLocation().makeAbsolute().append(defIdxFolderName).append(defIdxFileName).toFile().toURI());
                    File defIdxFileTarget = new File(itemsProjectFolder.getFile(defIdxRelativePath).getLocation().toFile().getAbsolutePath());
                    FilesUtils.copyFile(defIdxFileSource, defIdxFileTarget);
                }
                // add report header image & template files
                //$NON-NLS-1$
                String reportingBundlePath = PluginChecker.getBundlePath("org.talend.dataquality.reporting");
                //$NON-NLS-1$
                File imageFolder = new File(reportingBundlePath + PATH_SEPARATOR + "images");
                if (imageFolder.exists()) {
                    FilesUtils.copyDirectory(imageFolder, itemsFolderDir);
                }
                //$NON-NLS-1$ 
                File templateFolder = new File(reportingBundlePath + PATH_SEPARATOR + "reports");
                if (templateFolder.exists() && templateFolder.isDirectory()) {
                    FilesUtils.copyDirectory(templateFolder, itemsFolderDir);
                }
            }
        }
        // maven command 'include-survivorship-rules' to export.
        if (!isOptionChoosed(ExportChoice.needJobItem)) {
            ExportFileResource resouece = new ExportFileResource();
            BuildExportManager.getInstance().exportDependencies(resouece, processItem);
            if (!resouece.getAllResources().isEmpty()) {
                final Iterator<String> relativepath = resouece.getRelativePathList().iterator();
                //$NON-NLS-1$
                String pathStr = "metadata/survivorship";
                IFolder targetFolder = talendProcessJavaProject.getResourcesFolder();
                if (targetFolder.exists()) {
                    IFolder survFolder = targetFolder.getFolder(new Path(pathStr));
                    // only copy self job rules, clear the 'survivorship' folder before copy.
                    if (survFolder.exists()) {
                        survFolder.delete(true, null);
                    }
                    while (relativepath.hasNext()) {
                        String relativePath = relativepath.next();
                        Set<URL> sources = resouece.getResourcesByRelativePath(relativePath);
                        for (URL sourceUrl : sources) {
                            File currentResource = new File(org.talend.commons.utils.io.FilesUtils.getFileRealPath(sourceUrl.getPath()));
                            if (currentResource.exists()) {
                                FilesUtils.copyDirectory(currentResource, new File(targetFolder.getLocation().toPortableString() + File.separator + pathStr));
                            }
                        }
                    }
                }
            }
            parentFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) Project(org.talend.core.model.properties.Project) IProject(org.eclipse.core.resources.IProject) ExportFileResource(org.talend.repository.documentation.ExportFileResource) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITDQItemService(org.talend.core.ITDQItemService) IFolder(org.eclipse.core.resources.IFolder)

Example 57 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class BuildJobHandler method generateTestReports.

@Override
public void generateTestReports(IProgressMonitor monitor) throws Exception {
    if (!isOptionChoosed(ExportChoice.includeTestSource)) {
        return;
    }
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
        ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
        if (testContainerService != null) {
            List<IFile> reports = new ArrayList<IFile>();
            List<ProcessItem> testsItems = testContainerService.getAllTestContainers(processItem);
            for (ProcessItem testItem : testsItems) {
                List<IFile> testReportFiles = testContainerService.getTestReportFiles(testItem);
                if (testReportFiles.size() > 0) {
                    reports.add(testReportFiles.get(0));
                }
            }
            IFolder testsFolder = talendProcessJavaProject.getTestsFolder();
            talendProcessJavaProject.cleanFolder(monitor, testsFolder);
            IFolder parentFolder = talendProcessJavaProject.createSubFolder(monitor, testsFolder, processItem.getProperty().getLabel());
            for (IFile report : reports) {
                report.copy(parentFolder.getFile(report.getName()).getFullPath(), true, monitor);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ProcessItem(org.talend.core.model.properties.ProcessItem) ArrayList(java.util.ArrayList) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) IFolder(org.eclipse.core.resources.IFolder)

Example 58 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class OSGIJavaScriptForESBWithMavenManager method addMavenBuildScripts.

@Override
protected void addMavenBuildScripts(ExportFileResource[] processes, List<URL> scriptsUrls, Map<String, String> mavenPropertiesMap) {
    if (!PluginChecker.isPluginLoaded(PluginChecker.EXPORT_JOB_PLUGIN_ID)) {
        return;
    }
    try {
        //
        Item item = processes[0].getItem();
        File templateFile = null;
        if (item != null) {
            IPath itemLocationPath = ItemResourceUtil.getItemLocationPath(item.getProperty());
            IFolder objectTypeFolder = ItemResourceUtil.getObjectTypeFolder(item.getProperty());
            if (itemLocationPath != null && objectTypeFolder != null) {
                IPath itemRelativePath = itemLocationPath.removeLastSegments(1).makeRelativeTo(objectTypeFolder.getLocation());
                templateFile = PomUtil.getTemplateFile(objectTypeFolder, itemRelativePath, IProjectSettingTemplateConstants.OSGI_POM_FILE_NAME);
            }
        }
        final Map<String, Object> templateParameters = PomUtil.getTemplateParameters(item.getProperty());
        String mavenScript = MavenTemplateManager.getTemplateContent(templateFile, IProjectSettingPreferenceConstants.TEMPLATE_OSGI_BUNDLE_POM, PluginChecker.MAVEN_JOB_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_OSGI_BUNDLE + '/' + IProjectSettingTemplateConstants.POM_JOB_TEMPLATE_FILE_NAME, templateParameters);
        // .getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_OSGI_BUNDLE_POM);
        if (mavenScript == null) {
            return;
        }
        File mavenBuildFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.POM_FILE_NAME);
        FileOutputStream mavenBuildFileOutputStream = null;
        try {
            mavenBuildFileOutputStream = new FileOutputStream(mavenBuildFile);
            mavenBuildFileOutputStream.write(mavenScript.getBytes());
        } finally {
            if (mavenBuildFileOutputStream != null) {
                mavenBuildFileOutputStream.close();
            }
        }
        updateMavenBuildFileContent(mavenBuildFile, mavenPropertiesMap, true, false);
        scriptsUrls.add(mavenBuildFile.toURL());
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : Item(org.talend.core.model.properties.Item) IPath(org.eclipse.core.runtime.IPath) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 59 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class JobJavaScriptsManager method addRoutinesSourceCodes.

protected void addRoutinesSourceCodes(ExportFileResource[] process, ExportFileResource resource, ITalendProcessJavaProject talendProcessJavaProject, boolean useBeans) throws Exception {
    List<IRepositoryViewObject> collectRoutines = new ArrayList<IRepositoryViewObject>();
    String include;
    if (useBeans) {
        include = USER_BEANS_PATH;
    } else {
        include = USER_ROUTINES_PATH;
    }
    collectRoutines.addAll(collectRoutines(process, include));
    collectRoutines.addAll(collectRoutines(process, USER_PIGUDF_PATH));
    Set<String> dependedRoutines = new HashSet<String>();
    for (IRepositoryViewObject obj : collectRoutines) {
        dependedRoutines.add(//$NON-NLS-1$
        obj.getLabel() + "." + ECodeLanguage.JAVA.getExtension());
    }
    IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
    IFolder folder = null;
    if (useBeans) {
        folder = srcFolder.getFolder(USER_BEANS_PATH);
    } else {
        folder = srcFolder.getFolder(JavaUtils.JAVA_ROUTINES_DIRECTORY);
    }
    List<URL> userRoutinesFileUrls = new ArrayList<URL>();
    if (folder.exists()) {
        for (IResource fileResource : folder.members()) {
            if (fileResource instanceof IFile && ((IFile) fileResource).getFileExtension().equals(ECodeLanguage.JAVA.getExtension()) && dependedRoutines.contains(((IFile) fileResource).getName())) {
                userRoutinesFileUrls.add(fileResource.getLocationURI().toURL());
            }
        }
        if (useBeans) {
            resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + USER_BEANS_PATH, userRoutinesFileUrls);
        } else {
            resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + JavaUtils.JAVA_ROUTINES_DIRECTORY, userRoutinesFileUrls);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) URL(java.net.URL) IResource(org.eclipse.core.resources.IResource) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) IFolder(org.eclipse.core.resources.IFolder)

Example 60 with IFolder

use of org.eclipse.core.resources.IFolder in project tesb-studio-se by Talend.

the class KarafJavaScriptForESBWithMavenManager method addMavenBuildScripts.

@Override
protected void addMavenBuildScripts(ExportFileResource[] processes, List<URL> scriptsUrls, Map<String, String> mavenPropertiesMap) {
    if (!PluginChecker.isPluginLoaded(PluginChecker.EXPORT_ROUTE_PLUGIN_ID)) {
        return;
    }
    Item item = processes[0].getItem();
    File templatePomFile = null, templateBundleFile = null, templateFeatureFile = null, templateParentFile = null;
    if (item != null) {
        IPath itemLocationPath = ItemResourceUtil.getItemLocationPath(item.getProperty());
        IFolder objectTypeFolder = ItemResourceUtil.getObjectTypeFolder(item.getProperty());
        if (itemLocationPath != null && objectTypeFolder != null) {
            IPath itemRelativePath = itemLocationPath.removeLastSegments(1).makeRelativeTo(objectTypeFolder.getLocation());
            templatePomFile = PomUtil.getTemplateFile(objectTypeFolder, itemRelativePath, TalendMavenConstants.POM_FILE_NAME);
            if (FilesUtils.allInSameFolder(templatePomFile, IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_BUNDLE_FILE_NAME, IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_FEATURE_FILE_NAME, IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_PARENT_FILE_NAME)) {
                templateBundleFile = new File(templatePomFile.getParentFile(), IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_BUNDLE_FILE_NAME);
                templateFeatureFile = new File(templatePomFile.getParentFile(), IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_FEATURE_FILE_NAME);
                templateParentFile = new File(templatePomFile.getParentFile(), IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_PARENT_FILE_NAME);
            } else {
                // don't use template file from repository.
                // other files is not init, so no need set null at all.
                templatePomFile = null;
            }
        }
    }
    File mavenBuildFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.POM_FILE_NAME);
    File mavenBuildBundleFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_BUNDLE_FILE_NAME);
    File mavenBuildFeatureFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_FEATURE_FILE_NAME);
    File mavenBuildParentFile = new File(getTmpFolder() + PATH_SEPARATOR + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_PARENT_FILE_NAME);
    try {
        final Map<String, Object> templateParameters = PomUtil.getTemplateParameters(item.getProperty());
        String mavenScript = MavenTemplateManager.getTemplateContent(templatePomFile, IProjectSettingPreferenceConstants.TEMPLATE_ROUTES_KARAF_POM, PluginChecker.EXPORT_ROUTE_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_ROUTE + '/' + TalendMavenConstants.POM_FILE_NAME, templateParameters);
        if (mavenScript != null) {
            createMavenBuildFileFromTemplate(mavenBuildFile, mavenScript);
            updateMavenBuildFileContent(mavenBuildFile, mavenPropertiesMap, false, true);
            scriptsUrls.add(mavenBuildFile.toURI().toURL());
        }
        mavenScript = MavenTemplateManager.getTemplateContent(templateBundleFile, IProjectSettingPreferenceConstants.TEMPLATE_ROUTES_KARAF_BUNDLE, PluginChecker.EXPORT_ROUTE_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_ROUTE + '/' + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_BUNDLE_FILE_NAME, templateParameters);
        if (mavenScript != null) {
            createMavenBuildFileFromTemplate(mavenBuildBundleFile, mavenScript);
            updateMavenBuildFileContent(mavenBuildBundleFile, mavenPropertiesMap, true, false);
            scriptsUrls.add(mavenBuildBundleFile.toURI().toURL());
        }
        mavenScript = MavenTemplateManager.getTemplateContent(templateFeatureFile, IProjectSettingPreferenceConstants.TEMPLATE_ROUTES_KARAF_FEATURE, PluginChecker.EXPORT_ROUTE_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_ROUTE + '/' + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_FEATURE_FILE_NAME, templateParameters);
        if (mavenScript != null) {
            createMavenBuildFileFromTemplate(mavenBuildFeatureFile, mavenScript);
            updateMavenBuildFileContent(mavenBuildFeatureFile, mavenPropertiesMap);
            scriptsUrls.add(mavenBuildFeatureFile.toURI().toURL());
        }
        mavenScript = MavenTemplateManager.getTemplateContent(templateParentFile, IProjectSettingPreferenceConstants.TEMPLATE_ROUTES_KARAF_PARENT, PluginChecker.EXPORT_ROUTE_PLUGIN_ID, IProjectSettingTemplateConstants.PATH_ROUTE + '/' + IProjectSettingTemplateConstants.MAVEN_KARAF_BUILD_PARENT_FILE_NAME, templateParameters);
        if (mavenScript != null) {
            createMavenBuildFileFromTemplate(mavenBuildParentFile, mavenScript);
            updateMavenBuildFileContent(mavenBuildParentFile, mavenPropertiesMap);
            scriptsUrls.add(mavenBuildParentFile.toURI().toURL());
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) IPath(org.eclipse.core.runtime.IPath) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ZipFile(java.util.zip.ZipFile) File(java.io.File) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)299 IFile (org.eclipse.core.resources.IFile)129 IPath (org.eclipse.core.runtime.IPath)90 IProject (org.eclipse.core.resources.IProject)77 CoreException (org.eclipse.core.runtime.CoreException)72 IResource (org.eclipse.core.resources.IResource)66 Path (org.eclipse.core.runtime.Path)47 IContainer (org.eclipse.core.resources.IContainer)45 File (java.io.File)43 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)19 InputStream (java.io.InputStream)18 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)17 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15