Search in sources :

Example 1 with WarPlugin

use of org.gradle.api.plugins.WarPlugin in project gradle by gradle.

the class EclipseWtpPlugin method configureEclipseClasspath.

private void configureEclipseClasspath(final Project project, final EclipseModel model) {
    project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {

        @Override
        public void execute(JavaPlugin javaPlugin) {
            AfterEvaluateHelper.afterEvaluateOrExecute(project, new Action<Project>() {

                @Override
                public void execute(Project project) {
                    Collection<Configuration> plusConfigurations = model.getClasspath().getPlusConfigurations();
                    EclipseWtpComponent component = model.getWtp().getComponent();
                    plusConfigurations.addAll(component.getRootConfigurations());
                    plusConfigurations.addAll(component.getLibConfigurations());
                }
            });
            model.getClasspath().getFile().whenMerged(new Action<Classpath>() {

                @Override
                public void execute(Classpath classpath) {
                    new WtpClasspathAttributeSupport(project, model).enhance(classpath);
                }
            });
        }
    });
    project.getPlugins().withType(WarPlugin.class, new Action<WarPlugin>() {

        @Override
        public void execute(WarPlugin warPlugin) {
            model.getClasspath().containers(WEB_LIBS_CONTAINER);
        }
    });
}
Also used : Project(org.gradle.api.Project) Action(org.gradle.api.Action) WtpClasspathAttributeSupport(org.gradle.plugins.ide.eclipse.model.internal.WtpClasspathAttributeSupport) Configuration(org.gradle.api.artifacts.Configuration) Classpath(org.gradle.plugins.ide.eclipse.model.Classpath) EclipseWtpComponent(org.gradle.plugins.ide.eclipse.model.EclipseWtpComponent) JavaPlugin(org.gradle.api.plugins.JavaPlugin) WarPlugin(org.gradle.api.plugins.WarPlugin)

Example 2 with WarPlugin

use of org.gradle.api.plugins.WarPlugin in project gradle by gradle.

the class EclipseWtpPlugin method configureEclipseWtpComponent.

private void configureEclipseWtpComponent(final Project project, final EclipseModel model) {
    maybeAddTask(project, this, ECLIPSE_WTP_COMPONENT_TASK_NAME, GenerateEclipseWtpComponent.class, new Action<GenerateEclipseWtpComponent>() {

        @Override
        public void execute(final GenerateEclipseWtpComponent task) {
            //task properties:
            task.setDescription("Generates the Eclipse WTP component settings file.");
            task.setInputFile(project.file(".settings/org.eclipse.wst.common.component"));
            task.setOutputFile(project.file(".settings/org.eclipse.wst.common.component"));
            //model properties:
            model.getWtp().setComponent(task.getComponent());
            ((IConventionAware) task.getComponent()).getConventionMapping().map("deployName", new Callable<String>() {

                @Override
                public String call() throws Exception {
                    return model.getProject().getName();
                }
            });
            project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {

                @Override
                public void execute(JavaPlugin javaPlugin) {
                    if (hasWarOrEarPlugin(project)) {
                        return;
                    }
                    task.getComponent().setLibConfigurations(Sets.<Configuration>newHashSet(project.getConfigurations().getByName("runtime")));
                    task.getComponent().setMinusConfigurations(Sets.<Configuration>newHashSet());
                    task.getComponent().setClassesDeployPath("/");
                    ((IConventionAware) task.getComponent()).getConventionMapping().map("libDeployPath", new Callable<String>() {

                        @Override
                        public String call() throws Exception {
                            return "../";
                        }
                    });
                    ((IConventionAware) task.getComponent()).getConventionMapping().map("sourceDirs", new Callable<Set<File>>() {

                        @Override
                        public Set<File> call() throws Exception {
                            return getMainSourceDirs(project);
                        }
                    });
                }
            });
            project.getPlugins().withType(WarPlugin.class, new Action<WarPlugin>() {

                @Override
                public void execute(WarPlugin warPlugin) {
                    task.getComponent().setLibConfigurations(Sets.<Configuration>newHashSet(project.getConfigurations().getByName("runtime")));
                    task.getComponent().setMinusConfigurations(Sets.<Configuration>newHashSet(project.getConfigurations().getByName("providedRuntime")));
                    task.getComponent().setClassesDeployPath("/WEB-INF/classes");
                    ConventionMapping convention = ((IConventionAware) task.getComponent()).getConventionMapping();
                    convention.map("libDeployPath", new Callable<String>() {

                        @Override
                        public String call() throws Exception {
                            return "/WEB-INF/lib";
                        }
                    });
                    convention.map("contextPath", new Callable<String>() {

                        @Override
                        public String call() throws Exception {
                            return ((War) project.getTasks().getByName("war")).getBaseName();
                        }
                    });
                    convention.map("resources", new Callable<List<WbResource>>() {

                        @Override
                        public List<WbResource> call() throws Exception {
                            return Lists.newArrayList(new WbResource("/", project.getConvention().getPlugin(WarPluginConvention.class).getWebAppDirName()));
                        }
                    });
                    convention.map("sourceDirs", new Callable<Set<File>>() {

                        @Override
                        public Set<File> call() throws Exception {
                            return getMainSourceDirs(project);
                        }
                    });
                }
            });
            project.getPlugins().withType(EarPlugin.class, new Action<EarPlugin>() {

                @Override
                public void execute(EarPlugin earPlugin) {
                    task.getComponent().setRootConfigurations(Sets.<Configuration>newHashSet(project.getConfigurations().getByName("deploy")));
                    task.getComponent().setLibConfigurations(Sets.<Configuration>newHashSet(project.getConfigurations().getByName("earlib")));
                    task.getComponent().setMinusConfigurations(Sets.<Configuration>newHashSet());
                    task.getComponent().setClassesDeployPath("/");
                    final ConventionMapping convention = ((IConventionAware) task.getComponent()).getConventionMapping();
                    convention.map("libDeployPath", new Callable<String>() {

                        @Override
                        public String call() throws Exception {
                            String deployPath = ((Ear) project.getTasks().findByName(EarPlugin.EAR_TASK_NAME)).getLibDirName();
                            if (!deployPath.startsWith("/")) {
                                deployPath = "/" + deployPath;
                            }
                            return deployPath;
                        }
                    });
                    convention.map("sourceDirs", new Callable<Set<File>>() {

                        @Override
                        public Set<File> call() throws Exception {
                            return project.files(project.getConvention().getPlugin(EarPluginConvention.class).getAppDirName()).getFiles();
                        }
                    });
                    project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {

                        @Override
                        public void execute(JavaPlugin javaPlugin) {
                            convention.map("sourceDirs", new Callable<Set<File>>() {

                                @Override
                                public Set<File> call() throws Exception {
                                    return getMainSourceDirs(project);
                                }
                            });
                        }
                    });
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) Set(java.util.Set) JavaPlugin(org.gradle.api.plugins.JavaPlugin) ConventionMapping(org.gradle.api.internal.ConventionMapping) Callable(java.util.concurrent.Callable) WbResource(org.gradle.plugins.ide.eclipse.model.WbResource) List(java.util.List) IConventionAware(org.gradle.api.internal.IConventionAware) WarPlugin(org.gradle.api.plugins.WarPlugin) File(java.io.File) EarPlugin(org.gradle.plugins.ear.EarPlugin)

Aggregations

Action (org.gradle.api.Action)2 JavaPlugin (org.gradle.api.plugins.JavaPlugin)2 WarPlugin (org.gradle.api.plugins.WarPlugin)2 File (java.io.File)1 List (java.util.List)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Project (org.gradle.api.Project)1 Configuration (org.gradle.api.artifacts.Configuration)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 IConventionAware (org.gradle.api.internal.IConventionAware)1 EarPlugin (org.gradle.plugins.ear.EarPlugin)1 Classpath (org.gradle.plugins.ide.eclipse.model.Classpath)1 EclipseWtpComponent (org.gradle.plugins.ide.eclipse.model.EclipseWtpComponent)1 WbResource (org.gradle.plugins.ide.eclipse.model.WbResource)1 WtpClasspathAttributeSupport (org.gradle.plugins.ide.eclipse.model.internal.WtpClasspathAttributeSupport)1