-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b71950e
commit e344eed
Showing
12 changed files
with
229 additions
and
11 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
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
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
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
74 changes: 74 additions & 0 deletions
74
gradle-baseline-java/src/main/groovy/com/palantir/baseline/plugins/BaselineCircleCi.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,74 @@ | ||
/* | ||
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.plugins; | ||
|
||
import com.palantir.gradle.circlestyle.CircleStylePlugin; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.attribute.FileAttribute; | ||
import java.nio.file.attribute.PosixFilePermission; | ||
import java.nio.file.attribute.PosixFilePermissions; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Set; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.tasks.testing.Test; | ||
import org.gradle.profile.ProfileListener; | ||
import org.gradle.profile.ProfileReportRenderer; | ||
|
||
public final class BaselineCircleCi extends AbstractBaselinePlugin { | ||
private static final SimpleDateFormat FILE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); | ||
private static final FileAttribute<Set<PosixFilePermission>> PERMS_ATTRIBUTE = | ||
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-xr-x")); | ||
|
||
@Override | ||
public void apply(Project project) { | ||
project.getPluginManager().apply(CircleStylePlugin.class); | ||
String circleArtifactsDir = System.getenv("CIRCLE_ARTIFACTS"); | ||
if (circleArtifactsDir == null) { | ||
return; | ||
} | ||
|
||
try { | ||
Files.createDirectories(Paths.get(circleArtifactsDir), PERMS_ATTRIBUTE); | ||
} catch (IOException e) { | ||
throw new RuntimeException("failed to create CIRCLE_ARTIFACTS directory", e); | ||
} | ||
|
||
project.getRootProject().allprojects(proj -> | ||
proj.getTasks().withType(Test.class, test -> { | ||
Path junitReportsDir = Paths.get(circleArtifactsDir, "junit"); | ||
for (String component : test.getPath().substring(1).split(":")) { | ||
junitReportsDir = junitReportsDir.resolve(component); | ||
} | ||
test.getReports().getHtml().setEnabled(true); | ||
test.getReports().getHtml().setDestination(junitReportsDir.toFile()); | ||
})); | ||
|
||
if (project.getGradle().getStartParameter().isProfile()) { | ||
project.getGradle().addListener((ProfileListener) buildProfile -> { | ||
ProfileReportRenderer renderer = new ProfileReportRenderer(); | ||
File file = Paths.get(circleArtifactsDir, "profile", "profile-" | ||
+ FILE_DATE_FORMAT.format(new Date(buildProfile.getBuildStarted())) + ".html").toFile(); | ||
renderer.writeTo(buildProfile, file); | ||
}); | ||
} | ||
} | ||
} |
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
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
1 change: 1 addition & 0 deletions
1
...java/src/main/resources/META-INF/gradle-plugins/com.palantir.baseline-circleci.properties
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 @@ | ||
implementation-class=com.palantir.baseline.plugins.BaselineCircleCi |
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
83 changes: 83 additions & 0 deletions
83
...aseline-java/src/test/groovy/com/palantir/baseline/BaselineCircleCiIntegrationTest.groovy
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,83 @@ | ||
/* | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline | ||
|
||
|
||
import org.gradle.testkit.runner.BuildResult | ||
import org.gradle.testkit.runner.TaskOutcome | ||
|
||
class BaselineCircleCiIntegrationTest extends AbstractPluginTest { | ||
def standardBuildFile = ''' | ||
plugins { | ||
id 'java' | ||
id 'com.palantir.baseline-circleci' | ||
} | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
testCompile 'junit:junit:4.12' | ||
} | ||
'''.stripIndent() | ||
|
||
def javaFile = ''' | ||
package test; | ||
import org.junit.Test; | ||
public class TestClass { | ||
@Test | ||
public void test() {} | ||
} | ||
'''.stripIndent() | ||
|
||
def setup() { | ||
new File(System.getenv('CIRCLE_ARTIFACTS')).toPath().deleteDir() | ||
} | ||
|
||
def 'collects html reports'() { | ||
when: | ||
buildFile << standardBuildFile | ||
file('src/test/java/test/TestClass.java') << javaFile | ||
|
||
String artifacts = System.getenv('CIRCLE_ARTIFACTS') | ||
then: | ||
BuildResult result = with('test').build() | ||
result.task(':test').outcome == TaskOutcome.SUCCESS | ||
new File(new File(artifacts, 'junit'), 'test').list().toList().toSet() == ['classes', 'css', 'index.html', 'js', 'packages'].toSet() | ||
} | ||
|
||
def 'collects build profiles'() { | ||
when: | ||
buildFile << standardBuildFile | ||
|
||
String artifacts = System.getenv('CIRCLE_ARTIFACTS') | ||
Set<String> defaultDirs = ['js', 'css'].toSet() | ||
then: | ||
BuildResult result = with('build', '--profile').build() | ||
result.task(':build').outcome == TaskOutcome.SUCCESS | ||
Set<String> files = new File(artifacts, 'profile').list().toList().toSet() | ||
files.size() == 3 | ||
files.containsAll(defaultDirs) | ||
files.removeAll(defaultDirs) | ||
String profileFile = files.iterator().next() | ||
profileFile.startsWith("profile-") | ||
profileFile.endsWith(".html") | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
gradle-baseline-java/src/test/groovy/com/palantir/baseline/BaselineCircleCiTest.groovy
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,45 @@ | ||
/* | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline | ||
|
||
|
||
import com.palantir.baseline.plugins.BaselineCircleCi | ||
import com.palantir.gradle.circlestyle.CircleStylePlugin | ||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import spock.lang.Specification | ||
|
||
class BaselineCircleCiTest extends Specification { | ||
private Project project | ||
|
||
def setup() { | ||
project = ProjectBuilder.builder().build() | ||
project.plugins.apply 'java' | ||
project.plugins.apply BaselineCircleCi | ||
} | ||
|
||
def baselineCircleCiApplied() { | ||
expect: | ||
project.plugins.hasPlugin(BaselineCircleCi.class) | ||
} | ||
|
||
def circleStylePluginApplied() { | ||
expect: | ||
project.plugins.hasPlugin(CircleStylePlugin.class) | ||
} | ||
|
||
} |
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