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

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

Introduction

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

Prototype

public String getGroupId() 

Source Link

Usage

From source file:org.wso2.developerstudio.eclipse.distribution.project.export.CappArtifactsListProvider.java

License:Open Source License

public List<ListData> getArtifactsListForSingleArtifactProject(IProject project) throws Exception {
    MavenProject mavenProject = DistProjectUtils.getMavenProject(project);
    ArtifactTypeMapping artifactTypeMapping = new ArtifactTypeMapping();
    List<ListData> singleProjectArtifactAsAList = new ArrayList<ListData>();
    Dependency dependency = new Dependency();
    dependency.setArtifactId(mavenProject.getArtifactId());
    dependency.setGroupId(mavenProject.getGroupId());
    dependency.setVersion(mavenProject.getVersion());
    String cAppType = mavenProject.getModel().getPackaging();
    if (cAppType == null || !artifactTypeMapping.isValidArtifactType(cAppType)) {
        if (mavenProject.getModel().getProperties().containsKey("CApp.type")) {
            cAppType = (String) mavenProject.getModel().getProperties().get("CApp.type");
        }//from w w  w.  j a  va2 s. c om
    }

    dependency.setType(artifactTypeMapping.getType(cAppType));
    ServerRoleMapping serverRoleMapping = new ServerRoleMapping();
    String serverRole = serverRoleMapping.getServerRole(cAppType);

    DependencyData dependencyData = new DependencyData();
    dependencyData.setDependency(dependency);
    dependencyData.setSelf(project);
    dependencyData.setCApptype(cAppType);
    dependencyData.setServerRole(getServerRole(serverRole));

    singleProjectArtifactAsAList
            .add(createListData(DistProjectUtils.getArtifactInfoAsString(dependency), dependencyData));
    return singleProjectArtifactAsAList;
}

From source file:org.wso2.developerstudio.eclipse.distribution.project.export.CappArtifactsListProvider.java

License:Open Source License

private ListData getListDataForArtifact(IProject project, MavenProject mavenProject, GeneralArtifact artifact) {

    ListData artifactListData;//w w w. j av a  2s. c om
    ArtifactTypeMapping artifactTypeMapping = new ArtifactTypeMapping();
    Dependency dependency = new Dependency();
    dependency.setArtifactId(artifact.getName());
    if (artifact.getGroupId() != null && !artifact.getGroupId().trim().isEmpty()) {
        dependency.setGroupId(artifact.getGroupId());
    } else {
        dependency.setGroupId(mavenProject.getGroupId());
    }
    dependency.setVersion(artifact.getVersion());
    dependency.setType(artifactTypeMapping.getType(artifact.getType()));

    // Following artifact types should be changed to common template
    // artifact type
    String artifactType;
    if ((Constants.SEQUENCE_TEMPLATE_TYPE.equals(artifact.getType()))
            || (Constants.ENDPOINT_TEMPLATE_TYPE.equals(artifact.getType()))) {
        artifactType = Constants.COMMON_TEMPLATE_TYPE;
    } else {
        artifactType = artifact.getType();
    }

    DependencyData dependencyData = new DependencyData();
    dependencyData.setDependency(dependency);
    dependencyData.setParent(project);
    dependencyData.setSelf(artifact.getFile());
    dependencyData.setCApptype(artifactType);
    dependencyData.setServerRole(Constants.CAPP_PREFIX + artifact.getServerRole());
    artifactListData = createListData(DistProjectUtils.getArtifactInfoAsString(dependency, project.getName()),
            dependencyData);

    return artifactListData;
}

From source file:org.wso2.developerstudio.eclipse.distribution.project.validator.ProjectList.java

License:Open Source License

public List<ListData> getListData(String modelProperty, ProjectDataModel model) {
    List<ListData> list = new ArrayList<ListData>();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    IProject[] projects = root.getProjects();
    for (IProject project : projects) {
        try {//from  w  w w  .ja v a  2 s.  c o m
            if (project.isOpen()) {
                if (project.hasNature(Constants.AXIS2_PROJECT_NATURE)
                        || project.hasNature(Constants.BPEL_PROJECT_NATURE)
                        || project.hasNature(Constants.DS_PROJECT_NATURE)
                        || project.hasNature(Constants.DS_VALIDATOR_PROJECT_NATURE)
                        || project.hasNature(Constants.ESB_PROJECT_NATURE)
                        || project.hasNature(Constants.JAXWS_PROJECT_NATURE)
                        || project.hasNature(Constants.JAXRS_PROJECT_NATURE)
                        || project.hasNature(Constants.WEBAPP_PROJECT_NATURE)
                        || project.hasNature(Constants.GADGET_PROJECT_NATURE)
                        || project.hasNature(Constants.LIBRARY_PROJECT_NATURE)
                        || project.hasNature(Constants.MEDIATOR_PROJECT_NATURE)
                        || project.hasNature(Constants.REGISTRY_FILTER_PROJECT_NATURE)
                        || project.hasNature(Constants.REGISTRY_HANDLER_PROJECT_NATURE)
                        || project.hasNature(Constants.GENERAL_PROJECT_NATURE)
                        || project.hasNature(Constants.CARBON_UI_PROJECT_NATURE)
                        || project.hasNature(Constants.CEP_PROJECT_NATURE)
                        || project.hasNature(Constants.BRS_PROJECT_NATURE)
                        || project.hasNature(Constants.JAGGERY_NATURE)
                        || project.hasNature(Constants.SERVICE_META_PROJECT_NATURE)) {
                    try {
                        if (project.hasNature(Constants.ESB_PROJECT_NATURE)
                                || project.hasNature(Constants.GENERAL_PROJECT_NATURE)) {
                            IFile artifactXMLFile = project.getFile(Constants.ARTIFACT_XML);

                            MavenProject mavenProject = DistProjectUtils.getMavenProject(project);

                            if (artifactXMLFile.exists()) {
                                ESBProjectArtifact artifactXMLDoc = new ESBProjectArtifact();
                                try {
                                    artifactXMLDoc.fromFile(artifactXMLFile.getLocation().toFile());
                                    List<ESBArtifact> artifacts = artifactXMLDoc.getAllESBArtifacts();
                                    for (ESBArtifact artifact : artifacts) {
                                        Dependency dependency = new Dependency();
                                        dependency.setArtifactId(artifact.getName());
                                        if (artifact.getGroupId() != null
                                                && !artifact.getGroupId().trim().isEmpty()) {
                                            dependency.setGroupId(artifact.getGroupId());
                                        } else {
                                            dependency.setGroupId(mavenProject.getGroupId());
                                        }
                                        dependency.setVersion(artifact.getVersion());
                                        // dependency.setVersion(mavenProject.getModel().getVersion()); //referring parent version
                                        dependency.setType(ArtifactTypeMapping.getType(artifact.getType()));
                                        dependency.setScope(Artifact.SCOPE_SYSTEM);

                                        // Following artifact types should
                                        // be changed to common template
                                        // artifact type
                                        String artifactType;
                                        if ((Constants.SEQUENCE_TEMPLATE_TYPE.equals(artifact.getType()))
                                                || (Constants.ENDPOINT_TEMPLATE_TYPE
                                                        .equals(artifact.getType()))) {
                                            artifactType = Constants.COMMON_TEMPLATE_TYPE;
                                        } else {
                                            artifactType = artifact.getType();
                                        }

                                        // Target path for capp artifacts
                                        StringBuilder systemPathBuilder = new StringBuilder();
                                        systemPathBuilder.append(project.getLocation().toString());
                                        systemPathBuilder.append(File.separator);
                                        systemPathBuilder.append(Constants.ESB_PROJECT_TARGET_CAPP);
                                        String outputDirPath = systemPathBuilder.toString();

                                        // Post fix defines the target path
                                        String artifactPostFix = getArtifactPostFix(artifactType);

                                        // Generate system path for the
                                        // dependency
                                        systemPathBuilder = new StringBuilder();
                                        systemPathBuilder.append(outputDirPath);
                                        systemPathBuilder.append(File.separator);
                                        systemPathBuilder.append(artifactPostFix);
                                        systemPathBuilder.append(File.separator);
                                        systemPathBuilder.append(artifact.getName());
                                        systemPathBuilder.append(File.separator);
                                        systemPathBuilder.append(Constants.POM_FILE_NAME);
                                        systemPathBuilder.append(".");
                                        systemPathBuilder.append(Constants.POM_FILE_EXTENSION);
                                        dependency.setSystemPath(systemPathBuilder.toString());

                                        DependencyData dependencyData = new DependencyData();
                                        dependencyData.setDependency(dependency);
                                        dependencyData.setParent(project);
                                        dependencyData.setSelf(artifact.getFile());
                                        dependencyData.setCApptype(artifactType);
                                        dependencyData.setServerRole(
                                                Constants.CAPP_PREFIX + artifact.getServerRole());

                                        dependencyData.setServerRole("capp/" + artifact.getServerRole());
                                        list.add(createListData(DistProjectUtils.getArtifactInfoAsString(
                                                dependency, project.getName()), dependencyData));
                                    }
                                } catch (FactoryConfigurationError ignored) {
                                    // ignored
                                }
                            }
                        } else {
                            String cAppType = "";
                            MavenProject mavenProject = DistProjectUtils.getMavenProject(project);
                            Dependency dependency = new Dependency();
                            dependency.setArtifactId(mavenProject.getArtifactId());
                            dependency.setGroupId(mavenProject.getGroupId());
                            dependency.setVersion(mavenProject.getVersion());
                            cAppType = mavenProject.getModel().getPackaging();
                            if (cAppType == null || !ArtifactTypeMapping.isValidArtifactType(cAppType)) {
                                if (mavenProject.getModel().getProperties().containsKey("CApp.type")) {
                                    cAppType = (String) mavenProject.getModel().getProperties()
                                            .get("CApp.type");
                                }
                            }
                            dependency.setType(ArtifactTypeMapping.getType(cAppType));
                            String serverRole = ServerRoleMapping.getServerRole(cAppType);

                            DependencyData dependencyData = new DependencyData();
                            dependencyData.setDependency(dependency);
                            dependencyData.setSelf(project);
                            dependencyData.setCApptype(cAppType);

                            if (!"".equals(serverRole)) {
                                dependencyData.setServerRole("capp/" + serverRole);
                            } else {
                                dependencyData.setServerRole("capp/ApplicationServer");
                            }

                            list.add(createListData(DistProjectUtils.getArtifactInfoAsString(dependency),
                                    dependencyData));
                        }
                    } catch (Exception ignored) {
                        // ignored
                    }
                }
            }
        } catch (Exception e) {
            log.error("Error reading project list", e);
        }
    }
    return list;
}

From source file:org.wso2.developerstudio.eclipse.ds.capp.refactor.DataServiceDeleteParticipant.java

License:Open Source License

private Dependency getDependencyForTheProject(IProject project) throws Exception {

    MavenProject mavenProject = MavenUtils.getMavenProject(project.getFile("pom.xml").getLocation().toFile());
    Dependency dependency = new Dependency();
    if (mavenProject != null) {
        dependency.setGroupId(mavenProject.getGroupId() + ".dataservice");
        dependency.setArtifactId(mavenProject.getArtifactId());
        dependency.setVersion(mavenProject.getVersion());
    }//from w w  w.  java  2s .  com
    return dependency;
}

From source file:org.wso2.developerstudio.eclipse.esb.presentation.ui.NewResourceTemplateDialog.java

License:Open Source License

private String getMavenGroupId(File pomLocation) {
    String groupId = "org.wso2.carbon";
    if (pomLocation != null && pomLocation.exists()) {
        try {/*from   w  w  w .j  a  va2  s  . co m*/
            MavenProject mavenProject = MavenUtils.getMavenProject(pomLocation);
            groupId = mavenProject.getGroupId();
        } catch (Exception e) {
            log.error("error reading pom file", e);
        }
    }
    return groupId;
}

From source file:org.wso2.developerstudio.eclipse.esb.project.FileModificationManager.java

License:Open Source License

@Override
public void resourceChanged(IResourceChangeEvent event) {
    try {//from w  w w  .  j  a va  2 s.c o m
        event.getDelta().accept(new IResourceDeltaVisitor() {
            public boolean visit(final IResourceDelta delta) {

                final IResource resource = delta.getResource();
                if (resource.getType() == IResource.ROOT) {
                    return true;
                } else if (resource.getType() == IResource.PROJECT) {
                    try {
                        IProject iProject = (IProject) resource;
                        if (iProject != null && iProject.isOpen() && iProject.hasNature(ESB_PROJECT_NATURE)) {
                            return true;
                        }
                    } catch (CoreException e) {
                        log.error("Error while checking the project nature", e);
                        return false;
                    }
                    return false;
                } else if (resource.getType() == IResource.FILE) {
                    if (delta.getKind() == IResourceDelta.ADDED) {

                        Job job = new Job("update ArifactXML") {

                            @Override
                            protected IStatus run(IProgressMonitor monitor) {
                                try {
                                    if (resource instanceof IFile) {
                                        final IFile file = (IFile) resource;
                                        IProject iProject = file.getProject();
                                        if (file.getParent() instanceof IFolder) {
                                            IFolder folder = (IFolder) file.getParent();
                                            IPath location = file.getLocation();
                                            IPath removeLastSegments = location.removeLastSegments(2);
                                            String grandParentDir = removeLastSegments.lastSegment();

                                            if (SYNAPSE_CONFIG_DIR.equals(grandParentDir)) {

                                                String source = FileUtils
                                                        .getContentAsString(file.getLocationURI().toURL());
                                                Openable openable = ESBGraphicalEditor.getOpenable();
                                                ArtifactType artifactType = (ArtifactType) openable
                                                        .artifactTypeResolver(source);

                                                final String folderType = folder.getName();
                                                final String arifacLiteral = artifactType.getName()
                                                        .toLowerCase();

                                                if (folderType.startsWith(arifacLiteral)) {

                                                    File arifact = iProject.getFile(ARTIFACT_MEATADATA_FILE)
                                                            .getLocation().toFile();
                                                    ESBProjectArtifact artifact = new ESBProjectArtifact();
                                                    artifact.fromFile(arifact);
                                                    List<ESBArtifact> allESBArtifacts = artifact
                                                            .getAllESBArtifacts();
                                                    ESBArtifact esbTempartifact = null;
                                                    for (ESBArtifact esbartifact : allESBArtifacts) {
                                                        String name = esbartifact.getName() + ".xml";
                                                        if (name.equals(file.getName())) {
                                                            return Status.OK_STATUS;
                                                        }
                                                        esbTempartifact = esbartifact;
                                                    }

                                                    String version = "";
                                                    String type = COMMAN_NAME
                                                            + ESBProjectUtils.getType(folder.getName());
                                                    String groupId = "";
                                                    String name = file.getName().split("\\.")[0];

                                                    if (esbTempartifact == null) {
                                                        File pomLocation = iProject.getFile(POM).getLocation()
                                                                .toFile();
                                                        MavenProject mavenProject = MavenUtils
                                                                .getMavenProject(pomLocation);
                                                        version = mavenProject.getVersion();
                                                        groupId = mavenProject.getGroupId();
                                                    } else {
                                                        version = esbTempartifact.getVersion();
                                                        groupId = esbTempartifact.getGroupId();
                                                    }

                                                    ESBArtifact esbArtifact = new ESBArtifact();
                                                    esbArtifact.setName(name);
                                                    esbArtifact.setVersion(version);
                                                    esbArtifact.setType(type);
                                                    esbArtifact.setServerRole(ESB_SEVER_ROLE);
                                                    esbArtifact.setGroupId(groupId);
                                                    // Should not use file separator here
                                                    esbArtifact.setFile(FILE_PATH + folder.getName() + "/"
                                                            + file.getName());
                                                    artifact.addESBArtifact(esbArtifact);
                                                    artifact.toFile();
                                                } else {
                                                    IPath movedFromPath = delta.getMovedFromPath();
                                                    if (movedFromPath != null) {
                                                        Display.getDefault().syncExec(new Runnable() {

                                                            @Override
                                                            public void run() {

                                                                MessageDialog.openError(
                                                                        Display.getCurrent().getActiveShell(),
                                                                        "Error Move",
                                                                        "Cannot move due to invalid location");

                                                                try {
                                                                    IUndoContext workspaceContext = (IUndoContext) ResourcesPlugin
                                                                            .getWorkspace()
                                                                            .getAdapter(IUndoContext.class);
                                                                    OperationHistoryFactory
                                                                            .getOperationHistory()
                                                                            .undo(workspaceContext,
                                                                                    new NullProgressMonitor(),
                                                                                    null);

                                                                } catch (ExecutionException e) {
                                                                    log.error("Cannot undo last operation", e);
                                                                }

                                                            }
                                                        });
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } catch (FactoryConfigurationError | Exception e) {
                                    log.error("Error while updating the arifactxml", e);
                                }
                                return Status.OK_STATUS;
                            }
                        };
                        job.schedule();
                        return true;
                    } else if (delta.getKind() == IResourceDelta.REMOVED) {

                        Job job = new Job("update ArifactXML") {

                            @Override
                            protected IStatus run(IProgressMonitor monitor) {
                                try {
                                    if (resource instanceof IFile) {
                                        IFile file = (IFile) resource;
                                        if (file.exists()) {
                                            IProject project = file.getProject();
                                            IPath location = file.getLocation();
                                            IPath removeLastSegments = location.removeLastSegments(2);
                                            String grandParentDir = removeLastSegments.lastSegment();

                                            if (SYNAPSE_CONFIG_DIR.equals(grandParentDir)) {
                                                File arifact = project.getFile(ARTIFACT_MEATADATA_FILE)
                                                        .getLocation().toFile();
                                                ESBProjectArtifact artifact = new ESBProjectArtifact();
                                                artifact.fromFile(arifact);
                                                List<ESBArtifact> allESBArtifacts = artifact
                                                        .getAllESBArtifacts();
                                                ESBArtifact removeNode = null;
                                                Iterator<ESBArtifact> iterator = allESBArtifacts.iterator();
                                                while (iterator.hasNext()) {
                                                    ESBArtifact esbartifact = iterator.next();
                                                    String name = esbartifact.getName() + ".xml";
                                                    if (name.equals(file.getName())) {
                                                        removeNode = esbartifact;
                                                        break;
                                                    }

                                                }
                                                if (removeNode != null) {
                                                    artifact.removeESBArtifact(removeNode);
                                                    artifact.toFile();
                                                }
                                            }
                                        }
                                    }
                                } catch (FactoryConfigurationError | Exception e) {
                                    log.error("Error while updating the arifactxml", e);
                                }
                                return Status.OK_STATUS;
                            }
                        };
                        job.schedule();
                        return true;
                    }

                    return false;
                }
                return true;

            }
        });

    } catch (CoreException e) {
        log.error("Error while updating the arifactxml", e);
    }

}

From source file:org.wso2.developerstudio.eclipse.general.project.refactor.RefactorUtils.java

License:Open Source License

public static Dependency getDependencyForTheProject(IProject project) {
    MavenProject mavenProject = getMavenProject(project);

    Dependency dependency = new Dependency();

    if (mavenProject != null) {
        dependency.setGroupId(mavenProject.getGroupId() + ".resource");
        dependency.setArtifactId(mavenProject.getArtifactId());
        dependency.setVersion(mavenProject.getVersion());
    }// ww w.  j  av  a 2 s.  com
    return dependency;
}

From source file:org.wso2.developerstudio.eclipse.gmf.esb.diagram.edit.parts.CallTemplateMediatorEditPart.java

License:Open Source License

private String getMavenGroupID(IProject project) {
    String groupID = "com.example";
    try {//from  w  w w .  ja va2 s . c  o m
        MavenProject mavenProject = MavenUtils
                .getMavenProject(project.getFile("pom.xml").getLocation().toFile());
        groupID = mavenProject.getGroupId() + ".template";
    } catch (Exception e) {
        //ignore. Then group id would be default. 
    }

    return groupID;
}

From source file:org.wso2.developerstudio.eclipse.gmf.esb.diagram.edit.parts.SequenceEditPart.java

License:Open Source License

private String getMavenGroupID(IProject project) {
    String groupID = "com.example"; //$NON-NLS-1$
    try {// www.j  a  v a2s  .c o m
        MavenProject mavenProject = MavenUtils
                .getMavenProject(project.getFile("pom.xml").getLocation().toFile()); //$NON-NLS-1$
        groupID = mavenProject.getGroupId() + ".sequence"; //$NON-NLS-1$
    } catch (Exception e) {
        //ignore. Then group id would be default. 
    }

    return groupID;
}

From source file:org.wso2.developerstudio.eclipse.gmf.esb.diagram.edit.parts.SequenceEditPart.java

License:Open Source License

private void addSequenceToRegistryArtifactXML(String sequenceName, IProject currentProject) {

    GeneralProjectArtifact generalProjectArtifact = new GeneralProjectArtifact();
    try {/*from w ww  . j a  v  a2s. co m*/
        generalProjectArtifact.fromFile(currentProject.getFile("artifact.xml").getLocation().toFile()); //$NON-NLS-1$
        File pomLocation = currentProject.getFile("pom.xml").getLocation().toFile(); //$NON-NLS-1$
        MavenProject mavenProject = MavenUtils.getMavenProject(pomLocation);
        RegistryArtifact artifact = new RegistryArtifact();
        artifact.setName(sequenceName);
        artifact.setVersion(mavenProject.getVersion());
        artifact.setType("registry/resource"); //$NON-NLS-1$
        artifact.setServerRole("GovernanceRegistry"); //$NON-NLS-1$
        artifact.setGroupId(mavenProject.getGroupId() + ".resource"); //$NON-NLS-1$

        RegistryElement item = new RegistryItem();
        ((RegistryItem) item).setFile(sequenceName + ".xml"); //$NON-NLS-1$
        ((RegistryItem) item).setPath("/_system/governance/sequences"); //$NON-NLS-1$
        ((RegistryItem) item).setMediaType("application/vnd.wso2.sequence"); //$NON-NLS-1$
        artifact.addRegistryElement(item);
        generalProjectArtifact.addArtifact(artifact);
        generalProjectArtifact.toFile();

    } catch (Exception e) {
        log.error("Error while updating Artifact.xml", e); //$NON-NLS-1$
    }
}