important new feature is the ability to execute VAJ tasks from the command line by exploiting the Remote Tool Access feature of VAJ." Submitted by: wolf.siberski@tui.de Some patches look a lot larger as I had to remove stray CRs, I also killed TABs wherever I stumbled over them. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269819 13f79535-47bb-0310-9956-ffa450edef68master
@@ -4,6 +4,16 @@ Changes from Ant 1.4.1 to current CVS version | |||||
Changes that could break older environments: | Changes that could break older environments: | ||||
-------------------------------------------- | -------------------------------------------- | ||||
Fixed bugs: | |||||
----------- | |||||
* Fixed bug where ant would not copy system properties into new Project | |||||
in ant/antcall tasks when inheritall="false" is set. | |||||
* <propertyfile> would not close the original property file. | |||||
* <ant> will no longer override a subbuilds basedir with inheritall="true". | |||||
Other changes: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -23,15 +33,9 @@ Other changes: | |||||
* <taskdef> and <typedef> will now emit a warning if a task/type of | * <taskdef> and <typedef> will now emit a warning if a task/type of | ||||
the given name already exists. | the given name already exists. | ||||
Fixed bugs: | |||||
----------- | |||||
* Fixed bug where ant would not copy system properties into new Project | |||||
in ant/antcall tasks when inheritall="false" is set. | |||||
* <propertyfile> would not close the original property file. | |||||
* <ant> will no longer override a subbuilds basedir with inheritall="true". | |||||
* A new revision of VAJ tasks: The most important new feature | |||||
is the ability to execute VAJ tasks from the command line by | |||||
exploiting the Remote Tool Access feature of VAJ. | |||||
Changes from Ant 1.4 to Ant 1.4.1 | Changes from Ant 1.4 to Ant 1.4.1 | ||||
=========================================== | =========================================== | ||||
@@ -161,6 +161,10 @@ | |||||
<available property="xalan.envcheck" | <available property="xalan.envcheck" | ||||
classname="org.apache.xalan.xslt.EnvironmentCheck" | classname="org.apache.xalan.xslt.EnvironmentCheck" | ||||
classpathref="classpath" /> | classpathref="classpath" /> | ||||
<available property="servlet.present" | |||||
classname="javax.servlet.Servlet" | |||||
classpathref="classpath"/> | |||||
<condition property="javamail.complete"> | <condition property="javamail.complete"> | ||||
<and> | <and> | ||||
@@ -238,6 +242,8 @@ | |||||
<exclude name="${optional.package}/scm/AntStarTeam*.java" unless="starteam.present" /> | <exclude name="${optional.package}/scm/AntStarTeam*.java" unless="starteam.present" /> | ||||
<exclude name="${optional.package}/ANTLR.java" unless="antlr.present" /> | <exclude name="${optional.package}/ANTLR.java" unless="antlr.present" /> | ||||
<exclude name="${optional.package}/ide/VAJ*.java" unless="vaj.present" /> | <exclude name="${optional.package}/ide/VAJ*.java" unless="vaj.present" /> | ||||
<exclude name="${optional.package}/ide/VAJ*Servlet.java" | |||||
unless="servlet.present" /> | |||||
<exclude name="${optional.package}/perforce/*.java" unless="jakarta.oro.present" /> | <exclude name="${optional.package}/perforce/*.java" unless="jakarta.oro.present" /> | ||||
<exclude name="${optional.package}/sound/*.java" unless="jmf.present" /> | <exclude name="${optional.package}/sound/*.java" unless="jmf.present" /> | ||||
<exclude name="${optional.package}/junit/XMLResultAggregator.java" | <exclude name="${optional.package}/junit/XMLResultAggregator.java" | ||||
@@ -1,5 +1,3 @@ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
* | * | ||||
@@ -53,11 +51,16 @@ package org.apache.tools.ant.taskdefs.optional.ide; | |||||
* information on the Apache Software Foundation, please see | * information on the Apache Software Foundation, please see | ||||
* <http://www.apache.org/>. | * <http://www.apache.org/>. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import com.ibm.ivj.util.base.Project; | import com.ibm.ivj.util.base.Project; | ||||
import com.ibm.ivj.util.base.ToolData; | import com.ibm.ivj.util.base.ToolData; | ||||
import com.ibm.ivj.util.base.IvjException; | import com.ibm.ivj.util.base.IvjException; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
/** | /** | ||||
* This class is the equivalent to org.apache.tools.ant.Main for the | * This class is the equivalent to org.apache.tools.ant.Main for the | ||||
* VAJ tool environment. It's main is called when the user selects | * VAJ tool environment. It's main is called when the user selects | ||||
@@ -68,64 +71,81 @@ import org.apache.tools.ant.BuildException; | |||||
* @author: Wolf Siberski | * @author: Wolf Siberski | ||||
*/ | */ | ||||
public class VAJAntTool { | public class VAJAntTool { | ||||
private static final String TOOL_DATA_KEY = "AntTool"; | |||||
/** | |||||
* Loads the BuildInfo for the specified VAJ project from the | |||||
* tool data for this project. | |||||
* If there is no build info stored for that project, a new | |||||
* default BuildInfo is returned | |||||
* | |||||
* @return BuildInfo buildInfo build info for the specified project | |||||
* @param projectName String project name | |||||
*/ | |||||
public static VAJBuildInfo loadBuildData(String projectName) { | |||||
VAJBuildInfo result = null; | |||||
try { | |||||
Project project = VAJUtil.getWorkspace().loadedProjectNamed( projectName ); | |||||
if ( project.testToolRepositoryData(TOOL_DATA_KEY) ) { | |||||
ToolData td = project.getToolRepositoryData(TOOL_DATA_KEY); | |||||
String data = (String)td.getData(); | |||||
result = VAJBuildInfo.parse( data ); | |||||
} else { | |||||
result = new VAJBuildInfo(); | |||||
} | |||||
result.setVAJProjectName( projectName ); | |||||
} catch (Throwable t) { | |||||
System.out.println("BuildInfo for Project " + projectName + | |||||
" could not be loaded" + t); | |||||
throw new BuildException(t); | |||||
} | |||||
return result; | |||||
} | |||||
/** | |||||
* Starts the application. | |||||
* @param args an array of command-line arguments | |||||
*/ | |||||
public static void main(java.lang.String[] args) { | |||||
VAJBuildInfo info; | |||||
if ( args.length >= 2 && args[1] instanceof String ) { | |||||
String projectName = (String)args[1]; | |||||
info = loadBuildData( projectName ); | |||||
} | |||||
else { | |||||
info = new VAJBuildInfo(); | |||||
} | |||||
private static final String TOOL_DATA_KEY = "AntTool"; | |||||
VAJAntToolGUI mainFrame = new VAJAntToolGUI( info ); | |||||
mainFrame.show(); | |||||
} | |||||
/** | |||||
* Saves the BuildInfo for a project in the VAJ repository. | |||||
* @param info BuildInfo build info to save | |||||
*/ | |||||
public static void saveBuildData(VAJBuildInfo info) { | |||||
String data = info.asDataString(); | |||||
try { | |||||
ToolData td = new ToolData( TOOL_DATA_KEY, data ); | |||||
VAJUtil.getWorkspace().loadedProjectNamed( info.getVAJProjectName() ).setToolRepositoryData( td ); | |||||
} catch (Throwable t) { | |||||
throw new BuildException("BuildInfo for Project " + info.getVAJProjectName() + | |||||
" could not be saved", t); | |||||
} | |||||
} | |||||
/** | |||||
* Loads the BuildInfo for the specified VAJ project from the | |||||
* tool data for this project. | |||||
* If there is no build info stored for that project, a new | |||||
* default BuildInfo is returned | |||||
* | |||||
* @return BuildInfo buildInfo build info for the specified project | |||||
* @param projectName String project name | |||||
*/ | |||||
public static VAJBuildInfo loadBuildData(String projectName) { | |||||
VAJBuildInfo result = null; | |||||
try { | |||||
Project project = | |||||
VAJLocalUtil.getWorkspace().loadedProjectNamed( projectName ); | |||||
if ( project.testToolRepositoryData(TOOL_DATA_KEY) ) { | |||||
ToolData td = project.getToolRepositoryData(TOOL_DATA_KEY); | |||||
String data = (String)td.getData(); | |||||
result = VAJBuildInfo.parse( data ); | |||||
} else { | |||||
result = new VAJBuildInfo(); | |||||
} | |||||
result.setVAJProjectName( projectName ); | |||||
} catch (Throwable t) { | |||||
throw new BuildException("BuildInfo for Project " | |||||
+ projectName + " could not be loaded" + t); | |||||
} | |||||
return result; | |||||
} | |||||
/** | |||||
* Starts the application. | |||||
* | |||||
* @param args an array of command-line arguments. VAJ puts the | |||||
* VAJ project name into args[1] when starting the | |||||
* tool from the project context menu | |||||
*/ | |||||
public static void main(java.lang.String[] args) { | |||||
try { | |||||
VAJBuildInfo info; | |||||
if ( args.length >= 2 && args[1] instanceof String ) { | |||||
String projectName = (String)args[1]; | |||||
info = loadBuildData( projectName ); | |||||
} | |||||
else { | |||||
info = new VAJBuildInfo(); | |||||
} | |||||
VAJAntToolGUI mainFrame = new VAJAntToolGUI( info ); | |||||
mainFrame.show(); | |||||
} catch ( Throwable t ) { | |||||
// if all error handling fails, output at least | |||||
// something on the console | |||||
t.printStackTrace(); | |||||
} | |||||
} | |||||
/** | |||||
* Saves the BuildInfo for a project in the VAJ repository. | |||||
* | |||||
* @param info BuildInfo build info to save | |||||
*/ | |||||
public static void saveBuildData(VAJBuildInfo info) { | |||||
String data = info.asDataString(); | |||||
try { | |||||
ToolData td = new ToolData( TOOL_DATA_KEY, data ); | |||||
VAJLocalUtil.getWorkspace().loadedProjectNamed( | |||||
info.getVAJProjectName() ).setToolRepositoryData( td ); | |||||
} catch (Throwable t) { | |||||
throw new BuildException("BuildInfo for Project " | |||||
+ info.getVAJProjectName() + " could not be saved", t); | |||||
} | |||||
} | |||||
} | } |
@@ -1,5 +1,3 @@ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
* | * | ||||
@@ -53,11 +51,23 @@ package org.apache.tools.ant.taskdefs.optional.ide; | |||||
* information on the Apache Software Foundation, please see | * information on the Apache Software Foundation, please see | ||||
* <http://www.apache.org/>. | * <http://www.apache.org/>. | ||||
*/ | */ | ||||
import java.util.Hashtable; | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import java.util.Vector; | import java.util.Vector; | ||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
import org.apache.tools.ant.*; | |||||
import java.util.StringTokenizer; | |||||
import java.io.File; | import java.io.File; | ||||
import java.beans.PropertyChangeSupport; | |||||
import java.beans.PropertyChangeListener; | |||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.ProjectHelper; | |||||
import org.apache.tools.ant.Target; | |||||
import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.BuildListener; | |||||
import org.apache.tools.ant.BuildEvent; | |||||
/** | /** | ||||
* This class wraps the Ant project information needed to | * This class wraps the Ant project information needed to | ||||
@@ -68,276 +78,443 @@ import java.io.File; | |||||
* as ToolData in the VA repository) | * as ToolData in the VA repository) | ||||
* - wraps Project functions for the GUI (get target list, | * - wraps Project functions for the GUI (get target list, | ||||
* execute target) | * execute target) | ||||
* - manages a seperate thread for Ant project execution | |||||
* this allows interrupting a running build from a GUI | |||||
* | * | ||||
* @author Wolf Siberski, TUI Infotec GmbH | * @author Wolf Siberski, TUI Infotec GmbH | ||||
*/ | */ | ||||
public class VAJBuildInfo { | |||||
// name of the VA project this BuildInfo belongs to | |||||
private String vajProjectName = ""; | |||||
class VAJBuildInfo implements Runnable { | |||||
/** | |||||
* This exception is thrown when a build is interrupted | |||||
*/ | |||||
static public class BuildInterruptedException extends BuildException { | |||||
public String toString() { | |||||
return "BUILD INTERRUPTED"; | |||||
} | |||||
} | |||||
/** | |||||
* BuildListener which checks for interruption and throws Exception | |||||
* if build process is interrupted. This class is a wrapper around | |||||
* a 'real' listener. | |||||
*/ | |||||
private class InterruptedChecker implements BuildListener { | |||||
// the real listener | |||||
BuildListener wrappedListener; | |||||
/** | |||||
* Can only be constructed as wrapper around a real listener | |||||
* @param listener the real listener | |||||
*/ | |||||
public InterruptedChecker( BuildListener listener) { | |||||
super(); | |||||
wrappedListener = listener; | |||||
} | |||||
/** | |||||
* checks if the thread was interrupted. When an | |||||
* interrupt occured, throw an Exception to stop | |||||
* the execution. | |||||
*/ | |||||
protected void checkInterrupted() { | |||||
if ( buildThread.isInterrupted() ) { | |||||
throw new BuildInterruptedException(); | |||||
} | |||||
} | |||||
/** | |||||
* Fired after the last target has finished. This event | |||||
* will still be thrown if an error occured during the build. | |||||
*/ | |||||
public void buildFinished(BuildEvent event) { | |||||
wrappedListener.buildFinished( event ); | |||||
checkInterrupted(); | |||||
} | |||||
/** | |||||
* Fired before any targets are started. | |||||
*/ | |||||
public void buildStarted(BuildEvent event) { | |||||
wrappedListener.buildStarted( event ); | |||||
checkInterrupted(); | |||||
} | |||||
/** | |||||
* Fired whenever a message is logged. | |||||
*/ | |||||
public void messageLogged(BuildEvent event) { | |||||
wrappedListener.messageLogged( event ); | |||||
checkInterrupted(); | |||||
} | |||||
/** | |||||
* Fired when a target has finished. This event will | |||||
* still be thrown if an error occured during the build. | |||||
*/ | |||||
public void targetFinished(BuildEvent event) { | |||||
wrappedListener.targetFinished( event ); | |||||
checkInterrupted(); | |||||
} | |||||
/** | |||||
* Fired when a target is started. | |||||
*/ | |||||
public void targetStarted(BuildEvent event) { | |||||
wrappedListener.targetStarted( event ); | |||||
checkInterrupted(); | |||||
} | |||||
/** | |||||
* Fired when a task has finished. This event will still | |||||
* be throw if an error occured during the build. | |||||
*/ | |||||
public void taskFinished(BuildEvent event) { | |||||
wrappedListener.taskFinished( event ); | |||||
checkInterrupted(); | |||||
} | |||||
/** | |||||
* Fired when a task is started. | |||||
*/ | |||||
public void taskStarted(BuildEvent event) { | |||||
wrappedListener.taskStarted( event ); | |||||
checkInterrupted(); | |||||
} | |||||
} | |||||
// name of the Ant build file | |||||
private String buildFileName = ""; | |||||
// name of the VA project this BuildInfo belongs to | |||||
private String vajProjectName = ""; | |||||
// name of the Ant build file | |||||
private String buildFileName = ""; | |||||
// main targets found in the build file | |||||
private Vector projectTargets = new Vector(); | |||||
// main targets found in the build file | |||||
private Vector projectTargets = new Vector(); | |||||
// target selected for execution | |||||
private java.lang.String target = ""; | |||||
// target selected for execution | |||||
private java.lang.String target = ""; | |||||
// log level | |||||
private int outputMessageLevel = Project.MSG_INFO; | |||||
// log level | |||||
private int outputMessageLevel = Project.MSG_INFO; | |||||
// Ant Project created from build file | |||||
private transient Project project; | |||||
// Ant Project created from build file | |||||
private transient Project project; | |||||
// is true if Project initialization was successful | |||||
private transient boolean projectInitialized = false; | |||||
// is true if Project initialization was successful | |||||
private transient boolean projectInitialized = false; | |||||
// Support for bound properties | |||||
protected transient java.beans.PropertyChangeSupport propertyChange; | |||||
/** | |||||
* The addPropertyChangeListener method was generated to support the propertyChange field. | |||||
*/ | |||||
public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener listener) { | |||||
getPropertyChange().addPropertyChangeListener(listener); | |||||
} | |||||
/** | |||||
* Returns the BuildInfo information as String. The BuildInfo can | |||||
* be rebuilt from that String by calling parse(). | |||||
* @return java.lang.String | |||||
*/ | |||||
public String asDataString() { | |||||
String result = getOutputMessageLevel() + "|" + getBuildFileName() + "|" + getTarget(); | |||||
for ( Enumeration e = getProjectTargets().elements(); e.hasMoreElements(); ) { | |||||
result = result + "|" + e.nextElement(); | |||||
} | |||||
// Support for bound properties | |||||
protected transient PropertyChangeSupport propertyChange; | |||||
// thread for Ant build execution | |||||
private Thread buildThread; | |||||
// the listener used to log output. | |||||
private BuildListener projectLogger; | |||||
return result; | |||||
} | |||||
/** | |||||
* Executes the target set by setTarget(). | |||||
* @param listener BuildListener for the output of the build | |||||
*/ | |||||
public void executeProject( BuildListener listener ) { | |||||
Throwable error = null; | |||||
try { | |||||
if (!isProjectInitialized()) { | |||||
project = new Project(); | |||||
} | |||||
project.addBuildListener( listener ); | |||||
// Chris: HACK: replace when Ant-Refactoring is finished! | |||||
// project.fireBuildStarted(); | |||||
if (!isProjectInitialized()) { | |||||
initProject(); | |||||
} | |||||
project.executeTarget(target); | |||||
} catch (RuntimeException exc) { | |||||
error = exc; | |||||
throw exc; | |||||
} catch (Error err) { | |||||
error = err; | |||||
throw err; | |||||
} finally { | |||||
// Chris: HACK: replace when Ant-Refactoring is finished! | |||||
// project.fireBuildFinished(error); | |||||
project.removeBuildListener( listener ); | |||||
} | |||||
} | |||||
/** | |||||
* Search for the insert position to keep names a sorted list of Strings | |||||
* This method has been copied from org.apache.tools.ant.Main | |||||
*/ | |||||
private static int findTargetPosition(Vector names, String name) { | |||||
int res = names.size(); | |||||
for (int i=0; i<names.size() && res == names.size(); i++) { | |||||
if (name.compareTo((String)names.elementAt(i)) < 0) { | |||||
res = i; | |||||
} | |||||
} | |||||
return res; | |||||
} | |||||
/** | |||||
* The firePropertyChange method was generated to support the propertyChange field. | |||||
*/ | |||||
public void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue) { | |||||
getPropertyChange().firePropertyChange(propertyName, oldValue, newValue); | |||||
} | |||||
/** | |||||
* Returns the build file name. | |||||
* @return build file name. | |||||
*/ | |||||
public String getBuildFileName() { | |||||
return buildFileName; | |||||
} | |||||
/** | |||||
* Returns the log level | |||||
* @return log level. | |||||
*/ | |||||
public int getOutputMessageLevel() { | |||||
return outputMessageLevel; | |||||
} | |||||
/** | |||||
* Returns the Ant project | |||||
* @return org.apache.tools.ant.Project | |||||
*/ | |||||
private Project getProject() { | |||||
return project; | |||||
} | |||||
/** | |||||
* return a list of all targets in the current buildfile | |||||
*/ | |||||
public Vector getProjectTargets() { | |||||
return projectTargets; | |||||
} | |||||
/** | |||||
* Accessor for the propertyChange field. | |||||
*/ | |||||
protected java.beans.PropertyChangeSupport getPropertyChange() { | |||||
if (propertyChange == null) { | |||||
propertyChange = new java.beans.PropertyChangeSupport(this); | |||||
}; | |||||
return propertyChange; | |||||
} | |||||
/** | |||||
* Insert the method's description here. | |||||
* Creation date: (07.11.2000 10:34:18) | |||||
* @return java.lang.String | |||||
*/ | |||||
public java.lang.String getTarget() { | |||||
return target; | |||||
} | |||||
/** | |||||
* returns the VA project name | |||||
* @return The projectName property value. | |||||
*/ | |||||
public String getVAJProjectName() { | |||||
return vajProjectName; | |||||
} | |||||
/** | |||||
* Initializes the Ant project. Assumes that the | |||||
* project attribute is already set. | |||||
*/ | |||||
private void initProject() { | |||||
try { | |||||
project.init(); | |||||
File buildFile = new File(getBuildFileName()); | |||||
project.setUserProperty("ant.file", buildFile.getAbsolutePath()); | |||||
ProjectHelper.configureProject(project, buildFile); | |||||
setProjectInitialized(true); | |||||
} catch (RuntimeException exc) { | |||||
setProjectInitialized(false); | |||||
throw exc; | |||||
} catch (Error err) { | |||||
setProjectInitialized(false); | |||||
throw err; | |||||
} | |||||
} | |||||
/** | |||||
* Returns true, if the Ant project is initialized | |||||
* (i.e. buildfile loaded) | |||||
*/ | |||||
public boolean isProjectInitialized() { | |||||
return projectInitialized; | |||||
} | |||||
/** | |||||
* Creates a BuildInfo object from a String | |||||
* The String must be in the format | |||||
* outputMessageLevel'|'buildFileName'|'defaultTarget'|'(project target'|')* | |||||
* | |||||
* @return org.apache.tools.ant.taskdefs.optional.vaj.BuildInfo | |||||
* @param data java.lang.String | |||||
*/ | |||||
public static VAJBuildInfo parse(String data) { | |||||
VAJBuildInfo result = new VAJBuildInfo(); | |||||
try { | |||||
java.util.StringTokenizer tok = new java.util.StringTokenizer( data, "|" ); | |||||
result.setOutputMessageLevel( tok.nextToken() ); | |||||
result.setBuildFileName( tok.nextToken() ); | |||||
result.setTarget( tok.nextToken() ); | |||||
while( tok.hasMoreTokens() ) { | |||||
result.projectTargets.addElement( tok.nextToken() ); | |||||
} | |||||
} catch ( Throwable t ) { | |||||
} | |||||
return result; | |||||
} | |||||
/** | |||||
* The removePropertyChangeListener method was generated to support the propertyChange field. | |||||
*/ | |||||
public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener listener) { | |||||
getPropertyChange().removePropertyChangeListener(listener); | |||||
} | |||||
/** | |||||
* Sets the build file name | |||||
* @param buildFileName build file name | |||||
*/ | |||||
public void setBuildFileName(String newBuildFileName) { | |||||
String oldValue = buildFileName; | |||||
buildFileName = newBuildFileName; | |||||
setProjectInitialized(false); | |||||
firePropertyChange("buildFileName", oldValue, buildFileName); | |||||
} | |||||
/** | |||||
* Sets the log level (value must be one of the constants in Project) | |||||
* @param outputMessageLevel log level. | |||||
*/ | |||||
public void setOutputMessageLevel(int newOutputMessageLevel) { | |||||
int oldValue = outputMessageLevel; | |||||
outputMessageLevel = newOutputMessageLevel; | |||||
firePropertyChange("outputMessageLevel", new Integer(oldValue), new Integer(outputMessageLevel)); | |||||
} | |||||
/** | |||||
* Sets the log level (value must be one of the constants in Project) | |||||
* @param outputMessageLevel log level as String. | |||||
*/ | |||||
private void setOutputMessageLevel(String outputMessageLevel) { | |||||
int level = Integer.parseInt( outputMessageLevel ); | |||||
setOutputMessageLevel( level ); | |||||
} | |||||
/** | |||||
*/ | |||||
private void setProjectInitialized(boolean initialized) { | |||||
Boolean oldValue = new Boolean(projectInitialized); | |||||
projectInitialized = initialized; | |||||
firePropertyChange("projectInitialized", oldValue, new Boolean(projectInitialized)); | |||||
} | |||||
/** | |||||
* Sets the target to execute when executeBuild is called | |||||
* @param newTarget build target | |||||
*/ | |||||
public void setTarget(String newTarget) { | |||||
String oldValue = target; | |||||
target = newTarget; | |||||
firePropertyChange("target", oldValue, target); | |||||
} | |||||
/** | |||||
* Sets the name of the Visual Age for Java project where | |||||
* this BuildInfo belongs to | |||||
* @param newProjectName VAJ project | |||||
*/ | |||||
public void setVAJProjectName(String newVAJProjectName) { | |||||
String oldValue = vajProjectName; | |||||
vajProjectName = newVAJProjectName; | |||||
firePropertyChange("VAJProjectName", oldValue, vajProjectName); | |||||
} | |||||
/** | |||||
* reloads the build file and updates the target list | |||||
*/ | |||||
public void updateTargetList() { | |||||
project = new Project(); | |||||
initProject(); | |||||
projectTargets.removeAllElements(); | |||||
Enumeration ptargets = project.getTargets().elements(); | |||||
while (ptargets.hasMoreElements()) { | |||||
Target currentTarget = (Target) ptargets.nextElement(); | |||||
if ( currentTarget.getDescription() != null ) { | |||||
String targetName = currentTarget.getName(); | |||||
int pos = findTargetPosition( projectTargets, targetName ); | |||||
projectTargets.insertElementAt(targetName, pos); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* The addPropertyChangeListener method was generated to support the | |||||
* propertyChange field. | |||||
*/ | |||||
public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { | |||||
getPropertyChange().addPropertyChangeListener(listener); | |||||
} | |||||
/** | |||||
* Returns the BuildInfo information as String. The BuildInfo can | |||||
* be rebuilt from that String by calling parse(). | |||||
* @return java.lang.String | |||||
*/ | |||||
public String asDataString() { | |||||
String result = getOutputMessageLevel() + "|" + getBuildFileName() | |||||
+ "|" + getTarget(); | |||||
for ( Enumeration e = getProjectTargets().elements(); | |||||
e.hasMoreElements(); ) { | |||||
result = result + "|" + e.nextElement(); | |||||
} | |||||
return result; | |||||
} | |||||
/** | |||||
* Search for the insert position to keep names a sorted list of Strings | |||||
* This method has been copied from org.apache.tools.ant.Main | |||||
*/ | |||||
private static int findTargetPosition(Vector names, String name) { | |||||
int res = names.size(); | |||||
for (int i=0; i<names.size() && res == names.size(); i++) { | |||||
if (name.compareTo((String)names.elementAt(i)) < 0) { | |||||
res = i; | |||||
} | |||||
} | |||||
return res; | |||||
} | |||||
/** | |||||
* The firePropertyChange method was generated to support the propertyChange field. | |||||
*/ | |||||
public void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue) { | |||||
getPropertyChange().firePropertyChange(propertyName, oldValue, newValue); | |||||
} | |||||
/** | |||||
* Returns the build file name. | |||||
* @return build file name. | |||||
*/ | |||||
public String getBuildFileName() { | |||||
return buildFileName; | |||||
} | |||||
/** | |||||
* Returns the log level | |||||
* @return log level. | |||||
*/ | |||||
public int getOutputMessageLevel() { | |||||
return outputMessageLevel; | |||||
} | |||||
/** | |||||
* Returns the Ant project | |||||
* @return org.apache.tools.ant.Project | |||||
*/ | |||||
private Project getProject() { | |||||
if ( project == null ) { | |||||
project = new Project(); | |||||
} | |||||
return project; | |||||
} | |||||
/** | |||||
* return a list of all targets in the current buildfile | |||||
*/ | |||||
public Vector getProjectTargets() { | |||||
return projectTargets; | |||||
} | |||||
/** | |||||
* Accessor for the propertyChange field. | |||||
*/ | |||||
protected PropertyChangeSupport getPropertyChange() { | |||||
if (propertyChange == null) { | |||||
propertyChange = new PropertyChangeSupport(this); | |||||
} | |||||
return propertyChange; | |||||
} | |||||
/** | |||||
* returns the selected target. | |||||
*/ | |||||
public java.lang.String getTarget() { | |||||
return target; | |||||
} | |||||
/** | |||||
* returns the VA project name | |||||
*/ | |||||
public String getVAJProjectName() { | |||||
return vajProjectName; | |||||
} | |||||
/** | |||||
* Initializes the Ant project. Assumes that the | |||||
* project attribute is already set. | |||||
*/ | |||||
private void initProject() { | |||||
try { | |||||
project.init(); | |||||
File buildFile = new File(getBuildFileName()); | |||||
project.setUserProperty("ant.file", buildFile.getAbsolutePath()); | |||||
ProjectHelper.configureProject(project, buildFile); | |||||
setProjectInitialized(true); | |||||
} catch (RuntimeException exc) { | |||||
setProjectInitialized(false); | |||||
throw exc; | |||||
} catch (Error err) { | |||||
setProjectInitialized(false); | |||||
throw err; | |||||
} | |||||
} | |||||
/** | |||||
* Returns true, if the Ant project is initialized | |||||
* (i.e. buildfile loaded) | |||||
*/ | |||||
public boolean isProjectInitialized() { | |||||
return projectInitialized; | |||||
} | |||||
/** | |||||
* Creates a BuildInfo object from a String | |||||
* The String must be in the format | |||||
* outputMessageLevel'|'buildFileName'|'defaultTarget'|'(project target'|')* | |||||
* | |||||
* @return org.apache.tools.ant.taskdefs.optional.vaj.BuildInfo | |||||
* @param data java.lang.String | |||||
*/ | |||||
public static VAJBuildInfo parse(String data) { | |||||
VAJBuildInfo result = new VAJBuildInfo(); | |||||
try { | |||||
StringTokenizer tok = new StringTokenizer( data, "|" ); | |||||
result.setOutputMessageLevel( tok.nextToken() ); | |||||
result.setBuildFileName( tok.nextToken() ); | |||||
result.setTarget( tok.nextToken() ); | |||||
while( tok.hasMoreTokens() ) { | |||||
result.projectTargets.addElement( tok.nextToken() ); | |||||
} | |||||
} catch ( Throwable t ) { | |||||
// if parsing the info fails, just return | |||||
// an empty VAJBuildInfo | |||||
} | |||||
return result; | |||||
} | |||||
/** | |||||
* The removePropertyChangeListener method was generated | |||||
* to support the propertyChange field. | |||||
*/ | |||||
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { | |||||
getPropertyChange().removePropertyChangeListener(listener); | |||||
} | |||||
/** | |||||
* Sets the build file name | |||||
* @param buildFileName build file name | |||||
*/ | |||||
public void setBuildFileName(String newBuildFileName) { | |||||
String oldValue = buildFileName; | |||||
buildFileName = newBuildFileName; | |||||
setProjectInitialized(false); | |||||
firePropertyChange("buildFileName", oldValue, buildFileName); | |||||
} | |||||
/** | |||||
* Sets the log level (value must be one of the constants in Project) | |||||
* @param outputMessageLevel log level. | |||||
*/ | |||||
public void setOutputMessageLevel(int newOutputMessageLevel) { | |||||
int oldValue = outputMessageLevel; | |||||
outputMessageLevel = newOutputMessageLevel; | |||||
firePropertyChange("outputMessageLevel", | |||||
new Integer(oldValue), new Integer(outputMessageLevel)); | |||||
} | |||||
/** | |||||
* Sets the log level (value must be one of the constants in Project) | |||||
* @param outputMessageLevel log level as String. | |||||
*/ | |||||
private void setOutputMessageLevel(String outputMessageLevel) { | |||||
int level = Integer.parseInt( outputMessageLevel ); | |||||
setOutputMessageLevel( level ); | |||||
} | |||||
/** | |||||
* sets the initialized flag | |||||
*/ | |||||
private void setProjectInitialized(boolean initialized) { | |||||
Boolean oldValue = new Boolean(projectInitialized); | |||||
projectInitialized = initialized; | |||||
firePropertyChange("projectInitialized", oldValue, new Boolean(projectInitialized)); | |||||
} | |||||
/** | |||||
* Sets the target to execute when executeBuild is called | |||||
* @param newTarget build target | |||||
*/ | |||||
public void setTarget(String newTarget) { | |||||
String oldValue = target; | |||||
target = newTarget; | |||||
firePropertyChange("target", oldValue, target); | |||||
} | |||||
/** | |||||
* Sets the name of the Visual Age for Java project where | |||||
* this BuildInfo belongs to | |||||
* @param newProjectName VAJ project | |||||
*/ | |||||
public void setVAJProjectName(String newVAJProjectName) { | |||||
String oldValue = vajProjectName; | |||||
vajProjectName = newVAJProjectName; | |||||
firePropertyChange("VAJProjectName", oldValue, vajProjectName); | |||||
} | |||||
/** | |||||
* reloads the build file and updates the target list | |||||
*/ | |||||
public void updateTargetList() { | |||||
project = new Project(); | |||||
initProject(); | |||||
projectTargets.removeAllElements(); | |||||
Enumeration ptargets = project.getTargets().elements(); | |||||
while (ptargets.hasMoreElements()) { | |||||
Target currentTarget = (Target) ptargets.nextElement(); | |||||
if ( currentTarget.getDescription() != null ) { | |||||
String targetName = currentTarget.getName(); | |||||
int pos = findTargetPosition( projectTargets, targetName ); | |||||
projectTargets.insertElementAt(targetName, pos); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* cancels a build. | |||||
*/ | |||||
public void cancelBuild() { | |||||
buildThread.interrupt(); | |||||
} | |||||
/** | |||||
* Executes the target set by setTarget(). | |||||
* @param listener BuildListener for the output of the build | |||||
*/ | |||||
public void executeProject( BuildListener logger ) { | |||||
Throwable error; | |||||
projectLogger = logger; | |||||
try { | |||||
buildThread = new Thread( this ); | |||||
buildThread.setPriority(Thread.MIN_PRIORITY); | |||||
buildThread.start(); | |||||
} catch (RuntimeException exc) { | |||||
error = exc; | |||||
throw exc; | |||||
} catch (Error err) { | |||||
error = err; | |||||
throw err; | |||||
} | |||||
} | |||||
/** | |||||
* Executes a build. This method is executed by | |||||
* the Ant execution thread | |||||
*/ | |||||
public void run() { | |||||
try { | |||||
InterruptedChecker ic = new InterruptedChecker( projectLogger ); | |||||
BuildEvent e = new BuildEvent( getProject() ); | |||||
try { | |||||
ic.buildStarted(e); | |||||
if (!isProjectInitialized()) { | |||||
initProject(); | |||||
} | |||||
project.addBuildListener( ic ); | |||||
project.executeTarget(target); | |||||
ic.buildFinished( e ); | |||||
} catch (Throwable t) { | |||||
e.setException( t ); | |||||
ic.buildFinished( e ); | |||||
} finally { | |||||
project.removeBuildListener( ic ); | |||||
} | |||||
} catch ( Throwable t2 ) { | |||||
System.out.println("unexpected exception!"); | |||||
t2.printStackTrace(); | |||||
} | |||||
} | |||||
} | } |
@@ -55,17 +55,9 @@ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | package org.apache.tools.ant.taskdefs.optional.ide; | ||||
import com.ibm.ivj.util.base.ExportCodeSpec; | |||||
import com.ibm.ivj.util.base.IvjException; | |||||
import com.ibm.ivj.util.base.Package; | |||||
import java.io.File; | import java.io.File; | ||||
import java.util.Enumeration; | |||||
import java.util.Vector; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.Task; | |||||
import org.apache.tools.ant.types.PatternSet; | import org.apache.tools.ant.types.PatternSet; | ||||
/** | /** | ||||
@@ -96,146 +88,125 @@ import org.apache.tools.ant.types.PatternSet; | |||||
* @author Wolf Siberski, TUI Infotec GmbH | * @author Wolf Siberski, TUI Infotec GmbH | ||||
*/ | */ | ||||
public class VAJExport extends Task { | |||||
protected File destDir; | |||||
protected boolean exportSources = true; | |||||
protected boolean exportResources = true; | |||||
protected boolean exportClasses = false; | |||||
protected boolean exportDebugInfo = false; | |||||
protected boolean useDefaultExcludes = true; | |||||
protected PatternSet patternSet = new PatternSet(); | |||||
/** | |||||
* add a name entry on the exclude list | |||||
*/ | |||||
public PatternSet.NameEntry createExclude() { | |||||
return patternSet.createExclude(); | |||||
} | |||||
/** | |||||
* add a name entry on the include list | |||||
*/ | |||||
public PatternSet.NameEntry createInclude() { | |||||
return patternSet.createInclude(); | |||||
} | |||||
/** | |||||
* do the export | |||||
*/ | |||||
public void execute() throws BuildException { | |||||
// first off, make sure that we've got a destdir | |||||
if (destDir == null) { | |||||
throw new BuildException("destdir attribute must be set!"); | |||||
} | |||||
VAJWorkspaceScanner ds = this.getWorkspaceScanner(); | |||||
Package[] packages = ds.getIncludedPackages(); | |||||
export(packages); | |||||
} | |||||
/** | |||||
* export the array of Packages | |||||
*/ | |||||
public void export(Package[] packages) { | |||||
try { | |||||
String dest = destDir.getAbsolutePath(); | |||||
log("Exporting " + packages.length + " package(s) to " + dest); | |||||
for (int i = 0; i < packages.length; i++) { | |||||
log(" " + packages[i].getName(), Project.MSG_VERBOSE); | |||||
} | |||||
ExportCodeSpec exportSpec = new ExportCodeSpec(); | |||||
exportSpec.setPackages(packages); | |||||
exportSpec.includeJava(exportSources); | |||||
exportSpec.includeClass(exportClasses); | |||||
exportSpec.includeResources(exportResources); | |||||
exportSpec.includeClassDebugInfo(exportDebugInfo); | |||||
exportSpec.useSubdirectories(true); | |||||
exportSpec.overwriteFiles(true); | |||||
exportSpec.setExportDirectory(dest); | |||||
VAJUtil.getWorkspace().exportData(exportSpec); | |||||
} catch (IvjException ex) { | |||||
throw VAJUtil.createBuildException("Exporting failed!", ex); | |||||
} | |||||
} | |||||
/** | |||||
* Returns the directory scanner needed to access the files to process. | |||||
*/ | |||||
protected VAJWorkspaceScanner getWorkspaceScanner() { | |||||
VAJWorkspaceScanner scanner = new VAJWorkspaceScanner(); | |||||
scanner.setIncludes(patternSet.getIncludePatterns(getProject())); | |||||
scanner.setExcludes(patternSet.getExcludePatterns(getProject())); | |||||
if (useDefaultExcludes) | |||||
scanner.addDefaultExcludes(); | |||||
scanner.scan(); | |||||
return scanner; | |||||
} | |||||
/** | |||||
* Sets whether default exclusions should be used or not. | |||||
* | |||||
* @param useDefaultExcludes "true"|"on"|"yes" when default exclusions | |||||
* should be used, "false"|"off"|"no" when they | |||||
* shouldn't be used. | |||||
*/ | |||||
public void setDefaultexcludes(boolean useDefaultExcludes) { | |||||
this.useDefaultExcludes = useDefaultExcludes; | |||||
} | |||||
/** | |||||
* Set the destination directory into which the Java source | |||||
* files should be compiled. | |||||
*/ | |||||
public void setDestdir(File destDir) { | |||||
this.destDir = destDir; | |||||
} | |||||
/** | |||||
* Sets the set of exclude patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param excludes the string containing the exclude patterns | |||||
*/ | |||||
public void setExcludes(String excludes) { | |||||
patternSet.setExcludes(excludes); | |||||
} | |||||
/** | |||||
*/ | |||||
public void setExportClasses(boolean doExport) { | |||||
exportClasses = doExport; | |||||
} | |||||
/** | |||||
*/ | |||||
public void setExportDebugInfo(boolean doExport) { | |||||
exportDebugInfo = doExport; | |||||
} | |||||
/** | |||||
*/ | |||||
public void setExportResources(boolean doExport) { | |||||
exportResources = doExport; | |||||
} | |||||
/** | |||||
*/ | |||||
public void setExportSources(boolean doExport) { | |||||
exportSources = doExport; | |||||
} | |||||
/** | |||||
* Sets the set of include patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param includes the string containing the include patterns | |||||
*/ | |||||
public void setIncludes(String includes) { | |||||
patternSet.setIncludes(includes); | |||||
} | |||||
} | |||||
public class VAJExport extends VAJTask { | |||||
//set set... method comments for description | |||||
protected File destDir; | |||||
protected boolean exportSources = true; | |||||
protected boolean exportResources = true; | |||||
protected boolean exportClasses = false; | |||||
protected boolean exportDebugInfo = false; | |||||
protected boolean useDefaultExcludes = true; | |||||
protected boolean overwrite = true; | |||||
protected PatternSet patternSet = new PatternSet(); | |||||
/** | |||||
* add a name entry on the exclude list | |||||
*/ | |||||
public PatternSet.NameEntry createExclude() { | |||||
return patternSet.createExclude(); | |||||
} | |||||
/** | |||||
* add a name entry on the include list | |||||
*/ | |||||
public PatternSet.NameEntry createInclude() { | |||||
return patternSet.createInclude(); | |||||
} | |||||
/** | |||||
* do the export | |||||
*/ | |||||
public void execute() throws BuildException { | |||||
// first off, make sure that we've got a destdir | |||||
if (destDir == null) { | |||||
throw new BuildException("destdir attribute must be set!"); | |||||
} | |||||
// delegate the export to the VAJUtil object. | |||||
getUtil().exportPackages(destDir, | |||||
patternSet.getIncludePatterns(getProject()), | |||||
patternSet.getExcludePatterns(getProject()), | |||||
exportClasses, exportDebugInfo, | |||||
exportResources, exportSources, | |||||
useDefaultExcludes, overwrite); | |||||
} | |||||
/** | |||||
* Sets whether default exclusions should be used or not. | |||||
* | |||||
* @param useDefaultExcludes "true"|"on"|"yes" when default exclusions | |||||
* should be used, "false"|"off"|"no" when they | |||||
* shouldn't be used. | |||||
*/ | |||||
public void setDefaultexcludes(boolean useDefaultExcludes) { | |||||
this.useDefaultExcludes = useDefaultExcludes; | |||||
} | |||||
/** | |||||
* Set the destination directory into which the selected | |||||
* items should be exported | |||||
*/ | |||||
public void setDestdir(File destDir) { | |||||
this.destDir = destDir; | |||||
} | |||||
/** | |||||
* Sets the set of exclude patterns. Patterns may be separated by a comma | |||||
* or a space. Currently only patterns denoting packages are | |||||
* supported | |||||
* | |||||
* @param excludes the string containing the exclude patterns | |||||
*/ | |||||
public void setExcludes(String excludes) { | |||||
patternSet.setExcludes(excludes); | |||||
} | |||||
/** | |||||
* if exportClasses is set, class files are exported | |||||
*/ | |||||
public void setExportClasses(boolean doExport) { | |||||
exportClasses = doExport; | |||||
} | |||||
/** | |||||
* if exportDebugInfo is set, the exported class files contain | |||||
* debug info | |||||
*/ | |||||
public void setExportDebugInfo(boolean doExport) { | |||||
exportDebugInfo = doExport; | |||||
} | |||||
/** | |||||
* if exportResources is set, resource file will be exported | |||||
*/ | |||||
public void setExportResources(boolean doExport) { | |||||
exportResources = doExport; | |||||
} | |||||
/** | |||||
* if exportSources is set, java files will be exported | |||||
*/ | |||||
public void setExportSources(boolean doExport) { | |||||
exportSources = doExport; | |||||
} | |||||
/** | |||||
* Sets the set of include patterns. Patterns may be separated by a comma | |||||
* or a space.Currently only patterns denoting packages are | |||||
* supported | |||||
* | |||||
* @param includes the string containing the include patterns | |||||
*/ | |||||
public void setIncludes(String includes) { | |||||
patternSet.setIncludes(includes); | |||||
} | |||||
/** | |||||
* if Overwrite is set, files will be overwritten during export | |||||
*/ | |||||
public void setOverwrite(boolean doOverwrite) { | |||||
overwrite = doOverwrite; | |||||
} | |||||
} |
@@ -0,0 +1,172 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import java.io.File; | |||||
/** | |||||
* A Remote Access to Tools Servlet to extract package | |||||
* sets from the Workbench to the local file system. | |||||
* The following table describes the servlet parameters. | |||||
* | |||||
* <table border="1"> | |||||
* <tr> | |||||
* <td><strong>Parameter</strong></td> | |||||
* <td><strong>Values</strong></td> | |||||
* <td><strong>Description</strong></td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>dir</td> | |||||
* <td>Any valid directory name on the server.</td> | |||||
* <td>The directory to export the files to on the machine | |||||
* where the servlet is being run. If the directory | |||||
* doesn't exist, it will be created.<p> | |||||
* Relative paths are relative to | |||||
* IBMVJava/ide/tools/com-ibm-ivj-toolserver, | |||||
* where IBMVJava is the VisualAge for Java installation | |||||
* directory.</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>include</td> | |||||
* <td>See below.</td> | |||||
* <td>The pattern used to indicate which projects and | |||||
* packages to export.</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>exclude</td> | |||||
* <td>See below</td> | |||||
* <td>The pattern used to indicate which projects and | |||||
* packages <em>not</em> to export.</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>cls</td> | |||||
* <td>"yes" or "no" (without the quotes)</td> | |||||
* <td>Export class files. Defaults to "no".</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>src</td> | |||||
* <td>"yes" or "no" (without the quotes)</td> | |||||
* <td>Export source files. Defaults to "yes".</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>res</td> | |||||
* <td>"yes" or "no" (without the quotes)</td> | |||||
* <td>Export resource files associated with the included project(s). | |||||
* Defaults to "yes".</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>dex</td> | |||||
* <td>"yes" or "no" (without the quotes)</td> | |||||
* <td>Use the default exclusion patterns. Defaults to "yes". | |||||
* See below for an explanation of default excludes.</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>owr</td> | |||||
* <td>"yes" or "no" (without the quotes)</td> | |||||
* <td>Overwrite any existing files. Defaults to "yes".</td> | |||||
* </tr> | |||||
* </table> | |||||
* | |||||
* <p>The vajexport servlet uses include and exclude parameters to form | |||||
* the criteria for selecting packages to export. The parameter is | |||||
* broken up into ProjectName/packageNameSegments, where ProjectName | |||||
* is what you expect, and packageNameSegments is a partial (or complete) | |||||
* package name, separated by forward slashes, rather than periods. | |||||
* Each packageNameSegment can have wildcard characters.</p> | |||||
* | |||||
* <table border="1"> | |||||
* <tr> | |||||
* <td><strong>Wildcard Characters</strong></td> | |||||
* <td><strong>Description</strong></td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>*</td> | |||||
* <td>Match zero or more characters in that segment.</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>?</td> | |||||
* <td>Match one character in that segment.</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>**</td> | |||||
* <td>Matches all characters in zero or more segments.</td> | |||||
* </tr> | |||||
* </table> | |||||
* | |||||
* @author Wolf Siberski, based on servlets written by Glenn McAllister | |||||
*/ | |||||
public class VAJExportServlet extends VAJToolsServlet { | |||||
// constants for servlet param names | |||||
public static final String WITH_DEBUG_INFO = "deb"; | |||||
public static final String OVERWRITE_PARAM = "owr"; | |||||
/** | |||||
* Respond to a request to export packages from the Workbench. | |||||
*/ | |||||
protected void executeRequest() { | |||||
getUtil().exportPackages( | |||||
new File(getFirstParamValueString(DIR_PARAM)), | |||||
getParamValues(INCLUDE_PARAM), | |||||
getParamValues(EXCLUDE_PARAM), | |||||
getBooleanParam(CLASSES_PARAM, false), | |||||
getBooleanParam(WITH_DEBUG_INFO, false), | |||||
getBooleanParam(RESOURCES_PARAM, true), | |||||
getBooleanParam(SOURCES_PARAM, true), | |||||
getBooleanParam(DEFAULT_EXCLUDES_PARAM, true), | |||||
getBooleanParam(OVERWRITE_PARAM, true) | |||||
); | |||||
} | |||||
} |
@@ -53,11 +53,6 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs.optional.ide; | package org.apache.tools.ant.taskdefs.optional.ide; | ||||
import com.ibm.ivj.util.base.ImportCodeSpec; | |||||
import com.ibm.ivj.util.base.IvjException; | |||||
import com.ibm.ivj.util.base.Project; | |||||
import com.ibm.ivj.util.base.ProjectEdition; | |||||
import com.ibm.ivj.util.base.Type; | |||||
import java.io.File; | import java.io.File; | ||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
import java.util.Vector; | import java.util.Vector; | ||||
@@ -66,6 +61,8 @@ import org.apache.tools.ant.DirectoryScanner; | |||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
import org.apache.tools.ant.types.FileSet; | import org.apache.tools.ant.types.FileSet; | ||||
import java.lang.reflect.Field; | |||||
/** | /** | ||||
* Import source, class files, and resources to the Visual Age for Java | * Import source, class files, and resources to the Visual Age for Java | ||||
* workspace using FileSets. | * workspace using FileSets. | ||||
@@ -95,7 +92,7 @@ import org.apache.tools.ant.types.FileSet; | |||||
* <td align="center" valign="top"><b>Required</b></td> | * <td align="center" valign="top"><b>Required</b></td> | ||||
* </tr> | * </tr> | ||||
* <tr> | * <tr> | ||||
* <td valign="top">vajproject</td> | |||||
* <td valign="top">project</td> | |||||
* <td valign="top">the name of the Project to import to</td> | * <td valign="top">the name of the Project to import to</td> | ||||
* <td align="center" valign="top">Yes</td> | * <td align="center" valign="top">Yes</td> | ||||
* </tr> | * </tr> | ||||
@@ -119,221 +116,117 @@ import org.apache.tools.ant.types.FileSet; | |||||
* | * | ||||
* @author: Glenn McAllister, inspired by a similar task written by Peter Kelley | * @author: Glenn McAllister, inspired by a similar task written by Peter Kelley | ||||
*/ | */ | ||||
public class VAJImport extends Task { | |||||
protected Vector filesets = new Vector(); | |||||
protected boolean importSources = true; | |||||
protected boolean importResources = true; | |||||
protected boolean importClasses = false; | |||||
protected String importProject = null; | |||||
protected Project vajproject = null; | |||||
/** | |||||
* The VisualAge for Java Project name to import into. | |||||
*/ | |||||
public void setVajproject(String projectName) { | |||||
this.importProject = projectName; | |||||
} | |||||
/** | |||||
* Adds a set of files (nested fileset attribute). | |||||
*/ | |||||
public void addFileset(FileSet set) { | |||||
filesets.addElement(set); | |||||
} | |||||
/** | |||||
* Import .class files. | |||||
*/ | |||||
public void setImportClasses(boolean importClasses) { | |||||
this.importClasses = importClasses; | |||||
} | |||||
/** | |||||
* Import resource files (anything that doesn't end in | |||||
* .class or .java) | |||||
*/ | |||||
public void setImportResources(boolean importResources) { | |||||
this.importResources = importResources; | |||||
} | |||||
/** | |||||
* Import .java files | |||||
*/ | |||||
public void setImportSources(boolean importSources) { | |||||
this.importSources = importSources; | |||||
} | |||||
/** | |||||
* Do the import. | |||||
*/ | |||||
public void execute() throws BuildException { | |||||
if (filesets.size() == 0) { | |||||
throw new BuildException("At least one fileset is required!"); | |||||
} | |||||
if (importProject == null || "".equals(importProject)) { | |||||
throw new BuildException("The VisualAge for Java Project name is required!"); | |||||
} | |||||
vajproject = getVAJProject(); | |||||
if (vajproject == null) { | |||||
try { | |||||
vajproject = VAJUtil.getWorkspace().createProject(this.importProject, true); | |||||
} catch (IvjException e) { | |||||
throw VAJUtil.createBuildException( "Error while creating Project " + | |||||
importProject + ": ", | |||||
e ); | |||||
} | |||||
} | |||||
for (Enumeration e = filesets.elements(); e.hasMoreElements();) { | |||||
importFileset((FileSet) e.nextElement()); | |||||
} | |||||
} | |||||
/** | |||||
* Try to get the project we want from the Workspace. | |||||
*/ | |||||
protected Project getVAJProject() { | |||||
Project found = null; | |||||
Project[] currentProjects = VAJUtil.getWorkspace().getProjects(); | |||||
for (int i = 0; i < currentProjects.length; i++) { | |||||
Project p = currentProjects[i]; | |||||
if (p.getName().equals(this.importProject)) { | |||||
found = p; | |||||
break; | |||||
} | |||||
} | |||||
return found; | |||||
} | |||||
/** | |||||
* Import all files from the fileset into the Project in the | |||||
* Workspace. | |||||
*/ | |||||
protected void importFileset(FileSet fileset) { | |||||
DirectoryScanner ds = fileset.getDirectoryScanner(this.project); | |||||
if (ds.getIncludedFiles().length == 0) { | |||||
return; | |||||
} | |||||
Vector classes = new Vector(); | |||||
Vector sources = new Vector(); | |||||
Vector resources = new Vector(); | |||||
String[] classesArr = null; | |||||
String[] sourcesArr = null; | |||||
String[] resourcesArr = null; | |||||
StringBuffer msg = new StringBuffer(); | |||||
msg.append("Importing "); | |||||
String connector = ""; | |||||
ImportCodeSpec importSpec = new ImportCodeSpec(); | |||||
importSpec.setDefaultProject(vajproject); | |||||
scan( | |||||
fileset.getDir(this.project), | |||||
ds.getIncludedFiles(), | |||||
classes, | |||||
sources, | |||||
resources); | |||||
if (importClasses) { | |||||
classesArr = new String[classes.size()]; | |||||
classes.copyInto(classesArr); | |||||
importSpec.setClassFiles(classesArr); | |||||
if (classesArr.length > 0) { | |||||
logFiles(classes, "class"); | |||||
msg.append( classesArr.length ); | |||||
msg.append( " class " ); | |||||
msg.append( classesArr.length > 1 ? "files" : "file" ); | |||||
connector = ", "; | |||||
} | |||||
} | |||||
if (importSources) { | |||||
sourcesArr = new String[sources.size()]; | |||||
sources.copyInto(sourcesArr); | |||||
importSpec.setJavaFiles(sourcesArr); | |||||
if (sourcesArr.length > 0) { | |||||
logFiles(sources, "source"); | |||||
msg.append( connector ); | |||||
msg.append( sourcesArr.length ); | |||||
msg.append( " source " ); | |||||
msg.append( sourcesArr.length > 1 ? "files" : "file" ); | |||||
connector = ", "; | |||||
} | |||||
} | |||||
if (importResources) { | |||||
String resourcePath = fileset.getDir(this.project).getAbsolutePath(); | |||||
resourcesArr = new String[resources.size()]; | |||||
resources.copyInto(resourcesArr); | |||||
importSpec.setResourcePath(resourcePath); | |||||
importSpec.setResourceFiles(resourcesArr); | |||||
if (resourcesArr.length > 0) { | |||||
logFiles(resources, "resource"); | |||||
log( " (relative to resource path '" + resourcePath + "')", | |||||
org.apache.tools.ant.Project.MSG_VERBOSE ); | |||||
msg.append( connector ); | |||||
msg.append( resourcesArr.length ); | |||||
msg.append( " resource " ); | |||||
msg.append( resourcesArr.length > 1 ? "files" : "file" ); | |||||
} | |||||
} | |||||
msg.append( " into the " ); | |||||
msg.append( importProject ); | |||||
msg.append( " project." ); | |||||
log(msg.toString()); | |||||
try { | |||||
Type[] importedTypes = VAJUtil.getWorkspace().importData(importSpec); | |||||
if (importedTypes == null) { | |||||
throw new BuildException("Unable to import into Workspace!"); | |||||
} | |||||
} catch (IvjException ivje) { | |||||
throw VAJUtil.createBuildException("Error while importing into Workspace: ", ivje); | |||||
} | |||||
} | |||||
/** | |||||
* Sort the files into classes, sources, and resources. | |||||
*/ | |||||
protected void scan( | |||||
File dir, | |||||
String[] files, | |||||
Vector classes, | |||||
Vector sources, | |||||
Vector resources) { | |||||
for (int i = 0; i < files.length; i++) { | |||||
String file = (new File(dir, files[i])).getAbsolutePath(); | |||||
if (file.endsWith(".java") || file.endsWith(".JAVA")) { | |||||
sources.addElement(file); | |||||
} else | |||||
if (file.endsWith(".class") || file.endsWith(".CLASS")) { | |||||
classes.addElement(file); | |||||
} else { | |||||
// for resources VA expects the path relative to the resource path | |||||
resources.addElement(files[i]); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Logs a list of file names to the message log | |||||
* @param fileNames java.util.Vector file names to be logged | |||||
* @param type java.lang.String file type | |||||
*/ | |||||
protected void logFiles(Vector fileNames, String fileType) { | |||||
log( fileType + " files found for import:", org.apache.tools.ant.Project.MSG_VERBOSE); | |||||
for ( Enumeration e = fileNames.elements(); e.hasMoreElements(); ) { | |||||
log( " " + e.nextElement(), org.apache.tools.ant.Project.MSG_VERBOSE ); | |||||
} | |||||
} | |||||
} | |||||
public class VAJImport extends VAJTask { | |||||
protected Vector filesets = new Vector(); | |||||
protected boolean importSources = true; | |||||
protected boolean importResources = true; | |||||
protected boolean importClasses = false; | |||||
protected String importProject = null; | |||||
protected boolean useDefaultExcludes = true; | |||||
/** | |||||
* The VisualAge for Java Project name to import into. | |||||
*/ | |||||
public void setProject(String projectName) { | |||||
this.importProject = projectName; | |||||
} | |||||
/** | |||||
* Adds a set of files (nested fileset attribute). | |||||
*/ | |||||
public void addFileset(FileSet set) { | |||||
filesets.addElement(set); | |||||
} | |||||
/** | |||||
* Import .class files. | |||||
*/ | |||||
public void setImportClasses(boolean importClasses) { | |||||
this.importClasses = importClasses; | |||||
} | |||||
/** | |||||
* Import resource files (anything that doesn't end in | |||||
* .class or .java) | |||||
*/ | |||||
public void setImportResources(boolean importResources) { | |||||
this.importResources = importResources; | |||||
} | |||||
/** | |||||
* Import .java files | |||||
*/ | |||||
public void setImportSources(boolean importSources) { | |||||
this.importSources = importSources; | |||||
} | |||||
/** | |||||
* Sets whether default exclusions should be used or not. | |||||
* | |||||
* @param useDefaultExcludes "true"|"on"|"yes" when default exclusions | |||||
* should be used, "false"|"off"|"no" when they | |||||
* shouldn't be used. | |||||
*/ | |||||
public void setDefaultexcludes(boolean useDefaultExcludes) { | |||||
this.useDefaultExcludes = useDefaultExcludes; | |||||
} | |||||
/** | |||||
* Do the import. | |||||
*/ | |||||
public void execute() throws BuildException { | |||||
if (filesets.size() == 0) { | |||||
throw new BuildException("At least one fileset is required!"); | |||||
} | |||||
if (importProject == null || "".equals(importProject)) { | |||||
throw new BuildException("The VisualAge for Java Project name is required!"); | |||||
} | |||||
for (Enumeration e = filesets.elements(); e.hasMoreElements();) { | |||||
importFileset((FileSet) e.nextElement()); | |||||
} | |||||
} | |||||
/** | |||||
* Import all files from the fileset into the Project in the | |||||
* Workspace. | |||||
*/ | |||||
protected void importFileset(FileSet fileset) { | |||||
DirectoryScanner ds = fileset.getDirectoryScanner(this.project); | |||||
if (ds.getIncludedFiles().length == 0) { | |||||
return; | |||||
} | |||||
String[] includes = null; | |||||
String[] excludes = null; | |||||
// Hack to get includes and excludes. We could also use getIncludedFiles, | |||||
// but that would result in very long HTTP-requests. | |||||
// Therefore we want to send the patterns only to the remote tool server | |||||
// and let him figure out the files. | |||||
try { | |||||
Class directoryScanner = ds.getClass(); | |||||
Field includesField = directoryScanner.getDeclaredField("includes"); | |||||
includesField.setAccessible(true); | |||||
includes = (String[]) includesField.get(ds); | |||||
Field excludesField = directoryScanner.getDeclaredField("excludes"); | |||||
excludesField.setAccessible(true); | |||||
excludes = (String[]) excludesField.get(ds); | |||||
} catch (NoSuchFieldException nsfe) { | |||||
throw new BuildException( | |||||
"DirectoryScanner.includes or .excludes missing" + nsfe.getMessage()); | |||||
} catch (IllegalAccessException iae) { | |||||
throw new BuildException( | |||||
"Access to DirectoryScanner.includes or .excludes not allowed"); | |||||
} | |||||
getUtil().importFiles( importProject, ds.getBasedir(), | |||||
includes, excludes, | |||||
importClasses, importResources, importSources, | |||||
useDefaultExcludes); | |||||
} | |||||
} |
@@ -0,0 +1,102 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import java.io.File; | |||||
/** | |||||
* A Remote Access to Tools Servlet to import a Project | |||||
* from files into the Repository. The following | |||||
* table describes the servlet parameters. | |||||
* | |||||
* <table> | |||||
* <tr> | |||||
* <td>Parameter</td> | |||||
* <td>Description</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>project</td> | |||||
* <td>The name of the project where you want the imported | |||||
* items to go. | |||||
* </td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>dir</td> | |||||
* <td>The directory you want to import from.</td> | |||||
* </tr> | |||||
* </table> | |||||
* | |||||
* @author Wolf Siberski, based on servlets written by Glenn McAllister | |||||
*/ | |||||
public class VAJImportServlet extends VAJToolsServlet { | |||||
/** | |||||
* Respond to a request to import files to the Repository | |||||
*/ | |||||
protected void executeRequest() { | |||||
getUtil().importFiles( | |||||
getFirstParamValueString(PROJECT_NAME_PARAM), | |||||
new File(getFirstParamValueString(DIR_PARAM)), | |||||
getParamValues(INCLUDE_PARAM), | |||||
getParamValues(EXCLUDE_PARAM), | |||||
getBooleanParam(CLASSES_PARAM, false), | |||||
getBooleanParam(RESOURCES_PARAM, true), | |||||
getBooleanParam(SOURCES_PARAM, true), | |||||
false // no default excludes, because they | |||||
// are already added on client side | |||||
// getBooleanParam(DEFAULT_EXCLUDES_PARAM, true) | |||||
); | |||||
} | |||||
} |
@@ -0,0 +1,92 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import java.util.Vector; | |||||
/** | |||||
* Load specific project versions into the Visual Age for Java workspace. | |||||
* Each project and version name has to be specified completely. | |||||
* Example: | |||||
* <blockquote> | |||||
* <vajload> | |||||
* <project name="MyVAProject" version="2.1"/> | |||||
* <project name="Apache Xerces" version="1.2.0"/> | |||||
* </vajload> | |||||
* </blockquote> | |||||
* | |||||
* @author Wolf Siberski, TUI Infotec GmbH | |||||
*/ | |||||
public class VAJLoad extends VAJTask { | |||||
Vector projectDescriptions = new Vector(); | |||||
/** | |||||
* Load specified projects. | |||||
*/ | |||||
public void execute() { | |||||
getUtil().loadProjects( projectDescriptions ); | |||||
} | |||||
/** | |||||
* Add a project description entry on the project list. | |||||
*/ | |||||
public VAJProjectDescription createVAJProject() { | |||||
VAJProjectDescription d = new VAJProjectDescription(); | |||||
projectDescriptions.addElement(d); | |||||
return d; | |||||
} | |||||
} |
@@ -54,8 +54,8 @@ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | package org.apache.tools.ant.taskdefs.optional.ide; | ||||
import com.ibm.ivj.util.base.IvjException; | |||||
import com.ibm.ivj.util.base.ProjectEdition; | |||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
import java.util.Vector; | import java.util.Vector; | ||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
@@ -63,189 +63,23 @@ import org.apache.tools.ant.Project; | |||||
import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
/** | /** | ||||
* Load specific project versions into the Visual Age for Java workspace. | |||||
* Each project and version name has to be specified completely. | |||||
* Example: | |||||
* <blockquote> | |||||
* <vajload> | |||||
* <project name="MyVAProject" version="2.1"/> | |||||
* <project name="Apache Xerces" version="1.2.0"/> | |||||
* </vajload> | |||||
* </blockquote> | |||||
* This is only there for backward compatibility with the default task list | |||||
* and will be removed soon | |||||
* | * | ||||
* @author Wolf Siberski, TUI Infotec GmbH | * @author Wolf Siberski, TUI Infotec GmbH | ||||
*/ | */ | ||||
public class VAJLoadProjects extends Task { | |||||
Vector projectDescriptions = new Vector(); | |||||
Vector expandedProjectDescriptions = new Vector(); | |||||
/** | |||||
* Class to maintain VisualAge for Java Workspace Project descriptions. | |||||
*/ | |||||
public class VAJProjectDescription { | |||||
private String name; | |||||
private String version; | |||||
private boolean projectFound; | |||||
public VAJProjectDescription() { | |||||
} | |||||
public VAJProjectDescription(String n, String v) { | |||||
name = n; | |||||
version = v; | |||||
} | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
public String getVersion() { | |||||
return version; | |||||
} | |||||
public boolean projectFound() { | |||||
return projectFound; | |||||
} | |||||
public void setName(String newName) { | |||||
if (newName == null || newName.equals("")) { | |||||
throw new BuildException("name attribute must be set"); | |||||
} | |||||
name = newName; | |||||
} | |||||
public void setVersion(String newVersion) { | |||||
if (newVersion == null || newVersion.equals("")) { | |||||
throw new BuildException("version attribute must be set"); | |||||
} | |||||
version = newVersion; | |||||
} | |||||
public void setProjectFound() { | |||||
projectFound = true; | |||||
} | |||||
} | |||||
/** | |||||
* Add a project description entry on the project list. | |||||
*/ | |||||
public VAJProjectDescription createVAJProject() { | |||||
VAJProjectDescription d = new VAJProjectDescription(); | |||||
projectDescriptions.addElement(d); | |||||
return d; | |||||
} | |||||
/** | |||||
* Load specified projects. | |||||
*/ | |||||
public void execute() { | |||||
expandDescriptions(); | |||||
log( | |||||
"Loading " + expandedProjectDescriptions.size() + " project(s) into workspace"); | |||||
for (Enumeration e = expandedProjectDescriptions.elements(); | |||||
e.hasMoreElements(); | |||||
) { | |||||
VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); | |||||
ProjectEdition pe = findProjectEdition(d.getName(), d.getVersion()); | |||||
try { | |||||
log( "Loading " + d.getName() + ", Version " + d.getVersion() + | |||||
", into Workspace", | |||||
Project.MSG_VERBOSE ); | |||||
pe.loadIntoWorkspace(); | |||||
} catch (IvjException ex) { | |||||
throw VAJUtil.createBuildException( "Project " + d.getName() + | |||||
" could not be loaded.", | |||||
ex ); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
*/ | |||||
public void expandDescriptions() { | |||||
String[] projectNames; | |||||
try { | |||||
projectNames = VAJUtil.getWorkspace().getRepository().getProjectNames(); | |||||
} catch (IvjException e) { | |||||
throw VAJUtil.createBuildException("VA Exception occured: ", e); | |||||
} | |||||
for (int i = 0; i < projectNames.length; i++) { | |||||
for (Enumeration e = projectDescriptions.elements(); e.hasMoreElements();) { | |||||
VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); | |||||
String pattern = d.getName(); | |||||
if (VAJWorkspaceScanner.match(pattern, projectNames[i])) { | |||||
d.setProjectFound(); | |||||
expandedProjectDescriptions. | |||||
addElement(new VAJProjectDescription(projectNames[i], d.getVersion())); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
for (Enumeration e = projectDescriptions.elements(); e.hasMoreElements();) { | |||||
VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); | |||||
if (!d.projectFound()) { | |||||
log("No Projects match the name " + d.getName(), Project.MSG_WARN); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
*/ | |||||
public static Vector findMatchingProjects(String pattern) { | |||||
String[] projectNames; | |||||
try { | |||||
projectNames = VAJUtil.getWorkspace().getRepository().getProjectNames(); | |||||
} catch (IvjException e) { | |||||
throw VAJUtil.createBuildException("VA Exception occured: ", e); | |||||
} | |||||
Vector matchingProjects = new Vector(); | |||||
for (int i = 0; i < projectNames.length; i++) { | |||||
if (VAJWorkspaceScanner.match(pattern, projectNames[i])) { | |||||
matchingProjects.addElement(projectNames[i]); | |||||
} | |||||
} | |||||
return matchingProjects; | |||||
} | |||||
/** | |||||
* Finds a specific project edition in the repository. | |||||
* | |||||
* @param name project name | |||||
* @param versionName project version name | |||||
* @return com.ibm.ivj.util.base.ProjectEdition | |||||
*/ | |||||
public static ProjectEdition findProjectEdition( | |||||
String name, | |||||
String versionName) { | |||||
try { | |||||
ProjectEdition[] editions = null; | |||||
editions = VAJUtil.getWorkspace().getRepository().getProjectEditions(name); | |||||
if (editions == null) { | |||||
throw new BuildException("Project " + name + " doesn't exist"); | |||||
} | |||||
ProjectEdition pe = null; | |||||
for (int i = 0; i < editions.length && pe == null; i++) { | |||||
if (versionName.equals(editions[i].getVersionName())) { | |||||
pe = editions[i]; | |||||
} | |||||
} | |||||
if (pe == null) { | |||||
throw new BuildException( "Version " + versionName + " of Project " + | |||||
name + " doesn't exist" ); | |||||
} | |||||
return pe; | |||||
} catch (IvjException e) { | |||||
throw VAJUtil.createBuildException("VA Exception occured: ", e); | |||||
} | |||||
} | |||||
public class VAJLoadProjects extends VAJLoad { | |||||
} | } | ||||
@@ -0,0 +1,106 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import java.util.Vector; | |||||
/** | |||||
* A Remote Access to Tools Servlet to load a Project | |||||
* from the Repository into the Workbench. The following | |||||
* table describes the servlet parameters. | |||||
* | |||||
* <table> | |||||
* <tr> | |||||
* <td>Parameter</td> | |||||
* <td>Description</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>project</td> | |||||
* <td>The name of the Project you want to load into | |||||
* the Workbench.</td> | |||||
* </tr> | |||||
* <tr> | |||||
* <td>version</td> | |||||
* <td>The version of the package you want to load into | |||||
* the Workbench.</td> | |||||
* </tr> | |||||
* </table> | |||||
* | |||||
* @author Wolf Siberski, based on servlets written by Glenn McAllister | |||||
*/ | |||||
public class VAJLoadServlet extends VAJToolsServlet { | |||||
// constants for servlet param names | |||||
public static final String VERSION_PARAM = "version"; | |||||
/** | |||||
* Respond to a request to load a project from the Repository | |||||
* into the Workbench. | |||||
*/ | |||||
protected void executeRequest() { | |||||
String[] projectNames = getParamValues(PROJECT_NAME_PARAM); | |||||
String[] versionNames = getParamValues(VERSION_PARAM); | |||||
Vector projectDescriptions = new Vector(projectNames.length); | |||||
for (int i = 0; i < projectNames.length && i < versionNames.length; i++) { | |||||
VAJProjectDescription desc = new VAJProjectDescription(); | |||||
desc.setName(projectNames[i]); | |||||
desc.setVersion(versionNames[i]); | |||||
projectDescriptions.addElement(desc); | |||||
} | |||||
util.loadProjects(projectDescriptions); | |||||
} | |||||
} |
@@ -0,0 +1,465 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import java.util.Vector; | |||||
import java.util.Enumeration; | |||||
import java.io.File; | |||||
import com.ibm.ivj.util.base.*; | |||||
import com.ibm.ivj.util.base.Package; | |||||
import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.DirectoryScanner; | |||||
/** | |||||
* Helper class for VAJ tasks. Holds Workspace singleton and | |||||
* wraps IvjExceptions into BuildExceptions | |||||
* | |||||
* @author Wolf Siberski, TUI Infotec GmbH | |||||
*/ | |||||
abstract class VAJLocalUtil implements VAJUtil{ | |||||
// singleton containing the VAJ workspace | |||||
static private Workspace workspace; | |||||
/** | |||||
* Wraps IvjException into a BuildException | |||||
* | |||||
* @return org.apache.tools.ant.BuildException | |||||
* @param errMsg Additional error message | |||||
* @param e IvjException which is wrapped | |||||
*/ | |||||
static BuildException createBuildException( | |||||
String errMsg, IvjException e) { | |||||
errMsg = errMsg + "\n" + e.getMessage(); | |||||
String[] errors = e.getErrors(); | |||||
if (errors != null) { | |||||
for (int i = 0; i < errors.length; i++) { | |||||
errMsg = errMsg + "\n" + errors[i]; | |||||
} | |||||
} | |||||
return new BuildException(errMsg); | |||||
} | |||||
/** | |||||
* returns the current VAJ workspace. | |||||
* @return com.ibm.ivj.util.base.Workspace | |||||
*/ | |||||
static Workspace getWorkspace() { | |||||
if (workspace == null) { | |||||
workspace = ToolEnv.connectToWorkspace(); | |||||
if (workspace == null) { | |||||
throw new BuildException( | |||||
"Unable to connect to Workspace! " | |||||
+ "Make sure you are running in VisualAge for Java."); | |||||
} | |||||
} | |||||
return workspace; | |||||
} | |||||
//----------------------------------------------------------- | |||||
// export | |||||
//----------------------------------------------------------- | |||||
/** | |||||
* export packages | |||||
*/ | |||||
public void exportPackages( | |||||
File dest, | |||||
String[] includePatterns, String[] excludePatterns, | |||||
boolean exportClasses, boolean exportDebugInfo, | |||||
boolean exportResources, boolean exportSources, | |||||
boolean useDefaultExcludes, boolean overwrite) { | |||||
if (includePatterns == null || includePatterns.length == 0) { | |||||
log( "You must specify at least one include attribute. " | |||||
+ "Not exporting", MSG_ERR); | |||||
} else { | |||||
try { | |||||
VAJWorkspaceScanner scanner = new VAJWorkspaceScanner(); | |||||
scanner.setIncludes(includePatterns); | |||||
scanner.setExcludes(excludePatterns); | |||||
if (useDefaultExcludes) { | |||||
scanner.addDefaultExcludes(); | |||||
} | |||||
scanner.scan(); | |||||
Package[] packages = scanner.getIncludedPackages(); | |||||
log( "Exporting " + packages.length + " package(s) to " | |||||
+ dest, MSG_INFO); | |||||
for (int i = 0; i < packages.length; i++) { | |||||
log(" " + packages[i].getName(), MSG_VERBOSE); | |||||
} | |||||
ExportCodeSpec exportSpec = new ExportCodeSpec(); | |||||
exportSpec.setPackages(packages); | |||||
exportSpec.includeJava(exportSources); | |||||
exportSpec.includeClass(exportClasses); | |||||
exportSpec.includeResources(exportResources); | |||||
exportSpec.includeClassDebugInfo(exportDebugInfo); | |||||
exportSpec.useSubdirectories(true); | |||||
exportSpec.overwriteFiles(overwrite); | |||||
exportSpec.setExportDirectory(dest.getAbsolutePath()); | |||||
getWorkspace().exportData(exportSpec); | |||||
} catch (IvjException ex) { | |||||
throw createBuildException("Exporting failed!", ex); | |||||
} | |||||
} | |||||
} | |||||
//----------------------------------------------------------- | |||||
// load | |||||
//----------------------------------------------------------- | |||||
/** | |||||
* Load specified projects. | |||||
*/ | |||||
public void loadProjects( Vector projectDescriptions ) { | |||||
Vector expandedDescs = getExpandedDescriptions(projectDescriptions); | |||||
// output warnings for projects not found | |||||
for (Enumeration e = projectDescriptions.elements(); e.hasMoreElements();) { | |||||
VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); | |||||
if (!d.projectFound()) { | |||||
log("No Projects match the name " + d.getName(), MSG_WARN); | |||||
} | |||||
} | |||||
log( "Loading " + expandedDescs.size() | |||||
+ " project(s) into workspace", MSG_INFO); | |||||
for (Enumeration e = expandedDescs.elements(); | |||||
e.hasMoreElements(); ) { | |||||
VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); | |||||
ProjectEdition pe = findProjectEdition(d.getName(), d.getVersion()); | |||||
try { | |||||
log( "Loading '" + d.getName() + "', Version '" + d.getVersion() | |||||
+ "', into Workspace", MSG_VERBOSE ); | |||||
pe.loadIntoWorkspace(); | |||||
} catch (IvjException ex) { | |||||
throw createBuildException( "Project '" + d.getName() | |||||
+ "' could not be loaded.", ex ); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* returns a list of project names matching the given pattern | |||||
*/ | |||||
private Vector findMatchingProjects(String pattern) { | |||||
String[] projectNames; | |||||
try { | |||||
projectNames = getWorkspace().getRepository().getProjectNames(); | |||||
} catch (IvjException e) { | |||||
throw createBuildException("VA Exception occured: ", e); | |||||
} | |||||
Vector matchingProjects = new Vector(); | |||||
for (int i = 0; i < projectNames.length; i++) { | |||||
if (VAJWorkspaceScanner.match(pattern, projectNames[i])) { | |||||
matchingProjects.addElement(projectNames[i]); | |||||
} | |||||
} | |||||
return matchingProjects; | |||||
} | |||||
/** | |||||
* return project descriptions containing full project names instead | |||||
* of patterns with wildcards. | |||||
*/ | |||||
private Vector getExpandedDescriptions(Vector projectDescs) { | |||||
Vector expandedDescs = new Vector(projectDescs.size()); | |||||
try { | |||||
String[] projectNames = | |||||
getWorkspace().getRepository().getProjectNames(); | |||||
for (int i = 0; i < projectNames.length; i++) { | |||||
for (Enumeration e = projectDescs.elements(); | |||||
e.hasMoreElements();) { | |||||
VAJProjectDescription d = (VAJProjectDescription) e.nextElement(); | |||||
String pattern = d.getName(); | |||||
if (VAJWorkspaceScanner.match(pattern, projectNames[i])) { | |||||
d.setProjectFound(); | |||||
expandedDescs.addElement(new VAJProjectDescription( | |||||
projectNames[i], d.getVersion())); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} catch (IvjException e) { | |||||
throw createBuildException("VA Exception occured: ", e); | |||||
} | |||||
return expandedDescs; | |||||
} | |||||
/** | |||||
* Finds a specific project edition in the repository. | |||||
* | |||||
* @param name project name | |||||
* @param versionName project version name | |||||
* @return com.ibm.ivj.util.base.ProjectEdition the specified edition | |||||
*/ | |||||
private ProjectEdition findProjectEdition( | |||||
String name, String versionName) { | |||||
try { | |||||
ProjectEdition[] editions = null; | |||||
editions = getWorkspace().getRepository().getProjectEditions(name); | |||||
if (editions == null) { | |||||
throw new BuildException("Project " + name + " doesn't exist"); | |||||
} | |||||
ProjectEdition pe = null; | |||||
for (int i = 0; i < editions.length && pe == null; i++) { | |||||
if (versionName.equals(editions[i].getVersionName())) { | |||||
pe = editions[i]; | |||||
} | |||||
} | |||||
if (pe == null) { | |||||
throw new BuildException( "Version " + versionName | |||||
+ " of Project " + name + " doesn't exist" ); | |||||
} | |||||
return pe; | |||||
} catch (IvjException e) { | |||||
throw createBuildException("VA Exception occured: ", e); | |||||
} | |||||
} | |||||
//----------------------------------------------------------- | |||||
// import | |||||
//----------------------------------------------------------- | |||||
/** | |||||
* Do the import. | |||||
*/ | |||||
public void importFiles( | |||||
String importProject, File srcDir, | |||||
String[] includePatterns, String[] excludePatterns, | |||||
boolean importClasses, boolean importResources, | |||||
boolean importSources, boolean useDefaultExcludes) | |||||
throws BuildException { | |||||
if (importProject == null || "".equals(importProject)) { | |||||
throw new BuildException("The VisualAge for Java project " | |||||
+ "name is required!"); | |||||
} | |||||
ImportCodeSpec importSpec = new ImportCodeSpec(); | |||||
importSpec.setDefaultProject(getVAJProject(importProject)); | |||||
DirectoryScanner ds = new DirectoryScanner(); | |||||
ds.setBasedir(srcDir); | |||||
ds.setIncludes(includePatterns); | |||||
ds.setExcludes(excludePatterns); | |||||
if ( useDefaultExcludes ) { | |||||
ds.addDefaultExcludes(); | |||||
} | |||||
ds.scan(); | |||||
Vector classes = new Vector(); | |||||
Vector sources = new Vector(); | |||||
Vector resources = new Vector(); | |||||
scanForImport( srcDir, ds.getIncludedFiles(), classes, sources, resources); | |||||
StringBuffer summaryLog = new StringBuffer("Importing "); | |||||
addFilesToImport( importSpec, importClasses, classes, "Class", summaryLog ); | |||||
addFilesToImport( importSpec, importSources, sources, "Java", summaryLog ); | |||||
addFilesToImport( importSpec, importResources, resources, "Resource", summaryLog ); | |||||
importSpec.setResourcePath(srcDir.getAbsolutePath()); | |||||
summaryLog.append( " into the project '" ); | |||||
summaryLog.append( importProject ); | |||||
summaryLog.append( "'." ); | |||||
log(summaryLog.toString(), MSG_INFO); | |||||
try { | |||||
Type[] importedTypes = getWorkspace().importData(importSpec); | |||||
if (importedTypes == null) { | |||||
throw new BuildException("Unable to import into Workspace!"); | |||||
} | |||||
else { | |||||
log( importedTypes.length + " types imported", MSG_DEBUG); | |||||
for( int i = 0; i < importedTypes.length; i++ ) { | |||||
log( importedTypes[i].getPackage().getName() | |||||
+ "." + importedTypes[i].getName() | |||||
+ " into " + importedTypes[i].getProject().getName(), | |||||
MSG_DEBUG); | |||||
} | |||||
} | |||||
} catch (IvjException ivje) { | |||||
throw createBuildException("Error while importing into workspace: ", | |||||
ivje); | |||||
} | |||||
} | |||||
/** | |||||
* get a project from the Workspace. | |||||
*/ | |||||
static Project getVAJProject(String importProject) { | |||||
Project found = null; | |||||
Project[] currentProjects = getWorkspace().getProjects(); | |||||
for (int i = 0; i < currentProjects.length; i++) { | |||||
Project p = currentProjects[i]; | |||||
if (p.getName().equals(importProject)) { | |||||
found = p; | |||||
break; | |||||
} | |||||
} | |||||
if (found == null) { | |||||
try { | |||||
found = getWorkspace().createProject(importProject, true); | |||||
} catch (IvjException e) { | |||||
throw createBuildException( "Error while creating Project " | |||||
+ importProject + ": ", e ); | |||||
} | |||||
} | |||||
return found; | |||||
} | |||||
/** | |||||
* Sort the files into classes, sources, and resources. | |||||
*/ | |||||
private void scanForImport( | |||||
File dir, | |||||
String[] files, | |||||
Vector classes, | |||||
Vector sources, | |||||
Vector resources) { | |||||
for (int i = 0; i < files.length; i++) { | |||||
String file = (new File(dir, files[i])).getAbsolutePath(); | |||||
if (file.endsWith(".java") || file.endsWith(".JAVA")) { | |||||
sources.addElement(file); | |||||
} else | |||||
if (file.endsWith(".class") || file.endsWith(".CLASS")) { | |||||
classes.addElement(file); | |||||
} else { | |||||
// for resources VA expects the path relative to the resource path | |||||
resources.addElement(files[i]); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Adds files to an import specification. Helper method | |||||
* for importFiles() | |||||
* | |||||
* @param spec import specification | |||||
* @param doImport only add files if doImport is true | |||||
* @param files the files to add | |||||
* @param fileType type of files (Source/Class/Resource) | |||||
* @param summaryLog buffer for logging | |||||
*/ | |||||
private void addFilesToImport( | |||||
ImportCodeSpec spec, boolean doImport, | |||||
Vector files, String fileType, | |||||
StringBuffer summaryLog) | |||||
{ | |||||
if (doImport) { | |||||
String[] fileArr = new String[files.size()]; | |||||
files.copyInto(fileArr); | |||||
try { | |||||
// here it is assumed that fileType is one of the | |||||
// following strings: // "Java", "Class", "Resource" | |||||
String methodName = "set"+fileType+"Files"; | |||||
Class[] methodParams = new Class[]{fileArr.getClass()}; | |||||
java.lang.reflect.Method method = | |||||
spec.getClass().getDeclaredMethod( methodName, methodParams); | |||||
method.invoke(spec, new Object[]{fileArr}); | |||||
} catch( Exception e ) { | |||||
throw new BuildException( e ); | |||||
} | |||||
if (files.size() > 0) { | |||||
logFiles(files, fileType ); | |||||
summaryLog.append(files.size()); | |||||
summaryLog.append(" " + fileType.toLowerCase() + " file"); | |||||
summaryLog.append(files.size() > 1 ? "s, " : ", "); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Logs a list of file names to the message log | |||||
* @param fileNames java.util.Vector file names to be logged | |||||
* @param type java.lang.String file type | |||||
*/ | |||||
private void logFiles(Vector fileNames, String fileType) { | |||||
log( fileType + " files found for import:", MSG_VERBOSE); | |||||
for ( Enumeration e = fileNames.elements(); e.hasMoreElements(); ) { | |||||
log( " " + e.nextElement(), MSG_VERBOSE ); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,105 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import org.apache.tools.ant.BuildException; | |||||
/** | |||||
* Type class. Holds information about a project edition. | |||||
* @author: Wolf Siberski | |||||
*/ | |||||
public class VAJProjectDescription { | |||||
private String name; | |||||
private String version; | |||||
private boolean projectFound; | |||||
public VAJProjectDescription() { | |||||
} | |||||
public VAJProjectDescription(String n, String v) { | |||||
name = n; | |||||
version = v; | |||||
} | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
public String getVersion() { | |||||
return version; | |||||
} | |||||
public boolean projectFound() { | |||||
return projectFound; | |||||
} | |||||
public void setName(String newName) { | |||||
if (newName == null || newName.equals("")) { | |||||
throw new BuildException("name attribute must be set"); | |||||
} | |||||
name = newName; | |||||
} | |||||
public void setVersion(String newVersion) { | |||||
if (newVersion == null || newVersion.equals("")) { | |||||
throw new BuildException("version attribute must be set"); | |||||
} | |||||
version = newVersion; | |||||
} | |||||
public void setProjectFound() { | |||||
projectFound = true; | |||||
} | |||||
} |
@@ -0,0 +1,250 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import java.util.Vector; | |||||
import java.net.URLConnection; | |||||
import java.net.HttpURLConnection; | |||||
import java.util.Enumeration; | |||||
import java.net.URL; | |||||
import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.Task; | |||||
import java.io.BufferedReader; | |||||
import java.io.IOException; | |||||
import java.io.InputStreamReader; | |||||
import java.io.InputStream; | |||||
import java.io.File; | |||||
/** | |||||
* Helper class for VAJ tasks. Holds Workspace singleton and | |||||
* wraps IvjExceptions into BuildExceptions | |||||
* | |||||
* @author Wolf Siberski, TUI Infotec GmbH | |||||
*/ | |||||
class VAJRemoteUtil implements VAJUtil{ | |||||
// calling task | |||||
Task caller; | |||||
// VAJ remote tool server | |||||
String remoteServer; | |||||
public VAJRemoteUtil( Task caller, String remote ) { | |||||
this.caller = caller; | |||||
this.remoteServer = remote; | |||||
} | |||||
/** | |||||
* export the array of Packages | |||||
*/ | |||||
public void exportPackages(File destDir, | |||||
String[] includePatterns, String[] excludePatterns, | |||||
boolean exportClasses, boolean exportDebugInfo, boolean exportResources, | |||||
boolean exportSources, boolean useDefaultExcludes, boolean overwrite ) { | |||||
try { | |||||
String request = "http://" + remoteServer + "/servlet/vajexport?" | |||||
+ VAJExportServlet.WITH_DEBUG_INFO + "=" + exportDebugInfo + "&" | |||||
+ VAJExportServlet.OVERWRITE_PARAM + "=" + overwrite + "&" | |||||
+ assembleImportExportParams( destDir, | |||||
includePatterns, excludePatterns, | |||||
exportClasses, exportResources, | |||||
exportSources, useDefaultExcludes ); | |||||
sendRequest( request); | |||||
} catch (Exception ex) { | |||||
throw new BuildException(ex); | |||||
} | |||||
} | |||||
/** | |||||
* Do the import. | |||||
*/ | |||||
public void importFiles( | |||||
String importProject, File srcDir, | |||||
String[] includePatterns, String[] excludePatterns, | |||||
boolean importClasses, boolean importResources, | |||||
boolean importSources, boolean useDefaultExcludes) { | |||||
try { | |||||
String request = "http://" + remoteServer + "/servlet/vajimport?" | |||||
+ VAJImportServlet.PROJECT_NAME_PARAM + "=" | |||||
+ importProject + "&" | |||||
+ assembleImportExportParams( srcDir, | |||||
includePatterns, excludePatterns, | |||||
importClasses, importResources, | |||||
importSources, useDefaultExcludes ); | |||||
sendRequest( request); | |||||
} catch (Exception ex) { | |||||
throw new BuildException(ex); | |||||
} | |||||
} | |||||
/** | |||||
* Assemble string for parameters common for import and export | |||||
* Helper method to remove double code. | |||||
*/ | |||||
private String assembleImportExportParams( | |||||
File dir, | |||||
String[] includePatterns, String[] excludePatterns, | |||||
boolean includeClasses, boolean includeResources, | |||||
boolean includeSources, boolean useDefaultExcludes) { | |||||
String result = | |||||
VAJToolsServlet.DIR_PARAM + "=" | |||||
+ dir.getAbsolutePath().replace('\\', '/') + "&" | |||||
+ VAJToolsServlet.CLASSES_PARAM + "=" + includeClasses + "&" | |||||
+ VAJToolsServlet.RESOURCES_PARAM + "=" + includeResources + "&" | |||||
+ VAJToolsServlet.SOURCES_PARAM + "=" + includeSources + "&" | |||||
+ VAJToolsServlet.DEFAULT_EXCLUDES_PARAM + "=" + useDefaultExcludes; | |||||
if ( includePatterns != null ) { | |||||
for ( int i = 0; i < includePatterns.length; i++ ){ | |||||
result= result + "&" + VAJExportServlet.INCLUDE_PARAM + "=" | |||||
+ includePatterns[i].replace(' ', '+').replace('\\', '/'); | |||||
} | |||||
} | |||||
if ( excludePatterns != null ) { | |||||
for ( int i = 0; i < excludePatterns.length; i++ ){ | |||||
result = result + "&" + VAJExportServlet.EXCLUDE_PARAM + "=" | |||||
+ excludePatterns[i].replace(' ', '+').replace('\\', '/'); | |||||
} | |||||
} | |||||
return result; | |||||
} | |||||
/** | |||||
* Load specified projects. | |||||
*/ | |||||
public void loadProjects( Vector projectDescriptions) { | |||||
try { | |||||
String request = "http://" + remoteServer + "/servlet/vajload?"; | |||||
String delimiter = ""; | |||||
for ( Enumeration e = projectDescriptions.elements(); e.hasMoreElements(); ){ | |||||
VAJProjectDescription pd = (VAJProjectDescription)e.nextElement(); | |||||
request = request | |||||
+ delimiter + VAJLoadServlet.PROJECT_NAME_PARAM | |||||
+ "=" + pd.getName().replace(' ', '+') | |||||
+ "&" + VAJLoadServlet.VERSION_PARAM | |||||
+ "=" + pd.getVersion().replace(' ', '+'); | |||||
//the first param needs no delimiter, but all other | |||||
delimiter = "&"; | |||||
} | |||||
sendRequest( request); | |||||
} catch (Exception ex) { | |||||
throw new BuildException(ex); | |||||
} | |||||
} | |||||
/** | |||||
* logs a message. | |||||
*/ | |||||
public void log(String msg, int level) { | |||||
caller.log( msg, level ); | |||||
} | |||||
/** | |||||
* Sends a servlet request. | |||||
*/ | |||||
private void sendRequest(String request) { | |||||
boolean requestFailed = false; | |||||
try { | |||||
log("Request: " + request, MSG_DEBUG); | |||||
//must be HTTP connection | |||||
URL requestUrl = new URL( request ); | |||||
HttpURLConnection connection = | |||||
(HttpURLConnection) requestUrl.openConnection(); | |||||
InputStream is = null; | |||||
// retry three times | |||||
for (int i = 0; i < 3; i++) { | |||||
try { | |||||
is = connection.getInputStream(); | |||||
break; | |||||
} catch (IOException ex) { | |||||
} | |||||
} | |||||
if (is == null) { | |||||
log("Can't get " + request, MSG_ERR); | |||||
throw new BuildException("Couldn't execute " + request ); | |||||
} | |||||
// log the response | |||||
BufferedReader br = new BufferedReader( new InputStreamReader( is ) ); | |||||
String line = br.readLine(); | |||||
while ( line != null ) { | |||||
int level = MSG_ERR; | |||||
try { | |||||
// the first char of each line contains the log level | |||||
level = Integer.parseInt( line.substring(0,1) ); | |||||
if ( level == MSG_ERR ) { | |||||
requestFailed = true; | |||||
} | |||||
} catch ( Exception e ) { | |||||
log( "Response line doesn't contain log level!", MSG_ERR ); | |||||
} | |||||
log( line.substring(2), level ); | |||||
line = br.readLine(); | |||||
} | |||||
} catch (IOException ex) { | |||||
log("Error sending tool request to VAJ" + ex, MSG_ERR); | |||||
throw new BuildException("Couldn't execute " + request ); | |||||
} | |||||
if ( requestFailed ) { | |||||
throw new BuildException( "VAJ tool request failed" ); | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,103 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
/** | |||||
* Super class for all VAJ tasks. Contains common | |||||
* attributes (remoteServer) and util methods | |||||
* | |||||
* @author: Wolf Siberski | |||||
*/ | |||||
import org.apache.tools.ant.Task; | |||||
public class VAJTask extends Task { | |||||
/** | |||||
* Adaption of VAJLocalUtil to Task context. | |||||
*/ | |||||
class VAJLocalToolUtil extends VAJLocalUtil { | |||||
public void log(String msg, int level) { | |||||
VAJTask.this.log( msg, level ); | |||||
} | |||||
} | |||||
// server name / port of VAJ remote tool api server | |||||
protected String remoteServer = null; | |||||
// holds the appropriate VAJUtil implementation | |||||
private VAJUtil util = null; | |||||
/** | |||||
* returns the VAJUtil implementation | |||||
*/ | |||||
protected VAJUtil getUtil() { | |||||
if ( util == null ) { | |||||
if ( remoteServer == null ) { | |||||
util = new VAJLocalToolUtil(); | |||||
} else { | |||||
util = new VAJRemoteUtil( this, remoteServer ); | |||||
} | |||||
} | |||||
return util; | |||||
} | |||||
/** | |||||
* Set remote server attribute | |||||
*/ | |||||
public void setRemote(String remoteServer) { | |||||
this.remoteServer = remoteServer; | |||||
} | |||||
} |
@@ -0,0 +1,226 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* 2. Redistributions in binary form must reproduce the above copyright | |||||
* notice, this list of conditions and the following disclaimer in | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* any, must include the following acknowlegement: | |||||
* "This product includes software developed by the | |||||
* Apache Software Foundation (http://www.apache.org/)." | |||||
* Alternately, this acknowlegement may appear in the software itself, | |||||
* if and wherever such third-party acknowlegements normally appear. | |||||
* | |||||
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | |||||
* Foundation" must not be used to endorse or promote products derived | |||||
* from this software without prior written permission. For written | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import com.ibm.ivj.toolserver.servletclasses.servlet.*; | |||||
import com.ibm.ivj.toolserver.servletclasses.servlet.http.*; | |||||
import java.io.*; | |||||
import javax.servlet.http.HttpServlet; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import javax.servlet.ServletException; | |||||
import org.apache.tools.ant.BuildException; | |||||
/** | |||||
* Abstract base class to provide common services for the | |||||
* VAJ tool API servlets | |||||
* | |||||
* @author Wolf Siberski, based on servlets written by Glenn McAllister | |||||
*/ | |||||
public abstract class VAJToolsServlet extends HttpServlet { | |||||
/** | |||||
* Adaptation of VAJUtil for servlet context. | |||||
*/ | |||||
class VAJLocalServletUtil extends VAJLocalUtil { | |||||
public void log(String msg, int level) { | |||||
try { | |||||
if ( msg != null ) { | |||||
msg = msg.replace('\r', ' '); | |||||
int i = 0; | |||||
while ( i < msg.length() ) { | |||||
int nlPos = msg.indexOf('\n', i); | |||||
if ( nlPos == -1 ) { | |||||
nlPos = msg.length(); | |||||
} | |||||
response.getWriter().println( Integer.toString(level) | |||||
+ " " + msg.substring( i, nlPos )); | |||||
i = nlPos + 1; | |||||
} | |||||
} | |||||
} catch( IOException e ) { | |||||
throw new BuildException( "logging failed. msg was: " | |||||
+ e.getMessage() ); | |||||
} | |||||
} | |||||
} | |||||
// constants for servlet param names | |||||
public static final String DIR_PARAM = "dir"; | |||||
public static final String INCLUDE_PARAM = "include"; | |||||
public static final String EXCLUDE_PARAM = "exclude"; | |||||
public static final String CLASSES_PARAM = "cls"; | |||||
public static final String SOURCES_PARAM = "src"; | |||||
public static final String RESOURCES_PARAM = "res"; | |||||
public static final String DEFAULT_EXCLUDES_PARAM = "dex"; | |||||
public static final String PROJECT_NAME_PARAM = "project"; | |||||
// current request | |||||
HttpServletRequest request; | |||||
// response to current request | |||||
HttpServletResponse response; | |||||
// implementation of VAJUtil used by the servlet | |||||
VAJUtil util; | |||||
/** | |||||
* Execute the request by calling the appropriate | |||||
* VAJ tool API methods. This method must be implemented | |||||
* by the concrete servlets | |||||
*/ | |||||
protected abstract void executeRequest(); | |||||
/** | |||||
* Respond to a HTTP request. This method initializes | |||||
* the servlet and handles errors. | |||||
* The real work is done in the abstract method executeRequest() | |||||
*/ | |||||
public void doGet(HttpServletRequest req, HttpServletResponse res) | |||||
throws ServletException, IOException { | |||||
try { | |||||
response = res; | |||||
request = req; | |||||
initRequest(); | |||||
executeRequest(); | |||||
} catch( BuildException e ) { | |||||
util.log("Error occured: " + e.getMessage(), VAJUtil.MSG_ERR); | |||||
} catch( Exception e ) { | |||||
try { | |||||
if ( ! (e instanceof BuildException) ) { | |||||
StringWriter sw = new StringWriter(); | |||||
e.printStackTrace(new PrintWriter(sw)); | |||||
String trace = new String( sw.getBuffer() ); | |||||
util.log("Program error in " + this.getClass().getName() | |||||
+ ":\n" + trace, VAJUtil.MSG_ERR); | |||||
} | |||||
} catch( Throwable t ) { | |||||
t.printStackTrace(); | |||||
} finally { | |||||
if ( ! (e instanceof BuildException) ) | |||||
{ | |||||
throw new ServletException( e.getMessage() ); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* initialize the servlet. | |||||
*/ | |||||
protected void initRequest() throws IOException { | |||||
response.setContentType("text/ascii"); | |||||
if ( util == null ) { | |||||
util = new VAJLocalServletUtil(); | |||||
} | |||||
} | |||||
/** | |||||
* Get the VAJUtil implementation | |||||
*/ | |||||
VAJUtil getUtil() { | |||||
return util; | |||||
} | |||||
/** | |||||
* Get the boolean value of a parameter. | |||||
*/ | |||||
protected boolean getBooleanParam(String param) { | |||||
return getBooleanParam(param, false); | |||||
} | |||||
/** | |||||
* Get the boolean value of a parameter, with a default value if | |||||
* the parameter hasn't been passed to the servlet. | |||||
*/ | |||||
protected boolean getBooleanParam(String param, boolean defaultValue) { | |||||
String value = getFirstParamValueString(param); | |||||
if (value != null) { | |||||
return toBoolean(value); | |||||
} else { | |||||
return defaultValue; | |||||
} | |||||
} | |||||
/** | |||||
* Returns the first encountered value for a parameter. | |||||
*/ | |||||
protected String getFirstParamValueString(String param) { | |||||
String[] paramValuesArray = request.getParameterValues(param); | |||||
if (paramValuesArray == null) { | |||||
return null; | |||||
} | |||||
return paramValuesArray[0]; | |||||
} | |||||
/** | |||||
* Returns all values for a parameter. | |||||
*/ | |||||
protected String[] getParamValues(String param) { | |||||
return request.getParameterValues(param); | |||||
} | |||||
/** | |||||
* A utility method to translate the strings "yes", "true", and "ok" | |||||
* to boolean true, and everything else to false. | |||||
*/ | |||||
protected boolean toBoolean(String string) { | |||||
String lower = string.toLowerCase(); | |||||
return (lower.equals("yes") || lower.equals("true") || lower.equals("ok")); | |||||
} | |||||
} |
@@ -51,58 +51,52 @@ | |||||
* information on the Apache Software Foundation, please see | * information on the Apache Software Foundation, please see | ||||
* <http://www.apache.org/>. | * <http://www.apache.org/>. | ||||
*/ | */ | ||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
package org.apache.tools.ant.taskdefs.optional.ide; | |||||
import com.ibm.ivj.util.base.IvjException; | |||||
import com.ibm.ivj.util.base.ToolEnv; | |||||
import com.ibm.ivj.util.base.Workspace; | |||||
import org.apache.tools.ant.BuildException; | |||||
import java.util.Vector; | |||||
import java.io.File; | |||||
/** | /** | ||||
* Helper class for VAJ tasks. Holds Workspace singleton and | |||||
* wraps IvjExceptions into BuildExceptions | |||||
* Helper interface for VAJ tasks. Encapsulates | |||||
* the interface to the VAJ tool API. | |||||
* | * | ||||
* @author Wolf Siberski, TUI Infotec GmbH | * @author Wolf Siberski, TUI Infotec GmbH | ||||
*/ | */ | ||||
class VAJUtil { | |||||
static private Workspace workspace; | |||||
/** | |||||
* Wraps IvjException into a BuildException | |||||
* | |||||
* @return org.apache.tools.ant.BuildException | |||||
* @param errMsg Additional error message | |||||
* @param e IvjException which is wrapped | |||||
*/ | |||||
public static BuildException createBuildException( | |||||
String errMsg, | |||||
IvjException e) { | |||||
errMsg = errMsg + "\n" + e.getMessage(); | |||||
String[] errors = e.getErrors(); | |||||
if (errors != null) { | |||||
for (int i = 0; i < errors.length; i++) { | |||||
errMsg = errMsg + "\n" + errors[i]; | |||||
} | |||||
} | |||||
return new BuildException(errMsg); | |||||
} | |||||
/** | |||||
* Insert the method's description here. | |||||
* Creation date: (19.09.2000 13:41:21) | |||||
* @return com.ibm.ivj.util.base.Workspace | |||||
*/ | |||||
public static Workspace getWorkspace() { | |||||
if (workspace == null) { | |||||
workspace = ToolEnv.connectToWorkspace(); | |||||
if (workspace == null) { | |||||
throw new BuildException( | |||||
"Unable to connect to Workspace! " | |||||
+ "Make sure you are running in VisualAge for Java."); | |||||
} | |||||
} | |||||
interface VAJUtil { | |||||
// log levels | |||||
public static final int MSG_DEBUG = 4; | |||||
public static final int MSG_ERR = 0; | |||||
public static final int MSG_INFO = 2; | |||||
public static final int MSG_VERBOSE = 3; | |||||
public static final int MSG_WARN = 1; | |||||
/** | |||||
* export the array of Packages | |||||
*/ | |||||
void exportPackages( | |||||
File dest, | |||||
String[] includePatterns, String[] excludePatterns, | |||||
boolean exportClasses, boolean exportDebugInfo, | |||||
boolean exportResources, boolean exportSources, | |||||
boolean useDefaultExcludes, boolean overwrite); | |||||
/** | |||||
* Do the import. | |||||
*/ | |||||
void importFiles( | |||||
String importProject, File srcDir, | |||||
String[] includePatterns, String[] excludePatterns, | |||||
boolean importClasses, boolean importResources, | |||||
boolean importSources, boolean useDefaultExcludes); | |||||
/** | |||||
* Load specified projects. | |||||
*/ | |||||
void loadProjects(Vector projectDescriptions); | |||||
return workspace; | |||||
} | |||||
/** | |||||
* Logs a message with the specified log level. | |||||
*/ | |||||
void log(String msg, int level); | |||||
} | } |
@@ -85,13 +85,9 @@ import org.apache.tools.ant.DirectoryScanner; | |||||
* | * | ||||
* @author Wolf Siberski, TUI Infotec (based on Arnout J. Kuipers DirectoryScanner) | * @author Wolf Siberski, TUI Infotec (based on Arnout J. Kuipers DirectoryScanner) | ||||
*/ | */ | ||||
public class VAJWorkspaceScanner extends DirectoryScanner { | |||||
class VAJWorkspaceScanner extends DirectoryScanner { | |||||
/** | |||||
* Patterns that should be excluded by default. | |||||
* | |||||
* @see #addDefaultExcludes() | |||||
*/ | |||||
// Patterns that should be excluded by default. | |||||
private final static String[] DEFAULTEXCLUDES = | private final static String[] DEFAULTEXCLUDES = | ||||
{ | { | ||||
"IBM*/**", | "IBM*/**", | ||||
@@ -101,10 +97,8 @@ public class VAJWorkspaceScanner extends DirectoryScanner { | |||||
"VisualAge*/**", | "VisualAge*/**", | ||||
}; | }; | ||||
/** | |||||
* The packages that where found and matched at least one includes, and | |||||
* matched no excludes. | |||||
*/ | |||||
// The packages that where found and matched at least | |||||
// one includes, and matched no excludes. | |||||
private Vector packagesIncluded = new Vector(); | private Vector packagesIncluded = new Vector(); | ||||
/** | /** | ||||
@@ -119,18 +113,19 @@ public class VAJWorkspaceScanner extends DirectoryScanner { | |||||
} | } | ||||
for (int i = 0; i < DEFAULTEXCLUDES.length; i++) { | for (int i = 0; i < DEFAULTEXCLUDES.length; i++) { | ||||
newExcludes[i + excludesLength] = DEFAULTEXCLUDES[i]. | newExcludes[i + excludesLength] = DEFAULTEXCLUDES[i]. | ||||
replace( '/', File.separatorChar ).replace( '\\', File.separatorChar ); | |||||
replace( '/', File.separatorChar ). | |||||
replace( '\\', File.separatorChar ); | |||||
} | } | ||||
excludes = newExcludes; | excludes = newExcludes; | ||||
} | } | ||||
/** | /** | ||||
* Finds all Projects specified in include patterns. | * Finds all Projects specified in include patterns. | ||||
* | * | ||||
* @return the projects | * @return the projects | ||||
*/ | */ | ||||
public Vector findMatchingProjects() { | public Vector findMatchingProjects() { | ||||
Project[] projects = VAJUtil.getWorkspace().getProjects(); | |||||
Project[] projects = VAJLocalUtil.getWorkspace().getProjects(); | |||||
Vector matchingProjects = new Vector(); | Vector matchingProjects = new Vector(); | ||||
@@ -138,7 +133,8 @@ public class VAJWorkspaceScanner extends DirectoryScanner { | |||||
for (int i = 0; i < projects.length; i++) { | for (int i = 0; i < projects.length; i++) { | ||||
Project project = projects[i]; | Project project = projects[i]; | ||||
for (int j = 0; j < includes.length && !allProjectsMatch; j++) { | for (int j = 0; j < includes.length && !allProjectsMatch; j++) { | ||||
StringTokenizer tok = new StringTokenizer(includes[j], File.separator); | |||||
StringTokenizer tok = | |||||
new StringTokenizer(includes[j], File.separator); | |||||
String projectNamePattern = tok.nextToken(); | String projectNamePattern = tok.nextToken(); | ||||
if (projectNamePattern.equals("**")) { | if (projectNamePattern.equals("**")) { | ||||
// if an include pattern starts with '**', | // if an include pattern starts with '**', | ||||
@@ -161,7 +157,7 @@ public class VAJWorkspaceScanner extends DirectoryScanner { | |||||
return matchingProjects; | return matchingProjects; | ||||
} | } | ||||
/** | /** | ||||
* Get the names of the packages that matched at least one of the include | * Get the names of the packages that matched at least one of the include | ||||
* patterns, and didn't match one of the exclude patterns. | * patterns, and didn't match one of the exclude patterns. | ||||
@@ -176,7 +172,7 @@ public class VAJWorkspaceScanner extends DirectoryScanner { | |||||
} | } | ||||
return packages; | return packages; | ||||
} | } | ||||
/** | /** | ||||
* Matches a string against a pattern. The pattern contains two special | * Matches a string against a pattern. The pattern contains two special | ||||
* characters: | * characters: | ||||
@@ -193,6 +189,7 @@ public class VAJWorkspaceScanner extends DirectoryScanner { | |||||
protected static boolean match(String pattern, String str) { | protected static boolean match(String pattern, String str) { | ||||
return DirectoryScanner.match(pattern, str); | return DirectoryScanner.match(pattern, str); | ||||
} | } | ||||
/** | /** | ||||
* Scans the workspace for packages that match at least one include | * Scans the workspace for packages that match at least one include | ||||
* pattern, and don't match any exclude patterns. | * pattern, and don't match any exclude patterns. | ||||
@@ -215,7 +212,7 @@ public class VAJWorkspaceScanner extends DirectoryScanner { | |||||
scanProject(project); | scanProject(project); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Scans a project for packages that match at least one include | * Scans a project for packages that match at least one include | ||||
* pattern, and don't match any exclude patterns. | * pattern, and don't match any exclude patterns. | ||||
@@ -240,7 +237,7 @@ public class VAJWorkspaceScanner extends DirectoryScanner { | |||||
} | } | ||||
} | } | ||||
} catch (IvjException e) { | } catch (IvjException e) { | ||||
throw VAJUtil.createBuildException("VA Exception occured: ", e); | |||||
throw VAJLocalUtil.createBuildException("VA Exception occured: ", e); | |||||
} | } | ||||
} | } | ||||
} | } |