Search in sources :

Example 1 with MavenPluginActivator

use of org.eclipse.m2e.core.internal.MavenPluginActivator in project liferay-ide by liferay.

the class NewMavenJSFModuleProjectProvider method createArchetypeProject.

protected IPath createArchetypeProject(NewLiferayJSFModuleProjectOp op, IProgressMonitor monitor) throws CoreException {
    IPath projectLocation = null;
    String javaPackage = "com.example";
    String projectName = op.getProjectName().content();
    IPath location = PathBridge.create(op.getLocation().content());
    if (location.lastSegment().equals(projectName)) {
        // use parent dir since maven archetype will generate new dir under this
        // location
        location = location.removeLastSegments(1);
    }
    String groupId = op.getProjectName().content();
    String artifactId = op.getProjectName().content();
    String version = "1.0.0";
    String archetypeArtifactId = op.getArchetype().content();
    Archetype archetype = new Archetype();
    String[] gav = archetypeArtifactId.split(":");
    String archetypeVersion = gav[gav.length - 1];
    archetype.setGroupId(gav[0]);
    archetype.setArtifactId(gav[1]);
    archetype.setVersion(archetypeVersion);
    Artifact artifact = AetherUtil.getLatestAvailableArtifact(archetypeArtifactId);
    Properties properties = new Properties();
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    if (location == null) {
        location = workspaceRoot.getLocation();
    }
    try {
        MavenPluginActivator pluginActivator = MavenPluginActivator.getDefault();
        ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
        request.setTransferListener(pluginActivator.getMaven().createTransferListener(monitor));
        request.setArchetypeGroupId(artifact.getGroupId());
        request.setArchetypeArtifactId(artifact.getArtifactId());
        request.setArchetypeVersion(artifact.getVersion());
        request.setArchetypeRepository(AetherUtil.newCentralRepository().getUrl());
        request.setGroupId(groupId);
        request.setArtifactId(artifactId);
        request.setVersion(version);
        request.setPackage(javaPackage);
        // the model does not have a package field
        request.setLocalRepository(pluginActivator.getMaven().getLocalRepository());
        request.setRemoteArtifactRepositories(pluginActivator.getMaven().getArtifactRepositories(true));
        request.setProperties(properties);
        request.setOutputDirectory(location.toPortableString());
        ArchetypeGenerationResult result = _getArchetyper().generateProjectFromArchetype(request);
        Exception cause = result.getCause();
        if (cause != null) {
            throw new CoreException(LiferayCore.createErrorStatus("Unable to create project from archetype."));
        }
        projectLocation = location.append(artifactId);
        if (FileUtil.notExists(projectLocation)) {
            throw new CoreException(LiferayCore.createErrorStatus("Can't create gradle JSF project. "));
        }
    } catch (Exception e) {
        throw new CoreException(LiferayCore.createErrorStatus("Failed to create JSF project. ", e));
    }
    return projectLocation;
}
Also used : MavenPluginActivator(org.eclipse.m2e.core.internal.MavenPluginActivator) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) Archetype(org.apache.maven.archetype.catalog.Archetype) ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) ArchetypeGenerationResult(org.apache.maven.archetype.ArchetypeGenerationResult) Properties(java.util.Properties) Artifact(org.eclipse.aether.artifact.Artifact) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException)

Example 2 with MavenPluginActivator

use of org.eclipse.m2e.core.internal.MavenPluginActivator in project jbosstools-openshift by jbosstools.

the class MavenProjectImportOperation method importToWorkspace.

public List<IProject> importToWorkspace(IProgressMonitor monitor) throws CoreException, InterruptedException {
    MavenPluginActivator mavenPlugin = MavenPluginActivator.getDefault();
    IProjectConfigurationManager configurationManager = mavenPlugin.getProjectConfigurationManager();
    MavenModelManager modelManager = mavenPlugin.getMavenModelManager();
    Set<MavenProjectInfo> projectInfos = getMavenProjects(getProjectDirectory(), filters, modelManager, monitor);
    ProjectImportConfiguration projectImportConfiguration = new ProjectImportConfiguration();
    if (overwriteMavenProjects(projectInfos, projectImportConfiguration, monitor)) {
        List<IMavenProjectImportResult> importResults = configurationManager.importProjects(projectInfos, projectImportConfiguration, monitor);
        return validate(toProjects(importResults));
    } else {
        return Collections.emptyList();
    }
}
Also used : MavenPluginActivator(org.eclipse.m2e.core.internal.MavenPluginActivator) IMavenProjectImportResult(org.eclipse.m2e.core.project.IMavenProjectImportResult) ProjectImportConfiguration(org.eclipse.m2e.core.project.ProjectImportConfiguration) IProjectConfigurationManager(org.eclipse.m2e.core.project.IProjectConfigurationManager) MavenProjectInfo(org.eclipse.m2e.core.project.MavenProjectInfo) MavenModelManager(org.eclipse.m2e.core.embedder.MavenModelManager)

Aggregations

MavenPluginActivator (org.eclipse.m2e.core.internal.MavenPluginActivator)2 Properties (java.util.Properties)1 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)1 ArchetypeGenerationResult (org.apache.maven.archetype.ArchetypeGenerationResult)1 Archetype (org.apache.maven.archetype.catalog.Archetype)1 Artifact (org.eclipse.aether.artifact.Artifact)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 MavenModelManager (org.eclipse.m2e.core.embedder.MavenModelManager)1 IMavenProjectImportResult (org.eclipse.m2e.core.project.IMavenProjectImportResult)1 IProjectConfigurationManager (org.eclipse.m2e.core.project.IProjectConfigurationManager)1 MavenProjectInfo (org.eclipse.m2e.core.project.MavenProjectInfo)1 ProjectImportConfiguration (org.eclipse.m2e.core.project.ProjectImportConfiguration)1 JSONException (org.json.JSONException)1