use of org.talend.sdk.component.starter.server.service.domain.Dependency in project component-runtime by Talend.
the class ProjectGenerator method generate.
public void generate(final ProjectRequest request, final OutputStream outputStream) {
final BuildGenerator generator = generators.get(request.getBuildType());
final Map<String, byte[]> files = new HashMap<>();
// build dependencies to give them to the build
final Collection<String> facets = ofNullable(request.getFacets()).orElse(emptyList());
final List<Dependency> dependencies = new ArrayList<>(facets.stream().map(this.facets::get).flatMap(f -> f.dependencies(facets)).collect(toSet()));
dependencies.sort((o1, o2) -> {
{
// by scope
final int scope1 = scopesOrdering.indexOf(o1.getScope());
final int scope2 = scopesOrdering.indexOf(o2.getScope());
final int scopeDiff = scope1 - scope2;
if (scopeDiff != 0) {
return scopeDiff;
}
}
{
// by group
final int comp = o1.getGroup().compareTo(o2.getGroup());
if (comp != 0) {
return comp;
}
}
// by name
return o1.getArtifact().compareTo(o2.getArtifact());
});
// force component-api and force it first
dependencies.remove(Dependency.componentApi());
dependencies.add(0, Dependency.componentApi());
// create the build to be able to generate the files
final Build build = generator.createBuild(request.getBuildConfiguration(), request.getPackageBase(), dependencies, facets);
files.put(build.getBuildFileName(), build.getBuildFileContent().getBytes(StandardCharsets.UTF_8));
// generate facet files
final Map<FacetGenerator, List<String>> filePerFacet = facets.stream().map(s -> s.toLowerCase(Locale.ENGLISH)).collect(toMap(this.facets::get, f -> {
final FacetGenerator g = this.facets.get(f);
return g.create(request.getPackageBase(), build, facets, request.getSources(), request.getProcessors()).peek(file -> files.put(file.getPath(), file.getContent())).map(FacetGenerator.InMemoryFile::getPath).collect(toList());
}));
// generate README.adoc if needed
if (!files.containsKey("README.adoc")) {
files.put("README.adoc", readmeGenerator.createReadme(request.getBuildConfiguration().getName(), filePerFacet).getBytes(StandardCharsets.UTF_8));
}
// handle logging - centralized since we want a single setup per project
filePerFacet.keySet().stream().map(FacetGenerator::loggingScope).reduce((s1, s2) -> {
final List<String> scopes = asList(s1, s2);
if (scopes.contains("compile")) {
return "compile";
}
if (scopes.contains("provided")) {
return "provided";
}
if (scopes.contains("test")) {
return "test";
}
return s1;
}).filter(s -> !s.isEmpty()).ifPresent(scope -> {
dependencies.add(new Dependency("org.apache.logging.log4j", "log4j-slf4j-impl", Versions.LOG4J2_VERSION, scope));
files.put(("test".equals(scope) ? build.getTestResourcesDirectory() : build.getMainResourcesDirectory()) + "/log4j2.xml", tpl.render("generator/logging/log4j2.mustache", emptyMap()).getBytes(StandardCharsets.UTF_8));
});
componentGenerator.create(request.getPackageBase(), build, request.getFamily(), request.getCategory(), request.getSources(), request.getProcessors()).forEach(file -> files.put(file.getPath(), file.getContent()));
// add wrapper build files
build.getWrapperFiles().forEach(f -> files.put(f.getPath(), f.getContent()));
// now create the zip prefixing it with the artifact value
final String rootName = request.getBuildConfiguration().getArtifact();
final Set<String> createdFolders = new HashSet<>();
try (final ZipOutputStream zip = new ZipOutputStream(outputStream)) {
// first create folders
new HashSet<>(files.keySet()).forEach(path -> {
final String[] segments = (rootName + '/' + path).split("/");
final StringBuilder current = new StringBuilder();
for (int i = 0; i < segments.length; i++) {
if (i == segments.length - 1) {
break;
}
current.append(segments[i]).append('/');
final String folder = current.toString();
if (createdFolders.add(folder)) {
try {
zip.putNextEntry(new ZipEntry(folder));
zip.closeEntry();
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}
}
});
// now create files entries
files.forEach((path, content) -> {
try {
zip.putNextEntry(new ZipEntry(rootName + '/' + path));
zip.write(content);
zip.closeEntry();
} catch (final IOException e) {
throw new IllegalStateException(e);
}
});
} catch (final IOException e) {
throw new IllegalStateException(e);
}
onCreate.fire(new CreateProject(request));
}
use of org.talend.sdk.component.starter.server.service.domain.Dependency in project component-runtime by Talend.
the class WADLFacet method register.
void register(@Observes final GeneratorRegistration init) {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("generator/facet/wadl/specification.xml")))) {
specification = reader.lines().collect(joining("\n"));
} catch (final IOException e) {
throw new IllegalStateException(e);
}
dependencies = singleton(new Dependency("org.apache.cxf", "cxf-rt-rs-client", CXF, "compile"));
init.registerFacetType(this);
}
use of org.talend.sdk.component.starter.server.service.domain.Dependency in project component-runtime by Talend.
the class GradleBuildGenerator method createBuild.
@Override
public Build createBuild(final ProjectRequest.BuildConfiguration buildConfiguration, final String packageBase, final Collection<Dependency> dependencies, final Collection<String> facets) {
final Set<String> buildDependencies = new TreeSet<>();
final List<String> configurations = new ArrayList<>();
final Set<String> plugins = new TreeSet<>();
final List<String> tasks = new ArrayList<>();
final Set<String> imports = new TreeSet<>();
final Set<String> javaMainSourceSets = new TreeSet<>();
if (facets.contains(WADLFacet.Constants.NAME)) {
buildDependencies.add("org.apache.cxf:cxf-tools-wadlto-jaxrs:" + CXF);
imports.add("org.apache.cxf.tools.common.ToolContext");
imports.add("org.apache.cxf.tools.wadlto.WADLToJava");
tasks.add("def wadlGeneratedFolder = \"$buildDir/generated-sources/cxf\"\n" + "task generateWadlClient {\n" + " def wadl = \"$projectDir/src/main/resources/wadl/client.xml\"\n" + "\n" + " inputs.file(wadl)\n" + " outputs.dir(wadlGeneratedFolder)\n" + "\n" + " doLast {\n" + " new File(wadlGeneratedFolder).mkdirs()\n" + "\n" + " new WADLToJava([\n" + " \"-d\", wadlGeneratedFolder,\n" + " \"-p\", \"com.application.client.wadl\",\n" + " wadl\n" + " ] as String[]).run(new ToolContext())\n" + " }\n" + "}");
javaMainSourceSets.add("srcDir wadlGeneratedFolder");
javaMainSourceSets.add("project.tasks.compileJava.dependsOn project.tasks.generateWadlClient");
}
final GradleBuild model = new GradleBuild(Versions.KIT, buildConfiguration, dependencies.stream().map(d -> "test".equals(d.getScope()) ? new Dependency(d, "testCompile") : d).map(d -> "runtime".equals(d.getScope()) ? new Dependency(d, "compile") : d).collect(toList()), buildDependencies, configurations, plugins, tasks, imports, javaMainSourceSets);
return new Build(buildConfiguration.getArtifact(), buildConfiguration.getGroup(), buildConfiguration.getVersion(), "src/main/java", "src/test/java", "src/main/resources", "src/test/resources", "src/main/webapp", "build.gradle", tpl.render("generator/gradle/build.mustache", model), "build", generateWrapperFiles());
}
Aggregations