List of usage examples for org.apache.maven.project MavenProject getBuild
public Build getBuild()
From source file:org.wso2.developerstudio.eclipse.artifact.analytics.utils.AnalyticsProjectUtils.java
License:Open Source License
public static void addPluginEntry(MavenProject mavenProject, String groupId, String artifactId, String version, String Id) {// w w w.j a v a 2s .c o m List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plg : plugins) { if (plg.getGroupId().equalsIgnoreCase(groupId) && plg.getArtifactId().equalsIgnoreCase(artifactId) && plg.getVersion().equalsIgnoreCase(version)) { return; } } Plugin plugin = MavenUtils.createPluginEntry(mavenProject, groupId, artifactId, version, true); PluginExecution pluginExecution = new PluginExecution(); pluginExecution.addGoal("pom-gen"); pluginExecution.setPhase("process-resources"); pluginExecution.setId(Id); 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); } }
From source file:org.wso2.developerstudio.eclipse.artifact.carbon.ui.bundle.ui.wizard.CarbonUIbundleWizard.java
License:Open Source License
public boolean performFinish() { try {//from www . j av a2s .c o m if (uibundleModel.getSelectedOption().equals("new.uibundle")) { project = createNewProject(); IFolder srcFolder = ProjectUtils.getWorkspaceFolder(project, "src"); JavaUtils.addJavaSupportAndSourceFolder(project, srcFolder); ProjectUtils.createFolder(srcFolder); if (uibundleModel.isActivatorRequired()) { String className = uibundleModel.getActivatorClassName(); if (".Activator".equals(className)) { className = "Activator"; uibundleModel.setActivatorClassName(className); } className = getClassName(uibundleModel.getActivatorClassName()); String packageName = getPackageName(uibundleModel.getActivatorClassName()); IJavaProject iJavaProject = JavaCore.create(project); IPackageFragmentRoot root = iJavaProject.getPackageFragmentRoot(srcFolder); IPackageFragment sourcePackage = root.createPackageFragment(packageName, false, null); String template = CarbonUIbudleTemplate.createActivatorClassTemplete(packageName, className); sourcePackage.createCompilationUnit(className + ".java", template, false, null); } /*create Meta INF Folder data*/ IFolder metaInf = this.createWorkspaceFolder("META-INF"); String componentXmlSource = CarbonUIbudleTemplate.createComponentXMLTemplate(); createProjectFile(metaInf, "component.xml", componentXmlSource); String metaInfSource = CarbonUIbudleTemplate.createManifestFileTemplate(uibundleModel); createProjectFile(metaInf, "MANIFEST.MF", metaInfSource); IFolder webDir = createDirectoryhierarchy(uibundleModel.getDeployPath()); IFolder cssDir = webDir.getFolder("css"); cssDir.create(true, true, new NullProgressMonitor()); IFolder imgDir = webDir.getFolder("images"); imgDir.create(true, true, new NullProgressMonitor()); IFolder jsDir = webDir.getFolder("js"); jsDir.create(true, true, new NullProgressMonitor()); copyResourceFiles(cssDir.getLocation().toFile(), "menu.css"); copyResourceFiles(webDir.getLocation().toFile(), "index.jsp"); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } else { project = uibundleModel.getCarbonUIproject(); } File pomfile = project.getFile("pom.xml").getLocation().toFile(); getModel().getMavenInfo().setPackageName("bundle"); if (!pomfile.exists()) { createPOM(pomfile); } addDependancies(project); MavenProject mavenProject = MavenUtils.getMavenProject(pomfile); Dependency dependencies = new Dependency(); dependencies.setGroupId("org.eclipse.osgi"); dependencies.setArtifactId("org.eclipse.osgi"); dependencies.setVersion("3.7.0.v20110613"); MavenUtils.addMavenDependency(mavenProject, dependencies); mavenProject.getBuild().setSourceDirectory("src"); MavenUtils.saveMavenProject(mavenProject, pomfile); boolean pluginExists = MavenUtils.checkOldPluginEntry(mavenProject, "org.apache.felix", "maven-bundle-plugin", "2.3.4"); if (pluginExists) { project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); return true; } project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); ProjectUtils.addNatureToProject(project, false, CARBON_UI_BUNDLE_PROJECT_NATURE); MavenUtils.updateWithMavenEclipsePlugin(pomfile, new String[] { JDT_BUILD_COMMAND }, new String[] { CARBON_UI_BUNDLE_PROJECT_NATURE, JDT_PROJECT_NATURE }); project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); try { refreshDistProjects(); IFile activatorClassForProject = getManifestFileForProject(project); IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), activatorClassForProject); } catch (Exception e) { log.error("Cannot open file in editor", e); } } catch (CoreException e) { log.error("CoreException has occurred", e); } catch (Exception e) { log.error("An unexpected error has occurred", e); } return true; }
From source file:org.wso2.developerstudio.eclipse.artifact.connector.project.nature.ConnectorProjectNature.java
License:Open Source License
private void updatePom() { // TODO update the pom with the relavant packaging types & maven pligins File mavenProjectPomLocation = getProject().getFile("pom.xml").getLocation().toFile(); try {/* w w w . j av a 2 s.com*/ MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation); // Adding typrLidt property MavenUtils.updateMavenProjectWithCAppType(mavenProject, CAPP_TYPE); // Setting the directory mavenProject.getBuild().setDirectory("target/capp"); // Adding maven test skip property MavenUtils.updateMavenProjectWithSkipTests(mavenProject); // Adding maven exec plugin entry Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.codehaus.mojo", "exec-maven-plugin", "1.4.0", true); { PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId(ESBMavenConstants.PACKAGE_PHASE); pluginExecution.addGoal(ESBMavenConstants.EXEC_GOAL); pluginExecution.setPhase(ESBMavenConstants.PACKAGE_PHASE); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode, ESBMavenConstants.EXECUTABLE_TAG); executableNode.setValue(ESBMavenConstants.EXECUTABLE_VALUE); Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode, ESBMavenConstants.WORKING_DIRECTORY_TAG); workingDirectoryNode.setValue(ESBMavenConstants.WORKING_DIRECTORY_VALUE); Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode, ESBMavenConstants.ARGUMENTS_TAG); Xpp3Dom cleanArgumentNode = MavenUtils.createXpp3Node(argumentsNode, ESBMavenConstants.ARGUMENT_TAG); cleanArgumentNode.setValue(ESBMavenConstants.ARGUMENT_VALUE_CLEAN); Xpp3Dom installArgumentNode = MavenUtils.createXpp3Node(argumentsNode, ESBMavenConstants.ARGUMENT_TAG); installArgumentNode.setValue(ESBMavenConstants.PACKAGE_PHASE); Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode, ESBMavenConstants.ARGUMENT_TAG); testSkipArgumentNode.setValue(ESBMavenConstants.ARGUMENT_VALUE_SKIP_TESTS); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); } { PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId(ESBMavenConstants.INSTALL_PHASE); pluginExecution.addGoal(ESBMavenConstants.EXEC_GOAL); pluginExecution.setPhase(ESBMavenConstants.INSTALL_PHASE); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode, ESBMavenConstants.EXECUTABLE_TAG); executableNode.setValue(ESBMavenConstants.EXECUTABLE_VALUE); Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode, ESBMavenConstants.WORKING_DIRECTORY_TAG); workingDirectoryNode.setValue(ESBMavenConstants.WORKING_DIRECTORY_VALUE); Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode, ESBMavenConstants.ARGUMENTS_TAG); Xpp3Dom cleanArgumentNode = MavenUtils.createXpp3Node(argumentsNode, ESBMavenConstants.ARGUMENT_TAG); cleanArgumentNode.setValue(ESBMavenConstants.ARGUMENT_VALUE_CLEAN); Xpp3Dom installArgumentNode = MavenUtils.createXpp3Node(argumentsNode, ESBMavenConstants.ARGUMENT_TAG); installArgumentNode.setValue(ESBMavenConstants.INSTALL_PHASE); Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode, ESBMavenConstants.ARGUMENT_TAG); testSkipArgumentNode.setValue(ESBMavenConstants.ARGUMENT_VALUE_SKIP_TESTS); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); } { PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId(ESBMavenConstants.DEPLOY_PHASE); pluginExecution.addGoal(ESBMavenConstants.EXEC_GOAL); pluginExecution.setPhase(ESBMavenConstants.DEPLOY_PHASE); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode, ESBMavenConstants.EXECUTABLE_TAG); executableNode.setValue(ESBMavenConstants.EXECUTABLE_VALUE); Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode, ESBMavenConstants.WORKING_DIRECTORY_TAG); workingDirectoryNode.setValue(ESBMavenConstants.WORKING_DIRECTORY_VALUE); Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode, ESBMavenConstants.ARGUMENTS_TAG); Xpp3Dom deployArgumentNode = MavenUtils.createXpp3Node(argumentsNode, ESBMavenConstants.ARGUMENT_TAG); deployArgumentNode.setValue(ESBMavenConstants.DEPLOY_PHASE); Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode, ESBMavenConstants.ARGUMENT_TAG); testSkipArgumentNode.setValue(ESBMavenConstants.ARGUMENT_VALUE_SKIP_TESTS); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); } MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation); } catch (Exception e) { log.error(e); } try { getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } catch (CoreException e) { log.error(e); } }
From source file:org.wso2.developerstudio.eclipse.artifact.dataservice.project.export.DataServiceArtfactExportHandler.java
License:Open Source License
public List<IResource> exportArtifact(IProject project) throws Exception { String projectPath = project.getLocation().toFile().toString(); List<IResource> exportResources = new ArrayList<IResource>(); clearTarget(project);//w ww. j a v a2 s . com IFile pomFile = project.getFile(POM_FILE); IFile artifactXMLFile = project.getFile(ARTIFACT_XML); if (artifactXMLFile.exists()) { if (pomFile.exists()) { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plugin : plugins) { if (plugin.getArtifactId().equals(ARTIFACT_ID) && plugin.getGroupId().equals(GROUP_ID)) { Xpp3Dom[] artifactNodes = ((Xpp3Dom) plugin.getConfiguration()).getChildren(ARTIFACT_TAG); for (Xpp3Dom artifactNode : artifactNodes) { String dbsFile = artifactNode.getValue(); String[] pathArray = dbsFile.split("/"); IFile dbsFileRef = project .getFolder(DataServiceArtifactConstants.DS_PROJECT_DATASERVICE_FOLDER) .getFile(pathArray[pathArray.length - 1]); if (dbsFileRef.exists()) { exportResources.add((IResource) dbsFileRef); } } } } } else { File[] dbsFiles = FileUtils.getAllMatchingFiles(project.getLocation().toString(), null, DBS_FILE_EXTENSION, new ArrayList<File>()); for (File dbsFile : dbsFiles) { String filePath = dbsFile.toString(); // excluded any files inside target dir if (!filePath.substring(projectPath.length()) .startsWith(File.separator + TARGET + File.separator)) { IFile dbsFileRef = ResourcesPlugin.getWorkspace().getRoot() .getFileForLocation(Path.fromOSString(dbsFile.getAbsolutePath())); exportResources.add((IResource) dbsFileRef); } } } } else { if (pomFile.exists()) { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plugin : plugins) { if (plugin.getArtifactId().equals("maven-dataservice-plugin") && plugin.getGroupId().equals("org.wso2.maven")) { Xpp3Dom artifactNode = ((Xpp3Dom) plugin.getConfiguration()).getChild("artifact"); String dbsFile = artifactNode.getValue(); String[] pathArray = dbsFile.split("/"); IFile dbsFileRef = project.getFolder("src").getFolder("main").getFolder("dataservice") .getFile(pathArray[pathArray.length - 1]); if (dbsFileRef.exists()) { exportResources.add((IResource) dbsFileRef); } } } } else { File[] dbsFiles = FileUtils.getAllMatchingFiles(project.getLocation().toString(), null, DBS_FILE_EXTENSION, new ArrayList<File>()); for (File dbsFile : dbsFiles) { String filePath = dbsFile.toString(); // excluded any files inside target dir if (!filePath.substring(projectPath.length()) .startsWith(File.separator + "target" + File.separator)) { IFile dbsFileRef = ResourcesPlugin.getWorkspace().getRoot() .getFileForLocation(Path.fromOSString(dbsFile.getAbsolutePath())); exportResources.add((IResource) dbsFileRef); } } } } return exportResources; }
From source file:org.wso2.developerstudio.eclipse.artifact.dataservice.ui.wizard.DataServiceCreationWizard.java
License:Open Source License
/** * Gets the dss plugin if it is already available * /*from w w w . java2 s .c o m*/ * @param project * maven project * @param groupId * group ID * @param artifactId * artufact ID * @param version * version * @return dss plugin */ private Plugin getExistingPlugin(MavenProject project, String groupId, String artifactId, String version) { List<Plugin> plugins = project.getBuild().getPlugins(); Iterator<Plugin> iterator = plugins.iterator(); Plugin dssPlugin = null; while (iterator.hasNext()) { Plugin plugin = iterator.next(); if (plugin.getGroupId().equals(groupId) && plugin.getArtifactId().equals(artifactId)) { dssPlugin = plugin; } } return dssPlugin; }
From source file:org.wso2.developerstudio.eclipse.artifact.dataserviceProject.project.export.DataServiceArtfactExportHandler.java
License:Open Source License
public List<IResource> exportArtifact(IProject project) throws Exception { String projectPath = project.getLocation().toFile().toString(); List<IResource> exportResources = new ArrayList<IResource>(); clearTarget(project);/*from w ww. j a va 2 s.c om*/ IFile pomFile = project.getFile(POM_FILE); if (pomFile.exists()) { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plugin : plugins) { if (plugin.getArtifactId().equals(ARTIFACT_ID) && plugin.getGroupId().equals(GROUP_ID)) { Xpp3Dom[] artifactNodes = ((Xpp3Dom) plugin.getConfiguration()).getChildren(ARTIFACT_TAG); for (Xpp3Dom artifactNode : artifactNodes) { String dbsFile = artifactNode.getValue(); String[] pathArray = dbsFile.split("/"); IFile dbsFileRef = project .getFolder(DataServiceProjectConstants.DS_PROJECT_DATASERVICE_FOLDER) .getFile(pathArray[pathArray.length - 1]); if (dbsFileRef.exists()) { exportResources.add((IResource) dbsFileRef); } } } } } else { File[] dbsFiles = FileUtils.getAllMatchingFiles(project.getLocation().toString(), null, DBS_FILE_EXTENSION, new ArrayList<File>()); for (File dbsFile : dbsFiles) { String filePath = dbsFile.toString(); // excluded any files inside target dir if (!filePath.substring(projectPath.length()) .startsWith(File.separator + TARGET + File.separator)) { IFile dbsFileRef = ResourcesPlugin.getWorkspace().getRoot() .getFileForLocation(Path.fromOSString(dbsFile.getAbsolutePath())); exportResources.add((IResource) dbsFileRef); } } } return exportResources; }
From source file:org.wso2.developerstudio.eclipse.artifact.dataserviceProject.ui.wizard.DataServiceProjectCreationWizard.java
License:Open Source License
/** * Updates the pom file/*from ww w . ja v a 2 s. c om*/ * * @param openFile * current .dbs file * @throws Exception */ public void updatePom(File mavenProjectPomLocation) throws Exception { try { MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation); // Adding typrLidt property MavenUtils.updateMavenProjectWithCAppType(mavenProject, CAPP_TYPE); // Setting the directory mavenProject.getBuild().setDirectory("target/capp"); // Adding maven test skip property MavenUtils.updateMavenProjectWithSkipTests(mavenProject); // Adding maven exec plugin entry Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.codehaus.mojo", "exec-maven-plugin", "1.4.0", true); { PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId(MavenConstants.PACKAGE_PHASE); pluginExecution.addGoal(MavenConstants.EXEC_GOAL); pluginExecution.setPhase(MavenConstants.PACKAGE_PHASE); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.EXECUTABLE_TAG); executableNode.setValue(MavenConstants.EXECUTABLE_VALUE); Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.WORKING_DIRECTORY_TAG); workingDirectoryNode.setValue(MavenConstants.WORKING_DIRECTORY_VALUE); Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.ARGUMENTS_TAG); Xpp3Dom cleanArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); cleanArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_CLEAN); Xpp3Dom installArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); installArgumentNode.setValue(MavenConstants.PACKAGE_PHASE); Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); testSkipArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_SKIP_TESTS); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); } { PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId(MavenConstants.INSTALL_PHASE); pluginExecution.addGoal(MavenConstants.EXEC_GOAL); pluginExecution.setPhase(MavenConstants.INSTALL_PHASE); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.EXECUTABLE_TAG); executableNode.setValue(MavenConstants.EXECUTABLE_VALUE); Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.WORKING_DIRECTORY_TAG); workingDirectoryNode.setValue(MavenConstants.WORKING_DIRECTORY_VALUE); Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.ARGUMENTS_TAG); Xpp3Dom cleanArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); cleanArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_CLEAN); Xpp3Dom installArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); installArgumentNode.setValue(MavenConstants.INSTALL_PHASE); Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); testSkipArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_SKIP_TESTS); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); } { PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId(MavenConstants.DEPLOY_PHASE); pluginExecution.addGoal(MavenConstants.EXEC_GOAL); pluginExecution.setPhase(MavenConstants.DEPLOY_PHASE); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.EXECUTABLE_TAG); executableNode.setValue(MavenConstants.EXECUTABLE_VALUE); Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.WORKING_DIRECTORY_TAG); workingDirectoryNode.setValue(MavenConstants.WORKING_DIRECTORY_VALUE); Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.ARGUMENTS_TAG); Xpp3Dom deployArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); deployArgumentNode.setValue(MavenConstants.DEPLOY_PHASE); Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); testSkipArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_SKIP_TESTS); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); } MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation); } catch (Exception e) { // TODO Handle this properly. e.printStackTrace(); } try { project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } catch (CoreException e) { // TODO Handle this properly. e.printStackTrace(); } }
From source file:org.wso2.developerstudio.eclipse.artifact.datasource.project.export.DataSourceArtfactExportHandler.java
License:Open Source License
public List<IResource> exportArtifact(IProject project) throws Exception { String projectPath = project.getLocation().toFile().toString(); List<IResource> exportResources = new ArrayList<IResource>(); clearTarget(project);/* ww w. ja v a 2s . c om*/ IFile pomFile = project.getFile(POM_FILE); IFile artifactXMLFile = project.getFile(ARTIFACT_XML); if (artifactXMLFile.exists()) { if (pomFile.exists()) { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plugin : plugins) { if (plugin.getArtifactId().equals(ARTIFACT_ID) && plugin.getGroupId().equals(GROUP_ID)) { Xpp3Dom[] artifactNodes = ((Xpp3Dom) plugin.getConfiguration()).getChildren(ARTIFACT_TAG); for (Xpp3Dom artifactNode : artifactNodes) { String xmlFile = artifactNode.getValue(); String[] pathArray = xmlFile.split("/"); IFile dbsFileRef = project .getFolder(DataSourceArtifactConstants.DS_PROJECT_DATASERVICE_FOLDER) .getFile(pathArray[pathArray.length - 1]); if (dbsFileRef.exists()) { exportResources.add((IResource) dbsFileRef); } } } } } else { File[] xmlFiles = FileUtils.getAllMatchingFiles(project.getLocation().toString(), null, DATASOURCE_FILE_EXTENSION, new ArrayList<File>()); for (File xmlFile : xmlFiles) { String filePath = xmlFile.toString(); // excluded any files inside target dir if (!filePath.substring(projectPath.length()) .startsWith(File.separator + TARGET + File.separator)) { IFile datasourceFileRef = ResourcesPlugin.getWorkspace().getRoot() .getFileForLocation(Path.fromOSString(xmlFile.getAbsolutePath())); exportResources.add((IResource) datasourceFileRef); } } } } else { if (pomFile.exists()) { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plugin : plugins) { if (plugin.getArtifactId().equals(ARTIFACT_ID) && plugin.getGroupId().equals(GROUP_ID)) { Xpp3Dom artifactNode = ((Xpp3Dom) plugin.getConfiguration()).getChild(ARTIFACT_TAG); String dbsFile = artifactNode.getValue(); String[] pathArray = dbsFile.split("/"); IFile datasourceFileRef = project.getFolder("src").getFolder("main").getFolder("datasource") .getFile(pathArray[pathArray.length - 1]); if (datasourceFileRef.exists()) { exportResources.add((IResource) datasourceFileRef); } } } } else { File[] dbsFiles = FileUtils.getAllMatchingFiles(project.getLocation().toString(), null, DATASOURCE_FILE_EXTENSION, new ArrayList<File>()); for (File xmlFile : dbsFiles) { String filePath = xmlFile.toString(); // excluded any files inside target dir if (!filePath.substring(projectPath.length()) .startsWith(File.separator + "target" + File.separator)) { IFile datasourceFileRef = ResourcesPlugin.getWorkspace().getRoot() .getFileForLocation(Path.fromOSString(xmlFile.getAbsolutePath())); exportResources.add((IResource) datasourceFileRef); } } } } return exportResources; }
From source file:org.wso2.developerstudio.eclipse.artifact.datasourceProject.project.export.DataSourceArtfactExportHandler.java
License:Open Source License
public List<IResource> exportArtifact(IProject project) throws Exception { String projectPath = project.getLocation().toFile().toString(); List<IResource> exportResources = new ArrayList<IResource>(); clearTarget(project);/* w ww . j a v a 2s .c o m*/ IFile pomFile = project.getFile(POM_FILE); if (pomFile.exists()) { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plugin : plugins) { if (plugin.getArtifactId().equals(ARTIFACT_ID) && plugin.getGroupId().equals(GROUP_ID)) { Xpp3Dom[] artifactNodes = ((Xpp3Dom) plugin.getConfiguration()).getChildren(ARTIFACT_TAG); for (Xpp3Dom artifactNode : artifactNodes) { String dbsFile = artifactNode.getValue(); String[] pathArray = dbsFile.split("/"); IFile dbsFileRef = project .getFolder(DataSourceProjectConstants.DS_PROJECT_DATASERVICE_FOLDER) .getFile(pathArray[pathArray.length - 1]); if (dbsFileRef.exists()) { exportResources.add((IResource) dbsFileRef); } } } } } else { File[] dbsFiles = FileUtils.getAllMatchingFiles(project.getLocation().toString(), null, XML_FILE_EXTENSION, new ArrayList<File>()); for (File dbsFile : dbsFiles) { String filePath = dbsFile.toString(); // excluded any files inside target dir if (!filePath.substring(projectPath.length()) .startsWith(File.separator + TARGET + File.separator)) { IFile dbsFileRef = ResourcesPlugin.getWorkspace().getRoot() .getFileForLocation(Path.fromOSString(dbsFile.getAbsolutePath())); exportResources.add((IResource) dbsFileRef); } } } return exportResources; }
From source file:org.wso2.developerstudio.eclipse.artifact.datasourceProject.ui.wizard.DataSourceProjectCreationWizard.java
License:Open Source License
/** * Updates the pom file/* w w w . j a va2 s.c o m*/ * * @param openFile * current .dbs file * @throws Exception */ public void updatePom(File mavenProjectPomLocation) throws Exception { try { MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation); // Adding typrLidt property MavenUtils.updateMavenProjectWithCAppType(mavenProject, CAPP_TYPE); // Setting the directory mavenProject.getBuild().setDirectory("target/capp"); // Adding maven test skip property MavenUtils.updateMavenProjectWithSkipTests(mavenProject); // Adding maven exec plugin entry Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.codehaus.mojo", "exec-maven-plugin", "1.4.0", true); { PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId(MavenConstants.PACKAGE_PHASE); pluginExecution.addGoal(MavenConstants.EXEC_GOAL); pluginExecution.setPhase(MavenConstants.PACKAGE_PHASE); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.EXECUTABLE_TAG); executableNode.setValue(MavenConstants.EXECUTABLE_VALUE); Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.WORKING_DIRECTORY_TAG); workingDirectoryNode.setValue(MavenConstants.WORKING_DIRECTORY_VALUE); Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.ARGUMENTS_TAG); Xpp3Dom cleanArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); cleanArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_CLEAN); Xpp3Dom installArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); installArgumentNode.setValue(MavenConstants.PACKAGE_PHASE); Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); testSkipArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_SKIP_TESTS); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); } { PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId(MavenConstants.INSTALL_PHASE); pluginExecution.addGoal(MavenConstants.EXEC_GOAL); pluginExecution.setPhase(MavenConstants.INSTALL_PHASE); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.EXECUTABLE_TAG); executableNode.setValue(MavenConstants.EXECUTABLE_VALUE); Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.WORKING_DIRECTORY_TAG); workingDirectoryNode.setValue(MavenConstants.WORKING_DIRECTORY_VALUE); Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.ARGUMENTS_TAG); Xpp3Dom cleanArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); cleanArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_CLEAN); Xpp3Dom installArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); installArgumentNode.setValue(MavenConstants.INSTALL_PHASE); Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); testSkipArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_SKIP_TESTS); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); } { PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setId(MavenConstants.DEPLOY_PHASE); pluginExecution.addGoal(MavenConstants.EXEC_GOAL); pluginExecution.setPhase(MavenConstants.DEPLOY_PHASE); Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode(); Xpp3Dom executableNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.EXECUTABLE_TAG); executableNode.setValue(MavenConstants.EXECUTABLE_VALUE); Xpp3Dom workingDirectoryNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.WORKING_DIRECTORY_TAG); workingDirectoryNode.setValue(MavenConstants.WORKING_DIRECTORY_VALUE); Xpp3Dom argumentsNode = MavenUtils.createXpp3Node(configurationNode, MavenConstants.ARGUMENTS_TAG); Xpp3Dom deployArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); deployArgumentNode.setValue(MavenConstants.DEPLOY_PHASE); Xpp3Dom testSkipArgumentNode = MavenUtils.createXpp3Node(argumentsNode, MavenConstants.ARGUMENT_TAG); testSkipArgumentNode.setValue(MavenConstants.ARGUMENT_VALUE_SKIP_TESTS); pluginExecution.setConfiguration(configurationNode); plugin.addExecution(pluginExecution); } MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation); } catch (Exception e) { log.error(DataSourceProjectConstants.ERROR_MESSAGE_UNEXPECTED_ERROR, e); } try { project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } catch (CoreException e) { log.error(DataSourceProjectConstants.ERROR_MESSAGE_CORE_EXCEPTION, e); } }