org.codehaus.mojo.weblogic.AbstractWeblogicMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weblogic-maven-plugin Show documentation
Show all versions of weblogic-maven-plugin Show documentation
This plugin will support various tasks within the Weblogic 8.1,
9.x, 10.x and 12.x environment. This version starts to support weblogic 10 and
11. The mojo supports such tasks as deploy,
undeploy,clientgen,servicegen, and appc are supported as well as
many others. The plugin uses exposed API's that are subject to
change but have been tested in 8.1 SP 4-6 and 9.0 - 9.2 MP3, 10.x.
There are two versions of the plugin to support the two
environments based on differences in the JDK. The 9.x version is
currently being refactored to support the standard JSR supported
deployment interface. The code used in the plugin has been
contributed to the Cargo project however to date has not be
integrated into the codebase. Please feel free to suggest
improvements or help support this plugin effort.
The newest version!
package org.codehaus.mojo.weblogic;
/*
* Copyright 2008 The Apache Software Foundation.
*
* 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.
*/
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
import java.util.Set;
/**
* This class wraps handling for common functions for all weblogic
* plugin implementations. Specifically, this class manages the
* all important 'weblogic.home' property.
*
* @author Jon Osborn
* @version $Id: AbstractWeblogicMojo.java 17525 2012-09-16 13:39:50Z jonnio $
* @description Abstract base class for weblogic mojo
*/
public abstract class AbstractWeblogicMojo
extends AbstractMojo {
/**
* Property key for weblogic.home
*/
public static final String WEBLOGIC_HOME_KEY = "weblogic.home";
/**
* Property to set the weblogic home
*
* @parameter default-value="${weblogic.home}"
*/
private String weblogicHome;
/**
* This is the set of artifacts that are defined as part of this project's
* pom which are active for the compile scope. You should not need to
* override this unless your pom file is incomplete.
*
* @parameter expression="${project.artifacts}"
* @required
* @readonly
*/
private Set artifacts;
/**
* This is the set of dependencies that are defined as part of this project's
* pom which are active for the scope. You should not need to
* override this unless your pom file is incomplete.
*
* @parameter expression="${project.dependencies}"
* @required
* @readonly
*/
private List dependencies;
/**
* These are the plugin artifacts for the weblogic mojo
*
* @parameter expression="${plugin.artifacts}"
*/
private List pluginArtifacts;
/**
* This is the output directory for the artifacts. It defaults to
* $project.build.directory.
*
* @parameter expression="${project.build.directory}"
*/
private String outputDirectory;
/**
* The artifact factory
*
* @component
*/
private ArtifactFactory artifactFactory;
/**
* @component
*/
private ArtifactResolver resolver;
/**
* The local repository
*
* @parameter expression="${localRepository}"
*/
private ArtifactRepository localRepository;
/**
* The list of remote repositories
*
* @parameter expression="${project.remoteArtifactRepositories}"
*/
private List remoteRepositories;
/**
* The the location of tools.jar file. this file must be dynamically added
* to the classloader due to some issues with the way maven works and a bug
* in jdk 1.6
* Note that the java.home location should be to the jre not the jdk
*
* @parameter expression="${java.home}/../lib/tools.jar"
*/
private String toolsJar;
/**
* Getter for weblogic.home
*
* @return weblogic.home
*/
public String getWeblogicHome() {
return weblogicHome;
}
/**
* Setter for weblogic.home
*
* @param weblogicHome - a fully qualified path to weblogic home directory
*/
public void setWeblogicHome(String weblogicHome) {
this.weblogicHome = weblogicHome;
}
/**
* Getter for property artifacts.
*
* @return The value of artifacts.
*/
public Set getArtifacts() {
return artifacts;
}
/**
* Setter for the artifacts.
*
* @param inArtifacts The value of artifacts.
*/
public final void setArtifacts(Set inArtifacts) {
this.artifacts = inArtifacts;
}
/**
* Sets system property for weblogic.home
*
* @see #weblogicHome
*/
public void execute()
throws MojoExecutionException {
setProperties();
createTargetDirectory();
}
/**
* Sets the weblogic.home property
*
* @see #WEBLOGIC_HOME_KEY
* @see System#setProperty(String, String)
*/
protected void setProperties() {
if (System.getProperty(WEBLOGIC_HOME_KEY) == null ||
System.getProperty(WEBLOGIC_HOME_KEY).trim().length() == 0) {
if (getLog().isInfoEnabled()) {
getLog().info(" Setting " + WEBLOGIC_HOME_KEY + " = " + this.weblogicHome);
}
if (this.weblogicHome == null && getLog().isWarnEnabled()) {
getLog().warn(" Is the property weblogicHome configured? Users should configure this property " +
"to help weblogic functions perform as expected.");
} else if (this.weblogicHome != null) {
final File home = new File(this.weblogicHome);
if (!home.exists()) {
getLog().warn("weblogic.home folder '" + this.weblogicHome + "' does not appear to exist. This " +
"may cause issues with some weblogic functions.");
}
System.setProperty(WEBLOGIC_HOME_KEY, this.weblogicHome);
}
} else {
if (getLog().isDebugEnabled()) {
getLog().debug(
"weblogicHome property was set externally to '" + System.getProperty(WEBLOGIC_HOME_KEY) + "'.");
}
}
}
/**
* Load tools jar into the selected classloader. We need to do it this way
* because the addURL method is protected on the classloader. This is for a bug in 1.6
* tools.jar implementations
*
* @param classLoader the classloader to load
* @throws Exception
*/
protected void addToolsJar(ClassLoader classLoader) throws Exception {
if (this.toolsJar == null ||
this.toolsJar.trim().length() == 0) {
throw new MojoExecutionException(
"toolsJar is required for this mojo.");
}
final File f = new File(this.toolsJar);
if (!f.exists()) {
throw new MojoExecutionException(
"toolsJar was supplied but not found. was java.home correct?");
}
try {
final URL u = f.toURI().toURL();
final Class urlClass = URLClassLoader.class;
final Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
method.invoke(classLoader, new Object[]{u});
} catch (Exception e) {
throw new MojoExecutionException("Exceptions while setting up the classloader", e);
}
}
/**
* Generate a logger by using the default settings.
*
* @return a default logger that logs to System.out and System.err
*/
protected BuildListener getDefaultLogger() {
final DefaultLogger antLogger = new DefaultLogger();
antLogger.setOutputPrintStream(System.out);
antLogger.setErrorPrintStream(System.err);
antLogger
.setMessageOutputLevel(getLog().isDebugEnabled() ? Project.MSG_DEBUG : Project.MSG_INFO);
return antLogger;
}
/**
* Creates the target directory if it is missing from the file system.
*/
protected void createTargetDirectory() {
final File file = new File(this.outputDirectory);
if (!file.exists()) {
file.mkdir();
}
}
/**
* Getter for the outputDirectory
*
* @return - this.outputDirectory
*/
public String getOutputDirectory() {
return this.outputDirectory;
}
/**
* Setter for the output directory
*
* @param outputDirectory - the directory to write to
*/
public void setOutputDirectory(String outputDirectory) {
this.outputDirectory = outputDirectory;
}
/**
* Getter for the list of dependencies
*
* @return the dependencies
*/
public List getDependencies() {
return dependencies;
}
/**
* Setter for the dependencies
*
* @param dependencies the dependencies to set
*/
public void setDependencies(List dependencies) {
this.dependencies = dependencies;
}
/**
* The artifacts managed to the plugin
*
* @return the list of plugin artifacts
*/
public List getPluginArtifacts() {
return pluginArtifacts;
}
/**
* Setter for the plugin artifacts
*
* @param pluginArtifacts the artifacts to set
*/
public void setPluginArtifacts(List pluginArtifacts) {
this.pluginArtifacts = pluginArtifacts;
}
public ArtifactFactory getArtifactFactory() {
return artifactFactory;
}
public void setArtifactFactory(ArtifactFactory artifactFactory) {
this.artifactFactory = artifactFactory;
}
public ArtifactResolver getResolver() {
return resolver;
}
public void setResolver(ArtifactResolver resolver) {
this.resolver = resolver;
}
public ArtifactRepository getLocalRepository() {
return localRepository;
}
public void setLocalRepository(ArtifactRepository localRepository) {
this.localRepository = localRepository;
}
public List getRemoteRepositories() {
return remoteRepositories;
}
public void setRemoteRepositories(List remoteRepositories) {
this.remoteRepositories = remoteRepositories;
}
protected File getWeblogicJar() {
return new File(this.weblogicHome + "/server/lib/weblogic.jar");
}
protected File[] getWseeClientJars() {
final File dir = new File(this.weblogicHome + "/server/lib/wseeclient");
if (getLog().isDebugEnabled()) {
getLog().debug("WSEE Client Files Dir Exists: " + dir.exists());
getLog().debug("FILES: ");
if (dir.listFiles() != null) {
for (File f : dir.listFiles()) {
getLog().debug(f.getAbsolutePath());
}
}
}
return dir.listFiles() != null ? dir.listFiles() : new File[0];
}
/**
* Getter for the toolsJar value
*
* @return the location of toolsJar on disk
*/
public String getToolsJar() {
return toolsJar;
}
/**
* the setter for tools jar
*
* @param toolsJar the location on disk
*/
public void setToolsJar(String toolsJar) {
this.toolsJar = toolsJar;
}
/**
* Meaningful toString
*
* @return the string representation of this object
*/
public String toString() {
return "AbstractWeblogicMojo{" + "weblogicHome='" + weblogicHome + '\'' + ", artifacts=" + artifacts +
", dependencies=" + dependencies + ", pluginArtifacts=" + pluginArtifacts + ", outputDirectory='" +
outputDirectory + '\'' + '}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy