public void updatePom() throws IOException, XmlPullParserException { File mavenProjectPomLocation = project.getFile("pom.xml").getLocation().toFile(); MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation); version = mavenProject.getVersion(); // Skip changing the pom file if group ID and artifact ID are matched if (MavenUtils.checkOldPluginEntry( mavenProject, "org.wso2.maven", "wso2-esb-template-plugin")) { return; } Plugin plugin = MavenUtils.createPluginEntry( mavenProject, "org.wso2.maven", "wso2-esb-template-plugin", MavenConstants.WSO2_ESB_TEMPLATE_VERSION, true); PluginExecution pluginExecution = new PluginExecution(); pluginExecution.addGoal("pom-gen"); pluginExecution.setPhase("process-resources"); pluginExecution.setId("template"); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom artifactLocationNode = MavenUtils.createXpp3Node(configurationNode, "artifactLocation"); artifactLocationNode.setValue("."); Xpp3Dom typeListNode = MavenUtils.createXpp3Node(configurationNode, "typeList"); typeListNode.setValue("${artifact.types}"); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation); }
public void updatePom() throws Exception { File mavenProjectPomLocation = project.getFile("pom.xml").getLocation().toFile(); MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation); boolean pluginExists = MavenUtils.checkOldPluginEntry( mavenProject, "org.wso2.maven", "wso2-esb-template-plugin", MavenConstants.WSO2_ESB_TEMPLATE_VERSION); if (pluginExists) { return; } Plugin plugin = MavenUtils.createPluginEntry( mavenProject, "org.wso2.maven", "wso2-esb-template-plugin", MavenConstants.WSO2_ESB_TEMPLATE_VERSION, true); PluginExecution pluginExecution = new PluginExecution(); pluginExecution.addGoal("pom-gen"); pluginExecution.setPhase("process-resources"); pluginExecution.setId("template"); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom artifactLocationNode = MavenUtils.createXpp3Node(configurationNode, "artifactLocation"); artifactLocationNode.setValue("."); Xpp3Dom typeListNode = MavenUtils.createXpp3Node(configurationNode, "typeList"); typeListNode.setValue("${artifact.types}"); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); Repository repo = new Repository(); repo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/"); repo.setId("wso2-nexus"); RepositoryPolicy releasePolicy = new RepositoryPolicy(); releasePolicy.setEnabled(true); releasePolicy.setUpdatePolicy("daily"); releasePolicy.setChecksumPolicy("ignore"); repo.setReleases(releasePolicy); if (!mavenProject.getRepositories().contains(repo)) { mavenProject.getModel().addRepository(repo); mavenProject.getModel().addPluginRepository(repo); } MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation); }
public boolean performFinish() { try { if (customMediatorModel.getSelectedOption().equals("new.mediator")) { project = createNewProject(); IFolder srcFolder = ProjectUtils.getWorkspaceFolder(project, "src", "main", "java"); JavaUtils.addJavaSupportAndSourceFolder(project, srcFolder); /*create the new Java project*/ String className = customMediatorModel.getMediatorClassName(); String packageName = customMediatorModel.getMediatorClassPackageName(); IJavaProject iJavaProject = JavaCore.create(project); IPackageFragmentRoot root = iJavaProject.getPackageFragmentRoot(srcFolder); IPackageFragment sourcePackage = root.createPackageFragment(packageName, false, null); /*get the Mediator class template*/ String template = CustomMediatorClassTemplate.getClassTemplete(packageName, className); ICompilationUnit cu = sourcePackage.createCompilationUnit(className + ".java", template, false, null); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); try { IEditorPart javaEditor = JavaUI.openInEditor(cu); JavaUI.revealInEditor(javaEditor, (IJavaElement) cu); } catch (Exception e) { log.error(e); } } else { project = customMediatorModel.getMediatorProject(); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } File pomfile = project.getFile("pom.xml").getLocation().toFile(); getModel().getMavenInfo().setPackageName("bundle"); if (!pomfile.exists()) { createPOM(pomfile); addDependancies(project); } MavenProject mavenProject = MavenUtils.getMavenProject(pomfile); boolean pluginExists = MavenUtils.checkOldPluginEntry( mavenProject, "org.apache.felix", "maven-bundle-plugin", "2.3.4"); if (!pluginExists) { Plugin plugin = MavenUtils.createPluginEntry( mavenProject, "org.apache.felix", "maven-bundle-plugin", "2.3.4", true); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(plugin); Xpp3Dom instructionNode = MavenUtils.createXpp3Node("instructions"); Xpp3Dom bundleSymbolicNameNode = MavenUtils.createXpp3Node(instructionNode, "Bundle-SymbolicName"); Xpp3Dom bundleNameNode = MavenUtils.createXpp3Node(instructionNode, "Bundle-Name"); ; Xpp3Dom exportPackageNode = MavenUtils.createXpp3Node(instructionNode, "Export-Package"); Xpp3Dom dynamicImportNode = MavenUtils.createXpp3Node(instructionNode, "DynamicImport-Package"); bundleSymbolicNameNode.setValue(project.getName()); bundleNameNode.setValue(project.getName()); if (customMediatorModel.getMediatorClassPackageName() != null && !customMediatorModel.getMediatorClassPackageName().trim().isEmpty()) { exportPackageNode.setValue(customMediatorModel.getMediatorClassPackageName()); } else { IJavaProject javaProject = JavaCore.create(project); if (null != javaProject) { StringBuffer sb = new StringBuffer(); for (IPackageFragment pkg : javaProject.getPackageFragments()) { if (pkg.getKind() == IPackageFragmentRoot.K_SOURCE) { if (pkg.hasChildren()) { sb.append(pkg.getElementName()).append(","); } } } exportPackageNode.setValue(sb.toString().replaceAll(",$", "")); } } dynamicImportNode.setValue("*"); configurationNode.addChild(instructionNode); MavenUtils.saveMavenProject(mavenProject, pomfile); } project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); ProjectUtils.addNatureToProject(project, false, MEDIATOR_PROJECT_NATURE); MavenUtils.updateWithMavenEclipsePlugin( pomfile, new String[] {JDT_BUILD_COMMAND}, new String[] {MEDIATOR_PROJECT_NATURE, JDT_PROJECT_NATURE}); customMediatorModel.addToWorkingSet(project); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); refreshDistProjects(); } catch (CoreException e) { log.error(e); } catch (Exception e) { log.error(e); } return true; }