diff --git a/example-app/build.gradle b/example-app/build.gradle index 1917dc8..c23cbfa 100644 --- a/example-app/build.gradle +++ b/example-app/build.gradle @@ -29,6 +29,7 @@ buildDir = 'build/gradle' sourceCompatibility = 1.7 version = new Version(app_version, project) group = app_group +ext[Version.PROJECT_INFORMATION_PACKAGE] = 'com.example.app.config' final repoURL = "${repo_venture_tech_url}/${repo_venture_tech_key}" buildscript { @@ -145,7 +146,11 @@ task createCompiletimeAspectsLibs(type: Copy) { into "compiletime-aspects" rename { "${it.substring(0, it.lastIndexOf('-'))}.jar" } } -gradle.projectsEvaluated { createRuntimeAspectsLibs.execute(); createCompiletimeAspectsLibs.execute(); } +gradle.projectsEvaluated { + createRuntimeAspectsLibs.execute() + createCompiletimeAspectsLibs.execute() + version.generateProjectInformationClass() +} diff --git a/example-app/buildSrc/src/main/groovy/com/proteusframework/build/Version.groovy b/example-app/buildSrc/src/main/groovy/com/proteusframework/build/Version.groovy index af87baa..99f442b 100644 --- a/example-app/buildSrc/src/main/groovy/com/proteusframework/build/Version.groovy +++ b/example-app/buildSrc/src/main/groovy/com/proteusframework/build/Version.groovy @@ -19,6 +19,19 @@ import java.text.SimpleDateFormat */ class Version { + /** + * Optional variable that can be defined in the build.gradle + * to determine where the ProjectInformation.java class is put + * when {@link #generateProjectInformationClass()} is called. + * If not defined, the package name is "${project.group}.${project.name}". + *

+ * Example:
+ * ext[Version.PROJECT_INFORMATION_PACKAGE] = 'com.example.app.config' + *

+ */ + public static final String PROJECT_INFORMATION_PACKAGE = 'projectInformationPackage' + + String versionNumber; String originalVersion String thisVersion String status @@ -33,13 +46,14 @@ class Version if (originalVersion.endsWith('-SNAPSHOT')) { status = 'integration' - def version = originalVersion.substring(0, originalVersion.length() - '-SNAPSHOT'.length()) - thisVersion = "${version}-${getTimestamp()}" + versionNumber = originalVersion.substring(0, originalVersion.length() - '-SNAPSHOT'.length()) + thisVersion = "${versionNumber}-${getTimestamp()}" } else { status = 'release' thisVersion = versionValue + versionNumber = versionValue } } @@ -68,4 +82,107 @@ class Version { thisVersion } + + /** + * Generate a version class for the project. + */ + void generateProjectInformationClass() + { + def now = new SimpleDateFormat('yyyyMMdd\'T\'HHmmss.SSSZ').format(new java.util.Date()) + def srcDir = project.sourceSets.main.java.srcDirs.iterator().next() + def packageName = project.hasProperty(PROJECT_INFORMATION_PACKAGE) ? + project[PROJECT_INFORMATION_PACKAGE] : "${project.group.toString()}.${project.name}"; + def packageDir = new File(srcDir, packageName.replace('.', '/')) + packageDir.mkdirs() + def gitIgnore = new File(packageDir, '.gitignore') + if(!gitIgnore.exists()) { + gitIgnore.text = """# Ignore auto generated file ProjectInformation.java +ProjectInformation.java""" + } + def generatedClass = new File(packageDir, 'ProjectInformation.java') + generatedClass.text = """ +/* + * Copyright (c) Interactive Information R & D (I2RD) LLC. + * All Rights Reserved. + * + * This software is confidential and proprietary information of + * I2RD LLC ("Confidential Information"). You shall not disclose + * such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered + * into with I2RD. + */ + +package ${packageName}; + +import javax.annotation.Generated; + +/** + * Project Information. + * @author Auto Generated (noreply@i2rd.com) + */ +@Generated(value= "Generated by build system", date = "${now}") +public final class ProjectInformation +{ + /** Name. */ + private final static String _name = "${project.name}"; + /** Group. */ + private final static String _group = "${project.group}"; + /** Version. */ + private final static String _version = "${versionNumber}"; + /** Commit. */ + private final static String _commit = "${project?.gitinfo?.commit?:''}"; + /** Branch. */ + private final static String _branch = "${project?.gitinfo?.branch?:''}"; + /** Status: release, milestone, integration. */ + private final static String _status = "${status}"; + + + /** + * Get the project name. + * @return the name. + */ + public static String getName() { return _name; } + + /** + * Get the project group. + * @return the group. + */ + public static String getGroup() { return _group; } + + /** + * Get the project version. + * @return the version. + */ + public static String getVersion() { return _version; } + + /** + * Get the commit id. + * @return the commit id. + */ + public static String getCommit() { return _commit; } + + /** + * Get the branch. + * @return the branch. + */ + public static String getBranch() { return _branch; } + + /** + * Get the project status. + * @return the status. + */ + public static String getStatus() { return _status; } + + /** + * Get the major version number. + * @return the major version number + * @throws NumberFormatException if version is in the wrong format. + * @throws IndexOutOfBoundsException if version is in the wrong format. + */ + public static int getMajorVersion() { return Integer.parseInt(getVersion().substring(0, getVersion().indexOf('.'))); } } + +""" + + } +} \ No newline at end of file diff --git a/example-app/example-app.iml b/example-app/example-app.iml index b934151..efd4eae 100644 --- a/example-app/example-app.iml +++ b/example-app/example-app.iml @@ -1,5 +1,5 @@ - + @@ -44,7 +44,6 @@ - @@ -148,7 +147,6 @@ - @@ -240,6 +238,8 @@ + + diff --git a/example-app/gradle.properties b/example-app/gradle.properties index b6193ca..e9b28b8 100644 --- a/example-app/gradle.properties +++ b/example-app/gradle.properties @@ -15,7 +15,7 @@ publish_venture_tech_url=https://repo.venturetech.net/artifactory publish_venture_tech_snapshot_key=vt-snapshot-local publish_venture_tech_release_key=vt-release-local -app_group=com.i2rd.example-app +app_group=com.example app_version=1.0-SNAPSHOT # Put the following in ~/.gradle/gradle.properties with the proper values