================================================================================ Merge Diffs: /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/weaving/StaticWeave.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000003/AB0952363AC40CBFE034080020E8C54E.0 Report generated at Mon Nov 27 11:26:27 2006 -------------------------------------------------------------------------------- *** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000003/AB0952363AC40CBFE034080020E8C54E.0 Mon Nov 27 11:25:10 2006 --- /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/weaving/StaticWeave.java Mon Nov 27 11:25:10 2006 *************** *** 0 **** --- 1,225 ---- + package oracle.toplink.essentials.weaving; + + import java.io.File; + import java.io.FileWriter; + import java.io.PrintStream; + import java.io.Writer; + import java.net.MalformedURLException; + import java.net.URL; + import java.net.URLClassLoader; + + import oracle.toplink.essentials.exceptions.StaticWeaveException; + import oracle.toplink.essentials.internal.localization.ExceptionLocalization; + import oracle.toplink.essentials.internal.localization.ToStringLocalization; + import oracle.toplink.essentials.logging.AbstractSessionLog; + import oracle.toplink.essentials.logging.SessionLog; + + /** + *
+ * Description: This is the static weave command line processing class that verifies command options and invokes + * StaticWeaveProcessor to statically weave the classes. + *
+ * Usage:
+ * Usage:
+ *
+ * Responsibilities:Process the source classes, performs weaving as necessary out outputs to the target
+ **/
+ public class StaticWeaveProcessor {
+ private URL source;
+ private URL target;
+ private URL persistenceInfo;
+ private Writer logWriter;
+ private ClassLoader classLoader;
+ private int logLevel = SessionLog.OFF;
+
+ /**
+ * Constructs an instance of StaticWeaveProcessor
+ * @param source the name of the location to be weaved
+ * @param target the name of the location to be weaved to
+ * @throws MalformedURLException
+ */
+ public StaticWeaveProcessor(String source,String target)throws MalformedURLException{
+ if (source!=null){
+ this.source=new File(source).toURL();
+ }
+ if (target!=null){
+ this.target=new File(target).toURL();
+ }
+ }
+
+ /**
+ * Constructs an instance of StaticWeaveProcessor
+ * @param source the File object of the source to be weaved
+ * @param target the File object of the target to be weaved to
+ * @throws MalformedURLException
+ */
+ public StaticWeaveProcessor(File source, File target)throws MalformedURLException{
+ this.source=source.toURL();
+ this.target=target.toURL();
+ }
+
+ /**
+ * Constructs an instance of StaticWeaveProcessor
+ * @param source the URL of the source to be weaved
+ * @param target the URL of the target to be weaved to
+ */
+ public StaticWeaveProcessor(URL source, URL target){
+ this.source=source;
+ this.target=target;
+ }
+
+ /**
+ * The method allows user to specify the ouput for the log message.
+ * @param log writer - the lcation where the log message writes to. the default value is standardout
+ */
+ public void setLog(Writer logWriter){
+ this.logWriter= logWriter;
+ }
+
+ /**
+ * The method allows user to define nine levels toplink logging.
+ * @param level - the integer value of log level. default is OFF.
+ */
+ public void setLogLevel(int level){
+ this.logLevel=level;
+ }
+
+ /**
+ * Set the user classloader.
+ * @param classLoader
+ */
+ public void setClassLoader(ClassLoader classLoader){
+ this.classLoader=classLoader;
+ }
+
+ /**
+ * Set an explicitly identified URL of the location containing persistence.xml.
+ * @param persistenceInfo the URL of the location containing persistence.xml, the URL
+ * must point to the root of META-INF/persistence.xml
+ */
+ public void setPersistenceInfo (URL persistenceInfo){
+ this.persistenceInfo = persistenceInfo;
+ }
+
+ /**
+ * Set an explicitly identified the location containing persistence.xml.
+ * @param persistenceinfo the path of the location containing persistence.xml, the path
+ * must point to the root of META-INF/persistence.xml
+ */
+ public void setPersistenceInfo(String persistenceInfoPath) throws MalformedURLException{
+ if (persistenceInfoPath!=null){
+ this.persistenceInfo=new File(persistenceInfoPath).toURL();
+ }
+ }
+
+
+ /**
+ * Set an explicitly identified the location containing persistence.xml.
+ * @param persistenceinfo the file containing persistence.xml, the file
+ * should contain META-INF/persistence.xml
+ */
+ public void setPersistenceInfo(File persistenceInfoFile) throws MalformedURLException{
+ if (persistenceInfoFile!=null){
+ this.persistenceInfo=persistenceInfoFile.toURL();
+ }
+ }
+
+
+ /**
+ * This method performs weaving function on the class individually from the specified source.
+ * @throws Exception.
+ */
+ public void performWeaving() throws URISyntaxException,MalformedURLException,IOException{
+ preProcess();
+ process();
+ }
+
+ /*
+ * INTERNAL:
+ * This method perform all necessary steps(verification, pre-build the target directory)
+ * prior to the invokation of the weaving function.
+ */
+ private void preProcess() throws URISyntaxException,MalformedURLException{
+ //Instantiate default session log
+ AbstractSessionLog.getLog().setLevel(this.logLevel);
+ if(logWriter!=null){
+ ((DefaultSessionLog)AbstractSessionLog.getLog()).setWriter(logWriter);
+ }
+
+ //Make sure the source is existing
+ if(!(new File(source.toURI())).exists()){
+ throw StaticWeaveException.missingSource();
+ }
+
+ //Verification target and source, two use cases create warning or exception.
+ //1. If source is directory and target is jar -
+ // This will lead unkown outcome, user attempt to use this tool to pack outcome into a Jar.
+ // Warning message will be logged, this is can be workarounded by other utilities.
+ //2. Both source and target are specified as a same jar -
+ // User was tryint to perform waving in same Jar which is not support, Exception will be thrown.
+ if(isDirectory(source) && target.toURI().toString().endsWith(".jar")){
+ AbstractSessionLog.getLog().log(SessionLog.WARNING, ToStringLocalization.buildMessage("staticweave_processor_unknown_outcome", new Object[]{null}));
+ }
+
+ if(!isDirectory(source) && target.toString().equals(source.toString())){
+ throw StaticWeaveException.weaveInplaceForJar(source.toString());
+ }
+
+ //pre-create target if it is directory and dose not exsit.
+ //Using the method File.isDirectory() is not enough to determine what the type(dir or jar)
+ //of the target(specified by URL)that user want to create. File.isDirectory() will return false in
+ //two possibilities, the location either is not directory or the location dose not exist.
+ //Therefore pre-build of the directory target is required. Pre-build for the file(JAR) target
+ //is not required since it gets built automically by opening outputstream.
+ if(!(new File(target.toURI())).exists()){
+ if(!target.toURI().toString().endsWith(".jar")){
+ (new File(target.toURI())).mkdirs();
+ //if directory fails to build, which may leads to unknown outcome since it will
+ //be treated as single file in the class StaticWeaveHandler and automicatlly gets built
+ //by outputstream.
+
+ //re-assign URL.
+ target = (new File(target.toURI())).toURL();
+ }
+ }
+ }
+
+ /*
+ * INTERNAL:
+ * The method performs weaving function
+ */
+ private void process() throws IOException,URISyntaxException{
+ //Instantiate output handler
+ AbstractStaticWeaveOutputHandler swoh;
+ if(isDirectory(this.target)){
+ swoh= new StaticWeaveDirectoryOutputHandler(this.source,this.target);
+ }else{
+ swoh= new StaticWeaveJAROutputHandler(new JarOutputStream(new FileOutputStream(new File(this.target.toURI()))));
+ }
+
+ //Instantiate classloader
+ this.classLoader = (this.classLoader == null)? Thread.currentThread().getContextClassLoader():this.classLoader;
+ this.classLoader = new URLClassLoader(getURLs(), this.classLoader);
+
+ //Instantiate the classtransformer, we check if the persistenceinfo URL has been specified.
+ StaticWeaveClassTransformer classTransformer=null;
+ if(persistenceInfo!=null){
+ classTransformer = new StaticWeaveClassTransformer(persistenceInfo, this.classLoader,this.logWriter,this.logLevel);
+ } else{
+ classTransformer = new StaticWeaveClassTransformer(source, this.classLoader,this.logWriter,this.logLevel);
+ }
+
+ //Starting process...
+ Archive sourceArchive =(new ArchiveFactoryImpl()).createArchive(source);
+ Iterator entries = sourceArchive.getEntries();
+ while (entries.hasNext()){
+ String entryName = (String)entries.next();
+ InputStream entryInputStream = sourceArchive.getEntry(entryName);
+ String className = PersistenceUnitProcessor.buildClassNameFromEntryString(entryName) ;
+
+ //Add a directory entry
+ swoh.addDirEntry(getDirectoryFromEntryName(entryName));
+
+ //Add a regular entry
+ JarEntry newEntry = new JarEntry(entryName);
+
+ byte[] originalClassBytes=null;
+ byte[] transferredClassBytes=null;
+ try {
+ Class thisClass = this.classLoader.loadClass(className);
+ //if the class is not in the classpath, we simply copy the entry
+ //to the target(no weaving).
+ if (thisClass == null){
+ swoh.addEntry(entryInputStream, newEntry);
+ continue;
+ }
+
+ //Try to read the loaded class bytes, the class bytes is required for
+ //classtransformer to perform transfer. Simply copy entry to the target(no weaving)
+ //if the class bytes can't be read.
+ InputStream is = this.classLoader.getResourceAsStream(entryName);
+ if (is!=null){
+ originalClassBytes = new byte[is.available()];
+ is.read(originalClassBytes);
+ }else{
+ swoh.addEntry(entryInputStream, newEntry);
+ continue;
+ }
+
+ //If everything is OK so far, we perform the weaving. we need three paramteres in order to
+ //class to perform weaving for that class, the class name,the class object and class bytes.
+ transferredClassBytes = classTransformer.transform(className.replace('.', '/'), thisClass, originalClassBytes);
+
+ //if transferredClassBytes is null means the class dose not get woven.
+ if(transferredClassBytes!=null){
+ swoh.addEntry(newEntry, transferredClassBytes);
+ } else{
+ swoh.addEntry(entryInputStream, newEntry);
+ }
+ } catch (IllegalClassFormatException e) {
+ //Anything went wrong, we need log a warning message, copy the entry to the target and
+ //process next entry.
+ swoh.addEntry(entryInputStream, newEntry);
+ continue;
+ } catch (ClassNotFoundException e){
+ swoh.addEntry(entryInputStream, newEntry);
+ continue;
+ }finally{
+ //need close the inputstream for current entry before processing next one.
+ entryInputStream.close();
+ }
+ }
+ swoh.closeOutputStream();
+ }
+
+
+ //Extract directory from entry name.
+ public static String getDirectoryFromEntryName(String entryName){
+ String result="";
+ if (entryName==null ) {
+ return result;
+ }
+ if(entryName.lastIndexOf("/")>=0){
+ result=entryName.substring(0, entryName.lastIndexOf("/"))+File.separator;
+ }
+ return result;
+ }
+
+ /*
+ * Determine whether or not the URL is pointing to directory.
+ */
+ private boolean isDirectory(URL url) throws URISyntaxException{
+ File file = new File(url.toURI());
+ if (file.isDirectory()) {
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ /*
+ * Generate URL array for specified source and persistenceinfo
+ */
+ private URL[] getURLs(){
+ if((this.source!=null) && (this.persistenceInfo!=null)){
+ return new URL[]{this.persistenceInfo,this.source};
+ } else if(this.source!=null){
+ return new URL[]{this.source};
+ } else if (this.persistenceInfo!=null){
+ return new URL[]{this.persistenceInfo};
+ }
+ return new URL[]{};
+ }
+ }
================================================================================
Merge Diffs: /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/exceptions/i18n/StaticWeaveExceptionResource.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000007/AB0952363AC40CBFE034080020E8C54E.0
Report generated at Mon Nov 27 11:26:27 2006
--------------------------------------------------------------------------------
*** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000007/AB0952363AC40CBFE034080020E8C54E.0 Mon Nov 27 11:25:21 2006
--- /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/exceptions/i18n/StaticWeaveExceptionResource.java Mon Nov 27 11:25:21 2006
***************
*** 0 ****
--- 1,43 ----
+ /*
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * glassfish/bootstrap/legal/CDDLv1.0.txt or
+ * https://glassfish.dev.java.net/public/CDDLv1.0.html.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ */
+ // Copyright (c) 1998, 2006, Oracle. All rights reserved.
+ package oracle.toplink.essentials.exceptions.i18n;
+
+ import java.util.ListResourceBundle;
+
+ public class StaticWeaveExceptionResource extends ListResourceBundle {
+ static final Object[][] contents = {
+ { "40001", "An exception was thrown while trying to open an archive from URL: {0}"},
+ { "40002", "No source was specified for weaving"},
+ { "40003", "No target was specified for weaving"},
+ { "40004", "Performing weaving in place for JAR file is not allowed"},
+ { "40005", "An exception was thrown while trying to open a logging file: {0}"},
+ { "40006", "Logging level was specified in wrong value, must be one of (OFF,SEVERE,WARNING,INFO,CONFIG,FINE,FINER,FINEST)"},
+ { "40007", "An exception was thrown while weaving: {0}"}
+ };
+
+ /**
+ * Return the lookup table.
+ */
+ protected Object[][] getContents() {
+ return contents;
+ }
+ }
================================================================================
Merge Diffs: /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/exceptions/StaticWeaveException.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000009/AB0952363AC40CBFE034080020E8C54E.0
Report generated at Mon Nov 27 11:26:27 2006
--------------------------------------------------------------------------------
*** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000009/AB0952363AC40CBFE034080020E8C54E.0 Mon Nov 27 11:25:25 2006
--- /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/exceptions/StaticWeaveException.java Mon Nov 27 11:25:24 2006
***************
*** 0 ****
--- 1,163 ----
+ /*
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * glassfish/bootstrap/legal/CDDLv1.0.txt or
+ * https://glassfish.dev.java.net/public/CDDLv1.0.html.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ */
+ // Copyright (c) 1998, 2006, Oracle. All rights reserved.
+ package oracle.toplink.essentials.exceptions;
+
+ import java.io.File;
+ import java.net.URL;
+
+ import oracle.toplink.essentials.exceptions.i18n.*;
+
+ public class StaticWeaveException extends TopLinkException {
+
+ private String resourceName = null;
+
+ public static final int EXCEPTION_OPENNING_ARCHIVE = 40001;
+ public static final int EXCEPTION_NO_SOURCE_SPECIFIED = 40002;
+ public static final int EXCEPTION_NO_TARGET_SPECIFIED = 40003;
+ public static final int EXCEPTION_NO_SUPPORT_WEAVING_INPLACE_FOR_JAR = 40004;
+ public static final int EXCEPTION_OPEN_LOGGING_FILE = 40005;
+ public static final int EXCEPTION_FOR_ILLEGALE_LOGGING_LEVEL = 40006;
+ public static final int EXCEPTION_WEAVING = 40007;
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public StaticWeaveException() {
+ super();
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ protected StaticWeaveException(String message) {
+ super(message);
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ protected StaticWeaveException(String message, Throwable internalException) {
+ super(message);
+ setInternalException(internalException);
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException exceptionOpeningArchive(URL archive, Exception cause) {
+ Object[] args = { archive };
+
+ StaticWeaveException openArchiveException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_OPENNING_ARCHIVE, args),cause);
+ openArchiveException.setResourceName(archive.toString());
+ openArchiveException.setErrorCode(EXCEPTION_OPENNING_ARCHIVE);
+ return openArchiveException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException weaveInplaceForJar(String filePath) {
+ Object[] args = { filePath };
+
+ StaticWeaveException loadingException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_NO_SUPPORT_WEAVING_INPLACE_FOR_JAR, args));
+ loadingException.setResourceName(filePath);
+ loadingException.setErrorCode(EXCEPTION_NO_SUPPORT_WEAVING_INPLACE_FOR_JAR);
+ return loadingException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException missingSource() {
+ Object[] args = { null };
+
+ StaticWeaveException missingSourceException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_NO_SOURCE_SPECIFIED, args));
+ missingSourceException.setResourceName(null);
+ missingSourceException.setErrorCode(EXCEPTION_NO_SOURCE_SPECIFIED);
+ return missingSourceException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException missingTarget() {
+ Object[] args = { null };
+
+ StaticWeaveException missingTargetException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_NO_TARGET_SPECIFIED, args));
+ missingTargetException.setResourceName(null);
+ missingTargetException.setErrorCode(EXCEPTION_NO_TARGET_SPECIFIED);
+ return missingTargetException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException openLoggingFileException(String LoggingFile,Exception cause) {
+ Object[] args = { LoggingFile };
+
+ StaticWeaveException loadingException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_OPEN_LOGGING_FILE, args), cause);
+ loadingException.setResourceName(LoggingFile);
+ loadingException.setErrorCode(EXCEPTION_OPEN_LOGGING_FILE);
+ return loadingException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException illegalLoggingLevel(String loggingLevel) {
+ Object[] args = { loggingLevel };
+
+ StaticWeaveException loadingException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_FOR_ILLEGALE_LOGGING_LEVEL, args));
+ loadingException.setResourceName(loggingLevel);
+ loadingException.setErrorCode(EXCEPTION_FOR_ILLEGALE_LOGGING_LEVEL);
+ return loadingException;
+ }
+
+
+ public static StaticWeaveException exceptionPerformWeaving(Exception cause) {
+ Object[] args = { };
+
+ StaticWeaveException loadingException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_WEAVING, args), cause);
+ loadingException.setResourceName(null);
+ loadingException.setErrorCode(EXCEPTION_WEAVING);
+ return loadingException;
+ }
+
+
+ public String getResourceName(){
+ return resourceName;
+ }
+
+ public void setResourceName(String resourceName){
+ this.resourceName = resourceName;
+ }
+
+ }
================================================================================
Merge Diffs: /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/internal/weaving/AbstractStaticWeaveOutputHandler.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000011/AB0952363AC40CBFE034080020E8C54E.0
Report generated at Mon Nov 27 11:26:27 2006
--------------------------------------------------------------------------------
*** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000011/AB0952363AC40CBFE034080020E8C54E.0 Mon Nov 27 11:25:28 2006
--- /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/internal/weaving/AbstractStaticWeaveOutputHandler.java Mon Nov 27 11:25:28 2006
***************
*** 0 ****
--- 1,71 ----
+ package oracle.toplink.essentials.internal.weaving;
+
+ import java.io.IOException;
+ import java.io.InputStream;
+ import java.io.OutputStream;
+ import java.net.URISyntaxException;
+ import java.util.jar.JarEntry;
+ import java.util.jar.JarOutputStream;
+
+ /**
+ * The abstract class provides a set of methods to out outputs into the sepcified archive file.
+ */
+ public abstract class AbstractStaticWeaveOutputHandler{
+ protected JarOutputStream outputStreamHolder=null;
+
+ /**
+ * create directory into target directory, or insert directory entry into outputstream.
+ * @param dirPath
+ * @throws IOException
+ */
+ abstract public void addDirEntry(String dirPath)throws IOException;
+
+ /**
+ * Write entry bytes into target, this is usually called if class has been tranformed
+ * @param targetEntry
+ * @param entryBytes
+ * @throws IOException
+ */
+ abstract public void addEntry(JarEntry targetEntry,byte[] entryBytes)throws IOException;
+
+ /**
+ * Write entry into target, this method usually copy original class into target.
+ * @param jis
+ * @param entry
+ * @throws IOException
+ */
+ abstract public void addEntry(InputStream jis,JarEntry entry) throws IOException,URISyntaxException;
+
+
+ /**
+ * Close the output stream.
+ * @throws IOException
+ */
+ public void closeOutputStream() throws IOException {
+ if(outputStreamHolder!=null){
+ outputStreamHolder.close();
+ }
+ }
+
+ /**
+ * Get the ouput stream instance.
+ * @return
+ */
+ public JarOutputStream getOutputStream(){
+ return this.outputStreamHolder;
+ }
+
+
+ // This is part of the ugly workaround for a design flaw
+ // in the JDK zip API, the entry will not write into the target zip file
+ // properly if this method not being gone through.
+ protected void readwriteStreams(InputStream in, OutputStream out) throws IOException
+ {
+ int numRead;
+ byte[] buffer = new byte[8*1024];
+
+ while ((numRead = in.read(buffer,0,buffer.length)) != -1) {
+ out.write(buffer,0,numRead);
+ }
+ }
+ }
================================================================================
Merge Diffs: /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/internal/weaving/StaticWeaveClassTransformer.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000012/AB0952363AC40CBFE034080020E8C54E.0
Report generated at Mon Nov 27 11:26:27 2006
--------------------------------------------------------------------------------
*** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000012/AB0952363AC40CBFE034080020E8C54E.0 Mon Nov 27 11:25:32 2006
--- /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/internal/weaving/StaticWeaveClassTransformer.java Mon Nov 27 11:25:31 2006
***************
*** 0 ****
--- 1,170 ----
+ package oracle.toplink.essentials.internal.weaving;
+
+ import java.io.IOException;
+ import java.io.Writer;
+ import java.lang.instrument.IllegalClassFormatException;
+ import java.net.URISyntaxException;
+ import java.net.URL;
+ import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.HashMap;
+ import java.util.Iterator;
+ import java.util.List;
+ import java.util.zip.ZipException;
+
+ import javax.persistence.spi.ClassTransformer;
+ import javax.persistence.spi.PersistenceUnitInfo;
+
+ import oracle.toplink.essentials.ejb.cmp3.persistence.Archive;
+ import oracle.toplink.essentials.ejb.cmp3.persistence.ArchiveFactoryImpl;
+ import oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor;
+ import oracle.toplink.essentials.ejb.cmp3.persistence.SEPersistenceUnitInfo;
+ import oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException;
+ import oracle.toplink.essentials.exceptions.StaticWeaveException;
+ import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor;
+ import oracle.toplink.essentials.internal.helper.EJB30ConversionManager;
+ import oracle.toplink.essentials.logging.DefaultSessionLog;
+ import oracle.toplink.essentials.logging.SessionLog;
+ import oracle.toplink.essentials.sessions.DatabaseLogin;
+ import oracle.toplink.essentials.sessions.Project;
+ import oracle.toplink.essentials.threetier.ServerSession;
+
+ /**
+ *
+ * Description: This class provides the implementation of class transformer by leveraging on the following existing APIs,
+ *
+ * Responsibilities:
+ *
+ * Description: This is the static weave command line processing class that verifies command options and invokes
+ * StaticWeaveProcessor to statically weave the classes.
+ *
+ * Usage:
+ * Usage:
+ *
+ * Responsibilities:Process the source classes, performs weaving as necessary out outputs to the target
+ **/
+ public class StaticWeaveProcessor {
+ private URL source;
+ private URL target;
+ private URL persistenceInfo;
+ private Writer logWriter;
+ private ClassLoader classLoader;
+ private int logLevel = SessionLog.OFF;
+
+ /**
+ * Constructs an instance of StaticWeaveProcessor
+ * @param source the name of the location to be weaved
+ * @param target the name of the location to be weaved to
+ * @throws MalformedURLException
+ */
+ public StaticWeaveProcessor(String source,String target)throws MalformedURLException{
+ if (source!=null){
+ this.source=new File(source).toURL();
+ }
+ if (target!=null){
+ this.target=new File(target).toURL();
+ }
+ }
+
+ /**
+ * Constructs an instance of StaticWeaveProcessor
+ * @param source the File object of the source to be weaved
+ * @param target the File object of the target to be weaved to
+ * @throws MalformedURLException
+ */
+ public StaticWeaveProcessor(File source, File target)throws MalformedURLException{
+ this.source=source.toURL();
+ this.target=target.toURL();
+ }
+
+ /**
+ * Constructs an instance of StaticWeaveProcessor
+ * @param source the URL of the source to be weaved
+ * @param target the URL of the target to be weaved to
+ */
+ public StaticWeaveProcessor(URL source, URL target){
+ this.source=source;
+ this.target=target;
+ }
+
+ /**
+ * The method allows user to specify the ouput for the log message.
+ * @param log writer - the lcation where the log message writes to. the default value is standardout
+ */
+ public void setLog(Writer logWriter){
+ this.logWriter= logWriter;
+ }
+
+ /**
+ * The method allows user to define nine levels toplink logging.
+ * @param level - the integer value of log level. default is OFF.
+ */
+ public void setLogLevel(int level){
+ this.logLevel=level;
+ }
+
+ /**
+ * Set the user classloader.
+ * @param classLoader
+ */
+ public void setClassLoader(ClassLoader classLoader){
+ this.classLoader=classLoader;
+ }
+
+ /**
+ * Set an explicitly identified URL of the location containing persistence.xml.
+ * @param persistenceInfo the URL of the location containing persistence.xml, the URL
+ * must point to the root of META-INF/persistence.xml
+ */
+ public void setPersistenceInfo (URL persistenceInfo){
+ this.persistenceInfo = persistenceInfo;
+ }
+
+ /**
+ * Set an explicitly identified the location containing persistence.xml.
+ * @param persistenceinfo the path of the location containing persistence.xml, the path
+ * must point to the root of META-INF/persistence.xml
+ */
+ public void setPersistenceInfo(String persistenceInfoPath) throws MalformedURLException{
+ if (persistenceInfoPath!=null){
+ this.persistenceInfo=new File(persistenceInfoPath).toURL();
+ }
+ }
+
+
+ /**
+ * Set an explicitly identified the location containing persistence.xml.
+ * @param persistenceinfo the file containing persistence.xml, the file
+ * should contain META-INF/persistence.xml
+ */
+ public void setPersistenceInfo(File persistenceInfoFile) throws MalformedURLException{
+ if (persistenceInfoFile!=null){
+ this.persistenceInfo=persistenceInfoFile.toURL();
+ }
+ }
+
+
+ /**
+ * This method performs weaving function on the class individually from the specified source.
+ * @throws Exception.
+ */
+ public void performWeaving() throws URISyntaxException,MalformedURLException,IOException{
+ preProcess();
+ process();
+ }
+
+ /*
+ * INTERNAL:
+ * This method perform all necessary steps(verification, pre-build the target directory)
+ * prior to the invokation of the weaving function.
+ */
+ private void preProcess() throws URISyntaxException,MalformedURLException{
+ //Instantiate default session log
+ AbstractSessionLog.getLog().setLevel(this.logLevel);
+ if(logWriter!=null){
+ ((DefaultSessionLog)AbstractSessionLog.getLog()).setWriter(logWriter);
+ }
+
+ //Make sure the source is existing
+ if(!(new File(source.toURI())).exists()){
+ throw StaticWeaveException.missingSource();
+ }
+
+ //Verification target and source, two use cases create warning or exception.
+ //1. If source is directory and target is jar -
+ // This will lead unkown outcome, user attempt to use this tool to pack outcome into a Jar.
+ // Warning message will be logged, this is can be workarounded by other utilities.
+ //2. Both source and target are specified as a same jar -
+ // User was tryint to perform waving in same Jar which is not support, Exception will be thrown.
+ if(isDirectory(source) && target.toURI().toString().endsWith(".jar")){
+ AbstractSessionLog.getLog().log(SessionLog.WARNING, ToStringLocalization.buildMessage("staticweave_processor_unknown_outcome", new Object[]{null}));
+ }
+
+ if(!isDirectory(source) && target.toString().equals(source.toString())){
+ throw StaticWeaveException.weaveInplaceForJar(source.toString());
+ }
+
+ //pre-create target if it is directory and dose not exsit.
+ //Using the method File.isDirectory() is not enough to determine what the type(dir or jar)
+ //of the target(specified by URL)that user want to create. File.isDirectory() will return false in
+ //two possibilities, the location either is not directory or the location dose not exist.
+ //Therefore pre-build of the directory target is required. Pre-build for the file(JAR) target
+ //is not required since it gets built automically by opening outputstream.
+ if(!(new File(target.toURI())).exists()){
+ if(!target.toURI().toString().endsWith(".jar")){
+ (new File(target.toURI())).mkdirs();
+ //if directory fails to build, which may leads to unknown outcome since it will
+ //be treated as single file in the class StaticWeaveHandler and automicatlly gets built
+ //by outputstream.
+
+ //re-assign URL.
+ target = (new File(target.toURI())).toURL();
+ }
+ }
+ }
+
+ /*
+ * INTERNAL:
+ * The method performs weaving function
+ */
+ private void process() throws IOException,URISyntaxException{
+ //Instantiate output handler
+ AbstractStaticWeaveOutputHandler swoh;
+ if(isDirectory(this.target)){
+ swoh= new StaticWeaveDirectoryOutputHandler(this.source,this.target);
+ }else{
+ swoh= new StaticWeaveJAROutputHandler(new JarOutputStream(new FileOutputStream(new File(this.target.toURI()))));
+ }
+
+ //Instantiate classloader
+ this.classLoader = (this.classLoader == null)? Thread.currentThread().getContextClassLoader():this.classLoader;
+ this.classLoader = new URLClassLoader(getURLs(), this.classLoader);
+
+ //Instantiate the classtransformer, we check if the persistenceinfo URL has been specified.
+ StaticWeaveClassTransformer classTransformer=null;
+ if(persistenceInfo!=null){
+ classTransformer = new StaticWeaveClassTransformer(persistenceInfo, this.classLoader,this.logWriter,this.logLevel);
+ } else{
+ classTransformer = new StaticWeaveClassTransformer(source, this.classLoader,this.logWriter,this.logLevel);
+ }
+
+ //Starting process...
+ Archive sourceArchive =(new ArchiveFactoryImpl()).createArchive(source);
+ Iterator entries = sourceArchive.getEntries();
+ while (entries.hasNext()){
+ String entryName = (String)entries.next();
+ InputStream entryInputStream = sourceArchive.getEntry(entryName);
+ String className = PersistenceUnitProcessor.buildClassNameFromEntryString(entryName) ;
+
+ //Add a directory entry
+ swoh.addDirEntry(getDirectoryFromEntryName(entryName));
+
+ //Add a regular entry
+ JarEntry newEntry = new JarEntry(entryName);
+
+ byte[] originalClassBytes=null;
+ byte[] transferredClassBytes=null;
+ try {
+ Class thisClass = this.classLoader.loadClass(className);
+ //if the class is not in the classpath, we simply copy the entry
+ //to the target(no weaving).
+ if (thisClass == null){
+ swoh.addEntry(entryInputStream, newEntry);
+ continue;
+ }
+
+ //Try to read the loaded class bytes, the class bytes is required for
+ //classtransformer to perform transfer. Simply copy entry to the target(no weaving)
+ //if the class bytes can't be read.
+ InputStream is = this.classLoader.getResourceAsStream(entryName);
+ if (is!=null){
+ originalClassBytes = new byte[is.available()];
+ is.read(originalClassBytes);
+ }else{
+ swoh.addEntry(entryInputStream, newEntry);
+ continue;
+ }
+
+ //If everything is OK so far, we perform the weaving. we need three paramteres in order to
+ //class to perform weaving for that class, the class name,the class object and class bytes.
+ transferredClassBytes = classTransformer.transform(className.replace('.', '/'), thisClass, originalClassBytes);
+
+ //if transferredClassBytes is null means the class dose not get woven.
+ if(transferredClassBytes!=null){
+ swoh.addEntry(newEntry, transferredClassBytes);
+ } else{
+ swoh.addEntry(entryInputStream, newEntry);
+ }
+ } catch (IllegalClassFormatException e) {
+ //Anything went wrong, we need log a warning message, copy the entry to the target and
+ //process next entry.
+ swoh.addEntry(entryInputStream, newEntry);
+ continue;
+ } catch (ClassNotFoundException e){
+ swoh.addEntry(entryInputStream, newEntry);
+ continue;
+ }finally{
+ //need close the inputstream for current entry before processing next one.
+ entryInputStream.close();
+ }
+ }
+ swoh.closeOutputStream();
+ }
+
+
+ //Extract directory from entry name.
+ public static String getDirectoryFromEntryName(String entryName){
+ String result="";
+ if (entryName==null ) {
+ return result;
+ }
+ if(entryName.lastIndexOf("/")>=0){
+ result=entryName.substring(0, entryName.lastIndexOf("/"))+File.separator;
+ }
+ return result;
+ }
+
+ /*
+ * Determine whether or not the URL is pointing to directory.
+ */
+ private boolean isDirectory(URL url) throws URISyntaxException{
+ File file = new File(url.toURI());
+ if (file.isDirectory()) {
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ /*
+ * Generate URL array for specified source and persistenceinfo
+ */
+ private URL[] getURLs(){
+ if((this.source!=null) && (this.persistenceInfo!=null)){
+ return new URL[]{this.persistenceInfo,this.source};
+ } else if(this.source!=null){
+ return new URL[]{this.source};
+ } else if (this.persistenceInfo!=null){
+ return new URL[]{this.persistenceInfo};
+ }
+ return new URL[]{};
+ }
+ }
================================================================================
Merge Diffs: /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/exceptions/i18n/StaticWeaveExceptionResource.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000007/AB0952363AC40CBFE034080020E8C54E.0
Report generated at Mon Nov 27 11:28:07 2006
--------------------------------------------------------------------------------
*** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000007/AB0952363AC40CBFE034080020E8C54E.0 Mon Nov 27 11:25:21 2006
--- /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/exceptions/i18n/StaticWeaveExceptionResource.java Mon Nov 27 11:25:21 2006
***************
*** 0 ****
--- 1,43 ----
+ /*
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * glassfish/bootstrap/legal/CDDLv1.0.txt or
+ * https://glassfish.dev.java.net/public/CDDLv1.0.html.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ */
+ // Copyright (c) 1998, 2006, Oracle. All rights reserved.
+ package oracle.toplink.essentials.exceptions.i18n;
+
+ import java.util.ListResourceBundle;
+
+ public class StaticWeaveExceptionResource extends ListResourceBundle {
+ static final Object[][] contents = {
+ { "40001", "An exception was thrown while trying to open an archive from URL: {0}"},
+ { "40002", "No source was specified for weaving"},
+ { "40003", "No target was specified for weaving"},
+ { "40004", "Performing weaving in place for JAR file is not allowed"},
+ { "40005", "An exception was thrown while trying to open a logging file: {0}"},
+ { "40006", "Logging level was specified in wrong value, must be one of (OFF,SEVERE,WARNING,INFO,CONFIG,FINE,FINER,FINEST)"},
+ { "40007", "An exception was thrown while weaving: {0}"}
+ };
+
+ /**
+ * Return the lookup table.
+ */
+ protected Object[][] getContents() {
+ return contents;
+ }
+ }
================================================================================
Merge Diffs: /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/exceptions/StaticWeaveException.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000009/AB0952363AC40CBFE034080020E8C54E.0
Report generated at Mon Nov 27 11:28:07 2006
--------------------------------------------------------------------------------
*** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000009/AB0952363AC40CBFE034080020E8C54E.0 Mon Nov 27 11:25:25 2006
--- /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/exceptions/StaticWeaveException.java Mon Nov 27 11:25:24 2006
***************
*** 0 ****
--- 1,163 ----
+ /*
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * glassfish/bootstrap/legal/CDDLv1.0.txt or
+ * https://glassfish.dev.java.net/public/CDDLv1.0.html.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ */
+ // Copyright (c) 1998, 2006, Oracle. All rights reserved.
+ package oracle.toplink.essentials.exceptions;
+
+ import java.io.File;
+ import java.net.URL;
+
+ import oracle.toplink.essentials.exceptions.i18n.*;
+
+ public class StaticWeaveException extends TopLinkException {
+
+ private String resourceName = null;
+
+ public static final int EXCEPTION_OPENNING_ARCHIVE = 40001;
+ public static final int EXCEPTION_NO_SOURCE_SPECIFIED = 40002;
+ public static final int EXCEPTION_NO_TARGET_SPECIFIED = 40003;
+ public static final int EXCEPTION_NO_SUPPORT_WEAVING_INPLACE_FOR_JAR = 40004;
+ public static final int EXCEPTION_OPEN_LOGGING_FILE = 40005;
+ public static final int EXCEPTION_FOR_ILLEGALE_LOGGING_LEVEL = 40006;
+ public static final int EXCEPTION_WEAVING = 40007;
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public StaticWeaveException() {
+ super();
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ protected StaticWeaveException(String message) {
+ super(message);
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ protected StaticWeaveException(String message, Throwable internalException) {
+ super(message);
+ setInternalException(internalException);
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException exceptionOpeningArchive(URL archive, Exception cause) {
+ Object[] args = { archive };
+
+ StaticWeaveException openArchiveException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_OPENNING_ARCHIVE, args),cause);
+ openArchiveException.setResourceName(archive.toString());
+ openArchiveException.setErrorCode(EXCEPTION_OPENNING_ARCHIVE);
+ return openArchiveException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException weaveInplaceForJar(String filePath) {
+ Object[] args = { filePath };
+
+ StaticWeaveException loadingException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_NO_SUPPORT_WEAVING_INPLACE_FOR_JAR, args));
+ loadingException.setResourceName(filePath);
+ loadingException.setErrorCode(EXCEPTION_NO_SUPPORT_WEAVING_INPLACE_FOR_JAR);
+ return loadingException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException missingSource() {
+ Object[] args = { null };
+
+ StaticWeaveException missingSourceException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_NO_SOURCE_SPECIFIED, args));
+ missingSourceException.setResourceName(null);
+ missingSourceException.setErrorCode(EXCEPTION_NO_SOURCE_SPECIFIED);
+ return missingSourceException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException missingTarget() {
+ Object[] args = { null };
+
+ StaticWeaveException missingTargetException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_NO_TARGET_SPECIFIED, args));
+ missingTargetException.setResourceName(null);
+ missingTargetException.setErrorCode(EXCEPTION_NO_TARGET_SPECIFIED);
+ return missingTargetException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException openLoggingFileException(String LoggingFile,Exception cause) {
+ Object[] args = { LoggingFile };
+
+ StaticWeaveException loadingException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_OPEN_LOGGING_FILE, args), cause);
+ loadingException.setResourceName(LoggingFile);
+ loadingException.setErrorCode(EXCEPTION_OPEN_LOGGING_FILE);
+ return loadingException;
+ }
+
+ /**
+ * INTERNAL:
+ * TopLink exceptions should only be thrown by TopLink.
+ */
+ public static StaticWeaveException illegalLoggingLevel(String loggingLevel) {
+ Object[] args = { loggingLevel };
+
+ StaticWeaveException loadingException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_FOR_ILLEGALE_LOGGING_LEVEL, args));
+ loadingException.setResourceName(loggingLevel);
+ loadingException.setErrorCode(EXCEPTION_FOR_ILLEGALE_LOGGING_LEVEL);
+ return loadingException;
+ }
+
+
+ public static StaticWeaveException exceptionPerformWeaving(Exception cause) {
+ Object[] args = { };
+
+ StaticWeaveException loadingException = new StaticWeaveException(ExceptionMessageGenerator.buildMessage(StaticWeaveException.class, EXCEPTION_WEAVING, args), cause);
+ loadingException.setResourceName(null);
+ loadingException.setErrorCode(EXCEPTION_WEAVING);
+ return loadingException;
+ }
+
+
+ public String getResourceName(){
+ return resourceName;
+ }
+
+ public void setResourceName(String resourceName){
+ this.resourceName = resourceName;
+ }
+
+ }
================================================================================
Merge Diffs: /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/internal/weaving/AbstractStaticWeaveOutputHandler.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000011/AB0952363AC40CBFE034080020E8C54E.0
Report generated at Mon Nov 27 11:28:07 2006
--------------------------------------------------------------------------------
*** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000011/AB0952363AC40CBFE034080020E8C54E.0 Mon Nov 27 11:25:28 2006
--- /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/internal/weaving/AbstractStaticWeaveOutputHandler.java Mon Nov 27 11:25:28 2006
***************
*** 0 ****
--- 1,71 ----
+ package oracle.toplink.essentials.internal.weaving;
+
+ import java.io.IOException;
+ import java.io.InputStream;
+ import java.io.OutputStream;
+ import java.net.URISyntaxException;
+ import java.util.jar.JarEntry;
+ import java.util.jar.JarOutputStream;
+
+ /**
+ * The abstract class provides a set of methods to out outputs into the sepcified archive file.
+ */
+ public abstract class AbstractStaticWeaveOutputHandler{
+ protected JarOutputStream outputStreamHolder=null;
+
+ /**
+ * create directory into target directory, or insert directory entry into outputstream.
+ * @param dirPath
+ * @throws IOException
+ */
+ abstract public void addDirEntry(String dirPath)throws IOException;
+
+ /**
+ * Write entry bytes into target, this is usually called if class has been tranformed
+ * @param targetEntry
+ * @param entryBytes
+ * @throws IOException
+ */
+ abstract public void addEntry(JarEntry targetEntry,byte[] entryBytes)throws IOException;
+
+ /**
+ * Write entry into target, this method usually copy original class into target.
+ * @param jis
+ * @param entry
+ * @throws IOException
+ */
+ abstract public void addEntry(InputStream jis,JarEntry entry) throws IOException,URISyntaxException;
+
+
+ /**
+ * Close the output stream.
+ * @throws IOException
+ */
+ public void closeOutputStream() throws IOException {
+ if(outputStreamHolder!=null){
+ outputStreamHolder.close();
+ }
+ }
+
+ /**
+ * Get the ouput stream instance.
+ * @return
+ */
+ public JarOutputStream getOutputStream(){
+ return this.outputStreamHolder;
+ }
+
+
+ // This is part of the ugly workaround for a design flaw
+ // in the JDK zip API, the entry will not write into the target zip file
+ // properly if this method not being gone through.
+ protected void readwriteStreams(InputStream in, OutputStream out) throws IOException
+ {
+ int numRead;
+ byte[] buffer = new byte[8*1024];
+
+ while ((numRead = in.read(buffer,0,buffer.length)) != -1) {
+ out.write(buffer,0,numRead);
+ }
+ }
+ }
================================================================================
Merge Diffs: /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/internal/weaving/StaticWeaveClassTransformer.java vs. /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000012/AB0952363AC40CBFE034080020E8C54E.0
Report generated at Mon Nov 27 11:28:07 2006
--------------------------------------------------------------------------------
*** /net/stottnfs2.ca.oracle.com/vol/vol1/ade_ottawa_txn/xiaosche/xiaosche_main_staticweave_061124/ade_storage/000012/AB0952363AC40CBFE034080020E8C54E.0 Mon Nov 27 11:25:32 2006
--- /ade/xiaosche_tl_main_test/tldev/source/essentials/oracle/toplink/essentials/internal/weaving/StaticWeaveClassTransformer.java Mon Nov 27 11:25:31 2006
***************
*** 0 ****
--- 1,170 ----
+ package oracle.toplink.essentials.internal.weaving;
+
+ import java.io.IOException;
+ import java.io.Writer;
+ import java.lang.instrument.IllegalClassFormatException;
+ import java.net.URISyntaxException;
+ import java.net.URL;
+ import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.HashMap;
+ import java.util.Iterator;
+ import java.util.List;
+ import java.util.zip.ZipException;
+
+ import javax.persistence.spi.ClassTransformer;
+ import javax.persistence.spi.PersistenceUnitInfo;
+
+ import oracle.toplink.essentials.ejb.cmp3.persistence.Archive;
+ import oracle.toplink.essentials.ejb.cmp3.persistence.ArchiveFactoryImpl;
+ import oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor;
+ import oracle.toplink.essentials.ejb.cmp3.persistence.SEPersistenceUnitInfo;
+ import oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException;
+ import oracle.toplink.essentials.exceptions.StaticWeaveException;
+ import oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor;
+ import oracle.toplink.essentials.internal.helper.EJB30ConversionManager;
+ import oracle.toplink.essentials.logging.DefaultSessionLog;
+ import oracle.toplink.essentials.logging.SessionLog;
+ import oracle.toplink.essentials.sessions.DatabaseLogin;
+ import oracle.toplink.essentials.sessions.Project;
+ import oracle.toplink.essentials.threetier.ServerSession;
+
+ /**
+ *
+ * Description: This class provides the implementation of class transformer by leveraging on the following existing APIs,
+ *
+ * Responsibilities:
+ *
+ * StaticWeave [options] source target
+ * Options:
+ * -classpath
+ * Set the user class path, use ";" as the delimiter in Window system and ":" in Unix system.
+ * -log
+ * the path of log file, the standard output will be the default.
+ * -loglevel
+ * nbsp; specify a literal value for toplink log level(OFF,SEVERE,WARNING,INFO,CONFIG,FINE,FINER,FINEST). The default value is OFF.
+ * -persistenceinfo
+ * The path contains META-INF/persistence.xml. This is ONLY required when the source does not include it.
+ * The classpath must contain all the classes necessary in oder to perform weaving.
+ * The weaving will be performed in place if source and target point to the same location. Weaving in place is ONLY applicable for directory-based sources.
+ *Example:
+ * To weave all entites contained in c:\foo-source.jar with its persistence.xml contained within c:\foo-containing-persistence-xml.jar, and output to c:\\foo-target.jar,
+ *StaticWeave -persistenceinfo c:\foo-containing-persistencexml.jar -classpath c:\classpath1;c:\classpath2 c:\foo-source.jar -o c:\foo-target.jar\r\r"}
+ *
+ **/
+
+ public class StaticWeave {
+
+ // command line arguments
+ private String[] argv;
+
+ // The location path of the source, null if none was given
+ private String source;
+
+ // The location path containing persistence.xml, null if none was given
+ private String persistenceinfopath;
+
+ // The location path of the target, null if none was given
+ private String target;
+
+ private int loglevel=SessionLog.OFF;
+
+ private Writer logWriter;
+
+ private PrintStream vout = System.out;
+
+ private String[] classpaths;
+
+ public static void main(String[] argv) {
+
+ StaticWeave staticweaver = new StaticWeave(argv);
+
+ try {
+ // Verify the command line arguments
+ staticweaver.processCommandLine();
+ staticweaver.start();
+ } catch (Exception e) {
+ throw StaticWeaveException.exceptionPerformWeaving(e);
+ }
+ }
+
+
+ public StaticWeave(String[] argv) {
+ this.argv = argv;
+ }
+
+ /**
+ * Invoke StaticWeaveProcessor to perform weaving.
+ */
+ public void start() throws Exception {
+
+ //perform weaving
+ StaticWeaveProcessor staticWeaverProcessor= new StaticWeaveProcessor(this.source,this.target);
+ if(persistenceinfopath!=null){
+ staticWeaverProcessor.setPersistenceInfo(this.persistenceinfopath);
+ }
+ if(classpaths!=null){
+ staticWeaverProcessor.setClassLoader(getClassLoader());
+ }
+ if(logWriter!=null){
+ staticWeaverProcessor.setLog(logWriter);
+ }
+ staticWeaverProcessor.setLogLevel(loglevel);
+ staticWeaverProcessor.performWeaving();
+ }
+
+
+ /*
+ * Verify command line option.
+ */
+ void processCommandLine() throws Exception
+ {
+ if (argv.length < 2 || argv.length>10) {
+ printUsage();
+ System.exit(1);
+ }
+ for (int i=0;i
+ *
+ *Example:
+ *
+ *<target name="define.task" description="New task definition for toplink static weaving"/>
+ */
+
+
+ public class StaticWeaveAntTask extends Task{
+
+ private String source;
+ private String persistenceinfo;
+ private String target;
+ private Vector classPaths = new Vector();
+ private int logLevel=SessionLog.OFF;
+ private Writer logWriter;
+
+
+ /**
+ * Set the input archive to be used to weave.
+ * @param inputJarFile
+ */
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ /**
+ * Set output archive to be used to weave to
+ * @param outputJarFile
+ */
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ /**
+ * Set the archive containing persistence.xml while input archive does not contain it.
+ * @param inputMainJarFile
+ */
+ public void setLog(String logFile) throws IOException {
+ try{
+ this.logWriter = new FileWriter(logFile);
+ }catch(Exception e){
+ throw StaticWeaveException.openLoggingFileException(logFile,e);
+ }
+ }
+
+ public void setLogLevel(String logLevel) {
+ if (logLevel.equalsIgnoreCase("OFF") ||
+ logLevel.equalsIgnoreCase("SEVERE") ||
+ logLevel.equalsIgnoreCase("WARNING") ||
+ logLevel.equalsIgnoreCase("INFO") ||
+ logLevel.equalsIgnoreCase("CONFIG") ||
+ logLevel.equalsIgnoreCase("FINE") ||
+ logLevel.equalsIgnoreCase("FINER") ||
+ logLevel.equalsIgnoreCase("FINEST") ||
+ logLevel.equalsIgnoreCase("ALL")) {
+ this.logLevel=AbstractSessionLog.translateStringToLoggingLevel(logLevel.toUpperCase());
+ } else{
+ throw StaticWeaveException.illegalLoggingLevel(logLevel);
+ }
+ }
+
+ public void setPersistenceinfo(String persistenceinfo) {
+ this.persistenceinfo = persistenceinfo;
+ }
+
+ /**
+ * Add the dependent classpath in order to load classes from the specified input jar.
+ * @param path
+ */
+ public void addClasspath(Path path) {
+ classPaths.add(path);
+ }
+
+ /*
+ * Parse the class path element and store them into vector.
+ */
+ private Vector getPathElement(){
+ Vector pathElements = new Vector();
+ for(int i=0;i
+ * <taskdef name="weave" classname="oracle.toplink.essentials.weaving.StaticWeaverAntTask"/>
+ *</target>
+ *<target name="weaving" description="perform weaving." depends="define.task">
+ * <weave source= "c:\foo.jar" target = "c:\wovenfoo.jar" persistenceinfo="c:\foo-containing-persistenceinfo.jar">
+ * <classpath>
+ * <pathelement path="c:\foo-dependent.jar"/>
+ * </classpath>
+ * </weave>
+ *</target>
+ *
+ *
+ *
+ *
+ *
+ **/
+
+ public class StaticWeaveClassTransformer {
+ private ArrayList
+ * StaticWeave [options] source target
+ * Options:
+ * -classpath
+ * Set the user class path, use ";" as the delimiter in Window system and ":" in Unix system.
+ * -log
+ * the path of log file, the standard output will be the default.
+ * -loglevel
+ * nbsp; specify a literal value for toplink log level(OFF,SEVERE,WARNING,INFO,CONFIG,FINE,FINER,FINEST). The default value is OFF.
+ * -persistenceinfo
+ * The path contains META-INF/persistence.xml. This is ONLY required when the source does not include it.
+ * The classpath must contain all the classes necessary in oder to perform weaving.
+ * The weaving will be performed in place if source and target point to the same location. Weaving in place is ONLY applicable for directory-based sources.
+ *Example:
+ * To weave all entites contained in c:\foo-source.jar with its persistence.xml contained within c:\foo-containing-persistence-xml.jar, and output to c:\\foo-target.jar,
+ *StaticWeave -persistenceinfo c:\foo-containing-persistencexml.jar -classpath c:\classpath1;c:\classpath2 c:\foo-source.jar -o c:\foo-target.jar\r\r"}
+ *
+ **/
+
+ public class StaticWeave {
+
+ // command line arguments
+ private String[] argv;
+
+ // The location path of the source, null if none was given
+ private String source;
+
+ // The location path containing persistence.xml, null if none was given
+ private String persistenceinfopath;
+
+ // The location path of the target, null if none was given
+ private String target;
+
+ private int loglevel=SessionLog.OFF;
+
+ private Writer logWriter;
+
+ private PrintStream vout = System.out;
+
+ private String[] classpaths;
+
+ public static void main(String[] argv) {
+
+ StaticWeave staticweaver = new StaticWeave(argv);
+
+ try {
+ // Verify the command line arguments
+ staticweaver.processCommandLine();
+ staticweaver.start();
+ } catch (Exception e) {
+ throw StaticWeaveException.exceptionPerformWeaving(e);
+ }
+ }
+
+
+ public StaticWeave(String[] argv) {
+ this.argv = argv;
+ }
+
+ /**
+ * Invoke StaticWeaveProcessor to perform weaving.
+ */
+ public void start() throws Exception {
+
+ //perform weaving
+ StaticWeaveProcessor staticWeaverProcessor= new StaticWeaveProcessor(this.source,this.target);
+ if(persistenceinfopath!=null){
+ staticWeaverProcessor.setPersistenceInfo(this.persistenceinfopath);
+ }
+ if(classpaths!=null){
+ staticWeaverProcessor.setClassLoader(getClassLoader());
+ }
+ if(logWriter!=null){
+ staticWeaverProcessor.setLog(logWriter);
+ }
+ staticWeaverProcessor.setLogLevel(loglevel);
+ staticWeaverProcessor.performWeaving();
+ }
+
+
+ /*
+ * Verify command line option.
+ */
+ void processCommandLine() throws Exception
+ {
+ if (argv.length < 2 || argv.length>10) {
+ printUsage();
+ System.exit(1);
+ }
+ for (int i=0;i
+ *
+ *Example:
+ *
+ *<target name="define.task" description="New task definition for toplink static weaving"/>
+ */
+
+
+ public class StaticWeaveAntTask extends Task{
+
+ private String source;
+ private String persistenceinfo;
+ private String target;
+ private Vector classPaths = new Vector();
+ private int logLevel=SessionLog.OFF;
+ private Writer logWriter;
+
+
+ /**
+ * Set the input archive to be used to weave.
+ * @param inputJarFile
+ */
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ /**
+ * Set output archive to be used to weave to
+ * @param outputJarFile
+ */
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ /**
+ * Set the archive containing persistence.xml while input archive does not contain it.
+ * @param inputMainJarFile
+ */
+ public void setLog(String logFile) throws IOException {
+ try{
+ this.logWriter = new FileWriter(logFile);
+ }catch(Exception e){
+ throw StaticWeaveException.openLoggingFileException(logFile,e);
+ }
+ }
+
+ public void setLogLevel(String logLevel) {
+ if (logLevel.equalsIgnoreCase("OFF") ||
+ logLevel.equalsIgnoreCase("SEVERE") ||
+ logLevel.equalsIgnoreCase("WARNING") ||
+ logLevel.equalsIgnoreCase("INFO") ||
+ logLevel.equalsIgnoreCase("CONFIG") ||
+ logLevel.equalsIgnoreCase("FINE") ||
+ logLevel.equalsIgnoreCase("FINER") ||
+ logLevel.equalsIgnoreCase("FINEST") ||
+ logLevel.equalsIgnoreCase("ALL")) {
+ this.logLevel=AbstractSessionLog.translateStringToLoggingLevel(logLevel.toUpperCase());
+ } else{
+ throw StaticWeaveException.illegalLoggingLevel(logLevel);
+ }
+ }
+
+ public void setPersistenceinfo(String persistenceinfo) {
+ this.persistenceinfo = persistenceinfo;
+ }
+
+ /**
+ * Add the dependent classpath in order to load classes from the specified input jar.
+ * @param path
+ */
+ public void addClasspath(Path path) {
+ classPaths.add(path);
+ }
+
+ /*
+ * Parse the class path element and store them into vector.
+ */
+ private Vector getPathElement(){
+ Vector pathElements = new Vector();
+ for(int i=0;i
+ * <taskdef name="weave" classname="oracle.toplink.essentials.weaving.StaticWeaverAntTask"/>
+ *</target>
+ *<target name="weaving" description="perform weaving." depends="define.task">
+ * <weave source= "c:\foo.jar" target = "c:\wovenfoo.jar" persistenceinfo="c:\foo-containing-persistenceinfo.jar">
+ * <classpath>
+ * <pathelement path="c:\foo-dependent.jar"/>
+ * </classpath>
+ * </weave>
+ *</target>
+ *
+ *
+ *
+ *
+ *
+ **/
+
+ public class StaticWeaveClassTransformer {
+ private ArrayList