diff --git a/build.gradle b/build.gradle index 8ae05df93abd75b992db3a7b51e8c350599d8a2c..6a18333d465d07fbac395248950d9afd92cea972 100644 --- a/build.gradle +++ b/build.gradle @@ -2,62 +2,10 @@ apply plugin: 'base' /* --! Please Define the Parent ID and and the Group Id! --! */ -groupID = "de.prob" -parentID = "de.prob.parent" - - - -//--- Defining Tycho POM parts --// - - - def artifact(artifactId,versionNumber) { """ - <groupId>${groupId()}</groupId> - <artifactId>${artifactId}</artifactId> - <version>${versionNumber}</version> - <packaging>eclipse-plugin</packaging> - """ } - - - - def start() { """<?xml version="1.0" encoding="UTF-8"?> - <project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - """} - - - def elder() {""" - <parent> - <groupId>${groupId()}</groupId> - <artifactId>${parentId()}</artifactId> - <version>1.0.0.qualifier</version> - <relativePath>../${parentId()}/pom.xml</relativePath> - </parent> - """} - - def repos() {""" - <repositories> - <!-- configure p2 repository to resolve against --> - <repository> - <id>prob_target</id> - <layout>p2</layout> - <url>http://cobra.cs.uni-duesseldorf.de/prob_dev_target/</url> - </repository> - - <repository> - <id>indigo</id> - <layout>p2</layout> - <url>http://download.eclipse.org/releases/indigo/</url> - </repository> - </repositories> - """} - - - - def end() {""" - </project> - """} - +groupID = "de.prob" +parentID = "de.prob.parent" // must be the same as the folder name +features = ["de.prob2.feature"] // must be the same as the folder name +repositoryName = "de.prob.repository" // will be the folder name def download(address,target) { @@ -102,7 +50,7 @@ task downloadCli << { } -/* -- Define ParentId -- */ +/* -- Return ParentId -- */ def parentId(){ return parentID @@ -115,7 +63,7 @@ def parentId(){ -/* -- Define Group Id -- */ +/* -- Return Group Id -- */ def groupId(){ return groupID } @@ -124,11 +72,20 @@ def groupId(){ * This Group ID will be used in every sub project */ + +///////////////////////////////////////////////////////////////////////////////////////// +// -- !!! DEFINING SUB PROJECTS !!! -- // +///////////////////////////////////////////////////////////////////////////////////////// + subprojects { apply plugin: 'base' + + task deleteArtifacts(type: Delete) { + delete 'target','pom.xml' + } - task deploy(){ + task deploy() <<{ description = "\tGenerating the Tycho Poms. Please remember to add a '.qualifier' to the version numbers!" versionNumber = 'Version Number Error:\tcheck Manifest for Bundle-Version Number and make sure to add a ".qualifier" to the version numbers!\n' @@ -143,26 +100,170 @@ subprojects { * Versionnumber of the projects are equal to their * Bundle-Version Number */ - } + + + if(features.every{ it != project.name }){ + content = new File("${project.name}/META-INF/MANIFEST.MF").getText("UTF-8") + + printFileLine = { + if( it ==~ /Bundle-Version.+qualifier/ ){ + versionNumber = it.substring(16) // possibile error: cuts off first 16 chars + + /* Version Number is taken from Bundle-Version in Manifest.MF + * If there is no Bundle-Version or the versionnumber needs to + * be taken from a different key word, please change the + * regular expression and the substring above + */ + } + + if( it ==~ /Bundle-SymbolicName:.+/ ){ + artifactId = it.substring(21) + artifactId = artifactId.replace(";singleton:=true",'') + } + /* Artifact ID is taken from Bundle-SymbolicName minus the + * 16 chars ';singleton:=true' + */ + } - task deleteArtifacts(type: Delete) { - delete 'target','pom.xml' - } + content.eachLine( printFileLine ) -} + + println artifactId + println "\t"+versionNumber + + def f = new File(artifactId+'/pom.xml') + f.delete() + f << start()+elder()+repos()+artifact(artifactId, versionNumber)+end() + /* + * old pom.xml files are deleted and replaced by new auto generated Tycho pom.xml files + */ + }else{ // if subprojects are neither a feature, repository nor parent + + + +// -- Features -- // + + if(features.any{ it == project.name } ){ + + boolean idfound = false -task createPoms(dependsOn: subprojects.deploy) + content = new File("${project.name}/feature.xml").getText("UTF-8") -task collectArtifacts(type:Copy) { - from 'de.prob.repository/target/repository/' - into 'updatesite' - } + printFileLine = { + + if( it ==~ /.+version.+qualifier.+/ ){ + versionNumber = it.substring(15,it.size()-1) + // possibile error: cuts off first 15 chars and leaves out last '"' + + /* Version Number is taken from Feature.xml + * feature.xml is searched for version="version.qualifier" + * first 15 chars and last '"' are cut off + */ + + } + + + if( it ==~ /.+id=".+/ && idfound == false ){ + artifactId = it.substring(10,it.length()-1) + idfound = true + } + /* Artifact ID is taken from Bundle-SymbolicName minus the + * 16 chars ';singleton:=true' + */ + } + + content.eachLine( printFileLine ) + + + println artifactId + println "\t"+versionNumber + + + def f = new File(artifactId+'/pom.xml') + f.delete() + f << feature(artifactId, versionNumber) + + } + + } + } + + + +}// defining subprojects clean { dependsOn += subprojects.deleteArtifacts } +task createParent() << { + // -- define Parent -- // + + new File("${parentID}").mkdir() + versionNumber = '1.0.0.qualifier' + artifactId = parentId() + + def f = new File(artifactId+'/pom.xml') + f.delete() + f << parentPom(artifactId) + for(int i = 0; i < numberOfProjects(); i++){ + f << module(i) + } + f << endParent() + +} + +task createRepository() << { + + // -- define Repository -- // + + + new File("${repositoryName}").mkdir() + + versionNumber = '1.0.0.qualifier' + artifactId = repositoryName + featureVersionNumber = '1.0.0.qualifier' + def f = new File(artifactId+'/category.xml') + f.delete() + f << categoryHead() + for(int i = 0; i < features.size(); i++){ + + content = new File("${features[i]}/feature.xml").getText("UTF-8") + printFileLine = { + if( it ==~ /.+version.+qualifier.+/ ){ + featureVersionNumber = it.substring(15,it.size()-1) + // possibile error: cuts off first 15 chars and leaves out last '"' + + /* Version Number is taken from Feature.xml + * feature.xml is searched for version="version.qualifier" + * first 15 chars and last '"' are cut off + */ + } + } + content.eachLine( printFileLine ) + f << categoryFeatures(features[i], featureVersionNumber) + }// for + + for(int i = 0; i < features.size(); i++){ + + f << categoryDescription(features[i], "Test" ,"categorydescription") + }//for + + f << categoryEnd() + + def pom = new File(artifactId+'/pom.xml') + pom.delete() + pom << reposi() +}// end of repository definition + + +task createPoms(dependsOn: [createParent, createRepository, subprojects.deploy]) + +task collectArtifacts(type:Copy) { + from 'de.prob.repository/target/repository/' + into 'updatesite' + } task install(dependsOn: [createPoms, downloadCli] , type:Exec) { description = "\tExecutes a 'mvn install' of the parent pom.xml and auto-generates Tycho Poms" @@ -173,6 +274,190 @@ task install(dependsOn: [createPoms, downloadCli] , type:Exec) { } +//--- Defining Tycho POM parts --// + + + def artifact(artifactId,versionNumber) { """ + <groupId>${groupId()}</groupId> + <artifactId>${artifactId}</artifactId> + <version>${versionNumber}</version> + <packaging>eclipse-plugin</packaging> + """ } + + + + def start() { """<?xml version="1.0" encoding="UTF-8"?> + <project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + """} + + + def elder() {""" + <parent> + <groupId>${groupId()}</groupId> + <artifactId>${parentId()}</artifactId> + <version>1.0.0.qualifier</version> + <relativePath>../${parentId()}/pom.xml</relativePath> + </parent> + """} + + def repos() {""" + <repositories> + <!-- configure p2 repository to resolve against --> + <repository> + <id>prob_target</id> + <layout>p2</layout> + <url>http://cobra.cs.uni-duesseldorf.de/prob_dev_target/</url> + </repository> + + <repository> + <id>indigo</id> + <layout>p2</layout> + <url>http://download.eclipse.org/releases/indigo/</url> + </repository> + </repositories> + """} + + + + def end() {""" + </project> + """} + +// -- defining Parent Pom -- // + +def parentPom(artifactId) { """<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>${groupId()}</groupId> + <artifactId>${artifactId}</artifactId> + <version>1.0.0.qualifier</version> + + <packaging>pom</packaging> + + <!-- this is the parent POM from which all modules inherit common settings --> + <properties> + <tycho-version>0.14.1</tycho-version> + </properties> + + + <repositories> + <!-- configure p2 repository to resolve against --> + <repository> + <id>prob_target</id> + <layout>p2</layout> + <url>http://cobra.cs.uni-duesseldorf.de/prob_dev_target/</url> + </repository> + + + <repository> + <id>indigo</id> + <layout>p2</layout> + <url>http://download.eclipse.org/releases/indigo/</url> + </repository> + + </repositories> + + <build> + <plugins> + <plugin> + <!-- enable tycho build extension --> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-maven-plugin</artifactId> + <version>0.14.1</version> + <extensions>true</extensions> + </plugin> + </plugins> + </build> + + <!-- the modules that should be built together --> + <modules> + """} + +//for(int i = 0; i < numberOfProjects(); i++) + +def module(int i){ + if(projects(i)!=parentId()){""" <module>../${projects(i)}</module> +"""}else{""""""} +} + + +def endParent() {""" + </modules> +</project> + """} + +// end of defining parent pom.xml + +// repository Pom +def reposi() { """ +<?xml version="1.0" encoding="UTF-8"?> + <project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>${groupID}</groupId> + <artifactId>${parentID}</artifactId> + <version>1.0.0.qualifier</version> + <relativePath>../${parentID}/pom.xml</relativePath> + </parent> + + + <groupId>${groupID}</groupId> + <artifactId>${repositoryName}</artifactId> + <version>1.0.0.qualifier</version> + <packaging>eclipse-repository</packaging> + </project> +"""} + + +// creates a category in +def categoryHead() { """<?xml version="1.0" encoding="UTF-8"?> +<site> + +"""} + +def categoryFeatures(artifactId, versionNumber){""" + <feature url="features/${artifactId}_${versionNumber}.jar" id="${artifactId}" version="${versionNumber}"> + <category name="${artifactId}.category"/> + </feature> +"""} + +def categoryDescription(artifactId, categoryName, categorydescription){""" +<category-def name="${artifactId}.category" label="${categoryName}"> + <description> +${categorydescription} + </description> + </category-def> +"""} + +def categoryEnd(){""" +</site> +"""} +// end of category definition + +// feature pom +def feature(artifactId, versionNumber) { """ +<?xml version="1.0" encoding="UTF-8"?> + <project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>${groupId()}</groupId> + <artifactId>${parentId()}</artifactId> + <version>1.0.0.qualifier</version> + <relativePath>../${parentId()}/pom.xml</relativePath> + </parent> + <groupId>${groupId()}</groupId> + <artifactId>${artifactId}</artifactId> + <version>${versionNumber}</version> + <packaging>eclipse-feature</packaging> + </project> +"""} +// end of feature pom + // Build Script can be executed via gradle install // Pom Generation can be executed via gradle deploy