use of hudson.maven.MavenModule in project evosuite by EvoSuite.
the class Git method commit.
@Override
public int commit(AbstractMavenProject<?, ?> project, AbstractBuild<?, ?> build, BuildListener listener, String branchName, String ctgBestsDir) {
try {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Commiting new test cases");
Set<String> branches = this.getBranches();
if (!branches.contains(branchName)) {
// create a new branch called "evosuite-tests" to commit and
// push the new generated test suites
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "There is no branch called " + branchName);
this.gitClient.branch(branchName);
}
this.gitClient.setAuthor("jenkins", "jenkins@localhost.com");
this.gitClient.setCommitter("jenkins", "jenkins@localhost.com");
this.gitClient.checkoutBranch(branchName, "HEAD");
EnvVars env = build.getEnvironment(listener);
env.overrideAll(build.getBuildVariables());
int number_of_files_committed = 0;
try {
MavenModuleSet prj = (MavenModuleSet) project;
// parse list of new and modified files per module
StringBuilder filesToBeCommitted = new StringBuilder();
for (MavenModule module : prj.getModules()) {
String status = ((CliGitAPIImpl) this.gitClient).launchCommand("ls-files", "--deleted", "--modified", "--others", (module.getRelativePath().isEmpty() ? "" : module.getRelativePath() + File.separator) + ctgBestsDir);
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Status (" + status.length() + "):\n" + status);
filesToBeCommitted.append(status);
}
String s_filesToBeCommitted = filesToBeCommitted.toString();
if (s_filesToBeCommitted.isEmpty()) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Nothing to commit");
return 0;
}
for (String toCommit : s_filesToBeCommitted.split("\\R")) {
String filePath = build.getWorkspace().getRemote() + File.separator + toCommit;
if (new File(filePath).exists()) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "adding: " + filePath);
this.gitClient.add(filePath);
number_of_files_committed++;
} else {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "File '" + filePath + "' reported by git status command does not exist");
}
}
} catch (ClassCastException e) {
// FIXME when building a project remotely, we just have access to a GitClient of type
// RemoteGitImpl, which cannot be cast to CliGitAPIImpl. and therefore, we cannot use
// launchCommand method. as a workaround, we can simple add all files under .evosuite/best-tests
// and hopefully git will take care of the rest. GitClient already supports the creation
// of a new branch, checkout some branch, add files to be committed, commmit, push, etc.
// there must be a way of getting the list of modified / new / deleted files just using
// GitClient, however we still do not know how to get that.
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + e.getMessage() + "\nTrying a different approach!");
FilePath[] filesToCommit = build.getWorkspace().list(build.getEnvironment(listener).expand("**" + File.separator + ctgBestsDir + File.separator + "**" + File.separator + "*"));
if (filesToCommit.length == 0) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Nothing to commit");
return number_of_files_committed;
}
number_of_files_committed = filesToCommit.length;
for (FilePath fileToCommit : filesToCommit) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "adding: " + fileToCommit.getRemote());
this.gitClient.add(fileToCommit.getRemote());
}
}
// commit
String commit_msg = SCM.COMMIT_MSG_PREFIX + build.getProject().getName().replace(" ", "_") + "-" + build.getNumber();
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + commit_msg);
this.gitClient.commit(commit_msg);
return number_of_files_committed;
} catch (InterruptedException | IOException e) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Commit failed " + e.getMessage());
e.printStackTrace();
this.rollback(build, listener);
return -1;
}
}
use of hudson.maven.MavenModule in project evosuite by EvoSuite.
the class Mercurial method commit.
@Override
public int commit(AbstractMavenProject<?, ?> project, AbstractBuild<?, ?> build, BuildListener listener, String branchName, String ctgBestsDir) {
try {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Commiting new test cases");
Set<String> branches = this.getBranches(build.getWorkspace(), listener);
if (!branches.contains(branchName)) {
// create a new branch called "evosuite-tests" to commit and
// push the new generated test suites
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "There is no branch called " + branchName);
if (this.hgClient.run("branch", branchName).pwd(build.getWorkspace()).join() != 0) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Unable to create a new branch called " + branchName);
return -1;
}
}
// switch to EVOSUITE_BRANCH
if (this.hgClient.run("update", branchName).pwd(build.getWorkspace()).join() != 0) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Unable to switch to branch " + branchName);
return -1;
}
// start adding all removed files to commit
if (this.hgClient.run("remove", "--after").pwd(build.getWorkspace()).join() != 0) {
this.rollback(build, listener);
return -1;
}
MavenModuleSet prj = (MavenModuleSet) project;
// parse list of new and modified files
int number_of_files_committed = 0;
for (MavenModule module : prj.getModules()) {
for (String file : this.parseStatus(this.hgClient.popen(build.getWorkspace(), listener, true, new ArgumentListBuilder("status")), (module.getRelativePath().isEmpty() ? "" : module.getRelativePath() + File.separator) + ctgBestsDir)) {
if (this.hgClient.run("add", file).pwd(build.getWorkspace()).join() != 0) {
this.rollback(build, listener);
return -1;
}
number_of_files_committed++;
}
}
if (number_of_files_committed == 0) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Nothing to commit");
return 0;
}
// commit
String commit_msg = SCM.COMMIT_MSG_PREFIX + build.getProject().getName().replace(" ", "_") + "-" + build.getNumber();
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + commit_msg);
if (this.hgClient.run("commit", "--message", commit_msg).pwd(build.getWorkspace()).join() != 0) {
this.rollback(build, listener);
return -1;
}
return number_of_files_committed++;
} catch (IOException | InterruptedException e) {
e.printStackTrace();
return -1;
}
}
use of hudson.maven.MavenModule in project evosuite by EvoSuite.
the class ProjectAction method perform.
public void perform(AbstractMavenProject<?, ?> project, AbstractBuild<?, ?> build, BuildListener listener) throws InterruptedException, IOException {
EnvVars env = build.getEnvironment(listener);
env.overrideAll(build.getBuildVariables());
VirtualChannel channel = build.getWorkspace().getChannel();
MavenModuleSet prj = (MavenModuleSet) this.project;
for (MavenModule module : prj.getModules()) {
FilePath fp = new FilePath(channel, build.getWorkspace().getRemote() + File.separator + (module.getRelativePath().isEmpty() ? "" : module.getRelativePath() + File.separator) + Properties.CTG_DIR + File.separator + Properties.CTG_PROJECT_INFO);
if (!fp.exists()) {
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "There is not any " + fp.getRemote() + " file for module " + module.getName());
continue;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
fp.copyTo(out);
ByteArrayInputStream projectXML = new ByteArrayInputStream(out.toByteArray());
listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Analysing " + Properties.CTG_PROJECT_INFO + " file from " + fp.getRemote());
ModuleAction m = new ModuleAction(build, module.getName());
if (!m.build(channel, projectXML, listener)) {
continue;
}
this.modules.add(m);
}
}
Aggregations