Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Gradle.pdf
Скачиваний:
9
Добавлен:
24.03.2015
Размер:
1.4 Mб
Скачать

Example 34.7. Configuring the language to be analyzed

build.gradle

project(":project2") { sonar {

project {

language = "groovy"

}

}

}

When setting only a single property at a time, the equivalent property syntax is more succinct:

Example 34.8. Using property syntax

build.gradle

project(":project2").sonar.project.language = "groovy"

34.3. Analyzing Custom Source Sets

By default, the Sonar plugin will analyze the production sources in the main source set and the test sources in the test source set. This works independent of the project's source director layout. Additional source sets can be added as needed.

Example 34.9. Analyzing custom source sets

build.gradle

sonar.project {

sourceDirs += sourceSets.custom.allSource.srcDirs testDirs += sourceSets.integTest.allSource.srcDirs

}

34.4. Setting Custom Sonar Properties

Eventually, most configuration is passed to the Sonar code analyzer in the form of key-value pairs known as Sonar properties. The SonarProperty annotations in the API documentation show how properties of the plugin's object model get mapped to the corresponding Sonar properties. Th Sonar plugin offers hooks to post-process Sonar properties before they get passed to the code analyzer. The same hooks can be used to add additional properties which aren't covered by th plugin's object model.

For global Sonar properties, use the withGlobalProperties hook on SonarRootModel:

Page 188 of 343

Example 34.10. Setting custom global properties

build.gradle

sonar.withGlobalProperties { props -> props["some.global.property"] = "some value"

}

For per-project Sonar properties, use the withProjectProperties hook on SonarProject:

Example 34.11. Setting custom project properties

build.gradle

sonar.project.withProjectProperties { props -> props["some.project.property"] = "some value"

}

The Sonar documentation provides a complete list of Sonar properties. (Note that most of these properties are already covered by the plugin's object model.) For configuring third-party Sona plugins, consult their documentation.

34.5. Tasks

The Sonar plugin adds the following tasks to the project.

Table 34.1. Sonar plugin - tasks

Task name

Depends

Type

Description

 

on

 

 

sonarAnalyze

-

SonarAnalyze

Analyzes a project hierarchy and stores

 

 

 

the results in the Sonar database.

Page 189 of 343

35

The OSGi Plugin

The OSGi plugin provides a factory method to create an OsgiManifest object. OsgiManifest extends Manifest. To learn more about generic manifest handling, see Section 23.13.1, “Manifes.t” If the Java plugins is applied, the OSGi plugin replaces the manifest object of the default jar with an OsgiManifest object. The replaced manifest is merged into the new one.

The OSGi plugin makes heavy use of Peter Kriens BND tool.

35.1. Usage

To use the OSGi plugin, include in your build script:

Example 35.1. Using the OSGi plugin

build.gradle

apply plugin: 'osgi'

35.2. Implicitly applied plugins

Applies the Java base plugin.

35.3. Tasks

This plugin does not add any tasks.

35.4. Dependency management

TBD

35.5. Convention object

The OSGi plugin adds the following convention object: OsgiPluginConvention

Page 190 of 343

35.5.1. Convention properties

The OSGi plugin does not add any convention properties to the project.

35.5.2. Convention methods

The OSGi plugin adds the following methods. For more details, see the API documentation of the convention object.

Table 35.1. OSGi methods

Method

Return Type

Description

osgiManifest()

OsgiManifest

Returns an OsgiManifest object.

osgiManifest(Closure

OsgiManifest

Returns an OsgiManifest object configured by the

cl)

 

closure.

The classes in the classes dir are analyzed regarding there package dependencies and the packages they expose. Based on this the Import-Package and the Export-Package values of the OSGi Manifest are calculated. If the classpath contains jars with an OSGi bundle, the bundle information is used to specify version information for the Import-Package value. Beside the explicit properties of the OsgiManifest object you can add instructions.

Example 35.2. Configuration of OSGi MANIFEST.MF file

build.gradle

jar {

manifest { // the manifest of the default jar is of type OsgiManifest name = 'overwrittenSpecialOsgiName'

instruction 'Private-Package', 'org.mycomp.package1', 'org.mycomp.package2'

instruction 'Bundle-Vendor', 'MyCompany'

instruction 'Bundle-Description', 'Platform2: Metrics 2 Measures Frame instruction 'Bundle-DocURL', 'http://www.mycompany.com'

}

}

task fooJar(type: Jar) { manifest = osgiManifest {

instruction 'Bundle-Vendor', 'MyCompany'

}

}

The first argument of the instruction call is the key of the property. The other arguments form the value. They are joined by Gradle with the , separator. To learn more about the available instructions have a look at the BND tool.

Page 191 of 343

36

The Eclipse Plugin

The Eclipse plugin generates files that are used by the Eclipse IDE, thus making it possible to import the project into Eclipse (File - Import... - Existing Projects into Workspace). Both external dependencies (including associated source and javadoc files) and project dependencies are considered.

Since 1.0-milestone-4 WTP-generating code was refactored into a separate plugin called eclipse

. So if you are interested in WTP integration then only apply the eclipse-wtp plugin. Otherwise applying eclipse plugin is enough. This change was requested by Eclipse users who take advantage of war or ear plugin but they don't use Eclipse WTP. Internally,eclipse-wtp also applies the eclipse plugin so you don't need to apply both of those plugins.

What exactly the Eclipse plugin generates depends on which other plugins are used:

Table 36.1. Eclipse plugin behavior

Plugin

Description

None

Generates minimal .project file.

Java

Adds Java configuration to .project. Generates .classpath and JDT settings

 

file.

Groovy

Adds Groovy configuration to .project file.

Scala

Adds Scala support to .project file.

War

Adds web application support to .project file. Generates WTP settings files only if

 

eclipse-wtp plugin was applied.

Ear

Adds ear application support to .project file. Generates WTP settings files only if ec

 

plugin was applied.

The Eclipse plugin is open to customization and provides a standardized set of hooks for adding and removing content from the generated files.

Page 192 of 343

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]