Migrate initializr-web to Java

This commit is contained in:
Dave Syer
2017-02-01 17:35:06 +00:00
committed by Stephane Nicoll
parent 1385e82eb5
commit ec5a7da507
84 changed files with 4152 additions and 3789 deletions

View File

@@ -70,10 +70,6 @@ class BillOfMaterials {
final List<Mapping> mappings = []
static BillOfMaterials create(String groupId, String artifactId, String version) {
new BillOfMaterials(groupId: groupId, artifactId: artifactId, version: version)
}
/**
* Determine the version placeholder to use for this instance. If a version
* property is defined, this returns the reference for the property. Otherwise
@@ -135,14 +131,26 @@ class BillOfMaterials {
private VersionRange range
static Mapping create(String versionRange, String version) {
new Mapping(versionRange: versionRange, version: version)
}
String determineVersionRangeRequirement() {
range.toString()
}
public static Mapping create(String range, String version) {
return new Mapping(versionRange: range, version: version);
}
public static Mapping create(String range, String version, String... repositories) {
return new Mapping(versionRange: range, version: version, repositories: repositories);
}
}
public static BillOfMaterials create(String groupId, String artifactId) {
return new BillOfMaterials(groupId: groupId, artifactId: artifactId);
}
public static BillOfMaterials create(String groupId, String artifactId, String version) {
return new BillOfMaterials(groupId: groupId, artifactId: artifactId, version: version);
}
}

View File

@@ -21,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
import groovy.transform.AutoClone
import groovy.transform.AutoCloneStyle
import groovy.transform.ToString
import io.spring.initializr.metadata.Dependency.Mapping;
import io.spring.initializr.util.InvalidVersionException
import io.spring.initializr.util.Version
import io.spring.initializr.util.VersionParser
@@ -35,19 +36,19 @@ import io.spring.initializr.util.VersionRange
@ToString(ignoreNulls = true, includePackage = false)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@AutoClone(style = AutoCloneStyle.COPY_CONSTRUCTOR)
class Dependency extends MetadataElement {
class Dependency extends MetadataElement implements Describable {
static final String SCOPE_COMPILE = 'compile'
static final String SCOPE_COMPILE_ONLY = 'compileOnly'
static final String SCOPE_RUNTIME = 'runtime'
static final String SCOPE_PROVIDED = 'provided'
static final String SCOPE_TEST = 'test'
static final List<String> SCOPE_ALL = [
SCOPE_COMPILE,
SCOPE_RUNTIME,
SCOPE_COMPILE_ONLY,
SCOPE_PROVIDED,
SCOPE_TEST
SCOPE_COMPILE,
SCOPE_RUNTIME,
SCOPE_COMPILE_ONLY,
SCOPE_PROVIDED,
SCOPE_TEST
]
List<String> aliases = []
@@ -144,7 +145,7 @@ class Dependency extends MetadataElement {
if (id == null) {
if (!hasCoordinates()) {
throw new InvalidInitializrMetadataException(
'Invalid dependency, should have at least an id or a groupId/artifactId pair.')
'Invalid dependency, should have at least an id or a groupId/artifactId pair.')
}
generateId()
} else if (!hasCoordinates()) {
@@ -160,7 +161,7 @@ class Dependency extends MetadataElement {
}
} else {
throw new InvalidInitializrMetadataException(
"Invalid dependency, id should have the form groupId:artifactId[:version] but got $id")
"Invalid dependency, id should have the form groupId:artifactId[:version] but got $id")
}
}
links.forEach { l ->
@@ -176,7 +177,7 @@ class Dependency extends MetadataElement {
versionRequirement = range.toString()
} catch (InvalidVersionException ex) {
throw new InvalidInitializrMetadataException("Invalid version range '$versionRange' for " +
"dependency with id '$id'", ex)
"dependency with id '$id'", ex)
}
}
mappings.each {
@@ -223,7 +224,7 @@ class Dependency extends MetadataElement {
def generateId() {
if (groupId == null || artifactId == null) {
throw new IllegalArgumentException(
"Could not generate id for $this: at least groupId and artifactId must be set.")
"Could not generate id for $this: at least groupId and artifactId must be set.")
}
StringBuilder sb = new StringBuilder()
sb.append(groupId).append(':').append(artifactId)
@@ -257,6 +258,22 @@ class Dependency extends MetadataElement {
private VersionRange range
public static Mapping create(String range, String groupId, String artifactId,
String version) {
new Mapping(versionRange: range, groupId: groupId, artifactId: artifactId, version: version);
}
}
public static Dependency create(String groupId, String artifactId, String version, String scope) {
return new Dependency(groupId: groupId, artifactId: artifactId, version: version, scope: scope);
}
public static Dependency withId(String id, String groupId, String artifactId, String version) {
return new Dependency(groupId: groupId, artifactId: artifactId, versionRange: version, id: id);
}
public static Dependency withId(String id, String groupId, String artifactId) {
return new Dependency(groupId: groupId, artifactId: artifactId, id: id);
}
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring.initializr.metadata;
interface Describable {
String getDescription();
}

View File

@@ -104,4 +104,16 @@ class Link {
new URI(result)
}
public static Link create(String rel, String href) {
return new Link(rel: rel, href: href);
}
public static Link create(String rel, String href, String description) {
return new Link(rel: rel, href: href, description: description);
}
public static Link create(String rel, String href, boolean templated) {
return new Link(rel: rel, href: href, templated: templated);
}
}

View File

@@ -32,7 +32,7 @@ import org.springframework.util.Assert
@JsonIgnoreProperties(["default", "all"])
@JsonInclude(JsonInclude.Include.NON_NULL)
@AutoClone(style = AutoCloneStyle.COPY_CONSTRUCTOR)
abstract class ServiceCapability<T> {
abstract class ServiceCapability<T> implements Cloneable {
final String id

View File

@@ -22,7 +22,7 @@ package io.spring.initializr.metadata
*
* @author Stephane Nicoll
*/
class Type extends DefaultMetadataElement {
class Type extends DefaultMetadataElement implements Describable {
String description