Jens Schumacher avatar Jens Schumacher committed fa3369e

Working version of the Publishing plugin.

Comments (0)

Files changed (3)

src/main/java/pacrelease/ExampleTask.java

 import com.atlassian.bamboo.task.TaskResult;
 import com.atlassian.bamboo.task.TaskResultBuilder;
 import com.atlassian.bamboo.task.TaskType;
-import com.atlassian.plugins.client.service.plugin.ContributorServiceClientImpl;
-import com.atlassian.plugins.client.service.plugin.PluginServiceClientImpl;
-import com.atlassian.plugins.client.service.plugin.PluginVersionServiceClientImpl;
+import com.atlassian.plugins.client.service.AbstractRestServiceClient;
+import com.atlassian.plugins.client.service.category.CategoryServiceClientImpl;
+import com.atlassian.plugins.client.service.plugin.*;
 import com.atlassian.plugins.client.service.product.ProductCompatibilityServiceClientImpl;
 import com.atlassian.plugins.domain.model.category.Category;
 import com.atlassian.plugins.domain.model.product.ProductCompatibility;
     private PluginVersionServiceClientImpl pluginVersionService;
     private ProductCompatibilityServiceClientImpl productCompatibilityService;
     private ContributorServiceClientImpl contributorService;
+    private RequirementServiceClientImpl requirementService;
+    private ScreenshotServiceClientImpl screenshotService;
+    private CategoryServiceClientImpl categoryService;
+    private String username;
+    private String password;
+    private String pluginId;
+    private String version;
+    private String summary;
+    private String binaryURL;
 
 
     @NotNull
     @java.lang.Override
     public TaskResult execute(@NotNull final TaskContext taskContext) throws TaskException
     {
-        String username = taskContext.getConfigurationMap().get("username");
-        String password = taskContext.getConfigurationMap().get("password");
-        String pluginId = taskContext.getConfigurationMap().get("pluginid");
-        String version = taskContext.getConfigurationMap().get("version");
-        String summary = taskContext.getConfigurationMap().get("releasenote");
-        String binaryURL = taskContext.getConfigurationMap().get("binary");
+        username = taskContext.getConfigurationMap().get("username");
+        password = taskContext.getConfigurationMap().get("password");
+        pluginId = taskContext.getConfigurationMap().get("pluginid");
+        version = taskContext.getConfigurationMap().get("version");
+        summary = taskContext.getConfigurationMap().get("releasenote");
+        binaryURL = taskContext.getConfigurationMap().get("binary");
 
         final BuildLogger buildLogger = taskContext.getBuildLogger();
 
-
         // Init Plugin Service
         pluginService = new PluginServiceClientImpl();
-        pluginService.setBaseUrl("https://plugins.atlassian.com/server");
-        pluginService.setUsername(username);
-        pluginService.setPassword(password);
-       
+        initialiseService(pluginService);
 
         // Init Plugin Version Service
         pluginVersionService = new PluginVersionServiceClientImpl();
-        pluginVersionService.setBaseUrl("https://plugins.atlassian.com/server");
-        pluginVersionService.setUsername(username);
-        pluginVersionService.setPassword(password);
+        initialiseService(pluginVersionService);
 
         productCompatibilityService = new ProductCompatibilityServiceClientImpl();
-        productCompatibilityService.setBaseUrl("https://plugins.atlassian.com/server");
-        productCompatibilityService.setUsername(username);
-        productCompatibilityService.setPassword(password);
+        initialiseService(productCompatibilityService);
 
         contributorService = new ContributorServiceClientImpl();
-        contributorService.setBaseUrl("https://plugins.atlassian.com/server");
-        contributorService.setUsername(username);
-        contributorService.setPassword(password);
+        initialiseService(contributorService);
+
+        requirementService = new RequirementServiceClientImpl();
+        initialiseService(requirementService);
+
+        screenshotService = new ScreenshotServiceClientImpl();
+        initialiseService(screenshotService);
+
+        categoryService = new CategoryServiceClientImpl();
+        initialiseService(categoryService);
 
         // Retrieve Plugin
-        String pluginInfo = "latestVersion.plugin,latestVersion.contributors.contributor.user,latestVersion.productCompatibilities.productCompatibility.*,latestVersion.requirements.requirement,latestVersion.screenshots,latestVersion.buildNumber";
+        String pluginInfo = "latestVersion.plugin,latestVersion.contributors.contributor.user,latestVersion.productCompatibilities.productCompatibility.*,latestVersion.requirements.requirement,latestVersion.screenshots,latestVersion.buildNumber, latestVersion.categories.category";
         String[] infoArray = pluginInfo.split(",");
         Plugin plugin = pluginService.retrieve(pluginId, new ArrayList(Arrays.asList(infoArray)));
-        PluginVersion newPluginVersion = createPluginVersion(plugin, summary, binaryURL, version);
-
+        PluginVersion newPluginVersion = createPluginVersion(plugin);
 
         // Add log entry
         buildLogger.addBuildLogEntry("------ Plugin Release --------");
         buildLogger.addBuildLogEntry("Plugin ID:".concat(plugin.getId()));
-
         buildLogger.addBuildLogEntry("Binary: ".concat(binaryURL));
 
         return TaskResultBuilder.create(taskContext).success().build();
     }
 
 
-    private PluginVersion createPluginVersion(Plugin plugin, String summary, String binaryURL, String version)
+    private PluginVersion createPluginVersion(Plugin plugin)
     {
 
         PluginVersion latestVersion = plugin.getLatestVersion();
+
+        // increase Build number by 1
         Long newBuildNumber = latestVersion.getBuildNumber() + 1;
 
         ListWrapper<ProductCompatibility> existingCapabilities = latestVersion.getProductCompatibilities();
         ListWrapper<Contributor> existingContributors = latestVersion.getContributors();
+        ListWrapper<Requirement> existingRequirements = latestVersion.getRequirements();
+     //   ListWrapper<Screenshot> existingScreenshots = latestVersion.getScreenshots();
+//        ListWrapper<Category> existingCategories = latestVersion.getCategories();
 
         latestVersion.setId(null);
         latestVersion.setContributors(new ListWrapper<Contributor>());
         latestVersion.setProductCompatibilities(new ListWrapper<ProductCompatibility>());
-        latestVersion.  (new ListWrapper<Category>());
+//        latestVersion.setCategories(new ListWrapper<Category>());
         latestVersion.setRequirements(new ListWrapper<Requirement>());
-        latestVersion.setScreenshots(new ListWrapper<Screenshot>());
+       // latestVersion.setScreenshots(new ListWrapper<Screenshot>());
         latestVersion.setBuildNumber(newBuildNumber);
         latestVersion.setReleaseSummary(summary);
         latestVersion.setVersion(version);
             contributorService.create(contributor);
         }
 
+        for (Requirement requirement : existingRequirements) {
+            requirement.setId(null);
+            requirement.setPluginVersion(pv);
+            requirementService.create(requirement);
+        }
+
+//        for (Screenshot screenshot : existingScreenshots) {
+//            latestVersion.
+//            screenshot.setPlu
+//            screenshotService.create(screenshot);
+//        }
+
+//        for (Category category : existingCategories) {
+//            category.setId(null);
+//            category.set
+//            categoryService.create(category);
+//        }
 
         return latestVersion;
     }
+
+    private void initialiseService(AbstractRestServiceClient pluginService)
+    {
+       pluginService.setBaseUrl("https://plugins.atlassian.com/server");
+       pluginService.setUsername(username);
+       pluginService.setPassword(password);
+    }
 }

src/main/java/pacrelease/ExampleTaskConfigurator.java

 public class ExampleTaskConfigurator extends AbstractTaskConfigurator
 {
     private TextProvider textProvider;
+    private String password_placeholder = "*******";
 
     @NotNull
     @Override
     {
         final Map<String, String> config = super.generateTaskConfigMap(params, previousTaskDefinition);
         config.put("username", params.getString("username"));
-        config.put("password", params.getString("password"));
         config.put("releasenote", params.getString("releasenote"));
         config.put("version", params.getString("version"));
         config.put("pluginid", params.getString("pluginid"));
         config.put("binary", params.getString("binary"));
+
+        String password = params.getString("password");
+
+        if (!password.equalsIgnoreCase(password_placeholder) && !StringUtils.isEmpty(password))
+            config.put("password", password);
+        else
+            config.put("password", previousTaskDefinition.getConfiguration().get("password"));
+
         return config;
     }
 
     public void populateContextForCreate(@NotNull final Map<String, Object> context)
     {
         super.populateContextForCreate(context);
-
-        context.put("say", "Hello, World!");
     }
 
     @Override
     public void populateContextForEdit(@NotNull final Map<String, Object> context, @NotNull final TaskDefinition taskDefinition)
     {
         super.populateContextForEdit(context, taskDefinition);
-
         context.put("username", taskDefinition.getConfiguration().get("username"));
-        context.put("password", taskDefinition.getConfiguration().get("password"));
+        context.put("password", password_placeholder);
         context.put("releasenote", taskDefinition.getConfiguration().get("releasenote"));
         context.put("version", taskDefinition.getConfiguration().get("version"));
         context.put("pluginid", taskDefinition.getConfiguration().get("pluginid"));
     {
         super.populateContextForView(context, taskDefinition);
         context.put("username", taskDefinition.getConfiguration().get("username"));
-        context.put("password", taskDefinition.getConfiguration().get("password"));
         context.put("releasenote", taskDefinition.getConfiguration().get("releasenote"));
-        context.put("version", taskDefinition.getConfiguration().get("version"));
         context.put("pluginid", taskDefinition.getConfiguration().get("pluginid"));
         context.put("binary", taskDefinition.getConfiguration().get("binary"));
     }

src/main/resources/editExampleTask.ftl

 [@ww.textfield labelKey="pacrelease.username" name="username" required='true'/]
-[@ww.password labelKey="pacrelease.password" name="password" required='true'/]
+[@ww.password labelKey="pacrelease.password" name="password" required='true' showPassword='true'/]
 [@ww.textfield labelKey="pacrelease.pluginid" name="pluginid" required='true'/]
 [@ww.textfield labelKey="pacrelease.version" name="version" required='true'/]
 [@ww.textfield labelKey="pacrelease.releasenote" name="releasenote" required='true'/]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.