Search in sources :

Example 1 with Restricted

use of org.kohsuke.accmod.Restricted in project workflow-cps-plugin by jenkinsci.

the class CpsFlowExecution method suspendAll.

@Restricted(DoNotUse.class)
@Terminator
public static void suspendAll() {
    CpsFlowExecution exec = null;
    try (Timeout t = Timeout.limit(3, TimeUnit.MINUTES)) {
        // TODO some complicated sequence of calls to Futures could allow all of them to run in parallel
        LOGGER.fine("starting to suspend all executions");
        for (FlowExecution execution : FlowExecutionList.get()) {
            if (execution instanceof CpsFlowExecution) {
                LOGGER.log(Level.FINE, "waiting to suspend {0}", execution);
                exec = (CpsFlowExecution) execution;
                // Like waitForSuspension but with a timeout:
                if (exec.programPromise != null) {
                    exec.programPromise.get(1, TimeUnit.MINUTES).scheduleRun().get(1, TimeUnit.MINUTES);
                }
            }
        }
        LOGGER.fine("finished suspending all executions");
    } catch (Exception x) {
        LOGGER.log(Level.WARNING, "problem suspending " + exec, x);
    }
}
Also used : Timeout(org.jenkinsci.plugins.workflow.support.concurrent.Timeout) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) AbortException(hudson.AbortException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) Restricted(org.kohsuke.accmod.Restricted) Terminator(hudson.init.Terminator)

Example 2 with Restricted

use of org.kohsuke.accmod.Restricted in project workflow-cps-plugin by jenkinsci.

the class Snippetizer method getQuasiDescriptors.

@Restricted(NoExternalUse.class)
public Collection<QuasiDescriptor> getQuasiDescriptors(boolean advanced) {
    TreeSet<QuasiDescriptor> t = new TreeSet<>();
    for (StepDescriptor d : StepDescriptor.all()) {
        if (d.isAdvanced() == advanced) {
            t.add(new QuasiDescriptor(d));
            if (d.isMetaStep()) {
                DescribableModel<?> m = DescribableModel.of(d.clazz);
                Collection<DescribableParameter> parameters = m.getParameters();
                if (parameters.size() == 1) {
                    DescribableParameter delegate = parameters.iterator().next();
                    if (delegate.isRequired()) {
                        if (delegate.getType() instanceof HeterogeneousObjectType) {
                            // TODO HeterogeneousObjectType does not yet expose symbol information, and DescribableModel.symbolOf is private
                            for (DescribableModel<?> delegateOptionSchema : ((HeterogeneousObjectType) delegate.getType()).getTypes().values()) {
                                Class<?> delegateOptionType = delegateOptionSchema.getType();
                                Descriptor<?> delegateDescriptor = Jenkins.getActiveInstance().getDescriptorOrDie(delegateOptionType.asSubclass(Describable.class));
                                Set<String> symbols = SymbolLookup.getSymbolValue(delegateDescriptor);
                                if (!symbols.isEmpty()) {
                                    t.add(new QuasiDescriptor(delegateDescriptor));
                                }
                            }
                        }
                    }
                }
            // TODO currently not handling metasteps with other parameters, either required or (like GenericSCMStep) not
            }
        }
    }
    return t;
}
Also used : DescribableParameter(org.jenkinsci.plugins.structs.describable.DescribableParameter) UninstantiatedDescribable(org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable) Describable(hudson.model.Describable) TreeSet(java.util.TreeSet) HeterogeneousObjectType(org.jenkinsci.plugins.structs.describable.HeterogeneousObjectType) BuildStepDescriptor(hudson.tasks.BuildStepDescriptor) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) Restricted(org.kohsuke.accmod.Restricted)

Example 3 with Restricted

use of org.kohsuke.accmod.Restricted in project vsphere-cloud-plugin by jenkinsci.

the class CloudProvisioningAlgorithm method toBigInteger.

/**
 * Turns two 64-bit long numbers into a positive 128-bit {@link BigInteger}
 * that's in the range 0 to 2<sup>128</sup>-1.
 * <p>
 * <b>Note:</b> This is only package-level access for unit-testing.
 * </p>
 *
 * @param msb
 *            The most-significant 64 bits.
 * @param lsb
 *            The least-significant 64 bits.
 * @return A {@link BigInteger}.
 */
@Restricted(NoExternalUse.class)
static BigInteger toBigInteger(final long msb, final long lsb) {
    final byte[] bytes = new byte[17];
    int b = 0;
    // ensure we're all positive
    bytes[b++] = (byte) 0;
    bytes[b++] = (byte) (msb >> 56);
    bytes[b++] = (byte) (msb >> 48);
    bytes[b++] = (byte) (msb >> 40);
    bytes[b++] = (byte) (msb >> 32);
    bytes[b++] = (byte) (msb >> 24);
    bytes[b++] = (byte) (msb >> 16);
    bytes[b++] = (byte) (msb >> 8);
    bytes[b++] = (byte) (msb);
    bytes[b++] = (byte) (lsb >> 56);
    bytes[b++] = (byte) (lsb >> 48);
    bytes[b++] = (byte) (lsb >> 40);
    bytes[b++] = (byte) (lsb >> 32);
    bytes[b++] = (byte) (lsb >> 24);
    bytes[b++] = (byte) (lsb >> 16);
    bytes[b++] = (byte) (lsb >> 8);
    bytes[b++] = (byte) (lsb);
    final BigInteger bigNumber = new BigInteger(bytes);
    return bigNumber;
}
Also used : BigInteger(java.math.BigInteger) Restricted(org.kohsuke.accmod.Restricted)

Example 4 with Restricted

use of org.kohsuke.accmod.Restricted in project access-modifier by kohsuke.

the class EnforcerMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping access modifier checks");
        return;
    }
    try {
        File outputDir = new File(project.getBuild().getOutputDirectory());
        List<URL> dependencies = new ArrayList<URL>();
        for (Artifact a : (Collection<Artifact>) project.getArtifacts()) dependencies.add(a.getFile().toURI().toURL());
        URL outputURL = outputDir.toURI().toURL();
        dependencies.add(outputURL);
        final boolean[] failed = new boolean[1];
        Checker checker = new Checker(new URLClassLoader(dependencies.toArray(new URL[dependencies.size()]), getClass().getClassLoader()), new ErrorListener() {

            public void onError(Throwable t, Location loc, String msg) {
                String locMsg = loc + " " + msg;
                if (failOnError) {
                    getLog().error(locMsg, t);
                } else {
                    getLog().warn(locMsg, t);
                }
                failed[0] = true;
            }

            public void onWarning(Throwable t, Location loc, String msg) {
                getLog().warn(loc + " " + msg, t);
            }
        }, properties != null ? properties : new Properties());
        {
            // if there's restriction list in the inspected module itself, load it as well
            InputStream self = null;
            try {
                self = new URL(outputURL, "META-INF/annotations/" + Restricted.class.getName()).openStream();
            } catch (IOException e) {
            }
            if (self != null)
                checker.loadRestrictions(self, true);
        }
        // perform checks
        checker.check(outputDir);
        if (failed[0]) {
            String message = "Access modifier checks failed. See the details above";
            if (failOnError) {
                throw new MojoFailureException(message);
            } else {
                getLog().warn(message);
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to enforce @Restricted constraints", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Restricted(org.kohsuke.accmod.Restricted) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) Properties(java.util.Properties) URL(java.net.URL) Artifact(org.apache.maven.artifact.Artifact) URLClassLoader(java.net.URLClassLoader) Collection(java.util.Collection) File(java.io.File)

Example 5 with Restricted

use of org.kohsuke.accmod.Restricted in project promoted-builds-plugin by jenkinsci.

the class PromotedBuildAction method canPromote.

@Restricted(NoExternalUse.class)
public boolean canPromote(String processName) {
    PromotionProcess process = getPromotionProcess(processName);
    ManualCondition manualCondition = null;
    if (process != null) {
        manualCondition = (ManualCondition) process.getPromotionCondition(ManualCondition.class.getName());
    }
    return PromotionPermissionHelper.hasPermission(getProject(), manualCondition);
}
Also used : ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) Restricted(org.kohsuke.accmod.Restricted)

Aggregations

Restricted (org.kohsuke.accmod.Restricted)10 IOException (java.io.IOException)3 Describable (hudson.model.Describable)2 BuildStepDescriptor (hudson.tasks.BuildStepDescriptor)2 Jenkins (jenkins.model.Jenkins)2 JSONObject (net.sf.json.JSONObject)2 DescribableParameter (org.jenkinsci.plugins.structs.describable.DescribableParameter)2 UninstantiatedDescribable (org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable)2 StepDescriptor (org.jenkinsci.plugins.workflow.steps.StepDescriptor)2 AbortException (hudson.AbortException)1 Terminator (hudson.init.Terminator)1 Descriptor (hudson.model.Descriptor)1 TopLevelItem (hudson.model.TopLevelItem)1 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 File (java.io.File)1 InputStream (java.io.InputStream)1 GenericArrayType (java.lang.reflect.GenericArrayType)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1