Example usage for org.apache.maven.execution DefaultMavenExecutionRequest setLocalRepository

List of usage examples for org.apache.maven.execution DefaultMavenExecutionRequest setLocalRepository

Introduction

In this page you can find the example usage for org.apache.maven.execution DefaultMavenExecutionRequest setLocalRepository.

Prototype

@Override
    public MavenExecutionRequest setLocalRepository(ArtifactRepository localRepository) 

Source Link

Usage

From source file:com.google.gdt.eclipse.maven.e35.configurators.GoogleProjectConfigurator.java

License:Open Source License

@Override
protected void doConfigure(final MavenProject mavenProject, IProject project,
        ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException {

    final IMaven maven = MavenPlugin.getDefault().getMaven();

    boolean configureGaeNatureSuccess = configureNature(project, mavenProject, GaeNature.NATURE_ID, true,
            new NatureCallbackAdapter() {

                @Override//ww w  .  ja  va2 s  .  c o  m
                public void beforeAddingNature() {
                    try {
                        DefaultMavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
                        executionRequest.setBaseDirectory(mavenProject.getBasedir());
                        executionRequest.setLocalRepository(maven.getLocalRepository());
                        executionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
                        executionRequest
                                .setPluginArtifactRepositories(mavenProject.getPluginArtifactRepositories());
                        executionRequest.setPom(mavenProject.getFile());
                        executionRequest.setGoals(GAE_UNPACK_GOAL);

                        MavenExecutionResult result = maven.execute(executionRequest, monitor);
                        if (result.hasExceptions()) {
                            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                                    "Error configuring project", result.getExceptions().get(0)));
                        }
                    } catch (CoreException e) {
                        Activator.getDefault().getLog().log(
                                new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", e));
                    }
                }
            }, monitor);

    boolean configureGWTNatureSuccess = configureNature(project, mavenProject, GWTNature.NATURE_ID, true,
            new NatureCallbackAdapter() {

                @Override
                public void beforeAddingNature() {

                    // Get the GWT version from the project pom
                    String gwtVersion = null;
                    List<Dependency> dependencies = mavenProject.getDependencies();
                    for (Dependency dependency : dependencies) {
                        if (GWTMavenRuntime.MAVEN_GWT_GROUP_ID.equals(dependency.getGroupId())
                                && (GWTMavenRuntime.MAVEN_GWT_USER_ARTIFACT_ID
                                        .equals(dependency.getArtifactId())
                                        || GWTMavenRuntime.MAVEN_GWT_SERVLET_ARTIFACT_ID
                                                .equals(dependency.getArtifactId()))) {
                            gwtVersion = dependency.getVersion();
                            break;
                        }
                    }

                    // Check that the pom.xml has GWT dependencies
                    if (!StringUtilities.isEmpty(gwtVersion)) {
                        try {
                            /*
                             * Download and install the gwt-dev.jar into the local
                             * repository.
                             */
                            maven.resolve(GWTMavenRuntime.MAVEN_GWT_GROUP_ID,
                                    GWTMavenRuntime.MAVEN_GWT_DEV_JAR_ARTIFACT_ID, gwtVersion, "jar", null,
                                    mavenProject.getRemoteArtifactRepositories(), monitor);
                        } catch (CoreException e) {
                            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                                    "Error configuring project", e));
                        }
                    }
                }
            }, monitor);

    if (configureGWTNatureSuccess || configureGaeNatureSuccess) {
        try {
            // Add GWT Web Application configuration parameters
            WebAppProjectProperties.setWarSrcDir(project, new Path("src/main/webapp"));
            WebAppProjectProperties.setWarSrcDirIsOutput(project, false);

            String artifactId = mavenProject.getArtifactId();
            String version = mavenProject.getVersion();
            IPath location = (project.getRawLocation() != null ? project.getRawLocation()
                    : project.getLocation());
            if (location != null && artifactId != null && version != null) {
                WebAppProjectProperties.setLastUsedWarOutLocation(project,
                        location.append("target").append(artifactId + "-" + version));
            }
        } catch (BackingStoreException be) {
            Activator.getDefault().getLog()
                    .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error configuring project", be));
        }
    }
}

From source file:org.springframework.ide.eclipse.maven.legacy.internal.core.GoogleProjectConfigurator.java

License:Open Source License

/**
 * {@inheritDoc}//  w w w . j  a  va 2 s  .com
 */
@Override
protected void doConfigure(final MavenProject mavenProject, IProject project,
        ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException {

    final IMaven maven = MavenPlugin.getDefault().getMaven();

    configureNature(project, mavenProject, GAE_NATURE_ID, true, new NatureCallbackAdapter() {

        @Override
        public void beforeAddingNature() {
            try {
                DefaultMavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
                executionRequest.setBaseDirectory(mavenProject.getBasedir());
                executionRequest.setLocalRepository(maven.getLocalRepository());
                executionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
                executionRequest.setPluginArtifactRepositories(mavenProject.getPluginArtifactRepositories());
                executionRequest.setPom(mavenProject.getFile());
                executionRequest.setGoals(GAE_UNPACK_GOAL);

                MavenExecutionResult result = maven.execute(executionRequest, monitor);
                if (result.hasExceptions()) {
                    MavenCorePlugin.getDefault().getLog()
                            .log(new Status(IStatus.ERROR, MavenCorePlugin.NON_LEGACY_PLUGIN_ID,
                                    "Error configuring project", result.getExceptions().get(0)));
                }
            } catch (CoreException e) {
                MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                        MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
            }
        }
    }, monitor);

    if (configureNature(project, mavenProject, GWT_NATURE_ID, true, new NatureCallbackAdapter() {

        @Override
        public void beforeAddingNature() {

            // Get the GWT version from the project pom
            String gwtVersion = null;
            List<Dependency> dependencies = mavenProject.getDependencies();
            for (Dependency dependency : dependencies) {
                if (GWT_GROUP_ID.equals(dependency.getGroupId())
                        && ("gwt-user".equals(dependency.getArtifactId())
                                || "gwt-servlet".equals(dependency.getArtifactId()))) {
                    gwtVersion = dependency.getVersion();
                    break;
                }
            }

            // Check that the pom.xml has GWT dependencies
            if (StringUtils.hasLength(gwtVersion)) {
                try {
                    // Download and install the gwt-dev.jar into the local repository
                    maven.resolve(GWT_GROUP_ID, "gwt-dev", gwtVersion, "jar", null,
                            mavenProject.getRemoteArtifactRepositories(), monitor);
                } catch (CoreException e) {
                    MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                            MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
                }
            }
        }
    }, monitor)) {

        try {
            // Add GWT Web Application configuration parameters
            IEclipsePreferences prefs = SpringCorePreferences
                    .getProjectPreferences(project, "com.google.gdt.eclipse.core").getProjectPreferences();
            prefs.put("warSrcDir", "src/main/webapp");
            prefs.putBoolean("warSrcDirIsOutput", false);

            String artifactId = mavenProject.getArtifactId();
            String version = mavenProject.getVersion();
            IPath location = SpringCoreUtils.getProjectLocation(project);
            if (location != null && artifactId != null && version != null) {
                prefs.put("lastWarOutDir", location.append("target").append(artifactId + "-" + version).toFile()
                        .getAbsolutePath());
            }

            prefs.flush();
        } catch (BackingStoreException e) {
            MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                    MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
        }
    }
}