Search in sources :

Example 1 with IMavenPomCreator

use of org.talend.core.runtime.repository.build.IMavenPomCreator in project tdi-studio-se by Talend.

the class StandardJobStandaloneBuildProviderTest method test_createPomCreator.

@Test
public void test_createPomCreator() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    Item jobItem = createJobItem();
    final IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
    Assert.assertNotNull(designerCoreService);
    final IProcess processFromItem = designerCoreService.getProcessFromItem(jobItem);
    IProcessor processor = ProcessorUtilities.getProcessor(processFromItem, jobItem.getProperty());
    final Class<? extends IProcessor> processorClazz = processor.getClass();
    Assert.assertEquals("org.talend.designer.runprocess.maven.MavenJavaProcessor", processorClazz.getName());
    processor.setContext(processor.getProcess().getContextManager().getDefaultContext());
    parameters.put(IBuildPomCreatorParameters.PROCESSOR, processor);
    final Method getPomFileMethod = processorClazz.getDeclaredMethod("getPomFile");
    getPomFileMethod.setAccessible(true);
    final Object getPomFile = getPomFileMethod.invoke(processor);
    Assert.assertTrue(getPomFile instanceof IFile);
    IFile pomFile = (IFile) getPomFile;
    parameters.put(IBuildPomCreatorParameters.FILE_POM, pomFile);
    final Method getAssemblyFileMethod = processorClazz.getDeclaredMethod("getAssemblyFile");
    getAssemblyFileMethod.setAccessible(true);
    final Object getAssemblyFile = getAssemblyFileMethod.invoke(processor);
    Assert.assertTrue(getPomFile instanceof IFile);
    IFile assemblyFile = (IFile) getAssemblyFile;
    parameters.put(IBuildPomCreatorParameters.FILE_ASSEMBLY, assemblyFile);
    // before set classpath, must do initJobClasspath
    final Method initJobClasspathMethod = processorClazz.getDeclaredMethod("initJobClasspath");
    initJobClasspathMethod.setAccessible(true);
    initJobClasspathMethod.invoke(processor);
    final Field windowsClasspathField = processorClazz.getDeclaredField("windowsClasspath");
    windowsClasspathField.setAccessible(true);
    parameters.put(IBuildPomCreatorParameters.CP_WIN, windowsClasspathField.get(processor));
    final Field unixClasspathField = processorClazz.getDeclaredField("unixClasspath");
    unixClasspathField.setAccessible(true);
    parameters.put(IBuildPomCreatorParameters.CP_LINUX, unixClasspathField.get(processor));
    parameters.put(IBuildParametes.ITEM, processor.getProperty().getItem());
    final Map<String, Object> arguments = processor.getArguments();
    parameters.put(IBuildPomCreatorParameters.ARGUMENTS_MAP, arguments);
    parameters.put(IBuildPomCreatorParameters.OVERWRITE_POM, true);
    // create pom and assembly
    RepositoryObjectTypeBuildProvider provider = createTestBuildProvider();
    final IMavenPomCreator pomCreator = provider.createPomCreator(parameters);
    Assert.assertNotNull("Create the pom creator failure", pomCreator);
    Assert.assertEquals(CreateMavenJobPom.class, pomCreator.getClass());
    pomCreator.create(null);
    pomFile.getParent().refreshLocal(IResource.DEPTH_ONE, null);
    Assert.assertTrue("the pom file " + pomFile.getName() + " is not created ", pomFile.exists());
    assemblyFile.getParent().refreshLocal(IResource.DEPTH_ONE, null);
    Assert.assertTrue("the assembly file " + assemblyFile.getName() + " is not created ", assemblyFile.exists());
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) IProcessor(org.talend.designer.runprocess.IProcessor) Method(java.lang.reflect.Method) Item(org.talend.core.model.properties.Item) Field(java.lang.reflect.Field) RepositoryObjectTypeBuildProvider(org.talend.core.runtime.repository.build.RepositoryObjectTypeBuildProvider) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) Test(org.junit.Test)

Example 2 with IMavenPomCreator

use of org.talend.core.runtime.repository.build.IMavenPomCreator in project tesb-studio-se by Talend.

the class BundleJavaProcessor method createMavenPomCreator.

/*
     * (non-Javadoc)
     *
     * @see org.talend.designer.runprocess.maven.MavenJavaProcessor#createMavenPomCreator()
     */
@Override
protected IMavenPomCreator createMavenPomCreator() {
    final Property itemProperty = this.getProperty();
    String buildTypeName = null;
    // FIXME, better use the arguments directly for run/export/build/..., and remove this flag later.
    if (ProcessorUtilities.isExportConfig()) {
        // final Object exportType = itemProperty.getAdditionalProperties().get(MavenConstants.NAME_EXPORT_TYPE);
        final Object exportType = getArguments().get(TalendProcessArgumentConstant.ARG_BUILD_TYPE);
        buildTypeName = exportType != null ? exportType.toString() : null;
    }
    // else { //if run job, will be null (use Standalone by default)
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put(IBuildParametes.ITEM, itemProperty.getItem());
    parameters.put(IBuildPomCreatorParameters.PROCESSOR, this);
    parameters.put(IBuildPomCreatorParameters.FILE_POM, getPomFile());
    parameters.put(IBuildPomCreatorParameters.FILE_ASSEMBLY, getAssemblyFile());
    parameters.put(IBuildPomCreatorParameters.CP_LINUX, this.unixClasspath);
    parameters.put(IBuildPomCreatorParameters.CP_WIN, this.windowsClasspath);
    parameters.put(IBuildPomCreatorParameters.ARGUMENTS_MAP, getArguments());
    parameters.put(IBuildPomCreatorParameters.OVERWRITE_POM, Boolean.TRUE);
    AbstractBuildProvider foundBuildProvider = BuildExportManager.getInstance().getBuildProvider(buildTypeName, parameters);
    if (foundBuildProvider != null) {
        final IMavenPomCreator creator = foundBuildProvider.createPomCreator(parameters);
        if (creator != null) {
            return creator;
        }
    }
    // normally, won't be here, should return creator in font.
    CreateMavenBundlePom createTemplatePom = new CreateMavenBundlePom(this, getPomFile());
    createTemplatePom.setUnixClasspath(this.unixClasspath);
    createTemplatePom.setWindowsClasspath(this.windowsClasspath);
    createTemplatePom.setAssemblyFile(getAssemblyFile());
    IPath itemLocationPath = ItemResourceUtil.getItemLocationPath(this.getProperty());
    IFolder objectTypeFolder = ItemResourceUtil.getObjectTypeFolder(this.getProperty());
    if (itemLocationPath != null && objectTypeFolder != null) {
        IPath itemRelativePath = itemLocationPath.removeLastSegments(1).makeRelativeTo(objectTypeFolder.getLocation());
        createTemplatePom.setObjectTypeFolder(objectTypeFolder);
        createTemplatePom.setItemRelativePath(itemRelativePath);
    }
    return createTemplatePom;
}
Also used : AbstractBuildProvider(org.talend.core.runtime.repository.build.AbstractBuildProvider) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) RepositoryObject(org.talend.core.model.repository.RepositoryObject) IRepositoryObject(org.talend.core.model.repository.IRepositoryObject) CreateMavenBundlePom(org.talend.camel.designer.build.CreateMavenBundlePom) Property(org.talend.core.model.properties.Property) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with IMavenPomCreator

use of org.talend.core.runtime.repository.build.IMavenPomCreator in project tesb-studio-se by Talend.

the class RouteTestCaseBuildProviderTest method testCreatePomCreator.

/**
 * Test method for
 * {@link org.talend.camel.designer.build.RouteTestCaseBuildProvider#createPomCreator(java.util.Map)}.
 *
 * @throws Exception
 */
@Test
public void testCreatePomCreator() throws Exception {
    ProcessItem processItem = PropertiesFactory.eINSTANCE.createProcessItem();
    Property property = PropertiesFactory.eINSTANCE.createProperty();
    String id = ProxyRepositoryFactory.getInstance().getNextId();
    property.setId(id);
    ItemState itemState = PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(false);
    itemState.setPath("");
    processItem.setState(itemState);
    processItem.setProperty(property);
    ProcessType processType = TalendFileFactory.eINSTANCE.createProcessType();
    processItem.setProcess(processType);
    property.setLabel("testRoute");
    property.setVersion("0.1");
    property.setItem(processItem);
    // $NON-NLS-1$ //$NON-NLS-2$
    IComponent component = ComponentsFactoryProvider.getInstance().get("cTimer", "CAMEL");
    RouteProcess process = new RouteProcess(property);
    process.setId("routeprocess");
    INode nodeTimer = new Node(component, process);
    nodeTimer.setLabel("cTimer_1");
    MavenJavaProcessor processor = new MavenJavaProcessor(process, property, true);
    processor.setContext(process.getContextManager().getDefaultContext());
    Project project = ProjectManager.getInstance().getCurrentProject();
    IProject fsProject = ResourceUtils.getProject(project);
    IPath path = new Path("poms").append("jobs").append("process").append(property.getLabel().concat("_").concat(property.getVersion()).toLowerCase()).append("temp");
    ResourceUtils.createFolder(fsProject.getFolder(path));
    path = path.append("pom.xml");
    IFile file = fsProject.getFile(path);
    String pomContent = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n" + "  <modelVersion>4.0.0</modelVersion>\n" + "  <artifactId>esb.tooling.test</artifactId>\n" + "  <packaging>jar</packaging>\n" + "  <name>Test POM</name>\n" + "</project>";
    InputStream inputStream = new ByteArrayInputStream(pomContent.getBytes(StandardCharsets.UTF_8));
    file.delete(true, new NullProgressMonitor());
    file.create(inputStream, false, new NullProgressMonitor());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put(IBuildParametes.ITEM, processItem);
    parameters.put(IBuildPomCreatorParameters.PROCESSOR, processor);
    parameters.put(IBuildPomCreatorParameters.FILE_POM, file);
    parameters.put(IBuildPomCreatorParameters.OVERWRITE_POM, Boolean.TRUE);
    IMavenPomCreator creator = new RouteTestCaseBuildProvider().createPomCreator(parameters);
    creator.create(new NullProgressMonitor());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RouteTestCaseBuildProvider(org.talend.camel.designer.build.RouteTestCaseBuildProvider) INode(org.talend.core.model.process.INode) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IComponent(org.talend.core.model.components.IComponent) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) IProject(org.eclipse.core.resources.IProject) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) MavenJavaProcessor(org.talend.designer.runprocess.maven.MavenJavaProcessor) ProcessItem(org.talend.core.model.properties.ProcessItem) ByteArrayInputStream(java.io.ByteArrayInputStream) ItemState(org.talend.core.model.properties.ItemState) RouteProcess(org.talend.camel.designer.ui.editor.RouteProcess) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 4 with IMavenPomCreator

use of org.talend.core.runtime.repository.build.IMavenPomCreator in project tdi-studio-se by Talend.

the class MavenJavaProcessor method createMavenPomCreator.

protected IMavenPomCreator createMavenPomCreator() {
    final Property itemProperty = this.getProperty();
    String buildTypeName = null;
    // FIXME, better use the arguments directly for run/export/build/..., and remove this flag later.
    if (ProcessorUtilities.isExportConfig()) {
        // final Object exportType = itemProperty.getAdditionalProperties().get(MavenConstants.NAME_EXPORT_TYPE);
        final Object exportType = getArguments().get(TalendProcessArgumentConstant.ARG_BUILD_TYPE);
        buildTypeName = exportType != null ? exportType.toString() : null;
    }
    // else { //if run job, will be null (use Standalone by default)
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put(IBuildParametes.ITEM, itemProperty.getItem());
    parameters.put(IBuildPomCreatorParameters.PROCESSOR, this);
    parameters.put(IBuildPomCreatorParameters.FILE_POM, getPomFile());
    parameters.put(IBuildPomCreatorParameters.FILE_ASSEMBLY, getAssemblyFile());
    parameters.put(IBuildPomCreatorParameters.CP_LINUX, this.unixClasspath);
    parameters.put(IBuildPomCreatorParameters.CP_WIN, this.windowsClasspath);
    parameters.put(IBuildPomCreatorParameters.ARGUMENTS_MAP, getArguments());
    parameters.put(IBuildPomCreatorParameters.OVERWRITE_POM, Boolean.TRUE);
    AbstractBuildProvider foundBuildProvider = BuildExportManager.getInstance().getBuildProvider(buildTypeName, parameters);
    if (foundBuildProvider != null) {
        final IMavenPomCreator creator = foundBuildProvider.createPomCreator(parameters);
        if (creator != null) {
            return creator;
        }
    }
    // normally, won't be here, should return creator in font.
    CreateMavenJobPom createTemplatePom = new CreateMavenJobPom(this, getPomFile());
    createTemplatePom.setUnixClasspath(this.unixClasspath);
    createTemplatePom.setWindowsClasspath(this.windowsClasspath);
    createTemplatePom.setAssemblyFile(getAssemblyFile());
    IPath itemLocationPath = ItemResourceUtil.getItemLocationPath(this.getProperty());
    IFolder objectTypeFolder = ItemResourceUtil.getObjectTypeFolder(this.getProperty());
    if (itemLocationPath != null && objectTypeFolder != null) {
        IPath itemRelativePath = itemLocationPath.removeLastSegments(1).makeRelativeTo(objectTypeFolder.getLocation());
        createTemplatePom.setObjectTypeFolder(objectTypeFolder);
        createTemplatePom.setItemRelativePath(itemRelativePath);
    }
    return createTemplatePom;
}
Also used : AbstractBuildProvider(org.talend.core.runtime.repository.build.AbstractBuildProvider) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) CreateMavenJobPom(org.talend.designer.maven.tools.creator.CreateMavenJobPom) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) Property(org.talend.core.model.properties.Property) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with IMavenPomCreator

use of org.talend.core.runtime.repository.build.IMavenPomCreator in project tdi-studio-se by Talend.

the class MavenJavaProcessor method generatePom.

protected void generatePom(int option) {
    initJobClasspath();
    try {
        IMavenPomCreator createTemplatePom = createMavenPomCreator();
        if (createTemplatePom != null) {
            createTemplatePom.setSyncCodesPoms(option == 0);
            boolean previousValue = ProcessUtils.jarNeedsToContainContext();
            ProcessUtils.setJarWithContext(ProcessUtils.needsToHaveContextInsideJar((ProcessItem) property.getItem()));
            createTemplatePom.create(null);
            ProcessUtils.setJarWithContext(previousValue);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) ProcessorException(org.talend.designer.runprocess.ProcessorException)

Aggregations

IMavenPomCreator (org.talend.core.runtime.repository.build.IMavenPomCreator)8 HashMap (java.util.HashMap)5 IPath (org.eclipse.core.runtime.IPath)4 IFile (org.eclipse.core.resources.IFile)3 Test (org.junit.Test)3 Property (org.talend.core.model.properties.Property)3 IProcessor (org.talend.designer.runprocess.IProcessor)3 Method (java.lang.reflect.Method)2 IFolder (org.eclipse.core.resources.IFolder)2 IProject (org.eclipse.core.resources.IProject)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Project (org.talend.core.model.general.Project)2 IProcess (org.talend.core.model.process.IProcess)2 Item (org.talend.core.model.properties.Item)2 ProcessItem (org.talend.core.model.properties.ProcessItem)2 AbstractBuildProvider (org.talend.core.runtime.repository.build.AbstractBuildProvider)2 RepositoryObjectTypeBuildProvider (org.talend.core.runtime.repository.build.RepositoryObjectTypeBuildProvider)2 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)2 CreateMavenJobPom (org.talend.designer.maven.tools.creator.CreateMavenJobPom)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1