private OsgiManifest createDefaultOsgiManifest(final ProjectInternal project) { 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; }
@Lazy default String baseName() { return gradleProject() .getConvention() .getPlugin(BasePluginConvention.class) .getArchivesBaseName(); }
@Nullable private String getArchivesBaseName() { BasePluginConvention convention = project.getConvention().findPlugin(BasePluginConvention.class); return convention != null ? convention.getArchivesBaseName() : null; }
/** * Get the symbolic name as group + "." + archivesBaseName, with the following exceptions * <ul> * <li> * if group has only one section (no dots) and archivesBaseName is not null then the first package * name with classes is returned. eg. commons-logging:commons-logging -> org.apache.commons.logging * </li> * <li> * if archivesBaseName is equal to last section of group then group is returned. * eg. org.gradle:gradle -> org.gradle * </li> * <li> * if archivesBaseName starts with last section of group that portion is removed. * eg. org.gradle:gradle-core -> org.gradle.core * </li> * <li> * if archivesBaseName starts with the full group, the archivesBaseName is return, * e.g. org.gradle:org.gradle.core -> org.gradle.core * </li> * </ul> * * @param project The project being processed. * * @return Returns the SymbolicName that should be used for the bundle. */ public String getBundleSymbolicName(Project project) { String group = project.getGroup().toString(); String archiveBaseName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName(); if (archiveBaseName.startsWith(group)) { return archiveBaseName; } int i = group.lastIndexOf('.'); String lastSection = group.substring(++i); if (archiveBaseName.equals(lastSection)) { return group; } if (archiveBaseName.startsWith(lastSection)) { String artifactId = archiveBaseName.substring(lastSection.length()); if (Character.isLetterOrDigit(artifactId.charAt(0))) { return getBundleSymbolicName(group, artifactId); } else { return getBundleSymbolicName(group, artifactId.substring(1)); } } return getBundleSymbolicName(group, archiveBaseName); }
@Override public void apply(Project project) { project.getPluginManager().apply(ApplicationPlugin.class); project.getPluginManager().apply(GitPropertiesPlugin.class); project .getExtensions() .create(ImmutableDeploymentExtension.NAME, DeploymentExtension.class, project); project.getNormalization().getRuntimeClasspath().ignore("git.properties"); project.afterEvaluate( p -> { ImmutableDeploymentExtension config = project.getExtensions().getByType(DeploymentExtension.class); String archivesBaseName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName(); project .getConvention() .getPlugin(ApplicationPluginConvention.class) .setApplicationName(archivesBaseName); GroovyObject docker = project.getExtensions().getByType(DockerExtension.class); DockerJavaApplication javaApplication = (DockerJavaApplication) docker.getProperty("javaApplication"); javaApplication.setBaseImage("openjdk:8-jre"); project.getTasks().getByName("build").dependsOn("dockerDistTar"); for (ImmutableDeploymentConfiguration type : config.getTypes()) { String capitalized = Ascii.toUpperCase(type.getName().charAt(0)) + type.getName().substring(1); DeployConfigMapTask deployConfigMapTask = project .getTasks() .create("deployConfigMap" + capitalized, DeployConfigMapTask.class) .setType(type.getName()); project .getTasks() .create("deploy" + capitalized, DeployPodTask.class) .setType(type.getName()) .dependsOn(deployConfigMapTask); } }); project.getPluginManager().apply(DockerJavaApplicationPlugin.class); }
/** * Get the library directory * * @return Library directory */ public File getLibsDir() { BasePluginConvention baseConvention = this.project.getConvention().getPlugin(BasePluginConvention.class); File libsDir = Validate.notNull(baseConvention.getLibsDir(), "The libs dir must not be null"); return libsDir; }
/** * Create a {@link PublishArtifact} for a jar created by a {@link Jar} task * * We use this instead of {@link ArchivePublishArtifact} because we can add the unresolved task dependency by name, * thus avoiding a direct dependency on the task. * * @param project Project to create artifact for * @param name Name of the new artifact * @param classifier Classifier for new artifact * @param type Type of new artifact * @param extension Extension of new artifact * @param producingTask Task that produces the artifact * @return Publish artifact for the jar */ public static PublishArtifact createJarPublishArtifact(Project project, String name, @Nullable String classifier, String type, String extension, Jar producingTask) { BasePluginConvention baseConvention = project.getConvention().getPlugin(BasePluginConvention.class); String jarName = FILE_PART_JOINER.join(name, project.getVersion(), classifier) + "." + extension; File jarFile = baseConvention.getLibsDir().toPath().resolve(jarName).toFile(); DefaultPublishArtifact artifact = new DefaultPublishArtifact(name, extension, type, classifier, null, jarFile, producingTask); return artifact; }
/** * Provide the base plugin convention * * @param project Project to get convention from * @return Base plugin convention */ @Model @Hidden public BasePluginConvention basePluginConvention(Project project) { return project.getConvention().getPlugin(BasePluginConvention.class); }