Example usage for org.eclipse.jgit.util StringUtils isEmptyOrNull

List of usage examples for org.eclipse.jgit.util StringUtils isEmptyOrNull

Introduction

In this page you can find the example usage for org.eclipse.jgit.util StringUtils isEmptyOrNull.

Prototype

public static boolean isEmptyOrNull(String stringValue) 

Source Link

Document

Test if a string is empty or null.

Usage

From source file:com.genuitec.eclipse.gerrit.tools.utils.RepositoryUtils.java

License:Open Source License

public static String getUserId(Repository repository) {
    StoredConfig config;/* w w w. ja  va2s  .  c  o  m*/
    if (repository == null) {
        if (StringUtils.isEmptyOrNull(SystemReader.getInstance().getenv(Constants.GIT_CONFIG_NOSYSTEM_KEY))) {
            config = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED);
        } else {
            config = new FileBasedConfig(null, FS.DETECTED) {
                public void load() {
                    // empty, do not load
                }

                public boolean isOutdated() {
                    // regular class would bomb here
                    return false;
                }
            };
        }
        try {
            config.load();
            config = SystemReader.getInstance().openUserConfig(config, FS.DETECTED);
            config.load();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    } else {
        config = repository.getConfig();
    }
    String email = config.getString("user", null, "email"); //$NON-NLS-1$ //$NON-NLS-2$
    if (email != null) {
        int ind = email.indexOf('@');
        if (ind > 0) {
            return email.substring(0, ind);
        }
    }
    return null;
}

From source file:com.google.gct.idea.appengine.deploy.AppEngineUpdateDialog.java

License:Apache License

@Override
protected void doOKAction() {
    if (getOKAction().isEnabled()) {
        GoogleLogin login = GoogleLogin.getInstance();
        Module selectedModule = myModuleComboBox.getSelectedModule();
        String sdk = "";
        String war = "";
        AppEngineGradleFacet facet = AppEngineGradleFacet.getAppEngineFacetByModule(selectedModule);
        if (facet != null) {
            AppEngineConfigurationProperties model = facet.getConfiguration().getState();
            sdk = model.APPENGINE_SDKROOT;
            war = model.WAR_DIR;/*from w w  w.ja  va 2s.c  om*/
        }

        String client_secret = login.fetchOAuth2ClientSecret();
        String client_id = login.fetchOAuth2ClientId();
        String refresh_token = login.fetchOAuth2RefreshToken();

        if (StringUtils.isEmptyOrNull(client_secret) || StringUtils.isEmptyOrNull(client_id)
                || StringUtils.isEmptyOrNull(refresh_token)) {
            // The login is somehow invalid, bail -- this shouldn't happen.
            LOG.error("StartUploading while logged in, but it doesn't have full credentials.");
            Messages.showErrorDialog(this.getPeer().getOwner(), "Login credentials are not valid.", "Login");
            return;
        }

        // These should not fail as they are a part of the dialog validation.
        if (Strings.isNullOrEmpty(sdk) || Strings.isNullOrEmpty(war)
                || Strings.isNullOrEmpty(myProjectId.getText()) || selectedModule == null) {
            Messages.showErrorDialog(this.getPeer().getOwner(),
                    "Could not deploy due to missing information (sdk/war/projectid).", "Deploy");
            LOG.error("StartUploading was called with bad module/sdk/war");
            return;
        }

        close(OK_EXIT_CODE); // We close before kicking off the update so it doesn't interfere with the output window coming to focus.

        // Kick off the upload.  detailed status will be shown in an output window.
        new AppEngineUpdater(myProject, selectedModule, sdk, war, myProjectId.getText(), myVersion.getText(),
                client_secret, client_id, refresh_token).startUploading();
    }
}

From source file:com.google.gerrit.server.contact.ContactStoreModule.java

License:Apache License

@Nullable
@Provides/* w w w.  j  a  v  a2 s  .c o  m*/
public ContactStore provideContactStore(@GerritServerConfig final Config config, final SitePaths site,
        final SchemaFactory<ReviewDb> schema, final ContactStoreConnection.Factory connFactory) {
    final String url = config.getString("contactstore", null, "url");
    if (StringUtils.isEmptyOrNull(url)) {
        return new NoContactStore();
    }

    if (!havePGP()) {
        throw new ProvisionException(
                "BouncyCastle PGP not installed; " + " needed to encrypt contact information");
    }

    final URL storeUrl;
    try {
        storeUrl = new URL(url);
    } catch (MalformedURLException e) {
        throw new ProvisionException("Invalid contactstore.url: " + url, e);
    }

    final String storeAPPSEC = config.getString("contactstore", null, "appsec");
    final File pubkey = site.contact_information_pub;
    if (!pubkey.exists()) {
        throw new ProvisionException("PGP public key file \"" + pubkey.getAbsolutePath() + "\" not found");
    }
    return new EncryptedContactStore(storeUrl, storeAPPSEC, pubkey, schema, connFactory);
}

From source file:com.meltmedia.cadmium.blackbox.test.CadmiumAssertions.java

License:Apache License

/**
 * <p>Asserts that a remote resource exists.</p>
 * @param message The message that will be in the error if the remote resource doesn't exist.
 * @param remoteLocation A string containing the URL location of the remote resource to check.
 * @param username The Basic HTTP auth username.
 * @param password The Basic HTTP auth password.
 * @return The content of the remote file.
 *//*from  ww w . j  a v a 2 s.co m*/
public static HttpEntity assertExistsRemotely(String message, String remoteLocation, String username,
        String password) {
    DefaultHttpClient client = new DefaultHttpClient();
    try {
        HttpGet get = new HttpGet(remoteLocation);
        if (!StringUtils.isEmptyOrNull(username) && !StringUtils.isEmptyOrNull(password)) {
            get.setHeader("Authorization", encodeForBasicAuth(username, password));
        }

        HttpResponse resp = client.execute(get);
        if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new AssertionFailedError(message);
        }
        return resp.getEntity();
    } catch (ClientProtocolException e) {
        throw new AssertionFailedError(e.getMessage() + ": " + message);
    } catch (IOException e) {
        throw new AssertionFailedError(e.getMessage() + ": " + message);
    }
}

From source file:com.meltmedia.cadmium.blackbox.test.ContentTypeApiResponseValidator.java

License:Apache License

@Override
public void validate(HttpResponse response) {
    if (expectedStatusCode != -1) {
        super.validate(response);
    }/*from www .j a va2s  .c  o m*/
    if (!StringUtils.isEmptyOrNull(expectedContentType)) {
        String contentType = response.getFirstHeader("Content-Type").getValue();
        assertEquals("Content-Type {" + contentType + "} does not match the expected Content-Type: "
                + this.expectedContentType, this.expectedContentType, contentType);
    }
}

From source file:com.meltmedia.cadmium.blackbox.test.rest.RestApiTest.java

License:Apache License

@Parameterized.Parameters
public static Collection<Object[]> data() {
    if (!skip && StringUtils.isEmptyOrNull(token)) {
        File tokenFile = new File(System.getProperty("user.home"), ".cadmium/github.token");
        if (tokenFile.exists()) {
            try {
                token = FileUtils.readFileToString(tokenFile);
            } catch (Exception e) {
                System.err.println("Failed to attain github rest api token.");
            }/* w  ww. ja va 2  s.c o m*/
        } else {
            System.err.println("No token exists at path: " + tokenFile.getAbsolutePath());
        }
    }
    if (!skip && !StringUtils.isEmptyOrNull(token)) {
        return Arrays.asList(new Object[][] {
                // System api endpoints
                /*[0] */ { new StatusPingEndpointTest() }, /*[1] */ { new StatusHealthEndpointTest() },
                /*[2] */ { new StatusEndpointTest(token) }, /*[3] */ { new LoggerGetEndpointTest(token) },
                /*[4] */ { new LoggerPostEndpointTest(token) },
                /*[5] */ { new LoggerNamePostEndpointTest(token) },
                /*[6] */ { new LoggerNameGetEndpointTest(token) },
                /*[7] */ { new MaintenanceEndpointTest(token, MaintenanceRequest.State.ON) },
                /*[8] */ { new MaintenanceEndpointTest(token, MaintenanceRequest.State.OFF) },
                /*[9] */ { new HistoryEndpointTest(token) }, /*[10]*/ { new HistoryLimitEndpointTest(token) },
                /*[11]*/ { new HistoryFilterEndpointTest(token) },
                /*[12]*/ { new HistoryLimitFilterEndpointTest(token) },
                /*[13]*/ { new UpdateEndpointTest(token, gitInit) },
                /*[14]*/ { new UpdateConfigEndpointTest(token, gitInit) },
                /*[15]*/ { new ApiACLEndpointTest(token) },
                /*[16]*/ { new AuthenticationManagerEndpointTest(token) },
                // Client api endpoints
                /*[17]*/ { new SearchEndpointTest() } });
    } else {
        return Arrays.asList(new Object[][] {});
    }
}

From source file:com.meltmedia.cadmium.blackbox.test.rest.RestApiTest.java

License:Apache License

@BeforeClass
public static void deployWar() throws Exception {
    if (!skip && !StringUtils.isEmptyOrNull(token)) {
        gitInit.init(new File("./target/test-content-repo").getAbsoluteFile().getAbsolutePath(),
                new File("./target/filtered-resources/test-content").getAbsoluteFile().getAbsolutePath(),
                new File("./target/filtered-resources/test-config").getAbsoluteFile().getAbsolutePath());
        System.setProperty("com.meltmedia.cadmium.contentRoot",
                new File("target/filtered-resources").getAbsoluteFile().getAbsolutePath());
        WarUtils.updateWar(null, "target/deploy/cadmium-war.war", Arrays.asList("target/deploy/cadmium.war"),
                new File("./target/test-content-repo").getAbsoluteFile().getAbsolutePath(), "cd-master",
                new File("./target/test-content-repo").getAbsoluteFile().getAbsolutePath(), "cfg-master",
                "localhost", "/", true, logger);
        warContainer = new CadmiumWarContainer("target/deploy/cadmium.war", 8901);
        warContainer.setupCadmiumEnvironment("target", "testing");
        warContainer.startServer();/*  w  w w .ja  va 2 s .c  om*/
        while (!warContainer.isStarted()) {
            Thread.sleep(500l);
        }
    } else {
        gitInit = null;
    }
}

From source file:com.meltmedia.cadmium.cli.CloneCommand.java

License:Apache License

/**
 * Checks if a config update message is necessary and sends it if it is.
 * /*  w w  w .j  ava 2  s  . c  o m*/
 * @param site1 The source site for the configuration.
 * @param site2 The target site for the configuration.
 * @param site1Status The status of the source site.
 * @param site2Status The status of the target site.
 * @throws Exception
 */
private void checkSendUpdateConfigMessage(String site1, String site2, Status site1Status, Status site2Status)
        throws Exception {
    String repo;
    String revision;
    String branch;
    if (includeConfig) {
        repo = site1Status.getConfigRepo();
        revision = site1Status.getConfigRevision();
        branch = site1Status.getConfigBranch();
        if (!StringUtils.isEmptyOrNull(repo) && !StringUtils.isEmptyOrNull(revision)
                && !StringUtils.isEmptyOrNull(branch)) {
            if (!repo.equals(site2Status.getConfigRepo()) || !revision.equals(site2Status.getConfigRevision())
                    || !branch.equals(site2Status.getConfigBranch())) {
                System.out.println("Sending update/config message to [" + site2 + "]");
                UpdateCommand.sendUpdateMessage(site2, repo, branch, revision,
                        "Cloned config from [" + site1 + "]: " + comment, token,
                        UpdateConfigCommand.UPDATE_CONFIG_ENDPOINT, UpdateRequest.CONFIG_BRANCH_PREFIX);
            } else {
                System.out.println("Source [" + site1
                        + "] is on the same configuration repo, branch, and revision as the target [" + site2
                        + "].");
            }
        } else {
            System.out.println("Configuration status not available from source site [" + site1 + "]");
        }
    }
}

From source file:com.meltmedia.cadmium.core.commands.ApiEndpointAccessCommandAction.java

License:Apache License

@Override
public boolean execute(CommandContext<ApiEndpointAccessRequest> ctx) throws Exception {
    ApiEndpointAccessRequest req = ctx.getMessage().getBody();
    if (req != null && !StringUtils.isEmptyOrNull(req.getEndpoint())) {
        if (req.getOperation() == ApiEndpointAccessRequest.UpdateOpteration.DISABLE) {
            log.info("Disabling endpoint /api/" + req.getEndpoint());
            controller.disable(req.getEndpoint());
        } else if (req.getOperation() == ApiEndpointAccessRequest.UpdateOpteration.ENABLE) {
            log.info("Enabling endpoint /api/" + req.getEndpoint());
            controller.enable(req.getEndpoint());
        }//from   w ww .ja  va 2  s . c o  m
    }
    return true;
}

From source file:com.meltmedia.cadmium.core.commands.MaintenanceCommandAction.java

License:Apache License

@Override
public boolean execute(CommandContext<MaintenanceRequest> ctx) throws Exception {
    log.info("Beginning Maintenance Toggle, started by {}", ctx.getSource());
    MaintenanceRequest request = ctx.getMessage().getBody();
    if (!StringUtils.isEmptyOrNull(request.getState())) {
        if (request.getState().equalsIgnoreCase("on")) {
            log.info("Starting maintenance page.");
            siteDownService.start();//  w  ww . j a v  a 2s .  com
        } else if (request.getState().equalsIgnoreCase("off")) {
            log.info("Stopping maintenance page.");
            siteDownService.stop();
        }
    }
    manager.logEvent(siteDownService.isOn(), request.getOpenId(), emptyStringIfNull(request.getComment()));
    return true;
}