[nbusers] How to write a Java program to simulate Netbeans open-project functionnality

  • From: Olivier Bourdon < >
  • To:
  • Subject: [nbusers] How to write a Java program to simulate Netbeans open-project functionnality
  • Date: Tue, 28 Aug 2012 16:49:49 +0200

The basic issue I am trying to address here is that I have a SVN repository which contains netbeans basic ant projects (as opposed to maven)
for which I'd like to implement a continuous integration chain. However the SVN does not include the build-impl.xml files as several target
platforms can be used to generate the "binaries" for these projects. Therefore I'd like to regenerate the missing netbeans configuration files
by "simulating" the Netbeans IDE open function for each project.

Having Googled this, I found several hints but none seems satisfactory as I do not know what to put as the .xsl files

I noticed that some of these .xsl file where included in the .jar of the netbeans platform like:
/opt/java/netbeans-latest/java/modules/org-netbeans-modules-java-j2seproject.jar:org/netbeans/modules/java/j2seproject/resources/build-impl.xsl
/opt/java/netbeans-latest/java/modules/org-netbeans-modules-java-j2seproject.jar:org/netbeans/modules/java/j2seproject/resources/build.xsl
However I am now facing 2 issues:

a) how to assign my variables to use these files ? Guessing that this has to to with ClassLoader and getResource call but have no experience with this

b) I am also guessing that there is a upper level procedure which "guesses" what type of project I am opening (J2SE, J2EE, WEBservice, ...) as we can find other files like
/opt/java/netbeans-latest/enterprise/modules/org-netbeans-modules-j2ee-clientproject.jar:org/netbeans/modules/j2ee/clientproject/resources/build-impl.xsl
/opt/java/netbeans-latest/enterprise/modules/org-netbeans-modules-j2ee-clientproject.jar:org/netbeans/modules/j2ee/clientproject/resources/build.xsl
therefore I am assuming that what I really need is to get access to this procedure but could not really determine where to look (I ran
egrep 'GeneratedFilesHelper|refreshBuildScript' on the Netbeans source tree but got lost in all matches)

The code I have currently copied and trying to get to work is:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package netbeansrebuild;

import java.beans.PropertyVetoException;
import java.io.File;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Location;
import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
import org.openide.filesystems.*;

/**
 *
 * @author olivier
 */
public class NetbeansRebuild extends Task {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new NetbeansRebuild().xxx(args[0]);
    }

    public void xxx(String dir) {
        // TODO code application logic here
        try {
            File projectDir = new File(dir);
            File buildXsl = new File("");
            File buildImplXsl = new File("");
            // Might be running inside IDE, in which case already have a 
mount...
            FileObject projectFO = FileUtil.toFileObject(projectDir);
            if (projectFO == null) {
                // Probably not running inside IDE, so mount it.
                // XXX for some reason including masterfs.jar in <taskdef> 
does not work. Why?
                // Possibly a bug in AntClassLoader.getResources(String)?
                LocalFileSystem lfs = new LocalFileSystem();
                lfs.setRootDirectory(projectDir);
                Repository.getDefault().addFileSystem(lfs);
                projectFO = lfs.getRoot();
                assert projectFO != null;
            }
            GeneratedFilesHelper h = new GeneratedFilesHelper(projectFO);
            if (h.refreshBuildScript(GeneratedFilesHelper.BUILD_XML_PATH, 
buildXsl.toURI().toURL(), true)) {
                log("Regenerating " + new File(projectDir, 
GeneratedFilesHelper.BUILD_XML_PATH.replace('/', 
File.separatorChar)).getAbsolutePath());
            }
            if 
(h.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 
buildImplXsl.toURI().toURL(), true)) {
                log("Regenerating " + new File(projectDir, 
GeneratedFilesHelper.BUILD_IMPL_XML_PATH.replace('/', 
File.separatorChar)).getAbsolutePath());
            }
        } catch (IOException e) {
            throw new BuildException(e, getLocation());
        } catch (PropertyVetoException e) {
            throw new BuildException(e, getLocation());
        }
    }
}

Thanks for your time and help
Olivier



[nbusers] How to write a Java program to simulate Netbeans open-project functionnality

Olivier Bourdon 08/28/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close