use of com.thomasjensen.checkstyle.addons.build.ClasspathBuilder in project checkstyle-addons by checkstyle-addons.
the class GeneratePomConfigAction method buildDependencies4Pom.
private void buildDependencies4Pom(@Nonnull final Node pParentNode, @Nonnull final DependencyConfig pDepConfig) {
final Configuration cfg = new ClasspathBuilder(project).buildMainRuntimeConfiguration(pDepConfig);
for (Dependency d : cfg.getAllDependencies()) {
if (!(d instanceof ExternalDependency)) {
throw new GradleException("Incompatible dependency: " + d);
}
final ExternalDependency jar = (ExternalDependency) d;
final Iterator<DependencyArtifact> artifactIterator = jar.getArtifacts().iterator();
final DependencyArtifact artifcat = artifactIterator.hasNext() ? artifactIterator.next() : null;
final String depClassifier = artifcat != null ? artifcat.getClassifier() : null;
final Node n = pParentNode.appendNode("dependency");
n.appendNode(BuildUtil.GROUP_ID, jar.getGroup());
n.appendNode(BuildUtil.ARTIFACT_ID, jar.getName());
n.appendNode(BuildUtil.VERSION, jar.getVersion());
if (depClassifier != null) {
n.appendNode("classifier", depClassifier);
}
n.appendNode("scope", "compile");
}
}
use of com.thomasjensen.checkstyle.addons.build.ClasspathBuilder in project checkstyle-addons by checkstyle-addons.
the class JarConfigAction method configureTaskFor.
@Override
protected void configureTaskFor(@Nonnull Jar pJarTask, @Nullable DependencyConfig pDepConfig) {
Objects.requireNonNull(pDepConfig, "required dependency config not present");
final BuildConfigExtension buildConfig = buildUtil.getBuildConfig();
final TaskContainer tasks = project.getTasks();
pJarTask.setGroup(TaskCreator.ARTIFACTS_GROUP_NAME);
pJarTask.setDescription("Assembles a jar archive containing the '" + SourceSet.MAIN_SOURCE_SET_NAME + "' classes for dependency configuration '" + pDepConfig.getName() + "'");
// set appendix for archive name
final String appendix = pDepConfig.getName();
if (!pDepConfig.isDefaultConfig()) {
pJarTask.getArchiveAppendix().set(appendix);
}
// Dependency on pom.properties generating task
pJarTask.dependsOn(tasks.named(TaskNames.generatePomProperties.getName(pDepConfig)));
// Task Input: pom.properties file
final File pomPropsUsed = ((GeneratePomPropsTask) tasks.getByName(TaskNames.generatePomProperties.getName(pDepConfig))).getPluginPomProps();
pJarTask.getInputs().file(pomPropsUsed);
// Dependency on pom.xml generating task
final GenerateMavenPom generatePomTask = buildUtil.getTask(TaskNames.generatePomFileForCheckstyleAddonsPublication, GenerateMavenPom.class, pDepConfig);
pJarTask.dependsOn(generatePomTask);
// Dependency on 'classes' task (compile and resources)
pJarTask.dependsOn(buildUtil.getTaskProvider(TaskNames.mainClasses, Task.class, pDepConfig));
// Configuration of JAR file contents
pJarTask.from(generatePomTask.getDestination(), copySpec -> copySpec.rename(filename -> filename.replace("pom-default.xml", "pom.xml")));
final SourceSet mainSourceSet = buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME);
pJarTask.from(new ClasspathBuilder(project).getClassesDirs(mainSourceSet, pDepConfig));
pJarTask.from(mainSourceSet.getOutput().getResourcesDir());
pJarTask.exclude("download-guide.html", "**/*.md", "**/checks/all_checks.html", "eclipsecs-plugin.xml", "**/checkstyle-metadata.*");
pJarTask.into("META-INF", copySpec -> copySpec.from("LICENSE"));
// add generated pom.xml and pom.properties to archive, setting build timestamp in the process
pJarTask.into("META-INF/maven/" + project.getGroup() + "/" + project.getName(), copySpec -> {
copySpec.from(generatePomTask.getDestination());
copySpec.rename(filename -> filename.replace("pom-default.xml", "pom.xml"));
copySpec.from(pomPropsUsed);
Map<String, String> placeHolders = new HashMap<>();
placeHolders.put("buildTimestamp", buildConfig.getBuildTimestamp().get().toString());
Map<String, Object> propsMap = new HashMap<>();
propsMap.put("tokens", placeHolders);
copySpec.filter(propsMap, ReplaceTokens.class);
});
// Manifest
configureManifest(pJarTask, pDepConfig, appendix);
}
use of com.thomasjensen.checkstyle.addons.build.ClasspathBuilder in project checkstyle-addons by checkstyle-addons.
the class JavadocConfigAction method configureJavadocTask.
/**
* These configurations are also applied to the standard 'javadoc' task, plus they are applied to ours.
*
* @param pJavadocTask the task to configure
* @param pDepConfig dependency config
*/
public void configureJavadocTask(@Nonnull Javadoc pJavadocTask, @Nonnull final DependencyConfig pDepConfig) {
// can't use fields here
final Project project = pJavadocTask.getProject();
final BuildUtil buildUtil = new BuildUtil(project);
final StandardJavadocDocletOptions options = (StandardJavadocDocletOptions) pJavadocTask.getOptions();
options.setEncoding(StandardCharsets.UTF_8.toString());
options.setDocEncoding(StandardCharsets.UTF_8.toString());
options.setCharSet(StandardCharsets.UTF_8.toString());
options.setAuthor(false);
options.setUse(true);
options.setNoDeprecated(true);
options.setSplitIndex(false);
options.setLinks(pDepConfig.getJavadocLinks());
options.setHeader(buildUtil.getBuildConfig().getLongName().get());
options.setWindowTitle(buildUtil.getBuildConfig().getLongName().get());
pJavadocTask.setTitle(buildUtil.getBuildConfig().getLongName().get() + " v" + project.getVersion());
pJavadocTask.setSource(buildUtil.getSourceSet(SourceSet.MAIN_SOURCE_SET_NAME).getAllJava().plus(buildUtil.getSourceSet(BuildUtil.SONARQUBE_SOURCE_SET_NAME).getAllJava()));
pJavadocTask.setClasspath(new ClasspathBuilder(project).buildJavadocClasspath(pDepConfig));
// javadoc does not inherit the proxy settings (https://issues.gradle.org/browse/GRADLE-1228)
if (System.getProperty("http.proxyHost") != null) {
options.jFlags("-DproxyHost=" + System.getProperty("http.proxyHost"), "-DproxyPort=" + System.getProperty("http.proxyPort"), "-DproxyUser=" + System.getProperty("http.proxyUser"), "-DproxyPassword=" + System.getProperty("http.proxyPassword"));
}
}
Aggregations