Java Code Examples for hudson.model.AbstractProject

The following examples show how to use hudson.model.AbstractProject. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: warnings-ng-plugin   Source File: ModelValidation.java    License: MIT License 6 votes vote down vote up
/**
 * Performs on-the-fly validation on the ant pattern for input files.
 *
 * @param project
 *         the project
 * @param pattern
 *         the file pattern
 *
 * @return the validation result
 */
public FormValidation doCheckPattern(@AncestorInPath final AbstractProject<?, ?> project,
        @QueryParameter final String pattern) {
    if (project != null) { // there is no workspace in pipelines
        try {
            FilePath workspace = project.getSomeWorkspace();
            if (workspace != null && workspace.exists()) {
                return validatePatternInWorkspace(pattern, workspace);
            }
        }
        catch (InterruptedException | IOException ignore) {
            // ignore and return ok
        }
    }

    return FormValidation.ok();
}
 
Example 2
Source Project: warnings-ng-plugin   Source File: ModelValidation.java    License: MIT License 6 votes vote down vote up
/**
 * Performs on-the-fly validation on the source code directory.
 *
 * @param project
 *         the project
 * @param sourceDirectory
 *         the file pattern
 *
 * @return the validation result
 */
public FormValidation doCheckSourceDirectory(@AncestorInPath final AbstractProject<?, ?> project,
        @QueryParameter final String sourceDirectory) {
    if (project != null) { // there is no workspace in pipelines
        try {
            FilePath workspace = project.getSomeWorkspace();
            if (workspace != null && workspace.exists()) {
                return validateRelativePath(sourceDirectory, workspace);
            }
        }
        catch (InterruptedException | IOException ignore) {
            // ignore and return ok
        }
    }

    return FormValidation.ok();
}
 
Example 3
Source Project: github-integration-plugin   Source File: JobHelper.java    License: MIT License 6 votes vote down vote up
/**
 * support matrix plugin.
 *
 * @see JobInfoHelpers#triggerFrom(hudson.model.Job, java.lang.Class)
 */
@CheckForNull
public static <T extends Trigger> T triggerFrom(final Job<?, ?> job, Class<T> tClass) {
    Job<?, ?> guessJob;
    if (job instanceof MatrixConfiguration) {
        guessJob = ((MatrixConfiguration) job).getParent();
    } else {
        guessJob = job;
    }

    if (guessJob instanceof AbstractProject<?, ?>) {
        final AbstractProject<?, ?> abstractProject = (AbstractProject<?, ?>) guessJob;
        return abstractProject.getTrigger(tClass);
    } else if (guessJob instanceof ParameterizedJobMixIn.ParameterizedJob) {
        ParameterizedJobMixIn.ParameterizedJob pJob = (ParameterizedJobMixIn.ParameterizedJob) guessJob;

        for (Object candidate : pJob.getTriggers().values()) {
            if (tClass.isInstance(candidate)) {
                return tClass.cast(candidate);
            }
        }
    }
    return null;
}
 
Example 4
Source Project: junit-plugin   Source File: AggregatedTestResultPublisher.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation") // calls getProject in constructor, so needs owner immediately
public TestResultAction(String jobs, boolean includeFailedBuilds, AbstractBuild<?,?> owner) {
    super(owner);
    this.includeFailedBuilds = includeFailedBuilds;
    
    if(jobs==null) {
        // resolve null as the transitive downstream jobs
        StringBuilder buf = new StringBuilder();
        for (AbstractProject p : getProject().getTransitiveDownstreamProjects()) {
            if(buf.length()>0)  buf.append(',');
            buf.append(p.getFullName());
        }
        jobs = buf.toString();
    }
    this.jobs = jobs;
}
 
Example 5
/**
 * Returns the most recent build which contained an AWS Device Farm test run.
 *
 * @param project The Jenkins project which contains runs to examine.
 * @return The previous Device Farm build.
 */
public static AbstractBuild<?, ?> previousAWSDeviceFarmBuild(AbstractProject<?, ?> project) {
    AbstractBuild<?, ?> last = project.getLastBuild();
    while (last != null) {
        if (last.getAction(AWSDeviceFarmTestResultAction.class) != null) {
            break;
        }
        last = last.getPreviousBuild();
    }
    return last;
}
 
Example 6
Source Project: docker-swarm-plugin   Source File: DockerSwarmComputerLauncher.java    License: MIT License 5 votes vote down vote up
public DockerSwarmComputerLauncher(final Queue.BuildableItem bi) {
    super(DockerSwarmCloud.get().getTunnel(), null, new RemotingWorkDirSettings(false, "/tmp", null, false));
    this.bi = bi;
    this.label = bi.task.getAssignedLabel().getName();
    this.jobName = bi.task instanceof AbstractProject ? ((AbstractProject) bi.task).getFullName()
            : bi.task.getName();
}
 
Example 7
Source Project: DotCi   Source File: DbBackedBuild.java    License: MIT License 5 votes vote down vote up
@Deprecated
// Keeping this so we can more easily migrate from existing systems
public void restoreFromDb(final AbstractProject project, final Map<String, Object> input) {
    this.id = (ObjectId) input.get("_id");

    final String state = ((String) input.get("state"));
    setField(getState(state), "state");

    final Date date = ((Date) input.get("last_updated"));
    setField(date.getTime(), "timestamp");

    setField(project, "project");

    super.onLoad();
}
 
Example 8
Source Project: ez-templates   Source File: TemplateProjectListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onUpdated(Item item) {
    TemplateProperty property = getTemplateProperty(item);
    if (property != null) {
        try {
            TemplateUtils.handleTemplateSaved((AbstractProject) item, property);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
}
 
Example 9
/**
 * @param item A changed project
 * @return null if this is not a template implementation project
 */
private static TemplateImplementationProperty getTemplateImplementationProperty(Item item) {
    if (item instanceof AbstractProject) {
        return (TemplateImplementationProperty) ((AbstractProject) item).getProperty(TemplateImplementationProperty.class);
    }
    return null;
}
 
Example 10
Source Project: ez-templates   Source File: TemplateProperty.java    License: Apache License 2.0 5 votes vote down vote up
public static Collection<AbstractProject> getImplementations(final String templateFullName) {
    Collection<AbstractProject> projects = ProjectUtils.findProjectsWithProperty(TemplateImplementationProperty.class);
    return Collections2.filter(projects, new Predicate<AbstractProject>() {
        public boolean apply(AbstractProject abstractProject) {
            TemplateImplementationProperty prop = (TemplateImplementationProperty) abstractProject.getProperty(TemplateImplementationProperty.class);
            return templateFullName.equals(prop.getTemplateJobName());
        }
    });

}
 
Example 11
@Override
public void start(AbstractProject project, boolean newInstance) {
	this.job = project;

	try {// reparse the tabs with the job as the hash
		cronTabList = ParameterizedCronTabList.create(parameterizedSpecification, Hash.from(project.getFullName()));
	} catch (ANTLRException e) {
		// this shouldn't fail because we've already parsed stuff in the constructor,
		// so if it fails, use whatever 'tabs' that we already have.
		LOGGER.log(Level.FINE, "Failed to parse crontab spec: " + spec, e);
	}
}
 
Example 12
/**
 * Jenkins-convention to populate the drop-down box with discovered templates
 */
@SuppressWarnings("UnusedDeclaration")
public ListBoxModel doFillTemplateJobNameItems() {
    ListBoxModel items = new ListBoxModel();
    // Add null as first option - dangerous to force an existing project onto a template in case
    // a noob destroys their config
    items.add(Messages.TemplateImplementationProperty_noTemplateSelected(), null);
    // Add all discovered templates
    for (AbstractProject project : ProjectUtils.findProjectsWithProperty(TemplateProperty.class)) {
        // fullName includes any folder structure
        items.add(project.getFullDisplayName(), project.getFullName());
    }
    return items;
}
 
Example 13
Source Project: jenkins-mattermost-plugin   Source File: MattermostListener.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
FineGrainedNotifier getNotifier(AbstractProject project, TaskListener listener) {
  Map<Descriptor<Publisher>, Publisher> map = project.getPublishersList().toMap();
  for (Publisher publisher : map.values()) {
    if (publisher instanceof MattermostNotifier) {
      return new ActiveNotifier((MattermostNotifier) publisher, (BuildListener) listener, new JenkinsTokenExpander(listener));
    }
  }
  return new DisabledNotifier();
}
 
Example 14
Source Project: ez-templates   Source File: ProjectUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get a project by its fullName (including any folder structure if present).
 * Temporarily also allows a match by name if one exists.
 */
public static AbstractProject findProject(String fullName) {
    List<AbstractProject> projects = Jenkins.getInstance().getAllItems(AbstractProject.class);
    AbstractProject nameOnlyMatch = null; // marc: 20140831, Remove compat patch for users upgrading
    for (AbstractProject project : projects) {
        if (fullName.equals(project.getFullName())) {
            return project;
        }
        if (fullName.equals(project.getName())) {
            nameOnlyMatch = project;
        }
    }
    return nameOnlyMatch;
}
 
Example 15
Source Project: blueocean-plugin   Source File: Disabler.java    License: MIT License 5 votes vote down vote up
public static void makeDisabled(Object item, boolean b) throws IOException {
    if (item instanceof AbstractFolder) {
        Disabler.makeDisabled((AbstractFolder) item, b);
    }
    if (item instanceof AbstractProject) {
        Disabler.makeDisabled((AbstractProject) item, b);
    }
    if (item instanceof ParameterizedJobMixIn.ParameterizedJob ) {
        Disabler.makeDisabled((ParameterizedJobMixIn.ParameterizedJob ) item, b);
    }
}
 
Example 16
Source Project: blueocean-plugin   Source File: Disabler.java    License: MIT License 5 votes vote down vote up
@SuppressFBWarnings(value = "NP_BOOLEAN_RETURN_NULL", justification = "isDisabled will return null if the job type doesn't support it")
public static Boolean isDisabled(Object item) {
    if (item instanceof AbstractFolder) {
        return Disabler.isDisabled((AbstractFolder) item);
    }
    if (item instanceof AbstractProject) {
        return Disabler.isDisabled((AbstractProject) item);
    }
    if (item instanceof ParameterizedJobMixIn.ParameterizedJob ) {
        return Disabler.isDisabled((ParameterizedJobMixIn.ParameterizedJob ) item);
    }
    return null;
}
 
Example 17
@Override
public void onUpdated(Item item) {
    TemplateImplementationProperty property = getTemplateImplementationProperty(item);
    if (property != null) {
        try {
            TemplateUtils.handleTemplateImplementationSaved((AbstractProject) item, property);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
}
 
Example 18
@Test(expected=InvalidInputException.class)
public void testNonExistentCreds() {
    String credentialsId = "folder-creds";
    String folder = "folder";

    when(CredentialsMatchers.firstOrNull(any(Iterable.class), any(CredentialsMatcher.class))).thenReturn(null);

    Jenkins mockInstance = mock(Jenkins.class);
    Item mockFolder = mock(Item.class);
    PowerMockito.mockStatic(Jenkins.class);
    when(Jenkins.getInstance()).thenReturn(mockInstance);
    when(mockInstance.getItemByFullName(credentialsId)).thenReturn(mockFolder);

    PowerMockito.mockStatic(CredentialsProvider.class);

    AbstractProject mockProject = mock(AbstractProject.class);
    ItemGroup mockFolderItem = mock(ItemGroup.class);

    when(build.getParent()).thenReturn(mockProject);
    when(mockProject.getParent()).thenReturn(mockFolderItem);
    when(mockFolder.getFullName()).thenReturn(folder);

    try {
        new AWSClientFactory("jenkins", credentialsId, "", "", "", null, "", REGION, build, null);
    } catch (InvalidInputException e) {
        assert(e.getMessage().contains(CodeBuilderValidation.invalidCredentialsIdError));
        throw e;
    }
}
 
Example 19
Source Project: gitlab-plugin   Source File: TestUtility.java    License: GNU General Public License v2.0 5 votes vote down vote up
static AbstractBuild mockSimpleBuild(String gitLabConnection, Result result, String... remoteUrls) {
    AbstractBuild build = mock(AbstractBuild.class);
    BuildData buildData = mock(BuildData.class);
    when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
    when(build.getAction(BuildData.class)).thenReturn(buildData);
    when(build.getResult()).thenReturn(result);
    when(build.getUrl()).thenReturn(BUILD_URL);
    when(build.getResult()).thenReturn(result);
    when(build.getNumber()).thenReturn(BUILD_NUMBER);

    AbstractProject<?, ?> project = mock(AbstractProject.class);
    when(project.getProperty(GitLabConnectionProperty.class)).thenReturn(new GitLabConnectionProperty(gitLabConnection));
    when(build.getProject()).thenReturn(project);
    return build;
}
 
Example 20
Source Project: jenkins-test-harness   Source File: TestNotifier.java    License: MIT License 5 votes vote down vote up
@Override
public BuildStepDescriptor<Publisher> getDescriptor() {
    return new BuildStepDescriptor<Publisher>() {
        @Override
        public boolean isApplicable(Class<? extends AbstractProject> jobType) {
            return true;
        }
    };
}
 
Example 21
@Override
protected PollingResult compareRemoteRevisionWith(
        final AbstractProject<?, ?> project,
        final Launcher launcher,
        final FilePath filePath,
        final TaskListener listener,
        final SCMRevisionState revisionState)
        throws IOException, InterruptedException {

    final ActionTypeId actionTypeId = new ActionTypeId()
            .withCategory(actionTypeCategory)
            .withOwner(ActionOwner.Custom)
            .withProvider(actionTypeProvider)
            .withVersion(actionTypeVersion);

    final String projectName = Validation.sanitize(project.getName().trim());

    LoggingHelper.log(listener, "Polling for jobs for action type id: ["
            + "Owner: %s, Category: %s, Provider: %s, Version: %s, ProjectName: %s]",
            actionTypeId.getOwner(),
            actionTypeId.getCategory(),
            actionTypeId.getProvider(),
            actionTypeId.getVersion(),
            project.getName());

    return pollForJobs(projectName, actionTypeId, listener);
}
 
Example 22
Source Project: ez-templates   Source File: TemplateProjectListener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param item A changed project
 * @return null if this is not a template project
 */
private static TemplateProperty getTemplateProperty(Item item) {
    if (item instanceof AbstractProject) {
        return (TemplateProperty) ((AbstractProject) item).getProperty(TemplateProperty.class);
    }
    return null;
}
 
Example 23
Source Project: appcenter-plugin   Source File: AppCenterRecorder.java    License: MIT License 4 votes vote down vote up
@Override
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
    return true;
}
 
Example 24
@Override
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
    return true;
}
 
Example 25
Source Project: packer-plugin   Source File: PackerPublisher.java    License: MIT License 4 votes vote down vote up
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
    return true;
}
 
Example 26
Source Project: testrail-jenkins-plugin   Source File: TestRailNotifier.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
    // Indicates that this builder can be used with all kinds of project types
    return true;
}
 
Example 27
Source Project: jenkins-plugin   Source File: TimedBuildStepDescriptor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
    // Indicates that this builder can be used with all kinds of project
    // types
    return true;
}
 
Example 28
Source Project: jenkins-build-monitor-plugin   Source File: ByEstimatedDuration.java    License: MIT License 4 votes vote down vote up
@Override
public int compare(AbstractProject<?, ?> a, AbstractProject<?,?> b) {
    return compareEstimatedDuration(a, b);
}
 
Example 29
@Override
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
    return true;
}
 
Example 30
Source Project: git-changelog-plugin   Source File: GitChangelogDescriptor.java    License: MIT License 4 votes vote down vote up
@Override
public boolean isApplicable(
    @SuppressWarnings("rawtypes") final Class<? extends AbstractProject> jobType) {
  return true;
}