Search in sources :

Example 26 with CheckForNull

use of javax.annotation.CheckForNull in project sonarqube by SonarSource.

the class ScannerReportViewerApp method getLastUsedReport.

@CheckForNull
private File getLastUsedReport() {
    File f = new File(System.getProperty("java.io.tmpdir"), ".last_batch_report_dir");
    if (f.exists()) {
        String path;
        try {
            path = FileUtils.readFileToString(f, StandardCharsets.UTF_8);
        } catch (IOException e) {
            return null;
        }
        File lastReport = new File(path);
        if (lastReport.exists() && lastReport.isDirectory()) {
            return lastReport;
        }
    }
    return null;
}
Also used : IOException(java.io.IOException) File(java.io.File) CheckForNull(javax.annotation.CheckForNull)

Example 27 with CheckForNull

use of javax.annotation.CheckForNull in project blueocean-plugin by jenkinsci.

the class BlueI18n method getBundle.

@CheckForNull
private JSONObject getBundle(BundleParams bundleParams, Locale locale) {
    PluginWrapper plugin = bundleParams.getPlugin();
    if (plugin == null) {
        return null;
    }
    try {
        ResourceBundle resourceBundle = ResourceBundle.getBundle(bundleParams.bundleName, locale, plugin.classLoader);
        JSONObject bundleJSON = new JSONObject();
        for (String key : resourceBundle.keySet()) {
            bundleJSON.put(key, resourceBundle.getString(key));
        }
        return bundleJSON;
    } catch (MissingResourceException e) {
    // fall through and return null.
    }
    return null;
}
Also used : JSONObject(net.sf.json.JSONObject) MissingResourceException(java.util.MissingResourceException) PluginWrapper(hudson.PluginWrapper) ResourceBundle(java.util.ResourceBundle) CheckForNull(javax.annotation.CheckForNull)

Example 28 with CheckForNull

use of javax.annotation.CheckForNull in project promoted-builds-plugin by jenkinsci.

the class PromotionProcess method considerPromotion2.

@CheckForNull
public Future<Promotion> considerPromotion2(AbstractBuild<?, ?> build, List<ParameterValue> params) throws IOException {
    if (!isActive())
        // not active
        return null;
    PromotedBuildAction a = build.getAction(PromotedBuildAction.class);
    // if it's already promoted, no need to do anything.
    if (a != null && a.contains(this))
        return null;
    LOGGER.fine("Considering the promotion of " + build + " via " + getName() + " with parameters");
    Status qualification = isMet(build);
    if (qualification == null)
        // not this time
        return null;
    LOGGER.fine("Promotion condition of " + build + " is met: " + qualification);
    // TODO: define promotion cause
    Future<Promotion> f = promote2(build, new UserCause(), qualification, params);
    if (f == null)
        LOGGER.warning(build + " qualifies for a promotion but the queueing failed.");
    return f;
}
Also used : UserCause(hudson.model.Cause.UserCause) CheckForNull(javax.annotation.CheckForNull)

Example 29 with CheckForNull

use of javax.annotation.CheckForNull in project promoted-builds-plugin by jenkinsci.

the class PromotionProcess method considerPromotion2.

/**
     * Checks if the build is promotable, and if so, promote it.
     *
     * @param build Build to be promoted
     * @return
     *      {@code null} if the build was not promoted, otherwise Future that kicks in when the build is completed.
     * @throws IOException 
     */
@CheckForNull
public Future<Promotion> considerPromotion2(AbstractBuild<?, ?> build) throws IOException {
    LOGGER.fine("Considering the promotion of " + build + " via " + getName() + " without parmeters");
    // If the build has manual approvals, use the parameters from it
    List<ParameterValue> params = new ArrayList<ParameterValue>();
    List<ManualApproval> approvals = build.getActions(ManualApproval.class);
    for (ManualApproval approval : approvals) {
        if (approval.name.equals(getName())) {
            LOGGER.fine("Getting parameters from existing manual promotion");
            params = approval.badge.getParameterValues();
            LOGGER.finer("Using paramters: " + params.toString());
        }
    }
    return considerPromotion2(build, params);
}
Also used : ManualApproval(hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) ArrayList(java.util.ArrayList) CheckForNull(javax.annotation.CheckForNull)

Example 30 with CheckForNull

use of javax.annotation.CheckForNull in project promoted-builds-plugin by jenkinsci.

the class ItemPathResolver method findPath.

@CheckForNull
private static Item findPath(@CheckForNull ItemGroup base, @Nonnull String path) {
    @CheckForNull ItemGroup<?> pointer = base;
    final StringTokenizer t = new StringTokenizer(path, "/");
    while (pointer != null && t.hasMoreTokens()) {
        String current = t.nextToken();
        if (current.equals("..")) {
            if (pointer instanceof Item) {
                Item currentItem = (Item) pointer;
                pointer = currentItem.getParent();
            } else {
                // Cannot go upstairs
                pointer = null;
            }
        } else if (current.equals(".")) {
        // Do nothing, we stay on the same level
        } else {
            // Resolve the level beneath
            final Item item = pointer.getItem(current);
            if (!t.hasMoreTokens()) {
                // Last token => we consider it as a required item
                return item;
            }
            if (item instanceof ItemGroup<?>) {
                pointer = (ItemGroup<?>) item;
            } else {
                // Wrong path, we got to item before finishing the requested path
                pointer = null;
            }
        }
    }
    // Cannot retrieve the path => exit with null
    if (pointer instanceof Item) {
        return (Item) pointer;
    }
    return null;
}
Also used : TopLevelItem(hudson.model.TopLevelItem) Item(hudson.model.Item) StringTokenizer(java.util.StringTokenizer) ItemGroup(hudson.model.ItemGroup) CheckForNull(javax.annotation.CheckForNull) CheckForNull(javax.annotation.CheckForNull)

Aggregations

CheckForNull (javax.annotation.CheckForNull)149 IOException (java.io.IOException)18 Tree (org.apache.jackrabbit.oak.api.Tree)16 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)12 ArrayList (java.util.ArrayList)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)9 Stopwatch (com.google.common.base.Stopwatch)8 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)8 Date (java.util.Date)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 Period (org.sonar.server.computation.task.projectanalysis.period.Period)7 File (java.io.File)6 SQLException (java.sql.SQLException)6 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)6 ExecutionException (java.util.concurrent.ExecutionException)5 ValidationModel (org.apache.sling.validation.model.ValidationModel)5 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4 Root (org.apache.jackrabbit.oak.api.Root)4 Utils.resolveCommitRevision (org.apache.jackrabbit.oak.plugins.document.util.Utils.resolveCommitRevision)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4