package com.perforce.common.depot;
import java.io.File;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.perforce.common.Stats;
import com.perforce.common.StatsType;
import com.perforce.common.journal.BuildCounter;
import com.perforce.common.journal.BuildDepot;
import com.perforce.common.journal.JournalWriter;
import com.perforce.config.CFG;
import com.perforce.config.Config;
import com.perforce.config.ConfigException;
public class DepotConvert implements DepotInterface {
private Logger logger = LoggerFactory.getLogger(DepotConvert.class);
private String name;
private String depotSub;
private long defaultDate;
private JournalWriter journal;
public DepotConvert(String name) throws Exception {
this.name = name; // Depot name = parent's name of tree
if ((Boolean) Config.get(CFG.TEST) == false) {
Date date = new Date();
defaultDate = date.getTime() / 1000;
} else {
defaultDate = 0;
}
depotSub = (String) Config.get(CFG.P4_DEPOT_SUB);
if (!depotSub.endsWith("/")) {
depotSub = new String(depotSub + "/");
}
if (!depotSub.startsWith("/")) {
depotSub = new String("/" + depotSub);
}
// Create Depot root directory
String p4root = (String) Config.get(CFG.P4_ROOT);
if (!p4root.endsWith("/")) {
p4root = new String(p4root + "/");
}
File directory = new File(p4root);
directory.mkdirs();
// Create journal
String jnlPath = p4root + Config.get(CFG.P4_JNL_PREFIX)
+ Config.get(CFG.P4_JNL_INDEX);
journal = new JournalWriter(jnlPath);
// Add unicode counter if required
if ((Boolean) Config.get(CFG.P4_UNICODE)) {
journal.write(BuildCounter.toJournal("unicode", "1"));
}
// Create depot and write to journal
journal.write(BuildDepot.toJournal(this));
journal.flush();
}
@Override
public String getClient() {
try {
return (String) Config.get(CFG.P4_CLIENT);
} catch (ConfigException e) {
return "svn-client";
}
}
@Override
public long getDefaultDate() {
return defaultDate;
}
@Override
public String getUser() {
try {
return (String) Config.get(CFG.P4_USER);
} catch (ConfigException e) {
return "svn-user";
}
}
@Override
public String getName() {
return name;
}
@Override
public String getBase() {
return name + depotSub;
}
@Override
public String getRoot() throws ConfigException {
String depotPath = (String) Config.get(CFG.P4_ROOT);
if (!depotPath.endsWith("/") && !depotPath.endsWith("\\")) {
depotPath = new String(depotPath + "/");
Stats.inc(StatsType.warningCount);
logger.info("Adding missing delimiter '/' or '\\' to end of Depot path");
Config.set(CFG.P4_ROOT, depotPath);
}
return depotPath;
}
public JournalWriter getJournal() {
return journal;
}
@Override
public String getDefaultClientRoot() {
try {
return (String) Config.get(CFG.P4_CLIENT_ROOT);
} catch (ConfigException e) {
return "/ws";
}
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
10825 |
Paul Allen |
Branching using paul_allen.p4convert |
|
|
//guest/perforce_software/p4convert/src/com/perforce/common/depot/DepotConvert.java |
#1
|
9807 |
Paul Allen |
Initial import of p4-convert (from change 894340) |
|
|