cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to develop a java plugin for checkout operation with integrity

vk
1-Newbie
1-Newbie

How to develop a java plugin for checkout operation with integrity

I am developing a Java plugin using plugins provided by integrity to communicate with Integrity.

I am able to connect to the server. I need some inputs regarding checkout process.

I got the below code when I searched. But I am not sure what parameters do I need to pass for this method.

configPath is either sandbox path or servers path?And please check the parameters mentioned whether I am giving the correct values or not?

And In my code I am using first argument as Session instead of APISession.

When Iam running it it is giving me the error Error occurred when running command: si: MKS124819: Invalid option: "server"”.

What are all the option values it accepts? Is it different for every command? Where can I found this information?

Please suggest me If i can develop in a different way also.

       /**

        * Performs a checkout of this Integrity Source File to a  working file location on the build server represented by targetFile

        * @param api Integrity API Session

        * @param configPath Full server side path for this Integrity member's project/subproject

        * @param memberID Full server side path for this Integrity member

        * @param memberRev Member revision string for this Integrity member

        * @param targetFile File object representing the target location for this file

        * @param restoreTimestamp Toggles whether or not the original timestamp should be used

        * @param lineTerminator Sets the line terminator for this file (native, crlf, or lf)

        * @return true if the operation succeeded or false if failed

        * @throws APIException

        */

       String configPath="mentioned server side path till .pj";

       File targetFile=new File("D:/Vasavi/test-generated ");

       String memberID="config.ini";

       String memberRev="1.10";

       boolean restoreTimestamp=false;

       String lineTerminator="native";

       Response res;

       public boolean checkout(APISession api,String configPath,String memberID,String memberRev,File targetFile,boolean restoreTimestamp,String                lineTerminator) throws APIException {

      

              System.out.println("In Checkout method");

            if (!targetFile.getParentFile().isDirectory()) {

              System.out.println("If block");

           targetFile.getParentFile().mkdirs();

           System.out.println("end of if block");

         }

       System.out.println("after if block");

         Command coCMD=new Command(Command.SI,"co");

         coCMD.addOption(new Option("nolock"));

         coCMD.addOption(new Option("server",configPath));

         coCMD.addOption(new FileOption("targetFile",targetFile));

         coCMD.addOption(new Option(restoreTimestamp ? "restoreTimestamp" : "norestoreTimestamp"));

         coCMD.addOption(new Option("lineTerminator",lineTerminator));

         coCMD.addOption(new Option("revision",memberRev));

         coCMD.addOption(new Option("changePackageId", ":none"));

         coCMD.addSelection(memberID);

        

         try{

         res=integrity.cr.execute(coCMD);

         }

catch (APIException e) {

System.out.println("Error occurred when running command: " + e.getMessage());

e.printStackTrace();

}

         if (res.getExitCode() == 0) {

           return true;

         }

        else {

           return false;

         }

       }

2 REPLIES 2
vk
1-Newbie
1-Newbie
(To:vk)

Instead of "project" option, I mentioned it as server.

mrump
14-Alexandrite
(To:vk)

Hi,

you have to differenciate between two use cases:

1. a checkout (API command = si co) always requires a given sandbox, that defines the working location for the now editable member.

2 (and I assume that is your case) a fetch/download of a single member into a arbitrary location (API command = si projectco).

Please read up the details in the CLI reference document. (e.g. for I10.6 = http://support.ptc.com/WCMS/files/163511/en/SourceCLIReference_Integrity_10_6.pdf)

As a start for your development, here's a snippet from the Jenkins Plugin's source code on GitHub https://github.com/jenkinsci/integrity-plugin/blob/master/src/main/java/hudson/scm/IntegrityCMMember.java

/**

* Performs a checkout of a Integrity Source File to a

* working file location on the build server represented by targetFile

* @param api Integrity API Session

* @param configPath Full server side path for this Integrity member's project/subproject

* @param memberID Full server side path for this Integrity member

* @param memberRev Member revision string for this Integrity member

* @param targetFile File object representing the target location for this file

* @param restoreTimestamp Toggles whether or not the original timestamp should be used

* @param lineTerminator Sets the line terminator for this file (native, crlf, or lf)

* @return true if the operation succeeded or false if failed

* @throws APIException

*/

public static final boolean checkout(APISession api, String configPath, String memberID, String memberRev, Timestamp memberTimestamp,

      File targetFile, boolean restoreTimestamp, String lineTerminator) throws APIException

{

// Make sure the directory is created

if( ! targetFile.getParentFile().isDirectory() )

{

  targetFile.getParentFile().mkdirs();

}

// Construct the project check-co command

Command coCMD = new Command(Command.SI, "projectco");

coCMD.addOption(new Option("overwriteExisting"));

coCMD.addOption(new Option("nolock"));

coCMD.addOption(new Option("project", configPath));

coCMD.addOption(new FileOption("targetFile", targetFile));

coCMD.addOption(new Option(restoreTimestamp ? "restoreTimestamp" : "norestoreTimestamp"));

coCMD.addOption(new Option("lineTerminator", lineTerminator));

coCMD.addOption(new Option("revision", memberRev));

// Add the member selection

coCMD.addSelection(memberID);

// Execute the checkout command

Response res = api.runCommand(coCMD);

LOGGER.fine("Command: " + res.getCommandString() + " completed with exit code " + res.getExitCode());

// Return true if we were successful

if( res.getExitCode() == 0 )

{

  // Per JENKINS-13765 - providing a workaround due to API bug

  // Update the timestamp for the file, if appropriate

  if( restoreTimestamp )

  {

   targetFile.setLastModified(memberTimestamp.getTime());

  }

  return true;

}

// Otherwise return false...

else

{

  return false;

}

}

Top Tags