/** * */ package com.perforce.p4javademo; import java.util.Date; import java.util.List; import com.perforce.p4java.client.IClient; import com.perforce.p4java.core.ChangelistStatus; import com.perforce.p4java.core.IChangelist; import com.perforce.p4java.core.file.FileSpecBuilder; import com.perforce.p4java.core.file.FileSpecOpStatus; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.exception.RequestException; import com.perforce.p4java.impl.generic.core.Changelist; import com.perforce.p4java.impl.mapbased.server.Server; import com.perforce.p4java.server.IOptionsServer; /** * Simple P4Java changelist sample / demo code.<p> * * This class first retrieves an IOptionsServer object from * the ServerFactory (using the associated server URI property), * then logs in and retrieves a named Perforce client (name taken from * the associated system property). It then creates a new * Perforce changelist, opens a sample file for editing, then * attempts to submit the changelist. As with all the demos * in the P4JavaDemo project, this may or may not work depending * on your own circumstances, but it does illustrate some common * P4Java usage patterns that should be usable more-or-less as-is. */ public class ChangelistDemo extends P4JavaDemo { public static void main(String[] args) { try { IOptionsServer server = getOptionsServer(null, null); server.setUserName(userName); server.login(password); IClient client = server.getClient(clientName); if (client != null) { server.setCurrentClient(client); Changelist changeListImpl = new Changelist( IChangelist.UNKNOWN, client.getName(), userName, ChangelistStatus.NEW, new Date(), "Changelist demo new changelist", false, (Server) server ); IChangelist changelist = client.createChangelist(changeListImpl); EditFilesOptions editFilesOptions = new EditFilesOptions().setChangelistId(changelist.getId()); List<IFileSpec> editList = client.editFiles( FileSpecBuilder.makeFileSpecList("SampleText.txt"), editFilesOptions); if (editList != null) { for (IFileSpec fileSpec : editList) { if (fileSpec != null) { if (fileSpec.getOpStatus() == FileSpecOpStatus.VALID) { System.out.println("edited: " + ListFilesDemo.formatFileSpec(fileSpec)); } else { System.err.println(fileSpec.getStatusMessage()); } } } } changelist.update(); List<IFileSpec> submitFiles = changelist.submit(false); if (submitFiles != null) { for (IFileSpec fileSpec : submitFiles) { if (fileSpec != null) { if (fileSpec.getOpStatus() == FileSpecOpStatus.VALID) { System.out.println("submitted: " + ListFilesDemo.formatFileSpec(fileSpec)); } else if (fileSpec.getOpStatus() == FileSpecOpStatus.INFO){ System.out.println(fileSpec.getStatusMessage()); } else if (fileSpec.getOpStatus() == FileSpecOpStatus.ERROR){ System.err.println(fileSpec.getStatusMessage()); } } } } } } catch (RequestException rexc) { System.err.println(rexc.getDisplayString()); rexc.printStackTrace(); } catch (P4JavaException jexc) { System.err.println(jexc.getLocalizedMessage()); jexc.printStackTrace(); } catch (Exception exc) { System.err.println(exc.getLocalizedMessage()); exc.printStackTrace(); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19903 | stuartrowe |
Branching //guest/perforce_software/p4java/... to //guest/stuartrowe/p4java/... |
||
//guest/perforce_software/p4java/main/samples/basic/src/com/perforce/p4javademo/ChangelistDemo.java | |||||
#1 | 12851 | Matt Attaway | Reorganize content to match Workshop branch naming standards | ||
//guest/perforce_software/p4java/samples/basic/src/com/perforce/p4javademo/ChangelistDemo.java | |||||
#3 | 7948 | amorgan | fixed by adding a changelist id to client.editFiles(). | ||
#2 | 7778 | jkovisto | Updated for 2010.1 Release | ||
#1 | 7534 | hreid | Added P4Java basic demo samples to public depot for 9.2 beta release. |