Skip to content

Commit

Permalink
fix with the comments from the pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
BeckerFrank committed Oct 18, 2023
1 parent 191e22a commit 83e680c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ public GitlabActivityStyle clone() throws CloneNotSupportedException {
return (GitlabActivityStyle) super.clone();
}

@Override
public String toString() {
return "GitlabActivityStyle [start=" + start + ", length=" + length + ", fontStyle=" + fontStyle + ", color="
+ color + ", url=" + url + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ public Optional<GitlabConfiguration> load(RepositoryKey key) throws Exception {
}

public GitlabConfiguration getRepositoryConfiguration(TaskRepository repository) throws CoreException {
long startTime, endTime = 0;
long startTime = 0, endTime = 0;
Thread thread;
if (clientCache.getIfPresent(new RepositoryKey(repository)) == null) {
getClient(repository);
}
try {
if (TRACE) {
thread = Thread.currentThread();
startTime = Calendar.getInstance().getTimeInMillis();
startTime = System.currentTimeMillis();
System.out.println(thread.getName() + " start getRepositoryConfiguration " + repository.getUrl() + " "
+ Thread.currentThread().getStackTrace()[2].getMethodName() /*+ " " +startTime + " "+ Calendar.getInstance().getTime().toLocaleString()*/);
}
Expand All @@ -180,7 +180,7 @@ public GitlabConfiguration getRepositoryConfiguration(TaskRepository repository)
GitlabConfiguration result = configurationOptional.isPresent() ? configurationOptional.get() : null;
if (TRACE) {
thread = Thread.currentThread();
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
System.out.println(thread.getName() + " end getRepositoryConfiguration " + repository.getUrl() + " "
+ Thread.currentThread().getStackTrace()[2].getMethodName() + " " + (endTime - startTime) + " ms " /*+endTime +" " + Calendar.getInstance().getTime().toLocaleString()*/);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -91,6 +95,7 @@ public class GitlabRestClient {
private final CommonHttpClient client;
private final GitlabRepositoryConnector connector;
private final TaskRepository taskRepository;
private static final Pattern linkPattern = Pattern.compile("\\[(.+)\\]\\((.+)\\)");;

public static String AUTHORIZATION_HEADER = "authorization_header";
private static final boolean TRACE = false;
Expand Down Expand Up @@ -473,13 +478,13 @@ public String obtainAccessToken(IOperationMonitor monitor) throws Exception {
public TaskData getTaskData(TaskRepository repository, String taskId, IProgressMonitor monitor)
throws GitlabException {
TaskData result = null;
long startTime, endTime = 0;
long startTime = 0, endTime = 0;
Thread thread;
if (TRACE) {
thread = Thread.currentThread();
System.out.println(
thread.getName() + " getTaskData start: " + repository.getRepositoryUrl() + " id " + taskId);
startTime = Calendar.getInstance().getTimeInMillis();
startTime = System.currentTimeMillis();
}
String searchString = ".*(/projects/\\d+)/issues/(\\d+)";
Pattern pattern = Pattern.compile(searchString, Pattern.CASE_INSENSITIVE);
Expand Down Expand Up @@ -550,9 +555,12 @@ public TaskData getTaskData(TaskRepository repository, String taskId, IProgressM
if (states != null) {
for (JsonElement stateElem : states) {
JsonObject state = (JsonObject) stateElem;
Date date = GitlabTaskAttributeMapper.parseDate(state.get("created_at").getAsString());
Instant instant = Instant
.from(DateTimeFormatter.ISO_INSTANT.parse(state.get("created_at").getAsString()));
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, TimeZone.getDefault().toZoneId());

TaskAttribute taskAttribute = result.getRoot()
.createAttribute(GitlabCoreActivator.PREFIX_ACTIVITY + date.getTime());
.createAttribute(GitlabCoreActivator.PREFIX_ACTIVITY + instant);
taskAttribute.getMetaData().setType(GitlabCoreActivator.ATTRIBUTE_TYPE_ACTIVITY);

String stateText = state.get("state").getAsString();
Expand All @@ -563,7 +571,7 @@ public TaskData getTaskData(TaskRepository repository, String taskId, IProgressM
taskAttribute.getMetaData().putValue(TaskAttribute.META_ASSOCIATED_ATTRIBUTE_ID, child.getId());

child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_DATE).createAttribute(taskAttribute);
child.setValue(DateFormat.getDateTimeInstance().format(date));
child.setValue(localDateTime.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)));

child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_AUTHOR).createAttribute(taskAttribute);
child.setValue(state.get("user").getAsJsonObject().get("name").getAsString());
Expand All @@ -582,27 +590,30 @@ public TaskData getTaskData(TaskRepository repository, String taskId, IProgressM
JsonArray labels = getIssueLabelEvents(matcher.group(1), matcher.group(2), OperationUtil.convert(monitor));
if (labels != null) {
long lastLabelAt = 0;
Instant instantAt = null;
TaskAttribute labelText = null;
ArrayList<String> added = new ArrayList<String>();
ArrayList<String> removed = new ArrayList<String>();
for (JsonElement stateElem : labels) {
JsonObject label = (JsonObject) stateElem;
Date date = GitlabTaskAttributeMapper.parseDate(label.get("created_at").getAsString());
Instant instant = Instant
.from(DateTimeFormatter.ISO_INSTANT.parse(label.get("created_at").getAsString()));
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, TimeZone.getDefault().toZoneId());

if (lastLabelAt != date.getTime()) {
lastLabelAt = date.getTime();
if (!instant.equals(instantAt)) {
instantAt = instant;

buildLableText(labelText, added, removed);

added.clear();
removed.clear();

TaskAttribute taskAttribute = result.getRoot()
.createAttribute(GitlabCoreActivator.PREFIX_ACTIVITY + date.getTime());
.createAttribute(GitlabCoreActivator.PREFIX_ACTIVITY + instant);
taskAttribute.getMetaData().setType(GitlabCoreActivator.ATTRIBUTE_TYPE_ACTIVITY);
TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_DATE)
.createAttribute(taskAttribute);
child.setValue(DateFormat.getDateTimeInstance().format(date));
child.setValue(localDateTime.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)));

child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_AUTHOR).createAttribute(taskAttribute);
child.setValue(label.get("user").getAsJsonObject().get("name").getAsString());
Expand Down Expand Up @@ -630,7 +641,7 @@ public TaskData getTaskData(TaskRepository repository, String taskId, IProgressM
config.updateProductOptions(result);
}
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getTaskData taken: " + (endTime - startTime) + " ms "
+ repository.getRepositoryUrl() + " id " + taskId);
Expand All @@ -644,37 +655,26 @@ private void buildLableText(TaskAttribute labelText, ArrayList<String> added, Ar
if (added.size() > 0) {
text += "added ";
text += String.join(", ", added);
if (added.size() > 1) {
text += " labels";
} else {
text += " label";
}
text += added.size() > 1 ? " labels" : " label";
}
if (removed.size() > 0) {
if (text.length() == 0) {
text += "removed ";
} else {
text += " and removed ";
}
text += text.length() == 0 ? "removed " : " and removed ";
text += String.join(", ", removed);
if (removed.size() > 1) {
text += " labels";
} else {
text += " label";
}
text += removed.size() > 1 ? " labels" : " label";
}
labelText.setValue(text);
}
}

private TaskAttribute createActivityEventTaskAttribute(TaskRepository repository, TaskAttribute result,
JsonObject note) {
Date date = GitlabTaskAttributeMapper.parseDate(note.get("created_at").getAsString());
TaskAttribute taskAttribute = result.createAttribute(GitlabCoreActivator.PREFIX_ACTIVITY + date.getTime());
Instant instant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(note.get("created_at").getAsString()));
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, TimeZone.getDefault().toZoneId());
TaskAttribute taskAttribute = result.createAttribute(GitlabCoreActivator.PREFIX_ACTIVITY + instant);
taskAttribute.getMetaData().setType(GitlabCoreActivator.ATTRIBUTE_TYPE_ACTIVITY);

TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_DATE).createAttribute(taskAttribute);
child.setValue(DateFormat.getDateTimeInstance().format(date));
child.setValue(localDateTime.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)));

child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_AUTHOR).createAttribute(taskAttribute);
child.setValue(note.get("author").getAsJsonObject().get("name").getAsString());
Expand Down Expand Up @@ -708,7 +708,6 @@ private void buildActivityEventStyleInformation(TaskAttribute taskAttribute, Str

TaskAttribute styleAttribute = taskAttribute.createAttribute(GitlabCoreActivator.ATTRIBUTE_TYPE_ACTIVITY_STYLE);
String resultText = "";
Pattern r = Pattern.compile("\\[(.+)\\]\\((.+)\\)");

String[] parts = bodyText.split("\\*\\*|\\*\\*\\{\\-|\\{\\-|\\-\\}|\\{\\+|\\+\\}");
ArrayList<GitlabActivityStyle> styles = new ArrayList<GitlabActivityStyle>(parts.length);
Expand All @@ -722,21 +721,21 @@ private void buildActivityEventStyleInformation(TaskAttribute taskAttribute, Str
String marker = textIdx + 2 <= textLen ? bodyText.substring(textIdx, textIdx + 2) : " ";

String matchText = parts[idx];
Matcher m = r.matcher(matchText);
Matcher linkMatcher = linkPattern.matcher(matchText);

if (m.find()) {
if (m.start(1) > 0) {
resultText += matchText.substring(0, m.start(1) - 1);
styleRange.add2Length(m.start(1) - 1);
if (linkMatcher.find()) {
if (linkMatcher.start(1) > 0) {
resultText += matchText.substring(0, linkMatcher.start(1) - 1);
styleRange.add2Length(linkMatcher.start(1) - 1);
styleRange = createNewRangeIfNeeded(resultText.length(), styles, styleRange, actPartLen);
styleRange.setFontStyle(GitlabActivityStyle.UNDERLINE_LINK);
styleRange.add2Length(m.group(1).length());
styleRange.setUrl(getTaskRepository().getUrl() + m.group(2));
resultText += m.group(1);
styleRange.add2Length(linkMatcher.group(1).length());
styleRange.setUrl(getTaskRepository().getUrl() + linkMatcher.group(2));
resultText += linkMatcher.group(1);
styleRange = createNewRangeIfNeeded(resultText.length(), styles, styleRange,
matchText.length() - m.end(2));
matchText.length() - linkMatcher.end(2));
styleRange.setFontStyle(GitlabActivityStyle.NORMAL);
actPartLen = matchText.length() - m.end(2) - 1;
actPartLen = matchText.length() - linkMatcher.end(2) - 1;
}
}

Expand Down Expand Up @@ -1197,19 +1196,19 @@ protected JsonObject parseFromJson(InputStreamReader in) throws GitlabException

public GitlabConfiguration getConfiguration(TaskRepository repository, IOperationMonitor monitor)
throws GitlabException {
long startTime, endTime = 0;
long startTime = 0, endTime = 0;
Thread thread;
if (TRACE) {
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration start: " + repository.getRepositoryUrl());
startTime = Calendar.getInstance().getTimeInMillis();
startTime = System.currentTimeMillis();
}
GitlabConfiguration config = new GitlabConfiguration(repository.getUrl());
JsonObject user = getUser(monitor);
config.setUserID(user.get("id").getAsBigInteger());
config.setUserDetails(user);
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration getUser: " + (endTime - startTime) + " ms "
+ repository.getRepositoryUrl());
Expand All @@ -1222,7 +1221,7 @@ public GitlabConfiguration getConfiguration(TaskRepository repository, IOperatio
config.addProject(projectObject, labels, milestones);
}
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration get Projects: " + (endTime - startTime) + " ms "
+ repository.getRepositoryUrl());
Expand All @@ -1235,7 +1234,7 @@ public GitlabConfiguration getConfiguration(TaskRepository repository, IOperatio
JsonObject projectDetail = getProject(URLEncoder.encode(project, StandardCharsets.UTF_8.toString()),
monitor);
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration get Project: " + (endTime - startTime)
+ " ms " + project + " " + repository.getRepositoryUrl());
Expand All @@ -1244,7 +1243,7 @@ public GitlabConfiguration getConfiguration(TaskRepository repository, IOperatio
JsonArray labels = getProjectLabels(projectObject.get("id").getAsString(), monitor);
JsonArray milestones = getProjectMilestones(projectObject.get("id").getAsString(), monitor);
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration get Projects Labels/Milestone: "
+ (endTime - startTime) + " ms " + project + " " + repository.getRepositoryUrl());
Expand All @@ -1257,7 +1256,7 @@ public GitlabConfiguration getConfiguration(TaskRepository repository, IOperatio
}
}
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration get Groups: " + (endTime - startTime) + " ms "
+ repository.getRepositoryUrl());
Expand All @@ -1269,14 +1268,14 @@ public GitlabConfiguration getConfiguration(TaskRepository repository, IOperatio
JsonObject groupDetail = getGroup("/" + group, monitor);
config.addGroup(groupDetail);
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration get Group: " + (endTime - startTime)
+ " ms " + group + " " + repository.getRepositoryUrl());
}
projects = getGroupProjects(group, monitor);
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration get Group projects: "
+ (endTime - startTime) + " ms " + group + " " + repository.getRepositoryUrl());
Expand All @@ -1286,7 +1285,7 @@ public GitlabConfiguration getConfiguration(TaskRepository repository, IOperatio
JsonArray labels = getProjectLabels(projectObject.get("id").getAsString(), monitor);
JsonArray milestones = getProjectMilestones(projectObject.get("id").getAsString(), monitor);
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration get Group Projects Labels/Milestone: "
+ (endTime - startTime) + " ms " + group + " " + projectObject.get("id").getAsString()
Expand All @@ -1295,15 +1294,15 @@ public GitlabConfiguration getConfiguration(TaskRepository repository, IOperatio
config.addProject(projectObject, labels, milestones);
}
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration get Group projects: "
+ (endTime - startTime) + " ms " + group + " " + repository.getRepositoryUrl());
}
}
}
if (TRACE) {
endTime = Calendar.getInstance().getTimeInMillis();
endTime = System.currentTimeMillis();
thread = Thread.currentThread();
System.out.println(thread.getName() + " getConfiguration taken: " + (endTime - startTime) + " ms "
+ repository.getRepositoryUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<feature
id="org.eclipse.mylyn.gitlab.feature"
label="%featureName"
version="4.0.0.qualifier"
version="4.1.0.qualifier"
provider-name="%providerName"
plugin="org.eclipse.mylyn.gitlab.core"
license-feature="org.eclipse.license"
Expand Down
Loading

0 comments on commit 83e680c

Please sign in to comment.