Joe Clark avatar Joe Clark committed 6f58be7

Resolve Issue #13 - don't require a saved task config to be re-saved when upgrading to Bamboo 5.

Comments (0)

Files changed (2)

src/main/java/com/atlassian/bamboo/plugins/confdeploy/AutoDeployTask.java

 
 
         // Retrieve the referenced artifact definition
-        final AvailableArtifact artifactDesc = new AvailableArtifact(taskContext.getConfigurationMap().get(PLUGIN_ARTIFACT));
+        AvailableArtifact artifactDesc = null;
+
+        // May need to update the stored artifact definition to a newer format.
+        String persistedArtifactName = taskContext.getConfigurationMap().get(AutoDeployTask.PLUGIN_ARTIFACT);
+        if (!StringUtils.startsWith(persistedArtifactName, "v2:"))
+        {
+            final TaskContext buildTaskContext = Narrow.downTo(taskContext, TaskContext.class);
+            final ArtifactContext artifactContext = buildTaskContext.getBuildContext().getArtifactContext();
+            for (ArtifactSubscriptionContext artifactSubscriptionContext : artifactContext.getSubscriptionContexts())
+            {
+                final ArtifactDefinitionContext artifactDefinitionContext = artifactSubscriptionContext.getArtifactDefinitionContext();
+                if (artifactDefinitionContext.getName().equals(persistedArtifactName))
+                {
+                    artifactDesc = AvailableArtifact.from(artifactSubscriptionContext);
+                    break;
+                }
+            }
+        }
+        else
+        {
+            artifactDesc = new AvailableArtifact(persistedArtifactName);
+        }
 
         // Ensure that the artifact exists and is accessible.
         File pluginJar = null;

src/main/java/com/atlassian/bamboo/plugins/confdeploy/AvailableArtifact.java

 package com.atlassian.bamboo.plugins.confdeploy;
 
+import com.atlassian.bamboo.plan.artifact.ArtifactSubscriptionContext;
 import org.jetbrains.annotations.Nullable;
 
 import com.atlassian.bamboo.plan.artifact.ImmutableArtifactDefinition;
         this.name = name;
     }
 
+    public static AvailableArtifact from(ArtifactSubscriptionContext artifactSubscriptionContext)
+    {
+        return new AvailableArtifact(artifactSubscriptionContext.getArtifactDefinitionContext().getId(), null, null,
+                artifactSubscriptionContext.getArtifactDefinitionContext().getName());
+    }
+
     public static AvailableArtifact from(ImmutableArtifactSubscription artifactSubscription) {
         return new AvailableArtifact(artifactSubscription.getArtifactDefinition().getId(), null, null,
                 artifactSubscription.getName());
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.