Author: mriou
Date: Fri May 11 09:41:33 2007
New Revision: 537229

URL: http://svn.apache.org/viewvc?view=rev&rev=537229
Log:
Changed a bit the way the compiler generates the cbp file. Used to have some 
issues with several processes having the same name (but different namespaces) 
in the same bundle. So now:

1. The cbp file has the same name as the original bpel file.
2. It's generated in the same directory.

Also added a dry run mode so people can run the compiler to check their process 
without having any cbp file generated.

Modified:
    
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java
    
incubator/ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/bpelc/BpelCompileCommand.java

Modified: 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java?view=diff&rev=537229&r1=537228&r2=537229
==============================================================================
--- 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java
 (original)
+++ 
incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java
 Fri May 11 09:41:33 2007
@@ -58,12 +58,12 @@
 
     private CompileListener _compileListener;
     public OutputStream _outputStream = null;
-    private File _outputDir = null;
 
     private File _bpelFile;
     private ResourceFinder _wsdlFinder;
     private URI _bpel11wsdl;
     private Map<String,Object> _compileProperties;
+    private boolean _dryRun = false;
 
     public static BpelC newBpelCompiler() {
         return new BpelC();
@@ -82,7 +82,6 @@
         this.setResourceFinder(null);
         this.setCompileListener(null);
         this.setOutputStream(null);
-        this.setOutputDirectory(null);
     }
 
     /**
@@ -96,6 +95,15 @@
     }
 
     /**
+     * Configures the compiler to run a dry compilation, doesn't generate the 
produced
+     * compiled process.
+     * @param dryRun
+     */
+    public void setDryRun(boolean dryRun) {
+        _dryRun = dryRun;
+    }
+
+    /**
      * <p>
      * Tell the compiler how to locate WSDL imports for a BPEL process.  
Setting this
      * to <code>null</code> will cause the default behavior.
@@ -151,30 +159,6 @@
 
     /**
      * <p>
-     * Set the target directory for output.  This overrides [EMAIL PROTECTED] 
#setOutputStream(OutputStream)}.
-     * </p>
-     * @param outputDir the filesystem directory to write the compiled process 
to.
-     * @see #setOutputStream(OutputStream)
-     */
-    public void setOutputDirectory(File outputDir) {
-        // override any outputStream setting
-        this.setOutputStream(null);
-
-        // check if this is suitable for output
-        if (outputDir != null) {
-            if (outputDir.exists() && outputDir.isDirectory() && 
outputDir.canWrite()) {
-                _outputDir = outputDir;
-                if (__log.isDebugEnabled()) {
-                    __log.debug("Set output directory to " + 
outputDir.toURI());
-                }
-            } else {
-                throw new IllegalArgumentException("outputDirectory not 
writeable: " + outputDir.toURI());
-            }
-        }
-    }
-
-    /**
-     * <p>
      * Compile a BPEL process from a BOM [EMAIL PROTECTED] Process} object.
      * </p>
      *
@@ -187,7 +171,7 @@
      * @throws CompilationException
      *           if one occurs while compiling.
      */
-    public void compile(final Process process) throws CompilationException, 
IOException {
+    public void compile(final Process process, String outputPath) throws 
CompilationException, IOException {
         if (process == null)
             throw new NullPointerException("Attempt to compile NULL process.");
 
@@ -272,35 +256,37 @@
             throw cex;
         }
 
-        if (_outputStream != null) {
-            if (__log.isDebugEnabled()) {
-                __log.debug("Writing compilation results to " + 
_outputStream.getClass().getName());
-            }
-        } else if (_outputDir != null) {
-            File outFile = new File(_outputDir, oprocess.getName() + ".cbp");
-            this.setOutputStream(new BufferedOutputStream(new 
FileOutputStream(outFile)));
-            if (__log.isDebugEnabled()) {
-                __log.debug("Writing compilation results to " + 
outFile.toURI().toString());
+        if (!_dryRun) {
+            if (outputPath != null) {
+                this.setOutputStream(new BufferedOutputStream(new 
FileOutputStream(outputPath)));
+                System.out.println("Writing compilation results to " + 
outputPath);
+                if (__log.isDebugEnabled()) {
+                    __log.debug("Writing compilation results to " + 
outputPath);
+                }
+            } else if (_outputStream != null) {
+                if (__log.isDebugEnabled()) {
+                    __log.debug("Writing compilation results to " + 
_outputStream.getClass().getName());
+                }
+            } else {
+                throw new IllegalStateException("must setOutputStream() or 
setOutputDirectory()!");
             }
-        } else {
-            throw new IllegalStateException("must setOutputStream() or 
setOutputDirectory()!");
-        }
 
-        try {
-            Serializer fileHeader = new Serializer(System.currentTimeMillis());
-            fileHeader.writeOProcess(oprocess, _outputStream);
-        } finally {
-            // close & mark myself invalid
-            this.invalidate();
+            try {
+                Serializer fileHeader = new 
Serializer(System.currentTimeMillis());
+                fileHeader.writeOProcess(oprocess, _outputStream);
+            } finally {
+                // close & mark myself invalid
+                this.invalidate();
+            }
         }
     }
 
     /**
      * <p>
-     * Compile a BPEL process from a URL.  This method uses a [EMAIL 
PROTECTED] BpelProcessBuilder}
-     * to parse the XML and then calls [EMAIL PROTECTED] #compile(Process)}.
+     * Compile a BPEL process from a file.  This method uses a [EMAIL 
PROTECTED] BpelObjectFactory}
+     * to parse the XML and then calls [EMAIL PROTECTED] 
#compile(Process,String)}.
      * </p>
-     * @param bpelFile the URL of the BPEL process to be compiled.
+     * @param bpelFile the file of the BPEL process to be compiled.
      * @throws IOException if one occurs while reading the BPEL process or 
writing the
      * output.
      * @throws CompilationException if one occurs while compiling the process.
@@ -322,8 +308,6 @@
             isrc.setSystemId(bpelFile.getAbsolutePath());
 
             process = 
BpelObjectFactory.getInstance().parse(isrc,_bpelFile.toURI());
-
-
         } catch (Exception e) {
             CompilationMessage cmsg = __cmsgs.errBpelParseErr().setSource(new 
SourceLocationImpl(bpelFile.toURI()));
             this.invalidate();
@@ -332,7 +316,11 @@
 
         assert process != null;
 
-        compile(process);
+        // Output file = bpel file with a cbp extension
+        String bpelPath = bpelFile.getAbsolutePath();
+        String cbpPath = bpelPath.substring(0, bpelPath.lastIndexOf(".")) + 
".cbp";
+
+        compile(process, cbpPath);
         this.invalidate();
     }
 

Modified: 
incubator/ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java?view=diff&rev=537229&r1=537228&r2=537229
==============================================================================
--- 
incubator/ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
 (original)
+++ 
incubator/ode/trunk/bpel-store/src/main/java/org/apache/ode/store/DeploymentUnitDir.java
 Fri May 11 09:41:33 2007
@@ -128,7 +128,9 @@
         HashMap<QName, CBPInfo> processes = new HashMap<QName, CBPInfo>();
         ArrayList<File> cbps = listFilesRecursively(_duDirectory, 
DeploymentUnitDir._cbpFilter);
         for (File file : cbps) {
+            System.out.println("Found CBP file " + file.getAbsolutePath());
             CBPInfo cbpinfo = loadCBPInfo(file);
+            System.out.println("Process name " + cbpinfo.processName);
             processes.put(cbpinfo.processName, cbpinfo);
         }
         _processes = processes;
@@ -146,8 +148,8 @@
     }
 
     private void compile(File bpelFile) {
+        System.out.println("Compiling " + bpelFile.getAbsolutePath());
         BpelC bpelc = BpelC.newBpelCompiler();
-        bpelc.setOutputDirectory(_duDirectory);
         bpelc.setCompileProperties(prepareCompileProperties(bpelFile));
         try {
             bpelc.compile(bpelFile);

Modified: 
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/bpelc/BpelCompileCommand.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/bpelc/BpelCompileCommand.java?view=diff&rev=537229&r1=537228&r2=537229
==============================================================================
--- 
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/bpelc/BpelCompileCommand.java
 (original)
+++ 
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/bpelc/BpelCompileCommand.java
 Fri May 11 09:41:33 2007
@@ -108,7 +108,6 @@
       if (u != null) {
         compiler.setProcessWSDL(u);
       }
-      compiler.setOutputDirectory(_outputDir);
       compiler.setCompileListener(myListener);
 
       File bpelFile = new File(bpelURI);


Reply via email to