Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-ant-dev] AntRunner classpaths and class loaders

I managed to fix problem number 1 using the following custom classpath:

      private URL[] computeCustomClasspath() {
            // Add this plug-in's space
            AntCorePreferences preferences = AntCorePlugin.getPlugin
().getPreferences();
            URL [] defaultAntURLs = preferences.getDefaultAntURLs();
            URL installURL = PDEPlugin.getDefault().getDescriptor
().getInstallURL();
            try {
                  int length = defaultAntURLs.length;
                  URL [] customURLs = new URL[length+2];
                  System.arraycopy(defaultAntURLs, 0, customURLs, 0,
length);
                  customURLs[length] = new URL(installURL, "bin/");
                  customURLs[length+1] = new URL(installURL, "pdeui.jar");
                  return customURLs;
            }
            catch (IOException e) {
                  PDEPlugin.logException(e);
                  return null;
            }
      }

The code above seems to work in both the self-hosting scenarios (when bin
is used) and in a regular build (when jar will be used). However, I still
cannot fix the problem #2. I checked AntPluginLoader implementation and it
seems fairly logical why it happens: this new loader instance does not
'see' the class instance loaded by the calling plug-in loader - static
access to classes cannot work in this arrangement.

In general, is there a solution for reaching back into running plug-ins
from classes created by Ant classloader? The only thing my build listener
can now do is output the events into the file in the fixed location, which
is not very useful.

Regards,

Dejan Glozic, Ph.D.
Manager, Eclipse Platform Components
D2/MY7/8200/MKM
IBM Canada Ltd.
Tel. 905 413-2745  T/L 969-2745
Fax. 905 413-4854



                                                                                                                                        
                      Dejan                                                                                                             
                      Glozic/Toronto/IBM@IBMC        To:       platform-ant-dev@xxxxxxxxxxx                                             
                      A                              cc:                                                                                
                      Sent by:                       Subject:  [platform-ant-dev] AntRunner classpaths and class loaders                
                      platform-ant-dev-admin@                                                                                           
                      eclipse.org                                                                                                       
                                                                                                                                        
                                                                                                                                        
                      12/06/2002 09:16 PM                                                                                               
                      Please respond to                                                                                                 
                      platform-ant-dev                                                                                                  
                                                                                                                                        
                                                                                                                                        



I have a question that is related to PDE usage of Ant builds.

We are generating feature and plugin scripts and want to run them using
AntRunner using the following code:

      private void runScript(
            IFile scriptFile,
            ISiteBuildModel buildModel,
            IProgressMonitor monitor)
            throws CoreException {
            AntRunner runner = new AntRunner();
            createLogFile(buildModel);
            runner.setBuildFileLocation(scriptFile.getLocation().toOSString
());
            runner.setArguments(computeBuildArguments(buildModel));
            runner.setExecutionTargets(computeTargets());
            runner.setMessageOutputLevel(Project.MSG_ERR);
            runner.addBuildListener(BUILD_LISTENER_CLASS);
            runner.run(monitor);
      }

I have two problems: when I execute this code from within PDE UI plug-in,
it complains that it cannot find build listener class (the one passed to
the runner using the fully qualified class name). When I add my PDE UI JAR
to the list of JARs in Ant classpath preference page, it works.

Another problem I had was that this listener class (once class is loaded
and an instance created) seems to be loaded by a different class loader,
since it cannot communicate via static methods. Example: the method above
is in class 'SiteBuildOperation'. The call 'createLogFile' creates a File
object as a static field and exposes it using the static method. When
BuildListener class is loaded and I try to access the log file using the
static method, it returns null, which implies that SiteBuildOperation that
build listener is using is a different class instance (loaded by a
different class loader).

Question: how can I load AntRunner using the same class loader as my
plug-in and how to 'see' classes from my plug-in frmo the build listener
loaded by AntRunner?

Regards,

Dejan Glozic, Ph.D.
Manager, Eclipse Platform Components
D2/MY7/8200/MKM
IBM Canada Ltd.
Tel. 905 413-2745  T/L 969-2745
Fax. 905 413-4854

_______________________________________________
platform-ant-dev mailing list
platform-ant-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-ant-dev





Back to the top