diff --git a/buildSrc/src/main/groovy/org/opensearch/gradle/test/TestWithSslPlugin.java b/buildSrc/src/main/groovy/org/opensearch/gradle/test/TestWithSslPlugin.java index 33e8966bd32c1..ff1ecfd7de578 100644 --- a/buildSrc/src/main/groovy/org/opensearch/gradle/test/TestWithSslPlugin.java +++ b/buildSrc/src/main/groovy/org/opensearch/gradle/test/TestWithSslPlugin.java @@ -49,6 +49,7 @@ public class TestWithSslPlugin implements Plugin { @Override + @SuppressWarnings({ "unchecked" }) public void apply(Project project) { File keyStoreDir = new File(project.getBuildDir(), "keystore"); TaskProvider exportKeyStore = project.getTasks() diff --git a/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java index 5ca092a28cd4a..b5af379d8b67d 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java @@ -121,8 +121,8 @@ public String call() throws Exception { }); }); publishing.getPublications().withType(MavenPublication.class, publication -> { - //To exclude java artifcats for maven zip type publications - String zipPublicationSearch = "zip"; + // To exclude java artifcats for maven zip type publications + String zipPublicationSearch = "zip"; if (!publication.getName().toLowerCase().contains(zipPublicationSearch.toLowerCase())) { // Add git origin info to generated POM files publication.getPom().withXml(PublishPlugin::addScmInfo); @@ -134,9 +134,9 @@ public String call() throws Exception { if (project.getPluginManager().hasPlugin("opensearch.java")) { publication.artifact(project.getTasks().getByName("sourcesJar")); publication.artifact(project.getTasks().getByName("javadocJar")); - generatePomTask.configure( t -> { - t.dependsOn(String.format("generatePomFileFor%sPublication", Util.capitalize(publication.getName()))); - }); + generatePomTask.configure( + t -> { t.dependsOn(String.format("generatePomFileFor%sPublication", Util.capitalize(publication.getName()))); } + ); } } }); diff --git a/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublish.java b/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublish.java index 4200cbccd385f..35ca50b489708 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublish.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublish.java @@ -1,20 +1,44 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ package org.opensearch.gradle.zipplugin; import java.util.*; import org.gradle.api.Plugin; import org.gradle.api.Project; -import org.gradle.api.provider.Property; import org.gradle.api.publish.PublishingExtension; import org.gradle.api.publish.maven.MavenPublication; import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; -import org.gradle.api.file.DirectoryProperty; -import org.gradle.api.provider.Provider; import java.nio.file.Path; -import org.opensearch.gradle.zipplugin.ZipPublishExtension; -import org.gradle.api.tasks.TaskAction; import org.gradle.api.Task; -import org.opensearch.gradle.zipplugin.ZipPublishUtil; - public class ZipPublish implements Plugin { private Project project; @@ -22,8 +46,14 @@ public class ZipPublish implements Plugin { public final static String EXTENSION_NAME = "zipmavensettings"; public final static String PUBLICATION_NAME = "mavenzip"; public final static String STAGING_REPO = "zipstaging"; - public final static String MAVEN_ZIP_PUBLISH_TASK = "publish" + ZipPublishUtil.capitalize(PUBLICATION_NAME) + "PublicationTo" + ZipPublishUtil.capitalize(STAGING_REPO) + "Repository"; - public final static String MAVEN_ZIP_PUBLISH_POM_TASK = "generatePomFileFor" + ZipPublishUtil.capitalize(PUBLICATION_NAME) + "Publication"; + public final static String MAVEN_ZIP_PUBLISH_TASK = "publish" + + ZipPublishUtil.capitalize(PUBLICATION_NAME) + + "PublicationTo" + + ZipPublishUtil.capitalize(STAGING_REPO) + + "Repository"; + public final static String MAVEN_ZIP_PUBLISH_POM_TASK = "generatePomFileFor" + + ZipPublishUtil.capitalize(PUBLICATION_NAME) + + "Publication"; public final static String LOCALMAVEN = "publishToMavenLocal"; public final static String LOCAL_STAGING_REPO_PATH = "/build/local-staging-repo"; public final static String BUILD_DISTRIBUTIONS_LOCATION = "/build/distributions/"; @@ -42,25 +72,26 @@ private void configMaven() { publishing.publications(publications -> { publications.create(PUBLICATION_NAME, MavenPublication.class, mavenZip -> { ZipPublishExtension extset = this.project.getExtensions().findByType(ZipPublishExtension.class); - //Getting the Zip group from created extension + // Getting the Zip group from created extension String zipGroup = extset.getZipgroup(); String zipArtifact = getProperty("zipArtifact"); - //Getting the Zip version from gradle property with/without added snapshot and qualifier + // Getting the Zip version from gradle property with/without added snapshot and qualifier String zipVersion = getProperty("zipVersion"); String version = ""; String extraSuffix = ""; - if (zipVersion != null){ - StringTokenizer st = new StringTokenizer(zipVersion); - version = st.nextToken("-") + ".0"; + if (zipVersion != null) { + StringTokenizer st = new StringTokenizer(zipVersion); + version = st.nextToken("-") + ".0"; try { extraSuffix = zipVersion.substring(zipVersion.indexOf("-")); } catch (Exception e) { System.out.println(""); } - }; + } + ; String finalZipVersion = version + extraSuffix; String zipFilePath = BUILD_DISTRIBUTIONS_LOCATION + zipArtifact + "-" + finalZipVersion + ".zip"; - //-PzipFilePath=/build/distributions/opensearch-job-scheduler-2.0.0.0-alpha1-SNAPSHOT.zip + // -PzipFilePath=/build/distributions/opensearch-job-scheduler-2.0.0.0-alpha1-SNAPSHOT.zip mavenZip.artifact(buildDirectory.toString() + zipFilePath); mavenZip.setGroupId(zipGroup); mavenZip.setArtifactId(zipArtifact); @@ -69,6 +100,7 @@ private void configMaven() { }); }); } + private String getProperty(String name) { if (this.project.hasProperty(name)) { Object property = this.project.property(name); @@ -84,22 +116,22 @@ public void apply(Project project) { final Path buildDirectory = project.getRootDir().toPath(); this.project = project; project.getExtensions().create(EXTENSION_NAME, ZipPublishExtension.class); - //Applies the new publication once the plugin is applied + // Applies the new publication once the plugin is applied configMaven(); Task compileJava = project.getTasks().findByName("compileJava"); - if(compileJava != null) { + if (compileJava != null) { compileJava.setEnabled(false); } Task sourceJarTask = project.getTasks().findByName("sourcesJar"); - if(sourceJarTask != null) { + if (sourceJarTask != null) { sourceJarTask.setEnabled(false); } Task javaDocJarTask = project.getTasks().findByName("javadocJar"); - if(javaDocJarTask != null) { + if (javaDocJarTask != null) { javaDocJarTask.setEnabled(false); } project.getGradle().getTaskGraph().whenReady(graph -> { - if (graph.hasTask(LOCALMAVEN)){ + if (graph.hasTask(LOCALMAVEN)) { project.getTasks().getByName(MAVEN_ZIP_PUBLISH_POM_TASK).setEnabled(false); } diff --git a/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublishExtension.java b/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublishExtension.java index 38f09fc5de8fa..8d3a4cc2d2a6d 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublishExtension.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublishExtension.java @@ -1,15 +1,46 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ package org.opensearch.gradle.zipplugin; public class ZipPublishExtension { private String zipGroup = "org.opensearch.plugin"; - public void setZipgroup(String zipGroup){ - this.zipGroup=zipGroup; + public void setZipgroup(String zipGroup) { + this.zipGroup = zipGroup; } - public String getZipgroup(){ + + public String getZipgroup() { return zipGroup; } } - diff --git a/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublishUtil.java b/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublishUtil.java index 7ddf8018c98f7..b31ea602a919c 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublishUtil.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/zipplugin/ZipPublishUtil.java @@ -1,3 +1,34 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ package org.opensearch.gradle.zipplugin; class ZipPublishUtil { diff --git a/buildSrc/src/test/groovy/org/opensearch/gradle/zipplugin/ZipPublishTest.groovy b/buildSrc/src/test/groovy/org/opensearch/gradle/zipplugin/ZipPublishTest.groovy index aa4b2887e2c7d..f80f32f3852d8 100644 --- a/buildSrc/src/test/groovy/org/opensearch/gradle/zipplugin/ZipPublishTest.groovy +++ b/buildSrc/src/test/groovy/org/opensearch/gradle/zipplugin/ZipPublishTest.groovy @@ -1,3 +1,34 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ package org.opensearch.gradle.zipplugin; import org.gradle.testfixtures.ProjectBuilder