Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Remove dependencies on FishEye -- use the official FishEye API and SAL... #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,6 @@
<version>${fecru.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.fisheye</groupId>
<artifactId>fisheye-jar</artifactId>
<version>${fecru.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.atlassian.fisheye</groupId>
<artifactId>atlassian-fisheye-dependencies</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -179,13 +167,13 @@
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-webresource</artifactId>
<version>${plugins.version}</version>
<version>${webresource.plugins.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-webfragment</artifactId>
<version>${plugins.version}</version>
<version>${webfragment.plugins.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -311,6 +299,7 @@
com.atlassian.plugins.rest.common.security,
com.atlassian.sal.api.*;version="(2.4,3.0]",
org.apache.commons.lang.*;version="2.4",
com.atlassian.fisheye.spi.services,
com.atlassian.jira.config;resolution:=optional,
*;resolution:=optional
</Import-Package>
Expand Down Expand Up @@ -531,7 +520,9 @@
<bamboo.version>3.1-m2</bamboo.version>
<bamboo.data.version>2.6.1</bamboo.data.version>
<webdriver.browser>firefox-3.6</webdriver.browser>
<plugins.version>2.13.4</plugins.version>
<plugins.version>3.0.8</plugins.version>
<webresource.plugins.version>3.0.2</webresource.plugins.version>
<webfragment.plugins.version>3.0.0</webfragment.plugins.version>
<sal.version>2.5.0</sal.version>
<rest.version>2.5.0</rest.version>
<templaterenderer.version>1.1.1</templaterenderer.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.atlassian.plugin.web.descriptors.WebItemModuleDescriptor;
import com.atlassian.plugin.webresource.UrlMode;
import com.atlassian.plugin.webresource.WebResourceManager;
import com.atlassian.plugin.webresource.WebResourceUrlProvider;

import org.dom4j.Element;
import org.osgi.framework.BundleContext;

Expand All @@ -31,13 +33,20 @@ public class SpeakeasyWebItemModuleDescriptor extends AbstractModuleDescriptor<V
private final DescriptorGeneratorManager descriptorGeneratorManager;
private WebInterfaceManager webInterfaceManager;
private final WebResourceManager webResourceManager;

public SpeakeasyWebItemModuleDescriptor(ModuleFactory moduleFactory, BundleContext bundleContext, DescriptorGeneratorManager descriptorGeneratorManager, WebResourceManager webResourceManager)
private final WebResourceUrlProvider webResourceUrlProvider;

public SpeakeasyWebItemModuleDescriptor(
ModuleFactory moduleFactory,
BundleContext bundleContext,
DescriptorGeneratorManager descriptorGeneratorManager,
WebResourceManager webResourceManager,
WebResourceUrlProvider webResourceUrlProvider)
{
super(moduleFactory);
this.bundleContext = bundleContext;
this.descriptorGeneratorManager = descriptorGeneratorManager;
this.webResourceManager = webResourceManager;
this.webResourceUrlProvider = webResourceUrlProvider;
}

@Override
Expand Down Expand Up @@ -128,7 +137,7 @@ private void resolveLinkPaths(long stateKey, Element element)

private String getImageUrl(String pluginKey, long stateKey, String fileName)
{
String fullUrl = webResourceManager.getStaticResourcePrefix(UrlMode.AUTO) + "/download/resources/" + pluginKey + ":images-" + stateKey + "/" + fileName;
String fullUrl = webResourceUrlProvider.getStaticResourcePrefix(UrlMode.AUTO) + "/download/resources/" + pluginKey + ":images-" + stateKey + "/" + fileName;
if (!fullUrl.startsWith("/s"))
{
fullUrl = fullUrl.substring(fullUrl.indexOf("/s"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.atlassian.plugin.osgi.util.OsgiHeaderUtil;
import com.atlassian.plugin.webresource.WebResourceManager;
import com.atlassian.plugin.webresource.WebResourceModuleDescriptor;
import com.atlassian.plugin.webresource.WebResourceUrlProvider;

import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.osgi.framework.Bundle;
Expand All @@ -38,11 +40,23 @@ public class ConventionDescriptorGeneratorServiceFactory implements ServiceFacto
private final JsonToElementParser jsonToElementParser;
private final WebResourceManager webResourceManager;
private final JsonManifestHandler jsonManifestHandler;
private final WebResourceUrlProvider webResourceUrlProvider;
private final PluginController pluginController;

//private final Set<String> trackedPlugins = new CopyOnWriteArraySet<String>();

public ConventionDescriptorGeneratorServiceFactory(final ModuleFactory moduleFactory, final BundleContext bundleContext, final PluginAccessor pluginAccessor, HostContainer hostContainer, DescriptorGeneratorManagerImpl descriptorGeneratorManager, JsonToElementParser jsonToElementParser, WebResourceManager webResourceManager, PluginEventManager pluginEventManager, final PluginController pluginController, JsonManifestHandler jsonManifestHandler)
public ConventionDescriptorGeneratorServiceFactory(
final ModuleFactory moduleFactory,
final BundleContext bundleContext,
final PluginAccessor pluginAccessor,
HostContainer hostContainer,
DescriptorGeneratorManagerImpl descriptorGeneratorManager,
JsonToElementParser jsonToElementParser,
WebResourceManager webResourceManager,
PluginEventManager pluginEventManager,
final PluginController pluginController,
JsonManifestHandler jsonManifestHandler,
WebResourceUrlProvider webResourceUrlProvider)
{
this.moduleFactory = moduleFactory;
this.bundleContext = bundleContext;
Expand All @@ -54,6 +68,7 @@ public ConventionDescriptorGeneratorServiceFactory(final ModuleFactory moduleFac
this.webResourceManager = webResourceManager;
this.pluginController = pluginController;
this.jsonManifestHandler = jsonManifestHandler;
this.webResourceUrlProvider = webResourceUrlProvider;
}

public Object getService(Bundle bundle, ServiceRegistration registration)
Expand Down Expand Up @@ -117,7 +132,7 @@ private void registerSpeakeasyWebItems(Bundle bundle, Plugin plugin)
{
for (Element element : jsonToElementParser.createWebItems(plugin.getResourceAsStream("ui/web-items.json")))
{
SpeakeasyWebItemModuleDescriptor descriptor = new SpeakeasyWebItemModuleDescriptor(moduleFactory, bundleContext, descriptorGeneratorManager, webResourceManager);
SpeakeasyWebItemModuleDescriptor descriptor = new SpeakeasyWebItemModuleDescriptor(moduleFactory, bundleContext, descriptorGeneratorManager, webResourceManager, webResourceUrlProvider);
descriptor.init(plugin, element);
bundle.getBundleContext().registerService(ModuleDescriptor.class.getName(), descriptor, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.atlassian.labs.speakeasy.model;

import com.cenqua.fisheye.config1.Admins;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

import javax.xml.bind.annotation.*;
import java.util.Arrays;
import java.util.Set;

import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Sets.newHashSet;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.atlassian.labs.speakeasy.product;

import com.atlassian.fecru.user.User;
import com.atlassian.fisheye.spi.data.MailMessageData;
import com.atlassian.labs.speakeasy.util.PomProperties;
import com.atlassian.sal.api.user.UserProfile;
import com.atlassian.templaterenderer.TemplateRenderer;
import com.cenqua.fisheye.mail.Mailer;
import com.cenqua.fisheye.user.UserManager;
import com.atlassian.fisheye.spi.services.MailService;
import com.atlassian.sal.api.user.UserManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -20,10 +21,10 @@ public class FecruProductAccessor implements ProductAccessor {
private final PomProperties pomProperties;
private final UserManager userManager;
private final TemplateRenderer templateRenderer;
private final Mailer mailer;
private final MailService mailer;

public FecruProductAccessor(PomProperties pomProperties, TemplateRenderer templateRenderer, UserManager userManager,
Mailer mailer) {
MailService mailer) {
this.pomProperties = pomProperties;
this.templateRenderer = templateRenderer;

Expand All @@ -36,13 +37,11 @@ public String getSdkName() {
return "fecru";
}

public String getProfilePath()
{
public String getProfilePath() {
return "/plugins/servlet/speakeasy/user";
}

public String getTargetUsernameFromCondition(Map<String, Object> context)
{
public String getTargetUsernameFromCondition(Map<String, Object> context) {
return null;
}

Expand All @@ -57,17 +56,16 @@ public String getDataVersion() {
public void sendEmail(EmailOptions options) {
String toName = options.getToName();
String toEmail = options.getToEmail();
if (options.getToUsername() != null)
{
final User user = getUser(options.getToUsername());
if (options.getToUsername() != null) {
final UserProfile user = getUser(options.getToUsername());
if (user == null) {
return;
}
if (user.getEmail() == null) {
log.warn("No email found for username: " + options.getToUsername());
return;
}
toName = user.getDisplayName();
toName = user.getFullName();
toEmail = user.getEmail();
}

Expand All @@ -79,8 +77,7 @@ public void sendEmail(EmailOptions options) {
message.setFromDisplayName(options.getFromName());

message.addRecipient(toEmail);
if (options.getReplyToEmail() != null)
{
if (options.getReplyToEmail() != null) {
// todo: api doesn't seem to support this?
}

Expand All @@ -93,19 +90,18 @@ public void sendEmail(EmailOptions options) {
}
}

private String render(String templateName, Map<String,Object> context) throws IOException {
private String render(String templateName, Map<String, Object> context) throws IOException {
StringWriter writer = new StringWriter();
templateRenderer.render(templateName, context, writer);
return writer.toString();
}

private User getUser(String username) {
try {
return userManager.getUser(username);
} catch (Exception e) {
log.warn("Could not find user by username: " + username, e);
return null;
private UserProfile getUser(String username) {
UserProfile profile = userManager.getUserProfile(username);
if (profile == null) {
log.warn("Could not find user by username: " + username);
}
return profile;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.atlassian.labs.speakeasy.model.Settings;
import com.atlassian.plugin.webresource.UrlMode;
import com.atlassian.plugin.webresource.WebResourceManager;
import com.atlassian.plugin.webresource.WebResourceUrlProvider;
import com.atlassian.plugins.rest.common.json.JaxbJsonMarshaller;
import com.atlassian.sal.api.user.UserManager;
import com.atlassian.templaterenderer.TemplateRenderer;
Expand All @@ -32,14 +33,22 @@ public class AdminServlet extends HttpServlet
private final UserManager userManager;
private final WebResourceManager webResourceManager;
private final JaxbJsonMarshaller jsonMarshaller;
private final WebResourceUrlProvider webResourceUrlProvider;

public AdminServlet(SpeakeasyService speakeasyService, UserManager userManager, TemplateRenderer templateRenderer, WebResourceManager webResourceManager, JaxbJsonMarshaller jsonMarshaller)
public AdminServlet(
SpeakeasyService speakeasyService,
UserManager userManager,
TemplateRenderer templateRenderer,
WebResourceManager webResourceManager,
JaxbJsonMarshaller jsonMarshaller,
WebResourceUrlProvider webResourceUrlProvider)
{
this.speakeasyService = speakeasyService;
this.userManager = userManager;
this.templateRenderer = templateRenderer;
this.webResourceManager = webResourceManager;
this.jsonMarshaller = jsonMarshaller;
this.webResourceUrlProvider = webResourceUrlProvider;
}

@Override
Expand All @@ -62,7 +71,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
render("templates/admin.vm", ImmutableMap.<String,Object>builder().
put("user", user).
put("contextPath", req.getContextPath()).
put("staticResourcesPrefix", webResourceManager.getStaticResourcePrefix(UrlMode.RELATIVE)).
put("staticResourcesPrefix", webResourceUrlProvider.getStaticResourcePrefix(UrlMode.RELATIVE)).
put("settings", new JsRenderer(jsonMarshaller.marshal(settings))).
put("permissionsJson", new JsRenderer(jsonMarshaller.marshal(Permission.ALL))).
put("permissions", Permission.ALL).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.atlassian.plugin.elements.ResourceLocation;
import com.atlassian.plugin.servlet.DownloadableResource;
import com.atlassian.plugin.webresource.UrlMode;
import com.atlassian.plugin.webresource.WebResourceManager;
import com.atlassian.plugin.webresource.transformer.AbstractStringTransformedDownloadableResource;
import com.atlassian.plugin.webresource.WebResourceUrlProvider;
import com.atlassian.plugin.webresource.transformer.CharSequenceDownloadableResource;
import com.atlassian.plugin.webresource.transformer.WebResourceTransformer;
import com.atlassian.sal.api.xsrf.XsrfTokenAccessor;
import com.atlassian.sal.api.xsrf.XsrfTokenValidator;
Expand All @@ -16,23 +16,26 @@
*/
public class CssVariableTransformer implements WebResourceTransformer
{
private final WebResourceManager webResourceManager;
private final XsrfTokenAccessor xsrfTokenAccessor;
private final XsrfTokenValidator xsrfTokenValidator;
private final WebResourceUrlProvider webResourceUrlProvider;

public CssVariableTransformer(WebResourceManager webResourceManager, XsrfTokenAccessor xsrfTokenAccessor, XsrfTokenValidator xsrfTokenValidator)
public CssVariableTransformer(
XsrfTokenAccessor xsrfTokenAccessor,
XsrfTokenValidator xsrfTokenValidator,
WebResourceUrlProvider webResourceUrlProvider)
{
this.webResourceManager = webResourceManager;
this.xsrfTokenAccessor = xsrfTokenAccessor;
this.xsrfTokenValidator = xsrfTokenValidator;
this.webResourceUrlProvider = webResourceUrlProvider;
}

public DownloadableResource transform(Element configElement, ResourceLocation location, String filePath, DownloadableResource nextResource)
{
return new CssVariableDownloadableResource(nextResource, configElement);
}

private class CssVariableDownloadableResource extends AbstractStringTransformedDownloadableResource
private class CssVariableDownloadableResource extends CharSequenceDownloadableResource
{
private final Element configElement;

Expand All @@ -43,18 +46,19 @@ public CssVariableDownloadableResource(DownloadableResource originalResource, El
}

@Override
protected String transform(String originalContent)
protected CharSequence transform(CharSequence originalSequence)
{
String content = originalContent.replace("@staticResourcePrefix", webResourceManager.getStaticResourcePrefix(UrlMode.RELATIVE) + "/download/resources");
String originalContent = originalSequence.toString();
String content = originalContent.replace("@staticResourcePrefix", webResourceUrlProvider.getStaticResourcePrefix(UrlMode.RELATIVE) + "/download/resources");
String fullModuleKey = configElement.attributeValue("fullModuleKey");
if (fullModuleKey != null)
{
content = content.replace("@modulePrefix", webResourceManager.getStaticResourcePrefix(UrlMode.RELATIVE) + "/download/resources/" + fullModuleKey);
content = content.replace("@modulePrefix", webResourceUrlProvider.getStaticResourcePrefix(UrlMode.RELATIVE) + "/download/resources/" + fullModuleKey);
}
String imagesModuleKey = configElement.attributeValue("imagesModuleKey");
if (imagesModuleKey != null)
{
content = content.replace("@imagesPrefix", webResourceManager.getStaticResourcePrefix(UrlMode.RELATIVE) + "/download/resources/" + imagesModuleKey);
content = content.replace("@imagesPrefix", webResourceUrlProvider.getStaticResourcePrefix(UrlMode.RELATIVE) + "/download/resources/" + imagesModuleKey);
}
return content;
}
Expand Down
Loading