Skip to content

Commit

Permalink
bugzilla
Browse files Browse the repository at this point in the history
  • Loading branch information
mbien committed Mar 27, 2024
1 parent faa7720 commit 0d9f149
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 903 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,14 @@

package org.netbeans.modules.bugzilla;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
import org.netbeans.modules.bugtracking.api.Repository;
import org.netbeans.modules.team.spi.TeamBugtrackingConnector;
import org.netbeans.modules.bugzilla.repository.BugzillaRepository;
import org.netbeans.modules.bugtracking.spi.BugtrackingConnector;
import org.netbeans.modules.bugtracking.spi.RepositoryInfo;
import org.netbeans.modules.bugzilla.api.NBBugzillaUtils;
import org.netbeans.modules.bugzilla.kenai.KenaiRepository;
import org.netbeans.modules.bugzilla.repository.NBRepositorySupport;
import org.netbeans.modules.bugzilla.util.BugzillaUtil;
import org.netbeans.modules.team.spi.TeamAccessorUtils;
import org.netbeans.modules.team.spi.TeamProject;
import org.openide.util.NbBundle;

/**
Expand All @@ -54,10 +47,6 @@ public BugzillaConnector() {}

@Override
public Repository createRepository(RepositoryInfo info) {
Repository r = createKenaiRepository(info);
if(r != null) {
return r;
}
BugzillaRepository bugzillaRepository = new BugzillaRepository(info);
if(BugzillaUtil.isNbRepository(bugzillaRepository)) {
NBRepositorySupport.getInstance().setNBBugzillaRepository(bugzillaRepository);
Expand All @@ -75,67 +64,6 @@ public static String getConnectorName() {
return NbBundle.getMessage(BugzillaConnector.class, "LBL_ConnectorName"); // NOI18N
}

/******************************************************************************
* Kenai
******************************************************************************/

public Repository createKenaiRepository(RepositoryInfo info) {
String name = info.getValue(TeamBugtrackingConnector.TEAM_PROJECT_NAME);
TeamProject project = null;
if(name != null) {
project = TeamAccessorUtils.getTeamProject(info.getUrl(), name);
}
if(project == null || project.getType() != BugtrackingType.BUGZILLA) {
return null;
}

KenaiRepository repo = createKenaiRepository(project, project.getDisplayName(), project.getFeatureLocation());
if(BugzillaUtil.isNbRepository(repo)) {
NBRepositorySupport.getInstance().setNBBugzillaRepository(repo);
}
return BugzillaUtil.createRepository(repo);
}

private KenaiRepository createKenaiRepository(TeamProject kenaiProject, String displayName, String location) {
final URL loc;
try {
loc = new URL(location);
} catch (MalformedURLException ex) {
Bugzilla.LOG.log(Level.WARNING, null, ex);
return null;
}

String host = loc.getHost();
int idx = location.indexOf(IBugzillaConstants.URL_BUGLIST);
if (idx <= 0) {
Bugzilla.LOG.log(Level.WARNING, "can't get issue tracker url from [{0}, {1}]", new Object[]{displayName, location}); // NOI18N
return null;
}
String url = location.substring(0, idx);
if (url.startsWith("http:")) { // XXX hack??? // NOI18N
url = "https" + url.substring(4); // NOI18N
}
String productParamUrl = null;
String productAttribute = "product="; // NOI18N
String product = null;
int idxProductStart = location.indexOf(productAttribute);
if (idxProductStart <= 0) {
Bugzilla.LOG.log(Level.WARNING, "can''t get issue tracker product from [{0}, {1}]", new Object[]{displayName, location}); // NOI18N
return null;
} else {
int idxProductEnd = location.indexOf("&", idxProductStart); // NOI18N
if(idxProductEnd > -1) {
productParamUrl = location.substring(idxProductStart, idxProductEnd);
product = location.substring(idxProductStart + productAttribute.length(), idxProductEnd);
} else {
productParamUrl = location.substring(idxProductStart);
product = location.substring(idxProductStart + productAttribute.length());
}
}

return new KenaiRepository(kenaiProject, displayName, url, host, productParamUrl, product);
}

@Override
public BugtrackingType getType() {
return BugtrackingType.BUGZILLA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import org.netbeans.modules.bugtracking.spi.QueryController;
import org.netbeans.modules.bugtracking.spi.QueryProvider;
import org.netbeans.modules.bugzilla.issue.BugzillaIssue;
import org.netbeans.modules.bugzilla.kenai.KenaiRepository;
import org.netbeans.modules.bugzilla.query.BugzillaQuery;
import org.netbeans.modules.bugzilla.repository.BugzillaRepository;
import org.openide.util.NbBundle;

/**
*
Expand All @@ -34,10 +31,7 @@ public class BugzillaQueryProvider implements QueryProvider<BugzillaQuery, Bugzi

@Override
public String getDisplayName(BugzillaQuery query) {
String name = query.getDisplayName();
return name != null ?
name + (needsAndHasNoLogin(query) ? " " + NbBundle.getMessage(BugzillaQueryProvider.class, "LBL_NotLoggedIn") : "") :
null;
return query.getDisplayName();
}

@Override
Expand Down Expand Up @@ -77,24 +71,7 @@ public void setIssueContainer(BugzillaQuery query, IssueContainer<BugzillaIssue>

@Override
public void refresh(BugzillaQuery query) {
if(needsAndHasNoLogin(query)) {
return;
}
query.getController().refresh(true);
}


/************************************************************************************
* Kenai
************************************************************************************/

private boolean needsAndHasNoLogin(BugzillaQuery query) {
BugzillaRepository repo = query.getRepository();
if(repo instanceof KenaiRepository ) {
KenaiRepository kenaiRepo = (KenaiRepository) repo;
return kenaiRepo.isMyIssues(query) && !kenaiRepo.isLoggedIn();
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.MissingResourceException;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import org.apache.commons.httpclient.RedirectException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaStatus;
Expand Down Expand Up @@ -65,7 +64,6 @@ public class BugzillaExecutor {
private static final String USERNAME_CONFIRM_MATCH = "Confirm Match"; // NOI18N
private static final String INVALID_USERNAME_OR_PASSWORD = "invalid username or password"; // NOI18N
private static final String REPOSITORY_LOGIN_FAILURE = "unable to login to"; // NOI18N
private static final String KENAI_LOGIN_REDIRECT = "/people/login?original_uri="; // NOI18N
private static final String COULD_NOT_BE_FOUND = "could not be found"; // NOI18N
private static final String REPOSITORY = "repository"; // NOI18N
private static final String MIDAIR_COLLISION = "mid-air collision occurred while submitting to"; // NOI18N
Expand Down Expand Up @@ -351,10 +349,6 @@ static ExceptionHandler createHandler(CoreException ce, BugzillaExecutor executo
if(errormsg != null) {
return new LoginHandler(ce, errormsg, executor, repository);
}
errormsg = getKenaiRedirectError(ce);
if(errormsg != null) {
return new LoginHandler(ce, errormsg, executor, repository);
}
errormsg = getNotFoundError(ce);
if(errormsg != null) {
return new NotFoundHandler(ce, errormsg, executor, repository);
Expand Down Expand Up @@ -417,22 +411,6 @@ private static String getLoginError(BugzillaRepository repository, ValidateComma
return null;
}

private static String getKenaiRedirectError(CoreException ce) {
IStatus status = ce.getStatus();
if(status == null) {
return null;
}
Throwable cause = status.getException();
if(cause instanceof RedirectException) {
String msg = cause.getMessage();
if(msg.contains(KENAI_LOGIN_REDIRECT)) {
Bugzilla.LOG.log(Level.FINER, "returned error message [{0}]", msg); // NOI18N
return NbBundle.getMessage(BugzillaExecutor.class, "MSG_INVALID_USERNAME_OR_PASSWORD"); // NOI18N
}
}
return null;
}

private static String getMidAirColisionError(CoreException ce) {
String msg = getMessage(ce);
if(msg != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@
import org.netbeans.modules.bugtracking.commons.LinkButton;
import org.netbeans.modules.bugtracking.commons.UIUtils;
import org.netbeans.modules.bugzilla.Bugzilla;
import org.netbeans.modules.bugzilla.kenai.KenaiRepository;
import org.netbeans.modules.bugzilla.repository.IssueField;
import org.netbeans.modules.team.spi.TeamAccessorUtils;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;

Expand Down Expand Up @@ -217,15 +215,6 @@ private ExpandLabel addSection(GroupLayout layout, final Long number, String tex

// state label
JLabel stateLabel = null;
if (issue.getRepository() instanceof KenaiRepository) {
int index = author.indexOf('@'); // NOI18N
String userName = (index == -1) ? author : author.substring(0,index);
String host = ((KenaiRepository) issue.getRepository()).getHost();
stateLabel = TeamAccessorUtils.createUserWidget(issue.getRepository().getUrl(), userName, host, TeamAccessorUtils.getChatLink(issue.getID()));
if (stateLabel != null) {
stateLabel.setText(null);
}
}

// replay button
LinkButton replyButton = new LinkButton(bundle.getString("Comments.replyButton.text")); // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
import org.netbeans.modules.bugzilla.BugzillaConfig;
import org.netbeans.modules.bugzilla.issue.BugzillaIssue.Attachment;
import org.netbeans.modules.bugzilla.issue.BugzillaIssue.Comment;
import org.netbeans.modules.bugzilla.kenai.KenaiRepository;
import org.netbeans.modules.bugzilla.repository.BugzillaConfiguration;
import org.netbeans.modules.bugzilla.repository.BugzillaRepository;
import org.netbeans.modules.bugzilla.repository.CustomIssueField;
Expand Down Expand Up @@ -469,10 +468,7 @@ private void selectProduct() {
}
} else {
BugzillaRepository repository = issue.getRepository();
if (repository instanceof KenaiRepository) {
String productName = ((KenaiRepository)repository).getProductName();
productCombo.setSelectedItem(productName);
} else if (BugzillaUtil.isNbRepository(repository)) {
if (BugzillaUtil.isNbRepository(repository)) {
// IssueProvider 181224
String defaultProduct = "ide"; // NOI18N
String defaultComponent = "Code"; // NOI18N
Expand Down Expand Up @@ -512,7 +508,7 @@ void reloadForm(boolean force) {
clearHighlights();

boolean isNew = issue.isNew();
boolean showProductCombo = isNew || !(issue.getRepository() instanceof KenaiRepository) || NBBugzillaUtils.isNbRepository(issue.getRepository().getUrl());
boolean showProductCombo = true;
boolean hasTimeTracking = !isNew && issue.hasTimeTracking();
GroupLayout layout = (GroupLayout) attributesSectionPanel.getLayout();
if (showProductCombo) {
Expand Down Expand Up @@ -621,7 +617,6 @@ void reloadForm(boolean force) {
reloadField(addCommentArea, IssueField.COMMENT);
}

boolean isKenaiRepository = (issue.getRepository() instanceof KenaiRepository);
if (!isNew) {
// reported field
format = NbBundle.getMessage(IssuePanel.class, "IssuePanel.reportedLabel.format"); // NOI18N
Expand All @@ -633,17 +628,6 @@ void reloadForm(boolean force) {
String reportedTxt = MessageFormat.format(format, creationTxt, reporterTxt);
reportedField.setText(reportedTxt);
fixPrefSize(reportedField);
if (isKenaiRepository && (reportedStatusLabel.getIcon() == null)) {
int index = reporter.indexOf('@');
String userName = (index == -1) ? reporter : reporter.substring(0,index);
String host = ((KenaiRepository) issue.getRepository()).getHost();
JLabel label = TeamAccessorUtils.createUserWidget(issue.getRepository().getUrl(), userName, host, TeamAccessorUtils.getChatLink(issue.getID()));
if (label != null) {
label.setText(null);
((GroupLayout) attributesSectionPanel.getLayout()).replace(reportedStatusLabel, label);
reportedStatusLabel = label;
}
}

// modified field
Date modification = issue.getLastModifyDate();
Expand Down Expand Up @@ -686,18 +670,6 @@ void reloadForm(boolean force) {

String assignee = issue.getFieldValue(IssueField.ASSIGNED_TO);
String selectedAssignee = (assignedField.getParent() == null) ? assignedCombo.getSelectedItem().toString() : assignedField.getText();
if (isKenaiRepository && (assignee.trim().length() > 0) && (force || !selectedAssignee.equals(assignee))) {
int index = assignee.indexOf('@');
String userName = (index == -1) ? assignee : assignee.substring(0,index);
String host = ((KenaiRepository) issue.getRepository()).getHost();
JLabel label = TeamAccessorUtils.createUserWidget(issue.getRepository().getUrl(), userName, host, TeamAccessorUtils.getChatLink(issue.getID()));
if (label != null) {
label.setText(null);
((GroupLayout) attributesSectionPanel.getLayout()).replace(assignedToStatusLabel, label);
label.setVisible(assignedToStatusLabel.isVisible());
assignedToStatusLabel = label;
}
}
if (force) {
assignedToStatusLabel.setVisible(assignee.trim().length() > 0);
}
Expand Down Expand Up @@ -3305,9 +3277,6 @@ private void assignedComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN
if (value instanceof RepositoryUser) {
String assignee = ((RepositoryUser)value).getUserName();
BugzillaRepository repository = issue.getRepository();
if (repository instanceof KenaiRepository) {
assignee += '@' + ((KenaiRepository)repository).getHost();
}
assignedCombo.setSelectedItem(assignee);
}
}//GEN-LAST:event_assignedComboActionPerformed
Expand Down

This file was deleted.

Loading

0 comments on commit 0d9f149

Please sign in to comment.