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.whitesource.bamboo.agent.MavenOssInfoExtractor.java

License:Apache License

private Coordinates extractCoordinates(MavenProject mavenProject) {
    return new Coordinates(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion());
}

From source file:org.wildfly.swarm.plugin.MavenDependenciesResolver.java

License:Apache License

private File mockPom(MavenProject project) throws IOException {
    File pom = File.createTempFile("pom", ".xml");
    pom.deleteOnExit();//from w  ww  .  j a  v  a 2  s  .c o m
    InputStream templateStream = getClass().getResourceAsStream("/pom-template.xml");
    try (InputStreamReader streamReader = new InputStreamReader(templateStream);
            BufferedReader reader = new BufferedReader(streamReader);
            FileWriter writer = new FileWriter(pom)) {
        String line;
        while ((line = reader.readLine()) != null) {
            line = line.replace("FRACTION_GROUP_ID", project.getGroupId());
            line = line.replace("FRACTION_ARTIFACT_ID", project.getArtifactId());
            line = line.replace("FRACTION_VERSION", project.getVersion());
            writer.write(line);
        }
    }
    return pom;
}

From source file:org.wisdom.maven.mojos.RunMojo.java

License:Apache License

private MavenSession getMavenSession(final MavenProject project, MavenExecutionRequest request) {
    MavenSession newSession = new MavenSession(container, session.getRepositorySession(), request,
            session.getResult());/*from w  ww.  j a va 2 s  . c  om*/
    newSession.setAllProjects(session.getAllProjects());
    newSession.setCurrentProject(project);
    newSession.setParallel(session.isParallel());
    // Update project map to update the current project
    Map<String, MavenProject> projectMaps = new LinkedHashMap<>(session.getProjectMap());
    projectMaps.put(ArtifactUtils.key(project.getGroupId(), project.getArtifactId(), project.getVersion()),
            project);
    newSession.setProjectMap(projectMaps);

    /**
     * Fake implementation of the project dependency graph, as we don't support reactor.
     */
    ProjectDependencyGraph graph = new ProjectDependencyGraph() {

        @Override
        public List<MavenProject> getSortedProjects() {
            return ImmutableList.of(project);
        }

        @Override
        public List<MavenProject> getDownstreamProjects(MavenProject project, boolean transitive) {
            return Collections.emptyList();
        }

        @Override
        public List<MavenProject> getUpstreamProjects(MavenProject project, boolean transitive) {
            return Collections.emptyList();
        }
    };
    newSession.setProjectDependencyGraph(graph);
    newSession.setProjects(ImmutableList.of(project));
    return newSession;
}

From source file:org.wisdom.maven.utils.DefaultMaven2OsgiConverter.java

License:Apache License

/**
 * Computes the file name of the bundle used in Wisdom distribution for the given Maven project.
 * This convention is based on the uniqueness at runtime of 'bsn-version' (bsn is the bundle symbolic name).
 *
 * @param project the project//from www .  j a v a2s  .co  m
 * @return the computed name, composed by the symbolic name and the version: {@code bsn-version.jar}
 */
public static String getBundleFileName(MavenProject project) {
    return getBundleFileName(project.getGroupId(), project.getArtifactId(), project.getVersion());
}

From source file:org.wso2.developerstudio.datamapper.diagram.custom.util.CreateNewConfigurationDialog.java

License:Open Source License

private static String getMavenGroupId(File pomLocation) {
    String groupId = GROUP_ID;// www  . j ava 2 s  . c  o  m
    if (pomLocation != null && pomLocation.exists()) {
        try {
            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.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  ww . j av  a2 s  .  com

    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.connector.ui.wizard.AddRemoveConnectorWizard.java

License:Open Source License

private void copyConnectors() throws Exception {
    for (Object resource : libraryModel.getConnectors()) {
        File libraryResource = null;
        if (resource instanceof File) {
            libraryResource = (File) resource;
        } else if (resource instanceof IFile) {
            libraryResource = new File(((IFile) resource).getLocation().toOSString());
        }/*from  ww  w. j  a  va  2  s .  c  o m*/
        if (libraryResource != null) {
            String dest = new File(project.getLocation().toFile(), libraryResource.getName()).toString();
            if (!libraryResource.toString().equals(dest)) {
                FileUtils.copyFile(libraryResource.toString(), dest);
            }
        }

        File mavenProjectPomLocation = project.getFile("pom.xml").getLocation().toFile();
        MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);

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

        ConnectorArtifact connectorArtifact = new ConnectorArtifact();
        String connectorName = libraryResource.getName().substring(0,
                libraryResource.getName().lastIndexOf("-"));
        String[] segment = libraryResource.getName().split("-");
        String version = segment[segment.length - 1].split(".zip")[0];
        connectorArtifact.setName(connectorName);
        connectorArtifact.setVersion(version);
        connectorArtifact.setType("synapse/lib");
        connectorArtifact.setServerRole("EnterpriseServiceBus");
        connectorArtifact.setGroupId(mavenProject.getGroupId() + GROUP_ID);
        connectorArtifact.setFile(FileUtils
                .getRelativePath(project.getLocation().toFile(),
                        new File(project.getLocation().toFile(), libraryResource.getName()))
                .replaceAll(Pattern.quote(File.separator), "/"));
        artifact.addESBArtifact(connectorArtifact);
        artifact.toFile();
        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        refreshDistProjects();
    }
    project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}

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;//from  w  w w . jav a2  s . 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  av  a 2s .  c  om*/

    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.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 a  2  s.  co 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);

}