Example usage for org.apache.maven.project MavenProject getVersion

List of usage examples for org.apache.maven.project MavenProject getVersion

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getVersion.

Prototype

public String getVersion() 

Source Link

Usage

From source file:org.wso2.developerstudio.eclipse.artifact.analytics.execution.plan.ui.wizard.ExecutionPlanProjectCreationWizard.java

License:Open Source License

public String getProjectVersion(File pomLocation) {
    String version = "1.0.0";
    if (pomLocation != null && pomLocation.exists()) {
        try {//from  w w  w.  j  av  a  2s .  c o m
            MavenProject mavenProject = MavenUtils.getMavenProject(pomLocation);
            version = mavenProject.getVersion();
        } catch (Exception e) {
            log.error("error reading pom file", e);
        }
    }
    return version;
}

From source file:org.wso2.developerstudio.eclipse.artifact.analytics.publisher.refactor.RefactorUtils.java

License:Open Source License

public static Dependency getDependencyForTheProject(IFile file) {
    IProject project = file.getProject();
    MavenProject mavenProject = getMavenProject(project);

    String groupId = mavenProject.getGroupId();
    String artifactId = mavenProject.getArtifactId();
    String version = mavenProject.getVersion();

    String filePath = file.getLocation().toOSString();
    int startIndex = (project.getLocation().toOSString() + File.separator + "src" + File.separator + "main"
            + File.separator).length();
    int endIndex = filePath.lastIndexOf(File.separator);

    String typeString;//from  w  w w .  j  av a 2  s  .  co m

    String typeStringFromPath = filePath.substring(startIndex, endIndex);
    if (typeStringFromPath.equalsIgnoreCase(AnalyticsConstants.ANALYTICS_EXECUTION_PLAN_DIR)) {
        typeString = AnalyticsConstants.ANALYTICS_EXECUTION_PLAN_DIR;
    } else if (typeStringFromPath.equalsIgnoreCase(AnalyticsConstants.ANALYTICS_PUBLISHER_DIR)) {
        typeString = AnalyticsConstants.ANALYTICS_PUBLISHER_DIR;
    } else if (typeStringFromPath.equalsIgnoreCase(AnalyticsConstants.ANALYTICS_RECEIVER_DIR)) {
        typeString = AnalyticsConstants.ANALYTICS_RECEIVER_DIR;
    } else {
        typeString = AnalyticsConstants.ANALYTICS_STREAM_DIR;
    }
    Dependency dependency = new Dependency();
    dependency.setGroupId(groupId + "." + typeString);
    dependency.setArtifactId(artifactId);
    dependency.setVersion(version);

    return dependency;
}

From source file:org.wso2.developerstudio.eclipse.artifact.endpoint.refactor.RefactorUtils.java

License:Open Source License

public static Dependency getDependencyForTheProject(IFile file) {
    IProject project = file.getProject();
    MavenProject mavenProject = getMavenProject(project);

    String groupId = mavenProject.getGroupId();
    String artifactId = mavenProject.getArtifactId();
    String version = mavenProject.getVersion();

    String filePath = file.getLocation().toOSString();
    int startIndex = (project.getLocation().toOSString() + File.separator + "src" + File.separator + "main"
            + File.separator + "synapse-config" + File.separator).length();
    int endIndex = filePath.lastIndexOf(File.separator);

    String typeString;// ww  w  .ja  va2s  .co m
    if (startIndex < endIndex) {
        String typeStringFromPath = filePath.substring(startIndex, endIndex);
        if (typeStringFromPath.equalsIgnoreCase("sequences")) {
            typeString = "sequence";
        } else if (typeStringFromPath.equalsIgnoreCase("endpoints")) {
            typeString = "endpoint";
        } else if (typeStringFromPath.equalsIgnoreCase("proxy-services")) {
            typeString = "proxy-service";
        } else {
            typeString = "local-entry";
        }

    } else {
        typeString = "synapse";
    }

    Dependency dependency = new Dependency();
    dependency.setGroupId(groupId + "." + typeString);
    dependency.setArtifactId(artifactId);
    dependency.setVersion(version);

    return dependency;
}

From source file:org.wso2.developerstudio.eclipse.artifact.library.ui.wizard.LibraryArtifactCreationWizard.java

License:Open Source License

public static List<String> fillDependencyList(IProject project, LibraryArtifactModel libraryModel,
        List<Dependency> dependencyList) throws JavaModelException, Exception, CoreException, IOException {

    IFile bundlesDataFile = project.getFile("bundles-data.xml");
    List<String> exportedPackages = new ArrayList<String>();

    BundlesDataInfo bundleData = new BundlesDataInfo();
    if (libraryModel.isFragmentHostBundle()) {
        bundleData.setFragmentHost(libraryModel.getFragmentHostBundleName());
    }//from  ww  w  .  j a v  a  2  s  .c o m

    List<IProject> projects = new ArrayList<IProject>();
    for (Object resource : libraryModel.getLibraries()) {
        File libraryResource = null;
        if (resource instanceof File) {
            libraryResource = (File) resource;
        } else if (resource instanceof IFile) {
            libraryResource = new File(((IFile) resource).getLocation().toOSString());
        } else if (resource instanceof IProject) {
            IProject workSpacePrj = (IProject) resource;
            projects.add(workSpacePrj);
            handleWorkspaceProjectResource(workSpacePrj);
        }
        if (libraryResource != null) {
            String dest = new File(project.getLocation().toFile(), libraryResource.getName()).toString();
            if (!libraryResource.toString().equals(dest)) {
                FileUtils.copyFile(libraryResource.toString(), dest);
            }
        }
    }
    project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

    File[] jarsList = project.getLocation().toFile().listFiles(new FilenameFilter() {

        public boolean accept(File file, String name) {
            return name.endsWith(".jar");
        }
    });

    Map<File, ArrayList<String>> exportedPackagesInfoMap = FileUtils.processJarList(jarsList);

    for (File jarFile : exportedPackagesInfoMap.keySet()) {
        if (isExistsInLibraryModel(jarFile, libraryModel)) {

            Path base = new Path(project.getLocation().toFile().toString());

            ArrayList<String> packages = exportedPackagesInfoMap.get(jarFile);
            exportedPackages.addAll(packages);
            bundleData.createJarElement(jarFile.getName(), exportedPackagesInfoMap.get(jarFile));

            Dependency dependency = new Dependency();
            dependency.setArtifactId(jarFile.getName());
            dependency.setGroupId("dummy.groupid");
            dependency.setVersion("1.0.0");
            dependency.setScope("system");
            dependency.setSystemPath(
                    "${basedir}/" + jarFile.toString().substring(base.toFile().getPath().length() + 1));
            dependencyList.add(dependency);
        } else {
            try {
                jarFile.delete();
            } catch (Exception e) {
                log.warn("Failed to remove unused jar file(s)", e);
            }
        }
    }

    for (IProject prj : projects) {
        IFile pomFile = prj.getFile("pom.xml");
        if (pomFile.exists()) {
            try {
                MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile());
                Dependency dependency = new Dependency();
                dependency.setArtifactId(mavenProject.getArtifactId());
                dependency.setGroupId(mavenProject.getGroupId());
                dependency.setVersion(mavenProject.getVersion());
                dependencyList.add(dependency);
            } catch (Exception e) {
                log.warn("Error reading " + pomFile, e);
            }
        }
        bundleData.createProjectElement(prj, new ArrayList<String>());
        IJavaProject javaProject = JavaCore.create(prj);
        for (IPackageFragment pkg : javaProject.getPackageFragments()) {
            if (pkg.getKind() == IPackageFragmentRoot.K_SOURCE) {
                if (pkg.hasChildren()) {
                    exportedPackages.add(pkg.getElementName());
                }
            }
        }
    }

    bundleData.toFile(bundlesDataFile);
    project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    bundlesDataFile.setHidden(true);

    return exportedPackages;
}

From source file:org.wso2.developerstudio.eclipse.artifact.proxyservice.ui.wizard.ProxyServiceProjectCreationWizard.java

License:Open Source License

public void updatePom() throws IOException, XmlPullParserException {
    File mavenProjectPomLocation = esbProject.getFile("pom.xml").getLocation().toFile();
    MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
    String 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-proxy-plugin")) {
        return;/*from ww w .  j  a  v a  2  s.  co m*/
    }

    Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.wso2.maven", "wso2-esb-proxy-plugin",
            ESBMavenConstants.WSO2_ESB_PROXY_VERSION, true);
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.addGoal("pom-gen");
    pluginExecution.setPhase("process-resources");
    pluginExecution.setId("proxy");

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

From source file:org.wso2.developerstudio.eclipse.artifact.registry.handler.ui.wizard.RegistryHandlerCreationWizard.java

License:Open Source License

public void updatePom(IProject project, HandlerInfo handlerInfo) throws Exception {
    File mavenProjectPomLocation = project.getFile("pom.xml").getLocation().toFile();
    MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);

    Properties properties = mavenProject.getModel().getProperties();
    properties.put("CApp.type", "lib/registry/handlers");
    mavenProject.getModel().setProperties(properties);

    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 bundleActivatorNode = MavenUtils.createXpp3Node(instructionNode, "Bundle-Activator");
    Xpp3Dom exportPackageNode = MavenUtils.createXpp3Node(instructionNode, "Export-Package");
    Xpp3Dom dynamicImportNode = MavenUtils.createXpp3Node(instructionNode, "DynamicImport-Package");
    bundleSymbolicNameNode.setValue(project.getName());
    bundleNameNode.setValue(project.getName());
    bundleActivatorNode.setValue(BUNDLE_ACTIVATOR_NAME);
    exportPackageNode.setValue(getExportedPackage(handlerInfo));
    dynamicImportNode.setValue("*");
    configurationNode.addChild(instructionNode);

    Repository repo = new Repository();
    repo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/");
    repo.setId("wso2-maven2-repository-1");

    mavenProject.getModel().addRepository(repo);
    mavenProject.getModel().addPluginRepository(repo);

    List<Dependency> dependencyList = new ArrayList<Dependency>();

    Map<String, JavaLibraryBean> dependencyInfoMap = JavaLibraryUtil.getDependencyInfoMap(project);
    Map<String, String> map = ProjectDependencyConstants.DEPENDENCY_MAP;
    for (JavaLibraryBean bean : dependencyInfoMap.values()) {
        if (bean.getVersion().contains("${")) {
            for (String path : map.keySet()) {
                bean.setVersion(bean.getVersion().replace(path, map.get(path)));
            }/*from   ww  w . j  a  v a2s. c  o m*/
        }
        Dependency dependency = new Dependency();
        dependency.setArtifactId(bean.getArtifactId());
        dependency.setGroupId(bean.getGroupId());
        dependency.setVersion(bean.getVersion());
        dependencyList.add(dependency);
    }

    if (importHandlerFromWs && importHandlerProject != null) {
        try {
            IFile pomFile = importHandlerProject.getFile("pom.xml");
            MavenProject workspaceProject;
            if (pomFile.exists()) {
                workspaceProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile());
            } else {
                String srcDir = "src";
                workspaceProject = MavenUtils.createMavenProject(
                        "org.wso2.carbon." + importHandlerProject.getName(), importHandlerProject.getName(),
                        "1.0.0", "jar");
                IJavaProject javaProject = JavaCore.create(importHandlerProject);
                IClasspathEntry[] classpath = javaProject.getRawClasspath();
                int entryCount = 0;
                for (IClasspathEntry classpathEntry : classpath) {
                    if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                        if (entryCount == 0) {
                            String entryPath = "";
                            String[] pathSegments = classpathEntry.getPath().segments();
                            if (pathSegments.length > 1) {
                                for (int i = 1; i < pathSegments.length; i++) {
                                    if (i == 1) {
                                        entryPath = pathSegments[i];
                                    } else {
                                        entryPath += "/" + pathSegments[i];
                                    }
                                }
                                if (entryPath.length() > 0) {
                                    srcDir = entryPath;
                                    ++entryCount;
                                }
                            }
                        } else {
                            log.warn("multiple source directories found, Considering '" + srcDir
                                    + "' as source directory");
                            break;
                        }
                    }
                }
                if (entryCount == 0) {
                    log.warn("No source directory specified, using default source directory.");
                }
                workspaceProject.getBuild().setSourceDirectory(srcDir);

                Repository nexusRepo = new Repository();
                nexusRepo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/");
                nexusRepo.setId("wso2-maven2-repository-1");
                workspaceProject.getModel().addRepository(nexusRepo);
                workspaceProject.getModel().addPluginRepository(nexusRepo);

                List<Dependency> libList = new ArrayList<Dependency>();

                Map<String, JavaLibraryBean> dependencyMap = JavaLibraryUtil
                        .getDependencyInfoMap(importHandlerProject);

                for (JavaLibraryBean bean : dependencyMap.values()) {
                    Dependency dependency = new Dependency();
                    dependency.setArtifactId(bean.getArtifactId());
                    dependency.setGroupId(bean.getGroupId());
                    dependency.setVersion(bean.getVersion());
                    libList.add(dependency);
                }

                workspaceProject.setDependencies(libList);
                MavenUtils.saveMavenProject(workspaceProject, pomFile.getLocation().toFile());
                project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
            }

            Dependency dependency = new Dependency();
            dependency.setArtifactId(workspaceProject.getArtifactId());
            dependency.setGroupId(workspaceProject.getGroupId());
            dependency.setVersion(workspaceProject.getVersion());
            dependencyList.add(dependency);
        } catch (Exception e) {
            log.warn("Error reading or updating pom file.", e);
        }
    }

    MavenUtils.addMavenDependency(mavenProject, dependencyList);
    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);

}

From source file:org.wso2.developerstudio.eclipse.artifact.registry.ui.wizard.RegistryResourceCreationWizard.java

License:Open Source License

public boolean performFinish() {
    try {/*from   www  . ja va 2s.c  om*/
        File destFile = null;
        String templateContent = "";
        String template = "";
        RegistryArtifactModel regModel = (RegistryArtifactModel) getModel();
        IContainer resLocation = regModel.getResourceSaveLocation();
        IProject project = resLocation.getProject();
        //         File registryInfoFile = project.getFile(REGISTRY_INFO_FILE)
        //               .getLocation().toFile();
        RegistryResourceInfoDoc regResInfoDoc = new RegistryResourceInfoDoc();
        if (getModel().getSelectedOption().equals(RegistryArtifactConstants.OPTION_NEW_RESOURCE)) {

            RegistryTemplate selectedTemplate = regModel.getSelectedTemplate();
            templateContent = FileUtils.getContentAsString(selectedTemplate.getTemplateDataStream());
            template = createTemplate(templateContent, selectedTemplate.getId());

            resourceFile = resLocation
                    .getFile(new Path(regModel.getResourceName() + "." + selectedTemplate.getTemplateFileName()
                            .substring(selectedTemplate.getTemplateFileName().lastIndexOf(".") + 1)));
            destFile = resourceFile.getLocation().toFile();
            FileUtils.createFile(destFile, template);
            RegistryResourceUtils.createMetaDataForFolder(regModel.getCompleteRegistryPath(),
                    resLocation.getLocation().toFile());
            RegistryResourceUtils.addRegistryResourceInfo(destFile, regResInfoDoc,
                    project.getLocation().toFile(), regModel.getCompleteRegistryPath());

        } else if (getModel().getSelectedOption().equals(RegistryArtifactConstants.OPTION_IMPORT_RESOURCE)) {
            File importFile = getModel().getImportFile();
            if (importFile.isDirectory()) {
                if (regModel.getCopyContent()) {
                    FileUtils.copyDirectoryContents(importFile, resLocation.getLocation().toFile());
                    RegistryResourceUtils.createMetaDataForFolder(regModel.getCompleteRegistryPath(),
                            resLocation.getLocation().toFile());
                    File[] listFiles = importFile.listFiles();
                    for (File res : listFiles) {
                        File distFile = new File(resLocation.getLocation().toFile(), res.getName());
                        RegistryResourceUtils.addRegistryResourceInfo(distFile, regResInfoDoc,
                                project.getLocation().toFile(), regModel.getCompleteRegistryPath());
                    }
                } else {
                    File folder = new File(resLocation.getLocation().toFile(), importFile.getName());
                    //                  IFolder folder = resLocation.getProject().getFolder(getModel().getImportFile().getName());
                    FileUtils.copyDirectoryContents(importFile, folder);

                    RegistryResourceUtils.createMetaDataForFolder(regModel.getCompleteRegistryPath(), folder);
                    RegistryResourceUtils.addRegistryResourceInfo(folder, regResInfoDoc,
                            project.getLocation().toFile(), regModel.getCompleteRegistryPath());
                }
            } else {
                resourceFile = resLocation.getFile(new Path(importFile.getName()));
                destFile = resourceFile.getLocation().toFile();
                FileUtils.copy(importFile, destFile);
                RegistryResourceUtils.createMetaDataForFolder(regModel.getCompleteRegistryPath(),
                        destFile.getParentFile());
                RegistryResourceUtils.addRegistryResourceInfo(destFile, regResInfoDoc,
                        project.getLocation().toFile(), regModel.getCompleteRegistryPath());
            }

        } else if (getModel().getSelectedOption().equals(RegistryArtifactConstants.OPTION_IMPORT_DUMP)) {
            File importFile = getModel().getImportFile();
            resourceFile = resLocation.getFile(new Path(importFile.getName()));
            destFile = resourceFile.getLocation().toFile();
            FileUtils.copy(importFile, destFile);
            //RegistryResourceUtils.createMetaDataForFolder(regModel.getRegistryPath(), destFile.getParentFile());
            RegistryResourceUtils.addRegistryResourceInfo(destFile, regResInfoDoc,
                    project.getLocation().toFile(), regModel.getCompleteRegistryPath(),
                    RegistryArtifactConstants.REGISTRY_DUMP);
        } else if (getModel().getSelectedOption().equals(RegistryArtifactConstants.OPTION_CHECKOUT_PATH)) {
            RegistryResourceNode checkoutPath = regModel.getCheckoutPath();
            RegistryNode connectionInfo = checkoutPath.getConnectionInfo();
            String registryResourcePath = checkoutPath.getRegistryResourcePath();
            String resourceName = !checkoutPath.getCaption().equals("/") ? checkoutPath.getCaption() : "root";
            resourceFile = resLocation.getFile(new Path(resourceName));
            destFile = resourceFile.getLocation().toFile();
            regModel.setResourceName(resourceName);
            if (checkoutPath.getResourceType() == RegistryResourceType.COLLECTION) {
                RegistryCheckInClientUtils.checkout(connectionInfo.getUsername(), connectionInfo.getPassword(),
                        destFile.toString(), connectionInfo.getUrl().toString().concat("/"),
                        registryResourcePath);
                RegistryResourceUtils.addRegistryResourceInfo(destFile, regResInfoDoc,
                        project.getLocation().toFile(), regModel.getCompleteRegistryPath());
            } else {
                RegistryCheckInClientUtils.download(connectionInfo.getUsername(), connectionInfo.getPassword(),
                        destFile.toString(), connectionInfo.getUrl().toString().concat("/"),
                        registryResourcePath);
                RegistryResourceUtils.addRegistryResourceInfo(destFile, regResInfoDoc,
                        project.getLocation().toFile(), regModel.getCompleteRegistryPath());
            }

        }

        //STOPPed serializing the reg-info.xml file to avoid generating the file but keep the process since we need to entries in the reg-info.xml file
        //         regResInfoDoc.toFile(registryInfoFile);
        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        getModel().getMavenInfo().setPackageName("registry/resource");
        updatePOM(project);
        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        File pomLocation = project.getFile("pom.xml").getLocation().toFile();
        String groupId = getMavenGroupId(pomLocation);
        groupId += ".resource";
        MavenProject mavenProject = MavenUtils.getMavenProject(pomLocation);
        String version = mavenProject.getVersion();
        //Adding the metadata about the endpoint to the metadata store.
        GeneralProjectArtifact generalProjectArtifact = new GeneralProjectArtifact();
        generalProjectArtifact.fromFile(project.getFile("artifact.xml").getLocation().toFile());

        RegistryArtifact artifact = new RegistryArtifact();
        artifact.setName(regModel.getArtifactName());
        artifact.setVersion(version);
        artifact.setType("registry/resource");
        artifact.setServerRole("GovernanceRegistry");
        artifact.setGroupId(groupId);
        List<RegistryResourceInfo> registryResources = regResInfoDoc.getRegistryResources();
        for (RegistryResourceInfo registryResourceInfo : registryResources) {
            RegistryElement item = null;
            // item.setFile("resources"+File.separator+registryResourceInfo.getResourceBaseRelativePath());
            if (registryResourceInfo.getType() == RegistryArtifactConstants.REGISTRY_RESOURCE) {
                item = new RegistryItem();
                ((RegistryItem) item).setFile(registryResourceInfo.getResourceBaseRelativePath()
                        .replaceAll(Pattern.quote(File.separator), "/"));
                ((RegistryItem) item).setMediaType(registryResourceInfo.getMediaType());
            } else if (registryResourceInfo.getType() == RegistryArtifactConstants.REGISTRY_COLLECTION) {
                item = new RegistryCollection();
                ((RegistryCollection) item).setDirectory(registryResourceInfo.getResourceBaseRelativePath()
                        .replaceAll(Pattern.quote(File.separator), "/"));
            } else if (registryResourceInfo.getType() == RegistryArtifactConstants.REGISTRY_DUMP) {
                item = new RegistryDump();
                ((RegistryDump) item).setFile(registryResourceInfo.getResourceBaseRelativePath()
                        .replaceAll(Pattern.quote(File.separator), "/"));
            }
            if (item != null) {
                item.setPath(registryResourceInfo.getDeployPath().replaceAll("/$", ""));
                artifact.addRegistryElement(item);
            }
        }

        generalProjectArtifact.addArtifact(artifact);

        generalProjectArtifact.toFile();
        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        openEditor(project);

    } catch (Exception e) {
        log.error("cannot create resource ", e);
    }
    return true;
}

From source file:org.wso2.developerstudio.eclipse.artifact.sequence.ui.wizard.SequenceProjectCreationWizard.java

License:Open Source License

public void updatePom() throws IOException, XmlPullParserException {
    File mavenProjectPomLocation = project.getFile("pom.xml").getLocation().toFile();
    MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
    String 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-sequence-plugin")) {
        return;/* w  ww  .j  a  v  a  2 s  .c o m*/
    }

    Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.wso2.maven", "wso2-esb-sequence-plugin",
            ESBMavenConstants.WSO2_ESB_SEQUENCE_VERSION, true);
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.addGoal("pom-gen");
    pluginExecution.setPhase("process-resources");
    pluginExecution.setId("sequence");

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

From source file:org.wso2.developerstudio.eclipse.artifact.sequence.ui.wizard.SequenceProjectCreationWizard.java

License:Open Source License

public void createDynamicSequenceArtifact(IContainer location, SequenceModel sequenceModel) throws Exception {

    addGeneralProjectPlugin(project);//from   w  w  w  .  j  a  v a 2  s  . co m
    File pomLocation = project.getFile("pom.xml").getLocation().toFile();
    String groupId = getMavenGroupId(pomLocation) + ".resource";
    MavenProject mavenProject = MavenUtils.getMavenProject(pomLocation);
    String version = mavenProject.getVersion();

    String registryPath = sequenceModel.getDynamicSeqRegistryPath().replaceAll("^conf:", "/_system/config")
            .replaceAll("^gov:", "/_system/governance").replaceAll("^local:", "/_system/local");

    if (sequenceModel.getRegistryPathID().equals(CONF_REG_ID)) {
        if (!registryPath.startsWith("/_system/config")) {
            registryPath = "/_system/config/".concat(registryPath);
        }
    } else if (sequenceModel.getRegistryPathID().equals(GOV_REG_ID)) {
        if (!registryPath.startsWith("/_system/governance")) {
            registryPath = "/_system/governance/".concat(registryPath);
        }
    }

    RegistryResourceInfoDoc regResInfoDoc = new RegistryResourceInfoDoc();

    ArtifactTemplate selectedTemplate = ArtifactTemplateHandler
            .getArtifactTemplates("org.wso2.developerstudio.eclipse.esb.sequence");
    String templateContent = FileUtils.getContentAsString(selectedTemplate.getTemplateDataStream());
    String content = createSequenceTemplate(templateContent);
    File destFile = location.getFile(new Path(sequenceModel.getSequenceName() + ".xml")).getLocation().toFile();
    FileUtils.createFile(destFile, content);
    fileLst.add(destFile);
    RegistryResourceUtils.createMetaDataForFolder(registryPath, location.getLocation().toFile());
    RegistryResourceUtils.addRegistryResourceInfo(destFile, regResInfoDoc, project.getLocation().toFile(),
            registryPath);

    GeneralProjectArtifact generalProjectArtifact = new GeneralProjectArtifact();
    generalProjectArtifact.fromFile(project.getFile("artifact.xml").getLocation().toFile());

    RegistryArtifact artifact = new RegistryArtifact();
    artifact.setName(sequenceModel.getSequenceName());
    artifact.setVersion(version);
    artifact.setType("registry/resource");
    artifact.setServerRole("EnterpriseServiceBus");
    artifact.setGroupId(groupId);
    List<RegistryResourceInfo> registryResources = regResInfoDoc.getRegistryResources();
    for (RegistryResourceInfo registryResourceInfo : registryResources) {
        RegistryElement item = null;
        if (registryResourceInfo.getType() == REGISTRY_RESOURCE) {
            item = new RegistryItem();
            ((RegistryItem) item).setFile(registryResourceInfo.getResourceBaseRelativePath());
            ((RegistryItem) item).setMediaType(registryResourceInfo.getMediaType());
        }
        item.setPath(registryResourceInfo.getDeployPath().replaceAll("/$", ""));
        artifact.addRegistryElement(item);
    }
    generalProjectArtifact.addArtifact(artifact);
    generalProjectArtifact.toFile();
}

From source file:org.wso2.developerstudio.eclipse.artifact.synapse.api.ui.wizard.SynapseAPICreationWizard.java

License:Open Source License

public void updatePom() throws IOException, XmlPullParserException {
    File mavenProjectPomLocation = esbProject.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-api-plugin")) {
        return;/*from   w ww  . j a  v a  2  s  .  co m*/
    }

    Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.wso2.maven", "wso2-esb-api-plugin",
            ESBMavenConstants.WSO2_ESB_API_VERSION, true);
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.addGoal("pom-gen");
    pluginExecution.setPhase("process-resources");
    pluginExecution.setId("api");

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