Skip to content

Commit

Permalink
Remove devfile v1 leftovers (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig authored Sep 12, 2024
1 parent 3445db7 commit c2a2fca
Show file tree
Hide file tree
Showing 37 changed files with 53 additions and 2,321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import org.eclipse.che.api.core.rest.MessageBodyAdapterInterceptor;
import org.eclipse.che.api.deploy.jsonrpc.CheJsonRpcWebSocketConfigurationModule;
import org.eclipse.che.api.factory.server.FactoryAcceptValidator;
import org.eclipse.che.api.factory.server.FactoryCreateValidator;
import org.eclipse.che.api.factory.server.FactoryEditValidator;
import org.eclipse.che.api.factory.server.FactoryParametersResolver;
import org.eclipse.che.api.factory.server.RawDevfileUrlFactoryParameterResolver;
import org.eclipse.che.api.factory.server.ScmFileResolver;
Expand Down Expand Up @@ -144,10 +142,6 @@ protected void configure() {
// factory
bind(FactoryAcceptValidator.class)
.to(org.eclipse.che.api.factory.server.impl.FactoryAcceptValidatorImpl.class);
bind(FactoryCreateValidator.class)
.to(org.eclipse.che.api.factory.server.impl.FactoryCreateValidatorImpl.class);
bind(FactoryEditValidator.class)
.to(org.eclipse.che.api.factory.server.impl.FactoryEditValidatorImpl.class);
bind(org.eclipse.che.api.factory.server.FactoryService.class);
bind(ScmService.class);
install(new org.eclipse.che.api.factory.server.jpa.FactoryJpaModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@
import org.eclipse.che.api.factory.server.FactoryParametersResolver;
import org.eclipse.che.api.factory.server.scm.AuthorisationRequestManager;
import org.eclipse.che.api.factory.server.scm.PersonalAccessTokenManager;
import org.eclipse.che.api.factory.server.urlfactory.ProjectConfigDtoMerger;
import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl;
import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder;
import org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto;
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
import org.eclipse.che.api.factory.shared.dto.FactoryMetaDto;
import org.eclipse.che.api.factory.shared.dto.FactoryVisitor;
import org.eclipse.che.api.factory.shared.dto.ScmInfoDto;
import org.eclipse.che.api.workspace.server.devfile.URLFetcher;
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
import org.eclipse.che.api.workspace.shared.dto.SourceStorageDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.ProjectDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.SourceDto;

/**
* Provides Factory Parameters resolver for Azure DevOps repositories.
Expand All @@ -56,11 +51,9 @@ public class AzureDevOpsFactoryParametersResolver extends BaseFactoryParameterRe
private final URLFetcher urlFetcher;
private final URLFactoryBuilder urlFactoryBuilder;
private final PersonalAccessTokenManager personalAccessTokenManager;
private final ProjectConfigDtoMerger projectConfigDtoMerger;

@Inject
public AzureDevOpsFactoryParametersResolver(
ProjectConfigDtoMerger projectConfigDtoMerger,
AzureDevOpsURLParser azureDevOpsURLParser,
URLFetcher urlFetcher,
URLFactoryBuilder urlFactoryBuilder,
Expand All @@ -71,7 +64,6 @@ public AzureDevOpsFactoryParametersResolver(
this.urlFetcher = urlFetcher;
this.urlFactoryBuilder = urlFactoryBuilder;
this.personalAccessTokenManager = personalAccessTokenManager;
this.projectConfigDtoMerger = projectConfigDtoMerger;
}

@Override
Expand Down Expand Up @@ -122,44 +114,6 @@ public FactoryDevfileV2Dto visit(FactoryDevfileV2Dto factoryDto) {
.withBranch(azureDevOpsUrl.getBranch());
return factoryDto.withScmInfo(scmInfo);
}

@Override
public FactoryDto visit(FactoryDto factory) {
if (factory.getWorkspace() != null) {
return projectConfigDtoMerger.merge(
factory,
() -> {
// Compute project configuration
return newDto(ProjectConfigDto.class)
.withSource(buildWorkspaceConfigSource(azureDevOpsUrl))
.withName(azureDevOpsUrl.getRepository())
.withPath("/".concat(azureDevOpsUrl.getRepository()));
});
} else if (factory.getDevfile() == null) {
factory.setDevfile(urlFactoryBuilder.buildDefaultDevfile(azureDevOpsUrl.getRepository()));
}

updateProjects(
factory.getDevfile(),
() ->
newDto(ProjectDto.class)
.withSource(
newDto(SourceDto.class)
.withLocation(azureDevOpsUrl.getRepositoryLocation())
.withType("git")
.withBranch(azureDevOpsUrl.getBranch())
.withTag(azureDevOpsUrl.getTag()))
.withName(azureDevOpsUrl.getRepository()),
project -> {
final String location = project.getSource().getLocation();
if (location.equals(azureDevOpsUrl.getRepositoryLocation())) {
project.getSource().setBranch(azureDevOpsUrl.getBranch());
project.getSource().setTag(azureDevOpsUrl.getTag());
}
});

return factory;
}
}

@Override
Expand Down
4 changes: 0 additions & 4 deletions wsmaster/che-core-api-factory-bitbucket-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@
import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl;
import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder;
import org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto;
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
import org.eclipse.che.api.factory.shared.dto.FactoryMetaDto;
import org.eclipse.che.api.factory.shared.dto.FactoryVisitor;
import org.eclipse.che.api.factory.shared.dto.ScmInfoDto;
import org.eclipse.che.api.workspace.server.devfile.URLFetcher;
import org.eclipse.che.api.workspace.shared.dto.devfile.ProjectDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.SourceDto;

/**
* Provides Factory Parameters resolver for both public and private bitbucket repositories.
Expand Down Expand Up @@ -134,34 +131,6 @@ public FactoryDevfileV2Dto visit(FactoryDevfileV2Dto factoryDto) {
}
return factoryDto.withScmInfo(scmInfo);
}

@Override
public FactoryDto visit(FactoryDto factory) {
if (factory.getDevfile() == null) {
// initialize default devfile
factory.setDevfile(
urlFactoryBuilder.buildDefaultDevfile(bitbucketServerUrl.getRepository()));
}

updateProjects(
factory.getDevfile(),
() ->
newDto(ProjectDto.class)
.withSource(
newDto(SourceDto.class)
.withLocation(bitbucketServerUrl.repositoryLocation())
.withType("git")
.withBranch(bitbucketServerUrl.getBranch()))
.withName(bitbucketServerUrl.getRepository()),
project -> {
final String location = project.getSource().getLocation();
if (location.equals(bitbucketServerUrl.repositoryLocation())) {
project.getSource().setBranch(bitbucketServerUrl.getBranch());
}
});

return factory;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static java.util.Collections.singletonMap;
import static org.eclipse.che.api.factory.shared.Constants.CURRENT_VERSION;
import static org.eclipse.che.api.factory.shared.Constants.URL_PARAMETER_NAME;
import static org.eclipse.che.api.workspace.server.devfile.Constants.CURRENT_API_VERSION;
import static org.eclipse.che.dto.server.DtoFactory.newDto;
import static org.eclipse.che.security.oauth1.OAuthAuthenticationService.ERROR_QUERY_NAME;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -40,12 +39,8 @@
import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl;
import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder;
import org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto;
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
import org.eclipse.che.api.factory.shared.dto.ScmInfoDto;
import org.eclipse.che.api.workspace.server.devfile.URLFetcher;
import org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.MetadataDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.SourceDto;
import org.eclipse.che.security.oauth.OAuthAPI;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
Expand Down Expand Up @@ -131,21 +126,21 @@ public void shouldSetDefaultProjectIntoDevfileIfNotSpecified() throws Exception
String bitbucketUrl =
"http://bitbucket.2mcl.com/users/test/repos/repo/browse?at=refs%2Fheads%2Ffoobar";

FactoryDto computedFactory = generateDevfileFactory();
FactoryDevfileV2Dto factoryDevfileV2Dto = generateDevfileV2Factory();

when(urlFactoryBuilder.createFactoryFromDevfile(
any(RemoteFactoryUrl.class), any(), anyMap(), anyBoolean()))
.thenReturn(Optional.of(computedFactory));
.thenReturn(Optional.of(factoryDevfileV2Dto));

Map<String, String> params = ImmutableMap.of(URL_PARAMETER_NAME, bitbucketUrl);
// when
FactoryDto factory =
(FactoryDto) bitbucketServerFactoryParametersResolver.createFactory(params);
FactoryDevfileV2Dto factory =
(FactoryDevfileV2Dto) bitbucketServerFactoryParametersResolver.createFactory(params);
// then
assertNotNull(factory.getDevfile());
SourceDto source = factory.getDevfile().getProjects().get(0).getSource();
assertEquals(source.getLocation(), "http://bitbucket.2mcl.com/scm/~test/repo.git");
assertEquals(source.getBranch(), "refs%2Fheads%2Ffoobar");
ScmInfoDto source = factory.getScmInfo();
assertEquals(source.getRepositoryUrl(), "http://bitbucket.2mcl.com/scm/~test/repo.git");
assertEquals(source.getBranch(), "foobar");
}

@Test
Expand All @@ -172,16 +167,6 @@ public void shouldSetScmInfoIntoDevfileV2() throws Exception {
assertEquals(scmInfo.getBranch(), "foobar");
}

private FactoryDto generateDevfileFactory() {
return newDto(FactoryDto.class)
.withV(CURRENT_VERSION)
.withSource("repo")
.withDevfile(
newDto(DevfileDto.class)
.withApiVersion(CURRENT_API_VERSION)
.withMetadata(newDto(MetadataDto.class).withName("che")));
}

private FactoryDevfileV2Dto generateDevfileV2Factory() {
return newDto(FactoryDevfileV2Dto.class)
.withV(CURRENT_VERSION)
Expand All @@ -197,7 +182,7 @@ public void shouldCreateFactoryWithoutAuthentication() throws ApiException {
ImmutableMap.of(URL_PARAMETER_NAME, bitbucketServerUrl, ERROR_QUERY_NAME, "access_denied");
when(urlFactoryBuilder.createFactoryFromDevfile(
any(RemoteFactoryUrl.class), any(), anyMap(), anyBoolean()))
.thenReturn(Optional.of(generateDevfileFactory()));
.thenReturn(Optional.of(generateDevfileV2Factory()));

// when
bitbucketServerFactoryParametersResolver.createFactory(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@
import org.eclipse.che.api.factory.server.FactoryParametersResolver;
import org.eclipse.che.api.factory.server.scm.AuthorisationRequestManager;
import org.eclipse.che.api.factory.server.scm.PersonalAccessTokenManager;
import org.eclipse.che.api.factory.server.urlfactory.ProjectConfigDtoMerger;
import org.eclipse.che.api.factory.server.urlfactory.RemoteFactoryUrl;
import org.eclipse.che.api.factory.server.urlfactory.URLFactoryBuilder;
import org.eclipse.che.api.factory.shared.dto.FactoryDevfileV2Dto;
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
import org.eclipse.che.api.factory.shared.dto.FactoryMetaDto;
import org.eclipse.che.api.factory.shared.dto.FactoryVisitor;
import org.eclipse.che.api.factory.shared.dto.ScmInfoDto;
import org.eclipse.che.api.workspace.server.devfile.URLFetcher;
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.ProjectDto;

/** Provides Factory Parameters resolver for bitbucket repositories. */
@Singleton
Expand All @@ -51,8 +47,6 @@ public class BitbucketFactoryParametersResolver extends BaseFactoryParameterReso
private final BitbucketSourceStorageBuilder bitbucketSourceStorageBuilder;

private final URLFactoryBuilder urlFactoryBuilder;
/** ProjectDtoMerger */
private final ProjectConfigDtoMerger projectConfigDtoMerger;

/** Personal Access Token manager used when fetching protected content. */
private final PersonalAccessTokenManager personalAccessTokenManager;
Expand All @@ -65,7 +59,6 @@ public BitbucketFactoryParametersResolver(
URLFetcher urlFetcher,
BitbucketSourceStorageBuilder bitbucketSourceStorageBuilder,
URLFactoryBuilder urlFactoryBuilder,
ProjectConfigDtoMerger projectConfigDtoMerger,
PersonalAccessTokenManager personalAccessTokenManager,
BitbucketApiClient bitbucketApiClient,
AuthorisationRequestManager authorisationRequestManager) {
Expand All @@ -74,7 +67,6 @@ public BitbucketFactoryParametersResolver(
this.urlFetcher = urlFetcher;
this.bitbucketSourceStorageBuilder = bitbucketSourceStorageBuilder;
this.urlFactoryBuilder = urlFactoryBuilder;
this.projectConfigDtoMerger = projectConfigDtoMerger;
this.personalAccessTokenManager = personalAccessTokenManager;
this.bitbucketApiClient = bitbucketApiClient;
}
Expand Down Expand Up @@ -142,40 +134,6 @@ public FactoryDevfileV2Dto visit(FactoryDevfileV2Dto factoryDto) {
}
return factoryDto.withScmInfo(scmInfo);
}

@Override
public FactoryDto visit(FactoryDto factory) {
if (factory.getWorkspace() != null) {
return projectConfigDtoMerger.merge(
factory,
() -> {
// Compute project configuration
return newDto(ProjectConfigDto.class)
.withSource(
bitbucketSourceStorageBuilder.buildWorkspaceConfigSource(bitbucketUrl))
.withName(bitbucketUrl.getRepository())
.withPath("/".concat(bitbucketUrl.getRepository()));
});
} else if (factory.getDevfile() == null) {
// initialize default devfile
factory.setDevfile(urlFactoryBuilder.buildDefaultDevfile(bitbucketUrl.getRepository()));
}

updateProjects(
factory.getDevfile(),
() ->
newDto(ProjectDto.class)
.withSource(bitbucketSourceStorageBuilder.buildDevfileSource(bitbucketUrl))
.withName(bitbucketUrl.getRepository()),
project -> {
final String location = project.getSource().getLocation();
if (location.equals(bitbucketUrl.repositoryLocation())) {
project.getSource().setBranch(bitbucketUrl.getBranch());
}
});

return factory;
}
}

@Override
Expand Down
Loading

0 comments on commit c2a2fca

Please sign in to comment.