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

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

Introduction

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

Prototype

public Model getModel() 

Source Link

Usage

From source file:org.whitesource.bamboo.agent.MavenOssInfoExtractor.java

License:Apache License

private AgentProjectInfo processProject(MavenProject project) {
    long startTime = System.currentTimeMillis();

    log.info(WssUtils.logMsg(LOG_COMPONENT, "processing Maven project " + project.getId()));

    AgentProjectInfo projectInfo = new AgentProjectInfo();

    // project token
    if (project.equals(mavenParser.getMavenProject())) {
        projectInfo.setProjectToken(projectToken);
    } else {//from  w w w  . jav  a  2s  .  co  m
        projectInfo.setProjectToken(moduleTokens.get(project.getArtifactId()));
    }

    // project coordinates
    projectInfo.setCoordinates(extractCoordinates(project));

    Parent parent = project.getModel().getParent();
    // parent coordinates
    if (parent != null) {
        projectInfo.setParentCoordinates(extractParentCoordinates(parent));
    }

    // dependencies
    Map<Dependency, Artifact> lut = createLookupTable(project);
    for (Dependency dependency : mavenParser.getDependencies(project)) {
        DependencyInfo dependencyInfo = getDependencyInfo(dependency);

        Artifact artifact = lut.get(dependency);
        if (artifact != null) {
            File artifactFile = artifact.getFile();
            if (artifactFile != null && artifactFile.exists()) {
                try {
                    dependencyInfo.setSha1(ChecksumUtils.calculateSHA1(artifactFile));
                } catch (IOException e) {
                    log.warn(WssUtils.logMsg(LOG_COMPONENT, ERROR_SHA1 + " for " + artifact.getId()));
                }
            }
        }

        projectInfo.getDependencies().add(dependencyInfo);
    }

    log.info(WssUtils.logMsg(LOG_COMPONENT,
            "Total Maven project processing time is " + (System.currentTimeMillis() - startTime) + " [msec]"));

    return projectInfo;
}

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

License:Apache License

/**
 * Gets the default set of properties for the given project.
 *
 * @param currentProject the project//from w ww  . j a v  a  2s  .c  om
 * @return the set of properties, containing default bundle packaging instructions.
 */
public static Properties getDefaultProperties(MavenProject currentProject) {
    Properties properties = new Properties();
    String bsn = DefaultMaven2OsgiConverter.getBundleSymbolicName(currentProject.getArtifact());

    // Setup defaults
    properties.put(MAVEN_SYMBOLICNAME, bsn);
    properties.put("bundle.file.name",
            DefaultMaven2OsgiConverter.getBundleFileName(currentProject.getArtifact()));
    properties.put(Analyzer.BUNDLE_SYMBOLICNAME, bsn);
    properties.put(Analyzer.IMPORT_PACKAGE, "*");
    properties.put(Analyzer.BUNDLE_VERSION, DefaultMaven2OsgiConverter.getVersion(currentProject.getVersion()));

    header(properties, Analyzer.BUNDLE_DESCRIPTION, currentProject.getDescription());
    StringBuilder licenseText = printLicenses(currentProject.getLicenses());
    if (licenseText != null) {
        header(properties, Analyzer.BUNDLE_LICENSE, licenseText);
    }
    header(properties, Analyzer.BUNDLE_NAME, currentProject.getName());

    if (currentProject.getOrganization() != null) {
        if (currentProject.getOrganization().getName() != null) {
            String organizationName = currentProject.getOrganization().getName();
            header(properties, Analyzer.BUNDLE_VENDOR, organizationName);
            properties.put("project.organization.name", organizationName);
            properties.put("pom.organization.name", organizationName);
        }
        if (currentProject.getOrganization().getUrl() != null) {
            String organizationUrl = currentProject.getOrganization().getUrl();
            header(properties, Analyzer.BUNDLE_DOCURL, organizationUrl);
            properties.put("project.organization.url", organizationUrl);
            properties.put("pom.organization.url", organizationUrl);
        }
    }

    properties.putAll(currentProject.getModel().getProperties());

    for (String s : currentProject.getFilters()) {
        File filterFile = new File(s);
        if (filterFile.isFile()) {
            properties.putAll(PropertyUtils.loadProperties(filterFile));
        }
    }

    properties.putAll(getProperties(currentProject.getModel(), "project.build."));
    properties.putAll(getProperties(currentProject.getModel(), "pom."));
    properties.putAll(getProperties(currentProject.getModel(), "project."));

    properties.put("project.baseDir", currentProject.getBasedir().getAbsolutePath());
    properties.put("project.build.directory", currentProject.getBuild().getDirectory());
    properties.put("project.build.outputdirectory", currentProject.getBuild().getOutputDirectory());

    properties.put("project.source.roots", getArray(currentProject.getCompileSourceRoots()));
    properties.put("project.testSource.roots", getArray(currentProject.getTestCompileSourceRoots()));

    properties.put("project.resources", toString(currentProject.getResources()));
    properties.put("project.testResources", toString(currentProject.getTestResources()));

    return properties;
}

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

License:Open Source License

private static void addGeneralProjectPlugin(IProject project) throws Exception {
    MavenProject mavenProject;

    File mavenProjectPomLocation = project.getFile(POM_FILE).getLocation().toFile();
    if (!mavenProjectPomLocation.exists()) {
        mavenProject = MavenUtils.createMavenProject(GROUP_ID, project.getName(), ARTIFACT_VERSION,
                POM_PACKAGING_TYPE);/* www  .j  av a  2 s. c o  m*/
    } else {
        mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
    }

    boolean pluginExists = MavenUtils.checkOldPluginEntry(mavenProject, MAVEN_GROUP_ID, MAVEN_ARTIFACT_ID,
            MavenConstants.WSO2_GENERAL_PROJECT_VERSION);
    if (pluginExists) {
        return;
    }

    mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
    Plugin plugin = MavenUtils.createPluginEntry(mavenProject, MAVEN_GROUP_ID, MAVEN_ARTIFACT_ID,
            MavenConstants.WSO2_GENERAL_PROJECT_VERSION, true);

    PluginExecution pluginExecution;

    pluginExecution = new PluginExecution();
    pluginExecution.addGoal(POM_GEN);
    pluginExecution.setPhase(PROCESS_RESOURCES);
    pluginExecution.setId(REGISTRY);
    plugin.addExecution(pluginExecution);

    Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
    Xpp3Dom artifactLocationNode = MavenUtils.createXpp3Node(configurationNode, ARTIFACT_LOCATION);
    artifactLocationNode.setValue("."); //$NON-NLS-1$
    Xpp3Dom typeListNode = MavenUtils.createXpp3Node(configurationNode, TYPE_LIST);
    typeListNode.setValue(ARTIFACT_TYPES);
    pluginExecution.setConfiguration(configurationNode);

    Repository repo = new Repository();
    repo.setUrl(REPO_URL);
    repo.setId(REPO_ID);

    Repository repo1 = new Repository();
    repo1.setUrl(REPO_URL_1);
    repo1.setId(REPO_ID_1);

    if (!mavenProject.getRepositories().contains(repo)) {
        mavenProject.getModel().addRepository(repo);
        mavenProject.getModel().addPluginRepository(repo);
    }

    if (!mavenProject.getRepositories().contains(repo1)) {
        mavenProject.getModel().addRepository(repo1);
        mavenProject.getModel().addPluginRepository(repo1);
    }

    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);
}

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

License:Open Source License

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

    boolean pluginExists = MavenUtils.checkOldPluginEntry(mavenProject, "org.wso2.maven",
            "analytics-execution-plan-maven-plugin",
            AnalyticsMavenConstants.WSO2_ANALYTICS_EXECUTIONPLAN_VERSION);
    if (pluginExists) {
        return;/*from  ww w  .j av a 2s. co  m*/
    }

    Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.wso2.maven",
            "analytics-execution-plan-maven-plugin",
            AnalyticsMavenConstants.WSO2_ANALYTICS_EXECUTIONPLAN_VERSION, true);

    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.addGoal("pom-gen");
    pluginExecution.setPhase("process-resources");
    pluginExecution.setId("execution-plan");

    Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
    Xpp3Dom artifactLocationNode = MavenUtils.createXpp3Node(configurationNode, "artifactLocation");
    artifactLocationNode.setValue(".");
    Xpp3Dom typeListNode = MavenUtils.createXpp3Node(configurationNode, "typeList");
    typeListNode.setValue("${artifact.types}");
    pluginExecution.setConfiguration(configurationNode);

    plugin.addExecution(pluginExecution);
    Repository repo = new Repository();
    repo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/");
    repo.setId("wso2-nexus");

    RepositoryPolicy releasePolicy = new RepositoryPolicy();
    releasePolicy.setEnabled(true);
    releasePolicy.setUpdatePolicy("daily");
    releasePolicy.setChecksumPolicy("ignore");

    repo.setReleases(releasePolicy);

    if (!mavenProject.getRepositories().contains(repo)) {
        mavenProject.getModel().addRepository(repo);
        mavenProject.getModel().addPluginRepository(repo);
    }

    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);
}

From source file:org.wso2.developerstudio.eclipse.artifact.analytics.publisher.ui.wizard.PublisherProjectCreationWizard.java

License:Open Source License

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

    boolean pluginExists = MavenUtils.checkOldPluginEntry(mavenProject, "org.wso2.maven",
            "analytics-publisher-maven-plugin", AnalyticsMavenConstants.WSO2_ANALYTICS_PUBLISHER_VERSION);
    if (pluginExists) {
        return;/*w  w w  .  j av a2s.c om*/
    }

    Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.wso2.maven",
            "analytics-publisher-maven-plugin", AnalyticsMavenConstants.WSO2_ANALYTICS_PUBLISHER_VERSION, true);

    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.addGoal("pom-gen");
    pluginExecution.setPhase("process-resources");
    pluginExecution.setId("publisher");

    Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
    Xpp3Dom artifactLocationNode = MavenUtils.createXpp3Node(configurationNode, "artifactLocation");
    artifactLocationNode.setValue(".");
    Xpp3Dom typeListNode = MavenUtils.createXpp3Node(configurationNode, "typeList");
    typeListNode.setValue("${artifact.types}");
    pluginExecution.setConfiguration(configurationNode);

    plugin.addExecution(pluginExecution);
    Repository repo = new Repository();
    repo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/");
    repo.setId("wso2-nexus");

    RepositoryPolicy releasePolicy = new RepositoryPolicy();
    releasePolicy.setEnabled(true);
    releasePolicy.setUpdatePolicy("daily");
    releasePolicy.setChecksumPolicy("ignore");

    repo.setReleases(releasePolicy);

    if (!mavenProject.getRepositories().contains(repo)) {
        mavenProject.getModel().addRepository(repo);
        mavenProject.getModel().addPluginRepository(repo);
    }

    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);
}

From source file:org.wso2.developerstudio.eclipse.artifact.analytics.receiver.ui.wizard.ReceiverProjectCreationWizard.java

License:Open Source License

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

    boolean pluginExists = MavenUtils.checkOldPluginEntry(mavenProject, "org.wso2.maven",
            "analytics-receiver-maven-plugin", AnalyticsMavenConstants.WSO2_ANALYTICS_RECEIVER_VERSION);
    if (pluginExists) {
        return;//from   w w w.  jav  a 2s .  c o  m
    }

    Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.wso2.maven",
            "analytics-receiver-maven-plugin", AnalyticsMavenConstants.WSO2_ANALYTICS_RECEIVER_VERSION, true);

    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.addGoal("pom-gen");
    pluginExecution.setPhase("process-resources");
    pluginExecution.setId("receiver");

    Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
    Xpp3Dom artifactLocationNode = MavenUtils.createXpp3Node(configurationNode, "artifactLocation");
    artifactLocationNode.setValue(".");
    Xpp3Dom typeListNode = MavenUtils.createXpp3Node(configurationNode, "typeList");
    typeListNode.setValue("${artifact.types}");
    pluginExecution.setConfiguration(configurationNode);

    plugin.addExecution(pluginExecution);
    Repository repo = new Repository();
    repo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/");
    repo.setId("wso2-nexus");

    RepositoryPolicy releasePolicy = new RepositoryPolicy();
    releasePolicy.setEnabled(true);
    releasePolicy.setUpdatePolicy("daily");
    releasePolicy.setChecksumPolicy("ignore");

    repo.setReleases(releasePolicy);

    if (!mavenProject.getRepositories().contains(repo)) {
        mavenProject.getModel().addRepository(repo);
        mavenProject.getModel().addPluginRepository(repo);
    }

    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);
}

From source file:org.wso2.developerstudio.eclipse.artifact.analytics.stream.ui.wizard.StreamProjectCreationWizard.java

License:Open Source License

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

    boolean pluginExists = MavenUtils.checkOldPluginEntry(mavenProject, "org.wso2.maven",
            "analytics-stream-maven-plugin", AnalyticsMavenConstants.WSO2_ANALYTICS_STREAM_VERSION);
    if (pluginExists) {
        return;//from  w  w  w  .  j  a va2  s .  c  o m
    }

    Plugin plugin = MavenUtils.createPluginEntry(mavenProject, "org.wso2.maven",
            "analytics-stream-maven-plugin", AnalyticsMavenConstants.WSO2_ANALYTICS_STREAM_VERSION, true);

    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.addGoal("pom-gen");
    pluginExecution.setPhase("process-resources");
    pluginExecution.setId("stream");

    Xpp3Dom configurationNode = MavenUtils.createMainConfigurationNode();
    Xpp3Dom artifactLocationNode = MavenUtils.createXpp3Node(configurationNode, "artifactLocation");
    artifactLocationNode.setValue(".");
    Xpp3Dom typeListNode = MavenUtils.createXpp3Node(configurationNode, "typeList");
    typeListNode.setValue("${artifact.types}");
    pluginExecution.setConfiguration(configurationNode);

    plugin.addExecution(pluginExecution);
    Repository repo = new Repository();
    repo.setUrl("http://maven.wso2.org/nexus/content/groups/wso2-public/");
    repo.setId("wso2-nexus");

    RepositoryPolicy releasePolicy = new RepositoryPolicy();
    releasePolicy.setEnabled(true);
    releasePolicy.setUpdatePolicy("daily");
    releasePolicy.setChecksumPolicy("ignore");

    repo.setReleases(releasePolicy);

    if (!mavenProject.getRepositories().contains(repo)) {
        mavenProject.getModel().addRepository(repo);
        mavenProject.getModel().addPluginRepository(repo);
    }

    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);
}

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  ww  .  j  a v a  2 s.com*/
    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.project.nature.CarbonUIbundleProjectNature.java

License:Open Source License

public void updatePom() throws Exception {
    ResourceBundle mediatorPropetiesBundle = ResourceBundle.getBundle("carbonUI");
    String groupId = mediatorPropetiesBundle.getString("Plugin_groupId");
    String artifactId = mediatorPropetiesBundle.getString("Plugin_artficatId");
    String version = mediatorPropetiesBundle.getString("Plugin_version");

    File mavenProjectPomLocation = getProject().getFile("pom.xml").getLocation().toFile();
    MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
    mavenProject.getModel().getProperties().put("CApp.type", "lib/carbon/ui");
    Plugin plugin = MavenUtils.createPluginEntry(mavenProject, groupId, artifactId, version, true);
    PluginExecution pluginExecution;/*ww w  . jav  a 2  s. c  o  m*/
    pluginExecution = new PluginExecution();
    plugin.addExecution(pluginExecution);

    String projectName = getProject().getName();
    Xpp3Dom configNode = MavenUtils.createXpp3Node("configuration");
    Xpp3Dom instructionNode = MavenUtils.createXpp3Node(configNode, "instructions");
    Xpp3Dom sybundleNode = MavenUtils.createXpp3Node(instructionNode, "Bundle-SymbolicName");
    sybundleNode.setValue(projectName);
    Xpp3Dom bundleNode = MavenUtils.createXpp3Node(instructionNode, "Bundle-Name");
    bundleNode.setValue(projectName);
    Xpp3Dom activatorbundleNode = MavenUtils.createXpp3Node(instructionNode, "Bundle-Activator");
    activatorbundleNode.setValue(CarbonUIbundleWizard.getUibundleModel().getActivatorClassName());
    Xpp3Dom includeNode = MavenUtils.createXpp3Node(instructionNode, "Carbon-Component");
    includeNode.setValue("UIBundle");
    MavenUtils.createXpp3Node(instructionNode, "Export-Package");
    Xpp3Dom importNode = MavenUtils.createXpp3Node(instructionNode, "DynamicImport-Package");
    importNode.setValue("*");
    Xpp3Dom importode = MavenUtils.createXpp3Node(instructionNode, "Include-Resource");
    importode.setValue("META-INF/component.xml = META-INF/component.xml,web = web");

    plugin.setConfiguration(configNode);

    List<Dependency> dependencyList = new ArrayList<Dependency>();
    Map<String, JavaLibraryBean> dependencyInfoMap = JavaLibraryUtil.getDependencyInfoMap(getProject());
    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)));
            }
        }
        Dependency dependency = new Dependency();
        dependency.setArtifactId(bean.getArtifactId());
        dependency.setGroupId(bean.getGroupId());
        dependency.setVersion(bean.getVersion());
        dependencyList.add(dependency);
    }
    MavenUtils.addMavenDependency(mavenProject, dependencyList);
    MavenUtils.saveMavenProject(mavenProject, mavenProjectPomLocation);
}

From source file:org.wso2.developerstudio.eclipse.artifact.connector.ui.wizard.ConnectorCreationWizard.java

License:Open Source License

public void updatePom() throws IOException, XmlPullParserException {
    File mavenProjectPomLocation = project.getFile("pom.xml").getLocation().toFile();
    MavenProject mavenProject = MavenUtils.getMavenProject(mavenProjectPomLocation);
    mavenProject.getModel().getProperties().put("CApp.type", "synapse/lib");

    // Skip changing the pom file if group ID and artifact ID are matched
    if (MavenUtils.checkOldPluginEntry(mavenProject, "org.wso2.maven", "wso2-esb-connector-plugin")) {
        return;/* ww  w.jav  a2s  .  c o m*/
    }

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

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