You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by am...@apache.org on 2004/11/09 02:01:28 UTC
svn commit: rev 56981 - in geronimo/trunk/modules/deployment: . src/conf src/java/org/apache/geronimo/deployment/cli
Author: ammulder
Date: Mon Nov 8 17:01:27 2004
New Revision: 56981
Added:
geronimo/trunk/modules/deployment/src/conf/
geronimo/trunk/modules/deployment/src/conf/manifest.mf
Modified:
geronimo/trunk/modules/deployment/project.properties
geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java
geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandPackage.java
geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandRedeploy.java
geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/DeployTool.java
geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java
geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java
Log:
Enhancements and bug fixes for new deployer
- Add JSR-88 manifest attribute (GERONIMO-459)
- Take exploded modules as well as packed modules (GERONIMO-458)
- Process driver as JAR not class name (GERONIMO-449)
- Prompt for username/password (GERONIMO-443)
- Fix help text and formatting bug
Modified: geronimo/trunk/modules/deployment/project.properties
==============================================================================
--- geronimo/trunk/modules/deployment/project.properties (original)
+++ geronimo/trunk/modules/deployment/project.properties Mon Nov 8 17:01:27 2004
@@ -6,3 +6,4 @@
maven.eclipse.classpath.include=target/xmlbeans
maven.idea.generated.source=xmlbeans
+maven.jar.manifest=${basedir}/src/conf/manifest.mf
Added: geronimo/trunk/modules/deployment/src/conf/manifest.mf
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/deployment/src/conf/manifest.mf Mon Nov 8 17:01:27 2004
@@ -0,0 +1 @@
+J2EE-DeploymentFactory-Implementation-Class: org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl
Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java (original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandDistribute.java Mon Nov 8 17:01:27 2004
@@ -77,28 +77,28 @@
File plan = null;
if(args.length > 0) {
File test = new File(args[0]);
- if(DeployUtils.isJarFile(test)) {
+ if(DeployUtils.isJarFile(test) || test.isDirectory()) {
if(module != null) {
- throw new DeploymentSyntaxException("Module and plan cannot both be JAR files!");
+ throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!");
}
module = test;
} else {
if(plan != null) {
- throw new DeploymentSyntaxException("Module or plan must be a JAR file!");
+ throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
}
plan = test;
}
}
if(args.length > 1) {
File test = new File(args[1]);
- if(DeployUtils.isJarFile(test)) {
+ if(DeployUtils.isJarFile(test) || test.isDirectory()) {
if(module != null) {
- throw new DeploymentSyntaxException("Module and plan cannot both be JAR files!");
+ throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!");
}
module = test;
} else {
if(plan != null) {
- throw new DeploymentSyntaxException("Module or plan must be a JAR file!");
+ throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
}
plan = test;
}
Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandPackage.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandPackage.java (original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandPackage.java Mon Nov 8 17:01:27 2004
@@ -77,14 +77,14 @@
}
if(i < args.length-1) {
File test = new File(args[args.length-2]);
- if(DeployUtils.isJarFile(test)) {
+ if(DeployUtils.isJarFile(test) || test.isDirectory()) {
if(module != null) {
- throw new DeploymentSyntaxException("Module and plan cannot both be JAR files!");
+ throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!");
}
module = test;
} else {
if(plan != null) {
- throw new DeploymentSyntaxException("Module or plan must be a text file!");
+ throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
}
plan = test;
}
@@ -93,12 +93,12 @@
File test = new File(args[args.length-2]);
if(DeployUtils.isJarFile(test)) {
if(module != null) {
- throw new DeploymentSyntaxException("Module and plan cannot both be JAR files!");
+ throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!");
}
module = test;
} else {
if(plan != null) {
- throw new DeploymentSyntaxException("Module or plan must be a text file!");
+ throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
}
plan = test;
}
Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandRedeploy.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandRedeploy.java (original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/CommandRedeploy.java Mon Nov 8 17:01:27 2004
@@ -77,27 +77,27 @@
if(!test.canRead()) {
throw new DeploymentException("Cannot read file "+test.getAbsolutePath());
}
- if(DeployUtils.isJarFile(test)) {
+ if(DeployUtils.isJarFile(test) || test.isDirectory()) {
if(module != null) {
- throw new DeploymentSyntaxException("Module and plan cannot both be JAR files!");
+ throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!");
}
module = test;
} else {
if(plan != null) {
- throw new DeploymentSyntaxException("Module or plan must be a JAR file!");
+ throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
}
plan = test;
}
test = new File(args[1]);
if(test.exists() && test.canRead()) {
- if(DeployUtils.isJarFile(test)) {
+ if(DeployUtils.isJarFile(test) || test.isDirectory()) {
if(module != null) {
- throw new DeploymentSyntaxException("Module and plan cannot both be JAR files!");
+ throw new DeploymentSyntaxException("Module and plan cannot both be JAR files or directories!");
}
module = test;
} else {
if(plan != null) {
- throw new DeploymentSyntaxException("Module or plan must be a JAR file!");
+ throw new DeploymentSyntaxException("Module or plan must be a JAR file or directory!");
}
plan = test;
}
Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/DeployTool.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/DeployTool.java (original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/DeployTool.java Mon Nov 8 17:01:27 2004
@@ -22,6 +22,8 @@
import java.util.*;
import java.io.PrintWriter;
import java.io.OutputStreamWriter;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
/**
* The main class for the CLI deployer. Handles chunking the input arguments
@@ -77,6 +79,7 @@
public boolean execute(String args[]) {
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true);
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String command;
String[] commonArgs = new String[0];
String[] commandArgs = new String[0];
@@ -103,7 +106,7 @@
} else {
ServerConnection con = null;
try {
- con = new ServerConnection(commonArgs, dc.isLocalOnly());
+ con = new ServerConnection(commonArgs, dc.isLocalOnly(), out, in);
try {
dc.execute(out, con, commandArgs);
} catch (DeploymentSyntaxException e) {
Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java (original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java Mon Nov 8 17:01:27 2004
@@ -42,9 +42,9 @@
line = prefix + line;
if(line.length() > endCol) {
pos = line.lastIndexOf(' ', endCol);
- if(pos < 0) {
+ if(pos < indent) {
pos = line.indexOf(' ', endCol);
- if(pos < 0) {
+ if(pos < indent) {
pos = line.length();
}
}
@@ -75,6 +75,9 @@
}
public static boolean isJarFile(File file) throws DeploymentException {
+ if(file.isDirectory()) {
+ return false;
+ }
if(!file.canRead()) {
throw new DeploymentException("Cannot read file "+file.getAbsolutePath());
}
@@ -89,5 +92,10 @@
} catch(IOException e) {
throw new DeploymentException("Cannot read from file "+file.getAbsolutePath(), e);
}
+ }
+
+ public static void main(String[] args) {
+ String msg = "/home/ammulder/cvs/geronimo/modules/security/target/geronimo-security-1.0-SNAPSHOT.jar does not specify a J2EE-DeploymentFactory-Implementation-Class; cannot load driver.";
+ System.out.println(reformat("Error: "+msg, 4, 72));
}
}
Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java (original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/cli/ServerConnection.java Mon Nov 8 17:01:27 2004
@@ -18,7 +18,12 @@
package org.apache.geronimo.deployment.cli;
import java.util.*;
+import java.util.jar.JarFile;
import java.net.URI;
+import java.io.BufferedReader;
+import java.io.PrintWriter;
+import java.io.IOException;
+import java.io.File;
import javax.enterprise.deploy.spi.DeploymentManager;
import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
import javax.enterprise.deploy.spi.factories.DeploymentFactory;
@@ -66,9 +71,13 @@
private DeploymentManager manager;
private KernelWrapper kernel;
+ private PrintWriter out;
+ private BufferedReader in;
- public ServerConnection(String[] args, boolean forceLocal) throws DeploymentException {
+ public ServerConnection(String[] args, boolean forceLocal, PrintWriter out, BufferedReader in) throws DeploymentException {
String uri = null, driver = null, user = null, password = null;
+ this.out = out;
+ this.in = in;
for(int i = 0; i < args.length; i++) {
String arg = args[i];
if(arg.equals("--uri")) {
@@ -90,7 +99,7 @@
throw new DeploymentSyntaxException("This command does not use normal server connectivity. No standard options are allowed.");
}
if(!forceLocal) {
- tryToConnect(uri, driver, user, password);
+ tryToConnect(uri, driver, user, password, true);
if(manager == null) { // uri must be null too or we'd have thrown an exception
initializeKernel();
}
@@ -116,26 +125,66 @@
}
}
- private void tryToConnect(String uri, String driver, String user, String password) throws DeploymentException {
+ private void tryToConnect(String uri, String driver, String user, String password, boolean authPrompt) throws DeploymentException {
DeploymentFactoryManager mgr = DeploymentFactoryManager.getInstance();
- mgr.registerDeploymentFactory(new DeploymentFactoryImpl());
if(driver != null) {
- try {
- DeploymentFactory factory = (DeploymentFactory) Class.forName(driver).newInstance();
- mgr.registerDeploymentFactory(factory);
- } catch(Exception e) {
- throw new DeploymentSyntaxException("Unable to load driver class "+driver, e);
- }
+ loadDriver(driver, mgr);
+ } else {
+ mgr.registerDeploymentFactory(new DeploymentFactoryImpl());
}
try {
manager = mgr.getDeploymentManager(uri == null ? DEFAULT_URI : uri, user, password);
} catch(AuthenticationFailedException e) { // server's there, you just can't talk to it
- throw new DeploymentException("Unable to connect to server: "+e.getMessage());
+ if(authPrompt && (user == null || password == null)) {
+ doAuthPromptAndRetry(uri, user, password);
+ } else {
+ throw new DeploymentException("Unable to connect to server: "+e.getMessage());
+ }
} catch(DeploymentManagerCreationException e) {
if(uri != null) {
throw new DeploymentException("Unable to connect to server at "+uri+" -- "+e.getMessage());
} //else, fall through and try local access
}
+ }
+
+ private void loadDriver(String driver, DeploymentFactoryManager mgr) throws DeploymentException {
+ File file = new File(driver);
+ if(!file.exists() || !file.canRead() || !DeployUtils.isJarFile(file)) {
+ throw new DeploymentSyntaxException("Driver '"+file.getAbsolutePath()+"' is not a readable JAR file");
+ }
+ String className = null;
+ try {
+ JarFile jar = new JarFile(file);
+ className = jar.getManifest().getMainAttributes().getValue("J2EE-DeploymentFactory-Implementation-Class");
+ if(className == null) {
+ throw new DeploymentException("The driver JAR "+file.getAbsolutePath()+" does not specify a J2EE-DeploymentFactory-Implementation-Class; cannot load driver.");
+ }
+ jar.close();
+ DeploymentFactory factory = (DeploymentFactory) Class.forName(className).newInstance();
+ mgr.registerDeploymentFactory(factory);
+ } catch(DeploymentException e) {
+ throw e;
+ } catch(Exception e) {
+ throw new DeploymentSyntaxException("Unable to load driver class "+className+" from JAR "+file.getAbsolutePath(), e);
+ }
+ }
+
+ private void doAuthPromptAndRetry(String uri, String user, String password) throws DeploymentException {
+ try {
+ if(user == null) {
+ out.print("Username: ");
+ out.flush();
+ user = in.readLine();
+ }
+ if(password == null) {
+ out.print("Password: ");
+ out.flush();
+ password = in.readLine();
+ }
+ } catch(IOException e) {
+ throw new DeploymentException("Unable to prompt for login", e);
+ }
+ tryToConnect(uri, null, user, password, false);
}
public DeploymentManager getDeploymentManager() {