Java Code Examples for org.gradle.api.project#setVersion()

The following examples show how to use org.gradle.api.project#setVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RuntimeClassoaderFactoryTest.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
	// TODO address dependency resolution issues
	GeneratorPlugin.APPLY_DOCLET_BY_DEFAULT = false;

	testProjectDir.newFolder("src", "main", "java");

	File outputDir = testProjectDir.getRoot();

	Project project = ProjectBuilder.builder().withName("crnk-gen-typescript-test").withProjectDir(outputDir).build();
	project.setVersion("0.0.1");

	project.getPluginManager().apply(JavaPlugin.class);
	project.getPluginManager().apply(GeneratorPlugin.class);

	GeneratorExtension config = project.getExtensions().getByType(GeneratorExtension.class);
	config.getRuntime().setConfiguration("test");

	TSGeneratorModule module = new TSGeneratorModule();

	factory = new RuntimeClassLoaderFactory(project, module);
	ClassLoader parentClassLoader = getClass().getClassLoader();
	classLoader = factory.createClassLoader(parentClassLoader, true);
	sharedClassLoader = (RuntimeClassLoaderFactory.SharedClassLoader) classLoader.getParent();

}
 
Example 2
Source File: CustomVersionPlugin.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Project project) {
	String version = project.getVersion().toString();
	Object versionBranchProperty = project.getProperties().get(CUSTOM_VERSION_PROPERTY);
	if (versionBranchProperty == null) {
		return;
	}

	String versionBranch = versionBranchProperty.toString();
	//consider an empty string as "no custom version"
	if (versionBranch.isEmpty()) {
		return;
	}
	if (!ONLY_ALPHANUMERIC_PATTERN.matcher(versionBranch).matches()) {
		throw new InvalidUserDataException("Custom version for project passed through -PversionBranch must be alphanumeric chars only: " + versionBranch);
	}

	if (!version.endsWith(SNAPSHOT_SUFFIX)) {
		return;
	}

	String realVersion = version + "-" + versionBranch;
	project.setVersion(realVersion);
	System.out.println("Building custom snapshot for " + project + ": '" + project.getVersion());
}
 
Example 3
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void changesVersionIfPropertyVersionBranchAndSnapshot() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3-SNAPSHOT");
	project.getExtensions().add("versionBranch", "custom");

	plugin.apply(project);

	assertThat(project.getVersion()).hasToString("1.2.3-SNAPSHOT-custom");
}
 
Example 4
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void doNothingIfPropertyVersionBranchButNoQualifier() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3"); //this is the 2020 release scheme
	project.getExtensions().add("versionBranch", "custom");

	plugin.apply(project);

	assertThat(project.getVersion()).hasToString("1.2.3");
}
 
Example 5
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void doNothingIfPropertyVersionBranchButNotSnapshotQualifier() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3-M1");
	project.getExtensions().add("versionBranch", "custom");

	plugin.apply(project);

	assertThat(project.getVersion()).hasToString("1.2.3-M1");
}
 
Example 6
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void rejectUnderscoreEvenIfNotSnapshot() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3.SOMETHINGELSE");
	project.getExtensions().add("versionBranch", "custom_one");

	assertThatExceptionOfType(InvalidUserDataException.class)
			.isThrownBy(() -> plugin.apply(project))
			.withMessage("Custom version for project passed through -PversionBranch must be alphanumeric chars only: custom_one");

	assertThat(project.getVersion()).hasToString("1.2.3.SOMETHINGELSE");
}
 
Example 7
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void rejectDashEvenIfNotSnapshot() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3.SOMETHINGELSE");
	project.getExtensions().add("versionBranch", "custom-one");

	assertThatExceptionOfType(InvalidUserDataException.class)
			.isThrownBy(() -> plugin.apply(project))
			.withMessage("Custom version for project passed through -PversionBranch must be alphanumeric chars only: custom-one");

	assertThat(project.getVersion()).hasToString("1.2.3.SOMETHINGELSE");
}
 
Example 8
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void rejectSpaceEvenIfNotSnapshot() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3.SOMETHINGELSE");
	project.getExtensions().add("versionBranch", "custom one");

	assertThatExceptionOfType(InvalidUserDataException.class)
			.isThrownBy(() -> plugin.apply(project))
			.withMessage("Custom version for project passed through -PversionBranch must be alphanumeric chars only: custom one");

	assertThat(project.getVersion()).hasToString("1.2.3.SOMETHINGELSE");
}
 
Example 9
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void rejectUnderscore() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3-SNAPSHOT");
	project.getExtensions().add("versionBranch", "custom_one");

	assertThatExceptionOfType(InvalidUserDataException.class)
			.isThrownBy(() -> plugin.apply(project))
			.withMessage("Custom version for project passed through -PversionBranch must be alphanumeric chars only: custom_one");

	assertThat(project.getVersion()).hasToString("1.2.3-SNAPSHOT");
}
 
Example 10
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void rejectDash() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3-SNAPSHOT");
	project.getExtensions().add("versionBranch", "custom-one");

	assertThatExceptionOfType(InvalidUserDataException.class)
			.isThrownBy(() -> plugin.apply(project))
			.withMessage("Custom version for project passed through -PversionBranch must be alphanumeric chars only: custom-one");

	assertThat(project.getVersion()).hasToString("1.2.3-SNAPSHOT");
}
 
Example 11
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void rejectSpace() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3-SNAPSHOT");
	project.getExtensions().add("versionBranch", "custom one");

	assertThatExceptionOfType(InvalidUserDataException.class)
			.isThrownBy(() -> plugin.apply(project))
			.withMessage("Custom version for project passed through -PversionBranch must be alphanumeric chars only: custom one");

	assertThat(project.getVersion()).hasToString("1.2.3-SNAPSHOT");
}
 
Example 12
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void acceptsEmptyStringAsNoCustomVersion() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3-SNAPSHOT");
	project.getExtensions().add("versionBranch", "");

	assertThatCode(() -> plugin.apply(project)).doesNotThrowAnyException();
	assertThat(project.getVersion()).hasToString("1.2.3-SNAPSHOT");
}
 
Example 13
Source File: CustomVersionPluginTest.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Test
void noCustomVersionPropertyDoesNothing() {
	CustomVersionPlugin plugin = new CustomVersionPlugin();
	Project project = ProjectBuilder.builder().withName("foo").build();
	project.setVersion("1.2.3-SNAPSHOT");

	plugin.apply(project);

	assertThat(project.getVersion()).hasToString("1.2.3-SNAPSHOT");
}
 
Example 14
Source File: DeployTaskTest.java    From gradle-beanstalk-plugin with MIT License 5 votes vote down vote up
@Test
public void versionShouldIncludePrefix() {
    Project project = ProjectBuilder.builder().build();
    project.setVersion("version");
    Map<String, Object> params = new HashMap<>();
    params.put("type", TestDeployTask.class);
    TestDeployTask task = (TestDeployTask) project.task(params, "tasktest");
    BeanstalkDeployment deployment = new BeanstalkDeployment("tasktest");
    deployment.setVersionPrefix("test-");
    task.setDeployment(deployment);

    assertTrue(task.findVersionLabel().matches("test-version"));
}
 
Example 15
Source File: GitVersionPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    this.logger = project.getLogger();
    project.setVersion(resolveVersion());

    project.allprojects(p -> p.setVersion(project.getVersion()));
}
 
Example 16
Source File: GitVersionPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    this.logger = project.getLogger();
    project.setVersion(resolveVersion());

    project.allprojects(p -> p.setVersion(project.getVersion()));
}
 
Example 17
Source File: VersionPlugin.java    From pygradle with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(Project project) {
    project.setVersion(version);
}
 
Example 18
Source File: GeneratorPluginTest.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws IOException {
	GeneratorPlugin.APPLY_DOCLET_BY_DEFAULT = false;

    testProjectDir.newFolder("src", "main", "java");

    File outputDir = testProjectDir.getRoot();

    Project project = ProjectBuilder.builder().withName("crnk-gen-typescript-test").withProjectDir(outputDir).build();
    project.setVersion("0.0.1");

    project.getPluginManager().apply(JavaPlugin.class);
    project.getPluginManager().apply(GeneratorPlugin.class);

    extension = project.getExtensions().getByType(GeneratorExtension.class);
    extension.getRuntime().setConfiguration("test");
    extension.setResourcePackages(Arrays.asList("io.crnk.test.mock"));
    extension.setForked(false);
    extension.init();

    task = (InMemoryGeneratorTask) project.getTasks().getByName("generateTypescript");
    Assert.assertNotNull(task);


}