Skip to content

Commit

Permalink
fixed failure checks
Browse files Browse the repository at this point in the history
Signed-off-by: pgodithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Apr 20, 2022
1 parent 4a61852 commit 1e8c5f1
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
public class TestWithSslPlugin implements Plugin<Project> {

@Override
@SuppressWarnings({ "unchecked" })
public void apply(Project project) {
File keyStoreDir = new File(project.getBuildDir(), "keystore");
TaskProvider<ExportOpenSearchBuildResourcesTask> exportKeyStore = project.getTasks()
Expand Down
10 changes: 5 additions & 5 deletions buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()))); }
);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,59 @@
/*
* 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<Project> {
private Project project;

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/";
Expand All @@ -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);
Expand All @@ -69,6 +100,7 @@ private void configMaven() {
});
});
}

private String getProperty(String name) {
if (this.project.hasProperty(name)) {
Object property = this.project.property(name);
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}

Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 1e8c5f1

Please sign in to comment.