JSON script to checkin, comment, & commit change
I'm going by the following jazz.net article: https://jazz.net/library/article/1031 My CLM implementation is currently only at version 4.0.7, as is this article.
The article offers the following script below. I'm using JSON (Jackson 2.5.2) on a Windows 2008 server. Basically Jackson is 3 jar files, set in your CLASSPATH. i've also installed ActiveState Perl.
As in this example, i'm running the command; "commit.pl $comment <path to file in workspace>" or more precisely;
C:\commit.pl "Autobuild - edit CommonAssemblyInfo.cs version number" C:\EclipseWorkspaces\Source\CommonAssemblyInfo.cs
I'm looking for some help with the following error;
Argument syntax error: Missing arguments to subcommand "checkin" - path. Try 'lscm help checkin' for more information. malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at C:\Jackson-2.5.2\commit.pl line 34.
#! /usr/bin/perl
# /*******************************************************************************
# * Licensed Materials - Property of IBM
# * (c) Copyright IBM Corporation 2005, 2012. All Rights Reserved.
# *
# *******************************************************************************/
# Script to commit files, set comment and complete the change set.
# Script usage: commit.pl {comment} {file paths...}
# Script usage example: commit.pl "test comment" .
# Requirements:
# Install JSON module from http://search.cpan.org/~makamaka/JSON-2.53/lib/JSON.pm
use JSON;
my $comment = $ARGV[0];
my $filePattern = "";
for ($count = 1; $count <= $#ARGV; $count++) {
if ($count > 1) {
$filePattern = $filePattern . " ";
}
$filePattern = $filePattern . $ARGV[$count];
}
# Commit the changes
my $result = `lscm checkin $filePattern --json`;
quitOnError($?, $result);
# Decode the result
my @json = @{decode_json($result)};
# Loop through the workspaces->components->outgoingChangesets
foreach $ws (@json) {
foreach my $component (@{$ws->{components}}) {
foreach my $outgoingChangeset (@{$component->{"outgoing-changes"}}) {
$result = `lscm changeset comment $outgoingChangeset->{"uuid"} "$comment"`;
quitOnError($?, $result);
$result = `lscm changeset complete $outgoingChangeset->{"uuid"}`;
quitOnError($?, $result);
}
}
}
#
# Routine that prints the error message and quits
#
sub quitOnError {
my $error_code = shift;
my $error = shift;
if ($error_code != 0) {
print $error . "\n";
exit($error_code);
}
}
The article offers the following script below. I'm using JSON (Jackson 2.5.2) on a Windows 2008 server. Basically Jackson is 3 jar files, set in your CLASSPATH. i've also installed ActiveState Perl.
As in this example, i'm running the command; "commit.pl $comment <path to file in workspace>" or more precisely;
C:\commit.pl "Autobuild - edit CommonAssemblyInfo.cs version number" C:\EclipseWorkspaces\Source\CommonAssemblyInfo.cs
I'm looking for some help with the following error;
Argument syntax error: Missing arguments to subcommand "checkin" - path. Try 'lscm help checkin' for more information. malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at C:\Jackson-2.5.2\commit.pl line 34.
#! /usr/bin/perl
# /*******************************************************************************
# * Licensed Materials - Property of IBM
# * (c) Copyright IBM Corporation 2005, 2012. All Rights Reserved.
# *
# *******************************************************************************/
# Script to commit files, set comment and complete the change set.
# Script usage: commit.pl {comment} {file paths...}
# Script usage example: commit.pl "test comment" .
# Requirements:
# Install JSON module from http://search.cpan.org/~makamaka/JSON-2.53/lib/JSON.pm
use JSON;
my $comment = $ARGV[0];
my $filePattern = "";
for ($count = 1; $count <= $#ARGV; $count++) {
if ($count > 1) {
$filePattern = $filePattern . " ";
}
$filePattern = $filePattern . $ARGV[$count];
}
# Commit the changes
my $result = `lscm checkin $filePattern --json`;
quitOnError($?, $result);
# Decode the result
my @json = @{decode_json($result)};
# Loop through the workspaces->components->outgoingChangesets
foreach $ws (@json) {
foreach my $component (@{$ws->{components}}) {
foreach my $outgoingChangeset (@{$component->{"outgoing-changes"}}) {
$result = `lscm changeset comment $outgoingChangeset->{"uuid"} "$comment"`;
quitOnError($?, $result);
$result = `lscm changeset complete $outgoingChangeset->{"uuid"}`;
quitOnError($?, $result);
}
}
}
#
# Routine that prints the error message and quits
#
sub quitOnError {
my $error_code = shift;
my $error = shift;
if ($error_code != 0) {
print $error . "\n";
exit($error_code);
}
}
Accepted answer
One other answer
Jeff,
The error suggests that the file path is not supplied to the 'checkin' command.
Print the contents of the variable 'filePattern' before the line "# Commit the changes" and validate if the supplied file name is printed correctly. You can also print the contents of the variable 'comment'.
Comments
I am it giving to the command as; C:\commit.pl "Autobuild - edit CommonAssemblyInfo.cs version number" C:\EclipseWorkspaces\Source\CommonAssemblyInfo.cs, but yes I think it isn't being identified somehow and probably a print output would help. Can you indulge me though please, i'm not a Perl or JSON (or even java) developer; what is the syntax?
I tried inserting this, but it didn't give me anything;
...
$filePattern = $filePattern . $ARGV[$count];
}
print $filePattern;
# Commit the changes
...