Remove multiple implementations of getSshHost() in email classes
The getSshHost() method was implemented in both ReplacePatchSetSender and NewChangeSender. Remove these and implement it in the NotificationEmail base class instead. Change-Id: I55e36021915d147e01c676e7837557f5283812f6
This commit is contained in:
committed by
David Pursehouse
parent
618f878dc0
commit
3a495e6c46
@@ -29,9 +29,10 @@ public class AddReviewerSender extends NewChangeSender {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AddReviewerSender(EmailArguments ea,
|
public AddReviewerSender(EmailArguments ea,
|
||||||
@AnonymousCowardName String anonymousCowardName, SshInfo sshInfo,
|
@AnonymousCowardName String anonymousCowardName, SshInfo si,
|
||||||
@Assisted Change c) {
|
@Assisted Change c) {
|
||||||
super(ea, anonymousCowardName, sshInfo, c);
|
super(ea, anonymousCowardName, c);
|
||||||
|
setSshInfo(si);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -40,9 +40,10 @@ public class CreateChangeSender extends NewChangeSender {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CreateChangeSender(EmailArguments ea,
|
public CreateChangeSender(EmailArguments ea,
|
||||||
@AnonymousCowardName String anonymousCowardName, SshInfo sshInfo,
|
@AnonymousCowardName String anonymousCowardName, SshInfo si,
|
||||||
@Assisted Change c) {
|
@Assisted Change c) {
|
||||||
super(ea, anonymousCowardName, sshInfo, c);
|
super(ea, anonymousCowardName, c);
|
||||||
|
setSshInfo(si);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ package com.google.gerrit.server.mail;
|
|||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.server.ssh.SshInfo;
|
|
||||||
|
|
||||||
import com.jcraft.jsch.HostKey;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -29,14 +26,12 @@ import java.util.Set;
|
|||||||
|
|
||||||
/** Sends an email alerting a user to a new change for them to review. */
|
/** Sends an email alerting a user to a new change for them to review. */
|
||||||
public abstract class NewChangeSender extends ChangeEmail {
|
public abstract class NewChangeSender extends ChangeEmail {
|
||||||
private final SshInfo sshInfo;
|
|
||||||
private final Set<Account.Id> reviewers = new HashSet<Account.Id>();
|
private final Set<Account.Id> reviewers = new HashSet<Account.Id>();
|
||||||
private final Set<Account.Id> extraCC = new HashSet<Account.Id>();
|
private final Set<Account.Id> extraCC = new HashSet<Account.Id>();
|
||||||
|
|
||||||
protected NewChangeSender(EmailArguments ea, String anonymousCowardName,
|
protected NewChangeSender(EmailArguments ea, String anonymousCowardName,
|
||||||
SshInfo sshInfo, Change c) {
|
Change c) {
|
||||||
super(ea, anonymousCowardName, c, "newchange");
|
super(ea, anonymousCowardName, c, "newchange");
|
||||||
this.sshInfo = sshInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addReviewers(final Collection<Account.Id> cc) {
|
public void addReviewers(final Collection<Account.Id> cc) {
|
||||||
@@ -73,17 +68,4 @@ public abstract class NewChangeSender extends ChangeEmail {
|
|||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSshHost() {
|
|
||||||
final List<HostKey> hostKeys = sshInfo.getHostKeys();
|
|
||||||
if (hostKeys.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String host = hostKeys.get(0).getHost();
|
|
||||||
if (host.startsWith("*:")) {
|
|
||||||
return getGerritHost() + host.substring(1);
|
|
||||||
}
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,16 @@ import com.google.gerrit.reviewdb.client.Branch;
|
|||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
|
||||||
import com.google.gerrit.server.mail.ProjectWatch.Watchers;
|
import com.google.gerrit.server.mail.ProjectWatch.Watchers;
|
||||||
|
import com.google.gerrit.server.ssh.SshInfo;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
|
|
||||||
|
import com.jcraft.jsch.HostKey;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common class for notifications that are related to a project and branch
|
* Common class for notifications that are related to a project and branch
|
||||||
*/
|
*/
|
||||||
@@ -33,6 +38,7 @@ public abstract class NotificationEmail extends OutgoingEmail {
|
|||||||
|
|
||||||
protected Project.NameKey project;
|
protected Project.NameKey project;
|
||||||
protected Branch.NameKey branch;
|
protected Branch.NameKey branch;
|
||||||
|
private SshInfo sshInfo;
|
||||||
|
|
||||||
protected NotificationEmail(EmailArguments ea, String anonymousCowardName,
|
protected NotificationEmail(EmailArguments ea, String anonymousCowardName,
|
||||||
String mc, Project.NameKey project, Branch.NameKey branch) {
|
String mc, Project.NameKey project, Branch.NameKey branch) {
|
||||||
@@ -70,6 +76,26 @@ public abstract class NotificationEmail extends OutgoingEmail {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setSshInfo(SshInfo si) {
|
||||||
|
this.sshInfo = si;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSshHost() {
|
||||||
|
if (sshInfo == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final List<HostKey> hostKeys = sshInfo.getHostKeys();
|
||||||
|
if (hostKeys.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String host = hostKeys.get(0).getHost();
|
||||||
|
if (host.startsWith("*:")) {
|
||||||
|
return getGerritHost() + host.substring(1);
|
||||||
|
}
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setupVelocityContext() {
|
protected void setupVelocityContext() {
|
||||||
super.setupVelocityContext();
|
super.setupVelocityContext();
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ import com.google.gerrit.server.ssh.SshInfo;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
import com.jcraft.jsch.HostKey;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -39,14 +37,13 @@ public class ReplacePatchSetSender extends ReplyToChangeSender {
|
|||||||
|
|
||||||
private final Set<Account.Id> reviewers = new HashSet<Account.Id>();
|
private final Set<Account.Id> reviewers = new HashSet<Account.Id>();
|
||||||
private final Set<Account.Id> extraCC = new HashSet<Account.Id>();
|
private final Set<Account.Id> extraCC = new HashSet<Account.Id>();
|
||||||
private final SshInfo sshInfo;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ReplacePatchSetSender(EmailArguments ea,
|
public ReplacePatchSetSender(EmailArguments ea,
|
||||||
@AnonymousCowardName String anonymousCowardName, SshInfo si,
|
@AnonymousCowardName String anonymousCowardName, SshInfo si,
|
||||||
@Assisted Change c) {
|
@Assisted Change c) {
|
||||||
super(ea, anonymousCowardName, c, "newpatchset");
|
super(ea, anonymousCowardName, c, "newpatchset");
|
||||||
sshInfo = si;
|
setSshInfo(si);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addReviewers(final Collection<Account.Id> cc) {
|
public void addReviewers(final Collection<Account.Id> cc) {
|
||||||
@@ -88,17 +85,4 @@ public class ReplacePatchSetSender extends ReplyToChangeSender {
|
|||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSshHost() {
|
|
||||||
final List<HostKey> hostKeys = sshInfo.getHostKeys();
|
|
||||||
if (hostKeys.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String host = hostKeys.get(0).getHost();
|
|
||||||
if (host.startsWith("*:")) {
|
|
||||||
return getGerritHost() + host.substring(1);
|
|
||||||
}
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user