Skip to content

Commit

Permalink
Merge pull request #6 from Triple-T/chris-master
Browse files Browse the repository at this point in the history
Upload images in listings
  • Loading branch information
bhurling committed Oct 2, 2014
2 parents 21dea2b + ee43025 commit 424c2a2
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 65 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ dependencies {
compile 'commons-lang:commons-lang:2.6'
compile 'commons-io:commons-io:1.4'

testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile 'org.hamcrest:hamcrest-library:1.3'
}

afterEvaluate { project ->
Expand Down
9 changes: 9 additions & 0 deletions src/main/groovy/de/triplet/gradle/play/ImageFileFilter.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.triplet.gradle.play

class ImageFileFilter implements FileFilter {
@Override
boolean accept(File pathname) {
return pathname.name.toLowerCase().endsWith(".png") ||
pathname.name.toLowerCase().endsWith(".jpg")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class PlayPublishApkTask extends PlayPublishTask {
@InputDirectory
File inputFolder

def matcher = ~"^[a-z]{2}(-[A-Z]{2})?\\z"

@TaskAction
publishApk() {
super.publish()
Expand Down
116 changes: 58 additions & 58 deletions src/main/groovy/de/triplet/gradle/play/PlayPublishListingTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ class PlayPublishListingTask extends PlayPublishTask {
def IMAGE_TYPE_SEVEN_INCH_SCREENSHOTS = "sevenInchScreenshots"
def IMAGE_TYPE_TEN_INCH_SCREENSHOTS = "tenInchScreenshots"

def PATH_FOR_FEATURE_GRAPHIC = "featureGraphic/"
def PATH_FOR_ICON = "icon/"
def PATH_FOR_PHONE_SCREESHOTS = "phoneScreenshots/"
def PATH_FOR_PROMO_GRAPHIC = "promoGraphic/"
def PATH_FOR_SEVEN_INCH_SCREENSHOTS = "sevenInchScreenshots/"
def PATH_FOR_TEN_INCH_SCREENSHOTS = "tenInchScreenshots/"

def matcher = ~"^[a-z]{2}(-[A-Z]{2})?\\z"

@InputDirectory
File inputFolder

Expand Down Expand Up @@ -76,63 +67,72 @@ class PlayPublishListingTask extends PlayPublishTask {
editId, locale, listing);
updateListingsRequest.execute();

AndroidPublisher.Edits.Images images = edits.images()
//Only one ContentFile allow for featureGraphic
AbstractInputStreamContent featureGraphicContent = TaskHelper.getAbtractInputStreamContentFile(listingDir, PATH_FOR_FEATURE_GRAPHIC)
if (featureGraphicContent != null) {
images.upload(applicationId, editId, locale, IMAGE_TYPE_FEATURE_GRAPHIC, featureGraphicContent).execute()
}
// By default this value is false , optional you can set this value of true in play extension
def uploadImages = extension.uploadImages

//Only one ContentFile allow for iconGraphic
AbstractInputStreamContent iconGraphicContent = TaskHelper.getAbtractInputStreamContentFile(listingDir, PATH_FOR_ICON)
if (iconGraphicContent != null) {
images.upload(applicationId, editId, locale, IMAGE_TYPE_ICON, iconGraphicContent).execute()
}
if (uploadImages) {
// delete all images from play store entry for each locale
// after that upload the new one

//Only one ContentFile allow for promoGraphic
AbstractInputStreamContent promoGraphicContent = TaskHelper.getAbtractInputStreamContentFile(listingDir, PATH_FOR_PROMO_GRAPHIC)
if (promoGraphicContent != null) {
images.upload(applicationId, editId, locale, IMAGE_TYPE_PROMO_GRAPHIC, promoGraphicContent).execute()
}
//Only one ContentFile allow for featureGraphic
AbstractInputStreamContent featureGraphicContent = TaskHelper.getImageAsStream(listingDir, IMAGE_TYPE_FEATURE_GRAPHIC + "/")
uploadSingleGraphic(featureGraphicContent, locale, IMAGE_TYPE_FEATURE_GRAPHIC)

//Upload phoneScreenshots
List<AbstractInputStreamContent> phoneContentList = TaskHelper.getAbstractInputStreamContentList(listingDir, PATH_FOR_PHONE_SCREESHOTS)
if (phoneContentList != null) {
if (phoneContentList.size() > MAX_SCREESHOTS_SIZE) {
logger.info("Sorry! You could only upload 8 screenshots ")
} else {
phoneContentList.each { phoneContentGraphic ->
images.upload(applicationId, editId, locale, IMAGE_TYPE_PHONE_SCREENSHOTS, phoneContentGraphic).execute()
}
}
}
//Only one ContentFile allow for iconGraphic
AbstractInputStreamContent iconGraphicContent = TaskHelper.getImageAsStream(listingDir, IMAGE_TYPE_ICON + "/")
uploadSingleGraphic(iconGraphicContent, locale, IMAGE_TYPE_ICON)

//Upload sevenInchScreenshots
List<AbstractInputStreamContent> sevenInchContentList = TaskHelper.getAbstractInputStreamContentList(listingDir, PATH_FOR_SEVEN_INCH_SCREENSHOTS)
if (sevenInchContentList != null) {
if (sevenInchContentList.size() > MAX_SCREESHOTS_SIZE) {
logger.info("Sorry! You could only upload 8 screenshots ")
} else {
sevenInchContentList.each { sevenInchContentGraphic ->
images.upload(applicationId, editId, locale, IMAGE_TYPE_SEVEN_INCH_SCREENSHOTS, sevenInchContentGraphic).execute()
}
}
//Only one ContentFile allow for promoGraphic
AbstractInputStreamContent promoGraphicContent = TaskHelper.getImageAsStream(listingDir, IMAGE_TYPE_PROMO_GRAPHIC + "/")
uploadSingleGraphic(promoGraphicContent, locale, IMAGE_TYPE_PROMO_GRAPHIC)

//Upload phoneScreenshots
List<AbstractInputStreamContent> phoneContentList = TaskHelper.getImageListAsStream(listingDir, IMAGE_TYPE_PHONE_SCREENSHOTS + "/")
uploadScreenshots(phoneContentList, locale, IMAGE_TYPE_PHONE_SCREENSHOTS)

//Upload sevenInchScreenshots
List<AbstractInputStreamContent> sevenInchContentList = TaskHelper.getImageListAsStream(listingDir, IMAGE_TYPE_SEVEN_INCH_SCREENSHOTS + "/")
uploadScreenshots(sevenInchContentList, locale, IMAGE_TYPE_SEVEN_INCH_SCREENSHOTS)

//Upload tenInchScreenshots
List<AbstractInputStreamContent> tenInchContentList = TaskHelper.getImageListAsStream(listingDir, IMAGE_TYPE_TEN_INCH_SCREENSHOTS + "/")
uploadScreenshots(tenInchContentList, locale, IMAGE_TYPE_TEN_INCH_SCREENSHOTS)
}
}
}

AndroidPublisher.Edits.Commit commitRequest = edits.commit(applicationId, editId);
commitRequest.execute();
}


def uploadSingleGraphic(AbstractInputStreamContent contentGraphic, String locale, String imageType) {
AndroidPublisher.Edits.Images images = edits.images()


if (contentGraphic != null) {
// delete all images in play store before upload new images
images.deleteall(applicationId, editId, locale, imageType).execute()

images.upload(applicationId, editId, locale, imageType, contentGraphic).execute()
}
}

def uploadScreenshots(List<AbstractInputStreamContent> contentGraphicList, String locale, String imageType) {
AndroidPublisher.Edits.Images images = edits.images()


if (contentGraphicList != null) {
// delete all images in play store before upload new images
images.deleteall(applicationId, editId, locale, imageType).execute()

//Upload tenInchScreenshots
List<AbstractInputStreamContent> tenInchContentList = TaskHelper.getAbstractInputStreamContentList(listingDir, PATH_FOR_TEN_INCH_SCREENSHOTS)
if (tenInchContentList != null) {
if (tenInchContentList.size() > MAX_SCREESHOTS_SIZE) {
logger.info("Sorry! You could only upload 8 screenshots ")
} else {
tenInchContentList.each { tenInchContentGraphic ->
images.upload(applicationId, editId, locale, IMAGE_TYPE_TEN_INCH_SCREENSHOTS, tenInchContentGraphic).execute()
}
}
if (contentGraphicList.size() > MAX_SCREESHOTS_SIZE) {
logger.info("Sorry! You could only upload 8 screenshots ")
} else {
contentGraphicList.each { contentGraphic ->
images.upload(applicationId, editId, locale, imageType, contentGraphic).execute()
}
}
AndroidPublisher.Edits.Commit commitRequest = edits.commit(applicationId, editId);
commitRequest.execute();
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/groovy/de/triplet/gradle/play/PlayPublishTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import org.gradle.api.tasks.Input

class PlayPublishTask extends DefaultTask {

// region '419' is a special case in the play store that represents latin america
def matcher = ~"^[a-z]{2}(-([A-Z]{2}|419))?\\z"

PlayPublisherPluginExtension extension

@Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ class PlayPublisherPluginExtension {

private File pk12File

private boolean uploadImages = false

boolean getUploadImages() {
return uploadImages
}

void setUploadImages(boolean uploadImages) {
this.uploadImages = uploadImages
}


void setServiceAccountEmail(String email) {
serviceAccountEmail = email
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/groovy/de/triplet/gradle/play/TaskHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ class TaskHelper {
return message;
}

def static List<AbstractInputStreamContent> getAbstractInputStreamContentList(File listingDir, String graphicPath) {
def static List<AbstractInputStreamContent> getImageListAsStream(File listingDir, String graphicPath) {
File graphicDir = new File(listingDir, graphicPath)
if (graphicDir.exists()) {
return graphicDir.listFiles().collect { file ->
return graphicDir.listFiles(new ImageFileFilter()).collect { file ->
new FileContent(AndroidPublisherHelper.MIME_TYPE_IMAGE, file);
}
}
return null
}

def static AbstractInputStreamContent getAbtractInputStreamContentFile(File listingDir, String graphicPath) {
def static AbstractInputStreamContent getImageAsStream(File listingDir, String graphicPath) {
File graphicDir = new File(listingDir, graphicPath)
if (graphicDir.exists()) {
File[] files = graphicDir.listFiles()
File[] files = graphicDir.listFiles(new ImageFileFilter())
if (files.length > 0) {
File graphicFile = files[0]
return new FileContent(AndroidPublisherHelper.MIME_TYPE_IMAGE, graphicFile);
Expand Down
25 changes: 25 additions & 0 deletions src/test/groovy/de/triplet/gradle/play/PlayPublishTaskTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import org.junit.Test
import org.mockito.Mock
import org.mockito.MockitoAnnotations

import java.util.regex.Matcher
import java.util.regex.Pattern

import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertTrue
import static org.mockito.Matchers.any
import static org.mockito.Matchers.anyString
import static org.mockito.Mockito.doReturn
Expand Down Expand Up @@ -85,4 +90,24 @@ public class PlayPublishTaskTest {
// verify that we init the connection with the correct application id
verify(editsMock).insert("com.example.publisher.paid", null)
}

@Test
public void testMatcher() {
Project project = TestHelper.evaluatableProject();
project.evaluate()

Pattern pattern = project.tasks.publishApkRelease.matcher

Matcher m = pattern.matcher("de-DE")
assertTrue(m.find())

m = pattern.matcher("de")
assertTrue(m.find())

m = pattern.matcher("es-419")
assertTrue(m.find())

m = pattern.matcher("de_DE")
assertFalse(m.find())
}
}

0 comments on commit 424c2a2

Please sign in to comment.