How to get changeset information from tfs using Java tfs-sdk - java

I tried with the below code
TFSTeamProjectCollection tpc =
new TFSTeamProjectCollection(URIUtils.newURI(COLLECTION_URL), credentials );
VersionControlClient srcctrl = tpc.getVersionControlClient();
Changeset[] chngset;
try {
chngset = srcctrl.queryHistory("http://******/tfs/SpectaTestCollection/", LatestVersionSpec.INSTANCE, 0, RecursionType.FULL, null, new DateVersionSpec("6/10/2014"), LatestVersionSpec.INSTANCE, Integer.MAX_VALUE, false, true, false, true);
for(Changeset ch : chngset)
{
System.out.println("Change Set ID : "+ ch.getChangesetID());
System.out.println("Owner : "+ ch.getOwner());
}
} catch (ServerPathFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But eveytime getting this error : There is no working folder mapping for D:\WorkSpace\test-workspace\tfsplay.game\http:********\tfs\SpectaTestCollection.
where "D:\WorkSpace\test -workspace\tfsplay.game" is my local workspace.
can anyone help me in guiding to the right way for doing this

Don't pass a URL to the queryHistory method, pass a server path or a local path.
You're getting this error because you have passed a path that is not a server path (does not start with $/), so the system is trying to understand what server path you have mapped to http://...etc. Since that URL is also not a local path, you have gotten that error.
If you want to see all history, pass the server path $/.

public class TestTfsExample {
public static void main(String[] args)
{
Credentials cred=new UsernamePasswordCredentials("username","password") ;
TFSTeamProjectCollection tpc =new TFSTeamProjectCollection(URIUtils.newURI("Application_Collection_url")
, cred);
WorkItemClient workItemClient = tpc.getWorkItemClient();
Changeset[] chngset=null;
LabelSpec lable=new LabelSpec("tfs_start_Label", null);
LabelSpec lable1=new LabelSpec("tfs_end_label", null);
try {
chngset = tpc.getVersionControlClient().queryHistory("$project_directory", LatestVersionSpec.INSTANCE, 0,
RecursionType.FULL, null,new LabelVersionSpec(lable1), new LabelVersionSpec(lable), Integer.MAX_VALUE, true, true, false, true);
} catch (ServerPathFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(Changeset ch : chngset)
{
System.out.println("Change Set ID : "+ ch.getChangesetID());
System.out.println("Owner : "+ ch.getOwner());
Change changes[]=ch.getChanges();
System.out.println("Date : "+ new Date(ch.getDate().getTimeInMillis()));
for(Change chang:changes)
{
System.out.println(chang.getItem().getServerItem());;
//System.out.println("Owner : "+ chang.getItem().getItemType().toString());
}
}
}
}

Related

copying directories using .jar program in java

i want to copy directories from the the place where my .jar files exist?
here are what i tried.. but i always get /home/user/
how can i copy files from where my .jar program exist?
private void copy_dir() {
//Path sourceParentFolder = Paths.get(System.getProperty("user.dir") + "/Project/");
// Path sourceParentFolder = Paths.get(Paths.get(".").toAbsolutePath().normalize().toString());
Path destinationParentFolder = Paths.get(System.getProperty("user.home"));
try {
Stream<Path> allFilesPathStream = Files.walk(sourceParentFolder);
Consumer<? super Path> action = new Consumer<Path>() {
#Override
public void accept(Path t) {
try {
String destinationPath = t.toString().replaceAll(sourceParentFolder.toString(), destinationParentFolder.toString());
Files.copy(t, Paths.get(destinationPath));
} catch (FileAlreadyExistsException e) {
//TODO do acc to business needs
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
allFilesPathStream.forEach(action);
} catch (FileAlreadyExistsException e) {
//file already exists and unable to copy
} catch (IOException e) {
//permission issue
e.printStackTrace();
}
}
Try
Path destinationParentFolder = Paths.get(System.getProperty("user.dir"));
"user.dir" gets the absolute path from where your application was initialized.
"user.home" gets the user's home directory.

Smack Api Group not working

I am trying to create Group using Smack Api
I use the following code
It crashes on muc#roomconfig_roomowners tag
If i remove that line, it works fine, Group creates
But no group is assigned to the current user, no one is owner
public void createGroup() {
MultiUserChat chatRoom = MultiUserChatManager.getInstanceFor(mConnection).getMultiUserChat("room719#conference." + MYSITE);
try {
chatRoom.create("room719");
Form form = chatRoom.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_publicroom", true);
form.setAnswer("muc#roomconfig_roomname", "room719");
// List owners = new ArrayList();
// owners.add("currUser#"+MYSITE);
form.setAnswer("muc#roomconfig_roomowners", Arrays.asList("currUser#"+MYSITE));
form.setAnswer("muc#roomconfig_persistentroom", true);
chatRoom.sendConfigurationForm(form);
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
This code is working for me, can you try this?
if( !chatRoom.isJoined() ){
chatRoom.createOrJoin("your nickname");
List<String> owners = new ArrayList<String>();
owners.add("currUser#"+MYSITE);
Form form = chatRoom.getConfigurationForm().createAnswerForm();
form.setAnswer("muc#roomconfig_roomname", "your roomname");
form.setAnswer("muc#roomconfig_roomowners", owners);
form.setAnswer("muc#roomconfig_persistentroom", true);
form.setAnswer("muc#roomconfig_publicroom", true);
chatRoom.sendConfigurationForm(form);
}

Join existing PeerGroup in JXTA/JXSE

I have a problem using JXSE.
Let's say i have a rendezVous peer and an Edge peer, not on the same local network.
The rendezVous peer create a peerGroup "test", and publish an advertisement in this group with the name "test advertisement"
Let's say i'm sure than my EdgePeer is connected to the rendezVous peer. I can find the existing group "test" with netpeerGroup.getRemoteAdvertisements().
But i don't know how to join this existing group. I tried netpeergroup.newGroup(testAdv), with testAdv = the founded peerGroupAdvertisement.
I can't find the Advertisement "test advertisement" in the "test" PeerGroup.
But if i do all thats things locally, it works. Maybe i don't understand the difference on how jxta works locally and over internet.
here the code for creating or joining a group :
public void addGroup(final String name) {
ModuleImplAdvertisement mAdv = null;
PeerGroup group = null;
temp = null;
defaultGroup.getDiscoveryService().getRemoteAdvertisements(null, DiscoveryService.GROUP,
"Name", name, 1, new DiscoveryListener() {
#Override
public void discoveryEvent(DiscoveryEvent event) {
Enumeration<Advertisement> advs = event.getResponse().getAdvertisements();
while(advs.hasMoreElements()) {
System.out.println("groupe found");
PeerGroupAdvertisement adv = (PeerGroupAdvertisement) advs.nextElement();
System.out.println("group name : " + adv.getName());
try {
temp = defaultGroup.newGroup(adv);
System.out.println("group joined");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
try {
Thread.sleep(10000);
System.out.println("waiting for group ...");
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(temp == null) {
try {
System.out.println("creating new group ..");
mAdv = defaultGroup.getAllPurposePeerGroupImplAdvertisement(); /* Getting the advertisement of implemented modules */
temp = defaultGroup.newGroup(generatePeerGroupID(name), mAdv, name, name); /* creating & publishing the group */
getDefaultGroup().getDiscoveryService().remotePublish(temp.getPeerGroupAdvertisement());
} catch (Exception e) {
e.printStackTrace();
}
}
finally found the problem. You had to start the RendezVous service on each groups, and not only the netPeerGroup.
That's why my software works locally but not on internet.

Getting SVN Log of a particular Date Range in Java

I am trying to get the log from a SVN repo using SVNKit.
public static void svnLogTest() {
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
final SvnLog log = svnOperationFactory.createLog();
SVNURL url = null;
try {
url = SVNURL
.parseURIEncoded("https://svn-repo");
} catch (SVNException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.setSingleTarget(SvnTarget.fromURL(url));
log.addRange(SvnRevisionRange.create(SVNRevision.create(111),
SVNRevision.create(222)));
log.getRevisionRanges();
SVNLogEntry logEntry = null;
try {
logEntry = log.run();
System.out.println(logEntry.getAuthor() + " " + logEntry.getRevision() + " "
+ logEntry.getDate());
} catch (SVNException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But it will give me only the first revision, How should I iterate to print the log for a particular date range ?
This is because
log.run();
always returns only one log entry (the same is true for other SvnOperation#run methods). To get all entries use receiver:
log.setReceiver(new ISvnObjectReceiver<SVNLogEntry>() {
#Override
public void receive(SvnTarget target, SVNLogEntry logEntry) throws SVNException {
//process logEntry here
}
});
log.run();

Need help to find the filename

I used the following code to run an exe I load through my code.
private static String filelocation = "";
.
load_exe.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
try {
JFileChooser file_Choose = new JFileChooser();
file_Choose.showOpenDialog(frame);
JavaSamp.filelocation = file_Choose.getCurrentDirectory()
.toString()
+ "\\" + file_Choose.getSelectedFile().getName();
System.out.println("FileLocation" + JavaSamp.filelocation);
} catch (Exception expobj) {
// TODO Auto-generated catch block
}
Runtime rt = Runtime.getRuntime();
try {
System.out.println("File Run Location" + JavaSamp.filelocation);
proc = rt.exec(JavaSamp.filelocation);
} catch (IOException e4) {
e4.printStackTrace();
} catch (Exception e2) {
}
}
});
My problem is, the above execution of the JavaSamp.filelocation, should have to done many times. First time only I load the exe. Next time I wont. I need to store the exe in a string to run for the successive times.
Any suggestion pls
If you want remember the used file just initialize the filelocation with null and test for it. BTW: Storing it as File makes more sense and your way of constructing the absolute path is a bit intricate - compared to just calling getAbsolutePath()
private static File filelocation = null;
private static void test() {
load_exe.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Check if file-name to execute has already been set
if (filelocation != null) {
try {
JFileChooser file_Choose = new JFileChooser();
file_Choose.showOpenDialog(frame);
JavaSamp.filelocation = file_Choose.getSelectedFile();
System.out.println("FileLocation"
+ JavaSamp.filelocation.getAbsolutePath());
} catch (Exception expobj) {
}
}
Runtime rt = Runtime.getRuntime();
try {
System.out.println("File Run Location"
+ JavaSamp.filelocation.getAbsolutePath());
Process proc = rt.exec(JavaSamp.filelocation
.getAbsolutePath());
} catch (IOException e4) {
e4.printStackTrace();
}
}
};
}

Categories

Resources