Search in sources :

Example 6 with IConventionAware

use of org.gradle.api.internal.IConventionAware in project gradle by gradle.

the class EclipsePlugin method configureEclipseJdt.

private void configureEclipseJdt(final Project project, final EclipseModel model) {
    final EclipsePlugin eclipsePlugin = this;
    project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

        @Override
        public void execute(JavaBasePlugin javaBasePlugin) {
            maybeAddTask(project, eclipsePlugin, ECLIPSE_JDT_TASK_NAME, GenerateEclipseJdt.class, new Action<GenerateEclipseJdt>() {

                @Override
                public void execute(GenerateEclipseJdt task) {
                    //task properties:
                    task.setDescription("Generates the Eclipse JDT settings file.");
                    task.setOutputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
                    task.setInputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
                    //model properties:
                    EclipseJdt jdt = task.getJdt();
                    model.setJdt(jdt);
                    ConventionMapping conventionMapping = ((IConventionAware) jdt).getConventionMapping();
                    conventionMapping.map("sourceCompatibility", new Callable<JavaVersion>() {

                        @Override
                        public JavaVersion call() {
                            return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility();
                        }
                    });
                    conventionMapping.map("targetCompatibility", new Callable<JavaVersion>() {

                        @Override
                        public JavaVersion call() {
                            return project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility();
                        }
                    });
                    conventionMapping.map("javaRuntimeName", new Callable<String>() {

                        @Override
                        public String call() {
                            return eclipseJavaRuntimeNameFor(project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility());
                        }
                    });
                }
            });
        }
    });
}
Also used : EclipseJdt(org.gradle.plugins.ide.eclipse.model.EclipseJdt) Action(org.gradle.api.Action) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 7 with IConventionAware

use of org.gradle.api.internal.IConventionAware 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)

Example 8 with IConventionAware

use of org.gradle.api.internal.IConventionAware in project gradle by gradle.

the class IdeaPlugin method configureIdeaProject.

private void configureIdeaProject(final Project project) {
    if (isRoot(project)) {
        final GenerateIdeaProject task = project.getTasks().create("ideaProject", GenerateIdeaProject.class);
        task.setDescription("Generates IDEA project file (IPR)");
        XmlFileContentMerger ipr = new XmlFileContentMerger(task.getXmlTransformer());
        IdeaProject ideaProject = instantiator.newInstance(IdeaProject.class, project, ipr);
        task.setIdeaProject(ideaProject);
        ideaModel.setProject(ideaProject);
        ideaProject.setOutputFile(new File(project.getProjectDir(), project.getName() + ".ipr"));
        ConventionMapping conventionMapping = ((IConventionAware) ideaProject).getConventionMapping();
        conventionMapping.map("jdkName", new Callable<String>() {

            @Override
            public String call() throws Exception {
                return JavaVersion.current().toString();
            }
        });
        conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {

            @Override
            public IdeaLanguageLevel call() throws Exception {
                JavaVersion maxSourceCompatibility = getMaxJavaModuleCompatibilityVersionFor(SOURCE_COMPATIBILITY);
                return new IdeaLanguageLevel(maxSourceCompatibility);
            }
        });
        conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {

            @Override
            public JavaVersion call() throws Exception {
                return getMaxJavaModuleCompatibilityVersionFor(TARGET_COMPATIBILITY);
            }
        });
        ideaProject.setWildcards(Sets.newHashSet("!?*.class", "!?*.scala", "!?*.groovy", "!?*.java"));
        conventionMapping.map("modules", new Callable<List<IdeaModule>>() {

            @Override
            public List<IdeaModule> call() throws Exception {
                return Lists.newArrayList(Iterables.transform(Sets.filter(project.getRootProject().getAllprojects(), new Predicate<Project>() {

                    @Override
                    public boolean apply(Project p) {
                        return p.getPlugins().hasPlugin(IdeaPlugin.class);
                    }
                }), new Function<Project, IdeaModule>() {

                    @Override
                    public IdeaModule apply(Project p) {
                        return ideaModelFor(p).getModule();
                    }
                }));
            }
        });
        conventionMapping.map("pathFactory", new Callable<PathFactory>() {

            @Override
            public PathFactory call() throws Exception {
                return new PathFactory().addPathVariable("PROJECT_DIR", task.getOutputFile().getParentFile());
            }
        });
        addWorker(task);
    }
}
Also used : IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) PathFactory(org.gradle.plugins.ide.idea.model.PathFactory) XmlFileContentMerger(org.gradle.plugins.ide.api.XmlFileContentMerger) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) Predicate(com.google.common.base.Predicate) Project(org.gradle.api.Project) IdeaProject(org.gradle.plugins.ide.idea.model.IdeaProject) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) List(java.util.List) File(java.io.File) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 9 with IConventionAware

use of org.gradle.api.internal.IConventionAware in project gradle by gradle.

the class SigningExtension method addSignatureSpecConventions.

/**
     * Adds conventions to the given spec, using this settings object's default signatory and signature type as the default signatory and signature type for the spec.
     */
protected void addSignatureSpecConventions(SignatureSpec spec) {
    if (!(spec instanceof IConventionAware)) {
        throw new InvalidUserDataException("Cannot add conventions to signature spec \'" + String.valueOf(spec) + "\' as it is not convention aware");
    }
    ConventionMapping conventionMapping = ((IConventionAware) spec).getConventionMapping();
    conventionMapping.map("signatory", new Callable<Signatory>() {

        public Signatory call() {
            return getSignatory();
        }
    });
    conventionMapping.map("signatureType", new Callable<SignatureType>() {

        public SignatureType call() {
            return getSignatureType();
        }
    });
    conventionMapping.map("required", new Callable<Boolean>() {

        public Boolean call() {
            return isRequired();
        }
    });
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) Signatory(org.gradle.plugins.signing.signatory.Signatory) SignatureType(org.gradle.plugins.signing.type.SignatureType) DefaultTypeTransformation.castToBoolean(org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean) IConventionAware(org.gradle.api.internal.IConventionAware) ConventionMapping(org.gradle.api.internal.ConventionMapping)

Example 10 with IConventionAware

use of org.gradle.api.internal.IConventionAware in project gradle by gradle.

the class OsgiPluginConvention method createDefaultOsgiManifest.

private OsgiManifest createDefaultOsgiManifest() {
    OsgiManifest osgiManifest = project.getServices().get(Instantiator.class).newInstance(DefaultOsgiManifest.class, project.getFileResolver());
    ConventionMapping mapping = ((IConventionAware) osgiManifest).getConventionMapping();
    final OsgiHelper osgiHelper = new OsgiHelper();
    mapping.map("version", new Callable<Object>() {

        public Object call() throws Exception {
            return osgiHelper.getVersion(project.getVersion().toString());
        }
    });
    mapping.map("name", new Callable<Object>() {

        public Object call() throws Exception {
            return project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
        }
    });
    mapping.map("symbolicName", new Callable<Object>() {

        public Object call() throws Exception {
            return osgiHelper.getBundleSymbolicName(project);
        }
    });
    return osgiManifest;
}
Also used : DefaultOsgiManifest(org.gradle.api.internal.plugins.osgi.DefaultOsgiManifest) Instantiator(org.gradle.internal.reflect.Instantiator) OsgiHelper(org.gradle.api.internal.plugins.osgi.OsgiHelper) ConventionMapping(org.gradle.api.internal.ConventionMapping) IConventionAware(org.gradle.api.internal.IConventionAware)

Aggregations

IConventionAware (org.gradle.api.internal.IConventionAware)14 ConventionMapping (org.gradle.api.internal.ConventionMapping)11 Callable (java.util.concurrent.Callable)8 File (java.io.File)5 Configuration (org.gradle.api.artifacts.Configuration)5 JavaScriptExtension (org.gradle.plugins.javascript.base.JavaScriptExtension)4 RhinoExtension (org.gradle.plugins.javascript.rhino.RhinoExtension)3 List (java.util.List)2 Set (java.util.Set)2 Action (org.gradle.api.Action)2 JavaVersion (org.gradle.api.JavaVersion)2 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)2 ReportingExtension (org.gradle.api.reporting.ReportingExtension)2 IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)2 PathFactory (org.gradle.plugins.ide.idea.model.PathFactory)2 Predicate (com.google.common.base.Predicate)1 DefaultTypeTransformation.castToBoolean (org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1