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());
}
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;
}
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());
}
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;
}
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);
}
}
Aggregations