Skip to content
This repository was archived by the owner on Dec 13, 2017. It is now read-only.

Commit 7abeed6

Browse files
committed
Merge remote-tracking branch 'bitbucket/master' into master
2 parents bda7318 + 751a59d commit 7abeed6

File tree

12 files changed

+172
-221
lines changed

12 files changed

+172
-221
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
![Commit Graph](http://i.imgur.com/yPSMwCH.png)
22
# Installation
33

4-
Refer to the Atlassian Marketplace. Installing plugin versions that are not meant for your Stash version can cause stability issues.
4+
Refer to the Atlassian Marketplace. Installing plugin versions that are not meant for your Bitbucket Server version can cause stability issues.
55

66
# Development
77

mvnvm.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mvn_version=3.3.3

pom.xml

Lines changed: 38 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,32 @@
22

33
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
44
<modelVersion>4.0.0</modelVersion>
5+
56
<groupId>com.plugin.commitgraph</groupId>
67
<artifactId>commitgraph</artifactId>
7-
<version>1.1</version>
8+
<version>2.0</version>
9+
810
<organization>
911
<name>Chason Choate</name>
1012
<url>https://github.com/cha55son</url>
1113
</organization>
14+
1215
<name>Commit Graph</name>
13-
<description>The missing commit graph for Atlassian Stash.</description>
16+
<description>The missing commit graph for Atlassian Bitbucket Server.</description>
1417
<packaging>atlassian-plugin</packaging>
18+
1519
<dependencyManagement>
1620
<dependencies>
1721
<dependency>
18-
<groupId>com.atlassian.stash</groupId>
19-
<artifactId>stash-parent</artifactId>
20-
<version>${stash.version}</version>
22+
<groupId>com.atlassian.bitbucket.server</groupId>
23+
<artifactId>bitbucket-parent</artifactId>
24+
<version>${bitbucket.version}</version>
2125
<type>pom</type>
2226
<scope>import</scope>
2327
</dependency>
2428
</dependencies>
2529
</dependencyManagement>
30+
2631
<dependencies>
2732
<dependency>
2833
<groupId>com.atlassian.plugins</groupId>
@@ -35,93 +40,73 @@
3540
<scope>provided</scope>
3641
</dependency>
3742
<dependency>
38-
<groupId>com.atlassian.stash</groupId>
39-
<artifactId>stash-api</artifactId>
43+
<groupId>com.atlassian.bitbucket.server</groupId>
44+
<artifactId>bitbucket-api</artifactId>
4045
<scope>provided</scope>
4146
</dependency>
4247
<dependency>
43-
<groupId>com.atlassian.stash</groupId>
44-
<artifactId>stash-spi</artifactId>
48+
<groupId>com.atlassian.bitbucket.server</groupId>
49+
<artifactId>bitbucket-spi</artifactId>
4550
<scope>provided</scope>
4651
</dependency>
4752
<dependency>
48-
<groupId>com.atlassian.stash</groupId>
49-
<artifactId>stash-page-objects</artifactId>
53+
<groupId>com.atlassian.bitbucket.server</groupId>
54+
<artifactId>bitbucket-util</artifactId>
5055
<scope>provided</scope>
5156
</dependency>
5257
<dependency>
5358
<groupId>javax.servlet</groupId>
54-
<artifactId>servlet-api</artifactId>
55-
<scope>provided</scope>
56-
</dependency>
57-
<dependency>
58-
<groupId>junit</groupId>
59-
<artifactId>junit</artifactId>
60-
<version>4.10</version>
61-
<scope>test</scope>
62-
</dependency>
63-
<dependency>
64-
<groupId>commons-lang</groupId>
65-
<artifactId>commons-lang</artifactId>
66-
<version>2.6</version>
59+
<artifactId>javax.servlet-api</artifactId>
6760
<scope>provided</scope>
6861
</dependency>
69-
<!-- WIRED TEST RUNNER DEPENDENCIES -->
70-
<dependency>
71-
<groupId>com.atlassian.plugins</groupId>
72-
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
73-
<version>${plugin.testrunner.version}</version>
74-
<scope>test</scope>
75-
</dependency>
76-
<dependency>
77-
<groupId>javax.ws.rs</groupId>
78-
<artifactId>jsr311-api</artifactId>
79-
<version>1.1.1</version>
80-
<scope>provided</scope>
81-
</dependency>
82-
<dependency>
83-
<groupId>com.google.code.gson</groupId>
84-
<artifactId>gson</artifactId>
85-
<version>2.2.2-atlassian-1</version>
86-
</dependency>
8762
<dependency>
8863
<groupId>com.atlassian.soy</groupId>
8964
<artifactId>soy-template-renderer-api</artifactId>
90-
<version>1.1.1</version>
9165
<scope>provided</scope>
9266
</dependency>
9367
</dependencies>
68+
9469
<build>
9570
<plugins>
9671
<plugin>
9772
<groupId>com.atlassian.maven.plugins</groupId>
98-
<artifactId>maven-stash-plugin</artifactId>
73+
<artifactId>bitbucket-maven-plugin</artifactId>
9974
<version>${amps.version}</version>
10075
<extensions>true</extensions>
10176
<configuration>
77+
<instructions>
78+
<Atlassian-Plugin-Key>${project.groupId}.${project.artifactId}</Atlassian-Plugin-Key>
79+
<Import-Package>
80+
com.atlassian.bitbucket.web.conditions,
81+
*
82+
</Import-Package>
83+
<Spring-Context>*</Spring-Context>
84+
</instructions>
10285
<products>
10386
<product>
104-
<id>stash</id>
105-
<instanceId>stash</instanceId>
106-
<version>${stash.version}</version>
107-
<dataVersion>${stash.data.version}</dataVersion>
87+
<id>bitbucket</id>
88+
<instanceId>bitbucket</instanceId>
89+
<version>${bitbucket.version}</version>
90+
<dataVersion>${bitbucket.data.version}</dataVersion>
10891
</product>
10992
</products>
11093
</configuration>
11194
</plugin>
11295
<plugin>
11396
<artifactId>maven-compiler-plugin</artifactId>
97+
<version>3.3</version>
11498
<configuration>
115-
<source>1.6</source>
116-
<target>1.6</target>
99+
<source>1.8</source>
100+
<target>1.8</target>
117101
</configuration>
118102
</plugin>
119103
</plugins>
120104
</build>
105+
121106
<properties>
122-
<stash.version>3.11.3</stash.version>
123-
<stash.data.version>3.11.3</stash.data.version>
124-
<amps.version>5.1.18</amps.version>
107+
<bitbucket.version>4.0.0-rc12</bitbucket.version>
108+
<bitbucket.data.version>${bitbucket.version}</bitbucket.data.version>
109+
<amps.version>6.1.0</amps.version>
125110
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
126111
</properties>
127112
</project>

src/main/java/com/plugin/commitgraph/MyPluginComponent.java

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/main/java/com/plugin/commitgraph/MyPluginComponentImpl.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/networkservlet/NetworkServlet.java

Lines changed: 54 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package networkservlet;
22

3+
import com.atlassian.bitbucket.auth.AuthenticationContext;
4+
import com.atlassian.bitbucket.commit.Commit;
5+
import com.atlassian.bitbucket.commit.CommitRequest;
6+
import com.atlassian.bitbucket.commit.CommitService;
7+
import com.atlassian.bitbucket.commit.graph.*;
8+
import com.atlassian.bitbucket.repository.AbstractRefCallback;
9+
import com.atlassian.bitbucket.repository.Ref;
10+
import com.atlassian.bitbucket.repository.Repository;
11+
import com.atlassian.bitbucket.repository.RepositoryService;
12+
import com.atlassian.bitbucket.scm.ScmService;
13+
import com.atlassian.bitbucket.user.ApplicationUser;
14+
import com.atlassian.bitbucket.user.SecurityService;
15+
import com.atlassian.bitbucket.util.Page;
16+
import com.atlassian.bitbucket.util.PageUtils;
17+
import com.atlassian.plugin.webresource.WebResourceManager;
318
import com.atlassian.soy.renderer.SoyException;
419
import com.atlassian.soy.renderer.SoyTemplateRenderer;
5-
6-
import com.atlassian.stash.content.Changeset;
7-
import com.atlassian.stash.repository.*;
8-
import com.atlassian.stash.commit.CommitService;
9-
import com.atlassian.stash.user.SecurityService;
10-
import com.atlassian.plugin.webresource.WebResourceManager;
11-
import com.atlassian.stash.exception.NoSuchEntityException;
12-
13-
import com.atlassian.stash.commit.graph.*;
14-
import com.atlassian.stash.user.StashAuthenticationContext;
15-
import com.atlassian.stash.user.StashUser;
16-
import com.atlassian.stash.util.*;
17-
import com.atlassian.stash.scm.ScmService;
1820
import com.google.common.collect.ImmutableMap;
1921

20-
import org.slf4j.Logger;
21-
import org.slf4j.LoggerFactory;
22-
2322
import javax.annotation.Nonnull;
2423
import javax.servlet.ServletException;
2524
import javax.servlet.http.HttpServlet;
@@ -32,36 +31,32 @@
3231
import java.util.Map;
3332

3433
public class NetworkServlet extends HttpServlet {
35-
private static final Logger log = LoggerFactory.getLogger(NetworkServlet.class);
3634

37-
static final String NETWORK_PAGE = "stash.plugin.network";
38-
static final String NETWORK_PAGE_FRAGMENT = "stash.plugin.network_fragment";
35+
static final String NETWORK_PAGE = "bitbucket.plugin.network";
36+
static final String NETWORK_PAGE_FRAGMENT = "bitbucket.plugin.network_fragment";
3937

38+
private final AuthenticationContext authenticationContext;
39+
private final CommitService commitService;
4040
private final RepositoryService repositoryService;
41-
private final RepositoryMetadataService repositoryMetadataService;
41+
private final ScmService scmService;
42+
private final SecurityService securityService;
4243
private final SoyTemplateRenderer soyTemplateRenderer;
43-
private final CommitService commitService;
4444
private final WebResourceManager webResourceManager;
45-
private final SecurityService securityService;
46-
private final StashAuthenticationContext stashAuthenticationContext;
47-
private final ScmService scmService;
4845

49-
public NetworkServlet(SoyTemplateRenderer soyTemplateRenderer,
50-
RepositoryService repositoryService,
51-
RepositoryMetadataService repositoryMetadataService,
46+
public NetworkServlet(AuthenticationContext authenticationContext,
5247
CommitService commitService,
53-
WebResourceManager webResourceManager,
48+
RepositoryService repositoryService,
49+
ScmService scmService,
5450
SecurityService securityService,
55-
StashAuthenticationContext stashAuthenticationContext,
56-
ScmService scmService) {
57-
this.soyTemplateRenderer = soyTemplateRenderer;
58-
this.repositoryService = repositoryService;
59-
this.repositoryMetadataService = repositoryMetadataService;
51+
SoyTemplateRenderer soyTemplateRenderer,
52+
WebResourceManager webResourceManager) {
53+
this.authenticationContext = authenticationContext;
6054
this.commitService = commitService;
61-
this.webResourceManager = webResourceManager;
62-
this.securityService = securityService;
63-
this.stashAuthenticationContext = stashAuthenticationContext;
55+
this.repositoryService = repositoryService;
6456
this.scmService = scmService;
57+
this.securityService = securityService;
58+
this.soyTemplateRenderer = soyTemplateRenderer;
59+
this.webResourceManager = webResourceManager;
6560
}
6661

6762
@Override
@@ -80,34 +75,34 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
8075
return;
8176
}
8277
final Repository repository = repositoryService.getBySlug(components[1], components[2]);
83-
final StashUser user = stashAuthenticationContext.getCurrentUser();
78+
final ApplicationUser user = authenticationContext.getCurrentUser();
8479
// Ensure we have a valid repository and user
8580
if (repository == null || user == null) {
8681
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
8782
return;
8883
}
8984

9085
Map<String, List<Ref>> labels = getLabels(repository);
91-
Page<Changeset> changesets = this.getChangesets(repository, labels, limit, offset);
86+
Page<Commit> commits = this.getCommits(repository, labels, limit, offset);
9287

9388
webResourceManager.requireResource("com.plugin.commitgraph.commitgraph:commitgraph-resources");
94-
render(resp, (contentsOnly ? NETWORK_PAGE_FRAGMENT : NETWORK_PAGE), ImmutableMap.<String, Object>of(
95-
"repository", repository,
96-
"changesetPage", changesets,
97-
"labels", labels,
98-
"limit", limit,
99-
"page", (page + 1)
89+
render(resp, (contentsOnly ? NETWORK_PAGE_FRAGMENT : NETWORK_PAGE), ImmutableMap.of(
90+
"repository", repository,
91+
"commitPage", commits,
92+
"labels", labels,
93+
"limit", limit,
94+
"page", (page + 1)
10095
));
10196
}
10297

10398
protected Map<String, List<Ref>> getLabels(Repository repository) {
104-
final Map<String, List<Ref>> labels = new HashMap<String, List<Ref>>();
99+
final Map<String, List<Ref>> labels = new HashMap<>();
105100
scmService.getCommandFactory(repository).heads(new AbstractRefCallback() {
106101
@Override
107102
public boolean onRef(@Nonnull Ref ref) {
108-
List<Ref> refs = labels.get(ref.getLatestChangeset());
103+
List<Ref> refs = labels.get(ref.getLatestCommit());
109104
if (refs == null) {
110-
labels.put(ref.getLatestChangeset(), refs = new ArrayList<Ref>());
105+
labels.put(ref.getLatestCommit(), refs = new ArrayList<>());
111106
}
112107
refs.add(ref);
113108
return true;
@@ -116,34 +111,28 @@ public boolean onRef(@Nonnull Ref ref) {
116111
return labels;
117112
}
118113

119-
protected Page<Changeset> getChangesets(final Repository repository,
114+
protected Page<Commit> getCommits(final Repository repository,
120115
final Map<String, List<Ref>> labels,
121116
final Integer limit,
122117
final Integer offset) {
123-
final ArrayList<Changeset> changesets = new ArrayList<Changeset>();
118+
final ArrayList<Commit> commits = new ArrayList<>();
124119
TraversalRequest request = new TraversalRequest.Builder().repository(repository).include(labels.keySet()).build();
125-
final Integer counter = 0;
126-
long startTime = System.currentTimeMillis();
127-
final StashUser user = stashAuthenticationContext.getCurrentUser();
120+
final ApplicationUser user = authenticationContext.getCurrentUser();
128121
commitService.traverse(request, new TraversalCallback() {
129122
private Integer counter;
130123
@Override
131-
public void onStart(TraversalContext context) {
124+
public void onStart(@Nonnull TraversalContext context) {
132125
this.counter = 0;
133126
}
134127
@Override
135-
public TraversalStatus onNode(final CommitGraphNode node) {
136-
Boolean captured = false;
128+
public TraversalStatus onNode(final @Nonnull CommitGraphNode node) {
137129
if (counter >= offset && counter < (offset + limit)) {
138-
securityService.impersonating(user, "Reading repository changesets")
139-
.call(new UncheckedOperation<Boolean>() {
140-
@Override
141-
public Boolean perform() {
142-
changesets.add(commitService.getChangeset(repository, node.getCommit().getId()));
143-
return true;
144-
}
130+
securityService.impersonating(user, "Reading repository commits")
131+
.call(() -> {
132+
commits.add(commitService.getCommit(
133+
new CommitRequest.Builder(repository, node.getCommit().getId()).build()));
134+
return true;
145135
});
146-
captured = true;
147136
} else if (counter >= (offset + limit)) {
148137
return TraversalStatus.FINISH;
149138
}
@@ -156,9 +145,9 @@ public Boolean perform() {
156145
}
157146
}
158147
});
159-
// System.out.println("Graph traversal time: " + String.valueOf(System.currentTimeMillis() - startTime) + "ms");
148+
160149
// Convert the arraylist to a page
161-
return PageUtils.createPage(changesets, PageUtils.newRequest(0, changesets.size()));
150+
return PageUtils.createPage(commits, PageUtils.newRequest(0, commits.size()));
162151
}
163152

164153
protected void render(HttpServletResponse resp, String templateName, Map<String, Object> data) throws IOException, ServletException {

0 commit comments

Comments
 (0)