Skip to content

Commit

Permalink
Make devfile API do not use generated POJOs
Browse files Browse the repository at this point in the history
Signed-off-by: Sergii Leshchenko <sleshche@redhat.com>
  • Loading branch information
sleshchenko committed Apr 2, 2019
1 parent 4957200 commit bbad97e
Show file tree
Hide file tree
Showing 40 changed files with 564 additions and 772 deletions.
48 changes: 0 additions & 48 deletions wsmaster/che-core-api-devfile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
<packaging>jar</packaging>
<name>Che Core :: API :: Devfile</name>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down Expand Up @@ -59,10 +55,6 @@
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
Expand Down Expand Up @@ -181,46 +173,6 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>generate-pojo</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/java-gen</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>0.5.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<targetPackage>org.eclipse.che.api.devfile.model</targetPackage>
<includeAdditionalProperties>false</includeAdditionalProperties>
<includeHashcodeAndEquals>true</includeHashcodeAndEquals>
<includeToString>true</includeToString>
<initializeCollections>true</initializeCollections>
<generateBuilders>true</generateBuilders>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*/
package org.eclipse.che.api.devfile.server;

import org.eclipse.che.api.devfile.model.Endpoint;

public class Constants {

private Constants() {}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Collections.emptyMap;
import static org.eclipse.che.api.devfile.server.DevfileFactory.initializeMaps;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -27,7 +26,6 @@
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.ValidationException;
import org.eclipse.che.api.devfile.model.Devfile;
import org.eclipse.che.api.devfile.server.convert.DevfileConverter;
import org.eclipse.che.api.devfile.server.exception.DevfileException;
import org.eclipse.che.api.devfile.server.exception.DevfileFormatException;
Expand All @@ -37,6 +35,7 @@
import org.eclipse.che.api.workspace.server.WorkspaceManager;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl;
import org.eclipse.che.commons.env.EnvironmentContext;

/**
Expand Down Expand Up @@ -83,24 +82,23 @@ public DevfileManager(
}

/**
* Creates {@link Devfile} from given devfile content. Performs schema and integrity validation of
* input data.
* Creates {@link DevfileImpl} from given devfile content. Performs schema and integrity
* validation of input data.
*
* @param devfileContent raw content of devfile
* @return Devfile object created from the source content
* @throws DevfileFormatException when any of schema or integrity validations fail
* @throws DevfileFormatException when any yaml parsing error occurs
*/
public Devfile parse(String devfileContent) throws DevfileFormatException {
public DevfileImpl parse(String devfileContent) throws DevfileFormatException {
JsonNode parsed = schemaValidator.validateBySchema(devfileContent);

Devfile devfile;
DevfileImpl devfile;
try {
devfile = objectMapper.treeToValue(parsed, Devfile.class);
devfile = objectMapper.treeToValue(parsed, DevfileImpl.class);
} catch (JsonProcessingException e) {
throw new DevfileFormatException(e.getMessage());
}
initializeMaps(devfile);

integrityValidator.validateDevfile(devfile);
return devfile;
Expand All @@ -120,7 +118,7 @@ public Devfile parse(String devfileContent) throws DevfileFormatException {
* @throws NotFoundException when user account is not found
* @throws ServerException when other error occurs
*/
public WorkspaceImpl createWorkspace(Devfile devfile, FileContentProvider fileContentProvider)
public WorkspaceImpl createWorkspace(DevfileImpl devfile, FileContentProvider fileContentProvider)
throws ServerException, ConflictException, NotFoundException, ValidationException,
DevfileException {
checkArgument(devfile != null, "Devfile must not be null");
Expand All @@ -143,7 +141,7 @@ public WorkspaceImpl createWorkspace(Devfile devfile, FileContentProvider fileCo
* @throws DevfileException when any another devfile related error occurs
*/
public WorkspaceConfigImpl createWorkspaceConfig(
Devfile devfile, FileContentProvider fileContentProvider)
DevfileImpl devfile, FileContentProvider fileContentProvider)
throws DevfileFormatException, DevfileRecipeFormatException, DevfileException {
checkArgument(devfile != null, "Devfile must not be null");
checkArgument(fileContentProvider != null, "File content provider must not be null");
Expand All @@ -165,7 +163,7 @@ public WorkspaceConfigImpl createWorkspaceConfig(
* @throws ServerException when other error occurs
* @see WorkspaceManager#getByKey(String)
*/
public Devfile exportWorkspace(String key)
public DevfileImpl exportWorkspace(String key)
throws NotFoundException, ServerException, ConflictException {
WorkspaceImpl workspace = workspaceManager.getWorkspace(key);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.ValidationException;
import org.eclipse.che.api.core.rest.Service;
import org.eclipse.che.api.devfile.model.Devfile;
import org.eclipse.che.api.devfile.server.exception.DevfileException;
import org.eclipse.che.api.devfile.server.schema.DevfileSchemaProvider;
import org.eclipse.che.api.workspace.server.WorkspaceLinksGenerator;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto;

@Api(value = "/devfile", description = "Devfile REST API")
Expand Down Expand Up @@ -120,7 +120,7 @@ public Response createFromYaml(String data)

WorkspaceImpl workspace;
try {
Devfile devfile = devfileManager.parse(data);
DevfileImpl devfile = devfileManager.parse(data);
workspace = devfileManager.createWorkspace(devfile, urlFileContentProvider);
} catch (DevfileException e) {
throw new BadRequestException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.eclipse.che.api.devfile.server.exception.DevfileException;

/**
* Some types of {@link org.eclipse.che.api.devfile.model.Component} may have configuration located
* in a separate file. It fetches content of file by its name.
* Some types of {@link org.eclipse.che.api.core.model.workspace.devfile.Component} may have
* configuration located in a separate file. It fetches content of file by its name.
*
* @author Max Shaposhnyk
* @author Sergii Leshchenko
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import static java.lang.String.format;
import static org.eclipse.che.api.core.model.workspace.config.Command.WORKING_DIRECTORY_ATTRIBUTE;

import org.eclipse.che.api.devfile.model.Action;
import org.eclipse.che.api.devfile.model.Command;
import org.eclipse.che.api.core.model.workspace.devfile.Action;
import org.eclipse.che.api.core.model.workspace.devfile.Command;
import org.eclipse.che.api.devfile.server.Constants;
import org.eclipse.che.api.devfile.server.exception.DevfileFormatException;
import org.eclipse.che.api.devfile.server.exception.WorkspaceExportException;
import org.eclipse.che.api.workspace.server.model.impl.CommandImpl;
import org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl;
import org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl;

/**
* Helps to convert {@link CommandImpl workspace command} to {@link Command devfile command} and
Expand All @@ -37,7 +38,9 @@ public class CommandConverter {
* @throws WorkspaceExportException if workspace command does not has specified component name
* attribute where it should be run
*/
public Command toDevfileCommand(CommandImpl command) throws WorkspaceExportException {
public CommandImpl toDevfileCommand(
org.eclipse.che.api.workspace.server.model.impl.CommandImpl command)
throws WorkspaceExportException {
String componentName =
command.getAttributes().remove(Constants.COMPONENT_NAME_COMMAND_ATTRIBUTE);
if (componentName == null) {
Expand All @@ -46,8 +49,11 @@ public Command toDevfileCommand(CommandImpl command) throws WorkspaceExportExcep
"Command `%s` has no specified component where it should be run", command.getName()));
}

Command devCommand = new Command().withName(command.getName());
Action action = new Action().withCommand(command.getCommandLine()).withType(command.getType());
CommandImpl devCommand = new CommandImpl();
devCommand.setName(command.getName());
ActionImpl action = new ActionImpl();
action.setCommand(command.getCommandLine());
action.setType(command.getType());
action.setWorkdir(command.getAttributes().remove(WORKING_DIRECTORY_ATTRIBUTE));
action.setComponent(componentName);
action.setType(Constants.EXEC_ACTION_TYPE);
Expand All @@ -64,7 +70,8 @@ public Command toDevfileCommand(CommandImpl command) throws WorkspaceExportExcep
* @throws DevfileFormatException if devfile command does not have any action
* @throws DevfileFormatException if devfile command has more than one action
*/
public CommandImpl toWorkspaceCommand(Command devfileCommand) throws DevfileFormatException {
public org.eclipse.che.api.workspace.server.model.impl.CommandImpl toWorkspaceCommand(
Command devfileCommand) throws DevfileFormatException {
if (devfileCommand.getActions().size() != 1) {
throw new DevfileFormatException(
format("Command `%s` MUST has one and only one action", devfileCommand.getName()));
Expand All @@ -75,8 +82,10 @@ public CommandImpl toWorkspaceCommand(Command devfileCommand) throws DevfileForm
return toWorkspaceCommand(devfileCommand, commandAction);
}

private CommandImpl toWorkspaceCommand(Command devCommand, Action commandAction) {
CommandImpl command = new CommandImpl();
private org.eclipse.che.api.workspace.server.model.impl.CommandImpl toWorkspaceCommand(
Command devCommand, Action commandAction) {
org.eclipse.che.api.workspace.server.model.impl.CommandImpl command =
new org.eclipse.che.api.workspace.server.model.impl.CommandImpl();
command.setName(devCommand.getName());
command.setType(commandAction.getType());
command.setCommandLine(commandAction.getCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.che.api.devfile.model.Component;
import org.eclipse.che.api.devfile.model.Devfile;
import org.eclipse.che.api.core.model.workspace.devfile.Component;
import org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl;
import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl;
import org.eclipse.che.commons.lang.NameGenerator;

/**
Expand Down Expand Up @@ -58,7 +59,7 @@ public DefaultEditorProvisioner(
*
* @param devfile devfile where editor and plugins should be provisioned
*/
public void apply(Devfile devfile) {
public void apply(DevfileImpl devfile) {
if (defaultEditorRef == null) {
// there is no default editor configured
return;
Expand All @@ -68,20 +69,20 @@ public void apply(Devfile devfile) {
return;
}

List<Component> components = devfile.getComponents();
List<ComponentImpl> components = devfile.getComponents();
Set<String> componentsNames =
components.stream().map(Component::getName).collect(Collectors.toCollection(HashSet::new));

Optional<Component> editorOpt =
Optional<ComponentImpl> editorOpt =
components.stream().filter(t -> EDITOR_COMPONENT_TYPE.equals(t.getType())).findFirst();

boolean isDefaultEditorUsed;
if (!editorOpt.isPresent()) {
components.add(
new Component()
.withName(findAvailableName(componentsNames, defaultEditorRef))
.withType(EDITOR_COMPONENT_TYPE)
.withId(defaultEditorRef));
new ComponentImpl(
EDITOR_COMPONENT_TYPE,
findAvailableName(componentsNames, defaultEditorRef),
defaultEditorRef));
isDefaultEditorUsed = true;
} else {
Component editor = editorOpt.get();
Expand All @@ -93,7 +94,8 @@ public void apply(Devfile devfile) {
}
}

private void provisionDefaultPlugins(List<Component> components, Set<String> componentsNames) {
private void provisionDefaultPlugins(
List<ComponentImpl> components, Set<String> componentsNames) {
Map<String, String> missingPluginsIdToRef = new HashMap<>(defaultPluginsIdToRef);

components
Expand All @@ -106,10 +108,10 @@ private void provisionDefaultPlugins(List<Component> components, Set<String> com
.forEach(
pluginRef ->
components.add(
new Component()
.withType(PLUGIN_COMPONENT_TYPE)
.withId(pluginRef)
.withName(findAvailableName(componentsNames, pluginRef))));
new ComponentImpl(
PLUGIN_COMPONENT_TYPE,
findAvailableName(componentsNames, pluginRef),
pluginRef)));
}

/**
Expand Down
Loading

0 comments on commit bbad97e

Please sign in to comment.