Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
Added ProjectInformation.java support.
Browse files Browse the repository at this point in the history
  • Loading branch information
proteus-russ committed Feb 6, 2014
1 parent a98d2a4 commit 9a89718
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 7 deletions.
7 changes: 6 additions & 1 deletion example-app/build.gradle
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}



Expand Down
Expand Up @@ -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 <code> "${project.group}.${project.name}"</code>.
* <p>
* Example: <br>
* <code>ext[Version.PROJECT_INFORMATION_PACKAGE] = 'com.example.app.config'
* </p>
*/
public static final String PROJECT_INFORMATION_PACKAGE = 'projectInformationPackage'

String versionNumber;
String originalVersion
String thisVersion
String status
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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('.'))); }
}
"""

}
}
6 changes: 3 additions & 3 deletions example-app/example-app.iml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.i2rd.example-app" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.example" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="AspectJ" name="AspectJ">
<configuration>
Expand Down Expand Up @@ -44,7 +44,6 @@
<orderEntry type="library" exported="" name="Gradle: jcaptcha-api-1.0" level="project" />
<orderEntry type="library" exported="" name="Gradle: bcmail-jdk14-1.38" level="project" />
<orderEntry type="library" exported="" name="Gradle: org.eclipse.update.configurator-3.3.200.v20130326-1319" level="project" />
<orderEntry type="library" exported="" name="Gradle: slf4j-log4j12-1.7.5" level="project" />
<orderEntry type="library" exported="" name="Gradle: org.eclipse.datatools.connectivity.sqm.core-1.2.7.v201308160952" level="project" />
<orderEntry type="library" exported="" name="Gradle: org.eclipse.core.resources-3.8.101.v20130717-0806" level="project" />
<orderEntry type="library" exported="" name="Gradle: commons-io-2.2" level="project" />
Expand Down Expand Up @@ -148,7 +147,6 @@
<orderEntry type="library" exported="" name="Gradle: tagsoup-1.2.0" level="project" />
<orderEntry type="library" exported="" name="Gradle: aopalliance-1.0" level="project" />
<orderEntry type="library" exported="" name="Gradle: cracklib-0.5.3" level="project" />
<orderEntry type="library" exported="" name="Gradle: slf4j-api-1.7.5" level="project" />
<orderEntry type="library" exported="" name="Gradle: org.eclipse.datatools.enablement.ibm.informix.dbdefinition-1.0.4.v201107221502" level="project" />
<orderEntry type="library" exported="" name="Gradle: poi-3.9" level="project" />
<orderEntry type="library" exported="" name="Gradle: activation-1.1" level="project" />
Expand Down Expand Up @@ -240,6 +238,8 @@
<orderEntry type="library" exported="" name="Gradle: proteusframework-processes-0.3.0-20140131184251" level="project" />
<orderEntry type="library" exported="" name="Gradle: proteusframework-management-0.3.0-20140131184251" level="project" />
<orderEntry type="library" exported="" name="Gradle: proteusframework-commerce-0.3.0-20140131184251" level="project" />
<orderEntry type="library" exported="" name="Gradle: slf4j-api-1.7.6" level="project" />
<orderEntry type="library" exported="" name="Gradle: slf4j-log4j12-1.7.6" level="project" />
</component>
</module>

2 changes: 1 addition & 1 deletion example-app/gradle.properties
Expand Up @@ -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
Expand Down

0 comments on commit 9a89718

Please sign in to comment.