Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Maven plugin extension API #2380

Merged
merged 3 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2020 Google LLC.
*
* Licensed 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.
*/

package com.google.cloud.tools.jib.maven.extension;

import com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan;
import com.google.cloud.tools.jib.plugins.extension.ExtensionLogger;
import com.google.cloud.tools.jib.plugins.extension.JibPluginExtension;
import com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException;

/**
* Jib Maven plugin extension API.
*
* <p>If a class implementing the interface is visible on the classpath of the Jib Maven plugin and
* the plugin is configured to load the extension class, the Jib plugin extension framework calls
* the interface method of the class.
*/
public interface JibMavenPluginExtension extends JibPluginExtension {

/**
* Extends the build plan prepared by the Jib Maven plugin.
*
* @param buildPlan original build plan prepared by the Jib Maven plugin
* @param mavenData {@link MavenData} providing Maven-specific data and properties
* @param logger logger for writing log messages
* @return updated build plan
* @throws JibPluginExtensionException if an error occurs while running the plugin extension
*/
ContainerBuildPlan extendContainerBuildPlan(
ContainerBuildPlan buildPlan, MavenData mavenData, ExtensionLogger logger)
throws JibPluginExtensionException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020 Google LLC.
*
* Licensed 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.
*/

package com.google.cloud.tools.jib.maven.extension;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;

/** Holds Maven-specific data and properties. */
public interface MavenData {

MavenProject getMavenProject();

MavenSession getMavenSession();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2020 Google LLC.
*
* Licensed 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.
*/

package com.google.cloud.tools.jib.plugins.extension;

/** Logger for plugin extensions. */
public interface ExtensionLogger {

/** Levels for log messages generated by plugin extensions, in order of verbosity. */
enum LogLevel {
ERROR,
WARN,
LIFECYCLE,
INFO,
DEBUG
}

void log(LogLevel level, String message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2020 Google LLC.
*
* Licensed 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.
*/

package com.google.cloud.tools.jib.plugins.extension;

/** Base type for Jib plugin extensions. */
public interface JibPluginExtension {}
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2020 Google LLC.
*
* Licensed 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.
*/

package com.google.cloud.tools.jib.plugins.extension;

/** Exception while running Jib plugin extensions. */
public class JibPluginExtensionException extends Exception {

private final Class<? extends JibPluginExtension> extensionClass;

/**
* Constructs a new exception.
*
* @param extensionClass plugin extension creating the exception
* @param message the detail message
*/
public JibPluginExtensionException(
Class<? extends JibPluginExtension> extensionClass, String message) {
super(message);
this.extensionClass = extensionClass;
}

/**
* Constructs a new exception.
*
* @param extensionClass plugin extension creating the exception
* @param message the detail message
* @param cause the cause
*/
public JibPluginExtensionException(
Class<? extends JibPluginExtension> extensionClass, String message, Throwable cause) {
super(message, cause);
this.extensionClass = extensionClass;
}

/**
* Returns the originating extension class.
*
* @return originating extension class
*/
public Class<? extends JibPluginExtension> getExtensionClass() {
return extensionClass;
}
}