Search in sources :

Example 1 with EarPlugin

use of org.gradle.plugins.ear.EarPlugin in project gradle by gradle.

the class EclipseWtpPlugin method configureEclipseWtpFacet.

private void configureEclipseWtpFacet(final Project project, final EclipseModel eclipseModel) {
    TaskProvider<GenerateEclipseWtpFacet> task = project.getTasks().register(ECLIPSE_WTP_FACET_TASK_NAME, GenerateEclipseWtpFacet.class, eclipseModel.getWtp().getFacet());
    task.configure(new Action<GenerateEclipseWtpFacet>() {

        @Override
        public void execute(final GenerateEclipseWtpFacet task) {
            task.setDescription("Generates the Eclipse WTP facet settings file.");
            task.setInputFile(project.file(".settings/org.eclipse.wst.common.project.facet.core.xml"));
            task.setOutputFile(project.file(".settings/org.eclipse.wst.common.project.facet.core.xml"));
        }
    });
    addWorker(task, ECLIPSE_WTP_FACET_TASK_NAME);
    project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {

        @Override
        public void execute(JavaPlugin javaPlugin) {
            if (hasWarOrEarPlugin(project)) {
                return;
            }
            ((IConventionAware) eclipseModel.getWtp().getFacet()).getConventionMapping().map("facets", new Callable<List<Facet>>() {

                @Override
                public List<Facet> call() throws Exception {
                    return Lists.newArrayList(new Facet(Facet.FacetType.fixed, "jst.java", null), new Facet(Facet.FacetType.installed, "jst.utility", "1.0"), new Facet(Facet.FacetType.installed, "jst.java", toJavaFacetVersion(project.getExtensions().getByType(JavaPluginExtension.class).getSourceCompatibility())));
                }
            });
        }
    });
    project.getPlugins().withType(WarPlugin.class, new Action<WarPlugin>() {

        @Override
        public void execute(WarPlugin warPlugin) {
            ((IConventionAware) eclipseModel.getWtp().getFacet()).getConventionMapping().map("facets", new Callable<List<Facet>>() {

                @Override
                public List<Facet> call() throws Exception {
                    return Lists.newArrayList(new Facet(Facet.FacetType.fixed, "jst.java", null), new Facet(Facet.FacetType.fixed, "jst.web", null), new Facet(Facet.FacetType.installed, "jst.web", "2.4"), new Facet(Facet.FacetType.installed, "jst.java", toJavaFacetVersion(project.getExtensions().getByType(JavaPluginExtension.class).getSourceCompatibility())));
                }
            });
        }
    });
    project.getPlugins().withType(EarPlugin.class, new Action<EarPlugin>() {

        @Override
        public void execute(EarPlugin earPlugin) {
            ((IConventionAware) eclipseModel.getWtp().getFacet()).getConventionMapping().map("facets", new Callable<List<Facet>>() {

                @Override
                public List<Facet> call() throws Exception {
                    return Lists.newArrayList(new Facet(Facet.FacetType.fixed, "jst.ear", null), new Facet(Facet.FacetType.installed, "jst.ear", "5.0"));
                }
            });
        }
    });
}
Also used : JavaPlugin(org.gradle.api.plugins.JavaPlugin) Callable(java.util.concurrent.Callable) IConventionAware(org.gradle.api.internal.IConventionAware) WarPlugin(org.gradle.api.plugins.WarPlugin) Facet(org.gradle.plugins.ide.eclipse.model.Facet) EarPlugin(org.gradle.plugins.ear.EarPlugin)

Example 2 with EarPlugin

use of org.gradle.plugins.ear.EarPlugin in project gradle by gradle.

the class EclipseWtpPlugin method configureEclipseWtpComponent.

private void configureEclipseWtpComponent(final Project project, final EclipseModel model) {
    XmlTransformer xmlTransformer = new XmlTransformer();
    xmlTransformer.setIndentation("\t");
    final EclipseWtpComponent component = project.getObjects().newInstance(EclipseWtpComponent.class, project, new XmlFileContentMerger(xmlTransformer));
    model.getWtp().setComponent(component);
    TaskProvider<GenerateEclipseWtpComponent> task = project.getTasks().register(ECLIPSE_WTP_COMPONENT_TASK_NAME, GenerateEclipseWtpComponent.class, component);
    task.configure(new Action<GenerateEclipseWtpComponent>() {

        @Override
        public void execute(final GenerateEclipseWtpComponent task) {
            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"));
        }
    });
    addWorker(task, ECLIPSE_WTP_COMPONENT_TASK_NAME);
    ((IConventionAware) component).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;
            }
            Set<Configuration> libConfigurations = component.getLibConfigurations();
            libConfigurations.add(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
            component.setClassesDeployPath("/");
            ((IConventionAware) component).getConventionMapping().map("libDeployPath", new Callable<String>() {

                @Override
                public String call() throws Exception {
                    return "../";
                }
            });
            ((IConventionAware) component).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) {
            Set<Configuration> libConfigurations = component.getLibConfigurations();
            Set<Configuration> minusConfigurations = component.getMinusConfigurations();
            libConfigurations.add(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
            minusConfigurations.add(project.getConfigurations().getByName("providedRuntime"));
            component.setClassesDeployPath("/WEB-INF/classes");
            ConventionMapping convention = ((IConventionAware) component).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")).getArchiveBaseName().getOrNull();
                }
            });
            convention.map("resources", new Callable<List<WbResource>>() {

                @Override
                public List<WbResource> call() throws Exception {
                    File projectDir = project.getProjectDir();
                    File webAppDir = ((War) project.getTasks().getByName("war")).getWebAppDirectory().get().getAsFile();
                    String webAppDirName = RelativePathUtil.relativePath(projectDir, webAppDir);
                    return Lists.newArrayList(new WbResource("/", webAppDirName));
                }
            });
            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) {
            Set<Configuration> libConfigurations = component.getLibConfigurations();
            Set<Configuration> rootConfigurations = component.getRootConfigurations();
            rootConfigurations.clear();
            rootConfigurations.add(project.getConfigurations().getByName("deploy"));
            libConfigurations.clear();
            libConfigurations.add(project.getConfigurations().getByName("earlib"));
            component.setClassesDeployPath("/");
            final ConventionMapping convention = ((IConventionAware) component).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 WrapUtil.toSet(((Ear) project.getTasks().findByName(EarPlugin.EAR_TASK_NAME)).getAppDirectory().get().getAsFile());
                }
            });
            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) War(org.gradle.api.tasks.bundling.War) Callable(java.util.concurrent.Callable) XmlTransformer(org.gradle.internal.xml.XmlTransformer) EclipseWtpComponent(org.gradle.plugins.ide.eclipse.model.EclipseWtpComponent) WarPlugin(org.gradle.api.plugins.WarPlugin) XmlFileContentMerger(org.gradle.plugins.ide.api.XmlFileContentMerger) ConventionMapping(org.gradle.api.internal.ConventionMapping) WbResource(org.gradle.plugins.ide.eclipse.model.WbResource) Ear(org.gradle.plugins.ear.Ear) IConventionAware(org.gradle.api.internal.IConventionAware) File(java.io.File) EarPlugin(org.gradle.plugins.ear.EarPlugin)

Aggregations

Callable (java.util.concurrent.Callable)2 IConventionAware (org.gradle.api.internal.IConventionAware)2 JavaPlugin (org.gradle.api.plugins.JavaPlugin)2 WarPlugin (org.gradle.api.plugins.WarPlugin)2 EarPlugin (org.gradle.plugins.ear.EarPlugin)2 File (java.io.File)1 Set (java.util.Set)1 Action (org.gradle.api.Action)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 War (org.gradle.api.tasks.bundling.War)1 XmlTransformer (org.gradle.internal.xml.XmlTransformer)1 Ear (org.gradle.plugins.ear.Ear)1 XmlFileContentMerger (org.gradle.plugins.ide.api.XmlFileContentMerger)1 EclipseWtpComponent (org.gradle.plugins.ide.eclipse.model.EclipseWtpComponent)1 Facet (org.gradle.plugins.ide.eclipse.model.Facet)1 WbResource (org.gradle.plugins.ide.eclipse.model.WbResource)1