[JIRA] Created: (HUDSON-5467) Please add the improvement and fix I already did. For using node properties env vars in the plugin.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[JIRA] Created: (HUDSON-5467) Please add the improvement and fix I already did. For using node properties env vars in the plugin.

Hudson issues mailing list
Please add the improvement and fix I already did. For using node properties env vars in the plugin.
---------------------------------------------------------------------------------------------------

                 Key: HUDSON-5467
                 URL: http://issues.hudson-ci.org/browse/HUDSON-5467
             Project: Hudson
          Issue Type: Improvement
          Components: scp
            Reporter: kostakostadinov
            Assignee: ramazanyich2


First I fixed the recursive mkdirs bug that was reported for this scp plugin.
With my fix the workspace can be copied to an other computer over ssh and all the directory structure will be created.
The improvement:
I had the need to be able to use the node properties env vars in the plugin .
So for example we needed to build the same project on a different hardware and OS.
Like Solaris SPARC, AIX, HPUX, Windows and so on.
So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
Those environment variables we needed to use in the  plugin so we can know which project was build successful or failed or any
other problems.
Here is the code changes I made to work as I needed:
The changes was only in class
be/certipost/hudson/plugin/SCPRepositoryPublisher.java

I added a method:
    /**
     * Returns the environment variables set for a node/slave. So you can use
     * them, as are in your environment
     *
     * @param envVars
     * @return
     */
    public static EnvVars getEnvVars() {
        Node node = Computer.currentComputer().getNode();
        DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
            .getNodeProperties();
       
        if (Computer.currentComputer() instanceof MasterComputer) {
            Hudson instance = Hudson.getInstance();
            nodeProperties=instance.getGlobalNodeProperties();
        }
        Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
        while (iterator.hasNext()) {
            NodeProperty<?> next = iterator.next();
            if (next instanceof EnvironmentVariablesNodeProperty) {
                EnvironmentVariablesNodeProperty envVarProp = (EnvironmentVariablesNodeProperty) next;
                EnvVars envVars = envVarProp.getEnvVars();
                return envVars;
            }
           
        }
        return null;
    }

and changed the method perform :

public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
        throws InterruptedException, IOException {
.........................
.........................

            Map<String, String> envVars = build.getEnvVars();
            // Patched for env vars
            EnvVars objNodeEnvVars = getEnvVars();
            if (objNodeEnvVars != null) {
                envVars.putAll(objNodeEnvVars);
            }
            //~ Patched for env vars

            for (Entry e : entries) {
                String expanded = Util.replaceMacro(e.sourceFile, envVars);
                FilePath ws = build.getProject().getWorkspace();
                FilePath[] src = ws.list(expanded);
                if (src.length == 0) {
                    // try to do error diagnostics
                    log(listener.getLogger(), ("No file(s) found: " + expanded));
                    String error = ws.validateAntFileMask(expanded);
                    if (error != null)
                        log(listener.getLogger(), error);
                }
                String folderPath = Util.replaceMacro(e.filePath, envVars);
               
// Fix for recursive mkdirs
                String strWorkspacePath = ws.toString();
                envVars.put("strWorkspacePath", strWorkspacePath);
                // ~Fix for recursive mkdirs



I also changed the class be/certipost/hudson/plugin/SCPSite.java

I added the method extractRelativePath:


    /**
         * Returns the relative path to the workspace
     * @param strWorkspacePath
     * @param filePath
     * @return
     */
    private String extractRelativePath(String strWorkspacePath, FilePath filePath) {
        String strRet="";
        String strFilePath=filePath.toString();
        if(strWorkspacePath.length() == strFilePath.length()) {
            return "";
        }
        int indexOf = strFilePath.indexOf(strWorkspacePath);
        if(indexOf>=0) {
            strRet=strFilePath.substring(strWorkspacePath.length()+1,strFilePath.length());//Exclude first file separator
        }
        indexOf = strRet.lastIndexOf(File.separator);
        if(indexOf>0) {
            strRet=strRet.substring(0,indexOf);
        }
        strRet=strRet.replace((CharSequence) "\\", (CharSequence)"/");
        return strRet;
    }

I changed the upload method to became:
 
        public void upload(String folderPath, FilePath filePath,
                        Map<String, String> envVars, PrintStream logger)
                        throws IOException, InterruptedException, SftpException {
                if (session == null || channel == null) {
                        throw new IOException("Connection to " + hostname + ", user="
                                        + username + " is not established");
                }
                SftpATTRS rootdirstat = channel.stat(rootRepositoryPath);
                if (rootdirstat == null) {
                        throw new IOException(
                                        "Can't get stat of root repository directory:"
                                                        + rootRepositoryPath);
                } else {
                        if (!rootdirstat.isDir()) {
                                throw new IOException(rootRepositoryPath
                                                + " is not a directory");
                        }
                }
                if (filePath.isDirectory()) {
                        FilePath[] subfiles = filePath.list("**/*");
                        if (subfiles != null) {
                                for (int i = 0; i < subfiles.length; i++) {
                                        upload(folderPath + "/" + filePath.getName(), subfiles[i],
                                                        envVars, logger);
                                }
                        }
                } else {
                    String strWorkspacePath = envVars.get("strWorkspacePath");
                        String localfilename = filePath.getName();
                        mkdirs(folderPath, logger);
                        InputStream in = filePath.read();
            String strRelativePath=extractRelativePath(strWorkspacePath , filePath);
                        String strTmp = folderPath + "/" +strRelativePath;
            String strNewPath = rootRepositoryPath + "/" + strTmp;
                        if(!strRelativePath.equals("")) {
                            strNewPath += "/";
                        }
            String strNewFilename = strNewPath + localfilename;
            channel.put(in, strNewFilename);
                        in.close();
                }
        }


--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.hudson-ci.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[JIRA] Updated: (HUDSON-5467) Please add the improvement and fix I already did. For using node properties env vars in the plugin.

Hudson issues mailing list

     [ http://issues.hudson-ci.org/browse/HUDSON-5467?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

kostakostadinov updated HUDSON-5467:
------------------------------------

    Attachment: plugin.zip

Attached zip file has both fixed java files and the original but formatted with my Eclipse - for convenient diff for you.

So there was many problems with that plug-in.
In multiconfiguration project:
The Hudson seems to execute each plug-in in separated threads for each slave and master, but uses the same instances and execution is on the master with context of the slave.
Also I fixed strange problems under Linux/Unix.

The first my comment is not good to be placed in the plug-in.
Please use the attached files in NEW.zip.


> Please add the improvement and fix I already did. For using node properties env vars in the plugin.
> ---------------------------------------------------------------------------------------------------
>
>                 Key: HUDSON-5467
>                 URL: http://issues.hudson-ci.org/browse/HUDSON-5467
>             Project: Hudson
>          Issue Type: Improvement
>          Components: scp
>            Reporter: kostakostadinov
>            Assignee: ramazanyich2
>         Attachments: plugin.zip
>
>
> First I fixed the recursive mkdirs bug that was reported for this scp plugin.
> With my fix the workspace can be copied to an other computer over ssh and all the directory structure will be created.
> The improvement:
> I had the need to be able to use the node properties env vars in the plugin .
> So for example we needed to build the same project on a different hardware and OS.
> Like Solaris SPARC, AIX, HPUX, Windows and so on.
> So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
> Those environment variables we needed to use in the  plugin so we can know which project was build successful or failed or any
> other problems.
> Here is the code changes I made to work as I needed:
> The changes was only in class
> be/certipost/hudson/plugin/SCPRepositoryPublisher.java
> I added a method:
>     /**
>      * Returns the environment variables set for a node/slave. So you can use
>      * them, as are in your environment
>      *
>      * @param envVars
>      * @return
>      */
>     public static EnvVars getEnvVars() {
>         Node node = Computer.currentComputer().getNode();
>         DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
>             .getNodeProperties();
>        
>         if (Computer.currentComputer() instanceof MasterComputer) {
>             Hudson instance = Hudson.getInstance();
>             nodeProperties=instance.getGlobalNodeProperties();
>         }
>         Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
>         while (iterator.hasNext()) {
>             NodeProperty<?> next = iterator.next();
>             if (next instanceof EnvironmentVariablesNodeProperty) {
>                 EnvironmentVariablesNodeProperty envVarProp = (EnvironmentVariablesNodeProperty) next;
>                 EnvVars envVars = envVarProp.getEnvVars();
>                 return envVars;
>             }
>            
>         }
>         return null;
>     }
> and changed the method perform :
> public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
>         throws InterruptedException, IOException {
> .........................
> .........................
>             Map<String, String> envVars = build.getEnvVars();
>             // Patched for env vars
>             EnvVars objNodeEnvVars = getEnvVars();
>             if (objNodeEnvVars != null) {
>                 envVars.putAll(objNodeEnvVars);
>             }
>             //~ Patched for env vars
>             for (Entry e : entries) {
>                 String expanded = Util.replaceMacro(e.sourceFile, envVars);
>                 FilePath ws = build.getProject().getWorkspace();
>                 FilePath[] src = ws.list(expanded);
>                 if (src.length == 0) {
>                     // try to do error diagnostics
>                     log(listener.getLogger(), ("No file(s) found: " + expanded));
>                     String error = ws.validateAntFileMask(expanded);
>                     if (error != null)
>                         log(listener.getLogger(), error);
>                 }
>                 String folderPath = Util.replaceMacro(e.filePath, envVars);
>                
> // Fix for recursive mkdirs
>                 String strWorkspacePath = ws.toString();
>                 envVars.put("strWorkspacePath", strWorkspacePath);
>                 // ~Fix for recursive mkdirs
> I also changed the class be/certipost/hudson/plugin/SCPSite.java
> I added the method extractRelativePath:
>     /**
> * Returns the relative path to the workspace
>      * @param strWorkspacePath
>      * @param filePath
>      * @return
>      */
>     private String extractRelativePath(String strWorkspacePath, FilePath filePath) {
>         String strRet="";
>         String strFilePath=filePath.toString();
>         if(strWorkspacePath.length() == strFilePath.length()) {
>             return "";
>         }
>         int indexOf = strFilePath.indexOf(strWorkspacePath);
>         if(indexOf>=0) {
>             strRet=strFilePath.substring(strWorkspacePath.length()+1,strFilePath.length());//Exclude first file separator
>         }
>         indexOf = strRet.lastIndexOf(File.separator);
>         if(indexOf>0) {
>             strRet=strRet.substring(0,indexOf);
>         }
>         strRet=strRet.replace((CharSequence) "\\", (CharSequence)"/");
>         return strRet;
>     }
> I changed the upload method to became:
>  
> public void upload(String folderPath, FilePath filePath,
> Map<String, String> envVars, PrintStream logger)
> throws IOException, InterruptedException, SftpException {
> if (session == null || channel == null) {
> throw new IOException("Connection to " + hostname + ", user="
> + username + " is not established");
> }
> SftpATTRS rootdirstat = channel.stat(rootRepositoryPath);
> if (rootdirstat == null) {
> throw new IOException(
> "Can't get stat of root repository directory:"
> + rootRepositoryPath);
> } else {
> if (!rootdirstat.isDir()) {
> throw new IOException(rootRepositoryPath
> + " is not a directory");
> }
> }
> if (filePath.isDirectory()) {
> FilePath[] subfiles = filePath.list("**/*");
> if (subfiles != null) {
> for (int i = 0; i < subfiles.length; i++) {
> upload(folderPath + "/" + filePath.getName(), subfiles[i],
> envVars, logger);
> }
> }
> } else {
>    String strWorkspacePath = envVars.get("strWorkspacePath");
> String localfilename = filePath.getName();
> mkdirs(folderPath, logger);
> InputStream in = filePath.read();
>             String strRelativePath=extractRelativePath(strWorkspacePath , filePath);
> String strTmp = folderPath + "/" +strRelativePath;
>             String strNewPath = rootRepositoryPath + "/" + strTmp;
> if(!strRelativePath.equals("")) {
>    strNewPath += "/";
> }
>             String strNewFilename = strNewPath + localfilename;
>             channel.put(in, strNewFilename);
> in.close();
> }
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.hudson-ci.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[JIRA] Commented: (HUDSON-5467) Please add the improvement and fix I already did. For using node properties env vars in the plugin.

Hudson issues mailing list
In reply to this post by Hudson issues mailing list

    [ http://issues.hudson-ci.org/browse/HUDSON-5467?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=136159#action_136159 ]

ramazanyich2 commented on HUDSON-5467:
--------------------------------------

I committed your changes. Please check it and let me know, I will release it then.

> Please add the improvement and fix I already did. For using node properties env vars in the plugin.
> ---------------------------------------------------------------------------------------------------
>
>                 Key: HUDSON-5467
>                 URL: http://issues.hudson-ci.org/browse/HUDSON-5467
>             Project: Hudson
>          Issue Type: Improvement
>          Components: scp
>            Reporter: kostakostadinov
>            Assignee: ramazanyich2
>         Attachments: plugin.zip
>
>
> First I fixed the recursive mkdirs bug that was reported for this scp plugin.
> With my fix the workspace can be copied to an other computer over ssh and all the directory structure will be created.
> The improvement:
> I had the need to be able to use the node properties env vars in the plugin .
> So for example we needed to build the same project on a different hardware and OS.
> Like Solaris SPARC, AIX, HPUX, Windows and so on.
> So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
> Those environment variables we needed to use in the  plugin so we can know which project was build successful or failed or any
> other problems.
> Here is the code changes I made to work as I needed:
> The changes was only in class
> be/certipost/hudson/plugin/SCPRepositoryPublisher.java
> I added a method:
>     /**
>      * Returns the environment variables set for a node/slave. So you can use
>      * them, as are in your environment
>      *
>      * @param envVars
>      * @return
>      */
>     public static EnvVars getEnvVars() {
>         Node node = Computer.currentComputer().getNode();
>         DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
>             .getNodeProperties();
>        
>         if (Computer.currentComputer() instanceof MasterComputer) {
>             Hudson instance = Hudson.getInstance();
>             nodeProperties=instance.getGlobalNodeProperties();
>         }
>         Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
>         while (iterator.hasNext()) {
>             NodeProperty<?> next = iterator.next();
>             if (next instanceof EnvironmentVariablesNodeProperty) {
>                 EnvironmentVariablesNodeProperty envVarProp = (EnvironmentVariablesNodeProperty) next;
>                 EnvVars envVars = envVarProp.getEnvVars();
>                 return envVars;
>             }
>            
>         }
>         return null;
>     }
> and changed the method perform :
> public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
>         throws InterruptedException, IOException {
> .........................
> .........................
>             Map<String, String> envVars = build.getEnvVars();
>             // Patched for env vars
>             EnvVars objNodeEnvVars = getEnvVars();
>             if (objNodeEnvVars != null) {
>                 envVars.putAll(objNodeEnvVars);
>             }
>             //~ Patched for env vars
>             for (Entry e : entries) {
>                 String expanded = Util.replaceMacro(e.sourceFile, envVars);
>                 FilePath ws = build.getProject().getWorkspace();
>                 FilePath[] src = ws.list(expanded);
>                 if (src.length == 0) {
>                     // try to do error diagnostics
>                     log(listener.getLogger(), ("No file(s) found: " + expanded));
>                     String error = ws.validateAntFileMask(expanded);
>                     if (error != null)
>                         log(listener.getLogger(), error);
>                 }
>                 String folderPath = Util.replaceMacro(e.filePath, envVars);
>                
> // Fix for recursive mkdirs
>                 String strWorkspacePath = ws.toString();
>                 envVars.put("strWorkspacePath", strWorkspacePath);
>                 // ~Fix for recursive mkdirs
> I also changed the class be/certipost/hudson/plugin/SCPSite.java
> I added the method extractRelativePath:
>     /**
> * Returns the relative path to the workspace
>      * @param strWorkspacePath
>      * @param filePath
>      * @return
>      */
>     private String extractRelativePath(String strWorkspacePath, FilePath filePath) {
>         String strRet="";
>         String strFilePath=filePath.toString();
>         if(strWorkspacePath.length() == strFilePath.length()) {
>             return "";
>         }
>         int indexOf = strFilePath.indexOf(strWorkspacePath);
>         if(indexOf>=0) {
>             strRet=strFilePath.substring(strWorkspacePath.length()+1,strFilePath.length());//Exclude first file separator
>         }
>         indexOf = strRet.lastIndexOf(File.separator);
>         if(indexOf>0) {
>             strRet=strRet.substring(0,indexOf);
>         }
>         strRet=strRet.replace((CharSequence) "\\", (CharSequence)"/");
>         return strRet;
>     }
> I changed the upload method to became:
>  
> public void upload(String folderPath, FilePath filePath,
> Map<String, String> envVars, PrintStream logger)
> throws IOException, InterruptedException, SftpException {
> if (session == null || channel == null) {
> throw new IOException("Connection to " + hostname + ", user="
> + username + " is not established");
> }
> SftpATTRS rootdirstat = channel.stat(rootRepositoryPath);
> if (rootdirstat == null) {
> throw new IOException(
> "Can't get stat of root repository directory:"
> + rootRepositoryPath);
> } else {
> if (!rootdirstat.isDir()) {
> throw new IOException(rootRepositoryPath
> + " is not a directory");
> }
> }
> if (filePath.isDirectory()) {
> FilePath[] subfiles = filePath.list("**/*");
> if (subfiles != null) {
> for (int i = 0; i < subfiles.length; i++) {
> upload(folderPath + "/" + filePath.getName(), subfiles[i],
> envVars, logger);
> }
> }
> } else {
>    String strWorkspacePath = envVars.get("strWorkspacePath");
> String localfilename = filePath.getName();
> mkdirs(folderPath, logger);
> InputStream in = filePath.read();
>             String strRelativePath=extractRelativePath(strWorkspacePath , filePath);
> String strTmp = folderPath + "/" +strRelativePath;
>             String strNewPath = rootRepositoryPath + "/" + strTmp;
> if(!strRelativePath.equals("")) {
>    strNewPath += "/";
> }
>             String strNewFilename = strNewPath + localfilename;
>             channel.put(in, strNewFilename);
> in.close();
> }
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.hudson-ci.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[JIRA] Commented: (HUDSON-5467) Please add the improvement and fix I already did. For using node properties env vars in the plugin.

Hudson issues mailing list
In reply to this post by Hudson issues mailing list

    [ http://issues.hudson-ci.org/browse/HUDSON-5467?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=136160#action_136160 ]

scm_issue_link commented on HUDSON-5467:
----------------------------------------

Code changed in hudson
User: : ramazanyich2
Path:
 trunk/hudson/plugins/scp/src/main/java/be/certipost/hudson/plugin/SCPRepositoryPublisher.java
 trunk/hudson/plugins/scp/src/main/java/be/certipost/hudson/plugin/SCPSite.java
http://hudson-ci.org/commit/27692
Log:
[HUDSON-5467] fix for recursive mkdirs. introduction of node properties env vars


> Please add the improvement and fix I already did. For using node properties env vars in the plugin.
> ---------------------------------------------------------------------------------------------------
>
>                 Key: HUDSON-5467
>                 URL: http://issues.hudson-ci.org/browse/HUDSON-5467
>             Project: Hudson
>          Issue Type: Improvement
>          Components: scp
>            Reporter: kostakostadinov
>            Assignee: ramazanyich2
>         Attachments: plugin.zip
>
>
> First I fixed the recursive mkdirs bug that was reported for this scp plugin.
> With my fix the workspace can be copied to an other computer over ssh and all the directory structure will be created.
> The improvement:
> I had the need to be able to use the node properties env vars in the plugin .
> So for example we needed to build the same project on a different hardware and OS.
> Like Solaris SPARC, AIX, HPUX, Windows and so on.
> So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
> Those environment variables we needed to use in the  plugin so we can know which project was build successful or failed or any
> other problems.
> Here is the code changes I made to work as I needed:
> The changes was only in class
> be/certipost/hudson/plugin/SCPRepositoryPublisher.java
> I added a method:
>     /**
>      * Returns the environment variables set for a node/slave. So you can use
>      * them, as are in your environment
>      *
>      * @param envVars
>      * @return
>      */
>     public static EnvVars getEnvVars() {
>         Node node = Computer.currentComputer().getNode();
>         DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
>             .getNodeProperties();
>        
>         if (Computer.currentComputer() instanceof MasterComputer) {
>             Hudson instance = Hudson.getInstance();
>             nodeProperties=instance.getGlobalNodeProperties();
>         }
>         Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
>         while (iterator.hasNext()) {
>             NodeProperty<?> next = iterator.next();
>             if (next instanceof EnvironmentVariablesNodeProperty) {
>                 EnvironmentVariablesNodeProperty envVarProp = (EnvironmentVariablesNodeProperty) next;
>                 EnvVars envVars = envVarProp.getEnvVars();
>                 return envVars;
>             }
>            
>         }
>         return null;
>     }
> and changed the method perform :
> public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
>         throws InterruptedException, IOException {
> .........................
> .........................
>             Map<String, String> envVars = build.getEnvVars();
>             // Patched for env vars
>             EnvVars objNodeEnvVars = getEnvVars();
>             if (objNodeEnvVars != null) {
>                 envVars.putAll(objNodeEnvVars);
>             }
>             //~ Patched for env vars
>             for (Entry e : entries) {
>                 String expanded = Util.replaceMacro(e.sourceFile, envVars);
>                 FilePath ws = build.getProject().getWorkspace();
>                 FilePath[] src = ws.list(expanded);
>                 if (src.length == 0) {
>                     // try to do error diagnostics
>                     log(listener.getLogger(), ("No file(s) found: " + expanded));
>                     String error = ws.validateAntFileMask(expanded);
>                     if (error != null)
>                         log(listener.getLogger(), error);
>                 }
>                 String folderPath = Util.replaceMacro(e.filePath, envVars);
>                
> // Fix for recursive mkdirs
>                 String strWorkspacePath = ws.toString();
>                 envVars.put("strWorkspacePath", strWorkspacePath);
>                 // ~Fix for recursive mkdirs
> I also changed the class be/certipost/hudson/plugin/SCPSite.java
> I added the method extractRelativePath:
>     /**
> * Returns the relative path to the workspace
>      * @param strWorkspacePath
>      * @param filePath
>      * @return
>      */
>     private String extractRelativePath(String strWorkspacePath, FilePath filePath) {
>         String strRet="";
>         String strFilePath=filePath.toString();
>         if(strWorkspacePath.length() == strFilePath.length()) {
>             return "";
>         }
>         int indexOf = strFilePath.indexOf(strWorkspacePath);
>         if(indexOf>=0) {
>             strRet=strFilePath.substring(strWorkspacePath.length()+1,strFilePath.length());//Exclude first file separator
>         }
>         indexOf = strRet.lastIndexOf(File.separator);
>         if(indexOf>0) {
>             strRet=strRet.substring(0,indexOf);
>         }
>         strRet=strRet.replace((CharSequence) "\\", (CharSequence)"/");
>         return strRet;
>     }
> I changed the upload method to became:
>  
> public void upload(String folderPath, FilePath filePath,
> Map<String, String> envVars, PrintStream logger)
> throws IOException, InterruptedException, SftpException {
> if (session == null || channel == null) {
> throw new IOException("Connection to " + hostname + ", user="
> + username + " is not established");
> }
> SftpATTRS rootdirstat = channel.stat(rootRepositoryPath);
> if (rootdirstat == null) {
> throw new IOException(
> "Can't get stat of root repository directory:"
> + rootRepositoryPath);
> } else {
> if (!rootdirstat.isDir()) {
> throw new IOException(rootRepositoryPath
> + " is not a directory");
> }
> }
> if (filePath.isDirectory()) {
> FilePath[] subfiles = filePath.list("**/*");
> if (subfiles != null) {
> for (int i = 0; i < subfiles.length; i++) {
> upload(folderPath + "/" + filePath.getName(), subfiles[i],
> envVars, logger);
> }
> }
> } else {
>    String strWorkspacePath = envVars.get("strWorkspacePath");
> String localfilename = filePath.getName();
> mkdirs(folderPath, logger);
> InputStream in = filePath.read();
>             String strRelativePath=extractRelativePath(strWorkspacePath , filePath);
> String strTmp = folderPath + "/" +strRelativePath;
>             String strNewPath = rootRepositoryPath + "/" + strTmp;
> if(!strRelativePath.equals("")) {
>    strNewPath += "/";
> }
>             String strNewFilename = strNewPath + localfilename;
>             channel.put(in, strNewFilename);
> in.close();
> }
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.hudson-ci.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[JIRA] Commented: (HUDSON-5467) Please add the improvement and fix I already did. For using node properties env vars in the plugin.

Hudson issues mailing list
In reply to this post by Hudson issues mailing list

    [ http://issues.hudson-ci.org/browse/HUDSON-5467?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=140360#action_140360 ]

mindless commented on HUDSON-5467:
----------------------------------

should this issue be marked as resolved?

> Please add the improvement and fix I already did. For using node properties env vars in the plugin.
> ---------------------------------------------------------------------------------------------------
>
>                 Key: HUDSON-5467
>                 URL: http://issues.hudson-ci.org/browse/HUDSON-5467
>             Project: Hudson
>          Issue Type: Improvement
>          Components: scp
>            Reporter: kostakostadinov
>            Assignee: ramazanyich2
>         Attachments: plugin.zip
>
>
> First I fixed the recursive mkdirs bug that was reported for this scp plugin.
> With my fix the workspace can be copied to an other computer over ssh and all the directory structure will be created.
> The improvement:
> I had the need to be able to use the node properties env vars in the plugin .
> So for example we needed to build the same project on a different hardware and OS.
> Like Solaris SPARC, AIX, HPUX, Windows and so on.
> So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
> Those environment variables we needed to use in the  plugin so we can know which project was build successful or failed or any
> other problems.
> Here is the code changes I made to work as I needed:
> The changes was only in class
> be/certipost/hudson/plugin/SCPRepositoryPublisher.java
> I added a method:
>     /**
>      * Returns the environment variables set for a node/slave. So you can use
>      * them, as are in your environment
>      *
>      * @param envVars
>      * @return
>      */
>     public static EnvVars getEnvVars() {
>         Node node = Computer.currentComputer().getNode();
>         DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
>             .getNodeProperties();
>        
>         if (Computer.currentComputer() instanceof MasterComputer) {
>             Hudson instance = Hudson.getInstance();
>             nodeProperties=instance.getGlobalNodeProperties();
>         }
>         Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
>         while (iterator.hasNext()) {
>             NodeProperty<?> next = iterator.next();
>             if (next instanceof EnvironmentVariablesNodeProperty) {
>                 EnvironmentVariablesNodeProperty envVarProp = (EnvironmentVariablesNodeProperty) next;
>                 EnvVars envVars = envVarProp.getEnvVars();
>                 return envVars;
>             }
>            
>         }
>         return null;
>     }
> and changed the method perform :
> public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
>         throws InterruptedException, IOException {
> .........................
> .........................
>             Map<String, String> envVars = build.getEnvVars();
>             // Patched for env vars
>             EnvVars objNodeEnvVars = getEnvVars();
>             if (objNodeEnvVars != null) {
>                 envVars.putAll(objNodeEnvVars);
>             }
>             //~ Patched for env vars
>             for (Entry e : entries) {
>                 String expanded = Util.replaceMacro(e.sourceFile, envVars);
>                 FilePath ws = build.getProject().getWorkspace();
>                 FilePath[] src = ws.list(expanded);
>                 if (src.length == 0) {
>                     // try to do error diagnostics
>                     log(listener.getLogger(), ("No file(s) found: " + expanded));
>                     String error = ws.validateAntFileMask(expanded);
>                     if (error != null)
>                         log(listener.getLogger(), error);
>                 }
>                 String folderPath = Util.replaceMacro(e.filePath, envVars);
>                
> // Fix for recursive mkdirs
>                 String strWorkspacePath = ws.toString();
>                 envVars.put("strWorkspacePath", strWorkspacePath);
>                 // ~Fix for recursive mkdirs
> I also changed the class be/certipost/hudson/plugin/SCPSite.java
> I added the method extractRelativePath:
>     /**
> * Returns the relative path to the workspace
>      * @param strWorkspacePath
>      * @param filePath
>      * @return
>      */
>     private String extractRelativePath(String strWorkspacePath, FilePath filePath) {
>         String strRet="";
>         String strFilePath=filePath.toString();
>         if(strWorkspacePath.length() == strFilePath.length()) {
>             return "";
>         }
>         int indexOf = strFilePath.indexOf(strWorkspacePath);
>         if(indexOf>=0) {
>             strRet=strFilePath.substring(strWorkspacePath.length()+1,strFilePath.length());//Exclude first file separator
>         }
>         indexOf = strRet.lastIndexOf(File.separator);
>         if(indexOf>0) {
>             strRet=strRet.substring(0,indexOf);
>         }
>         strRet=strRet.replace((CharSequence) "\\", (CharSequence)"/");
>         return strRet;
>     }
> I changed the upload method to became:
>  
> public void upload(String folderPath, FilePath filePath,
> Map<String, String> envVars, PrintStream logger)
> throws IOException, InterruptedException, SftpException {
> if (session == null || channel == null) {
> throw new IOException("Connection to " + hostname + ", user="
> + username + " is not established");
> }
> SftpATTRS rootdirstat = channel.stat(rootRepositoryPath);
> if (rootdirstat == null) {
> throw new IOException(
> "Can't get stat of root repository directory:"
> + rootRepositoryPath);
> } else {
> if (!rootdirstat.isDir()) {
> throw new IOException(rootRepositoryPath
> + " is not a directory");
> }
> }
> if (filePath.isDirectory()) {
> FilePath[] subfiles = filePath.list("**/*");
> if (subfiles != null) {
> for (int i = 0; i < subfiles.length; i++) {
> upload(folderPath + "/" + filePath.getName(), subfiles[i],
> envVars, logger);
> }
> }
> } else {
>    String strWorkspacePath = envVars.get("strWorkspacePath");
> String localfilename = filePath.getName();
> mkdirs(folderPath, logger);
> InputStream in = filePath.read();
>             String strRelativePath=extractRelativePath(strWorkspacePath , filePath);
> String strTmp = folderPath + "/" +strRelativePath;
>             String strNewPath = rootRepositoryPath + "/" + strTmp;
> if(!strRelativePath.equals("")) {
>    strNewPath += "/";
> }
>             String strNewFilename = strNewPath + localfilename;
>             channel.put(in, strNewFilename);
> in.close();
> }
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.hudson-ci.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[JIRA] Resolved: (HUDSON-5467) Please add the improvement and fix I already did. For using node properties env vars in the plugin.

Hudson issues mailing list
In reply to this post by Hudson issues mailing list

     [ http://issues.hudson-ci.org/browse/HUDSON-5467?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

ramazanyich2 resolved HUDSON-5467.
----------------------------------

    Resolution: Fixed

as no comments given I suggest we mark it as resolved

> Please add the improvement and fix I already did. For using node properties env vars in the plugin.
> ---------------------------------------------------------------------------------------------------
>
>                 Key: HUDSON-5467
>                 URL: http://issues.hudson-ci.org/browse/HUDSON-5467
>             Project: Hudson
>          Issue Type: Improvement
>          Components: scp
>            Reporter: kostakostadinov
>            Assignee: ramazanyich2
>         Attachments: plugin.zip
>
>
> First I fixed the recursive mkdirs bug that was reported for this scp plugin.
> With my fix the workspace can be copied to an other computer over ssh and all the directory structure will be created.
> The improvement:
> I had the need to be able to use the node properties env vars in the plugin .
> So for example we needed to build the same project on a different hardware and OS.
> Like Solaris SPARC, AIX, HPUX, Windows and so on.
> So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
> Those environment variables we needed to use in the  plugin so we can know which project was build successful or failed or any
> other problems.
> Here is the code changes I made to work as I needed:
> The changes was only in class
> be/certipost/hudson/plugin/SCPRepositoryPublisher.java
> I added a method:
>     /**
>      * Returns the environment variables set for a node/slave. So you can use
>      * them, as are in your environment
>      *
>      * @param envVars
>      * @return
>      */
>     public static EnvVars getEnvVars() {
>         Node node = Computer.currentComputer().getNode();
>         DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
>             .getNodeProperties();
>        
>         if (Computer.currentComputer() instanceof MasterComputer) {
>             Hudson instance = Hudson.getInstance();
>             nodeProperties=instance.getGlobalNodeProperties();
>         }
>         Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
>         while (iterator.hasNext()) {
>             NodeProperty<?> next = iterator.next();
>             if (next instanceof EnvironmentVariablesNodeProperty) {
>                 EnvironmentVariablesNodeProperty envVarProp = (EnvironmentVariablesNodeProperty) next;
>                 EnvVars envVars = envVarProp.getEnvVars();
>                 return envVars;
>             }
>            
>         }
>         return null;
>     }
> and changed the method perform :
> public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
>         throws InterruptedException, IOException {
> .........................
> .........................
>             Map<String, String> envVars = build.getEnvVars();
>             // Patched for env vars
>             EnvVars objNodeEnvVars = getEnvVars();
>             if (objNodeEnvVars != null) {
>                 envVars.putAll(objNodeEnvVars);
>             }
>             //~ Patched for env vars
>             for (Entry e : entries) {
>                 String expanded = Util.replaceMacro(e.sourceFile, envVars);
>                 FilePath ws = build.getProject().getWorkspace();
>                 FilePath[] src = ws.list(expanded);
>                 if (src.length == 0) {
>                     // try to do error diagnostics
>                     log(listener.getLogger(), ("No file(s) found: " + expanded));
>                     String error = ws.validateAntFileMask(expanded);
>                     if (error != null)
>                         log(listener.getLogger(), error);
>                 }
>                 String folderPath = Util.replaceMacro(e.filePath, envVars);
>                
> // Fix for recursive mkdirs
>                 String strWorkspacePath = ws.toString();
>                 envVars.put("strWorkspacePath", strWorkspacePath);
>                 // ~Fix for recursive mkdirs
> I also changed the class be/certipost/hudson/plugin/SCPSite.java
> I added the method extractRelativePath:
>     /**
> * Returns the relative path to the workspace
>      * @param strWorkspacePath
>      * @param filePath
>      * @return
>      */
>     private String extractRelativePath(String strWorkspacePath, FilePath filePath) {
>         String strRet="";
>         String strFilePath=filePath.toString();
>         if(strWorkspacePath.length() == strFilePath.length()) {
>             return "";
>         }
>         int indexOf = strFilePath.indexOf(strWorkspacePath);
>         if(indexOf>=0) {
>             strRet=strFilePath.substring(strWorkspacePath.length()+1,strFilePath.length());//Exclude first file separator
>         }
>         indexOf = strRet.lastIndexOf(File.separator);
>         if(indexOf>0) {
>             strRet=strRet.substring(0,indexOf);
>         }
>         strRet=strRet.replace((CharSequence) "\\", (CharSequence)"/");
>         return strRet;
>     }
> I changed the upload method to became:
>  
> public void upload(String folderPath, FilePath filePath,
> Map<String, String> envVars, PrintStream logger)
> throws IOException, InterruptedException, SftpException {
> if (session == null || channel == null) {
> throw new IOException("Connection to " + hostname + ", user="
> + username + " is not established");
> }
> SftpATTRS rootdirstat = channel.stat(rootRepositoryPath);
> if (rootdirstat == null) {
> throw new IOException(
> "Can't get stat of root repository directory:"
> + rootRepositoryPath);
> } else {
> if (!rootdirstat.isDir()) {
> throw new IOException(rootRepositoryPath
> + " is not a directory");
> }
> }
> if (filePath.isDirectory()) {
> FilePath[] subfiles = filePath.list("**/*");
> if (subfiles != null) {
> for (int i = 0; i < subfiles.length; i++) {
> upload(folderPath + "/" + filePath.getName(), subfiles[i],
> envVars, logger);
> }
> }
> } else {
>    String strWorkspacePath = envVars.get("strWorkspacePath");
> String localfilename = filePath.getName();
> mkdirs(folderPath, logger);
> InputStream in = filePath.read();
>             String strRelativePath=extractRelativePath(strWorkspacePath , filePath);
> String strTmp = folderPath + "/" +strRelativePath;
>             String strNewPath = rootRepositoryPath + "/" + strTmp;
> if(!strRelativePath.equals("")) {
>    strNewPath += "/";
> }
>             String strNewFilename = strNewPath + localfilename;
>             channel.put(in, strNewFilename);
> in.close();
> }
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.hudson-ci.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[JIRA] Updated: (HUDSON-5467) Please add the improvement and fix I already did. For using node properties env vars in the plugin.

Hudson issues mailing list
In reply to this post by Hudson issues mailing list

     [ http://issues.hudson-ci.org/browse/HUDSON-5467?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

ramazanyich2 updated HUDSON-5467:
---------------------------------

    Fix Version/s: current

> Please add the improvement and fix I already did. For using node properties env vars in the plugin.
> ---------------------------------------------------------------------------------------------------
>
>                 Key: HUDSON-5467
>                 URL: http://issues.hudson-ci.org/browse/HUDSON-5467
>             Project: Hudson
>          Issue Type: Improvement
>          Components: scp
>            Reporter: kostakostadinov
>            Assignee: ramazanyich2
>             Fix For: current
>
>         Attachments: plugin.zip
>
>
> First I fixed the recursive mkdirs bug that was reported for this scp plugin.
> With my fix the workspace can be copied to an other computer over ssh and all the directory structure will be created.
> The improvement:
> I had the need to be able to use the node properties env vars in the plugin .
> So for example we needed to build the same project on a different hardware and OS.
> Like Solaris SPARC, AIX, HPUX, Windows and so on.
> So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
> Those environment variables we needed to use in the  plugin so we can know which project was build successful or failed or any
> other problems.
> Here is the code changes I made to work as I needed:
> The changes was only in class
> be/certipost/hudson/plugin/SCPRepositoryPublisher.java
> I added a method:
>     /**
>      * Returns the environment variables set for a node/slave. So you can use
>      * them, as are in your environment
>      *
>      * @param envVars
>      * @return
>      */
>     public static EnvVars getEnvVars() {
>         Node node = Computer.currentComputer().getNode();
>         DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
>             .getNodeProperties();
>        
>         if (Computer.currentComputer() instanceof MasterComputer) {
>             Hudson instance = Hudson.getInstance();
>             nodeProperties=instance.getGlobalNodeProperties();
>         }
>         Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
>         while (iterator.hasNext()) {
>             NodeProperty<?> next = iterator.next();
>             if (next instanceof EnvironmentVariablesNodeProperty) {
>                 EnvironmentVariablesNodeProperty envVarProp = (EnvironmentVariablesNodeProperty) next;
>                 EnvVars envVars = envVarProp.getEnvVars();
>                 return envVars;
>             }
>            
>         }
>         return null;
>     }
> and changed the method perform :
> public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
>         throws InterruptedException, IOException {
> .........................
> .........................
>             Map<String, String> envVars = build.getEnvVars();
>             // Patched for env vars
>             EnvVars objNodeEnvVars = getEnvVars();
>             if (objNodeEnvVars != null) {
>                 envVars.putAll(objNodeEnvVars);
>             }
>             //~ Patched for env vars
>             for (Entry e : entries) {
>                 String expanded = Util.replaceMacro(e.sourceFile, envVars);
>                 FilePath ws = build.getProject().getWorkspace();
>                 FilePath[] src = ws.list(expanded);
>                 if (src.length == 0) {
>                     // try to do error diagnostics
>                     log(listener.getLogger(), ("No file(s) found: " + expanded));
>                     String error = ws.validateAntFileMask(expanded);
>                     if (error != null)
>                         log(listener.getLogger(), error);
>                 }
>                 String folderPath = Util.replaceMacro(e.filePath, envVars);
>                
> // Fix for recursive mkdirs
>                 String strWorkspacePath = ws.toString();
>                 envVars.put("strWorkspacePath", strWorkspacePath);
>                 // ~Fix for recursive mkdirs
> I also changed the class be/certipost/hudson/plugin/SCPSite.java
> I added the method extractRelativePath:
>     /**
> * Returns the relative path to the workspace
>      * @param strWorkspacePath
>      * @param filePath
>      * @return
>      */
>     private String extractRelativePath(String strWorkspacePath, FilePath filePath) {
>         String strRet="";
>         String strFilePath=filePath.toString();
>         if(strWorkspacePath.length() == strFilePath.length()) {
>             return "";
>         }
>         int indexOf = strFilePath.indexOf(strWorkspacePath);
>         if(indexOf>=0) {
>             strRet=strFilePath.substring(strWorkspacePath.length()+1,strFilePath.length());//Exclude first file separator
>         }
>         indexOf = strRet.lastIndexOf(File.separator);
>         if(indexOf>0) {
>             strRet=strRet.substring(0,indexOf);
>         }
>         strRet=strRet.replace((CharSequence) "\\", (CharSequence)"/");
>         return strRet;
>     }
> I changed the upload method to became:
>  
> public void upload(String folderPath, FilePath filePath,
> Map<String, String> envVars, PrintStream logger)
> throws IOException, InterruptedException, SftpException {
> if (session == null || channel == null) {
> throw new IOException("Connection to " + hostname + ", user="
> + username + " is not established");
> }
> SftpATTRS rootdirstat = channel.stat(rootRepositoryPath);
> if (rootdirstat == null) {
> throw new IOException(
> "Can't get stat of root repository directory:"
> + rootRepositoryPath);
> } else {
> if (!rootdirstat.isDir()) {
> throw new IOException(rootRepositoryPath
> + " is not a directory");
> }
> }
> if (filePath.isDirectory()) {
> FilePath[] subfiles = filePath.list("**/*");
> if (subfiles != null) {
> for (int i = 0; i < subfiles.length; i++) {
> upload(folderPath + "/" + filePath.getName(), subfiles[i],
> envVars, logger);
> }
> }
> } else {
>    String strWorkspacePath = envVars.get("strWorkspacePath");
> String localfilename = filePath.getName();
> mkdirs(folderPath, logger);
> InputStream in = filePath.read();
>             String strRelativePath=extractRelativePath(strWorkspacePath , filePath);
> String strTmp = folderPath + "/" +strRelativePath;
>             String strNewPath = rootRepositoryPath + "/" + strTmp;
> if(!strRelativePath.equals("")) {
>    strNewPath += "/";
> }
>             String strNewFilename = strNewPath + localfilename;
>             channel.put(in, strNewFilename);
> in.close();
> }
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.hudson-ci.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]