use of hudson.model.AbstractProject in project hudson-2.x by hudson.
the class FilePath method validateFileMask.
/**
* Checks the GLOB-style file mask. See {@link #validateAntFileMask(String)}.
* Requires configure permission on ancestor AbstractProject object in request.
* @since 1.294
*/
public FormValidation validateFileMask(String value, boolean errorIfNotExist) throws IOException {
AbstractProject subject = Stapler.getCurrentRequest().findAncestorObject(AbstractProject.class);
subject.checkPermission(Item.CONFIGURE);
value = fixEmpty(value);
if (value == null)
return FormValidation.ok();
try {
if (// no workspace. can't check
!exists())
return FormValidation.ok();
String msg = validateAntFileMask(value);
if (errorIfNotExist)
return FormValidation.error(msg);
else
return FormValidation.warning(msg);
} catch (InterruptedException e) {
return FormValidation.ok();
}
}
use of hudson.model.AbstractProject in project hudson-2.x by hudson.
the class DependencyRunner method run.
public void run() {
Authentication saveAuth = SecurityContextHolder.getContext().getAuthentication();
SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
try {
Set<AbstractProject> topLevelProjects = new HashSet<AbstractProject>();
// Get all top-level projects
LOGGER.fine("assembling top level projects");
for (AbstractProject p : Hudson.getInstance().getAllItems(AbstractProject.class)) if (p.getUpstreamProjects().size() == 0) {
LOGGER.fine("adding top level project " + p.getName());
topLevelProjects.add(p);
} else {
LOGGER.fine("skipping project since not a top level project: " + p.getName());
}
populate(topLevelProjects);
for (AbstractProject p : polledProjects) {
LOGGER.fine("running project in correct dependency order: " + p.getName());
runnable.run(p);
}
} finally {
SecurityContextHolder.getContext().setAuthentication(saveAuth);
}
}
use of hudson.model.AbstractProject in project hudson-2.x by hudson.
the class BuildTrigger method execute.
/**
* Convenience method to trigger downstream builds.
*
* @param build
* The current build. Its downstreams will be triggered.
* @param listener
* Receives the progress report.
*/
public static boolean execute(AbstractBuild build, BuildListener listener) {
PrintStream logger = listener.getLogger();
// Check all downstream Project of the project, not just those defined by BuildTrigger
final DependencyGraph graph = Hudson.getInstance().getDependencyGraph();
List<Dependency> downstreamProjects = new ArrayList<Dependency>(graph.getDownstreamDependencies(build.getProject()));
// Sort topologically
Collections.sort(downstreamProjects, new Comparator<Dependency>() {
public int compare(Dependency lhs, Dependency rhs) {
// Swapping lhs/rhs to get reverse sort:
return graph.compare(rhs.getDownstreamProject(), lhs.getDownstreamProject());
}
});
for (Dependency dep : downstreamProjects) {
AbstractProject p = dep.getDownstreamProject();
if (p.isDisabled()) {
logger.println(Messages.BuildTrigger_Disabled(p.getName()));
continue;
}
List<Action> buildActions = new ArrayList<Action>();
if (dep.shouldTriggerBuild(build, listener, buildActions)) {
// this is not completely accurate, as a new build might be triggered
// between these calls
String name = p.getName() + " #" + p.getNextBuildNumber();
if (p.scheduleBuild(p.getQuietPeriod(), new UpstreamCause((Run) build), buildActions.toArray(new Action[buildActions.size()]))) {
logger.println(Messages.BuildTrigger_Triggering(name));
} else {
logger.println(Messages.BuildTrigger_InQueue(name));
}
}
}
return true;
}
use of hudson.model.AbstractProject in project hudson-2.x by hudson.
the class FilePath method validateRelativePath.
/**
* Validates a relative file path from this {@link FilePath}.
* Requires configure permission on ancestor AbstractProject object in request.
*
* @param value
* The relative path being validated.
* @param errorIfNotExist
* If true, report an error if the given relative path doesn't exist. Otherwise it's a warning.
* @param expectingFile
* If true, we expect the relative path to point to a file.
* Otherwise, the relative path is expected to be pointing to a directory.
*/
public FormValidation validateRelativePath(String value, boolean errorIfNotExist, boolean expectingFile) throws IOException {
AbstractProject subject = Stapler.getCurrentRequest().findAncestorObject(AbstractProject.class);
subject.checkPermission(Item.CONFIGURE);
value = fixEmpty(value);
// none entered yet, or something is seriously wrong
if (value == null || (AbstractProject<?, ?>) subject == null)
return FormValidation.ok();
// a common mistake is to use wildcard
if (value.contains("*"))
return FormValidation.error(Messages.FilePath_validateRelativePath_wildcardNotAllowed());
try {
if (// no base directory. can't check
!exists())
return FormValidation.ok();
FilePath path = child(value);
if (path.exists()) {
if (expectingFile) {
if (!path.isDirectory())
return FormValidation.ok();
else
return FormValidation.error(Messages.FilePath_validateRelativePath_notFile(value));
} else {
if (path.isDirectory())
return FormValidation.ok();
else
return FormValidation.error(Messages.FilePath_validateRelativePath_notDirectory(value));
}
}
String msg = expectingFile ? Messages.FilePath_validateRelativePath_noSuchFile(value) : Messages.FilePath_validateRelativePath_noSuchDirectory(value);
if (errorIfNotExist)
return FormValidation.error(msg);
else
return FormValidation.warning(msg);
} catch (InterruptedException e) {
return FormValidation.ok();
}
}
use of hudson.model.AbstractProject in project hudson-2.x by hudson.
the class GroovyCommand method run.
protected int run() throws Exception {
// this allows the caller to manipulate the JVM state, so require the admin privilege.
Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
Binding binding = new Binding();
binding.setProperty("out", new PrintWriter(stdout, true));
String j = getClientEnvironmentVariable("JOB_NAME");
if (j != null) {
Item job = Hudson.getInstance().getItemByFullName(j);
binding.setProperty("currentJob", job);
String b = getClientEnvironmentVariable("BUILD_NUMBER");
if (b != null && job instanceof AbstractProject) {
Run r = ((AbstractProject) job).getBuildByNumber(Integer.parseInt(b));
binding.setProperty("currentBuild", r);
}
}
GroovyShell groovy = new GroovyShell(binding);
groovy.run(loadScript(), "RemoteClass", remaining.toArray(new String[remaining.size()]));
return 0;
}
Aggregations