-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from vierbergenlars/add-appveyor-provider
Add appveyor provider
- Loading branch information
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/be/vbgn/gradle/cidetect/impl/appveyor/AppveyorInformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package be.vbgn.gradle.cidetect.impl.appveyor; | ||
|
||
import be.vbgn.gradle.cidetect.CiInformation; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* https://www.appveyor.com/docs/environment-variables/ | ||
*/ | ||
public class AppveyorInformation implements CiInformation { | ||
|
||
private final Map<String, String> env; | ||
|
||
AppveyorInformation(Map<String, String> env) { | ||
this.env = env; | ||
} | ||
|
||
@Override | ||
public boolean isCi() { | ||
return env.containsKey("APPVEYOR"); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getBuildNumber() { | ||
return env.getOrDefault("APPVEYOR_BUILD_NUMBER", null); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getBranch() { | ||
if (isTag()) { | ||
return null; | ||
} | ||
if (isPullRequest()) { | ||
return env.getOrDefault("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH", null); | ||
} | ||
return env.getOrDefault("APPVEYOR_REPO_BRANCH", null); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getPullRequest() { | ||
return env.getOrDefault("APPVEYOR_PULL_REQUEST_NUMBER", null); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getPullRequestTargetBranch() { | ||
if (isPullRequest()) { | ||
return env.getOrDefault("APPVEYOR_REPO_BRANCH", null); | ||
} | ||
return null; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getTag() { | ||
return env.getOrDefault("APPVEYOR_REPO_TAG_NAME", null); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/be/vbgn/gradle/cidetect/impl/appveyor/AppveyorInformationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package be.vbgn.gradle.cidetect.impl.appveyor; | ||
|
||
import be.vbgn.gradle.cidetect.CiInformation; | ||
import be.vbgn.gradle.cidetect.provider.CiInformationProvider; | ||
import javax.annotation.Nullable; | ||
import org.gradle.api.Project; | ||
|
||
public class AppveyorInformationProvider implements CiInformationProvider { | ||
|
||
@Nullable | ||
@Override | ||
public CiInformation newCiInformation(@Nullable Project project) { | ||
return new AppveyorInformation(System.getenv()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/be/vbgn/gradle/cidetect/impl/appveyor/AppveyorInformationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package be.vbgn.gradle.cidetect.impl.appveyor; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import be.vbgn.gradle.cidetect.CiInformation; | ||
import be.vbgn.gradle.cidetect.impl.AbstractCiInformationTest; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.Test; | ||
|
||
public class AppveyorInformationTest extends AbstractCiInformationTest { | ||
|
||
@Override | ||
protected Map<String, String> getBaseEnv(String buildNumber) { | ||
Map<String, String> env = new HashMap<>(); | ||
env.put("APPVEYOR", "True"); | ||
env.put("APPVEYOR_BUILD_NUMBER", buildNumber); | ||
return env; | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getBranchBuildEnv(String branch) { | ||
return Collections.singletonMap("APPVEYOR_REPO_BRANCH", branch); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getPullRequestBuildEnv(String sourceBranch, String targetBranch, String prNumber) { | ||
Map<String, String> environment = new HashMap<>(); | ||
environment.put("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH", sourceBranch); | ||
environment.put("APPVEYOR_REPO_BRANCH", targetBranch); | ||
environment.put("APPVEYOR_PULL_REQUEST_NUMBER", prNumber); | ||
return environment; | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getTagBuildEnv(String tagName) { | ||
Map<String, String> environment = new HashMap<>(); | ||
environment.put("APPVEYOR_REPO_BRANCH", "some-branch-name"); | ||
environment.put("APPVEYOR_REPO_TAG_NAME", tagName); | ||
environment.put("APPVEYOR_REPO_TAG", "true"); | ||
return environment; | ||
} | ||
|
||
@Override | ||
protected CiInformation createCiInformation(Map<String, String> env) { | ||
return new AppveyorInformation(env); | ||
} | ||
|
||
@Test | ||
public void testPlatform() { | ||
assertEquals("Appveyor", new AppveyorInformation(getBaseEnv("12")).getPlatform()); | ||
} | ||
} |