@Override public boolean isTargetItemPresent(Property<?> targetItem) { return targetItem != null && !targetItem.isEmpty(); } }
protected void validateIssue(I issue, List<Property<?>> properties, SCMChangeLog<T> changeLog) { for (Property<?> property : properties) { if (!property.isEmpty()) { validateIssue(issue, property, changeLog); } } }
/** * Tests if a property is defined. */ default <T> boolean hasProperty(ProjectEntity entity, Class<? extends PropertyType<T>> propertyTypeClass) { return !getProperty(entity, propertyTypeClass).isEmpty(); }
/** * Checks that the project is properly configured with a SVN configuration. */ @Override public boolean apply(Project project) { return !propertyService.getProperty(project, SVNProjectConfigurationPropertyType.class).isEmpty(); } }
public static boolean hasProperty(PropertyService propertyService, ProjectEntity entity, String propertyTypeName, String propertyValue) { try { Property<?> property = propertyService.getProperty(entity, propertyTypeName); return !property.isEmpty() && ( StringUtils.isBlank(propertyValue) || property.containsValue(propertyValue)); } catch (PropertyTypeNotFoundException ex) { return false; } }
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { // Argument check Validate.isTrue(entity instanceof Build, "Expecting build"); // Gets the `release` property Property<ReleaseProperty> property = propertyService.getProperty(entity, ReleasePropertyType.class); if (property.isEmpty()) { return Collections.emptyList(); } else { return Collections.singletonList( Decoration.of( this, property.getValue().getName() ) ); } }
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { Property<SVNProjectConfigurationProperty> property = propertyService.getProperty(entity, SVNProjectConfigurationPropertyType.class); if (!property.isEmpty()) { return Collections.singletonList( Decoration.of( this, property.getValue().getUrl() ) ); } else { return Collections.emptyList(); } }
protected <T> void doCopyProperty(ProjectEntity sourceEntity, Property<T> property, ProjectEntity targetEntity, Function<String, String> replacementFn) { if (!property.isEmpty() && property.getType().canEdit(targetEntity, securityService)) { // Copy of the property propertyService.copyProperty( sourceEntity, property, targetEntity, replacementFn ); } }
protected void validateIssues(List<I> issuesList, SCMChangeLog<T> changeLog) { // Same branch only if (changeLog.isSameBranch()) { // Gets the branch Branch branch = changeLog.getFrom().getBuild().getBranch(); // Gets the list of validators for this branch List<Property<?>> properties = propertyService.getProperties(branch).stream() .filter(property -> !property.isEmpty() && property.getType() instanceof SCMChangeLogIssueValidator) .collect(Collectors.toList()); // Validates each issues issuesList.forEach(issue -> validateIssue(issue, properties, changeLog)); } }
protected @Nullable Build lookupBuild(SVNLocation location, SVNLocation firstCopy, Branch branch) { // Gets the SVN configuration for the branch Property<SVNBranchConfigurationProperty> configurationProperty = propertyService.getProperty(branch, SVNBranchConfigurationPropertyType.class); if (configurationProperty.isEmpty()) { return null; } // Gets the build link ConfiguredBuildSvnRevisionLink<Object> revisionLink = buildSvnRevisionLinkService.getConfiguredBuildSvnRevisionLink( configurationProperty.getValue().getBuildRevisionLink() ); // Gets the earliest build return revisionLink.getEarliestBuild(branch, location, firstCopy, configurationProperty.getValue()).orElse(null); }
@Override public void forEachConfiguredBranch( Predicate<SVNProjectConfigurationProperty> projectConfigurationPredicate, BiConsumer<Branch, SVNBranchConfigurationProperty> branchConsumer) { // Loops over all authorised branches for (Project project : structureService.getProjectList()) { // Filter on SVN configuration: must be present and equal to the one the revision info is looked into Property<SVNProjectConfigurationProperty> projectSvnConfig = propertyService.getProperty(project, SVNProjectConfigurationPropertyType.class); if (!projectSvnConfig.isEmpty() && projectConfigurationPredicate.test(projectSvnConfig.getValue())) { structureService.getBranchesForProject(project.getId()).stream() .filter(branch -> propertyService.hasProperty(branch, SVNBranchConfigurationPropertyType.class)) .forEach(branch -> { // Branch configuration SVNBranchConfigurationProperty branchConfiguration = propertyService.getProperty(branch, SVNBranchConfigurationPropertyType.class).getValue(); // OK branchConsumer.accept(branch, branchConfiguration); }); } } }
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { Property<GitHubProjectConfigurationProperty> property = propertyService.getProperty(entity, GitHubProjectConfigurationPropertyType.class); if (!property.isEmpty()) { return Collections.singletonList( Decoration.of( this, String.format( "%s @ %s", property.getValue().getRepository(), property.getValue().getConfiguration().getName() ) ) ); } else { return Collections.emptyList(); } }
@Override public Optional<SVNRepository> getSVNRepository(Branch branch) { // Gets the SVN project configuration property Property<SVNProjectConfigurationProperty> projectConfiguration = propertyService.getProperty( branch.getProject(), SVNProjectConfigurationPropertyType.class ); if (projectConfiguration.isEmpty()) { return Optional.empty(); } else { SVNConfiguration configuration = projectConfiguration.getValue().getConfiguration(); return Optional.of( getRepository(configuration.getName()) ); } }
private JobRegistration getSVNBuildSyncJobRegistration(Branch branch) { Property<SVNSyncProperty> svnSync = propertyService.getProperty(branch, SVNSyncPropertyType.class); if (svnSync.isEmpty()) { throw new IllegalStateException("No SVN build sync is set"); } else { return JobRegistration.of(createJob(branch)) .everyMinutes(svnSync.getValue().getInterval()); } }
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { Property<GitLabProjectConfigurationProperty> property = propertyService.getProperty(entity, GitLabProjectConfigurationPropertyType.class); if (!property.isEmpty()) { return Collections.singletonList( Decoration.of( this, String.format( "%s @ %s", property.getValue().getRepository(), property.getValue().getConfiguration().getName() ) ) ); } else { return Collections.emptyList(); } }
@Override public List<Decoration<String>> getDecorations(ProjectEntity entity) { Property<StashProjectConfigurationProperty> property = propertyService.getProperty(entity, StashProjectConfigurationPropertyType.class); if (!property.isEmpty()) { return Collections.singletonList( Decoration.of( this, String.format( "%s/%s @ %s", property.getValue().getProject(), property.getValue().getRepository(), property.getValue().getConfiguration().getName() ) ) ); } else { return Collections.emptyList(); } }
@Override public List<Decoration<JenkinsJob>> getDecorations(ProjectEntity entity) { // Gets the Jenkins Job property for this entity, if any Property<JenkinsJobProperty> property = propertyService.getProperty(entity, JenkinsJobPropertyType.class.getName()); if (property.isEmpty()) { return Collections.emptyList(); } else { // Template branch? Decoration cannot be computed if (entity instanceof Branch && ((Branch) entity).getType() == BranchType.TEMPLATE_DEFINITION) { return Collections.emptyList(); } // Gets a client // FIXME getJob does not need a full HTTP client JenkinsClient jenkinsClient = jenkinsClientFactory.getClient(property.getValue().getConfiguration()); // Gets the Jenkins job JenkinsJob job = jenkinsClient.getJob(property.getValue().getJob()); // Gets the decoration for the job return Collections.singletonList( getDecoration(job) ); } }
private <T> boolean matchProperty(ProjectEntity e, PropertyFilter filter) { PropertyType<T> type = propertyService.getPropertyTypeByName(filter.getType()); Property<T> property = propertyService.getProperty(e, filter.getType()); return !property.isEmpty() && ( StringUtils.isBlank(filter.getValue()) || type.containsValue(property.getValue(), filter.getValue()) ); }
@Override public OptionalLong getBuildRevision(Build build) { // Gets the branch SVN information Property<SVNBranchConfigurationProperty> branchConfigurationProperty = propertyService.getProperty(build.getBranch(), SVNBranchConfigurationPropertyType.class); Property<SVNProjectConfigurationProperty> projectConfigurationProperty = propertyService.getProperty(build.getBranch().getProject(), SVNProjectConfigurationPropertyType.class); if (branchConfigurationProperty.isEmpty() || projectConfigurationProperty.isEmpty()) { return OptionalLong.empty(); } else { // Gets the branch revision link ConfiguredBuildSvnRevisionLink<Object> revisionLink = buildSvnRevisionLinkService.getConfiguredBuildSvnRevisionLink( branchConfigurationProperty.getValue().getBuildRevisionLink() ); // Returns revision information return revisionLink.getRevision(build, branchConfigurationProperty.getValue()); } }
protected String getSVNBuildPath(Build build) { // Gets the build path property value Property<SVNBranchConfigurationProperty> branchConfiguration = propertyService.getProperty( build.getBranch(), SVNBranchConfigurationPropertyType.class ); if (branchConfiguration.isEmpty()) { throw new MissingSVNBranchConfigurationException(build.getBranch().getName()); } else { // Gets the build revision link ConfiguredBuildSvnRevisionLink<Object> revisionLink = buildSvnRevisionLinkService.getConfiguredBuildSvnRevisionLink( branchConfiguration.getValue().getBuildRevisionLink() ); // Gets the path to the build return revisionLink.getBuildPath(build, branchConfiguration.getValue()); } }