Search in sources :

Example 6 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tdi-studio-se by Talend.

the class AbstractJavaProcessor method buildExportZip.

protected String buildExportZip(ProcessItem processItem, IProgressMonitor progressMonitor) throws ProcessorException {
    Map<ExportChoice, Object> exportChoiceMap = JobScriptsManagerFactory.getDefaultExportChoiceMap();
    exportChoiceMap.put(ExportChoice.needLauncher, false);
    exportChoiceMap.put(ExportChoice.needJobItem, true);
    // exportChoiceMap.put(ExportChoice.needJobScript, true); //?? for old build? no need
    if (CommonsPlugin.isDebugMode()) {
        exportChoiceMap.put(ExportChoice.needSourceCode, true);
    } else {
        exportChoiceMap.put(ExportChoice.needSourceCode, false);
    }
    exportChoiceMap.put(ExportChoice.binaries, true);
    exportChoiceMap.put(ExportChoice.includeLibs, true);
    exportChoiceMap.put(ExportChoice.needAssembly, true);
    if (progressMonitor.isCanceled()) {
        throw new ProcessorException(new InterruptedException());
    }
    final String archiveFilePath = Path.fromOSString(CorePlugin.getDefault().getPreferenceStore().getString(ITalendCorePrefConstants.FILE_PATH_TEMP)).append(getFilePathPrefix() + '_' + process.getName() + FileExtensions.ZIP_FILE_SUFFIX).toString();
    try {
        exportChoiceMap.put(ExportChoice.needContext, true);
        String contextName = processItem.getProcess().getDefaultContext();
        exportChoiceMap.put(ExportChoice.contextName, contextName);
        buildJob(archiveFilePath, processItem, processItem.getProperty().getVersion(), contextName, exportChoiceMap, JobExportType.POJO, progressMonitor);
    } catch (Exception e) {
        throw new ProcessorException(e);
    } finally {
        ProcessorUtilities.resetExportConfig();
    }
    return archiveFilePath;
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) ProcessorException(org.talend.designer.runprocess.ProcessorException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 7 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tdi-studio-se by Talend.

the class ExportProcessorHelper method exportPigudf.

public void exportPigudf(IProcessor processor, Property property, int statisticsPort, int tracePort) throws ProcessorException {
    // build java project
    CorePlugin.getDefault().getRunProcessService().buildJavaProject();
    Map<ExportChoice, Object> exportChoiceMap = new EnumMap<ExportChoice, Object>(ExportChoice.class);
    exportChoiceMap.put(ExportChoice.needPigudf, true);
    ProcessItem processItem = (ProcessItem) property.getItem();
    ExportFileResource fileResource = new ExportFileResource(processItem, property.getLabel());
    ExportFileResource[] exportFileResources = new ExportFileResource[] { fileResource };
    JobScriptsManager jobScriptsManager = JobScriptsManagerFactory.createManagerInstance(exportChoiceMap, processor.getContext().getName(), JobScriptsManager.ALL_ENVIRONMENTS, statisticsPort, tracePort, JobExportType.POJO);
    URL url = jobScriptsManager.getExportPigudfResources(exportFileResources);
    if (url == null) {
        return;
    }
    File file = new File(url.getFile());
    File libFolder = JavaProcessorUtilities.getJavaProjectLibFolder();
    if (libFolder == null) {
        return;
    }
    File target = new File(libFolder.getAbsolutePath() + property.getLabel() + "_" + property.getVersion() + "_" + file.getName());
    try {
        FilesUtils.copyFile(file, target);
    } catch (IOException e) {
        throw new ProcessorException(e.getMessage());
    }
}
Also used : JobScriptsManager(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager) ProcessorException(org.talend.designer.runprocess.ProcessorException) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) IOException(java.io.IOException) EnumMap(java.util.EnumMap) File(java.io.File) URL(java.net.URL)

Example 8 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tesb-studio-se by Talend.

the class RouteOSGiBundleBuildProvider method createBuildExportHandler.

/* (non-Javadoc)
     * @see org.talend.core.runtime.repository.build.AbstractBuildProvider#createBuildExportHandler(java.util.Map)
     */
@Override
public IBuildExportHandler createBuildExportHandler(Map<String, Object> parameters) {
    if (parameters == null || parameters.isEmpty()) {
        return null;
    }
    final Object item = parameters.get(ITEM);
    if (item == null || !(item instanceof ProcessItem)) {
        return null;
    }
    final Object version = parameters.get(VERSION);
    if (version == null) {
        return null;
    }
    final Object contextGroup = parameters.get(CONTEXT_GROUP);
    if (contextGroup == null) {
        return null;
    }
    Object choiceOption = parameters.get(CHOICE_OPTION);
    if (choiceOption == null) {
        choiceOption = Collections.emptyMap();
    }
    if (!(choiceOption instanceof Map)) {
        return null;
    }
    IBuildJobHandler buildHandler = new BuildBundleHandler((ProcessItem) item, version.toString(), contextGroup.toString(), (Map<ExportChoice, Object>) choiceOption);
    return buildHandler;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) BuildBundleHandler(org.talend.camel.designer.ui.view.handler.BuildBundleHandler) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) Map(java.util.Map)

Example 9 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tesb-studio-se by Talend.

the class ServiceExportWizard method performFinish.

@Override
public boolean performFinish() {
    final String destinationValue = mainPage.getDestinationValue();
    // TESB-7319: add confirm dialog
    if (new File(destinationValue).exists()) {
        boolean openQuestion = MessageDialog.openQuestion(getShell(), Messages.ServiceExportWizard_destinationExistTitle, Messages.ServiceExportWizard_destinationExistMessage);
        if (!openQuestion) {
            return false;
        }
    }
    // END TESB-7319
    Map<ExportChoice, Object> exportChoiceMap = mainPage.getExportChoiceMap();
    exportChoiceMap.put(ExportChoice.doNotCompileCode, false);
    exportChoiceMap.put(ExportChoice.needDependencies, false);
    exportChoiceMap.put(ExportChoice.addStatistics, false);
    exportChoiceMap.put(ExportChoice.addTracs, false);
    exportChoiceMap.put(ExportChoice.needAntScript, false);
    exportChoiceMap.put(ExportChoice.needMavenScript, false);
    exportChoiceMap.put(ExportChoice.applyToChildren, false);
    exportChoiceMap.put(ExportChoice.needContext, true);
    exportChoiceMap.put(ExportChoice.binaries, true);
    exportChoiceMap.put(ExportChoice.needSourceCode, false);
    exportChoiceMap.put(ExportChoice.executeTests, false);
    exportChoiceMap.put(ExportChoice.includeTestSource, false);
    exportChoiceMap.put(ExportChoice.includeLibs, true);
    exportChoiceMap.put(ExportChoice.needLog4jLevel, false);
    exportChoiceMap.put(ExportChoice.needAssembly, true);
    String bundleVersion = PomIdsHelper.getJobVersion(serviceItem.getProperty());
    if (bundleVersion != null) {
        bundleVersion = bundleVersion.replace("-", ".");
    }
    exportChoiceMap.put(ExportChoice.bundleVersion, bundleVersion);
    // update to use BuildDataServiceHandler
    IProgressMonitor pMonitor = new NullProgressMonitor();
    int scale = 10;
    BuildDataServiceHandler buildServiceHandler = new BuildDataServiceHandler(serviceItem, serviceItem.getProperty().getVersion(), IContext.DEFAULT, exportChoiceMap);
    Map<String, Object> prepareParams = new HashMap<String, Object>();
    prepareParams.put(IBuildResourceParametes.OPTION_ITEMS, true);
    prepareParams.put(IBuildResourceParametes.OPTION_ITEMS_DEPENDENCIES, true);
    try {
        buildServiceHandler.prepare(pMonitor, prepareParams);
        buildServiceHandler.build(new SubProgressMonitor(pMonitor, scale));
        IFile serviceTargetFile = buildServiceHandler.getJobTargetFile();
        if (serviceTargetFile != null && serviceTargetFile.exists()) {
            FilesUtils.copyFile(serviceTargetFile.getLocation().toFile(), new File(destinationValue));
        } else {
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
                IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
                ITalendProcessJavaProject talendJavaProject = service.getTalendJobJavaProject(serviceItem.getProperty());
                String mvnLogFilePath = // $NON-NLS-1$
                talendJavaProject.getProject().getFile("lastGenerated.log").getLocation().toPortableString();
                Exception e = new Exception("Service was not built successfully, please check the logs for more details available on " + mvnLogFilePath);
                MessageBoxExceptionHandler.process(e, getShell());
            }
            return false;
        }
    } catch (Exception e) {
        MessageBoxExceptionHandler.process(e, getShell());
        BuildCacheManager.getInstance().performBuildFailure();
        return false;
    } finally {
        ProcessorUtilities.resetExportConfig();
    }
    mainPage.finish();
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) BuildDataServiceHandler(org.talend.repository.services.export.BuildDataServiceHandler) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 10 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tesb-studio-se by Talend.

the class ExportServiceActionTest method testRun.

/**
 * Test method for
 * {@link org.talend.repository.services.ui.action.ExportServiceAction#run(org.eclipse.core.runtime.IProgressMonitor)}
 * .
 */
@Test
public void testRun() {
    Map<ExportChoice, Object> exportChoiceMap = new EnumMap<ExportChoice, Object>(ExportChoice.class);
    exportChoiceMap.put(ExportChoice.needLauncher, true);
    exportChoiceMap.put(ExportChoice.needSystemRoutine, true);
    exportChoiceMap.put(ExportChoice.needUserRoutine, true);
    exportChoiceMap.put(ExportChoice.needTalendLibraries, true);
    exportChoiceMap.put(ExportChoice.needJobItem, true);
    exportChoiceMap.put(ExportChoice.needJobScript, true);
    exportChoiceMap.put(ExportChoice.needContext, true);
    exportChoiceMap.put(ExportChoice.needSourceCode, true);
    exportChoiceMap.put(ExportChoice.applyToChildren, false);
    exportChoiceMap.put(ExportChoice.doNotCompileCode, false);
    exportChoiceMap.put(ExportChoice.needMavenScript, false);
    ServiceItem serviceItem = ServicesFactory.eINSTANCE.createServiceItem();
    Property property = PropertiesFactory.eINSTANCE.createProperty();
    property.setLabel("testSvr");
    serviceItem.setProperty(property);
    ItemState state = PropertiesFactory.eINSTANCE.createItemState();
    serviceItem.setState(state);
    ServiceConnection connection = ServicesFactoryImpl.eINSTANCE.createServiceConnection();
    serviceItem.setConnection(connection);
    try {
        File fileName = File.createTempFile("serviceExportTest", ".jar");
        ExportServiceAction action = new ExportServiceAction(serviceItem, fileName.getAbsolutePath(), exportChoiceMap);
        Assert.assertNotNull(action.getTmpFolderPath());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Test testRun() method failure.");
    }
}
Also used : ExportServiceAction(org.talend.repository.services.ui.action.ExportServiceAction) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) ItemState(org.talend.core.model.properties.ItemState) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) ServiceItem(org.talend.repository.services.model.services.ServiceItem) EnumMap(java.util.EnumMap) Property(org.talend.core.model.properties.Property) File(java.io.File) Test(org.junit.Test)

Aggregations

ExportChoice (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 File (java.io.File)7 ProcessItem (org.talend.core.model.properties.ProcessItem)7 IOException (java.io.IOException)6 ProcessorException (org.talend.designer.runprocess.ProcessorException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 EnumMap (java.util.EnumMap)4 Map (java.util.Map)4 IFile (org.eclipse.core.resources.IFile)4 IBuildJobHandler (org.talend.core.runtime.process.IBuildJobHandler)4 ExportFileResource (org.talend.repository.documentation.ExportFileResource)4 HashMap (java.util.HashMap)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 JobScriptsManager (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager)3 URL (java.net.URL)2 Properties (java.util.Properties)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Test (org.junit.Test)2