public static ESBArtifact getESBArtifactFromFile( IFile refactoredFile, String projectNatureFilter) { IProject esbProject = refactoredFile.getProject(); try { esbProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); if (esbProject.isOpen() && esbProject.hasNature(projectNatureFilter)) { ESBProjectArtifact esbProjectArtifact = new ESBProjectArtifact(); esbProjectArtifact.fromFile(esbProject.getFile("artifact.xml").getLocation().toFile()); List<ESBArtifact> allESBArtifacts = esbProjectArtifact.getAllESBArtifacts(); String originalFileRelativePath = FileUtils.getRelativePath( esbProject.getLocation().toFile(), refactoredFile.getLocation().toFile()) .replaceAll(Pattern.quote(File.separator), "/"); for (ESBArtifact esbArtifact : allESBArtifacts) { if (esbArtifact.getFile().equals(originalFileRelativePath)) { return esbArtifact; } } } } catch (CoreException e) { log.error("Error while reading ESB Project", e); } catch (FactoryConfigurationError e) { log.error("Error while reading ESB Project", e); } catch (Exception e) { log.error("Error while reading ESB Project", e); } return null; }
public void copyImportFile(IContainer importLocation, boolean isNewAritfact, String groupId) throws IOException { File importFile = getModel().getImportFile(); File destFile = null; List<OMElement> selectedSeqList = ((TemplateModel) getModel()).getSelectedTempSequenceList(); if (selectedSeqList != null && selectedSeqList.size() > 0) { for (OMElement element : selectedSeqList) { String name = element.getAttributeValue(new QName("name")); destFile = new File(importLocation.getLocation().toFile(), name + ".xml"); FileUtils.createFile(destFile, element.toString()); fileLst.add(destFile); if (isNewAritfact) { ESBArtifact artifact = new ESBArtifact(); artifact.setName(name); artifact.setVersion(version); artifact.setType("synapse/template"); artifact.setServerRole("EnterpriseServiceBus"); artifact.setGroupId(groupId); artifact.setFile( FileUtils.getRelativePath( importLocation.getProject().getLocation().toFile(), new File(importLocation.getLocation().toFile(), name + ".xml")) .replaceAll(Pattern.quote(File.separator), "/")); esbProjectArtifact.addESBArtifact(artifact); } } } else { destFile = new File(importLocation.getLocation().toFile(), importFile.getName()); FileUtils.copy(importFile, destFile); fileLst.add(destFile); String name = importFile.getName().replaceAll(".xml$", ""); if (isNewAritfact) { ESBArtifact artifact = new ESBArtifact(); artifact.setName(name); artifact.setVersion(version); artifact.setType("synapse/template"); artifact.setServerRole("EnterpriseServiceBus"); artifact.setGroupId(groupId); artifact.setFile( FileUtils.getRelativePath( importLocation.getProject().getLocation().toFile(), new File(importLocation.getLocation().toFile(), name + ".xml")) .replaceAll(Pattern.quote(File.separator), "/")); esbProjectArtifact.addESBArtifact(artifact); } } }
private boolean createSequenceArtifact(TemplateModel sequenceModel) throws Exception { boolean isNewArtifact = true; IContainer location = project.getFolder( "src" + File.separator + "main" + File.separator + "synapse-config" + File.separator + "templates"); esbProjectArtifact = new ESBProjectArtifact(); esbProjectArtifact.fromFile(project.getFile("artifact.xml").getLocation().toFile()); File pomfile = project.getFile("pom.xml").getLocation().toFile(); getModel().getMavenInfo().setPackageName("synapse/template"); if (!pomfile.exists()) { createPOM(pomfile); } updatePom(); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); String groupId = getMavenGroupId(pomfile); groupId += ".template"; if (getModel().getSelectedOption().equals("import.template")) { IFile sequence = location.getFile(new Path(getModel().getImportFile().getName())); if (sequence.exists()) { if (!MessageDialog.openQuestion( getShell(), "WARNING", "Do you like to override exsiting project in the workspace")) { return false; } isNewArtifact = false; } copyImportFile(location, isNewArtifact, groupId); } else { String templateContent = ""; String template = ""; ArtifactTemplate selectedTemplate = templateModel.getSelectedTemplate(); templateContent = FileUtils.getContentAsString(selectedTemplate.getTemplateDataStream()); if (selectedTemplate.getName().equals("Address Endpoint Template")) { template = createEPTemplate(templateContent, "Address Endpoint Template"); } else if (selectedTemplate.getName().equals("WSDL Endpoint Template")) { template = createEPTemplate(templateContent, "WSDL Endpoint Template"); } else if (selectedTemplate.getName().equals("Default Endpoint Template")) { template = createEPTemplate(templateContent, "Default Endpoint Template"); } else if (selectedTemplate.getName().equals("Sequence Template")) { template = createEPTemplate(templateContent, "Sequence Template"); } else if (selectedTemplate.getName().equals("HTTP Endpoint Template")) { template = createEPTemplate(templateContent, "HTTP Endpoint Template"); } else { template = createEPTemplate(templateContent, ""); } File destFile = new File(location.getLocation().toFile(), sequenceModel.getTemplateName() + ".xml"); FileUtils.createFile(destFile, template); fileLst.add(destFile); ESBArtifact artifact = new ESBArtifact(); artifact.setName(sequenceModel.getTemplateName()); artifact.setVersion(version); if ("Sequence Template".equals(selectedTemplate.getName())) { artifact.setType("synapse/sequenceTemplate"); } else { artifact.setType("synapse/endpointTemplate"); } artifact.setServerRole("EnterpriseServiceBus"); artifact.setGroupId(groupId); artifact.setFile( FileUtils.getRelativePath( project.getLocation().toFile(), new File( location.getLocation().toFile(), sequenceModel.getTemplateName() + ".xml")) .replaceAll(Pattern.quote(File.separator), "/")); esbProjectArtifact.addESBArtifact(artifact); } esbProjectArtifact.toFile(); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); return true; }