Search in sources :

Example 1 with BuildUtil

use of com.thomasjensen.checkstyle.addons.build.BuildUtil in project checkstyle-addons by checkstyle-addons.

the class SiteCopyAllChecksConfigAction method buildReplacements.

public static Map<String, Object> buildReplacements(@Nonnull final Project pProject) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ");
    Date buildTimestamp = new BuildUtil(pProject).getBuildConfig().getBuildTimestamp().get();
    Map<String, String> replacements = new HashMap<>();
    replacements.put("buildTimestamp", sdf.format(buildTimestamp));
    replacements.put("version", "v" + pProject.getVersion());
    Map<String, Object> result = new HashMap<>();
    result.put("tokens", replacements);
    return result;
}
Also used : BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with BuildUtil

use of com.thomasjensen.checkstyle.addons.build.BuildUtil in project checkstyle-addons by checkstyle-addons.

the class AbstractTaskConfigAction method execute.

@Override
public final void execute(@Nonnull final T pTask) {
    Objects.requireNonNull(pTask);
    if (pTask.getLogger().isInfoEnabled()) {
        String msg = "Configuring task '" + pTask.getPath() + "'";
        if (depConfig != null) {
            msg += " for depConfig '" + depConfig.getName() + "'" + getExtraLogInfo(pTask);
        }
        pTask.getLogger().info(msg);
    }
    project = pTask.getProject();
    buildUtil = new BuildUtil(pTask.getProject());
    configureTaskFor(pTask, depConfig);
}
Also used : BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil)

Example 3 with BuildUtil

use of com.thomasjensen.checkstyle.addons.build.BuildUtil in project checkstyle-addons by checkstyle-addons.

the class JarConfigAction method mfAttrStd.

/**
 * Build a little map with standard manifest attributes.
 *
 * @param pProject Gradle project
 * @return the map
 */
public static Map<String, String> mfAttrStd(final Project pProject) {
    final BuildConfigExtension buildConfig = new BuildUtil(pProject).getBuildConfig();
    Map<String, String> result = new HashMap<>();
    result.put("Manifest-Version", "1.0");
    result.put("Website", buildConfig.getWebsite().get());
    result.put("Created-By", GradleVersion.current().toString());
    result.put("Built-By", System.getProperty("user.name"));
    result.put("Build-Jdk", Jvm.current().toString());
    return result;
}
Also used : BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) HashMap(java.util.HashMap) BuildConfigExtension(com.thomasjensen.checkstyle.addons.build.BuildConfigExtension)

Example 4 with BuildUtil

use of com.thomasjensen.checkstyle.addons.build.BuildUtil in project checkstyle-addons by checkstyle-addons.

the class VersionFileTask method writeVersionFile.

@TaskAction
public void writeVersionFile() {
    final BuildConfigExtension buildConfig = new BuildUtil(getProject()).getBuildConfig();
    List<String> lines = new ArrayList<>();
    lines.add("# " + buildConfig.getLongName().get() + " version information");
    lines.add("# " + buildConfig.getBuildTimestamp().get());
    lines.add("version=" + getProject().getVersion());
    try {
        Files.write(getVersionFile().get().toPath(), lines, StandardCharsets.US_ASCII);
    } catch (IOException e) {
        throw new GradleException("Failed to create file: " + getVersionFile().get().getAbsolutePath(), e);
    }
}
Also used : BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) BuildConfigExtension(com.thomasjensen.checkstyle.addons.build.BuildConfigExtension) IOException(java.io.IOException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 5 with BuildUtil

use of com.thomasjensen.checkstyle.addons.build.BuildUtil 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"));
    }
}
Also used : Project(org.gradle.api.Project) BuildUtil(com.thomasjensen.checkstyle.addons.build.BuildUtil) ClasspathBuilder(com.thomasjensen.checkstyle.addons.build.ClasspathBuilder) StandardJavadocDocletOptions(org.gradle.external.javadoc.StandardJavadocDocletOptions)

Aggregations

BuildUtil (com.thomasjensen.checkstyle.addons.build.BuildUtil)7 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3 Project (org.gradle.api.Project)3 BuildConfigExtension (com.thomasjensen.checkstyle.addons.build.BuildConfigExtension)2 File (java.io.File)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 GradleException (org.gradle.api.GradleException)2 FileTree (org.gradle.api.file.FileTree)2 TaskAction (org.gradle.api.tasks.TaskAction)2 ClasspathBuilder (com.thomasjensen.checkstyle.addons.build.ClasspathBuilder)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1